Prechádzať zdrojové kódy

bugFix 解决巡检任务没有巡检点的问题

xiahan 3 mesiacov pred
rodič
commit
cb5b7892df

+ 3 - 1
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/RoutineInspectionServiceImpl.java

@@ -18,6 +18,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.time.LocalDateTime;
 import java.time.LocalTime;
@@ -76,6 +77,7 @@ public class RoutineInspectionServiceImpl implements RoutineInspectionService {
         return R.ok();
     }
 
+    @Transactional
     public void dataAsyncAndSave(List<SwInspectionRouteDo> swInspectionRouteDos,
                                  List<SwInspectionRoutePointDo> routePointDoList) {
         // 巡检路线对应别的巡检点
@@ -107,7 +109,7 @@ public class RoutineInspectionServiceImpl implements RoutineInspectionService {
                 swInspectionTaskDo.setInspectionpersonnelname(swInspectionRouteDo.getInspectionpersonnelname());
                 swInspectionTaskDo.setInspectionteam(swInspectionRouteDo.getInspectionteam());
                 String taskNumber = ZHSWCommonUtils.streamCodeGeneration(swInspectionTaskDo.getRoutenumber() + dateStr,
-                        "@{date:yyyyMMdd}@{serialNumber:#00}", "date:yyyyMMdd");
+                        swInspectionTaskDo.getRoutenumber() + "@{date:yyyyMMdd}@{serialNumber:#00}", "date:yyyyMMdd");
                 swInspectionTaskDo.setTasknumber(taskNumber);
                 swInspectionTaskDo.setPlannedtimestart(nowTime);
                 swInspectionTaskDo.setPlannedtimeend(nowTime.with(LocalTime.of(23, 59, 59)));

+ 18 - 8
zhsw-common/src/main/java/com/rongwei/zhsw/system/service/impl/ScheduledTaskServiceImpl.java

@@ -60,14 +60,24 @@ public class ScheduledTaskServiceImpl implements ScheduledTaskService {
         int dayOfMonth = now.getDayOfMonth();
         int currentMontLastDay = lastDate.getDayOfMonth();
         tenantDos.forEach(data -> {
-            ContextHolder.setValue("dsKey", data.getDskey());
-            List<SwInspectionRouteDo> routeList = getRouteList(weekValue, monthValue, dayOfMonth, currentMontLastDay);
-            log.debug("当前库:{}需要生成任务的数据有:{}条", data.getDskey(), routeList.size());
-            if (!routeList.isEmpty()) {
-                List<SwInspectionRoutePointDo> routePointDoList = swInspectionRoutePointService.getBaseMapper().selectBatchIds(routeList.stream().map(SwInspectionRouteDo::getId).collect(Collectors.toList()));
-                routineInspectionService.dataAsyncAndSave(routeList, routePointDoList);
+            try {
+                ContextHolder.setValue("dsKey", data.getDskey());
+                List<SwInspectionRouteDo> routeList = getRouteList(weekValue, monthValue, dayOfMonth, currentMontLastDay);
+                log.debug("当前库:{}需要生成任务的数据有:{}条", data.getDskey(), routeList.size());
+                if (!routeList.isEmpty()) {
+                    List<SwInspectionRoutePointDo> routePointDoList = swInspectionRoutePointService.
+                            list(new LambdaQueryWrapper<SwInspectionRoutePointDo>()
+                                    .eq(BaseDo::getDeleted, NO_REMOVE_FLAG)
+                                    .in(SwInspectionRoutePointDo::getInspectionrouteid,
+                                            routeList.stream().map(SwInspectionRouteDo::getId).collect(Collectors.toList())));
+                    routineInspectionService.dataAsyncAndSave(routeList, routePointDoList);
+                }
+            } catch (Exception e) {
+                log.error("当前库:{}生成巡检任务失败,失败原因为:{}", data.getDskey(), e.getMessage());
+            } finally {
+                ContextHolder.clear();
             }
-            ContextHolder.clear();
+
         });
         return R.ok();
     }
@@ -131,7 +141,7 @@ public class ScheduledTaskServiceImpl implements ScheduledTaskService {
         // 每月
         if ("month".equals(frequencys[0])) {
             int selectMonthDay = Integer.parseInt(frequencys[1]);
-            if(selectMonthDay==32){
+            if (selectMonthDay == 32) {
                 return true;
             }
             // 如果选择的日期比当前月份的最后一天还要大或者 当前日期和所选择的日期相同