浏览代码

开户开阀加入定时任务

wangli 4 年之前
父节点
当前提交
f61b538a9d

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

@@ -59,29 +59,7 @@ public class DeviceValveCommondSync implements InitializingBean, Job, Serializab
             entity.setJobClassName(DeviceValveCommondSync.class.getName());
             jobAndTriggerService.save(entity);
         }
-        //巡检中间表下发开关阀操作(开户开阀)
-        new Thread(() -> {
-            while (true) {
-                try {
-                    List<PayValveStateInfoDto> payValveStateInfos = payFeeMapper.getDeviceValveStateByRecord();
-                    if(payValveStateInfos.size() > 0){
-                        List<BigInteger> devices = payValveStateInfos.stream().map( d ->{
-                                    payFeeService.sendValveCommond(d);
-                                    return d.getMeterId();
-                                }
-                        ).collect(Collectors.toList());
-                        payFeeMapper.deleteControlValveInfoByDevice(devices);
-                    }
-                } catch (Exception e){
-                    e.printStackTrace();
-                }
-                try {
-                    Thread.sleep(60000);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-            }
-        }).start();
+
     }
 
     @Override

+ 81 - 0
smart-city-platform/src/main/java/com/bz/smart_city/quartz/job/OpenAccountValveInspection.java

@@ -0,0 +1,81 @@
+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.PayValveStateInfoDto;
+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;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/2/5 8:46
+ */
+@Slf4j
+@Component
+public class OpenAccountValveInspection  implements InitializingBean, Job, Serializable {
+
+    private static final long serialVersionUID = 485856043987682652L;
+
+
+    @Resource
+    private PayFeeMapper payFeeMapper;
+    @Resource
+    private JobAndTriggerService jobAndTriggerService;
+
+    @Autowired
+    private PayFeeService payFeeService;
+
+    @Resource
+    private PayControlRecordMapper payControlRecordMapper;
+
+    @Override
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+        try {
+            List<PayValveStateInfoDto> payValveStateInfos = payFeeMapper.getDeviceValveStateByRecord();
+            if(payValveStateInfos.size() > 0){
+                List<BigInteger> devices = payValveStateInfos.stream().map(d ->{
+                            payFeeService.sendValveCommond(d);
+                            return d.getMeterId();
+                        }
+                ).collect(Collectors.toList());
+                payFeeMapper.deleteControlValveInfoByDevice(devices);
+            }
+        } catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    //巡检中间表下发开关阀操作(开户开阀)
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        QuartzEntity entity = new QuartzEntity();
+        entity.setJobGroup("巡检开户开阀操作");
+        entity.setJobName("OpenAccountValveInspectionSyncByJob" );
+        entity.setDescription("OpenAccountValveInspectionSyncByJob" );
+        // modify by pengdi ,判断定时任务是否存在,不存在才进行新增
+
+        boolean exists = jobAndTriggerService.isExists(entity);
+        if(!exists) {
+            String cron = "0 */2 * * * ?";
+            log.info("巡检开户开阀操作:" + cron);
+            entity.setCronExpression(cron);
+            entity.setJobClassName(OpenAccountValveInspection.class.getName());
+            jobAndTriggerService.save(entity);
+        }
+    }
+}

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayFeeServiceImp.java

@@ -1372,7 +1372,7 @@ public class PayFeeServiceImp implements PayFeeService {
     public Boolean sendValveCommond(PayValveStateInfoDto payValveStateInfo){
 
         PayControlRecord lastPayControlRecord = payControlRecordMapper.findControlRecordByMetercode(payValveStateInfo.getMeterCode());
-        if(lastPayControlRecord != null && lastPayControlRecord.getResult() == null){
+        if(lastPayControlRecord != null && (lastPayControlRecord.getResult() == null ||lastPayControlRecord.getResult() == 0) ){
             if(lastPayControlRecord.getType().equals(payValveStateInfo.getOperation())){ //操作相同不再添加
                 return true;
             }

+ 6 - 6
smart-city-platform/src/main/resources/mapper/pay/payFeeMapper.xml

@@ -406,7 +406,7 @@
             d.account_id as "accountId"
             ,d.id as "meterId"
             ,d.water_meter_no as "eleno"
-            ,ifnull(d.water_meter_file_no,d.metercode )as "metercode"
+            ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
             ,d.control_status as "valveState"
             ,ifnull((select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}),0) as "debt"
             ,cs.customer_no as "customerNo"
@@ -425,7 +425,7 @@
             d.account_id as "accountId"
             ,d.id as "meterId"
             ,d.water_meter_no as "eleno"
-            ,ifnull(d.water_meter_file_no,d.metercode )as "metercode"
+            ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
             ,d.control_status as "valveState"
             ,(select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}) as "debt"
             ,cs.customer_no as "customerNo"
@@ -441,7 +441,7 @@
         r.account_id as "accountId"
         ,d.id as "meterId"
         ,d.water_meter_no as "eleno"
-        ,ifnull(d.water_meter_file_no,d.metercode )as "metercode"
+        ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
         ,d.control_status as "valveState"
         ,cs.customer_no as "customerNo"
         ,sum(re.debt) debt
@@ -458,7 +458,7 @@
                 #{item}
             </foreach>
         )
-        group by cs.customer_no, r.account_id	,d.id	,d.water_meter_no	,d.water_meter_file_no,d.metercode ,d.control_status
+        group by cs.customer_no, r.account_id	,d.id	,d.water_meter_no	,d.metercode,d.water_meter_file_no ,d.control_status
 
     </select>
 
@@ -468,7 +468,7 @@
             ,c.account_id as "accountId"
             ,d.id as "meterId"
             ,d.water_meter_no as "eleno"
-            ,ifnull(d.water_meter_file_no,d.metercode )as "metercode"
+            ,ifnull(d.metercode,d.water_meter_file_no )as "metercode"
             ,d.control_status as "valveState"
             ,cs.customer_no as "customerNo"
             ,v.control_state as "operation"
@@ -637,7 +637,7 @@
             ,TIMESTAMPDIFF(day,ifnull(r.create_date,NOW()),NOW()) as "days"
             ,d.id as "meterId"
             ,d.control_status as "valveState"
-            ,ifnull(d.water_meter_file_no,d.metercode) as "metercode"
+            ,ifnull(d.metercode,d.water_meter_file_no) as "metercode"
             ,(select customer_no from sc_customer where id = #{customerId}) as "customerNo"
         from pay_base_customerandmeterrela c
         left join sc_device d on c.watermeter_id =d.id