Browse Source

增加水表状态查询接口

hym 4 years ago
parent
commit
4ced41e82d

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/PlatformApiController.java

@@ -16,6 +16,7 @@ import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @RestController
@@ -53,6 +54,14 @@ public class PlatformApiController {
         System.out.println(waterMeterElectronicNumber);
         return new AjaxMessage<>(ResultStatus.OK,waterMeterElectronicNumber);
     }
+    @PostMapping  ("/getDeviceStatus")
+    @ApiOperation(value = "获取电子号")
+    public AjaxMessage getDeviceStatus (
+            @RequestBody  Map<String,Object> args) {
+        List<Map<String,Object>> result=platformAapiService.getDeviceStatus(args);
+        return new AjaxMessage<>(ResultStatus.OK,result);
+    }
+
     @GetMapping  ("/testKafka")
     public void testKafka(String meterNo,String meterStatus){
         Map<String,Object> valveMessage=new HashMap<>();

+ 18 - 5
smart-city-platform/src/main/java/com/bz/smart_city/kafka/consumer/ValveStatusReceiver.java

@@ -3,6 +3,7 @@ package com.bz.smart_city.kafka.consumer;
 import com.bz.smart_city.commom.util.MessageSend.JSONUtils;
 import com.bz.smart_city.dao.OperatingValveRecordMapper;
 import com.bz.smart_city.dto.ValveControlDataDto;
+import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.OperatingValveRecord;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,9 +32,10 @@ public class ValveStatusReceiver {
         operatingValveRecord.setStatus(1);
         List<OperatingValveRecord> operatingValveRecords = operatingValveRecordMapper.selectList(operatingValveRecord);
         OperatingValveRecord operatingValveRecordMessage=null;
-        log.info("上报水表信息");
+        log.info("上报水表信息={}",message);
+        ValveControlDataDto valveControlDataDto = JSONUtils.json2pojo(message, ValveControlDataDto.class);
         if(operatingValveRecords.size()>0){
-            ValveControlDataDto valveControlDataDto = JSONUtils.json2pojo(message, ValveControlDataDto.class);
+
             boolean flag=false;
             for (OperatingValveRecord valveRecord : operatingValveRecords) {
                     if(valveRecord.getWaterNo().equals(valveControlDataDto.getMeterNo())
@@ -45,12 +47,23 @@ public class ValveStatusReceiver {
                 }
             }
             if(flag){
+
+                operatingValveRecordMapper.updateStatus(operatingValveRecordMessage);
+            }
+            if(operatingValveRecordMessage==null){
+                operatingValveRecordMessage=new OperatingValveRecord();
+                operatingValveRecordMessage.setWaterNo(valveControlDataDto.getMeterNo());
+                operatingValveRecordMessage.setCustomerId(valveControlDataDto.getCustomerId());
+            }
+            Device device=operatingValveRecordMapper.getDevice(operatingValveRecordMessage);
+            if(device!=null){
+                log.info("同步水表阀门状态 电子号={}",device.getMetercode());
                 Map<String,Object>valveMessage=new HashMap<>();
-                valveMessage.put("meterNo",operatingValveRecordMessage.getWaterFileNo());
-                valveMessage.put("meterStatus",operatingValveRecordMessage.getOperation());
+                valveMessage.put("meterNo",device.getMetercode());
+                valveMessage.put("meterStatus",Integer.parseInt(valveControlDataDto.getValve()));
                 kafkaTemplate.send(billingValveStatusReceiving, JSONUtils.obj2json(valveMessage));
-                operatingValveRecordMapper.updateStatus(operatingValveRecordMessage);
             }
+
         }
     }
 }

+ 8 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/PlatformAapiService.java

@@ -1,9 +1,17 @@
 package com.bz.smart_city.service;
 
+import java.util.List;
+import java.util.Map;
+
 public interface PlatformAapiService {
     void updateMeterNo(String meterNo, String meterCode, String customerNo);
 
     void sendCommond(String meterNo, Integer type, String customerNo);
 
     String getWaterMeterNo(String meterNo, String customerNo);
+
+
+
+
+    List<Map<String, Object>> getDeviceStatus(Map<String, Object> args);
 }

+ 10 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/sync/PlatformAapiServiceImpl.java

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Service;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 @Service
 public class PlatformAapiServiceImpl implements PlatformAapiService {
@@ -74,6 +75,15 @@ public class PlatformAapiServiceImpl implements PlatformAapiService {
         }
         return null;
     }
+
+    @Override
+    public  List<Map<String, Object>> getDeviceStatus(Map<String, Object> args) {
+        String customerNo= (String) args.get("customerNo");
+        List<String>electronicMeterNos= (List<String>) args.get("electronicMeterNos");
+        List<Map<String,Object>> result=operatingValveRecordMapper.getDeviceStatus(electronicMeterNos,customerNo);
+        return result;
+    }
+
     private Device getDevice(String meterNo, String customerNo){
         Device device=null;
         List<String>fileNo=new ArrayList<>();

+ 18 - 0
smart-city-platform/src/main/resources/mapper/OperatingValveRecordMapper.xml

@@ -146,4 +146,22 @@
         update sc_operating_valve_record set status=0,update_date=now() where water_file_no=#{waterFileNo}
         and customer_id=#{customerId} and status=1
     </update>
+    <select id="getDevice" resultType="com.bz.smart_city.entity.Device">
+        select sil.metercode from sc_device sd  left join sc_install_list sil on(sil.device_id = sd.id)
+        where sd.water_meter_no=#{waterNo} and sd.customer_id=#{customerId} and sd.status=1
+    </select>
+    <select id="getDeviceStatus" resultType="java.util.HashMap">
+        select sd.device_status deviceStatus,b.days,sd.water_meter_no electronicMeterNo from
+         sc_device sd
+            join sc_customer c on sd.customer_id=c.id
+            left join sc_water_meter_error_days b on sd.id=b.device_id
+        where sd.water_meter_no in
+              <foreach collection="electronicMeterNo" item="item" separator="," open="(" close=")">
+                        #{item}
+                   </foreach>
+
+
+          and c.customer_no=#{customerNo} and sd.status=1
+
+    </select>
 </mapper>