|
@@ -25,6 +25,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
@@ -320,31 +321,58 @@ public class ElectricBoxController {
|
|
|
String[] split = id.split(",");
|
|
|
List<String> echo1 = new ArrayList<>();
|
|
|
List<String> echo3 = new ArrayList<>();
|
|
|
+ List<String> airIds = Arrays.asList(id.split(","));
|
|
|
+ List<ElectricModuleDTO> moduleAddressGroupById = electricModuleService.getModuleAddressByAirIds(airIds);
|
|
|
+ for (ElectricModuleDTO electricModuleDTO : moduleAddressGroupById) {
|
|
|
+ if (electricModuleDTO != null && electricModuleDTO.getAddress() != null) {
|
|
|
+ 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);
|
|
|
+ echo3.add(echo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int size1 = echo3.size();
|
|
|
+ int sum1 = 0;
|
|
|
+ for (String e : echo3) {
|
|
|
+ if (e.equals("00")) {
|
|
|
+ sum1++;
|
|
|
+ } else {
|
|
|
+ sum1--;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (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);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|
|
|
+ }
|
|
|
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) {
|
|
@@ -407,8 +435,7 @@ public class ElectricBoxController {
|
|
|
}
|
|
|
}
|
|
|
int size = echo1.size();
|
|
|
- int size1 = echo3.size();
|
|
|
- int sum = 0, sum1 = 0;
|
|
|
+ int sum = 0;
|
|
|
for (String e : echo1) {
|
|
|
if (e.equals("00")) {
|
|
|
sum++;
|
|
@@ -416,14 +443,7 @@ public class ElectricBoxController {
|
|
|
sum--;
|
|
|
}
|
|
|
}
|
|
|
- for (String e : echo3) {
|
|
|
- if (e.equals("00")) {
|
|
|
- sum1++;
|
|
|
- } else {
|
|
|
- sum1--;
|
|
|
- }
|
|
|
- }
|
|
|
- if (size == sum && size1 == sum1) {
|
|
|
+ if (size == sum) {
|
|
|
for (String airSwitchId : split) {
|
|
|
int l = Integer.parseInt(airSwitchId);
|
|
|
AirSwitchInfoDTO dto = new AirSwitchInfoDTO();
|
|
@@ -433,7 +453,7 @@ public class ElectricBoxController {
|
|
|
loopPolicyCmdService.updateAirSwitchPolicyByDTO(dto);
|
|
|
}
|
|
|
}
|
|
|
- if (size == sum && size1 == sum1) {
|
|
|
+ if (size == sum) {
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
} else {
|
|
|
return toolUtils.response(InterfaceResultEnum.COMMAND_FAIL,version);
|