|
|
@@ -16,18 +16,19 @@ import com.xunmei.mediator.websocket.constant.WebSocketConstants;
|
|
|
import com.xunmei.mediator.websocket.dto.WebsocketExecuteReq;
|
|
|
import com.xunmei.mediator.websocket.dto.WebsocketResult;
|
|
|
import com.xunmei.mediator.websocket.enums.ProductEnums;
|
|
|
-import com.xunmei.mediator.websocket.holder.WebSocketSessionHolder;
|
|
|
import com.xunmei.mediator.websocket.service.RouterService;
|
|
|
import com.xunmei.mediator.websocket.utils.IotServerUtils;
|
|
|
+import com.xunmei.mediator.websocket.utils.WebSocketUtils;
|
|
|
import com.xunmei.system.api.domain.iot.IotDeviceInfo;
|
|
|
import com.xunmei.system.api.enums.ProtectionStatus;
|
|
|
import com.xunmei.system.api.util.LogUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.Serializable;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.*;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
@Service
|
|
|
public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterService {
|
|
|
@@ -42,35 +43,34 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
ProtectionLogMapper protectionLogMapper;
|
|
|
|
|
|
|
|
|
-
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void changeAlarmHostStatus(WebsocketExecuteReq req){
|
|
|
+ public void changeAlarmHostStatus(WebsocketExecuteReq req) {
|
|
|
try {
|
|
|
- LogUtils.STATUS_INFO_DEFENCEAREA.info("【iot服务报警主机设备状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(),JSON.toJSONString(req));
|
|
|
- if (req.getData() != null){
|
|
|
+ LogUtils.STATUS_INFO_DEFENCEAREA.info("【iot服务报警主机设备状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(), JSON.toJSONString(req));
|
|
|
+ if (req.getData() != null) {
|
|
|
JSONObject object = (JSONObject) req.getData();
|
|
|
String status = object.getString("status");
|
|
|
String updateTime = object.getString("time");
|
|
|
|
|
|
QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda()
|
|
|
- .eq(IotDeviceInfo::getDeviceProduct,req.getProductName())
|
|
|
- .eq(IotDeviceInfo::getDeviceCode,req.getDeviceName())
|
|
|
- .eq(IotDeviceInfo::getIotToken,req.getToken())
|
|
|
- .eq(IotDeviceInfo::getDeleted,0);
|
|
|
+ .eq(IotDeviceInfo::getDeviceProduct, req.getProductName())
|
|
|
+ .eq(IotDeviceInfo::getDeviceCode, req.getDeviceName())
|
|
|
+ .eq(IotDeviceInfo::getIotToken, req.getToken())
|
|
|
+ .eq(IotDeviceInfo::getDeleted, 0);
|
|
|
IotDeviceInfo deviceInfo = iIotDeviceInfoService.getOne(wrapper);
|
|
|
- if (deviceInfo != null){
|
|
|
- if ("Online".equals(status)){
|
|
|
+ if (deviceInfo != null) {
|
|
|
+ if ("Online".equals(status)) {
|
|
|
deviceInfo.setNetStatus("1");
|
|
|
- }else if ("Offline".equals(status)){
|
|
|
+ } else if ("Offline".equals(status)) {
|
|
|
deviceInfo.setNetStatus("2");
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
deviceInfo.setNetStatus("0");
|
|
|
}
|
|
|
iIotDeviceInfoService.updateById(deviceInfo);
|
|
|
}
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
LogUtils.STATUS_INFO_DEFENCEAREA.error("处理报警主机设备状态改变事件出错", e);
|
|
|
throw new RuntimeException(e);
|
|
|
@@ -78,31 +78,31 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public void changeSubSystemStatus(WebsocketExecuteReq req){
|
|
|
+ public void changeSubSystemStatus(WebsocketExecuteReq req) {
|
|
|
try {
|
|
|
- LogUtils.STATUS_INFO_DEFENCEAREA.info("【iot服务报警主机布撤防状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(),JSON.toJSONString(req));
|
|
|
- if (req.getData() != null){
|
|
|
+ LogUtils.STATUS_INFO_DEFENCEAREA.info("【iot服务报警主机布撤防状态变更事件】【iotToken:{}】【msgId:{}】【接收参数:{}】", req.getToken(), req.getId(), JSON.toJSONString(req));
|
|
|
+ if (req.getData() != null) {
|
|
|
JSONObject object = (JSONObject) req.getData();
|
|
|
Integer subSystemId = object.getInteger("id");
|
|
|
String status = object.getString("status");
|
|
|
|
|
|
QueryWrapper<IotAlarmSubsystem> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda()
|
|
|
- .eq(IotAlarmSubsystem::getAlarmHostCode,req.getDeviceName())
|
|
|
- .eq(IotAlarmSubsystem::getCode,String.valueOf(subSystemId))
|
|
|
- .eq(IotAlarmSubsystem::getIotToken,req.getToken())
|
|
|
- .eq(IotAlarmSubsystem::getDeleted,0);
|
|
|
+ .eq(IotAlarmSubsystem::getAlarmHostCode, req.getDeviceName())
|
|
|
+ .eq(IotAlarmSubsystem::getCode, String.valueOf(subSystemId))
|
|
|
+ .eq(IotAlarmSubsystem::getIotToken, req.getToken())
|
|
|
+ .eq(IotAlarmSubsystem::getDeleted, 0);
|
|
|
IotAlarmSubsystem subsystem = subsystemService.getOne(wrapper);
|
|
|
|
|
|
- if (subsystem != null){
|
|
|
+ if (subsystem != null) {
|
|
|
Integer dbStatus = subsystem.getStatus();
|
|
|
//Arm:布防 DisArm:撤防 Unknown:未知
|
|
|
//0:撤防,1:布防,2:未知
|
|
|
- if ("Arm".equals(status)){
|
|
|
+ if ("Arm".equals(status)) {
|
|
|
subsystem.setStatus(ProtectionStatus.PROTECTION.ordinal());
|
|
|
- }else if ("DisArm".equals(status)){
|
|
|
+ } else if ("DisArm".equals(status)) {
|
|
|
subsystem.setStatus(ProtectionStatus.REMOVAL.ordinal());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
subsystem.setStatus(ProtectionStatus.UNKNOWN.ordinal());
|
|
|
}
|
|
|
subsystem.setStatusUpdateTime(LocalDateTime.now());
|
|
|
@@ -114,7 +114,7 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
this.saveProtectionLog(subsystem);
|
|
|
}
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
LogUtils.STATUS_INFO_DEFENCEAREA.error("处理报警主机布撤防状态改变事件出错", e);
|
|
|
throw new RuntimeException(e);
|
|
|
@@ -125,36 +125,36 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
public void subSystemControl(Serializable id, boolean isArm) {
|
|
|
try {
|
|
|
IotAlarmSubsystem subsystem = subsystemService.getById(id);
|
|
|
- if (subsystem != null){
|
|
|
+ if (subsystem != null) {
|
|
|
QueryWrapper<IotDeviceInfo> wrapper = new QueryWrapper<>();
|
|
|
wrapper.lambda()
|
|
|
- .eq(IotDeviceInfo::getDeviceCode,subsystem.getAlarmHostCode())
|
|
|
- .eq(IotDeviceInfo::getIotToken,subsystem.getIotToken());
|
|
|
+ .eq(IotDeviceInfo::getDeviceCode, subsystem.getAlarmHostCode())
|
|
|
+ .eq(IotDeviceInfo::getIotToken, subsystem.getIotToken());
|
|
|
IotDeviceInfo deviceInfo = iIotDeviceInfoService.getOne(wrapper);
|
|
|
- if (deviceInfo != null){
|
|
|
+ if (deviceInfo != null) {
|
|
|
JSONObject args = new JSONObject();
|
|
|
- args.put("id",Integer.valueOf(subsystem.getCode()));
|
|
|
- args.put("isArm",isArm);
|
|
|
+ args.put("id", Integer.valueOf(subsystem.getCode()));
|
|
|
+ args.put("isArm", isArm);
|
|
|
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());
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.info("报警主机布撤防控制topic:{},控制参数:{}", topic, args.toJSONString());
|
|
|
WebsocketResult websocketResult = IotServerUtils.invokeIotServer(topic, headers, WebSocketConstants.SUB_SYSTEM_CONTROL, args);
|
|
|
LogUtils.WEBSOCKET_MSG.info("布撤防控制指令:{}", JacksonUtils.toJSONString(websocketResult));
|
|
|
- boolean invoked = WebSocketSessionHolder.sendMessage(subsystem.getIotToken(), JacksonUtils.toJSONString(websocketResult));
|
|
|
- if (!invoked){
|
|
|
+ boolean invoked = WebSocketUtils.sendMessage(subsystem.getIotToken(), JacksonUtils.toJSONString(websocketResult));
|
|
|
+ if (!invoked) {
|
|
|
LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败,指令下发iot服务失败");
|
|
|
throw new RuntimeException();
|
|
|
}
|
|
|
- }else {
|
|
|
- LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败,未找到对应的报警主机,报警控制器编码:{}",id);
|
|
|
+ } else {
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败,未找到对应的报警主机,报警控制器编码:{}", id);
|
|
|
throw new RuntimeException();
|
|
|
}
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
- LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败",e);
|
|
|
+ LogUtils.DEVICE_CONTROL_LOG.error("报警主机布撤防控制失败", e);
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
@@ -188,12 +188,12 @@ public class IotAlarmHostServiceImpl implements IIotAlarmHostService, RouterServ
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public Object execute(WebsocketExecuteReq req) {
|
|
|
try {
|
|
|
- if (WebSocketConstants.ON_LINE_STATUS.equals(req.getEvent())){
|
|
|
+ if (WebSocketConstants.ON_LINE_STATUS.equals(req.getEvent())) {
|
|
|
changeAlarmHostStatus(req);
|
|
|
- }else if(WebSocketConstants.SUB_SYSTEM_STATUS.equals(req.getEvent())){
|
|
|
+ } else if (WebSocketConstants.SUB_SYSTEM_STATUS.equals(req.getEvent())) {
|
|
|
changeSubSystemStatus(req);
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
throw new RuntimeException(e);
|
|
|
}
|