Browse Source

解决设备状态查询只能查询31天问题

优化管控记录描述内容
优化设备调用逻辑
develop
zhaoxianglong 9 months ago
parent
commit
6f2416a509
  1. 115
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 288
      zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java
  3. 2
      zc-business/src/main/resources/mapper/business/StatusMapper.xml

115
zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java

@ -534,23 +534,103 @@ public class DcDeviceController extends BaseController {
JSONObject device = (JSONObject) JSON.toJSON(dev); JSONObject device = (JSONObject) JSON.toJSON(dev);
//JSONObject device = (JSONObject) JSON.toJSON(dev.toString()); //JSONObject device = (JSONObject) JSON.toJSON(dev.toString());
String iotDeviceId = device.getString("iotDeviceId"); String iotDeviceId = device.getString("iotDeviceId");
String deviceType = device.getString("deviceType");
boolean continueToExecute = true;
if (Objects.equals(deviceType, "10")) {
JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, "MD").get("data"));
String mdValue = mdJSONObject.getString("value");
JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, "TM").get("data"));
String tmValue = tmJSONObject.getString("value");
for (Object function : functions) { for (Object function : functions) {
JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function);
//JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ;
String functionId = functionJSONObject.getString("functionId"); String functionId = functionJSONObject.getString("functionId");
if (continueToExecute) {
JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject();
JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject); JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject);
resultArray.add(result); resultArray.add(result);
AjaxResult ajaxResult = (AjaxResult) result.get("result"); AjaxResult ajaxResult = (AjaxResult) result.get("result");
if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) { if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) {
continueToExecute = false;
if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) { if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) {
return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue()); return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue());
}
}
} else {
List<Object> collect = resultArray.stream().filter(item -> Objects.equals(((JSONObject) JSON.toJSON(item)).getString("device"), device.getString("id"))).collect(Collectors.toList());
if (collect.size() == 0) {
JSONObject result = new JSONObject();
result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType"));
result.put("functionId", functionId);
result.put("result", AjaxResult.error());
resultArray.add(result);
} else { } else {
//return AjaxResult.success(resultArray); for (int i = 0; i < resultArray.size(); i++) {
JSONObject jsonObject = (JSONObject) JSON.toJSON(resultArray.get(i));
if (!Objects.equals(jsonObject.getString("device"), device.getString("id"))) {
JSONObject result = jsonObject.getJSONObject("result");
if (!Objects.equals(result.getString("code"), "200")) {
break;
} else {
result.put("code", "500");
jsonObject.put("result", result);
resultArray.add(i, jsonObject);
}
} else {
break;
}
}
} }
if (Objects.equals(functionId, "SETMD")) {
JSONObject jsonObjectMD = new JSONObject();
jsonObjectMD.put("SET", mdValue);
getAjaxResult(iotDeviceId, functionId, jsonObjectMD.toJavaObject(new TypeReference<HashMap<String, Object>>() {
}));
} }
if (Objects.equals(functionId, "SETTM")) {
JSONObject jsonObjectTM = new JSONObject();
jsonObjectTM.put("SET", tmValue);
getAjaxResult(iotDeviceId, functionId, jsonObjectTM.toJavaObject(new TypeReference<HashMap<String, Object>>() {
}));
} }
} }
}
} else {
for (Object function : functions) {
JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function);
//JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ;
String functionId = functionJSONObject.getString("functionId");
if (continueToExecute) {
JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject();
//JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject);
//resultArray.add(result);
//AjaxResult ajaxResult = (AjaxResult) result.get("result");
//if (!Objects.equals(String.valueOf(ajaxResult.get("code")), UniversalEnum.TWO_HUNDRED.getValue())) {
// continueToExecute = false;
// if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) {
// return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue());
// }
//}
} else {
JSONObject result = new JSONObject();
result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType"));
result.put("functionId", functionId);
result.put("result", AjaxResult.error());
resultArray.add(result);
}
}
}
}
return AjaxResult.success(resultArray); return AjaxResult.success(resultArray);
} }
@ -561,22 +641,22 @@ public class DcDeviceController extends BaseController {
result.put("device", device.getString("id")); result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType")); result.put("deviceType", device.getInteger("deviceType"));
result.put("functionId", functionId); result.put("functionId", functionId);
if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { //if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) {
JSONObject value = broadcastController.nearCamListDistance(jsonObject); // JSONObject value = broadcastController.nearCamListDistance(jsonObject);
AjaxResult ajaxResult = new AjaxResult(); // AjaxResult ajaxResult = new AjaxResult();
value.keySet().forEach(item -> { // value.keySet().forEach(item -> {
ajaxResult.put(item, value.getString(item)); // ajaxResult.put(item, value.getString(item));
}); // });
if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())){ // if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())) {
ajaxResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber()); // ajaxResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber());
}else { // } else {
ajaxResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber()); // ajaxResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber());
} // }
//
result.put("result", ajaxResult); // result.put("result", ajaxResult);
} else { //} else {
result.put("result", getAjaxResult(iotDeviceId, functionId, params)); // result.put("result", getAjaxResult(iotDeviceId, functionId, params));
} //}
return result; return result;
} }
@ -831,6 +911,7 @@ public class DcDeviceController extends BaseController {
String key = configService.selectConfigByKey(UniversalEnum.SBX_FUN_KL.getValue());//密钥 String key = configService.selectConfigByKey(UniversalEnum.SBX_FUN_KL.getValue());//密钥
return AjaxResult.success(key.equals(secretKey)); return AjaxResult.success(key.equals(secretKey));
} }
//设备分析 //设备分析
@PostMapping("/properties/deviceAnalysis") @PostMapping("/properties/deviceAnalysis")
public AjaxResult deviceAnalysis(@RequestBody HashMap map) throws IOException, HttpException { public AjaxResult deviceAnalysis(@RequestBody HashMap map) throws IOException, HttpException {

288
zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java

@ -81,6 +81,7 @@ public class OperationLogAspect {
put(UniversalEnum.THREE_C.getValue(), UniversalEnum.READ_THE_CURRENT_DEVICE_STATUS.getValue()); put(UniversalEnum.THREE_C.getValue(), UniversalEnum.READ_THE_CURRENT_DEVICE_STATUS.getValue());
}}); }});
put(UniversalEnum.THIRTEEN.getValue(), new HashMap<String, Object>() {{ put(UniversalEnum.THIRTEEN.getValue(), new HashMap<String, Object>() {{
put("102", "设备开关");
}}); }});
put(UniversalEnum.FOURTEEN.getValue(), new HashMap<String, Object>() {{ put(UniversalEnum.FOURTEEN.getValue(), new HashMap<String, Object>() {{
}}); }});
@ -93,6 +94,7 @@ public class OperationLogAspect {
put(UniversalEnum.A_SIX.getValue(), UniversalEnum.QUERY_DATA.getValue()); put(UniversalEnum.A_SIX.getValue(), UniversalEnum.QUERY_DATA.getValue());
}}); }});
put(UniversalEnum.SIXTEEN.getValue(), new HashMap<String, Object>() {{ put(UniversalEnum.SIXTEEN.getValue(), new HashMap<String, Object>() {{
put("102", "设备开关");
}}); }});
}}; }};
@ -104,7 +106,7 @@ public class OperationLogAspect {
@AfterThrowing(value = "@annotation(operationLog)", throwing = "e") @AfterThrowing(value = "@annotation(operationLog)", throwing = "e")
public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable { public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable {
around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ONE.getValue(), null, e); around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ONE.getValue(), AjaxResult.error(), e);
} }
public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable { public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable {
@ -208,21 +210,241 @@ public class OperationLogAspect {
return; return;
} }
remark.append(deviceName);
String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ?
UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : // UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() :
String.valueOf( // String.valueOf(
((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))) // ((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
.get(functionId) == null ? // .get(functionId) == null ?
UniversalEnum.UNKNOWN_METHOD.getValue() : // UniversalEnum.UNKNOWN_METHOD.getValue() :
((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))) // ((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
.get(functionId)); // .get(functionId));
//remark.append(hashMap).append(":");
remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); JSONObject params = function.getJSONObject("params");
if (Objects.equals(deviceType, "2")) {
//if (Objects.equals(functionId, UniversalEnum.ELEVEN.getValue())) {
//
// remark.append("文件名称:").append(params.getString("fileName")).append("、文件大小:").append(params.getString("size")).append("KB");
//
//} else
if (Objects.equals(functionId, UniversalEnum.THIRTEEN.getValue())) {
JSONArray parameters = params.getJSONArray("parameters");
for (int i2 = 0; i2 < parameters.size(); i2++) {
remark.append(((JSONObject) JSON.toJSON(parameters.get(i2))).getString("CONTENT"));
//remark.append("文件内容:").append(((JSONObject) JSON.toJSON(parameters.get(i2))).getString("CONTENT"));
if (i2 < parameters.size() - 1) {
remark.append("、");
}
}
}
//else if (Objects.equals(functionId, UniversalEnum.ONE_B.getValue())) {
//
// remark.append("文件标识:").append(params.getString("fileId"));
//
//}
} else if (Objects.equals(deviceType, "5")) {
remark.append(params.getString("text"));
} else if (Objects.equals(deviceType, "10")) {
String set = params.getString("SET");
if (Objects.equals(functionId, UniversalEnum.SETMD.getValue())) {
if (Objects.equals(set, "0")) {
remark.append("关闭");
} else if (Objects.equals(set, "1")) {
remark.append("常亮");
} else if (Objects.equals(set, "2")) {
remark.append("间隔100ms闪烁");
} else if (Objects.equals(set, "3")) {
remark.append("间隔200ms闪烁");
} else if (Objects.equals(set, "4")) {
remark.append("间隔500ms闪烁");
} else if (Objects.equals(set, "5")) {
remark.append("2次闪烁");
} else if (Objects.equals(set, "6")) {
remark.append("SOS");
} else if (Objects.equals(set, "7")) {
remark.append("自定义闪烁时间");
}
remark.append("模式");
} else if (Objects.equals(functionId, UniversalEnum.SETTM.getValue())) {
remark.append(set).append("分钟");
}
} else if (Objects.equals(deviceType, "12")) {
if (Objects.equals(functionId, "51")) {
//remark.append("模式:");
String mode = params.getString("mode");
if (Objects.equals(mode, "00")) {
remark.append("远程手动控制模式:上行:");
String onWorkStatus = params.getString("onWorkStatus");
String inWorkStatus = params.getString("inWorkStatus");
if (Objects.equals(onWorkStatus, "00")) {
remark.append("不更新状态,下行:");
} else if (Objects.equals(onWorkStatus, "01")) {
remark.append("常亮,下行:");
} else if (Objects.equals(onWorkStatus, "02")) {
remark.append("流水,下行:");
} else if (Objects.equals(onWorkStatus, "03")) {
remark.append("闪烁,下行:");
} else if (Objects.equals(onWorkStatus, "04")) {
remark.append("关闭,下行:");
}
if (Objects.equals(inWorkStatus, "00")) {
remark.append("不更新状态");
} else if (Objects.equals(inWorkStatus, "01")) {
remark.append("常亮");
} else if (Objects.equals(inWorkStatus, "02")) {
remark.append("流水");
} else if (Objects.equals(inWorkStatus, "03")) {
remark.append("闪烁");
} else if (Objects.equals(inWorkStatus, "04")) {
remark.append("关闭");
}
} else if (Objects.equals(mode, "01")) {
remark.append("时间段自动控制模式:")
.append(params.getString("startDisplayTime"))
.append("-")
.append(params.getString("endDisplayTime"));
} else if (Objects.equals(mode, "02")) {
remark.append("万年历自动控制模式");
} else if (Objects.equals(mode, "03")) {
remark.append("能见度自动控制模式");
}
} else if (Objects.equals(functionId, "30")) {
String onWorkStatus = params.getString("onWorkStatus");
String inWorkStatus = params.getString("inWorkStatus");
if (Objects.equals(onWorkStatus, "00")) {
remark.append("上行:不更新状态,下行:");
} else if (Objects.equals(onWorkStatus, "01")) {
remark.append("上行:常亮,下行:");
} else if (Objects.equals(onWorkStatus, "02")) {
remark.append("上行:流水,下行:");
} else if (Objects.equals(onWorkStatus, "03")) {
remark.append("上行:闪烁,下行:");
} else if (Objects.equals(onWorkStatus, "04")) {
remark.append("上行:关闭,下行:");
}
if (Objects.equals(inWorkStatus, "00")) {
remark.append("不更新状态");
} else if (Objects.equals(inWorkStatus, "01")) {
remark.append("常亮");
} else if (Objects.equals(inWorkStatus, "02")) {
remark.append("流水");
} else if (Objects.equals(inWorkStatus, "03")) {
remark.append("闪烁");
} else if (Objects.equals(inWorkStatus, "04")) {
remark.append("关闭");
}
}
if (i1 < functions.size() - UniversalEnum.ONE.getNumber()) { }
remark.append(UniversalEnum.SEMICOLON.getValue());
//remark.append(deviceName);
//String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ?
// UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() :
// String.valueOf(
// ((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
// .get(functionId) == null ?
// UniversalEnum.UNKNOWN_METHOD.getValue() :
// ((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
// .get(functionId));
//remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue());
if (i1 < functions.size() - UniversalEnum.ONE.getNumber() && !Objects.equals(deviceType, "2")) {
remark.append(UniversalEnum.COMMA.getValue());
} }
@ -239,7 +461,7 @@ public class OperationLogAspect {
} }
if (i < (devices.size() - UniversalEnum.ONE.getNumber())) { if (i < (devices.size() - UniversalEnum.ONE.getNumber())) {
remark.append(UniversalEnum.COMMA.getValue()); remark.append(UniversalEnum.UNDERLINE.getValue());
} }
} }
@ -317,6 +539,8 @@ public class OperationLogAspect {
String functionId = String.valueOf(pointArgs[UniversalEnum.ONE.getNumber()]); String functionId = String.valueOf(pointArgs[UniversalEnum.ONE.getNumber()]);
JSONObject params = (JSONObject) JSON.toJSON(pointArgs[UniversalEnum.TWO.getNumber()]);
if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) || if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) || Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) || Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) ||
@ -332,9 +556,39 @@ public class OperationLogAspect {
return; return;
} }
String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue())
// ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue()
// : String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
//
//remark.append(hashMap).append(":");
if (Objects.equals(deviceType, "13") || Objects.equals(deviceType, "16")) {
String identification = params.getString("deviceName");
String value = params.getString("value");
if (Objects.equals(identification, "ac_out_1_en")) {
remark.append("220V 输出 1").append(Objects.equals(value, "1") ? "打开" : "关闭");
} else if (Objects.equals(identification, "ac_out_2_en")) {
remark.append("220V 输出 2").append(Objects.equals(value, "1") ? "打开" : "关闭");
} else if (Objects.equals(identification, "dc_out_1_en")) {
remark.append(deviceName).append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); remark.append("12V 输出 1").append(Objects.equals(value, "1") ? "打开" : "关闭");
} else if (Objects.equals(identification, "dc_out_2_en")) {
remark.append("12V 输出 2").append(Objects.equals(value, "1") ? "打开" : "关闭");
} else if (Objects.equals(identification, "fan_out_en")) {
remark.append("风扇").append(Objects.equals(value, "1") ? "打开" : "关闭");
}
}
if (loginUser != null) { if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
@ -396,7 +650,7 @@ public class OperationLogAspect {
operLog.setOperTime(new Date()); operLog.setOperTime(new Date());
operLog.setDcDeviceType(deviceType); operLog.setDcDeviceType(deviceType);
operLog.setRemark(remark.toString()); operLog.setRemark(remark.toString());
operLog.setJsonResult(jsonResult.toJSONString()); operLog.setJsonResult(jsonResult != null ? jsonResult.toJSONString() : AjaxResult.error().toString());
dcOperLogService.save(operLog); dcOperLogService.save(operLog);
} }
} }

2
zc-business/src/main/resources/mapper/business/StatusMapper.xml

@ -261,7 +261,7 @@
GROUP BY GROUP BY
d.child_type, d.child_type,
d.device_type, d.device_type,
DAY (s.time) DATE_FORMAT(s.time, '%Y-%m-%d')
</where> </where>
<if test="status.orderByField != null and status.orderDirection != null"> <if test="status.orderByField != null and status.orderDirection != null">
ORDER BY ${status.orderByField} ${status.orderDirection} ORDER BY ${status.orderByField} ${status.orderDirection}

Loading…
Cancel
Save