Browse Source

手机端-巡检自检-巡检上报-提交

jichaobo 2 years ago
parent
commit
8fd8e31642

+ 15 - 4
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/AppPatrolInspectionController.java

@@ -4,11 +4,9 @@ package com.usky.fire.controller.web;
 import com.usky.common.core.bean.ApiResult;
 import com.usky.fire.service.PatrolInspectionPlanSonService;
 import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
+import com.usky.fire.service.vo.PlanRecordVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Map;
@@ -80,4 +78,17 @@ public class AppPatrolInspectionController {
                                                       @RequestParam(value = "siteNubmber") String siteNubmber) {
         return ApiResult.success(patrolInspectionPlanSonService.siteDetails(siteId, siteNubmber));
     }
+
+
+    /**
+     * 手机端-巡检自检-巡检上报-提交
+     *
+     * @param planRecordVo
+     * @return
+     */
+    @PostMapping("updatePlan")
+    public ApiResult<Void> updatePlan(@RequestBody PlanRecordVo planRecordVo) {
+        patrolInspectionPlanSonService.updatePlan(planRecordVo);
+        return ApiResult.success();
+    }
 }

+ 7 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/domain/PatrolInspectionPlanSiteSon.java

@@ -3,6 +3,8 @@ package com.usky.fire.domain;
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
 import java.io.Serializable;
+import java.time.LocalDateTime;
+
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
@@ -43,5 +45,10 @@ public class PatrolInspectionPlanSiteSon implements Serializable {
      */
     private Integer inspectionStatus;
 
+    /**
+     * 创建时间
+     */
+    private LocalDateTime createTime;
+
 
 }

+ 3 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/PatrolInspectionRecordMapper.java

@@ -1,7 +1,8 @@
 package com.usky.fire.mapper;
 
-import com.usky.fire.domain.PatrolInspectionRecord;
 import com.usky.common.mybatis.core.CrudMapper;
+import com.usky.fire.domain.PatrolInspectionRecord;
+import org.springframework.stereotype.Repository;
 
 /**
  * <p>
@@ -11,6 +12,7 @@ import com.usky.common.mybatis.core.CrudMapper;
  * @author JCB
  * @since 2022-07-21
  */
+@Repository
 public interface PatrolInspectionRecordMapper extends CrudMapper<PatrolInspectionRecord> {
 
 }

+ 17 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/PatrolInspectionPlanSonService.java

@@ -5,6 +5,7 @@ import com.usky.fire.domain.PatrolInspectionPlanSon;
 import com.usky.fire.service.vo.DataCountVo;
 import com.usky.fire.service.vo.PatrolInspectionContentVo;
 import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
+import com.usky.fire.service.vo.PlanRecordVo;
 
 import java.util.List;
 import java.util.Map;
@@ -58,6 +59,22 @@ public interface PatrolInspectionPlanSonService extends CrudService<PatrolInspec
     Map<String, Object> siteDetails(Integer siteId, String siteNubmber);
 
 
+    /**
+     * 手机端-巡检自检-巡检上报-提交
+     * @param planRecordVo
+     */
+    void updatePlan(PlanRecordVo planRecordVo);
+
+
+    /**
+     * 手机端-巡检自检-子计划巡检点位统计
+     *
+     * @param planSonId        子计划ID
+     * @param inspectionStatus 巡检状态(1 未巡检,2 已巡检)
+     * @return
+     */
+    Integer planSiteSonCount(Integer planSonId, Integer inspectionStatus);
+
     /**
      * 手机端-巡检自检-根据巡检地点ID查巡检内容
      *

+ 103 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionPlanSonServiceImpl.java

@@ -8,15 +8,20 @@ import com.usky.common.security.utils.SecurityUtils;
 import com.usky.fire.domain.*;
 import com.usky.fire.mapper.PatrolInspectionPlanMapper;
 import com.usky.fire.mapper.PatrolInspectionPlanSonMapper;
+import com.usky.fire.mapper.PatrolInspectionRecordMapper;
 import com.usky.fire.service.*;
+import com.usky.fire.service.util.OnlineMethod;
 import com.usky.fire.service.vo.DataCountVo;
 import com.usky.fire.service.vo.PatrolInspectionContentVo;
 import com.usky.fire.service.vo.PatrolInspectionPlanSonVo;
+import com.usky.fire.service.vo.PlanRecordVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -53,6 +58,18 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
     @Autowired
     private PatrolInspectionContentOptionService patrolInspectionContentOptionService;
 
+    @Autowired
+    private PatrolInspectionRecordMapper patrolInspectionRecordMapper;
+
+    @Autowired
+    private PatrolInspectionAreaService patrolInspectionAreaService;
+
+    @Autowired
+    private PatrolInspectionRecordOptionService patrolInspectionRecordOptionService;
+
+    @Autowired
+    private PatrolInspectionRecordPictureService patrolInspectionRecordPictureService;
+
     @Override
     public Map<String, Object> appPlanStatistics(Integer personnelId, String currentDate) {
         LambdaQueryWrapper<PatrolInspectionPlanSchedule> queryWrapper = Wrappers.lambdaQuery();
@@ -181,8 +198,93 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
         return map;
     }
 
-    public void updatePlan(){
+    @Override
+    @Transactional
+    public void updatePlan(PlanRecordVo planRecordVo) {
+        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(PatrolInspectionPlanSon::getId, planRecordVo.getPlanSonId());
+        List<PatrolInspectionPlanSon> planSonList = this.list(queryWrapper);
+        if (planSonList.size() <= 0) {
+            throw new BusinessException("计划不存在,可能已被删除,请联系管理人员");
+        }
+        LambdaQueryWrapper<PatrolInspectionArea> queryWrapperOne = Wrappers.lambdaQuery();
+        queryWrapperOne.select(PatrolInspectionArea::getId, PatrolInspectionArea::getAreaName)
+                .eq(PatrolInspectionArea::getId, planSonList.get(0).getAreaId());
+        List<PatrolInspectionArea> areaList = patrolInspectionAreaService.list(queryWrapperOne);
+
+        PatrolInspectionRecord patrolInspectionRecord = new PatrolInspectionRecord();
+        patrolInspectionRecord.setSiteNubmber(planRecordVo.getSiteNubmber());
+        patrolInspectionRecord.setSiteType(planRecordVo.getSiteType());
+        patrolInspectionRecord.setAreaName(areaList.get(0).getAreaName());
+        patrolInspectionRecord.setSiteName(planRecordVo.getSiteName());
+        patrolInspectionRecord.setName(SecurityUtils.getUsername());
+        patrolInspectionRecord.setPhone("人员表缺少");
+        patrolInspectionRecord.setPlanType(planSonList.get(0).getPlanType());
+        patrolInspectionRecord.setSiteStatus(planRecordVo.getSiteStatus());
+        patrolInspectionRecord.setLongitude(planRecordVo.getLongitude());
+        patrolInspectionRecord.setLatitude(planRecordVo.getLatitude());
+        String startDate = null;
+        String endDate = null;
+        if (planSonList.get(0).getPlanType() == 1) {
+            startDate = df1.format(planSonList.get(0).getInspectionDate()) + "T" + planSonList.get(0).getStartTime();
+            endDate = df1.format(planSonList.get(0).getInspectionDate()) + "T" + planSonList.get(0).getEndTime();
+        } else {
+            startDate = df1.format(planSonList.get(0).getStartDate()) + "T" + planSonList.get(0).getStartTime();
+            endDate = df1.format(planSonList.get(0).getEndDate()) + "T" + planSonList.get(0).getEndTime();
+        }
+        patrolInspectionRecord.setStartDate(LocalDateTime.parse(startDate));
+        patrolInspectionRecord.setEndDate(LocalDateTime.parse(endDate));
+        patrolInspectionRecord.setCreateTime(LocalDateTime.now());
+        patrolInspectionRecord.setPlanId(planSonList.get(0).getPlanId());
+        patrolInspectionRecord.setPlanSonId(planRecordVo.getPlanSonId());
+        patrolInspectionRecord.setSiteId(planRecordVo.getSiteId());
+        patrolInspectionRecord.setTenantId(SecurityUtils.getTenantId());
+        patrolInspectionRecord.setCompanyId(planRecordVo.getCompanyId());
+        patrolInspectionRecord.setCreator(SecurityUtils.getUsername());
+        patrolInspectionRecordMapper.insert(patrolInspectionRecord);
+        Integer recordId = patrolInspectionRecord.getId();
+        List<PatrolInspectionRecordPicture> recordPictureList = planRecordVo.getRecordPictureList();
+        List<PatrolInspectionRecordOption> recordOptionList = planRecordVo.getRecordOptionList();
+        for (int i = 0; i < recordPictureList.size(); i++) {
+            recordPictureList.get(i).setRecordId(recordId);
+            patrolInspectionRecordPictureService.save(recordPictureList.get(i));
+        }
+
+        for (int i = 0; i < recordOptionList.size(); i++) {
+            recordOptionList.get(i).setRecordId(recordId);
+            patrolInspectionRecordOptionService.save(recordOptionList.get(i));
+        }
 
+        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapperTwo = Wrappers.lambdaQuery();
+        queryWrapperTwo.eq(PatrolInspectionPlanSiteSon::getPlanId, planRecordVo.getPlanSonId())
+                .eq(PatrolInspectionPlanSiteSon::getSiteId, planRecordVo.getSiteId());
+        List<PatrolInspectionPlanSiteSon> planSiteSonList = patrolInspectionPlanSiteSonService.list(queryWrapperTwo);
+        PatrolInspectionPlanSiteSon planSiteSon = new PatrolInspectionPlanSiteSon();
+        planSiteSon.setId(planSiteSonList.get(0).getId());
+        planSiteSon.setInspectionStatus(2);
+        planSiteSon.setCreateTime(LocalDateTime.now());
+        patrolInspectionPlanSiteSonService.updateById(planSiteSon);
+        Integer patrolledCount = this.planSiteSonCount(planRecordVo.getPlanSonId(), 2);
+        Integer undetectedCount = this.planSiteSonCount(planRecordVo.getPlanSonId(), 1);
+        Integer siteCount = patrolledCount + undetectedCount;
+        String rad = OnlineMethod.myPercent(patrolledCount, siteCount).replace("%", "");
+        Double d = Double.parseDouble(rad); // 先转换成double类型
+        Integer completion = d.intValue(); // 再转换成int类型(会损失精度)
+        PatrolInspectionPlanSon planSon = new PatrolInspectionPlanSon();
+        planSon.setId(planRecordVo.getPlanSonId());
+        planSon.setCompletion(completion);
+        this.updateById(planSon);
+    }
+
+
+    @Override
+    public Integer planSiteSonCount(Integer planSonId, Integer inspectionStatus) {
+        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.eq(PatrolInspectionPlanSiteSon::getPlanId, planSonId)
+                .eq(PatrolInspectionPlanSiteSon::getInspectionStatus, inspectionStatus);
+        Integer planSiteSonCount = patrolInspectionPlanSiteSonService.count(queryWrapper);
+        return planSiteSonCount;
     }
 
 

+ 0 - 6
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/util/OnlineMethod.java

@@ -28,14 +28,8 @@ public class OnlineMethod {
         double baiy = y * 1.0;
         double baiz = z * 1.0;
         double fen = baiy / baiz;
-// NumberFormat nf = NumberFormat.getPercentInstance();注释掉的也是一种方法
-// nf.setMinimumFractionDigits( 2 ); 保留到小数点后几位
         DecimalFormat df1 = new DecimalFormat("##.00%");
-// ##.00%
-// 百分比格式,后面不足2位的用0补齐
-// baifenbi=nf.format(fen);
         baifenbi = df1.format(fen);
-//        System.out.println(baifenbi);
         return baifenbi;
     }
 

+ 13 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/vo/PlanRecordVo.java

@@ -2,12 +2,15 @@ package com.usky.fire.service.vo;
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableId;
+import com.usky.fire.domain.PatrolInspectionRecordOption;
+import com.usky.fire.domain.PatrolInspectionRecordPicture;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
 
 import java.io.Serializable;
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * <p>
@@ -125,4 +128,14 @@ public class PlanRecordVo implements Serializable {
      */
     private String creator;
 
+    /**
+     * 图片路径
+     */
+    private List<PatrolInspectionRecordPicture> recordPictureList;
+
+    /**
+     * 巡检内容选项
+     */
+    private List<PatrolInspectionRecordOption> recordOptionList;
+
 }

+ 1 - 0
service-fire/service-fire-biz/src/main/resources/mapper.fire/PatrolInspectionPlanSiteSonMapper.xml

@@ -8,6 +8,7 @@
         <result column="plan_id" property="planId" />
         <result column="site_id" property="siteId" />
         <result column="inspection_status" property="inspectionStatus" />
+        <result column="create_time" property="createTime" />
     </resultMap>
 
 </mapper>