diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index b1cdbaac..48da7ae8 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -534,22 +534,102 @@ public class DcDeviceController extends BaseController { JSONObject device = (JSONObject) JSON.toJSON(dev); //JSONObject device = (JSONObject) JSON.toJSON(dev.toString()); String iotDeviceId = device.getString("iotDeviceId"); - for (Object function : functions) { - JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function); - //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; - String functionId = functionJSONObject.getString("functionId"); - 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())) { - if (Objects.equals(device.getString("deviceType"), UniversalEnum.FIFTEEN.getValue())) { - return AjaxResult.error(UniversalEnum.TWO_HUNDRED.getNumber(), UniversalEnum.FIVE_HUNDRED.getValue()); + 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) { + 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 { - //return AjaxResult.success(resultArray); + List 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 { + 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>() { + })); + } + if (Objects.equals(functionId, "SETTM")) { + JSONObject jsonObjectTM = new JSONObject(); + jsonObjectTM.put("SET", tmValue); + getAjaxResult(iotDeviceId, functionId, jsonObjectTM.toJavaObject(new TypeReference>() { + })); + } + } + } + } 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); } @@ -561,22 +641,22 @@ public class DcDeviceController extends BaseController { result.put("device", device.getString("id")); result.put("deviceType", device.getInteger("deviceType")); result.put("functionId", functionId); - if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { - JSONObject value = broadcastController.nearCamListDistance(jsonObject); - AjaxResult ajaxResult = new AjaxResult(); - value.keySet().forEach(item -> { - ajaxResult.put(item, value.getString(item)); - }); - if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())){ - ajaxResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber()); - }else { - ajaxResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber()); - } - - result.put("result", ajaxResult); - } else { - result.put("result", getAjaxResult(iotDeviceId, functionId, params)); - } + //if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { + // JSONObject value = broadcastController.nearCamListDistance(jsonObject); + // AjaxResult ajaxResult = new AjaxResult(); + // value.keySet().forEach(item -> { + // ajaxResult.put(item, value.getString(item)); + // }); + // if (Objects.equals(String.valueOf(ajaxResult.get("retCode")), UniversalEnum.ZERO.getValue())) { + // ajaxResult.put("code", UniversalEnum.TWO_HUNDRED.getNumber()); + // } else { + // ajaxResult.put("code", UniversalEnum.FIVE_HUNDRED.getNumber()); + // } + // + // result.put("result", ajaxResult); + //} else { + // result.put("result", getAjaxResult(iotDeviceId, functionId, params)); + //} return result; } @@ -798,8 +878,8 @@ public class DcDeviceController extends BaseController { results.sort(Comparator.comparing(hashMap -> hashMap.get("timestamp"))); return AjaxResult.success(results); } - if (UniversalEnum.THREE.getValue().equals(deviceType)||UniversalEnum.SEVENTEEN.getValue().equals(deviceType)|| - UniversalEnum.FIFTEEN.getValue().equals(deviceType)){ //气象预警/ups设备/太阳能板 + if (UniversalEnum.THREE.getValue().equals(deviceType) || UniversalEnum.SEVENTEEN.getValue().equals(deviceType) || + UniversalEnum.FIFTEEN.getValue().equals(deviceType)) { //气象预警/ups设备/太阳能板 JSONObject data = (JSONObject) ajaxResult.get("data"); JSONArray dataValue = (JSONArray) data.get("data"); List jsonObjectList = dataValue.toJavaList(JSONObject.class); @@ -831,10 +911,11 @@ public class DcDeviceController extends BaseController { String key = configService.selectConfigByKey(UniversalEnum.SBX_FUN_KL.getValue());//密钥 return AjaxResult.success(key.equals(secretKey)); } + //设备分析 @PostMapping("/properties/deviceAnalysis") public AjaxResult deviceAnalysis(@RequestBody HashMap map) throws IOException, HttpException { - if (map==null||!map.containsKey("deviceId")||!map.containsKey("deviceType") ||!map.containsKey("dateTime")){ + if (map == null || !map.containsKey("deviceId") || !map.containsKey("deviceType") || !map.containsKey("dateTime")) { return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue()); } String type = map.get("deviceType").toString();//设备类型 @@ -860,7 +941,7 @@ public class DcDeviceController extends BaseController { props.put("sorts[0].order", "asc"); props.put("sorts[0].name", "timestamp"); List> mapList = dcDeviceService.selectDeviceParameterProperties(dcDevice);//属性的参数信息 - List resultsMapValue=new ArrayList<>(); + List resultsMapValue = new ArrayList<>(); for (HashMap hashMap : mapList) { HashMap resultsMap = new HashMap<>(); String name = hashMap.get("name").toString();//属性名称 diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java index ff8670b4..6854137e 100644 --- a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java +++ b/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.THIRTEEN.getValue(), new HashMap() {{ + put("102", "设备开关"); }}); put(UniversalEnum.FOURTEEN.getValue(), new HashMap() {{ }}); @@ -93,6 +94,7 @@ public class OperationLogAspect { put(UniversalEnum.A_SIX.getValue(), UniversalEnum.QUERY_DATA.getValue()); }}); put(UniversalEnum.SIXTEEN.getValue(), new HashMap() {{ + put("102", "设备开关"); }}); }}; @@ -104,7 +106,7 @@ public class OperationLogAspect { @AfterThrowing(value = "@annotation(operationLog)", throwing = "e") 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 { @@ -208,21 +210,241 @@ public class OperationLogAspect { return; } - remark.append(deviceName); - String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? - UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : - String.valueOf( - ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) - .get(functionId) == null ? - UniversalEnum.UNKNOWN_METHOD.getValue() : - ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) - .get(functionId)); + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? + // UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : + // String.valueOf( + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId) == null ? + // UniversalEnum.UNKNOWN_METHOD.getValue() : + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId)); + //remark.append(hashMap).append(":"); - remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); + JSONObject params = function.getJSONObject("params"); - if (i1 < functions.size() - UniversalEnum.ONE.getNumber()) { - remark.append(UniversalEnum.SEMICOLON.getValue()); + + 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("关闭"); + + } + } + + } + + + //remark.append(deviceName); + + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? + // UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : + // String.valueOf( + // ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + // .get(functionId) == null ? + // UniversalEnum.UNKNOWN_METHOD.getValue() : + // ((HashMap) (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())) { - 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()]); + JSONObject params = (JSONObject) JSON.toJSON(pointArgs[UniversalEnum.TWO.getNumber()]); + if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) || Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) || Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) || @@ -332,9 +556,39 @@ public class OperationLogAspect { return; } - String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : String.valueOf(((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); + //String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) + // ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() + // : String.valueOf(((HashMap) (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("12V 输出 1").append(Objects.equals(value, "1") ? "打开" : "关闭"); - remark.append(deviceName).append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue()); + } 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) { SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); @@ -396,7 +650,7 @@ public class OperationLogAspect { operLog.setOperTime(new Date()); operLog.setDcDeviceType(deviceType); operLog.setRemark(remark.toString()); - operLog.setJsonResult(jsonResult.toJSONString()); + operLog.setJsonResult(jsonResult != null ? jsonResult.toJSONString() : AjaxResult.error().toString()); dcOperLogService.save(operLog); } } diff --git a/zc-business/src/main/resources/mapper/business/StatusMapper.xml b/zc-business/src/main/resources/mapper/business/StatusMapper.xml index 6d9e9f7d..33bd42dd 100644 --- a/zc-business/src/main/resources/mapper/business/StatusMapper.xml +++ b/zc-business/src/main/resources/mapper/business/StatusMapper.xml @@ -261,7 +261,7 @@ GROUP BY d.child_type, d.device_type, - DAY (s.time) + DATE_FORMAT(s.time, '%Y-%m-%d') ORDER BY ${status.orderByField} ${status.orderDirection}