Эх сурвалжийг харах

pms 日报 校验 施工队伍 运行记录生成时间必填

zhangcl 3 долоо хоног өмнө
parent
commit
975e878f87

+ 3 - 0
yudao-module-pms/yudao-module-pms-api/src/main/java/cn/iocoder/yudao/module/pms/enums/ErrorCodeConstant.java

@@ -72,6 +72,7 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_MATERIAL_REQUISITION_DETAIL_NOT_EXISTS = new ErrorCode(155, "PMS 物料领用明细不存在");
     ErrorCode IOT_PROJECT_INFO_NOT_EXISTS = new ErrorCode(152, "项目信息不存在");
     ErrorCode IOT_PROJECT_TASK_NOT_EXISTS = new ErrorCode(153, "该任务不存在");
+    ErrorCode IOT_PROJECT_TASK_NOT_RELATED = new ErrorCode(264, "当前部门没有关联项目任务");
     ErrorCode PRODUCT_EXITS_CHILDREN = new ErrorCode(1_002_004_003, "存在子分类,无法删除");
     ErrorCode INSPECT_DEVICE_CHANGE = new ErrorCode(154, "设备已调拨");
     ErrorCode IOT_APP_NOT_EXISTS = new ErrorCode(155, "app版本不存在");
@@ -86,4 +87,6 @@ public interface ErrorCodeConstant{
     ErrorCode IOT_DAILY_REPORT_ATTRS_NOT_EXISTS = new ErrorCode(261, "日报扩展模板属性不存在");
     ErrorCode IOT_PROJECT_DAILY_REPORT_NOT_EXISTS = new ErrorCode(262, "项目日报不存在");
     ErrorCode IOT_RH_DAILY_REPORT_NOT_EXISTS = new ErrorCode(263, "瑞恒日报不存在");
+    ErrorCode IOT_RH_DAILY_REPORT_NO_DATE = new ErrorCode(265, "未传递运行记录生成日期");
+    ErrorCode IOT_RH_DAILY_REPORT_NO_DEPT = new ErrorCode(266, "未传递运行记录所属部门");
 }

+ 108 - 106
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotrhdailyreport/IotRhDailyReportServiceImpl.java

@@ -34,14 +34,12 @@ import javax.annotation.Resource;
 import java.lang.reflect.Type;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.time.Duration;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicReference;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_PROJECT_TASK_NOT_EXISTS;
-import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.IOT_RH_DAILY_REPORT_NOT_EXISTS;
+import static cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant.*;
 
 /**
  * 瑞恒日报 Service 实现类
@@ -76,123 +74,127 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
         IotRhDailyReportDO iotRhDailyReport = BeanUtils.toBean(createReqVO, IotRhDailyReportDO.class);
         LocalDateTime reportDate = createReqVO.getFillOrderCreateTime();
         if (ObjUtil.isEmpty(reportDate)) {
-            throw exception(IOT_RH_DAILY_REPORT_NOT_EXISTS);
+            throw exception(IOT_RH_DAILY_REPORT_NO_DATE);
+        }
+        if (ObjUtil.isEmpty(createReqVO.getDeptId())) {
+            throw exception(IOT_RH_DAILY_REPORT_NO_DEPT);
         }
         // 根据日报的 施工队伍 deptId 查询队伍所在的 项目 任务
         // 根据日报的施工状态 更新 对应任务的 状态
-        if (ObjUtil.isNotEmpty(createReqVO.getDeptId())) {
-            Long taskId = Long.MIN_VALUE;
-            Set<Long> deviceIds = new HashSet<>();
-            IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
-            reqVO.setDeptId(createReqVO.getDeptId());
-            // 查询包含当前日报施工队伍的任务
-            List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
-            if (CollUtil.isNotEmpty(tasks)) {
-                IotProjectTaskDO task = tasks.get(0);
-                // 暂时只考虑1个施工队伍只属于1个任务
-                iotRhDailyReport.setProjectId(task.getProjectId());
-                iotRhDailyReport.setTaskId(task.getId());
-                taskId = task.getId();
-                // 根据日报状态 查询 日报所属任务的状态
-                if (ObjUtil.isNotEmpty(createReqVO.getConstructionStatus())) {
-                    task.setStatus(createReqVO.getConstructionStatus());
-                    // 更新任务状态
-                    iotProjectTaskMapper.updateById(task);
-                }
-                // 查询任务的设备列表
-                deviceIds = task.getDeviceIds();
+        Long taskId = Long.MIN_VALUE;
+        Set<Long> deviceIds = new HashSet<>();
+        IotProjectTaskPageReqVO reqVO = new IotProjectTaskPageReqVO();
+        reqVO.setDeptId(createReqVO.getDeptId());
+        // 查询包含当前日报施工队伍的任务
+        List<IotProjectTaskDO> tasks = iotProjectTaskMapper.selectList(reqVO);
+        if (CollUtil.isNotEmpty(tasks)) {
+            IotProjectTaskDO task = tasks.get(0);
+            // 暂时只考虑1个施工队伍只属于1个任务
+            iotRhDailyReport.setProjectId(task.getProjectId());
+            iotRhDailyReport.setTaskId(task.getId());
+            taskId = task.getId();
+            // 根据日报状态 查询 日报所属任务的状态
+            if (ObjUtil.isNotEmpty(createReqVO.getConstructionStatus())) {
+                task.setStatus(createReqVO.getConstructionStatus());
+                // 更新任务状态
+                iotProjectTaskMapper.updateById(task);
             }
+            // 查询任务的设备列表
+            deviceIds = task.getDeviceIds();
+        } else {
+            // 当前队伍没有关联任务 不生成日报
+            throw exception(IOT_PROJECT_TASK_NOT_RELATED);
+        }
 
-            // 查询当前任务下关联的所有设备 查询这些设备的当日注气量 进而计算累计注气量
-            IotDevicePageReqVO deptDeviceReqVO = new IotDevicePageReqVO();
-            deptDeviceReqVO.setDeptId(createReqVO.getDeptId());
-            List<IotDeviceDO> deptDevices = iotDeviceMapper.selectList(deptDeviceReqVO);
-            Set<String> deviceCodes = new HashSet<>();
-            if (CollUtil.isNotEmpty(deptDevices)) {
-                deptDevices.forEach(device -> {
-                    deviceCodes.add(device.getDeviceCode());
+        // 查询当前任务下关联的所有设备 查询这些设备的当日注气量 进而计算累计注气量
+        IotDevicePageReqVO deptDeviceReqVO = new IotDevicePageReqVO();
+        deptDeviceReqVO.setDeptId(createReqVO.getDeptId());
+        List<IotDeviceDO> deptDevices = iotDeviceMapper.selectList(deptDeviceReqVO);
+        Set<String> deviceCodes = new HashSet<>();
+        if (CollUtil.isNotEmpty(deptDevices)) {
+            deptDevices.forEach(device -> {
+                deviceCodes.add(device.getDeviceCode());
+            });
+            // 查询当前小队在运行记录填报结果表中 生产日报虚拟设备id 查询当年的日报
+            // 然后根据 虚拟设备id 在 rq_iot_device_run_log 表中查询 日报中填写的 当日注气量
+            List<IotOpeationFillDO> reports = iotOpeationFillMapper.selectReportsByYear(createReqVO.getDeptId(), LocalDateTime.now().getYear());
+            Set<Long> reportDeviceIds = new HashSet<>();
+            if (CollUtil.isNotEmpty(reports)) {
+                reports.forEach(report -> {
+                    reportDeviceIds.add(report.getDeviceId());
                 });
-                // 查询当前小队在运行记录填报结果表中 生产日报虚拟设备id 查询当年的日报
-                // 然后根据 虚拟设备id 在 rq_iot_device_run_log 表中查询 日报中填写的 当日注气量
-                List<IotOpeationFillDO> reports = iotOpeationFillMapper.selectReportsByYear(createReqVO.getDeptId(), LocalDateTime.now().getYear());
-                Set<Long> reportDeviceIds = new HashSet<>();
-                if (CollUtil.isNotEmpty(reports)) {
-                    reports.forEach(report -> {
-                        reportDeviceIds.add(report.getDeviceId());
-                    });
-                    // 累计注气量
-                    BigDecimal currentYearFillContentSum = iotDeviceRunLogMapper.selectCurrentYearFillContentSum(createReqVO.getDeptId(), reportDeviceIds);
-                    iotRhDailyReport.setTotalGasInjection(currentYearFillContentSum);
-                }
+                // 累计注气量
+                BigDecimal currentYearFillContentSum = iotDeviceRunLogMapper.selectCurrentYearFillContentSum(createReqVO.getDeptId(), reportDeviceIds);
+                iotRhDailyReport.setTotalGasInjection(currentYearFillContentSum);
             }
+        }
 
-            BigDecimal capacity = queryCapacity(createReqVO.getDeptId());
-            // 计算运行时效 当日注气量/产能
-            if (ObjUtil.isNotEmpty(createReqVO.getDailyGasInjection()) && (capacity.compareTo(BigDecimal.ZERO)>0)) {
-                // 将当日注气量单位 换算成 万方
-                // 将当日注气量单位由"方"换算成"万方"
-                iotRhDailyReport.setTransitTime(createReqVO.getDailyGasInjection().divide(capacity, 4, RoundingMode.HALF_UP));
-            }
+        BigDecimal capacity = queryCapacity(createReqVO.getDeptId());
+        // 计算运行时效 当日注气量/产能
+        if (ObjUtil.isNotEmpty(createReqVO.getDailyGasInjection()) && (capacity.compareTo(BigDecimal.ZERO)>0)) {
+            // 将当日注气量单位 换算成 万方
+            // 将当日注气量单位由"方"换算成"万方"
+            iotRhDailyReport.setTransitTime(createReqVO.getDailyGasInjection().divide(capacity, 4, RoundingMode.HALF_UP));
+        }
 
-            // 查询当前日报所属任务关联的设备 更新设备状态
-            /* if (CollUtil.isNotEmpty(deviceIds)) {
-                // 查询当前任务下关联的所有设备
-                IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
-                // deviceReqVO.setDeptId(createReqVO.getDeptId());
-                deviceReqVO.setDeviceIds(new ArrayList<>(deviceIds));
-                List<IotDeviceDO> devices = iotDeviceMapper.selectList(deviceReqVO);
-                if (CollUtil.isNotEmpty(devices)) {
-                    AtomicReference<String> deviceNewStatus = new AtomicReference<>(StrUtil.EMPTY);
-                    // 日报状态 与 设备状态 对应关系
-                    // 动迁 施工 现场待命/驻地待命(待命) pms_device_status
-                    List<DictDataDO> dictDatas = dictDataService.getDictDataListByDictType("constructionStatus");
-                    AtomicReference<String> dailyDictLabel = new AtomicReference<>(StrUtil.EMPTY);
-                    List<DictDataDO> deviceDictDatas = dictDataService.getDictDataListByDictType("pms_device_status");
-                    if (CollUtil.isNotEmpty(dictDatas)) {
-                        dictDatas.forEach(data -> {
-                            if (createReqVO.getConstructionStatus().equals(Integer.valueOf(data.getValue()))) {
-                                dailyDictLabel.set(data.getLabel());
+        // 查询当前日报所属任务关联的设备 更新设备状态
+        /* if (CollUtil.isNotEmpty(deviceIds)) {
+            // 查询当前任务下关联的所有设备
+            IotDevicePageReqVO deviceReqVO = new IotDevicePageReqVO();
+            // deviceReqVO.setDeptId(createReqVO.getDeptId());
+            deviceReqVO.setDeviceIds(new ArrayList<>(deviceIds));
+            List<IotDeviceDO> devices = iotDeviceMapper.selectList(deviceReqVO);
+            if (CollUtil.isNotEmpty(devices)) {
+                AtomicReference<String> deviceNewStatus = new AtomicReference<>(StrUtil.EMPTY);
+                // 日报状态 与 设备状态 对应关系
+                // 动迁 施工 现场待命/驻地待命(待命) pms_device_status
+                List<DictDataDO> dictDatas = dictDataService.getDictDataListByDictType("constructionStatus");
+                AtomicReference<String> dailyDictLabel = new AtomicReference<>(StrUtil.EMPTY);
+                List<DictDataDO> deviceDictDatas = dictDataService.getDictDataListByDictType("pms_device_status");
+                if (CollUtil.isNotEmpty(dictDatas)) {
+                    dictDatas.forEach(data -> {
+                        if (createReqVO.getConstructionStatus().equals(Integer.valueOf(data.getValue()))) {
+                            dailyDictLabel.set(data.getLabel());
+                        }
+                    });
+                    if (CollUtil.isNotEmpty(deviceDictDatas)) {
+                        deviceDictDatas.forEach(data -> {
+                            if (dailyDictLabel.equals(data.getLabel())) {
+                                // 动迁 施工
+                                deviceNewStatus.set(data.getValue());
+                            }
+                            if (data.getLabel().contains(dailyDictLabel.get())) {
+                                // 现场待命/驻地待命(待命)
+                                deviceNewStatus.set(data.getValue());
                             }
                         });
-                        if (CollUtil.isNotEmpty(deviceDictDatas)) {
-                            deviceDictDatas.forEach(data -> {
-                                if (dailyDictLabel.equals(data.getLabel())) {
-                                    // 动迁 施工
-                                    deviceNewStatus.set(data.getValue());
-                                }
-                                if (data.getLabel().contains(dailyDictLabel.get())) {
-                                    // 现场待命/驻地待命(待命)
-                                    deviceNewStatus.set(data.getValue());
-                                }
-                            });
-                        }
                     }
-                    // 批量更新设备状态
-                    devices.forEach(device -> {
-                        device.setDeviceStatus(deviceNewStatus.get());
-                    });
-                    iotDeviceMapper.updateBatch(devices);
                 }
-            } */
-
-            // 当天如果已经有此小队的记录 新增 当天如果没有此小队的日报记录 修改
-            // deptId - taskId - createTime(yyyy-MM-dd) 确定唯一一条记录 不能使用 LocalDateTime.now() 来查询,应该使用 运行记录工单的创建日期查询
-            IotRhDailyReportDO existReport = iotRhDailyReportMapper.selectExistReport(createReqVO.getDeptId(), taskId, reportDate);
-            if (ObjUtil.isEmpty(existReport)) {
-                // 今天下午4点
-                LocalDateTime today4pm = reportDate.withHour(16).withMinute(0).withSecond(0).withNano(0);
-                // 昨天下午4点
-                LocalDateTime yesterday4pm = today4pm.minusDays(1);
-                iotRhDailyReport.setConstructionStartDate(yesterday4pm);
-                iotRhDailyReport.setConstructionEndDate(today4pm);
-                iotRhDailyReport.setCreateTime(reportDate);
-                iotRhDailyReport.setUpdateTime(reportDate);
-                iotRhDailyReportMapper.insert(iotRhDailyReport);
-            } else {
-                // 修改现有记录
-                iotRhDailyReport.setId(existReport.getId());
-                iotRhDailyReportMapper.updateById(iotRhDailyReport);
+                // 批量更新设备状态
+                devices.forEach(device -> {
+                    device.setDeviceStatus(deviceNewStatus.get());
+                });
+                iotDeviceMapper.updateBatch(devices);
             }
+        } */
+
+        // 当天如果已经有此小队的记录 新增 当天如果没有此小队的日报记录 修改
+        // deptId - taskId - createTime(yyyy-MM-dd) 确定唯一一条记录 不能使用 LocalDateTime.now() 来查询,应该使用 运行记录工单的创建日期查询
+        IotRhDailyReportDO existReport = iotRhDailyReportMapper.selectExistReport(createReqVO.getDeptId(), taskId, reportDate);
+        if (ObjUtil.isEmpty(existReport)) {
+            // 今天下午4点
+            LocalDateTime today4pm = reportDate.withHour(16).withMinute(0).withSecond(0).withNano(0);
+            // 昨天下午4点
+            LocalDateTime yesterday4pm = today4pm.minusDays(1);
+            iotRhDailyReport.setConstructionStartDate(yesterday4pm);
+            iotRhDailyReport.setConstructionEndDate(today4pm);
+            iotRhDailyReport.setCreateTime(reportDate);
+            iotRhDailyReport.setUpdateTime(reportDate);
+            iotRhDailyReportMapper.insert(iotRhDailyReport);
+        } else {
+            // 修改现有记录
+            iotRhDailyReport.setId(existReport.getId());
+            iotRhDailyReportMapper.updateById(iotRhDailyReport);
         }
         // 返回
         return iotRhDailyReport.getId();