|
@@ -4,8 +4,12 @@ import com.welampiot.common.BaseResult;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
import com.welampiot.dto.AirSwitchInfoDTO;
|
|
|
import com.welampiot.dto.ElectricBoxDTO;
|
|
|
+import com.welampiot.dto.ElectricModuleDTO;
|
|
|
+import com.welampiot.dto.LoopPolicyCmdDTO;
|
|
|
import com.welampiot.service.AirSwitchInfoService;
|
|
|
import com.welampiot.service.ElectricBoxService;
|
|
|
+import com.welampiot.service.ElectricModuleService;
|
|
|
+import com.welampiot.service.LoopPolicyCmdService;
|
|
|
import com.welampiot.utils.ToolUtils;
|
|
|
import com.welampiot.vo.AirSwitchDetailVO;
|
|
|
import com.welampiot.vo.AirSwitchInfoReturnVO;
|
|
@@ -13,12 +17,16 @@ import com.welampiot.vo.ElectricBoxReturnVO;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
-import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneOffset;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* ClassName: ElectricBoxController
|
|
@@ -42,6 +50,12 @@ public class ElectricBoxController {
|
|
|
@Autowired
|
|
|
private ToolUtils toolUtils;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ElectricModuleService electricModuleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoopPolicyCmdService loopPolicyCmdService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取电箱列表
|
|
|
* @param request
|
|
@@ -123,7 +137,7 @@ public class ElectricBoxController {
|
|
|
}
|
|
|
/**
|
|
|
* 添加编辑空开
|
|
|
- * @param electricBoxDTO
|
|
|
+ * @param airSwitchInfoDTO
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/saveAirSwitch")
|
|
@@ -143,7 +157,7 @@ public class ElectricBoxController {
|
|
|
}
|
|
|
/**
|
|
|
* 删除空开
|
|
|
- * @param electricBoxDTO
|
|
|
+ * @param airSwitchInfoDTO
|
|
|
* @return
|
|
|
*/
|
|
|
@PostMapping("/delAirSwitch")
|
|
@@ -166,4 +180,567 @@ public class ElectricBoxController {
|
|
|
electricBoxService.delete(electricBoxDTO);
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,electricBoxDTO.getVersion());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 空开分合闸
|
|
|
+ * @param request id,status
|
|
|
+ * @return 设置空开分合闸状态
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "setAirSwitchStatus", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> setAirSwitchStatus(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ int status = (int) toolUtils.getRequestContent(request,"status",1);
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ AirSwitchInfoDTO airSwitchInfoDTO = airSwitchInfoService.getAirSwitchAddressById(id);
|
|
|
+ String sendTopic = "/welampiot/ManDunLoopTransIn/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ String resTopic = "/welampiot/ManDunLoopTransOut/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ String cmd;
|
|
|
+ if (status == 1) {
|
|
|
+ cmd = "F1D3A10000090011" + s + "00000001" + "0000000000000000" + airSwitchInfoDTO.getAddress();
|
|
|
+ } else {
|
|
|
+ cmd = "F1D3A20000090011" + s + "00000001" + "0000000000000000" + airSwitchInfoDTO.getAddress();
|
|
|
+ }
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + airSwitchInfoDTO.getModuleAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ if (echo.equals("00")) {
|
|
|
+ AirSwitchInfoDTO dto = new AirSwitchInfoDTO();
|
|
|
+ dto.setId(id);
|
|
|
+ dto.setStatus(status);
|
|
|
+ airSwitchInfoService.updateAirSwitchStatusById(dto);
|
|
|
+ }
|
|
|
+ if (echo.equals("00")) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置电箱分合闸
|
|
|
+ * @param request id,status
|
|
|
+ * @return 设置电箱分合闸
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "setBoxStatus", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> setBoxStatus(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ int status = (int) toolUtils.getRequestContent(request,"status",1);
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ List<ElectricModuleDTO> moduleAddressList = electricModuleService.getModuleAddressById(id);
|
|
|
+ List<String> echo1 = new ArrayList<>();
|
|
|
+ for (ElectricModuleDTO moduleDTO : moduleAddressList) {
|
|
|
+ String sendTopic,resTopic;
|
|
|
+ sendTopic = "/welampiot/ManDunLoopTransIn/" + moduleDTO.getAddress();
|
|
|
+ resTopic = "/welampiot/ManDunLoopTransOut/" + moduleDTO.getAddress();
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ System.out.println("S:" + s);
|
|
|
+ String head, hex = "0009";
|
|
|
+ if (status == 1) {
|
|
|
+ head = "F1D3A100";
|
|
|
+ } else {
|
|
|
+ head = "F1D3A200";
|
|
|
+ }
|
|
|
+ String cmd = "";
|
|
|
+ StringBuilder headAndData = new StringBuilder("0011" + s + "00000001" + "0000000000000000");
|
|
|
+ List<AirSwitchInfoDTO> airSwitchAddressList = electricModuleService.getAirSwitchAddressById(moduleDTO.getId());
|
|
|
+ for (AirSwitchInfoDTO airSwitchInfoDTO : airSwitchAddressList) {
|
|
|
+ headAndData.append(airSwitchInfoDTO.getAddress());
|
|
|
+ cmd = head + hex + headAndData;
|
|
|
+ byte decimal = Byte.parseByte(hex,16);
|
|
|
+ decimal++;
|
|
|
+ hex = String.format("%04X",decimal);
|
|
|
+ }
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + moduleDTO.getAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ echo1.add(echo);
|
|
|
+ }
|
|
|
+ int size = echo1.size();
|
|
|
+ int sum = 0;
|
|
|
+ for (String s : echo1) {
|
|
|
+ if (s.equals("00")) {
|
|
|
+ sum++;
|
|
|
+ } else {
|
|
|
+ sum--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("size:" + size);
|
|
|
+ System.out.println("sum:" + sum);
|
|
|
+ AirSwitchInfoDTO airSwitchInfoDTO = new AirSwitchInfoDTO();
|
|
|
+ airSwitchInfoDTO.setStatus(status);
|
|
|
+ if (sum == size) {
|
|
|
+ for (ElectricModuleDTO electricModuleDTO : moduleAddressList) {
|
|
|
+ if (electricModuleDTO.getId() != null && electricModuleDTO.getId() != 0) {
|
|
|
+ airSwitchInfoDTO.setModuleId(electricModuleDTO.getId());
|
|
|
+ electricModuleService.updateElectricBoxStatusById(airSwitchInfoDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (sum == size) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 配电箱、空开绑定策略
|
|
|
+ * @param request id,type,policyId(为0时,是空开关闭策略)
|
|
|
+ * @return 实现配电箱、空开对策略的绑定
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "setAirPolicy", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> setAirPolicy(HttpServletRequest request) throws NoSuchFieldException, IllegalAccessException {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int type = (int) toolUtils.getRequestContent(request,"type",1);
|
|
|
+ String id = (String) toolUtils.getRequestContent(request,"id",2);
|
|
|
+ if (id == null || id.length() == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ int policyId = (int) toolUtils.getRequestContent(request,"policyId",1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
|
|
+ if (policyId == 0) {
|
|
|
+ if (type == 1) { // 空开关闭策略
|
|
|
+ String[] split = id.split(",");
|
|
|
+ List<String> echo1 = new ArrayList<>();
|
|
|
+ List<String> echo3 = new ArrayList<>();
|
|
|
+ for (String airId : split) {
|
|
|
+ int l = Integer.parseInt(airId);
|
|
|
+ AirSwitchInfoDTO airSwitchAddress = airSwitchInfoService.getAirSwitchAddressById(l);
|
|
|
+ String sendTopic,resTopic;
|
|
|
+ sendTopic = "/welampiot/ManDunLoopTransIn/" + airSwitchAddress.getModuleAddress();
|
|
|
+ resTopic = "/welampiot/ManDunLoopTransOut/" + airSwitchAddress.getModuleAddress();
|
|
|
+ String headCommon = "F1D3AA00001A0011";
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ System.out.println("S:" + s);
|
|
|
+ String head = headCommon + s + "00000001";
|
|
|
+ String data = "190102030405060708090A0B0C0D0E0F" + "10111213141516171819";
|
|
|
+ String cmd = head + data;
|
|
|
+ System.out.println("cmd:" + cmd);
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + airSwitchAddress.getModuleAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ echo3.add(echo);
|
|
|
+ // 把其他的空开的策略复原
|
|
|
+ List<AirSwitchInfoDTO> airSwitchList = airSwitchInfoService.getAirSwitchAddressByModuleId(airSwitchAddress.getModuleId());
|
|
|
+ for (AirSwitchInfoDTO airSwitchInfoDTO : airSwitchList) {
|
|
|
+ if (airSwitchInfoDTO != null && airSwitchInfoDTO.getId() != l) {
|
|
|
+ LoopPolicyCmdDTO policyCmdDTO = loopPolicyCmdService.getCmdByLoopPolicyCmdDTO(airSwitchInfoDTO.getPolicyId());
|
|
|
+ if (policyCmdDTO == null) break;
|
|
|
+ String resTopic1 = "/welampiot/ManDunLoopTransOut/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ String sendTopic1 = "/welampiot/ManDunLoopTransIn/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ long timeNow = System.currentTimeMillis() / 1000;
|
|
|
+ String s1 = Long.toHexString(timeNow).toUpperCase();
|
|
|
+ String cmd1, head1 = "F1D3A60000120011" + s1 + "00000001", data1;
|
|
|
+ String serialNum = "01",valLenRep = "01017F";
|
|
|
+ String numAndUid, setTime;
|
|
|
+ for (int i = 1; i <= 10; i++) {
|
|
|
+ Field timeField = policyCmdDTO.getClass().getDeclaredField("time" + i); // 获取time属性的值
|
|
|
+ System.out.println("timeField:" + timeField);
|
|
|
+ timeField.setAccessible(true); // 设置可以访问
|
|
|
+ String timeValue = (String) timeField.get(policyCmdDTO);
|
|
|
+ System.out.println("timeValue:" + timeValue);
|
|
|
+ if (timeValue != null && !timeValue.equals("")) {
|
|
|
+ Field valueField = policyCmdDTO.getClass().getDeclaredField("value" + i); // 获取value属性的值
|
|
|
+ System.out.println("valueField:" + valueField);
|
|
|
+ valueField.setAccessible(true); // 设置可以访问
|
|
|
+ int valueValue = (int) valueField.get(policyCmdDTO);
|
|
|
+ System.out.println("valueValue:" + valueValue);
|
|
|
+ if (valueValue == 1) {
|
|
|
+ numAndUid = "0000000000000001A2" + airSwitchInfoDTO.getAddress();
|
|
|
+ } else {
|
|
|
+ numAndUid = "0000000000000001A1" + airSwitchInfoDTO.getAddress();
|
|
|
+ }
|
|
|
+ setTime = policyCmdDTO.getStartTime() + " " + timeValue;
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(setTime, formatter);
|
|
|
+ System.out.println("dateTime:" + dateTime);
|
|
|
+ long timestamp = dateTime.toEpochSecond(ZoneOffset.UTC) - 3600 * 8;
|
|
|
+ System.out.println("timestamp:" + timestamp);
|
|
|
+ setTime = Long.toHexString(timestamp).toUpperCase();
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ data1 = serialNum + valLenRep + setTime + numAndUid;
|
|
|
+ System.out.println("data:" + data1);
|
|
|
+ cmd1 = head1 + data1;
|
|
|
+ System.out.println("cmd:" + cmd1);
|
|
|
+ String crc1 = toolUtils.getCRC32ByHexString2Bytes(cmd1);
|
|
|
+ System.out.println("crc:" + crc1);
|
|
|
+ String cmdInfo1 = cmd1 + crc1;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo1);
|
|
|
+ cmdInfo1 = "{" + "\"address\":" + "\"" + airSwitchInfoDTO.getModuleAddress() + "\",\"cmd\":\"" + cmdInfo1 + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo1);
|
|
|
+ String resCmd1 = toolUtils.sendMqttCmd(sendTopic1, cmdInfo1, resTopic1);
|
|
|
+ System.out.println("resCmd:" + resCmd1);
|
|
|
+ String echo2 = String.valueOf(resCmd1.charAt(6)) + resCmd1.charAt(7);
|
|
|
+ System.out.println("echo:" + echo2);
|
|
|
+ echo1.add(echo2);
|
|
|
+ byte serByte = Byte.parseByte(serialNum, 16);
|
|
|
+ serByte++;
|
|
|
+ serialNum = String.format("%02X", serByte);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int size = echo1.size();
|
|
|
+ int size1 = echo3.size();
|
|
|
+ int sum = 0, sum1 = 0;
|
|
|
+ for (String e : echo1) {
|
|
|
+ if (e.equals("00")) {
|
|
|
+ sum++;
|
|
|
+ } else {
|
|
|
+ sum--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (String e : echo3) {
|
|
|
+ if (e.equals("00")) {
|
|
|
+ sum1++;
|
|
|
+ } else {
|
|
|
+ sum1--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum && size1 == sum1) {
|
|
|
+ for (String airSwitchId : split) {
|
|
|
+ int l = Integer.parseInt(airSwitchId);
|
|
|
+ AirSwitchInfoDTO dto = new AirSwitchInfoDTO();
|
|
|
+ dto.setId(l);
|
|
|
+ dto.setPolicyId(0);
|
|
|
+ dto.setControlType(0);
|
|
|
+ loopPolicyCmdService.updateAirSwitchPolicyByDTO(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum && size1 == sum1) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ LoopPolicyCmdDTO loopPolicyCmdDTO = loopPolicyCmdService.getCmdByLoopPolicyCmdDTO(policyId);
|
|
|
+ if (loopPolicyCmdDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
+ if (type == 1) { // 空开绑定策略
|
|
|
+ String[] split = id.split(",");
|
|
|
+ List<String> echo1 = new ArrayList<>();
|
|
|
+ for (String airSwitchId : split) {
|
|
|
+ int l = Integer.parseInt(airSwitchId);
|
|
|
+ AirSwitchInfoDTO airSwitchDTO = airSwitchInfoService.getAirSwitchAddressById(l);
|
|
|
+ String sendTopic = "/welampiot/ManDunLoopTransIn/" + airSwitchDTO.getModuleAddress();
|
|
|
+ String resTopic = "/welampiot/ManDunLoopTransOut/" + airSwitchDTO.getModuleAddress();
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ String cmd, head = "F1D3A60000120011" + s + "00000001", data;
|
|
|
+ String serialNum = "01",valLenRep = "01017F";
|
|
|
+ String numAndUid, setTime;
|
|
|
+ for (int i = 1; i <= 10; i++) {
|
|
|
+ Field timeField = loopPolicyCmdDTO.getClass().getDeclaredField("time" + i); // 获取time属性的值
|
|
|
+ System.out.println("timeField:" + timeField);
|
|
|
+ timeField.setAccessible(true); // 设置可以访问
|
|
|
+ String timeValue = (String) timeField.get(loopPolicyCmdDTO);
|
|
|
+ System.out.println("timeValue:" + timeValue);
|
|
|
+ if (timeValue != null && !timeValue.equals("")) {
|
|
|
+ Field valueField = loopPolicyCmdDTO.getClass().getDeclaredField("value" + i); // 获取value属性的值
|
|
|
+ System.out.println("valueField:" + valueField);
|
|
|
+ valueField.setAccessible(true); // 设置可以访问
|
|
|
+ int valueValue = (int) valueField.get(loopPolicyCmdDTO);
|
|
|
+ System.out.println("valueValue:" + valueValue);
|
|
|
+ if (valueValue == 1) {
|
|
|
+ numAndUid = "0000000000000001A2" + airSwitchDTO.getAddress();
|
|
|
+ } else {
|
|
|
+ numAndUid = "0000000000000001A1" + airSwitchDTO.getAddress();
|
|
|
+ }
|
|
|
+ setTime = loopPolicyCmdDTO.getStartTime() + " " + timeValue;
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(setTime,formatter);
|
|
|
+ System.out.println("dateTime:" + dateTime);
|
|
|
+ long timestamp = dateTime.toEpochSecond(ZoneOffset.UTC) - 3600 * 8;
|
|
|
+ System.out.println("timestamp:" + timestamp);
|
|
|
+ setTime = Long.toHexString(timestamp).toUpperCase();
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ data = serialNum + valLenRep + setTime + numAndUid;
|
|
|
+ System.out.println("data:" + data);
|
|
|
+ cmd = head + data;
|
|
|
+ System.out.println("cmd:" + cmd);
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + airSwitchDTO.getModuleAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ echo1.add(echo);
|
|
|
+ byte serByte = Byte.parseByte(serialNum,16);
|
|
|
+ serByte++;
|
|
|
+ serialNum = String.format("%02X",serByte);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int size = echo1.size();
|
|
|
+ int sum = 0;
|
|
|
+ for (String s : echo1) {
|
|
|
+ if (s.equals("00")) {
|
|
|
+ sum++;
|
|
|
+ } else {
|
|
|
+ sum--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum) {
|
|
|
+ for (String airSwitchId : split) {
|
|
|
+ int l = Integer.parseInt(airSwitchId);
|
|
|
+ AirSwitchInfoDTO dto = new AirSwitchInfoDTO();
|
|
|
+ dto.setId(l);
|
|
|
+ dto.setPolicyId(policyId);
|
|
|
+ dto.setControlType(1);
|
|
|
+ loopPolicyCmdService.updateAirSwitchPolicyByDTO(dto);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ } else { // 配电箱绑定策略
|
|
|
+ Pattern pattern = Pattern.compile("[0-9]*");
|
|
|
+ // 判断id字符串是否为纯数字
|
|
|
+ if (!pattern.matcher(id).matches()) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
+ List<ElectricModuleDTO> moduleAddressList = electricModuleService.getModuleAddressById(Integer.valueOf(id));
|
|
|
+ List<String> echo1 = new ArrayList<>();
|
|
|
+ for (ElectricModuleDTO moduleDTO : moduleAddressList) {
|
|
|
+ String sendTopic,resTopic;
|
|
|
+ sendTopic = "/welampiot/ManDunLoopTransIn/" + moduleDTO.getAddress();
|
|
|
+ resTopic = "/welampiot/ManDunLoopTransOut/" + moduleDTO.getAddress();
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ System.out.println("S:" + s);
|
|
|
+ String headForm, len = "0012";
|
|
|
+ headForm = "F1D3A600";
|
|
|
+ String cmd, head = "";
|
|
|
+ String headCommon = "0011" + s + "00000001";
|
|
|
+ StringBuilder address = new StringBuilder();
|
|
|
+ String serialNum = "01", mark = "01", nodeLen = "00", sameFlag = "7F", data;
|
|
|
+ List<AirSwitchInfoDTO> airSwitchAddressList = electricModuleService.getAirSwitchAddressById(moduleDTO.getId());
|
|
|
+ for (AirSwitchInfoDTO airSwitchInfoDTO : airSwitchAddressList) {
|
|
|
+ address.append(airSwitchInfoDTO.getAddress());
|
|
|
+ head = headForm + len + headCommon;
|
|
|
+ byte decimal = Byte.parseByte(len,16);
|
|
|
+ decimal++;
|
|
|
+ len = String.format("%04X",decimal);
|
|
|
+ byte nodeByte = Byte.parseByte(nodeLen,16);
|
|
|
+ nodeByte++;
|
|
|
+ nodeLen = String.format("%02X",nodeByte);
|
|
|
+ }
|
|
|
+ System.out.println("nodeLen:" + nodeLen);
|
|
|
+ System.out.println("len:" + len);
|
|
|
+ System.out.println("address:" + address);
|
|
|
+ System.out.println("head:" + head);
|
|
|
+ String numAndUid, setTime;
|
|
|
+ for (int i = 1; i <= 10; i++) {
|
|
|
+ Field timeField = loopPolicyCmdDTO.getClass().getDeclaredField("time" + i); // 获取time属性的值
|
|
|
+ System.out.println("timeField:" + timeField);
|
|
|
+ timeField.setAccessible(true); // 设置可以访问
|
|
|
+ String timeValue = (String) timeField.get(loopPolicyCmdDTO);
|
|
|
+ System.out.println("timeValue:" + timeValue);
|
|
|
+ if (timeValue != null && !timeValue.equals("")) {
|
|
|
+ Field valueField = loopPolicyCmdDTO.getClass().getDeclaredField("value" + i); // 获取value属性的值
|
|
|
+ System.out.println("valueField:" + valueField);
|
|
|
+ valueField.setAccessible(true); // 设置可以访问
|
|
|
+ int valueValue = (int) valueField.get(loopPolicyCmdDTO);
|
|
|
+ System.out.println("valueValue:" + valueValue);
|
|
|
+ if (valueValue == 1) {
|
|
|
+ numAndUid = "0000000000000001A2";
|
|
|
+ } else {
|
|
|
+ numAndUid = "0000000000000001A1";
|
|
|
+ }
|
|
|
+ setTime = loopPolicyCmdDTO.getStartTime() + " " + timeValue;
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ LocalDateTime dateTime = LocalDateTime.parse(setTime,formatter);
|
|
|
+ System.out.println("dateTime:" + dateTime);
|
|
|
+ long timestamp = dateTime.toEpochSecond(ZoneOffset.UTC) - 3600 * 8;
|
|
|
+ System.out.println("timestamp:" + timestamp);
|
|
|
+ setTime = Long.toHexString(timestamp).toUpperCase();
|
|
|
+ System.out.println("setTime:" + setTime);
|
|
|
+ data = serialNum + mark + nodeLen + sameFlag + setTime + numAndUid + address;
|
|
|
+ System.out.println("data:" + data);
|
|
|
+ cmd = head + data;
|
|
|
+ System.out.println("cmd:" + cmd);
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + moduleDTO.getAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ echo1.add(echo);
|
|
|
+ byte serByte = Byte.parseByte(serialNum,16);
|
|
|
+ serByte++;
|
|
|
+ serialNum = String.format("%02X",serByte);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int size = echo1.size();
|
|
|
+ int sum = 0;
|
|
|
+ for (String s : echo1) {
|
|
|
+ if (s.equals("00")) {
|
|
|
+ sum++;
|
|
|
+ } else {
|
|
|
+ sum--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 操作成功后修改电箱以及电箱绑定的空开表中的策略id和控制类型
|
|
|
+ ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
|
|
|
+ AirSwitchInfoDTO airSwitchInfoDTO = new AirSwitchInfoDTO();
|
|
|
+ if (sum == size) {
|
|
|
+ electricBoxDTO.setId(Integer.parseInt(id));
|
|
|
+ electricBoxDTO.setPolicyId(policyId);
|
|
|
+ electricBoxDTO.setControlType(1);
|
|
|
+ loopPolicyCmdService.updateElectricBoxPolicyByElectricBoxDTO(electricBoxDTO);
|
|
|
+ for (ElectricModuleDTO electricModuleDTO : moduleAddressList) {
|
|
|
+ if (electricModuleDTO.getId() != null && electricModuleDTO.getId() != 0) {
|
|
|
+ airSwitchInfoDTO.setModuleId(electricModuleDTO.getId());
|
|
|
+ airSwitchInfoDTO.setPolicyId(policyId);
|
|
|
+ airSwitchInfoDTO.setControlType(1);
|
|
|
+ loopPolicyCmdService.updateElectricBoxPolicyByDTO(airSwitchInfoDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 电箱关闭策略
|
|
|
+ * @param request id
|
|
|
+ * @return 关闭电箱中的策略,并修改策略id为0
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "closeAirPolicy", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> closeAirPolicy(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ List<ElectricModuleDTO> moduleAddressList = electricModuleService.getModuleAddressById(id);
|
|
|
+ List<String> echo1 = new ArrayList<>();
|
|
|
+ for (ElectricModuleDTO electricModuleDTO : moduleAddressList) {
|
|
|
+ String sendTopic,resTopic;
|
|
|
+ sendTopic = "/welampiot/ManDunLoopTransIn/" + electricModuleDTO.getAddress();
|
|
|
+ resTopic = "/welampiot/ManDunLoopTransOut/" + electricModuleDTO.getAddress();
|
|
|
+ String headCommon = "F1D3AA00001A0011";
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ System.out.println("S:" + s);
|
|
|
+ String head = headCommon + s + "00000001";
|
|
|
+ String data = "190102030405060708090A0B0C0D0E0F" + "10111213141516171819";
|
|
|
+ String cmd = head + data;
|
|
|
+ System.out.println("cmd:" + cmd);
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + electricModuleDTO.getAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ echo1.add(echo);
|
|
|
+ }
|
|
|
+ int size = echo1.size();
|
|
|
+ int sum = 0;
|
|
|
+ for (String s : echo1) {
|
|
|
+ if (s.equals("00")) {
|
|
|
+ sum++;
|
|
|
+ } else {
|
|
|
+ sum--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 操作成功后修改电箱以及电箱绑定的空开表中的策略id和控制类型
|
|
|
+ ElectricBoxDTO electricBoxDTO = new ElectricBoxDTO();
|
|
|
+ AirSwitchInfoDTO airSwitchInfoDTO = new AirSwitchInfoDTO();
|
|
|
+ if (sum == size) {
|
|
|
+ electricBoxDTO.setId(id);
|
|
|
+ electricBoxDTO.setPolicyId(0);
|
|
|
+ electricBoxDTO.setControlType(0);
|
|
|
+ loopPolicyCmdService.updateElectricBoxPolicyByElectricBoxDTO(electricBoxDTO);
|
|
|
+ for (ElectricModuleDTO electricModuleDTO : moduleAddressList) {
|
|
|
+ if (electricModuleDTO.getId() != null && electricModuleDTO.getId() != 0) {
|
|
|
+ airSwitchInfoDTO.setModuleId(electricModuleDTO.getId());
|
|
|
+ airSwitchInfoDTO.setPolicyId(0);
|
|
|
+ airSwitchInfoDTO.setControlType(0);
|
|
|
+ loopPolicyCmdService.updateElectricBoxPolicyByDTO(airSwitchInfoDTO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (size == sum) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解锁空开设备
|
|
|
+ * @param request id
|
|
|
+ * @return 解除异常的分闸的空开
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "unClockDev", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> unClockDev(HttpServletRequest request) {
|
|
|
+ int version = (int) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ int id = (int) toolUtils.getRequestContent(request,"id",1);
|
|
|
+ if (id == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ AirSwitchInfoDTO airSwitchInfoDTO = airSwitchInfoService.getAirSwitchAddressById(id);
|
|
|
+ String sendTopic = "/welampiot/ManDunLoopTransIn/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ String resTopic = "/welampiot/ManDunLoopTransOut/" + airSwitchInfoDTO.getModuleAddress();
|
|
|
+ long time = System.currentTimeMillis() / 1000;
|
|
|
+ String s = Long.toHexString(time).toUpperCase();
|
|
|
+ String cmd = "F1D3AD0000090011" + s + "00000001" + "0000000000000000" + airSwitchInfoDTO.getAddress();
|
|
|
+ String crc = toolUtils.getCRC32ByHexString2Bytes(cmd);
|
|
|
+ System.out.println("crc:" + crc);
|
|
|
+ String cmdInfo = cmd + crc;
|
|
|
+ System.out.println("cmdInfo1:" + cmdInfo);
|
|
|
+ cmdInfo = "{" + "\"address\":" + "\"" + airSwitchInfoDTO.getModuleAddress() + "\",\"cmd\":\"" + cmdInfo + "\"}";
|
|
|
+ System.out.println("cmdInfo2:" + cmdInfo);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic,cmdInfo,resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ String echo = String.valueOf(resCmd.charAt(6)) + resCmd.charAt(7);
|
|
|
+ System.out.println("echo:" + echo);
|
|
|
+ if (echo.equals("00")) {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|