Quellcode durchsuchen

巡检阀门操作有效期 2*24*60

wangli vor 4 Jahren
Ursprung
Commit
4c36f1da8f

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayControlRecordMapper.java

@@ -31,4 +31,6 @@ public interface PayControlRecordMapper {
     Integer updateControlRecordResult(@Param("result") Integer result,@Param("valveStatus") Integer valveStatus,@Param("id") BigInteger id);
     //最后一次记录
     PayControlRecord getRecentRecord(@Param("payControlRecord") PayControlRecord payControlRecord);
+
+    void updateControlRecordResultTimeOut();
 }

+ 39 - 1
smart-city-platform/src/main/java/com/bz/smart_city/quartz/job/DeviceValveCommondSync.java

@@ -1,14 +1,21 @@
 package com.bz.smart_city.quartz.job;
 
+import com.bz.smart_city.dao.pay.PayControlRecordMapper;
 import com.bz.smart_city.dao.pay.PayFeeMapper;
 import com.bz.smart_city.dto.pay.payfee.PayValveStateInfo;
+import com.bz.smart_city.quartz.entity.QuartzEntity;
+import com.bz.smart_city.quartz.service.JobAndTriggerService;
 import com.bz.smart_city.service.pay.PayFeeService;
 import lombok.extern.slf4j.Slf4j;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
+import java.io.Serializable;
 import java.math.BigInteger;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -20,15 +27,39 @@ import java.util.stream.Collectors;
  */
 @Slf4j
 @Component
-public class DeviceValveCommondSync implements InitializingBean {
+public class DeviceValveCommondSync implements InitializingBean, Job, Serializable {
+
+    private static final long serialVersionUID = -5732782747738726245L;
 
     @Resource
     private PayFeeMapper payFeeMapper;
+    @Resource
+    private JobAndTriggerService jobAndTriggerService;
 
     @Autowired
     private PayFeeService payFeeService;
+
+    @Resource
+    private PayControlRecordMapper payControlRecordMapper;
+
     @Override
     public void afterPropertiesSet() {
+
+        QuartzEntity entity = new QuartzEntity();
+        entity.setJobGroup("巡检阀门操作有效期");
+        entity.setJobName("DeviceValveSyncByJob" );
+        entity.setDescription("DeviceValveSyncByJob" );
+        // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
+
+        boolean exists = jobAndTriggerService.isExists(entity);
+        if(!exists) {
+            String cron = "0 */1 * * * ?";
+            log.info("巡检阀门操作有效期:" + cron);
+            entity.setCronExpression(cron);
+            entity.setJobClassName(DeviceValveCommondSync.class.getName());
+            jobAndTriggerService.save(entity);
+        }
+
         new Thread(() -> {
             while (true) {
                 try {
@@ -52,4 +83,11 @@ public class DeviceValveCommondSync implements InitializingBean {
             }
         }).start();
     }
+
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+        log.info("巡检阀门操作有效期开始");
+        payControlRecordMapper.updateControlRecordResultTimeOut();
+        log.info("巡检阀门操作有效期结束");
+    }
 }

+ 0 - 3
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/AmountSynDayServiceImpl.java

@@ -65,9 +65,6 @@ public class AmountSynDayServiceImpl implements AmountSynByDayService, Initializ
     }
 
     public void saveQrtzTask() {
-
-
-
         // 1,查询需要批量推送的配置项目并构建定时任务
         // 2,若对应定时任务不存在则创建
         QuartzEntity entity = new QuartzEntity();

+ 5 - 1
smart-city-platform/src/main/resources/mapper/pay/PayControlRecordMapper.xml

@@ -185,8 +185,12 @@
         update sc_device  set control_status = #{valveStatus}  where metercode = #{meterCode}
     </update>
     <update id="updateControlRecordResult">
-        update pay_control_record set result =#{result} ,state =#{valveStatus} where id = #{id}
+        update pay_control_record set result =#{result} ,state =#{valveStatus},update_date = now() where id = #{id}
     </update>
 
+    <update id="updateControlRecordResultTimeOut">
+        update pay_control_record set result= 2 ,update_date = now()
+        where result = 0 and TIMESTAMPDIFF(MINUTE,create_date,NOW()) > 2*24*60
+    </update>
 
 </mapper>