设备增加同步告警状态
This commit is contained in:
parent
82b7fb036d
commit
658c567917
|
@ -0,0 +1,17 @@
|
||||||
|
package com.zjyr.beidouservice.constenum;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonValue;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Getter
|
||||||
|
public enum DeviceAlarmStatusEnum {
|
||||||
|
INIT(0, "初始化"),
|
||||||
|
ALARMING(1, "告警中"),
|
||||||
|
FINAL_STATE(2, "告警终态"),
|
||||||
|
;
|
||||||
|
@JsonValue
|
||||||
|
private final Integer code;
|
||||||
|
private final String msg;
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DeviceMapper {
|
public interface DeviceMapper {
|
||||||
|
@ -15,5 +16,7 @@ public interface DeviceMapper {
|
||||||
|
|
||||||
|
|
||||||
DeviceDO selectDeviceByDeviceId(@Param("deviceId") Long deviceId);
|
DeviceDO selectDeviceByDeviceId(@Param("deviceId") Long deviceId);
|
||||||
|
|
||||||
|
void batchUpdateDeviceAlarmStatus(@Param("ids") Set<Integer> alarmingDeviceIds, @Param("status") Integer code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,10 @@ public class DeviceDO {
|
||||||
* 警报器功率
|
* 警报器功率
|
||||||
*/
|
*/
|
||||||
private Integer power;
|
private Integer power;
|
||||||
|
/**
|
||||||
|
* 告警状态
|
||||||
|
*/
|
||||||
|
private Integer alarmStatus;
|
||||||
/**
|
/**
|
||||||
* 创建时间
|
* 创建时间
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.zjyr.beidouservice.service;
|
package com.zjyr.beidouservice.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.zjyr.beidouservice.pojo.dataobject.AlarmDeviceTaskDO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.DeviceReqDTO;
|
import com.zjyr.beidouservice.pojo.dto.DeviceReqDTO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.DeviceRespDTO;
|
import com.zjyr.beidouservice.pojo.dto.DeviceRespDTO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.DeviceSearchDTO;
|
import com.zjyr.beidouservice.pojo.dto.DeviceSearchDTO;
|
||||||
|
@ -22,4 +23,11 @@ public interface DeviceService {
|
||||||
*/
|
*/
|
||||||
DeviceRespDTO getDeviceByDeviceId(DeviceSearchDTO deviceSearchDTO);
|
DeviceRespDTO getDeviceByDeviceId(DeviceSearchDTO deviceSearchDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据设备任务更新设备告警状态
|
||||||
|
*
|
||||||
|
* @param deviceTaskDOS
|
||||||
|
*/
|
||||||
|
void refreshDeviceAlarmStatus(List<AlarmDeviceTaskDO> deviceTaskDOS);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package com.zjyr.beidouservice.service.impl;
|
package com.zjyr.beidouservice.service.impl;
|
||||||
|
|
||||||
|
import com.zjyr.beidouservice.common.impl.AlarmControlTypeName;
|
||||||
|
import com.zjyr.beidouservice.common.impl.AlarmModeName;
|
||||||
|
import com.zjyr.beidouservice.common.impl.AlarmTypeName;
|
||||||
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
|
import com.zjyr.beidouservice.common.impl.SensorControlTunnelName;
|
||||||
import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
||||||
import com.zjyr.beidouservice.constenum.ApprovalStatusEnum;
|
import com.zjyr.beidouservice.constenum.ApprovalStatusEnum;
|
||||||
|
@ -21,6 +24,7 @@ import com.zjyr.beidouservice.pojo.dto.DeviceInfoDTO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.task.AlarmTaskReqDTO;
|
import com.zjyr.beidouservice.pojo.dto.task.AlarmTaskReqDTO;
|
||||||
import com.zjyr.beidouservice.service.AdapterProtocolService;
|
import com.zjyr.beidouservice.service.AdapterProtocolService;
|
||||||
import com.zjyr.beidouservice.service.AlarmTaskService;
|
import com.zjyr.beidouservice.service.AlarmTaskService;
|
||||||
|
import com.zjyr.beidouservice.service.DeviceService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -39,6 +43,8 @@ import java.util.Objects;
|
||||||
public class AlarmTaskServiceImpl implements AlarmTaskService {
|
public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
@Resource
|
@Resource
|
||||||
AdapterProtocolService adapterProtocolService;
|
AdapterProtocolService adapterProtocolService;
|
||||||
|
@Resource
|
||||||
|
DeviceService deviceService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AlarmTaskMapper alarmTaskMapper;
|
AlarmTaskMapper alarmTaskMapper;
|
||||||
|
@ -70,19 +76,6 @@ public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
//生成规则为"JL"+"当前年月日"+"4位自增ID"
|
//生成规则为"JL"+"当前年月日"+"4位自增ID"
|
||||||
String taskId = generateRecordNumber();
|
String taskId = generateRecordNumber();
|
||||||
|
|
||||||
//执行控制任,默认只有一种通道方式
|
|
||||||
// adapterProtocolService.createSensorControlProtocol(
|
|
||||||
// Integer.parseInt(taskId),
|
|
||||||
// AlarmModeName.getByCode(alarmTaskReqDTO.getAlarmMode()),
|
|
||||||
// AlarmControlTypeName.getByCode(alarmTaskReqDTO.getAlarmType()),
|
|
||||||
// AlarmTypeName.getByCode(alarmTaskReqDTO.getAlarmKind()),
|
|
||||||
// alarmTaskReqDTO.getControlChannel(),
|
|
||||||
// alarmTaskReqDTO.getSendTime(),
|
|
||||||
// deviceInfo.getCityCodes(),
|
|
||||||
// deviceInfo.getCountyCodes(),
|
|
||||||
// deviceInfo.getDeviceIds()
|
|
||||||
// );
|
|
||||||
|
|
||||||
AlarmTaskDO alarmTaskDO = AlarmTaskDO.builder()
|
AlarmTaskDO alarmTaskDO = AlarmTaskDO.builder()
|
||||||
.taskIdStr(taskId)
|
.taskIdStr(taskId)
|
||||||
.alarmType(alarmTaskReqDTO.getAlarmType())
|
.alarmType(alarmTaskReqDTO.getAlarmType())
|
||||||
|
@ -100,6 +93,21 @@ public class AlarmTaskServiceImpl implements AlarmTaskService {
|
||||||
|
|
||||||
List<AlarmDeviceTaskDO> alarmDeviceTaskDOS = getAlarmDeviceTaskDOS(alarmTaskReqDTO, deviceInfo, generatedId);
|
List<AlarmDeviceTaskDO> alarmDeviceTaskDOS = getAlarmDeviceTaskDOS(alarmTaskReqDTO, deviceInfo, generatedId);
|
||||||
alarmDeviceTaskMapper.addAlarmDevTaskInfoList(alarmDeviceTaskDOS);
|
alarmDeviceTaskMapper.addAlarmDevTaskInfoList(alarmDeviceTaskDOS);
|
||||||
|
// 刷新设备告警状态
|
||||||
|
deviceService.refreshDeviceAlarmStatus(alarmDeviceTaskDOS);
|
||||||
|
//执行控制任,默认只有一种通道方式
|
||||||
|
adapterProtocolService.createSensorControlProtocol(
|
||||||
|
generatedId.intValue(),
|
||||||
|
AlarmModeName.getByCode(alarmTaskReqDTO.getAlarmMode()),
|
||||||
|
AlarmControlTypeName.getByCode(alarmTaskReqDTO.getAlarmType()),
|
||||||
|
AlarmTypeName.getByCode(alarmTaskReqDTO.getAlarmKind()),
|
||||||
|
alarmTaskReqDTO.getControlChannel(),
|
||||||
|
alarmTaskReqDTO.getSendTime(),
|
||||||
|
deviceInfo.getCityCodes(),
|
||||||
|
deviceInfo.getCountyCodes(),
|
||||||
|
deviceInfo.getDeviceIds()
|
||||||
|
);
|
||||||
|
|
||||||
return MyResp.build();
|
return MyResp.build();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
package com.zjyr.beidouservice.service.impl;
|
package com.zjyr.beidouservice.service.impl;
|
||||||
|
|
||||||
|
|
||||||
|
import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
||||||
|
import com.zjyr.beidouservice.constenum.DeviceAlarmStatusEnum;
|
||||||
import com.zjyr.beidouservice.mapper.DeviceMapper;
|
import com.zjyr.beidouservice.mapper.DeviceMapper;
|
||||||
|
import com.zjyr.beidouservice.pojo.dataobject.AlarmDeviceTaskDO;
|
||||||
import com.zjyr.beidouservice.pojo.dataobject.DeviceDO;
|
import com.zjyr.beidouservice.pojo.dataobject.DeviceDO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.DeviceByLocationDTO;
|
import com.zjyr.beidouservice.pojo.dto.DeviceByLocationDTO;
|
||||||
import com.zjyr.beidouservice.pojo.dto.DeviceReqDTO;
|
import com.zjyr.beidouservice.pojo.dto.DeviceReqDTO;
|
||||||
|
@ -14,6 +17,8 @@ import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -82,4 +87,25 @@ public class DeviceServiceImpl implements DeviceService {
|
||||||
|
|
||||||
return respDTO;
|
return respDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshDeviceAlarmStatus(List<AlarmDeviceTaskDO> deviceTaskDOS) {
|
||||||
|
// 全部有告警任务的设备id
|
||||||
|
Set<Integer> deviceIdSet = deviceTaskDOS.stream().map(AlarmDeviceTaskDO::getDeviceId).collect(Collectors.toSet());
|
||||||
|
// 告警状态为执行中的设备id
|
||||||
|
Set<Integer> alarmingDeviceIds = deviceTaskDOS.stream()
|
||||||
|
.filter(s -> TaskStatusName.TASK_EXECUTING.getValue().equals(s.getStatus()))
|
||||||
|
.map(AlarmDeviceTaskDO::getDeviceId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
// 去掉执行中的,剩下的需要更新为终态
|
||||||
|
deviceIdSet.removeAll(alarmingDeviceIds);
|
||||||
|
|
||||||
|
if (!alarmingDeviceIds.isEmpty()) {
|
||||||
|
deviceMapper.batchUpdateDeviceAlarmStatus(alarmingDeviceIds, DeviceAlarmStatusEnum.ALARMING.getCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deviceIdSet.isEmpty()) {
|
||||||
|
deviceMapper.batchUpdateDeviceAlarmStatus(deviceIdSet, DeviceAlarmStatusEnum.FINAL_STATE.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.zjyr.beidouservice.common.impl.TaskStatusName;
|
||||||
import com.zjyr.beidouservice.mapper.AlarmDeviceTaskMapper;
|
import com.zjyr.beidouservice.mapper.AlarmDeviceTaskMapper;
|
||||||
import com.zjyr.beidouservice.pojo.dataobject.AlarmDeviceTaskDO;
|
import com.zjyr.beidouservice.pojo.dataobject.AlarmDeviceTaskDO;
|
||||||
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
import com.zjyr.beidouservice.pojo.po.AlarmTaskResult;
|
||||||
|
import com.zjyr.beidouservice.service.DeviceService;
|
||||||
import com.zjyr.beidouservice.service.SensorTaskService;
|
import com.zjyr.beidouservice.service.SensorTaskService;
|
||||||
import com.zjyr.beidouservice.utils.DateUtil;
|
import com.zjyr.beidouservice.utils.DateUtil;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -27,6 +28,8 @@ public class AlarmStatusTask {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
SensorTaskService sensorTaskService;
|
SensorTaskService sensorTaskService;
|
||||||
|
@Resource
|
||||||
|
DeviceService deviceService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AlarmDeviceTaskMapper alarmDeviceTaskMapper;
|
AlarmDeviceTaskMapper alarmDeviceTaskMapper;
|
||||||
|
@ -77,5 +80,7 @@ public class AlarmStatusTask {
|
||||||
|
|
||||||
// 结果入库
|
// 结果入库
|
||||||
alarmDeviceTaskMapper.batchUpdate(deviceTaskList);
|
alarmDeviceTaskMapper.batchUpdate(deviceTaskList);
|
||||||
|
// 刷新设备状态
|
||||||
|
deviceService.refreshDeviceAlarmStatus(deviceTaskList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,5 +54,14 @@
|
||||||
where device_id = #{deviceId}
|
where device_id = #{deviceId}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="batchUpdateDeviceAlarmStatus">
|
||||||
|
update device
|
||||||
|
set alarm_status = #{status}
|
||||||
|
where device_id in
|
||||||
|
<foreach collection="ids" item="item" separator="," open="(" close=")">
|
||||||
|
#{item}
|
||||||
|
</foreach>
|
||||||
|
</update>
|
||||||
|
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
Loading…
Reference in New Issue