Bladeren bron

Merge remote-tracking branch 'origin/master'

lipenghui 1 week geleden
bovenliggende
commit
34e0fc50ec

+ 108 - 184
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/IotOperationPlanJob.java

@@ -81,15 +81,9 @@ public class IotOperationPlanJob implements JobHandler {
     @Override
     public String execute(String param) throws Exception {
         TenantContextHolder.setIgnore(true);
-
-
         //1、查询开启,非删除状态运行计划
         List<IotOperationPlanDO> planList = planMapper.getPlanList();
-
         if(planList.size()>0){
-
-
-
             for (IotOperationPlanDO planDO:planList) {
                 if (planDO.getLastCreateTime()==null&& Objects.nonNull(planDO.getBeginCreateTime())) {
                     //当首次执行时间大于当前时间
@@ -98,97 +92,48 @@ public class IotOperationPlanJob implements JobHandler {
                                 planDO.getBeginCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
                                         .toInstant()                    // 转为 Instant(时间戳)
                         );
-
-
-                        Set<Long> idList = new HashSet<>();
-                        if(Objects.nonNull(planDO.getDeptId())){
-                            idList =  deptService.getChildDeptIdListFromCache(planDO.getDeptId());
-                            idList.add(planDO.getDeptId());
-                        }
-
-
-                        //2、根据计划获取设备ID
-                        List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
-
-                        if(devList.size()>0){
-                            List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
-                            //3、根据设备ID生成主表数据
-                            List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
-                            List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
-
-                            for (IotOpeationFillDO pd:pdList) {
-
-                                IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
-
-                                fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
-                                fillDO.setDeptId(pd.getDeptId());
-                                fillDO.setOrderStatus(0);
-                                fillDO.setCreateTime(LocalDateTime.now());
-                                fillDO.setUserName(pd.getUserName());
-                                fillDO.setUserId(pd.getUserId());
-                                fillDO.setMobile(pd.getMobile());
-                                orderList.add(fillDO);
-
-                            }
-
-                            deal(planDO, date,devIdList,orderList);
-                        }
-
-
+                        extractedOrder(planDO, date);
                     }
                 } else {
                     Date lastdate = Date.from(
                             planDO.getLastCreateTime().atZone(ZoneId.systemDefault()) // 使用系统默认时区
                                     .toInstant()                    // 转为 Instant(时间戳)
                     );
-
-
-
-                    Set<Long> idList = new HashSet<>();
-                    if(Objects.nonNull(planDO.getDeptId())){
-                        idList =  deptService.getChildDeptIdListFromCache(planDO.getDeptId());
-                        idList.add(planDO.getDeptId());
-                    }
-
-
-                    //2、根据计划获取设备ID
-                    List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
-                    if(devList.size()>0){
-                        List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
-                        //3、根据设备ID生成主表数据
-                        List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
-                        List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
-
-                        for (IotOpeationFillDO pd:pdList) {
-
-                            IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
-
-                            fillDO.setOrderName(pd.getOrgName()+"/"+LocalDate.now()+"运行记录填报");
-                            fillDO.setDeptId(pd.getDeptId());
-                            fillDO.setOrderStatus(0);
-                            fillDO.setCreateTime(LocalDateTime.now());
-                            fillDO.setUserName(pd.getUserName());
-                            fillDO.setUserId(pd.getUserId());
-                            fillDO.setMobile(pd.getMobile());
-                            orderList.add(fillDO);
-
-                        }
-
-
-                        deal(planDO, lastdate,devIdList,orderList);
-                    }
-
+                    extractedOrder(planDO, lastdate);
                 }
             }
-
-
-
         }
-
-
         return "创建成功";
     }
 
+    private void extractedOrder(IotOperationPlanDO planDO, Date date) {
+        Set<Long> idList = new HashSet<>();
+        if(Objects.nonNull(planDO.getDeptId())){
+            idList =  deptService.getChildDeptIdListFromCache(planDO.getDeptId());
+            idList.add(planDO.getDeptId());
+        }
+        //2、根据计划获取设备ID
+        List<IotDeviceRespVO> devList = iotOpeationFillMapper.getFillDevices2(idList);
+        if(devList.size()>0){
+            List<Long> devIdList= devList.stream().map(IotDeviceRespVO::getId).collect(Collectors.toList());
+            //3、根据设备ID生成主表数据
+            List<IotOpeationFillOrderDO> orderList = new ArrayList<>();
+            List<IotOpeationFillDO> pdList = iotOpeationFillMapper.pdList(devIdList);
+            for (IotOpeationFillDO pd:pdList) {
+                IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
+                fillDO.setOrderName(pd.getOrgName()+"/"+ LocalDate.now()+"运行记录填报");
+                fillDO.setDeptId(pd.getDeptId());
+                fillDO.setOrderStatus(0);
+                fillDO.setCreateTime(LocalDateTime.now());
+                fillDO.setUserName(pd.getUserName());
+                fillDO.setUserId(pd.getUserId());
+                fillDO.setMobile(pd.getMobile());
+                orderList.add(fillDO);
+            }
+            deal(planDO, date,devIdList,orderList);
+        }
+    }
+
 
     private void deal(IotOperationPlanDO plan, Date date,List<Long> devIdList, List<IotOpeationFillOrderDO> orderList) {
         Date date1 = new Date();
@@ -196,19 +141,16 @@ public class IotOperationPlanJob implements JobHandler {
             DateTime dateTime = DateUtil.offsetHour(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
             if (date1.compareTo(dateTime) > 0){
                 extracted(devIdList, orderList,plan);
-
             }
         } else if ("day".equals(plan.getPlanUnit())){
             DateTime dateTime = DateUtil.offsetDay(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
             if (date1.compareTo(dateTime) > 0){
                 extracted(devIdList, orderList,plan);
-
             }
         } else if ("month".equals(plan.getPlanUnit())){
             DateTime dateTime = DateUtil.offsetMonth(date, Integer.parseInt(StringUtils.substringBeforeLast(String.valueOf(plan.getPlanCycle()),".")));
             if (date1.compareTo(dateTime) > 0){
                 extracted(devIdList, orderList,plan);
-
             }
         }
     }
@@ -219,44 +161,27 @@ public class IotOperationPlanJob implements JobHandler {
         LocalDateTime localDateTime = DateUtils.contactTime(plan.getBeginCreateTime());
         plan.setLastCreateTime(localDateTime);
         planMapper.updateById(plan);
-
         //4、根据设备ID生成子表数据
         List<IotOpeationFillDO> deviceList = iotOpeationFillMapper.getFillDevices(devIdList);
-
         List<Integer> idList = deviceList.stream().map(IotOpeationFillDO::getUserId).collect(Collectors.toList());
-
-
         List<IotOpeationFillOrderDO> orderList1 = orderList.stream()
                 .filter(obj -> idList.contains(obj.getUserId()))
                 .collect(Collectors.toList());
-
-
         //插入工单主表
         iotOpeationFillOrderMapper.insertBatch(orderList1);
-
-
-
         Set<Long> rdIdList = new HashSet<>();
         rdIdList =  deptService.getChildDeptIdListFromCache(163L);
         rdIdList.add(163L);
-
         Set<Long> rhIdList = new HashSet<>();
         rhIdList =  deptService.getChildDeptIdListFromCache(157L);
         rhIdList.add(157L);
-
-
         boolean exist = rdIdList.contains(plan.getDeptId());
-
         if(!exist){
-
-
             //瑞鹰SCP项目部50010队伍临时创建
             if(plan.getDeptId()==292){
                 //筛选日报工单
                 List<IotOpeationFillOrderDO> virOrderList = new ArrayList<>();
-
                 IotOpeationFillOrderDO fillDO = new IotOpeationFillOrderDO();
-
                 fillDO.setOrderName("40006队"+"/"+LocalDate.now()+"运行记录填报");
                 fillDO.setDeptId(322L);
                 fillDO.setOrderStatus(0);
@@ -265,112 +190,111 @@ public class IotOperationPlanJob implements JobHandler {
                 fillDO.setUserId(486);
                 fillDO.setMobile(String.valueOf(17723897643L));
                 virOrderList.add(fillDO);
-
                 orderList1.addAll(virOrderList);
                 iotOpeationFillOrderMapper.insertBatch(virOrderList);
                 //创建日报设备
                 List <IotOpeationFillDO> devList = opeationFillService.reportMethod(virOrderList);
                 //插入日报设备
                 iotOpeationFillMapper.insertFill(devList);
-
-
             }
 
             boolean rhContain = rhIdList.contains(plan.getDeptId());
-
-            if(rhContain){
-
-                //创建日报设备
-                List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
-                //插入日报设备
-                iotOpeationFillMapper.insertFill(devList);
-
-                //2、瑞恒无指定队伍全部队伍插入日报设备
-                //筛选正常工单部门id
-                List<Long> deptIdList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
-                //查询瑞恒所有责任人数据
-                Set<Long> pIdList = new HashSet<>();
-                pIdList =  deptService.getChildDeptIdListFromCache(plan.getDeptId());
-                pIdList.add(plan.getDeptId());
-                List<IotOpeationFillDO> rhPdList = iotOpeationFillMapper.pdListRh(pIdList);
-                //筛选与正常工单不同部门的责任人数据
-                List<IotOpeationFillDO> verRPList = rhPdList.stream().filter(e->!deptIdList.contains(e.getDeptId())).collect(Collectors.toList());
-                //筛选小队责任人数据
-                // 使用迭代器遍历集合
-                Iterator<IotOpeationFillDO> iterator = verRPList.iterator();
-                while (iterator.hasNext()) {
-                    IotOpeationFillDO rp = iterator.next();
-                    IotOpeationFillOrderDO rpOrder = new IotOpeationFillOrderDO();
-                    rpOrder.setDeptId(rp.getDeptId());
-                    List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(rpOrder);
-
-                    // 当childList有元素时,通过迭代器删除当前元素
-                    if (childList.size() > 0) {
-                        iterator.remove(); // 使用迭代器的remove方法安全删除
-                    }
-                }
-                //创建虚拟工单
-                if(verRPList.size()>0){
-                    for (IotOpeationFillDO vir:verRPList) {
-                        IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
-                        //查询队伍增压机状态
-                        IotDeviceDO virDev = new IotDeviceDO();
-                        virDev.setDeptId(vir.getDeptId());
-                        IotDeviceDO devStatus = iotOpeationFillMapper.devStatus(virDev);
-                        //不为空则为日报赋值
-                        if(devStatus!=null){
-                            saveReqVO.setConstructionStatus(devStatus.getDeviceStatus());
-                        }
-                        //当日注气量
-                        saveReqVO.setDailyGasInjection(BigDecimal.valueOf(0.00));
-                        //当日注水量
-                        saveReqVO.setDailyWaterInjection(BigDecimal.valueOf(0.00));
-                        //当日注气时间
-                        saveReqVO.setDailyInjectGasTime(BigDecimal.valueOf(0.00));
-                        //当日注水时间
-                        saveReqVO.setDailyInjectWaterTime(BigDecimal.valueOf(0.00));
-                        //当日用电量
-                        saveReqVO.setDailyPowerUsage(BigDecimal.valueOf(0.00));
-                        //非生产时间
-                        saveReqVO.setNonProductionTime(BigDecimal.valueOf(0.00));
-                        saveReqVO.setDeptId(vir.getDeptId());
-                        saveReqVO.setFillOrderCreateTime(LocalDateTime.now());
-                        iotRhDailyReportService.createIotRhDailyReport(saveReqVO);
-                    }
+            //瑞恒日报插入
+            rhReportInsert(plan, orderList1, rhContain);
+        }
+        //发送钉钉消息
+        sendDingMessage(orderList1);
+        //正常工单设备
+        for (IotOpeationFillDO device:deviceList) {
+            for (IotOpeationFillOrderDO order:orderList1) {
+                if(device.getUserId().intValue()==order.getUserId().intValue()){
+                    device.setOrderId(order.getId());
                 }
             }
         }
+        //插入子表
+        for (IotOpeationFillDO re:deviceList) {
+            re.setDeviceId(re.getId());
+        }
+        iotOpeationFillMapper.insertFill(deviceList);
 
+    }
 
-
-
+    private void sendDingMessage(List<IotOpeationFillOrderDO> orderList1) {
         //发送钉钉通知
         pmsThreadPoolTaskExecutor.execute(()->{
             try{
-                for (IotOpeationFillOrderDO order:orderList1) {
+                for (IotOpeationFillOrderDO order: orderList1) {
                     pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
                 }
             }catch (Exception e){
                 e.printStackTrace();
             }
         });
+    }
 
-
-        //正常工单设备
-        for (IotOpeationFillDO device:deviceList) {
-            for (IotOpeationFillOrderDO order:orderList1) {
-                if(device.getUserId().intValue()==order.getUserId().intValue()){
-                    device.setOrderId(order.getId());
+    private void rhReportInsert(IotOperationPlanDO plan, List<IotOpeationFillOrderDO> orderList1, boolean rhContain) {
+        if(rhContain){
+
+            //创建日报设备
+            List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
+            //插入日报设备
+            iotOpeationFillMapper.insertFill(devList);
+
+            //2、瑞恒无指定队伍全部队伍插入日报设备
+            //筛选正常工单部门id
+            List<Long> deptIdList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+            //查询瑞恒所有责任人数据
+            Set<Long> pIdList = new HashSet<>();
+            pIdList =  deptService.getChildDeptIdListFromCache(plan.getDeptId());
+            pIdList.add(plan.getDeptId());
+            List<IotOpeationFillDO> rhPdList = iotOpeationFillMapper.pdListRh(pIdList);
+            //筛选与正常工单不同部门的责任人数据
+            List<IotOpeationFillDO> verRPList = rhPdList.stream().filter(e->!deptIdList.contains(e.getDeptId())).collect(Collectors.toList());
+            //筛选小队责任人数据
+            // 使用迭代器遍历集合
+            Iterator<IotOpeationFillDO> iterator = verRPList.iterator();
+            while (iterator.hasNext()) {
+                IotOpeationFillDO rp = iterator.next();
+                IotOpeationFillOrderDO rpOrder = new IotOpeationFillOrderDO();
+                rpOrder.setDeptId(rp.getDeptId());
+                List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(rpOrder);
+
+                // 当childList有元素时,通过迭代器删除当前元素
+                if (childList.size() > 0) {
+                    iterator.remove(); // 使用迭代器的remove方法安全删除
+                }
+            }
+            //创建虚拟工单
+            if(verRPList.size()>0){
+                for (IotOpeationFillDO vir:verRPList) {
+                    IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
+                    //查询队伍增压机状态
+                    IotDeviceDO virDev = new IotDeviceDO();
+                    virDev.setDeptId(vir.getDeptId());
+                    IotDeviceDO devStatus = iotOpeationFillMapper.devStatus(virDev);
+                    //不为空则为日报赋值
+                    if(devStatus!=null){
+                        saveReqVO.setConstructionStatus(devStatus.getDeviceStatus());
+                    }
+                    //当日注气量
+                    saveReqVO.setDailyGasInjection(BigDecimal.valueOf(0.00));
+                    //当日注水量
+                    saveReqVO.setDailyWaterInjection(BigDecimal.valueOf(0.00));
+                    //当日注气时间
+                    saveReqVO.setDailyInjectGasTime(BigDecimal.valueOf(0.00));
+                    //当日注水时间
+                    saveReqVO.setDailyInjectWaterTime(BigDecimal.valueOf(0.00));
+                    //当日用电量
+                    saveReqVO.setDailyPowerUsage(BigDecimal.valueOf(0.00));
+                    //非生产时间
+                    saveReqVO.setNonProductionTime(BigDecimal.valueOf(0.00));
+                    saveReqVO.setDeptId(vir.getDeptId());
+                    saveReqVO.setFillOrderCreateTime(LocalDateTime.now());
+                    iotRhDailyReportService.createIotRhDailyReport(saveReqVO);
                 }
             }
         }
-
-        //插入子表
-        for (IotOpeationFillDO re:deviceList) {
-            re.setDeviceId(re.getId());
-        }
-        iotOpeationFillMapper.insertFill(deviceList);
-
     }
 
 }

+ 31 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/service/iotopeationfill/IotOpeationFillServiceImpl.java

@@ -28,8 +28,11 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -341,7 +344,7 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
             for (IotOpeationFillOrderDO orderDO:orderList) {
                 List<IotOpeationFillOrderDO> childList = iotOpeationFillMapper.childList(orderDO);
 
-                int randomNum = ThreadLocalRandom.current().nextInt(100000, 1000000);
+                int randomNum = generateUniqueNumber();
 
                 //如果是根节点,则证明该部门为小队并且属于瑞恒,创建对应日报虚拟设备
                 if(childList.size()==0){
@@ -368,6 +371,33 @@ public class IotOpeationFillServiceImpl implements IotOpeationFillService {
         return devList;
     }
 
+    // 用于记录每天的序列号,确保当天内不重复
+    private static final ConcurrentHashMap<String, AtomicInteger> dailySequence = new ConcurrentHashMap<>();
+    // 日期格式化器,用于生成每天的唯一标识
+    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
+    public static synchronized int generateUniqueNumber() {
+        // 获取当前日期字符串,如20231005
+        String today = LocalDate.now().format(DATE_FORMATTER);
+        // 提取年份后两位和月份日期的哈希值作为日期标识(2位)
+        int dateCode = (Integer.parseInt(today.substring(2, 4)) +
+                Integer.parseInt(today.substring(4, 6)) +
+                Integer.parseInt(today.substring(6, 8))) % 99 + 1;
+
+        // 获取当天的序列号生成器,不存在则创建
+        AtomicInteger sequence = dailySequence.computeIfAbsent(today, k -> new AtomicInteger(1));
+        // 获取下一个序列号
+        int seq = sequence.getAndIncrement();
+
+        // 检查是否超过每天的最大生成量
+        if (seq > 9999) {
+            throw new RuntimeException("今日已超过最大生成数量(9999个)");
+        }
+
+        // 组合日期标识和序列号,生成6位唯一数字
+        return dateCode * 10000 + seq;
+    }
+
+
     @Override
     public IotOpeationFillDO isReport(IotOpeationFillDO fillDO) {
         return iotOpeationFillMapper.isReport(fillDO);

+ 1 - 1
yudao-module-pms/yudao-module-pms-biz/src/main/resources/mapper/static/IotOpeationFillMapper.xml

@@ -1052,7 +1052,7 @@
         SELECT device_status
         FROM rq_iot_device
         WHERE dept_id = #{deptId}
-          AND asset_class in (159,160)
+          AND asset_class in (159,160,122,106,157,158,191)
             LIMIT 1
     </select>