Ver código fonte

lora188协议阀门控制

lin 4 anos atrás
pai
commit
b9a150fe08

+ 9 - 1
smart-city-intf/src/main/java/com/zcxk/smartcity/data/access/service/impl/DeviceDataServiceImpl.java

@@ -504,11 +504,19 @@ public class DeviceDataServiceImpl implements DeviceDataService {
 		// 2,判断设备是否水表,如果是水表则保存读数
 		if(device.getIsWater() == 1) {
 			MeasuringData wsvData = dataMap.get("WSV");
-			if(wsvData != null) {
+			MeasuringData valveData = dataMap.get("VALVE");
+			if(wsvData != null || valveData !=null) {
 				WaterMeterErrorDays record = new WaterMeterErrorDays();
 				record.setDeviceId(device.getId());
 				record.setMeterReading(Double.parseDouble(wsvData.getMeasuringVaule()));
 				record.setStatus(1);
+				if (valveData.getMeasuringVaule() != null) {
+					if("00".equals(valveData.getMeasuringVaule())){//00开,01关,11异常
+						record.setValveStatus(1);
+					}else {
+						record.setValveStatus(0);
+					}
+				}
 				waterMeterErrorDaysMapper.insertSelective(record);
 			}
 		}

+ 38 - 20
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/DeviceServiceImpl.java

@@ -14,6 +14,8 @@ import com.bz.smart_city.dto.assistant.PlanCommunityDTO;
 import com.bz.smart_city.dto.udip.DataCommandRequestDTO;
 import com.bz.smart_city.entity.*;
 import com.bz.smart_city.service.*;
+import com.bz.smart_city.service.udip.EasylinkinUtils;
+import com.bz.smart_city.service.udip.Lora188Parser;
 import com.bz.smart_city.service.udip.UdipEtlDataCommandService;
 import com.bz.smart_city.service.udip.UdipUnitService;
 import com.github.pagehelper.PageHelper;
@@ -98,6 +100,8 @@ public  class DeviceServiceImpl implements DeviceService {
     private UdipEtlDataCommandService udipEtlDataCommandService;
     @Autowired
     private DeviceValveRecordService deviceValveRecordService;
+    @Autowired
+    private EasylinkinUtils easylinkinUtils;
 
     @Override
     public int insert(Device device) {
@@ -1339,32 +1343,46 @@ public  class DeviceServiceImpl implements DeviceService {
             }
         }
 
-        if (device.getUdipId() != null && !"".equals(device.getUdipId())) {
+        if(device.getDeviceType()==30){
             //1、下发开关阀门
             Map<String,Object> map = new HashMap<>();
-            map.put("electronicNo","AAAAAAAAAAAAAA");
-            map.put("valveStatus", sendValveStatus);//阀门状态  0:关阀 1:开阀
-            DataCommandRequestDTO dataCommandRequest = new DataCommandRequestDTO();
-            dataCommandRequest.setDeviceId(device.getUdipId());
-            dataCommandRequest.setUnitIdentifier(device.getDeviceNo());
-            dataCommandRequest.setReceiveTime(new Date());
-            dataCommandRequest.setMethod("WriteValve");
-            dataCommandRequest.setParams(map);
-            JSONObject commandResult = udipEtlDataCommandService.commandSend(dataCommandRequest);
-
-            //2、插入开关阀门记录
-            DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
-            deviceValveRecord.setDeviceId(deviceId);
-            deviceValveRecord.setSendValveStatus(Integer.valueOf(sendValveStatus));
-            deviceValveRecord.setSendStatus(1);
-            deviceValveRecord.setCommandId(commandResult.getString("commandId"));
-            deviceValveRecord.setCommandStatus(commandResult.getString("status"));
-            deviceValveRecord.setRemark("");
-            deviceValveRecordService.insertSelective(deviceValveRecord);
+            Map<String,Object> paras = new HashMap<>();
+            paras.put("electronicNo",device.getWaterMeterNo());
+            paras.put("valveStatus", sendValveStatus);//阀门状态  0:关阀 1:开阀
+            map.put("params", paras);
+            map.put("method", "WriteValve");
+            easylinkinUtils.sendDownlink(device.getDeviceNo(),map);
+        }else
+        {
+            if (device.getUdipId() != null && !"".equals(device.getUdipId())) {
+                //1、下发开关阀门
+                Map<String,Object> map = new HashMap<>();
+                map.put("electronicNo","AAAAAAAAAAAAAA");
+                map.put("valveStatus", sendValveStatus);//阀门状态  0:关阀 1:开阀
+                DataCommandRequestDTO dataCommandRequest = new DataCommandRequestDTO();
+                dataCommandRequest.setDeviceId(device.getUdipId());
+                dataCommandRequest.setUnitIdentifier(device.getDeviceNo());
+                dataCommandRequest.setReceiveTime(new Date());
+                dataCommandRequest.setMethod("WriteValve");
+                dataCommandRequest.setParams(map);
+                JSONObject commandResult = udipEtlDataCommandService.commandSend(dataCommandRequest);
+
+                //2、插入开关阀门记录
+                DeviceValveRecord deviceValveRecord = new DeviceValveRecord();
+                deviceValveRecord.setDeviceId(deviceId);
+                deviceValveRecord.setSendValveStatus(Integer.valueOf(sendValveStatus));
+                deviceValveRecord.setSendStatus(1);
+                deviceValveRecord.setCommandId(commandResult.getString("commandId"));
+                deviceValveRecord.setCommandStatus(commandResult.getString("status"));
+                deviceValveRecord.setRemark("");
+                deviceValveRecordService.insertSelective(deviceValveRecord);
+            }
         }
 
 
 
+
+
         //3、更新按钮阀门状态
         WaterMeterErrorDays waterMeterErrorDayUpdate = new WaterMeterErrorDays();
         waterMeterErrorDayUpdate.setDeviceId(deviceId);

+ 51 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/udip/EasylinkinUtils.java

@@ -0,0 +1,51 @@
+package com.bz.smart_city.service.udip;
+
+import com.bz.smart_city.commom.exception.ServiceException;
+import com.bz.smart_city.commom.util.HttpRequest;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+
+@Slf4j
+@Service
+public class EasylinkinUtils {
+
+    public void sendDownlink(String deviceNo, Map<String, Object> mapData){
+        Lora188Parser lora188Parser = new Lora188Parser();
+        Map<String,Object> resultMap = lora188Parser.protocolToRawData(mapData);
+        Integer status = (Integer) resultMap.get("status");
+        String data = "";
+        if(status == 0){
+            data = (String) resultMap.get("data");
+        }else {
+            throw new ServiceException(-900, "协议解析错误");
+        }
+
+        String url = "http://api.easylinkin.com/api/v1/application/downlink?";
+        Map<String,Object> map = new HashMap<>();
+        map.put("mac",deviceNo);
+        map.put("token","huaxu180820");
+        map.put("appeui","2C26C501241E0000");
+        map.put("payload",data);
+        map.put("ttl","2h");
+        map.put("payloadType","1");
+        map.put("confirmed",true);
+        String temp = "";
+        for (String key : map.keySet()) {
+            temp += "&" + key + "=" +map.get(key);
+        }
+        url += temp.substring(1);
+        System.out.println(url);
+        try {
+            String result = HttpRequest.doGet(url);
+            log.info(result);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+}