|
|
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.Serializable;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.List;
|
|
|
import java.util.StringJoiner;
|
|
|
|
|
|
@Service
|
|
|
@@ -175,6 +176,7 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
if (subsystem != null) {
|
|
|
QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda()
|
|
|
+ .eq(IotDeviceInfo::getDeleted, 0)
|
|
|
.eq(IotDeviceInfo::getDeviceCode, subsystem.getAlarmHostCode())
|
|
|
.eq(IotDeviceInfo::getIotToken, subsystem.getIotToken());
|
|
|
IotDeviceInfo deviceInfo = iIotDeviceInfoService.getOne(wrapper);
|
|
|
@@ -206,6 +208,72 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void breakerControlByOrgId(Long orgId,String command) {
|
|
|
+ try {
|
|
|
+ QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
|
|
|
+ wrapper.lambda()
|
|
|
+ .eq(IotDeviceInfo::getDeleted, 0)
|
|
|
+ .eq(IotDeviceInfo::getOrgId, orgId)
|
|
|
+ .eq(IotDeviceInfo::getDeviceProduct, "FSU_DoPowerControl");
|
|
|
+ List<IotDeviceInfo> list = iIotDeviceInfoService.list(wrapper);
|
|
|
+ if (list != null && list.size() > 0) {
|
|
|
+ for (int i = 0; i < list.size(); i++) {
|
|
|
+ IotDeviceInfo deviceInfo = list.get(i);
|
|
|
+ JSONObject args = new JSONObject();
|
|
|
+ args.put("command", command);
|
|
|
+ String topic = "/things/" + deviceInfo.getDeviceProduct() + "/" + deviceInfo.getDeviceCode() + "/service/invoke";
|
|
|
+ JSONObject headers = new JSONObject();
|
|
|
+ headers.put("productName", deviceInfo.getDeviceProduct());
|
|
|
+ headers.put("deviceName", deviceInfo.getDeviceCode());
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.info("通断电控制topic:{},控制参数:{}", topic, args.toJSONString());
|
|
|
+ WebsocketResult websocketResult = IotServerUtils.invokeHostServer(topic, headers, WebSocketConstants.BREAKER_CONTROL, args);
|
|
|
+ LogUtils.WEBSOCKET_MSG.info("通断电控制指令:{}", JacksonUtils.toJSONString(websocketResult));
|
|
|
+ boolean invoked = WebSocketUtils.sendMessage(deviceInfo.getIotToken(), JacksonUtils.toJSONString(websocketResult));
|
|
|
+ if (!invoked) {
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,指令下发iot服务失败");
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,组织机构:{} 下未找到控制设备", orgId);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void breakerControlByDeviceId(Serializable id,String command) {
|
|
|
+ try {
|
|
|
+ IotDeviceInfo deviceInfo = iIotDeviceInfoService.getById(id);
|
|
|
+ if (deviceInfo != null) {
|
|
|
+ String topic = "/things/" + deviceInfo.getDeviceProduct() + "/" + deviceInfo.getDeviceCode() + "/service/invoke";
|
|
|
+ JSONObject args = new JSONObject();
|
|
|
+ args.put("command", command);
|
|
|
+ JSONObject headers = new JSONObject();
|
|
|
+ headers.put("deviceName", deviceInfo.getDeviceCode());
|
|
|
+ headers.put("productName", deviceInfo.getDeviceProduct());
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.info("通断电控制topic:{},控制参数:{}", topic, args.toJSONString());
|
|
|
+ WebsocketResult websocketResult = IotServerUtils.invokeHostServer(topic, headers, WebSocketConstants.BREAKER_CONTROL, args);
|
|
|
+ LogUtils.WEBSOCKET_MSG.info("通断电控制:{}", JacksonUtils.toJSONString(websocketResult));
|
|
|
+ boolean invoked = WebSocketUtils.sendMessage(deviceInfo.getIotToken(), JacksonUtils.toJSONString(websocketResult));
|
|
|
+ if (!invoked) {
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,指令下发iot服务失败");
|
|
|
+ throw new RuntimeException();
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制,未找到控制设备:{}", id);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("通断电控制", e);
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void saveProtectionLog(IotAlarmSubsystem protection) {
|
|
|
IotAlarmSubsystemLog protectionLog = new IotAlarmSubsystemLog();
|
|
|
BeanHelper.copyProperties(protectionLog, protection);
|