Browse Source

优化魔法值

develop
zhaoxianglong 4 months ago
parent
commit
972c686d59
  1. 72
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 6
      zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java
  3. 45
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  4. 116
      zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java

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

@ -536,13 +536,13 @@ public class DcDeviceController extends BaseController {
String iotDeviceId = device.getString("iotDeviceId");
String deviceType = device.getString("deviceType");
boolean continueToExecute = true;
if (Objects.equals(deviceType, "10")) {
if (Objects.equals(deviceType, UniversalEnum.TEN.getValue())) {
JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, "MD").get("data"));
JSONObject mdJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.MD.getValue()).get("data"));
String mdValue = mdJSONObject.getString("value");
JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, "TM").get("data"));
JSONObject tmJSONObject = (JSONObject) JSON.toJSON(getDeviceLatestProperty(iotDeviceId, UniversalEnum.TM.getValue()).get("data"));
String tmValue = tmJSONObject.getString("value");
@ -563,7 +563,7 @@ public class DcDeviceController extends BaseController {
}
} 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) {
if (collect.size() == UniversalEnum.ZERO.getNumber()) {
JSONObject result = new JSONObject();
result.put("device", device.getString("id"));
result.put("deviceType", device.getInteger("deviceType"));
@ -571,14 +571,14 @@ public class DcDeviceController extends BaseController {
result.put("result", AjaxResult.error());
resultArray.add(result);
} else {
for (int i = 0; i < resultArray.size(); i++) {
for (int i = UniversalEnum.ZERO.getNumber(); 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")) {
if (!Objects.equals(result.getString("code"), UniversalEnum.TWO_HUNDRED.getValue())) {
break;
} else {
result.put("code", "500");
result.put("code", UniversalEnum.FIVE_HUNDRED.getValue());
jsonObject.put("result", result);
resultArray.add(i, jsonObject);
}
@ -588,15 +588,15 @@ public class DcDeviceController extends BaseController {
}
}
if (Objects.equals(functionId, "SETMD")) {
if (Objects.equals(functionId, UniversalEnum.SETMD.getValue())) {
JSONObject jsonObjectMD = new JSONObject();
jsonObjectMD.put("SET", mdValue);
jsonObjectMD.put(UniversalEnum.SET.getValue(), mdValue);
getAjaxResult(iotDeviceId, functionId, jsonObjectMD.toJavaObject(new TypeReference<HashMap<String, Object>>() {
}));
}
if (Objects.equals(functionId, "SETTM")) {
if (Objects.equals(functionId, UniversalEnum.SETTM.getValue())) {
JSONObject jsonObjectTM = new JSONObject();
jsonObjectTM.put("SET", tmValue);
jsonObjectTM.put(UniversalEnum.SET.getValue(), tmValue);
getAjaxResult(iotDeviceId, functionId, jsonObjectTM.toJavaObject(new TypeReference<HashMap<String, Object>>() {
}));
}
@ -610,15 +610,15 @@ public class DcDeviceController extends BaseController {
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());
// }
//}
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"));
@ -641,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;
}

6
zc-business/src/main/java/com/zc/business/controller/DeviceStatus.java

@ -15,7 +15,6 @@ import com.zc.business.service.impl.StatusService;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.BufferedReader;
@ -23,7 +22,9 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
@ -103,7 +104,8 @@ public class DeviceStatus {
//@Scheduled(cron = "0 30 23 * * ?")
public void periodicDataClearing() {
StatusService statusService = SpringUtils.getBean(StatusService.class);
LocalDateTime startTime = LocalDateTime.now().minusMonths(UniversalEnum.THREE.getNumber());
LocalDateTime startTime = LocalDateTime.of(LocalDate.now().minusMonths(UniversalEnum.THREE.getNumber()), LocalTime.MIN);
;
Status status = new Status();
status.setStartTime(startTime);
statusService.delStatusByTime(status);

45
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -772,6 +772,36 @@ public enum UniversalEnum {
// 内容
CONTENT(0, "内容"),
// 关闭
OFF(0, "关闭"),
// 打开
UNPACK(0, "打开"),
// 常亮
STEADY_ON(0, "常亮"),
// 间隔100ms闪烁
BLINK_AT_AN_INTERVAL_OF_100_MS(0, "间隔100ms闪烁"),
// 间隔200ms闪烁
BLINK_AT_AN_INTERVAL_OF_200_MS(0, "间隔200ms闪烁"),
// 间隔500ms闪烁
BLINK_AT_AN_INTERVAL_OF_500_MS(0, "间隔500ms闪烁"),
// 2次闪烁
DOUBLE_FLICKER(0, "2次闪烁"),
// SOS
SOS(0, "SOS"),
// 自定义闪烁时间
CUSTOMIZE_THE_BLINKING_TIME(0, "自定义闪烁时间"),
// 模式
MODE(0, "模式"),
// 一般
NORMAL(0, "一般"),
@ -1162,12 +1192,18 @@ public enum UniversalEnum {
// SETMD
SETMD(0, "SETMD"),
// MD
MD(0, "MD"),
// ASKMD
ASKMD(0, "ASKMD"),
// SETTM
SETTM(0, "SETTM"),
// TM
TM(0, "TM"),
// ASKTM
ASKTM(0, "ASKTM"),
@ -2064,6 +2100,15 @@ public enum UniversalEnum {
// 行车诱导功能码 01
ZERO_ONE(0, "01"),
// 行车诱导功能码 02
ZERO_TWO(0, "02"),
// 行车诱导功能码 03
ZERO_THREE(0, "03"),
// 行车诱导功能码 04
ZERO_FOUR(0, "04"),
// 行车诱导功能码 0b
ZERO_B(0, "0b"),

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

@ -224,7 +224,7 @@ public class OperationLogAspect {
JSONObject params = function.getJSONObject("params");
if (Objects.equals(deviceType, "2")) {
if (Objects.equals(deviceType, UniversalEnum.TWO.getValue())) {
//if (Objects.equals(functionId, UniversalEnum.ELEVEN.getValue())) {
//
@ -235,13 +235,13 @@ public class OperationLogAspect {
JSONArray parameters = params.getJSONArray("parameters");
for (int i2 = 0; i2 < parameters.size(); i2++) {
for (int i2 = UniversalEnum.ZERO.getNumber(); 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("、");
if (i2 < parameters.size() - UniversalEnum.ONE.getNumber()) {
remark.append(UniversalEnum.SEMICOLON.getValue());
}
}
@ -252,175 +252,175 @@ public class OperationLogAspect {
//
//}
} else if (Objects.equals(deviceType, "5")) {
} else if (Objects.equals(deviceType, UniversalEnum.FIVE.getValue())) {
remark.append(params.getString("text"));
} else if (Objects.equals(deviceType, "10")) {
} else if (Objects.equals(deviceType, UniversalEnum.TEN.getValue())) {
String set = params.getString("SET");
String set = params.getString(UniversalEnum.SET.getValue());
if (Objects.equals(functionId, UniversalEnum.SETMD.getValue())) {
if (Objects.equals(set, "0")) {
if (Objects.equals(set, UniversalEnum.ZERO.getValue())) {
remark.append("关闭");
remark.append(UniversalEnum.OFF.getValue());
} else if (Objects.equals(set, "1")) {
} else if (Objects.equals(set, UniversalEnum.ONE.getValue())) {
remark.append("常亮");
remark.append(UniversalEnum.STEADY_ON.getValue());
} else if (Objects.equals(set, "2")) {
} else if (Objects.equals(set, UniversalEnum.TWO.getValue())) {
remark.append("间隔100ms闪烁");
remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_100_MS.getValue());
} else if (Objects.equals(set, "3")) {
} else if (Objects.equals(set, UniversalEnum.THREE.getValue())) {
remark.append("间隔200ms闪烁");
remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_200_MS.getValue());
} else if (Objects.equals(set, "4")) {
} else if (Objects.equals(set, UniversalEnum.FOUR.getValue())) {
remark.append("间隔500ms闪烁");
remark.append(UniversalEnum.BLINK_AT_AN_INTERVAL_OF_500_MS.getValue());
} else if (Objects.equals(set, "5")) {
} else if (Objects.equals(set, UniversalEnum.FIVE.getValue())) {
remark.append("2次闪烁");
remark.append(UniversalEnum.DOUBLE_FLICKER.getValue());
} else if (Objects.equals(set, "6")) {
} else if (Objects.equals(set, UniversalEnum.SIX.getValue())) {
remark.append("SOS");
remark.append(UniversalEnum.SOS.getValue());
} else if (Objects.equals(set, "7")) {
} else if (Objects.equals(set, UniversalEnum.SEVEN.getValue())) {
remark.append("自定义闪烁时间");
remark.append(UniversalEnum.CUSTOMIZE_THE_BLINKING_TIME.getValue());
}
remark.append("模式");
remark.append(UniversalEnum.MODE.getValue());
} else if (Objects.equals(functionId, UniversalEnum.SETTM.getValue())) {
remark.append(set).append("分钟");
remark.append(set).append(UniversalEnum.MINUTES.getValue());
}
} else if (Objects.equals(deviceType, "12")) {
} else if (Objects.equals(deviceType, UniversalEnum.TWELVE.getValue())) {
if (Objects.equals(functionId, "51")) {
if (Objects.equals(functionId, UniversalEnum.FIFTY_ONE.getValue())) {
//remark.append("模式:");
String mode = params.getString("mode");
if (Objects.equals(mode, "00")) {
if (Objects.equals(mode, UniversalEnum.ZERO_ZERO.getValue())) {
remark.append("远程手动控制模式:上行:");
String onWorkStatus = params.getString("onWorkStatus");
String inWorkStatus = params.getString("inWorkStatus");
if (Objects.equals(onWorkStatus, "00")) {
if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) {
remark.append("不更新状态,下行:");
} else if (Objects.equals(onWorkStatus, "01")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ONE.getValue())) {
remark.append("常亮,下行:");
} else if (Objects.equals(onWorkStatus, "02")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_TWO.getValue())) {
remark.append("流水,下行:");
} else if (Objects.equals(onWorkStatus, "03")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_THREE.getValue())) {
remark.append("闪烁,下行:");
} else if (Objects.equals(onWorkStatus, "04")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) {
remark.append("关闭,下行:");
}
if (Objects.equals(inWorkStatus, "00")) {
if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) {
remark.append("不更新状态");
} else if (Objects.equals(inWorkStatus, "01")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ONE.getValue())) {
remark.append("常亮");
} else if (Objects.equals(inWorkStatus, "02")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_TWO.getValue())) {
remark.append("流水");
} else if (Objects.equals(inWorkStatus, "03")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_THREE.getValue())) {
remark.append("闪烁");
} else if (Objects.equals(inWorkStatus, "04")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) {
remark.append("关闭");
}
} else if (Objects.equals(mode, "01")) {
} else if (Objects.equals(mode, UniversalEnum.ZERO_ONE.getValue())) {
remark.append("时间段自动控制模式:")
.append(params.getString("startDisplayTime"))
.append("-")
.append(params.getString("endDisplayTime"));
} else if (Objects.equals(mode, "02")) {
} else if (Objects.equals(mode, UniversalEnum.ZERO_TWO.getValue())) {
remark.append("万年历自动控制模式");
} else if (Objects.equals(mode, "03")) {
} else if (Objects.equals(mode, UniversalEnum.ZERO_THREE.getValue())) {
remark.append("能见度自动控制模式");
}
} else if (Objects.equals(functionId, "30")) {
} else if (Objects.equals(functionId, UniversalEnum.THIRTY.getValue())) {
String onWorkStatus = params.getString("onWorkStatus");
String inWorkStatus = params.getString("inWorkStatus");
if (Objects.equals(onWorkStatus, "00")) {
if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) {
remark.append("上行:不更新状态,下行:");
} else if (Objects.equals(onWorkStatus, "01")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_ONE.getValue())) {
remark.append("上行:常亮,下行:");
} else if (Objects.equals(onWorkStatus, "02")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_TWO.getValue())) {
remark.append("上行:流水,下行:");
} else if (Objects.equals(onWorkStatus, "03")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_THREE.getValue())) {
remark.append("上行:闪烁,下行:");
} else if (Objects.equals(onWorkStatus, "04")) {
} else if (Objects.equals(onWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) {
remark.append("上行:关闭,下行:");
}
if (Objects.equals(inWorkStatus, "00")) {
if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ZERO.getValue())) {
remark.append("不更新状态");
} else if (Objects.equals(inWorkStatus, "01")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_ONE.getValue())) {
remark.append("常亮");
} else if (Objects.equals(inWorkStatus, "02")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_TWO.getValue())) {
remark.append("流水");
} else if (Objects.equals(inWorkStatus, "03")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_THREE.getValue())) {
remark.append("闪烁");
} else if (Objects.equals(inWorkStatus, "04")) {
} else if (Objects.equals(inWorkStatus, UniversalEnum.ZERO_FOUR.getValue())) {
remark.append("关闭");
@ -561,30 +561,30 @@ public class OperationLogAspect {
// : String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
//
//remark.append(hashMap).append(":");
if (Objects.equals(deviceType, "13") || Objects.equals(deviceType, "16")) {
if (Objects.equals(deviceType, UniversalEnum.THIRTEEN.getValue()) || Objects.equals(deviceType, UniversalEnum.SIXTEEN.getValue())) {
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") ? "打开" : "关闭");
remark.append("220V 输出 1").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue());
} else if (Objects.equals(identification, "ac_out_2_en")) {
remark.append("220V 输出 2").append(Objects.equals(value, "1") ? "打开" : "关闭");
remark.append("220V 输出 2").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue());
} else if (Objects.equals(identification, "dc_out_1_en")) {
remark.append("12V 输出 1").append(Objects.equals(value, "1") ? "打开" : "关闭");
remark.append("12V 输出 1").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue());
} else if (Objects.equals(identification, "dc_out_2_en")) {
remark.append("12V 输出 2").append(Objects.equals(value, "1") ? "打开" : "关闭");
remark.append("12V 输出 2").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue());
} else if (Objects.equals(identification, "fan_out_en")) {
remark.append("风扇").append(Objects.equals(value, "1") ? "打开" : "关闭");
remark.append("风扇").append(Objects.equals(value, UniversalEnum.ONE.getValue()) ? UniversalEnum.UNPACK.getValue() : UniversalEnum.OFF.getValue());
}

Loading…
Cancel
Save