Преглед на файлове

天津接口增加地埋表类型 PengDi@2021/4/1

pengdi@zoniot.com преди 3 години
родител
ревизия
69744b85eb

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

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

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

@@ -57,8 +57,11 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
     @Value("${customer.code}")
     Integer customerCode ;
 
-    @Value("${device.type.nb.code}")
-    Integer deviceTypeNBCode ;
+    @Value("${device.type.nb.tj.code}")
+    Integer deviceTypeNBTjCode ;
+
+    @Value("${device.type.nb.188.code}")
+    Integer deviceTypeNB188Code ;
 
     @Value("${device.type.lora.code}")
     Integer deviceTypeLoraCode ;
@@ -114,10 +117,15 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
                     waterMeter.setDeviceNo(crmInfo.getNccid());
                 }
             }
-            else if(request.getMeterType() == 2){
+            else{
                 // nb表
                 waterMeter.setDeviceNo(request.getImei());
-                waterMeter.setDeviceTypeId(deviceTypeNBCode);
+                if(request.getMeterType() == 2){
+                    waterMeter.setDeviceTypeId(deviceTypeNBTjCode);
+                }
+                else if(request.getMeterType() == 3){
+                    waterMeter.setDeviceTypeId(deviceTypeNB188Code);
+                }
                 // 校验设备是否已经注册
                 WaterMeter exists = waterMeterMapper.findWaterMeterByDeviceNoAndCustomerList(request.getImei(),customerIds);
                 if(exists != null){
@@ -266,16 +274,107 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
             buildRtnDataForLora(meterReadRecord,rtnData);
         }
         else if(meterType == 2){
-            // 进行NB数据处理
+            // 进行NB天津协议处理
             buildRtnDataForNB(meterReadRecord,rtnData);
         }
+        else if(meterType == 3){
+            // 进行NB188协议处理
+            buildRtnDataForNB188(meterReadRecord,rtnData);
+        }
     }
 
+    /**
+     * @param meterReadRecord
+     * @param rtnData
+     */
+    protected  void buildRtnDataForNB188(MeterReadRecord meterReadRecord,RtnData rtnData){
+        Map<String, String> lastSendData = meterReadRecord.getLastSendData();
+        // 1:关阀 ,0:其他
+        rtnData.setValve(meterReadRecord.getValveState() == 0 ? "1":"0");
+        String batteryQuantity = lastSendData.get("VolStatus");
+        rtnData.setBatteryVotage(batteryQuantity);
+        // 没有的数据默认填0
+        rtnData.setBaseStationID("0");
+        rtnData.setSignalIntensity(lastSendData.get("CSQ"));
+        List<String> stateList = processWaterMeterStateForNB188(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("正常");
+    }
+    /**
+     * 返回数据格式第一位为是否告警,0:正常,1:有告警
+     * 第二位告警信息,多个告警信息拼接一起
+     *  {
+     *               "CSQ" : "19",
+     *               "RemoveStatus" : "0",
+     *               "VolStatus" : "0",
+     *               "valveState" : "10",
+     *               "SNR" : "11",
+     *               "ElectronicNo" : "18001201002269",
+     *               "TIME" : "20210401012615",
+     *               "ForcedStatus" : "0",
+     *               "DistrubStatus" : "0",
+     *               "currentQuantity" : "0.6"
+     *  }
+     * @param data
+     * @return
+     */
+    protected  List<String> processWaterMeterStateForNB188(Map<String, String> data){
+        List<String> result = new ArrayList<>();
+        // 以下报警信息均,0:正常,1:报警
+        String meterState = "0";
+        StringBuffer waringMessage =  new StringBuffer();
+        // 低电告警
+        String lowVoltageWarning = data.get("VolStatus");
+        if(RtnData.ALARM_STATE_ERROR.equals(lowVoltageWarning)){
+            waringMessage.append("低电告警,");
+            meterState = "1";
+        }
+        // 磁干扰告警
+        String magneticInterWarning = data.get("DistrubStatus");
+        if(RtnData.ALARM_STATE_ERROR.equals(magneticInterWarning)){
+            waringMessage.append("磁干扰告警,");
+            meterState = "1";
+        }
+        // 电子模块分离告警
+        String eleModuleWarning = data.get("RemoveStatus");
+        if(RtnData.ALARM_STATE_ERROR.equals(eleModuleWarning)){
+            waringMessage.append("电子模块分离告警,");
+            meterState = "1";
+        }
+        // 阀门异常告警
+        String valveWaring = data.get("valveState");
+        if("11".equals(valveWaring)){
+            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 buildRtnDataForLora(MeterReadRecord meterReadRecord,RtnData rtnData){
         // 获取如下信息:基站ID-->cellID,电池电量,信号强度-->CSQ,阀门状态,水表状态,水表状态信息
         Map<String, String> lastSendData = meterReadRecord.getLastSendData();
-        String valveState = lastSendData.get("VALVE");
-        rtnData.setValve(valveState);
+        // 1:关阀 ,0:其他
+        rtnData.setValve(meterReadRecord.getValveState() == 0 ? "1":"0");
 
         String batteryQuantity = lastSendData.get("VOL");
         rtnData.setBatteryVotage(batteryQuantity);
@@ -339,8 +438,8 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
         // 获取如下信息:基站ID-->cellID,电池电量,信号强度-->CSQ,阀门状态,水表状态,水表状态信息
         Map<String, String> lastSendData = meterReadRecord.getLastSendData();
 
-        String valveState = lastSendData.get("valveState");
-        rtnData.setValve(valveState);
+        // 1:关阀 ,0:其他
+        rtnData.setValve(meterReadRecord.getValveState() == 0 ? "1":"0");
 
         String batteryQuantity = lastSendData.get("batteryQuantity");
         rtnData.setBatteryVotage(batteryQuantity);
@@ -459,7 +558,7 @@ public class TianJinMeterReadingServiceImpl implements TianJinMeterReadingServic
             // 表类型为Lora时,imei对应为物联网平台电子号;
             waterMeter = waterMeterMapper.findWaterMeterByMeterNoAndCustomerList(imei,customerIds);
         }
-        else if(meterType == 2){
+        else if(meterType == 2 || meterType == 3){
             // 表类型为NB时,imei对应为物联网平台设备编号;
             waterMeter = waterMeterMapper.findWaterMeterByDeviceNoAndCustomerList(imei,customerIds);
         }

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

@@ -43,8 +43,9 @@ public class IntegrationController {
 
     /**
      *  天津查询数据接口,根据IMEI号查询当天的抄表数据
-     *  新增MeterType参数,1:LoRa ,2:NB ;LoRa表查询数据为前一天数据,NB表查询数据为今日数据
-     *  当查询表型为LoRa时,IMEI对应为平台中电子号,dang
+     *  新增MeterType参数,1:LoRa ,2:NB,3:地埋表 ;LoRa表查询数据为前一天数据,NB表查询数据为今日数据
+     *  当查询表型为LoRa时,IMEI对应为平台中电子号;
+     *  备注:地埋表也为NB表,此处NB表为天津协议,地埋表为188协议
      * @param imei
      * @param apiKey
      * @return
@@ -54,7 +55,7 @@ public class IntegrationController {
     public RespData queryReadRecordData(
             @ApiParam(value = "IMEI号,多个逗号分隔", required = true)@RequestParam String imei ,
             @ApiParam(value = "apiKey", required = true) @RequestParam String apiKey,
-            @ApiParam(value = "表类型,1:Lora,2:NB", required = true) @RequestParam Integer meterType
+            @ApiParam(value = "表类型,1:Lora,2:NB,3:地埋表", required = true) @RequestParam Integer meterType
             ) {
         RespData respData = new RespData();
         if(StringUtils.isNotBlank(apiKey) &&apiKey.equals(this.apiKey)){
@@ -105,7 +106,7 @@ public class IntegrationController {
     @PostMapping("/queryIMEI")
     @ApiOperation(value = "查询是否已注册")
     public RespData queryIMEI(  @ApiParam(value = "水表编号", required = true)@RequestParam String imei ,
-                                @ApiParam(value = "表类型,1:LoRa,2:NB",required = true,defaultValue="2")@RequestParam(defaultValue="2") Integer meterType ,
+                                @ApiParam(value = "表类型,1:LoRa,2:NB天津协议,3:NB188(地埋表)",required = true,defaultValue="2")@RequestParam(defaultValue="2") Integer meterType ,
                                 @ApiParam(value = "apiKey", required = true)@RequestParam String apiKey) {
         RespData respData = new RespData();
         if(StringUtils.isNotBlank(apiKey)&& apiKey.equals(this.apiKey)){

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

@@ -12,5 +12,8 @@ city.code=120100
 region.code=120112
 #配置津南总公司的客户ID
 customer.code=54
-device.type.nb.code=20
+#nb天津协议
+device.type.nb.tj.code=20
+#nb188协议
+device.type.nb.188.code=21
 device.type.lora.code=15

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

@@ -12,5 +12,9 @@ city.code=120100
 region.code=120112
 #配置津南总公司的客户ID
 customer.code=29
-device.type.nb.code=25
+#nb天津协议
+device.type.nb.tj.code=25
+#nb188协议
+device.type.nb.188.code=26
 device.type.lora.code=15
+

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

@@ -12,5 +12,8 @@ city.code=120100
 region.code=120112
 #配置津南总公司的客户ID
 customer.code=54
-device.type.nb.code=20
+#nb天津协议
+device.type.nb.tj.code=20
+#nb188协议
+device.type.nb.188.code=21
 device.type.lora.code=15