Przeglądaj źródła

refactor: 手动生成运行记录改为按部门查询上级计划

Zimo 2 dni temu
rodzic
commit
ad5e7c61d7

+ 4 - 4
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/iotoperationplan/IotOperationPlanController.java

@@ -83,11 +83,11 @@ public class IotOperationPlanController {
     }
 
     @PostMapping("/manual-generate")
-    @Operation(summary = "根据设备手动重新生成所在小部门当天的运行记录")
-    @Parameter(name = "deviceId", description = "设备编号", required = true)
+    @Operation(summary = "根据部门手动重新生成当天的运行记录")
+    @Parameter(name = "deptId", description = "部门编号", required = true)
     @PreAuthorize("@ss.hasPermission('rq:iot-operation-plan:create')")
-    public CommonResult<String> manualGenerateByDeviceId(@RequestParam("deviceId") Long deviceId) {
-        return success(iotOperationPlanService.manualGenerateByDeviceId(deviceId));
+    public CommonResult<String> manualGenerateByDeptId(@RequestParam("deptId") Long deptId) {
+        return success(iotOperationPlanService.manualGenerateByDeptId(deptId));
     }
 
     @DeleteMapping("/delete")

+ 3 - 3
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotoperationplan/IotOperationPlanService.java

@@ -55,11 +55,11 @@ public interface IotOperationPlanService {
     void updateInspectPlanStatus(Long id, Integer status);
 
     /**
-     * 根据设备手动重新生成设备所在小部门当天的运行记录。
+     * 根据部门手动重新生成当天的运行记录。
      *
-     * @param deviceId 用于定位小部门和上级运行计划的设备编号
+     * @param deptId 用于生成运行记录和查找上级运行计划的部门编号
      * @return 生成结果说明
      */
-    String manualGenerateByDeviceId(Long deviceId);
+    String manualGenerateByDeptId(Long deptId);
 
 }

+ 16 - 28
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotoperationplan/IotOperationPlanServiceImpl.java

@@ -2,11 +2,9 @@ package cn.iocoder.yudao.module.pms.service.iotoperationplan;
 
 import cn.iocoder.yudao.module.pms.constant.PmsConstants;
 import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
-import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
 import cn.iocoder.yudao.module.pms.dal.dataobject.iotoperationplandev.IotOperationPlanDevDO;
-import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotopeationfill.IotOpeationFillOrderMapper;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplandev.IotOperationPlanDevMapper;
@@ -36,8 +34,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 import cn.iocoder.yudao.module.pms.dal.mysql.iotoperationplan.IotOperationPlanMapper;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_DEVICE_NOT_EXISTS;
 import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_OPERATION_PLAN_NOT_EXISTS;
+import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.DEPT_NOT_FOUND;
 import static cn.iocoder.yudao.module.pms.framework.config.MultiThreadConfiguration.PMS_THREAD_POOL_TASK_EXECUTOR;
 
 
@@ -56,8 +54,6 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
     @Resource
     private IotOperationPlanDevMapper planDevMapper;
     @Resource
-    private IotDeviceMapper iotDeviceMapper;
-    @Resource
     private IotOpeationFillMapper iotOpeationFillMapper;
     @Resource
     private IotOpeationFillOrderMapper iotOpeationFillOrderMapper;
@@ -137,16 +133,10 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public String manualGenerateByDeviceId(Long deviceId) {
-        IotDeviceDO device = iotDeviceMapper.selectById(deviceId);
-        if (device == null || device.getDeptId() == null) {
-            throw exception(IOT_DEVICE_NOT_EXISTS);
-        }
-
-        Long deptId = device.getDeptId();
+    public String manualGenerateByDeptId(Long deptId) {
         DeptDO dept = deptService.getDeptNoPermission(deptId);
         if (dept == null) {
-            throw exception(IOT_DEVICE_NOT_EXISTS);
+            throw exception(DEPT_NOT_FOUND);
         }
 
         IotOperationPlanDO plan = findNearestEnabledPlan(dept);
@@ -157,33 +147,31 @@ public class IotOperationPlanServiceImpl implements IotOperationPlanService {
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime beginTime = LocalDate.now().atStartOfDay();
         LocalDateTime endTime = beginTime.plusDays(1);
-        boolean deviceGeneratedToday = !iotOpeationFillMapper
-                .selectOrderIdsByDeviceAndCreateTime(deviceId, beginTime, endTime).isEmpty();
+        List<Long> oldOrderIds = iotOpeationFillMapper
+                .selectOrderIdsByDeptAndCreateTime(deptId, beginTime, endTime);
 
-        // 已经生成过的设备允许重建当天记录;尚未生成时必须先到达计划生成时间。
-        if (!deviceGeneratedToday && now.isBefore(calculateNextCreateTime(plan))) {
+        // 已经生成过的部门允许重建当天记录;尚未生成时必须先到达计划生成时间。
+        if (oldOrderIds.isEmpty() && now.isBefore(calculateNextCreateTime(plan))) {
             return "未到运行记录生成时间,无需生成";
         }
-        if (!deviceGeneratedToday && !"sg".equals(device.getDeviceStatus())) {
-            return "当前设备不在施工状态,无需生成";
-        }
 
-        // 设备只是定位入口。重建时删除并重建它所在小部门当天的全部运行记录。
-        List<Long> oldOrderIds = iotOpeationFillMapper
-                .selectOrderIdsByDeptAndCreateTime(deptId, beginTime, endTime);
+        List<IotDeviceRespVO> constructionDevices = iotOpeationFillMapper
+                .getFillDevices2(Collections.singleton(deptId));
         Set<Long> runLogDeviceIds = new HashSet<>();
-        runLogDeviceIds.add(deviceId);
+        for (IotDeviceRespVO constructionDevice : constructionDevices) {
+            runLogDeviceIds.add(constructionDevice.getId());
+        }
         if (!oldOrderIds.isEmpty()) {
             runLogDeviceIds.addAll(iotOpeationFillMapper.selectDeviceIdsByOrderIds(oldOrderIds));
+        }
+        if (!runLogDeviceIds.isEmpty()) {
             iotOpeationFillMapper.deleteManualRunLogs(runLogDeviceIds, beginTime, endTime);
+        }
+        if (!oldOrderIds.isEmpty()) {
             iotOpeationFillMapper.logicalDeleteByOrderIds(oldOrderIds);
             iotOpeationFillMapper.logicalDeleteOrdersByIds(oldOrderIds);
-        } else {
-            iotOpeationFillMapper.deleteManualRunLogs(runLogDeviceIds, beginTime, endTime);
         }
 
-        List<IotDeviceRespVO> constructionDevices = iotOpeationFillMapper
-                .getFillDevices2(Collections.singleton(deptId));
         if (constructionDevices.isEmpty()) {
             return oldOrderIds.isEmpty()
                     ? "当前小部门没有可生成运行记录的施工设备"