Browse Source

运行记录定时任务优化

yuanchao 2 weeks ago
parent
commit
c2e4e29cd4

+ 4 - 0
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/dal/mysql/iotopeationfill/IotOpeationFillMapper.java

@@ -143,6 +143,10 @@ public interface IotOpeationFillMapper extends BaseMapperX<IotOpeationFillDO> {
     @TenantIgnore
     List<IotOpeationFillDO> pdList2(@Param("deviceIds")Collection<Long> deviceIds);
 
+    @TenantIgnore
+    List<IotOpeationFillOrderDO> allOrder(@Param("localDateTime")LocalDateTime localDateTime,@Param("userNames")Collection<String> userNames);
+
+
     List<IotOpeationFillDO> deviceList(IotOpeationFillRespVO vo);
     @TenantIgnore
     PageResult<IotOpeationFillDO> fillList1(IotOpeationFillPageReqVO vo);

+ 71 - 72
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/job/IotOperationPlanJob.java

@@ -316,103 +316,102 @@ public class IotOperationPlanJob implements JobHandler {
             }
         }
 
-        iotOpeationFillOrderMapper.insertBatch(orderList1);
+        IotOpeationFillOrderDO todayTime = new IotOpeationFillOrderDO();
+        todayTime.setCreateTime(localDateTime);
 
+        List<String> userList = orderList1.stream().map(IotOpeationFillOrderDO::getUserName).collect(Collectors.toList());
 
+        List<IotOpeationFillOrderDO> allOrder = iotOpeationFillMapper.allOrder(localDateTime,userList);
 
+        if(allOrder.size()>0){
 
+        }else{
 
+            iotOpeationFillOrderMapper.insertBatch(orderList1);
 
 
-       /* //发送钉钉通知
-        pmsThreadPoolTaskExecutor.execute(()->{
-            try{
-                for (IotOpeationFillOrderDO order:orderList1) {
-                    pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
+                 /* //发送钉钉通知
+            pmsThreadPoolTaskExecutor.execute(()->{
+                try{
+                    for (IotOpeationFillOrderDO order:orderList1) {
+                        pmsMessage.sendMessage(order.getId(), order.getOrderName(), PmsConstants.GENERATE_OPERATION, (long)order.getUserId(), order.getMobile());
+                    }
+                }catch (Exception e){
+                    e.printStackTrace();
                 }
-            }catch (Exception e){
-                e.printStackTrace();
-            }
-        });*/
+            });*/
 
-
-        for (IotOpeationFillDO device:deviceList) {
-            System.out.println("deviceUser"+device.getUserId());
-            for (IotOpeationFillOrderDO order:orderList1) {
-                System.out.println("orderId"+order.getUserId());
-                if(device.getUserId().intValue()==order.getUserId().intValue()){
-                    System.out.println("-----相等-------");
-                    device.setOrderId(order.getId());
+            for (IotOpeationFillDO device:deviceList) {
+                System.out.println("deviceUser"+device.getUserId());
+                for (IotOpeationFillOrderDO order:orderList1) {
+                    System.out.println("orderId"+order.getUserId());
+                    if(device.getUserId().intValue()==order.getUserId().intValue()){
+                        System.out.println("-----相等-------");
+                        device.setOrderId(order.getId());
+                    }
                 }
             }
-        }
 
 
-        System.out.println("***********创建运行记录填报工单执行结束*********8");
+            System.out.println("***********创建运行记录填报工单执行结束*********8");
 
 
-        System.out.println("*****************插入运行记录设备表***********************");
-
-        for (IotOpeationFillDO re:deviceList) {
-            re.setDeviceId(re.getId());
-            re.setIsReport(0);
-        }
-        iotOpeationFillMapper.insertFill(deviceList);
+            System.out.println("*****************插入运行记录设备表***********************");
 
+            for (IotOpeationFillDO re:deviceList) {
+                re.setDeviceId(re.getId());
+                re.setIsReport(0);
+            }
+            iotOpeationFillMapper.insertFill(deviceList);
 
 
 
-        List<Long> oDeptList = new ArrayList<>();
 
-        if(rpList.size()>0){
-            oDeptList = orderList2.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+            List<Long> oDeptList = new ArrayList<>();
 
-            // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
-            boolean exist;
-            if (oDeptList.isEmpty()) {
-                // 当oDeptList为空时,这里可以根据实际场景设置默认值
-                // 例如:空列表认为所有元素都被包含,设置为true
-                exist = false;
-                // 或者认为不满足,设置为false
-                // exist = false;
-            } else {
-                exist = idList1.containsAll(oDeptList);
-            }
+            if(rpList.size()>0){
+                oDeptList = orderList2.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+
+                // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
+                boolean exist;
+                if (oDeptList.isEmpty()) {
+                    // 当oDeptList为空时,这里可以根据实际场景设置默认值
+                    // 例如:空列表认为所有元素都被包含,设置为true
+                    exist = false;
+                    // 或者认为不满足,设置为false
+                    // exist = false;
+                } else {
+                    exist = idList1.containsAll(oDeptList);
+                }
 
-            if(exist){
-                List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList2);
-                //插入虚拟设备
-                iotOpeationFillMapper.insertFill(devList);
-            }
+                if(exist){
+                    List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList2);
+                    //插入虚拟设备
+                    iotOpeationFillMapper.insertFill(devList);
+                }
 
 
-        }else{
-            oDeptList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
-
-            // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
-            boolean exist;
-            if (oDeptList.isEmpty()) {
-                // 当oDeptList为空时,这里可以根据实际场景设置默认值
-                // 例如:空列表认为所有元素都被包含,设置为true
-                exist = false;
-                // 或者认为不满足,设置为false
-                // exist = false;
-            } else {
-                exist = idList1.containsAll(oDeptList);
-            }
+            }else{
+                oDeptList = orderList1.stream().map(IotOpeationFillOrderDO::getDeptId).collect(Collectors.toList());
+
+                // 先判断oDeptList是否为空,如果为空则根据业务需求设置exist的值
+                boolean exist;
+                if (oDeptList.isEmpty()) {
+                    // 当oDeptList为空时,这里可以根据实际场景设置默认值
+                    // 例如:空列表认为所有元素都被包含,设置为true
+                    exist = false;
+                    // 或者认为不满足,设置为false
+                    // exist = false;
+                } else {
+                    exist = idList1.containsAll(oDeptList);
+                }
 
-            if(exist){
-                List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
-                //插入虚拟设备
-                iotOpeationFillMapper.insertFill(devList);
+                if(exist){
+                    List <IotOpeationFillDO> devList = opeationFillService.reportMethod(orderList1);
+                    //插入虚拟设备
+                    iotOpeationFillMapper.insertFill(devList);
+                }
             }
         }
-
-
-
-
-
-
-
-}
+    }
 }

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

@@ -556,6 +556,21 @@
         </if>
     </select>
 
+
+    <select id="allOrder" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO">
+        select distinct user_name
+        from
+            rq_iot_opeation_fill_order
+        where
+            DATE(create_time) = DATE(#{localDateTime})
+            <if test="userNames != null and !userNames.isEmpty()">
+                and user_name  in
+                <foreach collection="userNames" item="userName" open="(" separator="," close=")">
+                    #{userName}
+                </foreach>
+            </if>
+    </select>
+
     <select id="pdList2" resultType="cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO">
         select
             distinct