Commit d7c66356 authored by 王蔡翾's avatar 王蔡翾
Browse files

更新

parent df0b20b6
......@@ -52,5 +52,9 @@ public class OperationJobController extends BaseController {
public Result<List<OperationJobVO>> queryWarn() {
return Result.data(operationJobService.queryWarn());
}
@PostMapping("/page/operation")
public TableDataInfo pageOperation(@RequestBody OperationJobDTO operationJobDTO) {
startPage(operationJobDTO.getPageNum(), operationJobDTO.getPageSize());
return getDataTable(operationJobService.queryJobAndOperationTypeList(operationJobDTO));
}
}
......@@ -55,9 +55,10 @@ public class OperationRecordController extends BaseController {
startPage(operationRecordDTO.getPageNum(), operationRecordDTO.getPageSize());
return getDataTable(tbOperationRecordService.queryRunLogRecordList(operationRecordDTO));
}
@PostMapping("/warn/run")
public Result <List<OperationRecordVO>> pageWarnRun(@RequestBody OperationRecordDTO operationRecordDTO) {
return Result.data(tbOperationRecordService.queryRunLogRecordListAndWarnMessage(operationRecordDTO));
@PostMapping("/page/warn/run")
public TableDataInfo pageWarnRun(@RequestBody OperationRecordDTO operationRecordDTO) {
startPage(operationRecordDTO.getPageNum(), operationRecordDTO.getPageSize());
return getDataTable(tbOperationRecordService.queryRunLogRecordListAndWarnMessage(operationRecordDTO));
}
}
package com.example.operation_platform.controller;
import com.example.operation_platform.task.OperationDoTask;
import com.example.operation_platform.task.RunLogTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -12,11 +13,19 @@ public class TaskController {
@Autowired
private OperationDoTask operationDoTask;
@Autowired
private RunLogTask runLogTask;
@GetMapping("/run-task")
public String runTask() {
operationDoTask.runScheduleOperationJobsNow();
return "定时任务已手动触发";
return "维保定时任务已手动触发";
}
@GetMapping("/run-log-task")
public String runLogTask() {
runLogTask.processRealTimeAlerts();
return "告警定时任务已手动触发";
}
}
......@@ -55,5 +55,7 @@ public interface OperationJobMapper extends BaseMapper<OperationJob> {
// 定时任务所需信息
List<OperationJobVO> queryRunJobList(OperationJobDTO operationJobDTO);
//维保任务详情页面的第一个接口
List<OperationJobVO> queryJobAndOperationTypeList(OperationJobDTO operationJobDTO);
}
......@@ -21,7 +21,7 @@ public class OperationJobDTO extends OperationJob {
private LocalDate date;
private Integer year;
private Integer month;
private Integer stationId;
private String stationId;
private Integer robotId;
private Integer droneId;
......
......@@ -20,5 +20,7 @@ public class OperationJobVO extends OperationJob {
private String warnMessage;
private Integer runLogId;
private String stationId;
private Integer operationId;
private String itemId;
private String operationItems;
}
......@@ -52,4 +52,6 @@ public interface OperationJobService extends IService<OperationJob> {
void updateRunLogStatus(Integer id);
//首页轮播告警信息
List<OperationJobVO> queryWarn();
//维保任务详情页面的第一个接口
List<OperationJobVO> queryJobAndOperationTypeList(OperationJobDTO operationJobDTO);
}
......@@ -51,5 +51,10 @@ public class OperationJobServiceImpl extends ServiceImpl<OperationJobMapper, Ope
List<OperationJobVO> operationJobVO = baseMapper.queryWarn();
return operationJobVO;
}
@Override
public List<OperationJobVO> queryJobAndOperationTypeList(OperationJobDTO operationJobDTO) {
List<OperationJobVO> operationJobVO = baseMapper.queryJobAndOperationTypeList(operationJobDTO);
return operationJobVO;
}
}
package com.example.operation_platform.task;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.operation_platform.mapper.MessageMapper;
import com.example.operation_platform.mapper.OperationDoMapper;
......@@ -17,9 +18,12 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Component
......@@ -39,95 +43,108 @@ public class RunLogTask {
@Autowired
private OperationJobMapper operationJobMapper;
private final Map<Integer, OperationJobVO> alertTrackingMap = new ConcurrentHashMap<>();
/**
* 处理带有告警信息的操作任务
* @param operationJobVOList 操作任务列表
* 实时告警任务(每5分钟执行)
*/
public void processOperationsWithWarnings(List<OperationJobVO> operationJobVOList) {
// 1. 首先为列表中的任务添加告警信息
List<OperationJobVO> enrichedList = enrichOperationJobListWithWarnMessages(operationJobVOList);
@Scheduled(cron = "0 */5 * * * ?")
public void processRealTimeAlerts() {
// 1. 获取需要发送短信的完整数据列表
List<OperationJobVO> alertJobs = enrichOperationJobListWithWarnMessages(getBaseOperationList());
// 2. 对每个带有告警信息的任务进行处理
for (OperationJobVO job : enrichedList) {
if (job.getWarnMessage() != null && !job.getWarnMessage().isEmpty()) {
handleOperationWithWarning(job);
}
}
// 2. 直接发送短信(列表已包含所有需要的信息)
alertJobs.forEach(this::sendAlertSms);
}
/**
* 处理单个带有告警信息的操作任务
* @param job 操作任务
* 每日状态检查(每天0点执行)
*/
private void handleOperationWithWarning(OperationJobVO job) {
Integer operationId = job.getOperationId();
boolean shouldContinue = true;
@Scheduled(cron = "0 0 0 * * ?")
public void dailyStatusCheck() {
// 1. 获取需要检查的完整数据列表
List<OperationJobVO> alertJobs = enrichOperationJobListWithWarnMessages(getBaseOperationList());
while (shouldContinue) {
try {
// 1. 检查操作的当前状态
OperationJob operationjob = operationJobMapper.selectById(operationId);
if (operationjob == null) {
logger.error("未找到ID为{}的操作记录", operationId);
shouldContinue = false;
continue;
// 2. 检查状态并发送提醒
alertJobs.forEach(job -> {
OperationJob current = operationJobMapper.selectById(job.getOperationId());
if (current != null && current.getFinishStatus() != 4) {
sendAlertSms(job); // 使用列表中原有的完整信息
}
// 2. 如果状态为4,停止处理该任务
if (operationjob.getFinishStatus() == 4) {
logger.info("操作ID {} 已完成(状态4),停止发送通知", operationId);
shouldContinue = false;
continue;
});
}
// 3. 发送短信通知
sendAlertSms(job);
// 4. 等待5分钟后再次检查(可根据需要调整时间间隔)
Thread.sleep(300000); // 5分钟(300000毫秒)
} catch (InterruptedException e) {
logger.error("处理操作ID {} 时线程被中断", operationId, e);
Thread.currentThread().interrupt();
shouldContinue = false;
/**
* 发送短信(完全使用OperationJobVO中的数据)
*/
private void sendAlertSms(OperationJobVO job) {
List<String> phones = getPhoneByOperation(job.getOperationId());
phones.forEach(phone -> {
try {
JSONObject params = new JSONObject();
// 直接使用VO中的完整数据
params.put("stationName", job.getStationName());
params.put("device", job.getRobotName());
params.put("alert", job.getWarnMessage());
params.put("time", job.getStartTime());
aliSmsUtil.sendSms(phone, params, "SMS_481615406");
logger.info("已发送短信至 {} | 操作ID: {} | 设备: {} | 告警: {}",
phone, job.getOperationId(), job.getRobotName(), job.getWarnMessage());
} catch (Exception e) {
logger.error("处理操作ID {} 时发生错误", operationId, e);
shouldContinue = false;
}
logger.error("发送失败: {} | 错误: {}", phone, e.getMessage());
}
});
}
/**
* 发送告警短信
* @param job 操作任务
* 获取基础操作列表(仅获取operationId用于查询)
*/
private void sendAlertSms(OperationJobVO job) {
List<String> phones = getPhoneByOperation(job.getOperationId());
if (phones.isEmpty()) {
logger.warn("操作ID {} 没有关联的手机号码", job.getOperationId());
return;
private List<OperationJobVO> getBaseOperationList() {
// 只需要查询operationId用于关联数据
// List<OperationJob> operationJobs = operationJobMapper.selectList(
// new LambdaQueryWrapper<OperationJob>()
// .select(OperationJob::getId)
// );
List<OperationJob> operationJobs = operationJobMapper.selectList(
new LambdaQueryWrapper<>());
return operationJobs.stream()
.map(job -> {
OperationJobVO vo = new OperationJobVO();
BeanUtil.copyProperties(job, vo);
return vo;
})
.collect(Collectors.toList());
}
for (String phone : phones) {
/**
* 发送每日提醒短信
*/
private void sendDailyReminder(OperationJobVO job) {
List<String> phones = getPhoneByOperation(job.getOperationId());
phones.forEach(phone -> {
try {
// 构建短信模板参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("stationName", job.getStationName()); // 站点名称
jsonObject.put("device", job.getRobotName()); // 设备名称
jsonObject.put("alert", job.getWarnMessage()); // 告警类型
jsonObject.put("time", job.getStartTime()); // 开始时间
// 发送短信
aliSmsUtil.sendSms(phone, jsonObject, "SMS_481615406");
logger.info("已向 {} 发送操作ID {} 的告警短信", phone, job.getOperationId());
JSONObject params = new JSONObject();
params.put("stationName", job.getStationName());
params.put("device", job.getRobotName());
params.put("alert", job.getWarnMessage());
params.put("time", job.getStartTime());
aliSmsUtil.sendSms(phone, params, "SMS_481615406");
logger.info("已发送每日提醒至:{},任务ID:{}", phone, job.getOperationId());
} catch (Exception e) {
logger.error("向 {} 发送操作ID {} 的告警短信失败", phone, job.getOperationId(), e);
}
logger.error("发送每日提醒失败,手机号:{}", phone, e);
}
});
}
/**
* 为操作任务列表添加告警信息
*
* @param operationJobVOList 原始操作任务列表
* @return 带有告警信息的操作任务列表
*/
......@@ -156,8 +173,10 @@ public class RunLogTask {
return operationJobVOList;
}
/**
* 获取操作关联的手机号列表
*
* @param operationId 操作ID
* @return 手机号列表
*/
......@@ -216,4 +235,5 @@ public class RunLogTask {
.distinct()
.collect(Collectors.toList());
}
}
\ No newline at end of file
......@@ -175,9 +175,11 @@
select
top.tb_run_log_id AS runLogId
from tb_operation top
left join
tb_operation_job tp on top.id = tp.operation_id
where
top.runlog_or_operation = 1
AND top.finish_status NOT IN (2, 4)
AND tp.finish_status NOT IN (2, 4)
</select>
<select id="queryEquipment" resultType="com.example.operation_platform.model.vo.OperationDoVO">
select DISTINCT
......
......@@ -58,7 +58,7 @@
and tp.operation_type like concat('%',#{operationType},'%')
</if>
<if test="stationId != null and stationId != ''">
and top.station_id = #{stationId}
and tp.station_id = #{stationId}
</if>
<if test="username != null and username != ''">
and bw.username = #{username}
......@@ -137,7 +137,9 @@
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName, -- 保留操作人员名称
top.runlog_or_operation AS runlog_or_operation
top.runlog_or_operation AS runlog_or_operation,
tp.tb_run_log_id AS runLogId,
tp.station_id AS stationId
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
......@@ -154,7 +156,7 @@
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
<where>
<if test="stationId != null and stationId != ''">
and top.station_id = #{stationId}
and tp.station_id = #{stationId}
</if>
<if test="username != null and username != ''">
and bw.username = #{username}
......@@ -184,7 +186,10 @@
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
bw.worker_name AS workerName -- 保留操作人员名称
bw.worker_name AS workerName,
tp.tb_run_log_id AS runLogId,
tp.station_id AS stationId
-- 保留操作人员名称
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
......@@ -224,7 +229,7 @@
and tp.operation_type like concat('%',#{operationType},'%')
</if>
<if test="stationId != null and stationId != ''">
and top.station_id = #{stationId}
and tp.station_id = #{stationId}
</if>
<if test="finishStatus != null and finishStatus != ''">
and top.finish_status = #{finishStatus}
......@@ -235,6 +240,9 @@
<if test="droneId != null and droneId != ''">
and tp.drone_id = #{droneId}
</if>
<if test="id != null and id != ''">
and top.id = #{id}
</if>
</where>
ORDER BY top.start_time DESC
</select>
......@@ -280,18 +288,89 @@
tp.operation_type AS operationType,
bs.name AS stationName,
COALESCE(br.name, dr.name) AS robotName,
tp.run_log_id AS runLogId,
tp.tb_run_log_id AS runLogId,
top.start_time AS startTime,
tp.station_id AS stationId,
top.operation_id AS operationId,
top.operation_id AS operationId
from
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
LEFT JOIN bs_robot br ON tp.robot_id = br.id
LEFT JOIN uav_drone dr ON tp.drone_id = dr.id
WHERE
tp.runlog_or_operation=1
AND tp.finish_status NOT 4
</select>
<!-- 维保详情页面的第一个模块信息-->
<select id="queryJobAndOperationTypeList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
SELECT
top.id,
tp.operation_type AS operationType,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
tp.robot_id AS robotId,
tp.drone_id AS droneId,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
WHERE FIND_IN_SET(bti.id, tp.item_id) > 0
) AS operationItems,
tp.item_id AS itemId,
tp.station_id AS stationId
FROM
tb_operation_job top
LEFT JOIN tb_operation tp ON top.operation_id = tp.id
LEFT JOIN bs_station bs ON tp.station_id = bs.id
-- 关联 robot 表(通过 tb_message)
LEFT JOIN bs_robot br ON tp.robot_id = br.id
-- 关联 drone 表(通过 tb_message)
LEFT JOIN uav_drone ud ON tp.drone_id = ud.id
LEFT JOIN tb_operation_item bti ON tp.item_id = bti.id
<where>
top.runlog_or_operation = 0
<if test="robotName != null and robotName != ''">
and br.name like concat('%',#{robotName},'%')
or ud.name like concat('%',#{robotName},'%')
</if>
<if test="stationName != null and stationName != ''">
and bs.name like concat('%',#{stationName},'%')
</if>
<if test="workerName != null and workerName != ''">
and bw.worker_name like concat('%',#{workerName},'%')
</if>
<if test="status != null and status != ''">
and top.status like concat('%',#{status},'%')
</if>
<if test="startTime != null ">
and top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null ">
and top.endTime &lt;= #{endTime}
</if>
<if test="operationType != null and operationType != ''">
and tp.operation_type like concat('%',#{operationType},'%')
</if>
<if test="stationId != null and stationId != ''">
and tp.station_id = #{stationId}
</if>
<if test="username != null and username != ''">
and bw.username = #{username}
</if>
<if test="id != null and id != ''">
and top.id = #{id}
</if>
</where>
ORDER BY top.start_time DESC
</select>
</mapper>
</mapper>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment