Browse Source

App巡检-巡检计划查询接口开发

jichaobo 2 years ago
parent
commit
e0aee75052

+ 19 - 2
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/AppPatrolInspectionController.java

@@ -31,7 +31,24 @@ public class AppPatrolInspectionController {
      * @return
      */
     @GetMapping("appPlanStatistics")
-    public ApiResult<Map<String, Object>> appPlanStatistics(@RequestParam(value = "personnelId") Integer personnelId) {
-        return ApiResult.success(patrolInspectionPlanSonService.appPlanStatistics(personnelId));
+    public ApiResult<Map<String, Object>> appPlanStatistics(@RequestParam(value = "personnelId") Integer personnelId,
+                                                            @RequestParam(value = "currentDate", required = false) String currentDate) {
+        return ApiResult.success(patrolInspectionPlanSonService.appPlanStatistics(personnelId, currentDate));
+    }
+
+
+    /**
+     * App-巡检自查-巡检计划
+     *
+     * @param personnelId 人员ID
+     * @param currentDate 日期 格式:yyyy-MM-dd
+     * @param sort        排序 (正序:ASC 倒序:DESC)
+     * @return
+     */
+    @GetMapping("patrolInspectionPlan")
+    public ApiResult<Map<String, Object>> patrolInspectionPlan(@RequestParam(value = "personnelId") Integer personnelId,
+                                                               @RequestParam(value = "currentDate", required = false) String currentDate,
+                                                               @RequestParam(value = "sort", required = false, defaultValue = "DESC") String sort) {
+        return ApiResult.success(patrolInspectionPlanSonService.patrolInspectionPlan(personnelId, currentDate, sort));
     }
 }

+ 4 - 2
service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/PatrolInspectionPlanMapper.java

@@ -1,16 +1,18 @@
 package com.usky.fire.mapper;
 
-import com.usky.fire.domain.PatrolInspectionPlan;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.fire.domain.PatrolInspectionPlan;
+import org.springframework.stereotype.Repository;
 
 /**
  * <p>
- *  Mapper 接口
+ * Mapper 接口
  * </p>
  *
  * @author JCB
  * @since 2022-07-18
  */
+@Repository
 public interface PatrolInspectionPlanMapper extends CrudMapper<PatrolInspectionPlan> {
 
 }

+ 36 - 4
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/PatrolInspectionPlanSonService.java

@@ -2,6 +2,8 @@ package com.usky.fire.service;
 
 import com.usky.common.mybatis.core.CrudService;
 import com.usky.fire.domain.PatrolInspectionPlanSon;
+import com.usky.fire.service.vo.DataCountVo;
+import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
 
 import java.util.List;
 import java.util.Map;
@@ -22,14 +24,44 @@ public interface PatrolInspectionPlanSonService extends CrudService<PatrolInspec
      * @param personnelId 人员ID
      * @return
      */
-    Map<String, Object> appPlanStatistics(Integer personnelId);
+    Map<String, Object> appPlanStatistics(Integer personnelId, String currentDate);
+
+    /**
+     * 手机端-巡检自检-巡检计划
+     * @param personnelId
+     * @param currentDate
+     * @param sort
+     * @return
+     */
+    Map<String, Object> patrolInspectionPlan(Integer personnelId, String currentDate, String sort);
+
+
+    /**
+     * 手机端-巡检自检-巡检计划列表查询
+     * @param planIdList
+     * @param currentDate
+     * @param sort
+     * @return
+     */
+    List<PatrolInspectionPlanSonVo> patrolInspectionPlanSon(List<Integer> planIdList, String currentDate, String sort);
+
+
+    /**
+     * 手机端-巡检自检-巡检任务-巡检子计划地点统计
+     *
+     * @param planSonidList    子计划ID
+     * @param inspectionStatus 巡检状态(1 未巡检,2 已巡检)
+     * @return
+     */
+    List<DataCountVo> planSiteSonCount(List<Integer> planSonidList, Integer inspectionStatus);
 
     /**
      * 手机端-巡检子计划数量查询
      *
-     * @param planIdList 主计划ID
-     * @param completion 完成百分比
+     * @param planIdList  主计划ID
+     * @param completion  完成百分比
+     * @param currentDate 当前日期
      * @return
      */
-    Integer planSonCount(List<Integer> planIdList, Integer completion);
+    Integer planSonCount(List<Integer> planIdList, Integer completion, String currentDate);
 }

+ 204 - 12
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionPlanSonServiceImpl.java

@@ -3,18 +3,25 @@ package com.usky.fire.service.impl;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.common.mybatis.core.AbstractCrudService;
+import com.usky.fire.domain.PatrolInspectionPlan;
 import com.usky.fire.domain.PatrolInspectionPlanSchedule;
+import com.usky.fire.domain.PatrolInspectionPlanSiteSon;
 import com.usky.fire.domain.PatrolInspectionPlanSon;
+import com.usky.fire.mapper.PatrolInspectionPlanMapper;
 import com.usky.fire.mapper.PatrolInspectionPlanSonMapper;
 import com.usky.fire.service.PatrolInspectionPlanScheduleService;
+import com.usky.fire.service.PatrolInspectionPlanSiteSonService;
 import com.usky.fire.service.PatrolInspectionPlanSonService;
+import com.usky.fire.service.vo.DataCountVo;
+import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -30,7 +37,40 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
     @Autowired
     private PatrolInspectionPlanScheduleService patrolInspectionPlanScheduleService;
 
-    public Map<String, Object> appPlanStatistics(Integer personnelId) {
+    @Autowired
+    private PatrolInspectionPlanMapper patrolInspectionPlanMapper;
+
+    @Autowired
+    private PatrolInspectionPlanSiteSonService patrolInspectionPlanSiteSonService;
+
+    @Override
+    public Map<String, Object> appPlanStatistics(Integer personnelId, String currentDate) {
+        LambdaQueryWrapper<PatrolInspectionPlanSchedule> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.select(PatrolInspectionPlanSchedule::getPlanId)
+                .eq(PatrolInspectionPlanSchedule::getPersonnelId, personnelId)
+                .groupBy(PatrolInspectionPlanSchedule::getPlanId);
+        List<PatrolInspectionPlanSchedule> planScheduleList = patrolInspectionPlanScheduleService.list(queryWrapper);
+        Integer planSonCount = 0;
+        Integer patrolledCount = 0;
+        Integer undetectedCount = 0;
+        if (planScheduleList.size() > 0) {
+            List<Integer> planIdList = new ArrayList<>();
+            for (int i = 0; i < planScheduleList.size(); i++) {
+                planIdList.add(planScheduleList.get(i).getPlanId());
+            }
+            planSonCount = this.planSonCount(planIdList, null, currentDate);
+            patrolledCount = this.planSonCount(planIdList, 100, currentDate);
+            undetectedCount = planSonCount - patrolledCount;
+        }
+        Map<String, Object> map = new HashMap<>();
+        map.put("planSonCount", planSonCount);//巡检任务总数
+        map.put("patrolledCount", patrolledCount);//已巡检任务
+        map.put("undetectedCount", undetectedCount);//漏检任务
+        return map;
+    }
+
+
+    public Map<String, Object> patrolInspectionPlan(Integer personnelId, String currentDate, String sort) {
         LambdaQueryWrapper<PatrolInspectionPlanSchedule> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.select(PatrolInspectionPlanSchedule::getPlanId)
                 .eq(PatrolInspectionPlanSchedule::getPersonnelId, personnelId)
@@ -39,23 +79,171 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
         Integer planSonCount = 0;
         Integer patrolledCount = 0;
         Integer undetectedCount = 0;
+        List<PatrolInspectionPlanSonVo> planList = new ArrayList<>();
         if (planScheduleList.size() > 0) {
             List<Integer> planIdList = new ArrayList<>();
             for (int i = 0; i < planScheduleList.size(); i++) {
                 planIdList.add(planScheduleList.get(i).getPlanId());
             }
-            planSonCount = this.planSonCount(planIdList, null);
-            patrolledCount = this.planSonCount(planIdList, 100);
+            planList = this.patrolInspectionPlanSon(planIdList, currentDate, sort);
+            planSonCount = this.planSonCount(planIdList, null, currentDate);
+            patrolledCount = this.planSonCount(planIdList, 100, currentDate);
             undetectedCount = planSonCount - patrolledCount;
+
         }
         Map<String, Object> map = new HashMap<>();
         map.put("planSonCount", planSonCount);//巡检任务总数
         map.put("patrolledCount", patrolledCount);//已巡检任务
         map.put("undetectedCount", undetectedCount);//漏检任务
+        map.put("planList", planList);
         return map;
     }
 
-    public Integer planSonCount(List<Integer> planIdList, Integer completion) {
+
+    @Override
+    public List<PatrolInspectionPlanSonVo> patrolInspectionPlanSon(List<Integer> planIdList, String currentDate, String sort) {
+//        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper = Wrappers.lambdaQuery();
+        if (planIdList != null && planIdList.size() > 0) {
+            queryWrapper.in(PatrolInspectionPlanSon::getPlanId, planIdList);
+        }
+        queryWrapper.and((wrapper) -> {
+            wrapper.eq(PatrolInspectionPlanSon::getInspectionDate, currentDate)
+                    .or()
+                    .le(PatrolInspectionPlanSon::getStartDate, currentDate)
+                    .ge(PatrolInspectionPlanSon::getEndDate, currentDate);
+        });
+        if (sort.equals("ASC")) {
+            queryWrapper.orderByAsc(PatrolInspectionPlanSon::getId);
+        } else {
+            queryWrapper.orderByDesc(PatrolInspectionPlanSon::getId);
+        }
+        List<PatrolInspectionPlanSon> planSonList = this.list(queryWrapper);
+        List<PatrolInspectionPlanSonVo> list = new ArrayList<>();
+        if (planSonList.size() > 0) {
+            List<Integer> planSonidList = new ArrayList<>();
+            for (int i = 0; i < planSonList.size(); i++) {
+                planSonidList.add(planSonList.get(i).getId());
+            }
+            //巡检计划名称查询
+            LambdaQueryWrapper<PatrolInspectionPlan> queryWrapperOne = Wrappers.lambdaQuery();
+            queryWrapperOne.select(PatrolInspectionPlan::getId, PatrolInspectionPlan::getPlanName);
+            if (planIdList != null && planIdList.size() > 0) {
+                queryWrapperOne.in(PatrolInspectionPlan::getId, planIdList);
+            }
+
+            List<PatrolInspectionPlan> planList = patrolInspectionPlanMapper.selectList(queryWrapperOne);
+            List<DataCountVo> patrolledSiteCountList = this.planSiteSonCount(planSonidList, 2);//已巡检地点数量
+            List<DataCountVo> undetectedSiteCountList = this.planSiteSonCount(planSonidList, 1);//漏检地点数量
+            for (int i = 0; i < planSonList.size(); i++) {
+                PatrolInspectionPlanSonVo patrolInspectionPlanSonVo = new PatrolInspectionPlanSonVo();
+                patrolInspectionPlanSonVo.setId(planSonList.get(i).getId());
+                patrolInspectionPlanSonVo.setStartTime(planSonList.get(i).getStartTime());
+                patrolInspectionPlanSonVo.setEndTime(planSonList.get(i).getEndTime());
+                patrolInspectionPlanSonVo.setCompletion(planSonList.get(i).getCompletion());
+                patrolInspectionPlanSonVo.setPlanType(planSonList.get(i).getPlanType());
+                patrolInspectionPlanSonVo.setPlanCycle(planSonList.get(i).getPlanCycle());
+                patrolInspectionPlanSonVo.setStartDate(planSonList.get(i).getStartDate());
+                patrolInspectionPlanSonVo.setEndDate(planSonList.get(i).getEndDate());
+                patrolInspectionPlanSonVo.setInspectionDate(planSonList.get(i).getInspectionDate());
+                patrolInspectionPlanSonVo.setPatrolledSiteCount(0);
+                patrolInspectionPlanSonVo.setUndetectedSiteCount(0);
+                //计划名称
+                for (int j = 0; j < planList.size(); j++) {
+                    if (planSonList.get(i).getPlanId() == planList.get(j).getId()) {
+                        patrolInspectionPlanSonVo.setPlanName(planList.get(j).getPlanName());
+                    }
+                }
+                Integer planStatus = 1;
+                Date currentTime = new Date();
+                Date endTime = null;
+                if (planSonList.get(i).getPlanType() == 1) {
+                    //获取结束日期时间
+                    LocalDate inspectionDate = planSonList.get(i).getInspectionDate();
+                    String inspectionDateOne = df1.format(inspectionDate);
+                    String inspectionDateTwo = inspectionDateOne + " " + planSonList.get(i).getEndTime();
+                    try {
+                        endTime = formatter.parse(inspectionDateTwo);
+                    } catch (Exception e) {
+                    }
+
+                } else {
+                    //获取结束日期时间
+                    LocalDate endDate = planSonList.get(i).getEndDate();
+                    String endDateOne = df1.format(endDate) + " 23:59:59";
+                    try {
+                        endTime = formatter.parse(endDateOne);
+                    } catch (Exception e) {
+                    }
+                    //计划类型描述
+                    String planCycleName = null;
+                    if (planSonList.get(i).getPlanCycle() == 1) {
+                        planCycleName = "(日)";
+                    } else if (planSonList.get(i).getPlanCycle() == 2) {
+                        planCycleName = "(周)";
+                    } else if (planSonList.get(i).getPlanCycle() == 3) {
+                        planCycleName = "(月)";
+                    } else if (planSonList.get(i).getPlanCycle() == 4) {
+                        planCycleName = "(年)";
+                    }
+                    patrolInspectionPlanSonVo.setPlanTypeDescribe("按次计划" + planCycleName);
+                }
+                //判断计划状态
+                int status = endTime.compareTo(currentTime);
+                if (status == -1) {
+                    if (planSonList.get(i).getCompletion() == 100) {
+                        planStatus = 2;
+                    } else {
+                        planStatus = 3;
+                    }
+                }
+                patrolInspectionPlanSonVo.setPlanStatus(planStatus);
+                for (int j = 0; j < patrolledSiteCountList.size(); j++) {
+                    if (planSonList.get(i).getId() == patrolledSiteCountList.get(j).getId()) {
+                        patrolInspectionPlanSonVo.setPatrolledSiteCount(patrolledSiteCountList.get(j).getListCount());
+                    }
+                }
+                for (int j = 0; j < undetectedSiteCountList.size(); j++) {
+                    if (planSonList.get(i).getId() == undetectedSiteCountList.get(j).getId()) {
+                        patrolInspectionPlanSonVo.setUndetectedSiteCount(undetectedSiteCountList.get(j).getListCount());
+                    }
+                }
+                list.add(patrolInspectionPlanSonVo);
+            }
+        }
+        return list;
+    }
+
+    @Override
+    public List<DataCountVo> planSiteSonCount(List<Integer> planSonidList, Integer inspectionStatus) {
+
+        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
+        if (planSonidList != null && planSonidList.size() > 0) {
+            queryWrapper.in(PatrolInspectionPlanSiteSon::getPlanId, planSonidList);
+        }
+        if (inspectionStatus != null) {
+            queryWrapper.eq(PatrolInspectionPlanSiteSon::getInspectionStatus, inspectionStatus);
+        }
+        List<PatrolInspectionPlanSiteSon> planSiteSonList = patrolInspectionPlanSiteSonService.list(queryWrapper);
+
+        Map<Integer, List<PatrolInspectionPlanSiteSon>> grouypByAreaPlanId = planSiteSonList.stream().collect(
+                Collectors.groupingBy(o -> o.getPlanId())
+        );
+        List<DataCountVo> dataCountVoList = new ArrayList<>();
+        grouypByAreaPlanId.forEach((k, v) -> {
+            DataCountVo dataCountVo = new DataCountVo();
+            dataCountVo.setListCount(v.size());
+            dataCountVo.setId(k);
+            dataCountVoList.add(dataCountVo);
+        });
+        return dataCountVoList;
+    }
+
+    @Override
+    public Integer planSonCount(List<Integer> planIdList, Integer completion, String currentDate) {
+        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper = Wrappers.lambdaQuery();
         if (planIdList != null && planIdList.size() > 0) {
             queryWrapper.in(PatrolInspectionPlanSon::getPlanId, planIdList);
@@ -63,12 +251,16 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
         if (completion != null) {
             queryWrapper.eq(PatrolInspectionPlanSon::getCompletion, completion);
         }
-
+        LocalDate currentDate1 = LocalDate.now();
+        if (currentDate != null && !"".equals(currentDate)) {
+            currentDate1 = LocalDate.parse(currentDate);
+        }
+        LocalDate finalCurrentDate = currentDate1;
         queryWrapper.and((wrapper) -> {
-            wrapper.eq(PatrolInspectionPlanSon::getInspectionDate, "2022-07-31")
+            wrapper.eq(PatrolInspectionPlanSon::getInspectionDate, finalCurrentDate)
                     .or()
-                    .ge(PatrolInspectionPlanSon::getStartDate, "2022-07-31")
-                    .le(PatrolInspectionPlanSon::getEndDate, "2022-08-07");
+                    .le(PatrolInspectionPlanSon::getStartDate, finalCurrentDate)
+                    .ge(PatrolInspectionPlanSon::getEndDate, finalCurrentDate);
         });
 
         Integer planSonCount = this.count(queryWrapper);

+ 159 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PatrolInspectionPlanSonVo.java

@@ -0,0 +1,159 @@
+package com.usky.fire.service.vo;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author JCB
+ * @since 2022-07-18
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+public class PatrolInspectionPlanSonVo implements Serializable {
+
+    private static final long serialVersionUID=1L;
+
+    /**
+     * 巡检计划子信息表主键ID
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 计划主表id
+     */
+    private Integer planId;
+
+    /**
+     * 巡检日期
+     */
+    private LocalDate inspectionDate;
+
+    /**
+     * 开始日期
+     */
+    private LocalDate startDate;
+
+    /**
+     * 结束日期
+     */
+    private LocalDate endDate;
+
+    /**
+     * 开始时间
+     */
+    private String startTime;
+
+    /**
+     * 结束时间
+     */
+    private String endTime;
+
+    /**
+     * 巡检人员ID
+     */
+    private Integer personnelId;
+
+    /**
+     * 巡检区域ID
+     */
+    private Integer areaId;
+
+    /**
+     * 计划类型(1 普通计划,2 按次计划)
+     */
+    private Integer planType;
+
+    /**
+     * 巡检周期(1 日,2 周,3 月,4 年)
+     */
+    private Integer planCycle;
+
+    /**
+     * 计划次数
+     */
+    private Integer planFrequency;
+
+    /**
+     * 每圈用时(分钟)
+     */
+    private Integer lapTime;
+
+    /**
+     * 两圈间隔时间(分钟)
+     */
+    private Integer intervalTime;
+
+    /**
+     * 计划描述
+     */
+    private String planDescribe;
+
+    /**
+     * 完成情况(百分比)
+     */
+    private Integer completion;
+
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
+    /**
+     * 创建人
+     */
+    private String creator;
+
+    /**
+     * 备用字段
+     */
+    private String alternateField;
+
+    /**
+     * 租户ID
+     */
+    private Integer tenantId;
+
+    /**
+     * 单位ID
+     */
+    private Integer companyId;
+
+    /**
+     * 计划名称
+     */
+    private String planName;
+
+    /**
+     * 计划状态(1执行中、2巡检结束合格、3巡检结束不合格 )
+     */
+    private Integer planStatus;
+
+    /**
+     * 已巡检地点数量
+     */
+    private Integer patrolledSiteCount;
+
+    /**
+     * 漏检地点数量
+     */
+    private Integer undetectedSiteCount;
+
+    /**
+     * 计划类型描述
+     */
+    private String planTypeDescribe;
+
+}