Просмотр исходного кода

新增 气象站预警手动触发接口

zhaiyifei 9 месяцев назад
Родитель
Сommit
dbdce346a6

+ 71 - 0
src/main/java/com/yunfeiyun/agmp/iots/device/controller/TestController.java

@@ -1,6 +1,7 @@
 package com.yunfeiyun.agmp.iots.device.controller;
 
 import com.alibaba.fastjson2.JSONObject;
+import com.yunfeiyun.agmp.common.constant.ErrorCode;
 import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
 import com.yunfeiyun.agmp.common.utils.DateUtils;
 import com.yunfeiyun.agmp.common.utils.JSONUtils;
@@ -19,6 +20,7 @@ import com.yunfeiyun.agmp.iots.device.mapper.IotDeviceMapper;
 import com.yunfeiyun.agmp.iots.device.service.IYfQxzDevice;
 import com.yunfeiyun.agmp.iots.device.serviceImp.YfQxzDeviceImpl;
 import com.yunfeiyun.agmp.iots.service.IIotDeviceService;
+import com.yunfeiyun.agmp.iots.service.IIotDevicelasteddataService;
 import com.yunfeiyun.agmp.iots.service.IIotYfScddataService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -71,6 +73,9 @@ public class TestController {
     @Autowired
     private IYfQxzDevice iYfQxzDevice;
 
+    @Autowired
+    private IIotDevicelasteddataService iIotDevicelasteddataService;
+
     private static final Random random = new Random();
     private static final DateTimeFormatter stampFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
 
@@ -633,4 +638,70 @@ public class TestController {
         }
         return AjaxResult.success();
     }
+
+    public Class getTableClass(String devtypeBid) {
+        Class tableClass = null;
+        if(QxzTypeUtil.isXphYfQxSq(devtypeBid)){
+            tableClass = IotXphYfqxzdata.class;
+        }else if(QxzTypeUtil.isYfQxSq(devtypeBid)){
+            tableClass = IotYfqxzdata.class;
+        }
+//        else if (devtypeBid.equals(IotDeviceDictConst.TYPE_ADZN_GSSQ)) {
+//            tableClass = IotAdznGssqdata.class;
+//        }
+        return tableClass;
+    }
+
+
+    /**
+     * 设备上报数据
+     * @param req
+     * @return
+     * @throws Exception
+     */
+    @GetMapping("/warn/dev/data")
+    public AjaxResult getDevData(WarnTestReq req) throws Exception {
+        String devCode = req.getDevCode();
+
+        if(StringUtils.isEmpty(devCode)) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备编码为空");
+        }
+
+        List<IotDevice> iotDeviceList = iotDeviceService.selectIotDeviceByDevCode(devCode);
+        if (iotDeviceList == null || iotDeviceList.isEmpty()) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
+        }
+        if(iotDeviceList.size() > 1) {
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不唯一");
+        }
+        IotDevice iotDevice = iotDeviceList.get(0);
+
+        String devtypeBid = iotDevice.getDevtypeBid();
+        String devBid = iotDevice.getDevBid();
+        if(QxzTypeUtil.isYfCommQxz(devtypeBid)){
+            Class tableClass = getTableClass(devtypeBid);
+            if(tableClass == null){
+                throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
+            }
+
+            IotDevicelasteddata iotDevicelasteddata = iIotDevicelasteddataService.selectDeviceLastedDataBydevBid(devBid);
+            String devldContent = iotDevicelasteddata.getDevldContent();
+            List jsonList = JSONUtils.toList(devldContent);
+            List<Map<String, String>> dataList = new ArrayList<>();
+            for(Object dataObj : jsonList){
+                JSONObject jsonData = JSONObject.from(dataObj);
+                Map<String, String> dataMap = new HashMap<>();
+                dataMap.put("eNum", jsonData.getString("eNum"));
+                dataMap.put("eName", jsonData.getString("eName"));
+                dataMap.put("eValue", jsonData.getString("eValue"));
+                dataMap.put("eKey", jsonData.getString("eKey"));
+                dataList.add(dataMap);
+            }
+            JSONObject data = new JSONObject();
+            data.put("data", dataList);
+            return AjaxResult.success(data);
+        }else{
+            throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备类型不支持");
+        }
+    }
 }