|
|
@@ -6,6 +6,7 @@ import com.yunfeiyun.agmp.common.core.domain.AjaxResult;
|
|
|
import com.yunfeiyun.agmp.common.utils.DateUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.JSONUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.StringUtils;
|
|
|
+import com.yunfeiyun.agmp.common.utils.spring.SpringUtils;
|
|
|
import com.yunfeiyun.agmp.common.utils.uuid.IdUtils;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.IotErrorCode;
|
|
|
import com.yunfeiyun.agmp.iot.common.constant.devicetype.IotDeviceDictConst;
|
|
|
@@ -22,6 +23,7 @@ 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 com.yunfeiyun.agmp.iots.warn.service.WarnService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
@@ -44,7 +46,8 @@ import java.util.concurrent.CompletableFuture;
|
|
|
@RequestMapping("/test")
|
|
|
@Slf4j
|
|
|
public class TestController {
|
|
|
-
|
|
|
+ @Autowired
|
|
|
+ private IIotDeviceService iIotDeviceService;
|
|
|
|
|
|
@Resource(name = "threadPoolTaskExecutor")
|
|
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
|
@@ -609,11 +612,11 @@ public class TestController {
|
|
|
String devCode = req.getDevCode();
|
|
|
JSONObject data = req.getData();
|
|
|
|
|
|
- if(StringUtils.isEmpty(devCode)) {
|
|
|
+ if (StringUtils.isEmpty(devCode)) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备编码为空");
|
|
|
}
|
|
|
|
|
|
- if(data == null) {
|
|
|
+ if (data == null) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "数据为空");
|
|
|
}
|
|
|
|
|
|
@@ -621,7 +624,7 @@ public class TestController {
|
|
|
if (iotDeviceList == null || iotDeviceList.isEmpty()) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
|
|
|
}
|
|
|
- if(iotDeviceList.size() > 1) {
|
|
|
+ if (iotDeviceList.size() > 1) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不唯一");
|
|
|
}
|
|
|
IotDevice iotDevice = iotDeviceList.get(0);
|
|
|
@@ -629,11 +632,11 @@ public class TestController {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
|
|
|
}
|
|
|
String devtypeBid = iotDevice.getDevtypeBid();
|
|
|
- if(QxzTypeUtil.isYfCommQxz(devtypeBid)){
|
|
|
+ if (QxzTypeUtil.isYfCommQxz(devtypeBid)) {
|
|
|
YfQxzDeviceImpl yfQxzDevice = (YfQxzDeviceImpl) iYfQxzDevice;
|
|
|
String devUpdateddate = DateUtils.dateTimeNow();
|
|
|
yfQxzDevice.processData(iotDevice, data, devUpdateddate);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备类型不支持");
|
|
|
}
|
|
|
return AjaxResult.success();
|
|
|
@@ -641,9 +644,9 @@ public class TestController {
|
|
|
|
|
|
public Class getTableClass(String devtypeBid) {
|
|
|
Class tableClass = null;
|
|
|
- if(QxzTypeUtil.isXphYfQxSq(devtypeBid)){
|
|
|
+ if (QxzTypeUtil.isXphYfQxSq(devtypeBid)) {
|
|
|
tableClass = IotXphYfqxzdata.class;
|
|
|
- }else if(QxzTypeUtil.isYfQxSq(devtypeBid)){
|
|
|
+ } else if (QxzTypeUtil.isYfQxSq(devtypeBid)) {
|
|
|
tableClass = IotYfqxzdata.class;
|
|
|
}
|
|
|
// else if (devtypeBid.equals(IotDeviceDictConst.TYPE_ADZN_GSSQ)) {
|
|
|
@@ -655,6 +658,7 @@ public class TestController {
|
|
|
|
|
|
/**
|
|
|
* 设备上报数据
|
|
|
+ *
|
|
|
* @param req
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
@@ -663,7 +667,7 @@ public class TestController {
|
|
|
public AjaxResult getDevData(WarnTestReq req) throws Exception {
|
|
|
String devCode = req.getDevCode();
|
|
|
|
|
|
- if(StringUtils.isEmpty(devCode)) {
|
|
|
+ if (StringUtils.isEmpty(devCode)) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备编码为空");
|
|
|
}
|
|
|
|
|
|
@@ -671,16 +675,16 @@ public class TestController {
|
|
|
if (iotDeviceList == null || iotDeviceList.isEmpty()) {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备不存在");
|
|
|
}
|
|
|
- if(iotDeviceList.size() > 1) {
|
|
|
+ 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)){
|
|
|
+ if (QxzTypeUtil.isYfCommQxz(devtypeBid)) {
|
|
|
Class tableClass = getTableClass(devtypeBid);
|
|
|
- if(tableClass == null){
|
|
|
+ if (tableClass == null) {
|
|
|
throw new IotBizException(ErrorCode.INVALID_PARAMETER.getCode(), "设备类型不存在");
|
|
|
}
|
|
|
|
|
|
@@ -688,7 +692,7 @@ public class TestController {
|
|
|
String devldContent = iotDevicelasteddata.getDevldContent();
|
|
|
List jsonList = JSONUtils.toList(devldContent);
|
|
|
List<Map<String, String>> dataList = new ArrayList<>();
|
|
|
- for(Object dataObj : jsonList){
|
|
|
+ for (Object dataObj : jsonList) {
|
|
|
JSONObject jsonData = JSONObject.from(dataObj);
|
|
|
Map<String, String> dataMap = new HashMap<>();
|
|
|
dataMap.put("eNum", jsonData.getString("eNum"));
|
|
|
@@ -700,8 +704,32 @@ public class TestController {
|
|
|
JSONObject data = new JSONObject();
|
|
|
data.put("data", dataList);
|
|
|
return AjaxResult.success(data);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw new IotBizException(IotErrorCode.FAILURE.getCode(), "设备类型不支持");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping("/warn/cmd/offline")
|
|
|
+ public AjaxResult cmdOffline(WarnTestReq req) {
|
|
|
+ List<IotDevice> oldIotDevice = iIotDeviceService.selectIotDeviceByDevCode(req.getDevCode());
|
|
|
+ for (IotDevice iotDevice : oldIotDevice) {
|
|
|
+ IotDevice newIotDevice = new IotDevice();
|
|
|
+ newIotDevice.setDevBid(iotDevice.getDevBid());
|
|
|
+ newIotDevice.setDevOriginalStatus(iotDevice.getDevStatus());
|
|
|
+ newIotDevice.setDevStatus("0");
|
|
|
+ newIotDevice.setDevOfflinedate(DateUtils.dateTimeNow());
|
|
|
+ newIotDevice.setTid(iotDevice.getTid());
|
|
|
+ newIotDevice.setDevtypeBid(iotDevice.getDevtypeBid());
|
|
|
+ newIotDevice.setDevCreateddate(iotDevice.getDevCreateddate());
|
|
|
+ newIotDevice.setDevUpdateddate(iotDevice.getDevUpdateddate());
|
|
|
+ newIotDevice.setDevCode(iotDevice.getDevCode());
|
|
|
+ iIotDeviceService.updateIotDevice(newIotDevice);
|
|
|
+ //发送离线预警
|
|
|
+ SpringUtils.getBean(WarnService.class).processWarningOfflineData(newIotDevice, JSONObject.from(iotDevice));
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|