Browse Source

天津接口代码提交 PengDi@2021/1/26

pengdi@zoniot.com 4 years ago
parent
commit
ce3532b0e6

+ 3 - 0
meter-reading-tianjin/src/main/java/com/huaxu/zoniot/dto/RegistIMEIRequest.java

@@ -48,6 +48,9 @@ public class RegistIMEIRequest implements Serializable {
      */
     @ApiModelProperty("IMEI号")
     String imei	 ;
+
+    @ApiModelProperty("水表类型,1:Lora,2:NB(天津协议)")
+    Integer meterType;
     /**
      * 验证值 --> 验证值
      */

+ 1 - 1
meter-reading-tianjin/src/main/java/com/huaxu/zoniot/service/TianJinMeterReadingService.java

@@ -24,7 +24,7 @@ public interface TianJinMeterReadingService {
      * @param readDay 抄表日期
      * @return
      */
-    RespData queryReadRecordData(String[] imeiArray,Integer readDay) ;
+    RespData queryReadRecordData(String[] imeiArray,Integer readDay,Integer meterType) ;
 
     /**
      * 根据IMEI查询是否已注册

+ 109 - 12
meter-reading-tianjin/src/main/java/com/huaxu/zoniot/service/impl/TianJinMeterReadingServiceImpl.java

@@ -56,9 +56,11 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
     @Value("${customer.code}")
     Integer customerCode ;
 
-    @Value("${device.type.code}")
-    Integer deviceTypeCode ;
+    @Value("${device.type.nb.code}")
+    Integer deviceTypeNBCode ;
 
+    @Value("${device.type.lora.code}")
+    Integer deviceTypeLoraCode ;
 
     @Autowired
     MeterReadRecordRepository  meterReadRecordRepository ;
@@ -92,7 +94,14 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
             waterMeter.setMeterNo(request.getRegistNo());
             waterMeter.setMeterFileNo(request.getCustomerNo());
             waterMeter.setLocation(request.getLocation());
-            waterMeter.setDeviceTypeId(deviceTypeCode);
+            if(request.getMeterType() == 1){
+                // Lora表
+                waterMeter.setDeviceTypeId(deviceTypeLoraCode);
+            }
+            else if(request.getMeterType() == 2){
+                // nb表
+                waterMeter.setDeviceTypeId(deviceTypeNBCode);
+            }
             waterMeter.setSiteId(community.getSiteId());
             waterMeter.setCustomerId(community.getCustomerId());
             waterMeter.setProvince(community.getProvince());
@@ -143,15 +152,22 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
         return waterMeterService.saveWaterWaterMeter(waterMeter) ;
     }
     @Override
-    public RespData queryReadRecordData(String[] imeiArray,Integer readDay){
+    public RespData queryReadRecordData(String[] imeiArray,Integer readDay,Integer meterType){
         if(readDay == null){
-            // 默认查询今天的
-            readDay = Integer.parseInt(DateUtil.format(DateUtil.date(),
-                    Constants.DEFAULT_METER_READ_DATE_FORMAT));
+            // Lora表,默认查询前一天的数据,NB表,默认查询当天的数据
+            if(meterType == 1){
+                readDay = Integer.parseInt(DateUtil.format(DateUtil.offsetDay(DateUtil.date(),-1),
+                        Constants.DEFAULT_METER_READ_DATE_FORMAT));
+            }
+            else{
+                // 默认查询今天的
+                readDay = Integer.parseInt(DateUtil.format(DateUtil.date(),
+                        Constants.DEFAULT_METER_READ_DATE_FORMAT));
+            }
         }
         RespData  respData = new RespData();
         List<String> deviceNoList = Arrays.asList(imeiArray);
-        List<Integer> customerIds = findCustomerIdsWithChildren(customerCode);
+        //List<Integer> customerIds = findCustomerIdsWithChildren(customerCode);
         List<WaterMeter> waterMeterList = waterMeterService.findWaterMeterListWithChildrenCustomer(deviceNoList,
                 customerCode);
         Criteria criteria = Criteria.where("readDate").is(readDay)
@@ -174,7 +190,7 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
                 MeterReadRecord meterReadRecord = meterReadRecordMap.get(imei);
                 rtnData.setECURegDate(DateUtil.format(waterMeter.getDateCreate(), "yyyy-MM-dd HH:mm:ss"));
                 if(meterReadRecord != null){
-                    buildRtnData(meterReadRecord,rtnData);
+                    buildRtnData(meterReadRecord,rtnData,meterType);
                 }
                 else {
                     rtnData.setECUState(RtnData.STATE_NO_DATA);
@@ -193,7 +209,88 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
         return respData;
     }
 
-    protected void buildRtnData(MeterReadRecord meterReadRecord,RtnData rtnData){
+    /**
+     * 构造返回数据
+     * @param meterReadRecord 抄表记录
+     * @param rtnData 返回数据
+     * @param meterType 表类型
+     */
+    protected void buildRtnData(MeterReadRecord meterReadRecord,RtnData rtnData,Integer meterType){
+        if(meterType == 1){
+            // 进行LoRa数据处理
+            buildRtnDataForLora(meterReadRecord,rtnData);
+        }
+        else if(meterType == 2){
+            // 进行NB数据处理
+            buildRtnDataForNB(meterReadRecord,rtnData);
+        }
+    }
+
+    protected void buildRtnDataForLora(MeterReadRecord meterReadRecord,RtnData rtnData){
+        // 获取如下信息:基站ID-->cellID,电池电量,信号强度-->CSQ,阀门状态,水表状态,水表状态信息
+        Map<String, String> lastSendData = meterReadRecord.getLastSendData();
+        String valveState = lastSendData.get("VALVE");
+        rtnData.setValve(valveState);
+
+        String batteryQuantity = lastSendData.get("VOL");
+        rtnData.setBatteryVotage(batteryQuantity);
+        // 没有的数据默认填0
+        rtnData.setBaseStationID("0");
+        rtnData.setSignalIntensity("0");
+
+        List<String> stateList = processWaterMeterStateForLora(lastSendData);
+        String state = stateList.get(0);
+        rtnData.setECUState(state);
+
+        if(!RtnData.STATE_NORMAL.equals(state)){
+            String warnMessage = stateList.get(1);
+            rtnData.setMessage(warnMessage);
+        }
+
+        // 获取抄表时间,格式:yyyy-MM-dd
+        Date readTime = meterReadRecord.getReadTime();
+        rtnData.setRXDDate(DateUtil.format(readTime, "yyyy-MM-dd HH:mm:ss"));
+        // 表盘读数,原数据
+        rtnData.setRXDReading(meterReadRecord.getReadData());
+        // 抄表止度,向下取整
+        rtnData.setReading(String.valueOf(
+                ((Double)Math.floor(
+                        Double.parseDouble(meterReadRecord.getReadData()))).intValue()));
+        rtnData.setMessage("正常");
+    }
+
+    protected  List<String> processWaterMeterStateForLora(Map<String, String> data){
+        List<String> result = new ArrayList<>();
+        // 以下报警信息均,0:正常,1:报警
+        String meterState = "0";
+        StringBuffer waringMessage =  new StringBuffer();
+        // 低电告警
+        String lowVoltageWarning = data.get("VOL_STATUS");
+        if(RtnData.ALARM_STATE_ERROR.equals(lowVoltageWarning)){
+            waringMessage.append("低电告警,");
+            meterState = "1";
+        }
+        // 磁干扰告警
+        String magneticInterWarning = data.get("DISTURB");
+        if(RtnData.ALARM_STATE_ERROR.equals(magneticInterWarning)){
+            waringMessage.append("磁干扰告警,");
+            meterState = "1";
+        }
+        // 反流告警
+        String refluxWarningQuantity = data.get("FORCED");
+        if(RtnData.ALARM_STATE_ERROR.equals(refluxWarningQuantity)){
+            waringMessage.append("反流告警,");
+            meterState = "1";
+        }
+        result.add(meterState);
+        String waringString = waringMessage.toString();
+        if(StringUtils.isNotBlank(waringString)){
+            result.add(waringString.substring(0,waringString.length()-1));
+        }
+        return result ;
+    }
+
+    protected void buildRtnDataForNB(MeterReadRecord meterReadRecord,RtnData rtnData){
         // 获取如下信息:基站ID-->cellID,电池电量,信号强度-->CSQ,阀门状态,水表状态,水表状态信息
         Map<String, String> lastSendData = meterReadRecord.getLastSendData();
 
@@ -209,7 +306,7 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
         String rspr = lastSendData.get("RSPR");
         rtnData.setSignalIntensity(rspr);
 
-        List<String> stateList = processWaterMeterState(lastSendData);
+        List<String> stateList = processWaterMeterStateForNB(lastSendData);
         String state = stateList.get(0);
         rtnData.setECUState(state);
 
@@ -235,7 +332,7 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
      * @param data
      * @return
      */
-    protected  List<String> processWaterMeterState(Map<String, String> data){
+    protected  List<String> processWaterMeterStateForNB(Map<String, String> data){
         List<String> result = new ArrayList<>();
         // 以下报警信息均,0:正常,1:报警
         String meterState = "0";

+ 4 - 2
meter-reading-tianjin/src/main/java/com/huaxu/zoniot/web/IntegrationController.java

@@ -51,11 +51,13 @@ public class IntegrationController {
     @ApiOperation(value = "查询数据接口")
     public RespData queryReadRecordData(
             @ApiParam(value = "IMEI号,多个逗号分隔", required = true)@RequestParam String imei ,
-            @ApiParam(value = "apiKey", required = true) @RequestParam String apiKey) {
+            @ApiParam(value = "apiKey", required = true) @RequestParam String apiKey,
+            @ApiParam(value = "表类型,1:Lora,2:NB", required = true) @RequestParam Integer meterType
+            ) {
         RespData respData = new RespData();
         if(StringUtils.isNotBlank(apiKey) &&apiKey.equals(this.apiKey)){
             if(StringUtils.isNotBlank(imei.trim())){
-                respData = tianJinMeterReadingService.queryReadRecordData(imei.split(","),null);
+                respData = tianJinMeterReadingService.queryReadRecordData(imei.split(","),null,meterType);
             }else{
                 respData.setRtnId(RespData.FAIL);
                 respData.setRtnData(new ArrayList<>());

+ 2 - 1
meter-reading-tianjin/src/main/resources/application-tianjin-dev.properties

@@ -12,4 +12,5 @@ city.code=120100
 region.code=120112
 #ÅäÖýòÄÏ×ܹ«Ë¾µÄ¿Í»§ID
 customer.code=54
-device.type.code=20
+device.type.nb.code=20
+device.type.lora.code=15

+ 2 - 1
meter-reading-tianjin/src/main/resources/application-tianjin-prd.properties

@@ -12,4 +12,5 @@ city.code=120100
 region.code=120112
 #ÅäÖýòÄÏ×ܹ«Ë¾µÄ¿Í»§ID
 customer.code=29
-device.type.code=25
+device.type.nb.code=25
+device.type.lora.code=15

+ 2 - 1
meter-reading-tianjin/src/main/resources/application-tianjin-sit.properties

@@ -12,4 +12,5 @@ city.code=120100
 region.code=120112
 #ÅäÖýòÄÏ×ܹ«Ë¾µÄ¿Í»§ID
 customer.code=54
-device.type.code=20
+device.type.nb.code=20
+device.type.lora.code=15

+ 1 - 1
meter-reading-tianjin/src/test/java/com/huaxu/zoniot/MeterReadRecordTests.java

@@ -74,7 +74,7 @@ public class MeterReadRecordTests {
         String imeis = "862458040181858,868246044954071";
         Integer readDay = 20210110;
         RespData respData = tianJinMeterReadingService.
-                queryReadRecordData(imeis.split(","), readDay);
+                queryReadRecordData(imeis.split(","), readDay,1);
         System.out.println(JSON.toJSONString(respData));
 
     }