فهرست منبع

Merge branch 'usky-zyj' of uskycloud/usky-modules into server-165

James 10 ماه پیش
والد
کامیت
814b64e9e5

+ 11 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/AppPatrolInspectionController.java

@@ -164,4 +164,15 @@ public class AppPatrolInspectionController {
         return ApiResult.success(patrolInspectionPlanSonService.recordOption(recordId, siteId));
     }
 
+    /**
+     * 巡检系统漏检数据到巡检异常记录表中
+     *
+     * @return
+     */
+    @PostMapping("addPatrolInspectionAbnormalData")
+    public ApiResult<Void> addPatrolInspectionAbnormalData(){
+        patrolInspectionPlanSonService.addPatrolInspectionAbnormalData();
+        return ApiResult.success();
+    }
+
 }

+ 11 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/controller/web/TaskController.java

@@ -7,6 +7,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.sql.SQLOutput;
+
 /**
  * @author JCB
  * @since 2022-08-08
@@ -38,6 +40,9 @@ public class TaskController {
     @Autowired
     private PatrolInspectionPlanService patrolInspectionPlanService;
 
+    @Autowired
+    private PatrolInspectionPlanSonService patrolInspectionPlanSonService;
+
     //    @Scheduled(cron = "0/5 * *  * * ?") // 间隔5秒执行
     @Scheduled(cron = "0 0/5 * * * ? ") // 间隔5分钟执行
     public void task() {
@@ -79,5 +84,11 @@ public class TaskController {
         patrolInspectionPlanService.addPatrolInspectionPlanSon();
     }
 
+    @Scheduled(cron = "0 5 * * * ?") //每个小时第五分钟执行
+    public void task6(){
+        System.out.println(Thread.currentThread().getName() + "巡检漏检数据同步到巡检异常记录表");
+        patrolInspectionPlanSonService.addPatrolInspectionAbnormalData();
+    }
+
 }
 

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

@@ -20,4 +20,6 @@ public interface PatrolInspectionPlanMapper extends CrudMapper<PatrolInspectionP
     int planSiteCount(@Param("personnelIdList") List<Integer> personnelIdList,
                       @Param("siteId") Integer siteId,
                       @Param("inspectionDate") String inspectionDate);
+
+    List<PatrolInspectionPlan> selectNoPlanList(@Param("planIdList") List<Integer> planIdList);
 }

+ 4 - 1
service-fire/service-fire-biz/src/main/java/com/usky/fire/mapper/PatrolInspectionPlanSonMapper.java

@@ -2,8 +2,11 @@ package com.usky.fire.mapper;
 
 import com.usky.fire.domain.PatrolInspectionPlanSon;
 import com.usky.common.mybatis.core.CrudMapper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -14,5 +17,5 @@ import org.springframework.stereotype.Repository;
  */
 @Repository
 public interface PatrolInspectionPlanSonMapper extends CrudMapper<PatrolInspectionPlanSon> {
-
+    List<PatrolInspectionPlanSon> selectInspectionPlanSonData(@Param("datetime1") String datetime1, @Param("datetime2") String datetime2);
 }

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

@@ -169,4 +169,11 @@ public interface PatrolInspectionPlanSonService extends CrudService<PatrolInspec
      * @return
      */
     List<Integer> planSonIdList(List<Integer> planSonSiteIdList, String startTime, String endTime);
+
+    /**
+     * 定时同步巡检系统漏检数据到巡检异常记录表中
+     *
+     * @return
+     */
+    void addPatrolInspectionAbnormalData();
 }

+ 20 - 2
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionAbnormalServiceImpl.java

@@ -2,6 +2,7 @@ package com.usky.fire.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -62,25 +63,42 @@ public class PatrolInspectionAbnormalServiceImpl extends AbstractCrudService<Pat
     @Autowired
     private PatrolInspectionContentOptionService contentOptionService;
 
+    @Autowired
+    private PatrolInspectionPersonnelService patrolInspectionPersonnelService;
+
     @Override
     public void addAbnormal(PatrolInspectionAbnormal patrolInspectionAbnormal) {
         DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
         LambdaQueryWrapper<PatrolInspectionPlanSon> queryWrapper = Wrappers.lambdaQuery();
         queryWrapper.eq(PatrolInspectionPlanSon::getId, patrolInspectionAbnormal.getPlanSonId());
         List<PatrolInspectionPlanSon> planSonList = patrolInspectionPlanSonMapper.selectList(queryWrapper);
+        if(CollectionUtils.isEmpty(planSonList)){
+            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);
+        if(areaList.size() <= 0){
+            throw new BusinessException("巡检区域不存在");
+        }
+
+        LambdaQueryWrapper<PatrolInspectionPersonnel> personnelQueryWrapper = Wrappers.lambdaQuery();
+        personnelQueryWrapper.eq(PatrolInspectionPersonnel::getId,planSonList.get(0).getPersonnelId())
+                .eq(PatrolInspectionPersonnel::getEnable,1);
+        List<PatrolInspectionPersonnel> inspectionPersonnelList = patrolInspectionPersonnelService.list(personnelQueryWrapper);
+        if(inspectionPersonnelList.size() <= 0){
+            throw new BusinessException("巡检人员信息不存在");
+        }
 
         PatrolInspectionAbnormal insertAbnormal = new PatrolInspectionAbnormal();
         insertAbnormal.setSiteNubmber(patrolInspectionAbnormal.getSiteNubmber());
         insertAbnormal.setSiteType(patrolInspectionAbnormal.getSiteType());
         insertAbnormal.setAreaName(areaList.get(0).getAreaName());
         insertAbnormal.setSiteName(patrolInspectionAbnormal.getSiteName());
-        insertAbnormal.setName(SecurityUtils.getLoginUser().getSysUser().getNickName());
-        insertAbnormal.setPhone(SecurityUtils.getLoginUser().getSysUser().getPhonenumber());
+        insertAbnormal.setName(inspectionPersonnelList.get(0).getFullName());
+        insertAbnormal.setPhone(inspectionPersonnelList.get(0).getPhoneNumber());
         insertAbnormal.setPlanType(planSonList.get(0).getPlanType());
         insertAbnormal.setSiteStatus(patrolInspectionAbnormal.getSiteStatus());
         insertAbnormal.setLongitude(patrolInspectionAbnormal.getLongitude());

+ 149 - 0
service-fire/service-fire-biz/src/main/java/com/usky/fire/service/impl/PatrolInspectionPlanSonServiceImpl.java

@@ -1,7 +1,9 @@
 package com.usky.fire.service.impl;
 
+import ch.qos.logback.core.pattern.FormatInfo;
 import cn.hutool.core.collection.CollectionUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.usky.common.core.exception.BusinessException;
 import com.usky.common.core.util.DateUtils;
@@ -43,6 +45,9 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
     @Autowired
     private PatrolInspectionPlanMapper patrolInspectionPlanMapper;
 
+    @Autowired
+    private PatrolInspectionPlanSonMapper patrolInspectionPlanSonMapper;
+
     @Autowired
     private PatrolInspectionPlanSiteSonService patrolInspectionPlanSiteSonService;
 
@@ -76,6 +81,9 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
     @Autowired
     private PatrolInspectionEventService patrolInspectionEventService;
 
+    @Autowired
+    private PatrolInspectionAbnormalService patrolInspectionAbnormalService;
+
     @Override
     public Map<String, Object> appPlanStatistics(String currentDate) {
         Integer planSonCount = 0;
@@ -346,6 +354,147 @@ public class PatrolInspectionPlanSonServiceImpl extends AbstractCrudService<Patr
         this.updateById(planSon);
     }
 
+    @Override
+    public void addPatrolInspectionAbnormalData(){
+        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        String datetime1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        String datetime2 = LocalDateTime.now().minusHours(1).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+
+        List<PatrolInspectionPlanSon> list = patrolInspectionPlanSonMapper.selectInspectionPlanSonData(datetime1,datetime2);
+        if(list.size() <=0){
+            throw new BusinessException("当前时间向前一小时没有漏检记录");
+        }
+        List<Integer> sonIdlist = new ArrayList<>();
+        for (int i = 0; i < list.size(); i++) {
+            sonIdlist.add(list.get(i).getId());
+        }
+        LambdaQueryWrapper<PatrolInspectionPlanSiteSon> queryWrapper = Wrappers.lambdaQuery();
+        queryWrapper.in(PatrolInspectionPlanSiteSon::getPlanId,sonIdlist)
+                .eq(PatrolInspectionPlanSiteSon::getInspectionStatus,1);
+        List<PatrolInspectionPlanSiteSon> siteSonList = patrolInspectionPlanSiteSonService.list(queryWrapper);
+        if(CollectionUtils.isNotEmpty(siteSonList)){
+            List<Integer> siteIdList = new ArrayList<>();
+            List<Integer> noSonIdList = new ArrayList<>();
+            for (int i = 0; i < siteSonList.size(); i++) {
+                siteIdList.add(siteSonList.get(i).getSiteId());
+                noSonIdList.add(siteSonList.get(i).getPlanId());
+            }
+            //获取巡检地点
+            LambdaQueryWrapper<PatrolInspectionSite> queryWrapper1 = Wrappers.lambdaQuery();
+            queryWrapper1.in(PatrolInspectionSite::getId,siteIdList)
+                    .eq(PatrolInspectionSite::getEnable,1);
+            List<PatrolInspectionSite> siteList = patrolInspectionSiteService.list(queryWrapper1);
+            if(siteList.size() <= 0){
+                throw new BusinessException("查询巡检地点记录为空");
+            }
+            //获取巡检子计划
+            LambdaQueryWrapper<PatrolInspectionPlanSon> planSonQueryWrapper = Wrappers.lambdaQuery();
+            planSonQueryWrapper.in(PatrolInspectionPlanSon::getId,noSonIdList);
+            List<PatrolInspectionPlanSon> noPlanSonList = this.list(planSonQueryWrapper);
+            List<Integer> planIdList = new ArrayList<>();
+            List<Integer> personnelList = new ArrayList<>();
+            List<Integer> areaList = new ArrayList<>();
+            for (int i = 0; i < noPlanSonList.size(); i++) {
+                planIdList.add(noPlanSonList.get(i).getPlanId());
+                personnelList.add(noPlanSonList.get(i).getPersonnelId());
+                areaList.add(noPlanSonList.get(i).getAreaId());
+            }
+
+            //获取巡检计划
+            List<PatrolInspectionPlan> noPlanIdList = patrolInspectionPlanMapper.selectNoPlanList(planIdList);
+            //获取巡检人员
+            LambdaQueryWrapper<PatrolInspectionPersonnel> personnelQueryWrapper = Wrappers.lambdaQuery();
+            personnelQueryWrapper.in(PatrolInspectionPersonnel::getId,personnelList)
+                    .eq(PatrolInspectionPersonnel::getEnable,1);
+            List<PatrolInspectionPersonnel> inspectionPersonnelList = patrolInspectionPersonnelService.list(personnelQueryWrapper);
+            if(inspectionPersonnelList.size() <= 0){
+                throw new BusinessException("巡检人员信息不存在");
+            }
+            //获取巡检区域
+            LambdaQueryWrapper<PatrolInspectionArea> queryWrapperOne = Wrappers.lambdaQuery();
+            queryWrapperOne.in(PatrolInspectionArea::getId, areaList)
+                    .eq(PatrolInspectionArea::getEnable,1);
+            List<PatrolInspectionArea> areaInfoList = patrolInspectionAreaService.list(queryWrapperOne);
+            if(areaInfoList.size() <= 0){
+                throw new BusinessException("巡检区域不存在");
+            }
+
+            for (int i = 0; i < siteSonList.size(); i++) {
+                PatrolInspectionAbnormal patrolInspectionAbnormal = new PatrolInspectionAbnormal();
+                Integer siteId = siteSonList.get(i).getSiteId();
+                Integer planSonId = siteSonList.get(i).getPlanId();
+                for (int j = 0; j < siteList.size(); j++) {
+                    if(siteId.equals(siteList.get(j).getId())){
+                        patrolInspectionAbnormal.setSiteNubmber(siteList.get(j).getSiteNubmber());
+                        patrolInspectionAbnormal.setSiteType(siteList.get(j).getSiteType());
+                        patrolInspectionAbnormal.setSiteName(siteList.get(j).getSiteName());
+                        patrolInspectionAbnormal.setLongitude(siteList.get(j).getLongitude());
+                        patrolInspectionAbnormal.setLatitude(siteList.get(j).getLatitude());
+                        patrolInspectionAbnormal.setSiteId(siteList.get(j).getId());
+                        patrolInspectionAbnormal.setCompanyId(siteList.get(j).getCompanyId());
+                        break;
+                    }
+                }
+
+                for (int j = 0; j < noPlanSonList.size(); j++) {
+                    if(planSonId.equals(noPlanSonList.get(j).getId())){
+                        patrolInspectionAbnormal.setPlanId(noPlanSonList.get(j).getPlanId());
+                        patrolInspectionAbnormal.setPlanSonId(noPlanSonList.get(j).getId());
+                        patrolInspectionAbnormal.setTenantId(noPlanSonList.get(j).getTenantId());
+                        patrolInspectionAbnormal.setPlanType(noPlanSonList.get(j).getPlanType());
+                        Integer planType = noPlanSonList.get(j).getPlanType();
+                        String startDate = null;
+                        String endDate = null;
+                        if (planType.equals(1)) {
+                            startDate = df1.format(noPlanSonList.get(j).getInspectionDate()) + "T" + noPlanSonList.get(j).getStartTime();
+                            endDate = df1.format(noPlanSonList.get(j).getInspectionDate()) + "T" + noPlanSonList.get(j).getEndTime();
+                        } else {
+                            startDate = df1.format(noPlanSonList.get(j).getStartDate()) + "T" + noPlanSonList.get(j).getStartTime();
+                            endDate = df1.format(noPlanSonList.get(j).getEndDate()) + "T" + noPlanSonList.get(j).getEndTime();
+                        }
+
+                        patrolInspectionAbnormal.setStartDate(LocalDateTime.parse(startDate));
+                        patrolInspectionAbnormal.setEndDate(LocalDateTime.parse(endDate));
+
+                        Integer noAreaId = noPlanSonList.get(j).getAreaId();
+                        for (int k = 0; k < areaInfoList.size(); k++) {
+                            if(noAreaId.equals(areaInfoList.get(k).getId())){
+                                patrolInspectionAbnormal.setAreaName(areaInfoList.get(k).getAreaName());
+                                break;
+                            }
+                        }
+                        Integer noPersonnelId = noPlanSonList.get(j).getPersonnelId();
+                        for (int k = 0; k < inspectionPersonnelList.size(); k++) {
+                            if(noPersonnelId.equals(inspectionPersonnelList.get(k).getId())){
+                                patrolInspectionAbnormal.setName(inspectionPersonnelList.get(k).getFullName());
+                                patrolInspectionAbnormal.setPhone(inspectionPersonnelList.get(k).getPhoneNumber());
+                                break;
+                            }
+                        }
+                        Integer planId = noPlanSonList.get(j).getPlanId();
+                        for (int k = 0; k < noPlanIdList.size(); k++) {
+                            if(planId.equals(noPlanIdList.get(k).getId())){
+                                patrolInspectionAbnormal.setRouteId(noPlanIdList.get(k).getRouteId());
+                                break;
+                            }
+                        }
+
+                        break;
+                    }
+                }
+                patrolInspectionAbnormal.setAbnormalStatus(1);
+                patrolInspectionAbnormal.setCreateTime(LocalDateTime.now());
+                patrolInspectionAbnormal.setCreator("YT_admin");
+
+
+                patrolInspectionAbnormalService.save(patrolInspectionAbnormal);
+
+            }
+
+        }
+
+    }
+
 
     @Override
     public List<PatrolInspectionSiteVo> planSonSiteDetails(Integer planSonId) {

+ 12 - 0
service-fire/service-fire-biz/src/main/resources/mapper/fire/PatrolInspectionPlanMapper.xml

@@ -39,4 +39,16 @@
             </foreach>
         </where>
     </select>
+    <select id="selectNoPlanList" resultType="com.usky.fire.domain.PatrolInspectionPlan">
+        select
+        *
+        from patrol_inspection_plan
+        <where>
+            enable = 1
+            and id in
+            <foreach item="item" collection="planIdList" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </where>
+    </select>
 </mapper>

+ 10 - 0
service-fire/service-fire-biz/src/main/resources/mapper/fire/PatrolInspectionPlanSonMapper.xml

@@ -27,4 +27,14 @@
         <result column="company_id" property="companyId" />
     </resultMap>
 
+    <select id="selectInspectionPlanSonData" resultType="com.usky.fire.domain.PatrolInspectionPlanSon">
+        select
+        *
+        from patrol_inspection_plan_son
+        <where>
+            and concat(inspection_date,' ',end_time) &lt; #{datetime1}
+            and CONCAT(inspection_date,' ',end_time) > #{datetime2}
+        </where>
+    </select>
+
 </mapper>