|
@@ -0,0 +1,141 @@
|
|
|
+package com.rongwei.zhsw.system.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.rongwe.zhsw.system.domain.SwInspectionRouteDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwInspectionRoutePointDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwInspectionTaskDo;
|
|
|
+import com.rongwe.zhsw.system.domain.SwInspectionTaskPointDo;
|
|
|
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
|
|
|
+import com.rongwei.rwcommon.base.BaseDo;
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
+import com.rongwei.zhsw.system.dao.CommonBusinessDao;
|
|
|
+import com.rongwei.zhsw.system.service.RoutineInspectionService;
|
|
|
+import com.rongwei.zhsw.system.utils.SaveConstans;
|
|
|
+import com.rongwei.zhsw.system.utils.ZHSWCommonUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static com.rongwei.zhsw.system.utils.SaveConstans.NO_REMOVE_FLAG;
|
|
|
+import static com.rongwei.zhsw.system.utils.SaveConstans.RoutineInspection.STATUS.DISABLE;
|
|
|
+
|
|
|
+/**
|
|
|
+ * RoutineInspectionServiceImpl class
|
|
|
+ *
|
|
|
+ * @author XH
|
|
|
+ * @date 2025/04/18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class RoutineInspectionServiceImpl implements RoutineInspectionService {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(RoutineInspectionServiceImpl.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SwInspectionRoutePointServiceImpl swInspectionRoutePointService;
|
|
|
+ @Autowired
|
|
|
+ private SwInspectionRouteServiceImpl swInspectionRouteService;
|
|
|
+ @Autowired
|
|
|
+ private SwInspectionTaskServiceImpl swInspectionTaskService;
|
|
|
+ @Autowired
|
|
|
+ private SwInspectionTaskPointServiceImpl swInspectionTaskPointService;
|
|
|
+ @Autowired
|
|
|
+ private CommonBusinessDao commonBusinessDao;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R generateTask(List<String> ids) {
|
|
|
+ log.debug("手动生成任务的Id信息:{}", ids);
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ log.error("参数异常");
|
|
|
+ throw new CustomException("参数异常");
|
|
|
+ }
|
|
|
+ List<SwInspectionRouteDo> swInspectionRouteDos = swInspectionRouteService.getBaseMapper().selectBatchIds(ids);
|
|
|
+ if (swInspectionRouteDos.isEmpty()) {
|
|
|
+ log.error("无法获取对应的巡检路线");
|
|
|
+ throw new CustomException("巡检路线不存在或已删除");
|
|
|
+ }
|
|
|
+ if (swInspectionRouteDos.stream().anyMatch(data -> DISABLE.equals(data.getStatus()))) {
|
|
|
+ log.error("存在已停用的巡检路线");
|
|
|
+ throw new CustomException("存在已停用的巡检路线");
|
|
|
+ }
|
|
|
+ // 巡检路线
|
|
|
+ List<SwInspectionRoutePointDo> routePointDoList = swInspectionRoutePointService.list(new LambdaQueryWrapper<SwInspectionRoutePointDo>()
|
|
|
+ .eq(BaseDo::getDeleted, NO_REMOVE_FLAG)
|
|
|
+ .in(SwInspectionRoutePointDo::getInspectionrouteid, ids));
|
|
|
+
|
|
|
+ dataAsyncAndSave(swInspectionRouteDos, routePointDoList);
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void dataAsyncAndSave(List<SwInspectionRouteDo> swInspectionRouteDos,
|
|
|
+ List<SwInspectionRoutePointDo> routePointDoList) {
|
|
|
+ // 巡检路线对应别的巡检点
|
|
|
+ Map<String, List<SwInspectionRoutePointDo>> routePointDoMap = routePointDoList.stream().collect(Collectors.groupingBy(SwInspectionRoutePointDo::getInspectionrouteid));
|
|
|
+ List<SwInspectionRoutePointDo> currentRoutePointDos;
|
|
|
+
|
|
|
+ SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
+ SwInspectionTaskDo swInspectionTaskDo;
|
|
|
+ SwInspectionTaskPointDo swInspectionTaskPointDo;
|
|
|
+ LocalDateTime nowTime = LocalDateTime.now();
|
|
|
+ String dateStr = nowTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
|
|
+ List<SwInspectionTaskDo> taskSaveList = new ArrayList<>();
|
|
|
+ List<SwInspectionTaskPointDo> taskPointSaveList = new ArrayList<>();
|
|
|
+ for (SwInspectionRouteDo swInspectionRouteDo : swInspectionRouteDos) {
|
|
|
+ // 该任务需要生成的次数
|
|
|
+ Integer frequency = swInspectionRouteDo.getFrequency();
|
|
|
+ if (frequency == null || frequency < 0) {
|
|
|
+ frequency = 0;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < frequency; i++) {
|
|
|
+ swInspectionTaskDo = new SwInspectionTaskDo();
|
|
|
+ currentRoutePointDos = routePointDoMap.getOrDefault(swInspectionRouteDo.getId(), new ArrayList<>());
|
|
|
+ ZHSWCommonUtils.initModelGeneralParameters(swInspectionRouteDo, currentUser);
|
|
|
+ swInspectionTaskDo.setId(SecurityUtil.getUUID());
|
|
|
+ swInspectionTaskDo.setRoutenumber(swInspectionRouteDo.getRoutenumber());
|
|
|
+ swInspectionTaskDo.setRoutename(swInspectionRouteDo.getRoutename());
|
|
|
+ swInspectionTaskDo.setInspectionpointsnumber(currentRoutePointDos.size());
|
|
|
+ swInspectionTaskDo.setInspectionpersonnelid(swInspectionRouteDo.getInspectionpersonnelid());
|
|
|
+ swInspectionTaskDo.setInspectionpersonnelname(swInspectionRouteDo.getInspectionpersonnelname());
|
|
|
+ swInspectionTaskDo.setInspectionteam(swInspectionRouteDo.getInspectionteam());
|
|
|
+ String taskNumber = ZHSWCommonUtils.streamCodeGeneration(swInspectionTaskDo.getRoutenumber() + dateStr,
|
|
|
+ "@{date:yyyyMMdd}@{serialNumber:#00}", "date:yyyyMMdd");
|
|
|
+ swInspectionTaskDo.setTasknumber(taskNumber);
|
|
|
+ swInspectionTaskDo.setPlannedtimestart(nowTime);
|
|
|
+ swInspectionTaskDo.setPlannedtimeend(nowTime.with(LocalTime.of(23, 59, 59)));
|
|
|
+ swInspectionTaskDo.setInspectionstatus(SaveConstans.RoutineInspectionTask.STATUS.WAIT);
|
|
|
+ swInspectionTaskDo.setAttachments(swInspectionRouteDo.getAttachments());
|
|
|
+ swInspectionTaskDo.setInspectioncycleid(swInspectionRouteDo.getInspectioncycleid());
|
|
|
+ swInspectionTaskDo.setFrequency(swInspectionRouteDo.getFrequency());
|
|
|
+ swInspectionTaskDo.setInspectioncyclename(swInspectionRouteDo.getInspectioncyclename());
|
|
|
+ taskSaveList.add(swInspectionTaskDo);
|
|
|
+
|
|
|
+ // 获取路线下的巡检点信息
|
|
|
+ for (SwInspectionRoutePointDo swInspectionRoutePointDo : currentRoutePointDos) {
|
|
|
+ swInspectionTaskPointDo = new SwInspectionTaskPointDo();
|
|
|
+ ZHSWCommonUtils.initModelGeneralParameters(swInspectionTaskPointDo, currentUser);
|
|
|
+ swInspectionTaskPointDo.setId(SecurityUtil.getUUID());
|
|
|
+ swInspectionTaskPointDo.setCheckpointname(swInspectionRoutePointDo.getCheckpointname());
|
|
|
+ swInspectionTaskPointDo.setCheckpointposition(swInspectionRoutePointDo.getCheckpointposition());
|
|
|
+ swInspectionTaskPointDo.setInspectiontaskid(swInspectionTaskDo.getId());
|
|
|
+ swInspectionTaskPointDo.setInspectionroutepointid(swInspectionRoutePointDo.getId());
|
|
|
+ taskPointSaveList.add(swInspectionTaskPointDo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!taskSaveList.isEmpty()) {
|
|
|
+ swInspectionTaskService.saveBatch(taskSaveList);
|
|
|
+ }
|
|
|
+ if (!taskPointSaveList.isEmpty()) {
|
|
|
+ swInspectionTaskPointService.saveBatch(taskPointSaveList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|