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

优化

parent f2f9d720
......@@ -3,7 +3,9 @@ package com.example.operation_platform.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.example.operation_platform.model.dto.OperationJobDTO;
import com.example.operation_platform.model.entity.OperationJob;
import com.example.operation_platform.model.vo.JobVO;
import com.example.operation_platform.model.vo.OperationJobVO;
import io.swagger.models.Operation;
import java.util.List;
......
......@@ -6,9 +6,8 @@ import com.example.operation_platform.model.dto.OperationJobDTO;
import com.example.operation_platform.model.entity.OperationJob;
import com.example.operation_platform.model.vo.OperationJobVO;
import com.example.operation_platform.service.OperationJobService;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.List;
@Service
......@@ -16,18 +15,97 @@ public class OperationJobServiceImpl extends ServiceImpl<OperationJobMapper, Ope
@Override
public List<OperationJobVO> queryJobList(OperationJobDTO operationJobDTO) {
List<OperationJobVO> operationJobVOS = baseMapper.queryJobList(operationJobDTO);
// 定义日期格式
SimpleDateFormat fullFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
// 转换数据
for (OperationJobVO source : operationJobVOS) {
// 处理开始时间
if (source.getStartTime() != null) {
// 使用 SimpleDateFormat 格式化时间,不会进行四舍五入,直接截断
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getStartTime()) :
fullFormat.format(source.getStartTime());
source.setStartTimeStr(formattedTime);
}
// 处理结束时间
if (source.getEndTime() != null) {
// 使用 SimpleDateFormat 格式化时间,不会进行四舍五入,直接截断
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getEndTime()) :
fullFormat.format(source.getEndTime());
source.setEndTimeStr(formattedTime);
}
}
return operationJobVOS;
}
@Override
public List<OperationJobVO> queryJobListByDate(OperationJobDTO operationJobDTO) {
List<OperationJobVO> operationJobVOS = baseMapper.queryJobListByDate(operationJobDTO);
// 定义日期格式
SimpleDateFormat fullFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
// 转换数据
for (OperationJobVO source : operationJobVOS) {
// 处理开始时间
if (source.getStartTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getStartTime()) :
fullFormat.format(source.getStartTime());
source.setStartTimeStr(formattedTime);
}
// 处理结束时间
if (source.getEndTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getEndTime()) :
fullFormat.format(source.getEndTime());
source.setEndTimeStr(formattedTime);
}
}
return operationJobVOS;
}
@Override
public List<OperationJobVO> queryAllJobList(OperationJobDTO operationJobDTO) {
// 获取原始数据
List<OperationJobVO> operationJobVOS = baseMapper.queryAllJobList(operationJobDTO);
// 定义日期格式
SimpleDateFormat fullFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
// 转换数据
for (OperationJobVO source : operationJobVOS) {
// 处理开始时间
if (source.getStartTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getStartTime()) :
fullFormat.format(source.getStartTime());
source.setStartTimeStr(formattedTime);
}
// 处理结束时间
if (source.getEndTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getEndTime()) :
fullFormat.format(source.getEndTime());
source.setEndTimeStr(formattedTime);
}
}
return operationJobVOS;
}
@Override
public List<OperationJobVO> queryRunLogJobList(OperationJobDTO operationJobDTO) {
List<OperationJobVO> operationJobVOS = baseMapper.queryRunLogJobList(operationJobDTO);
......@@ -54,6 +132,30 @@ public class OperationJobServiceImpl extends ServiceImpl<OperationJobMapper, Ope
@Override
public List<OperationJobVO> queryJobAndOperationTypeList(OperationJobDTO operationJobDTO) {
List<OperationJobVO> operationJobVO = baseMapper.queryJobAndOperationTypeList(operationJobDTO);
// 定义日期格式
SimpleDateFormat fullFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat dateOnlyFormat = new SimpleDateFormat("yyyy-MM-dd");
// 转换数据
for (OperationJobVO source : operationJobVO) {
// 处理开始时间
if (source.getStartTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getStartTime()) :
fullFormat.format(source.getStartTime());
source.setStartTimeStr(formattedTime);
}
// 处理结束时间
if (source.getEndTime() != null) {
String formattedTime = source.getRunlogOrOperation() != null &&
source.getRunlogOrOperation() == 0 ?
dateOnlyFormat.format(source.getEndTime()) :
fullFormat.format(source.getEndTime());
source.setEndTimeStr(formattedTime);
}
}
return operationJobVO;
}
......
......@@ -18,10 +18,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
......@@ -93,10 +90,14 @@ public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> i
public List<Map<String, Object>> getAlertAndFailureLogs() {
List<Map<String, Object>> result = new ArrayList<>();
List<Integer> runLogIds = operationDoService.queryRunLogIdList();
Set<String> uniqueKeys = new HashSet<>();
for (Integer runLogId : runLogIds) {
List<UavOperateLogEntity> logs = getInfoById(runLogId.toString());
for (UavOperateLogEntity log : logs) {
if (log.getContent().contains("告警") || log.getContent().contains("失败")) {
String key = runLogId + "_" + log.getContent();
if (uniqueKeys.add(key)) { // 如果添加成功,说明是唯一的
Map<String, Object> entry = new HashMap<>();
entry.put("run_log_id", runLogId);
entry.put("content", log.getContent());
......@@ -105,6 +106,7 @@ public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> i
}
}
}
}
return result;
}
@Override
......
......@@ -22,7 +22,28 @@ public class TbOperationRecordServiceImpl extends ServiceImpl<TbOperationRecordM
@Override
public List<OperationRecordVO> queryrecordList(OperationRecordDTO operationRecordDTO) {
return baseMapper.queryrecordList(operationRecordDTO);
List<OperationRecordVO> operationRecordVOList= baseMapper.queryrecordList(operationRecordDTO);
List<Map<String, Object>> alertAndFailureLogs = runLogService.getAlertAndFailureLogs();
// 创建一个Map来存储日志ID和日志内容的映射
Map<Integer, String> logMap = new HashMap<>();
for (Map<String, Object> log : alertAndFailureLogs) {
Integer logId = (Integer) log.get("run_log_id");
String content = (String) log.get("content");
if (logId != null && content != null && !content.isEmpty()) {
logMap.put(logId, content);
}
}
// 遍历每个操作记录,根据run_log_id获取对应的告警信息
for (OperationRecordVO operationRecordVO : operationRecordVOList) {
Integer tbRunLogId = operationRecordVO.getRunLogId();
if (tbRunLogId != null && logMap.containsKey(tbRunLogId)) {
operationRecordVO.setOperationItems(logMap.get(tbRunLogId));
}
}
return operationRecordVOList;
}
@Override
public List<OperationRecordVO> queryrecordListById(String stationId,Long robotId) {
......
package com.example.operation_platform.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.operation_platform.mapper.MessageMapper;
import com.example.operation_platform.mapper.OperationDoMapper;
......@@ -17,9 +16,11 @@ 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.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
import org.json.JSONObject;
......@@ -27,24 +28,27 @@ import org.json.JSONObject;
public class OperationDoTask {
private static final Logger logger = LoggerFactory.getLogger(OperationDoTask.class);
@Autowired
private OperationDoMapper operationDoMapper;
@Autowired
private OperationJobMapper operationJobMapper;
@Autowired
private MessageMapper messageMapper;
@Autowired
private WorkerMapper workerMapper;
@Autowired
private AliSmsUtil aliSmsUtil;
// 使用 ConcurrentMap 来存储已经发送过的 operationJobId
private final ConcurrentMap<Integer, Boolean> sentSmsTracker = new ConcurrentHashMap<>();
@Scheduled(cron = "0 0 0 * * ?") // 每天午夜执行
@Scheduled(cron = "0 0 7 * * ?") // 每天7点执行
public void scheduleOperationJobs() {
List<OperationDoEntity> operations = operationDoMapper.selectList(null);
LocalDate now = LocalDate.now(); // 改用 LocalDate 类型
Date now = new Date(); // 改用 Date 类型
for (OperationDoEntity operation : operations) {
// 获取 OperationEntity 实体
......@@ -54,7 +58,7 @@ public class OperationDoTask {
}
// 1. 获取计划参数
LocalDate planStartDate = operation.getStartTime(); // 直接使用 LocalDate
Date planStartDate = operation.getStartTime(); // 直接使用 Date
int cycleDays = operation.getOperationCycle();
int durationDays = operation.getFinishTime();
......@@ -65,38 +69,65 @@ public class OperationDoTask {
.orderByDesc(OperationJob::getStartTime)
);
// 3. 自动生成新任务逻辑
if (existingJobs.isEmpty()) {
if (now.isBefore(planStartDate)) {
if (planStartDate.after(now)) {
// 如果当前时间在计划开始时间之前,只创建一条任务
createOneJob(operation, planStartDate, durationDays);
} else {
// 如果当前时间等于或在计划开始时间之后,创建两条任务
createTwoJobs(operation, planStartDate, cycleDays, durationDays);
}
} else {
// 3. 去除重复任务
removeDuplicateJobs(operation.getId());
// 4. 维护现有任务
maintainTwoValidJobs(operation, existingJobs, cycleDays, durationDays, now);
}
// 4. 更新所有任务状态并发送短信
// 5. 更新所有任务状态并发送短信
updateJobStatusAndSendReminder(operation, now);
}
}
private void removeDuplicateJobs(Integer operationId) {
// 查询当前计划下的所有任务(按时间倒序)
List<OperationJob> jobs = operationJobMapper.selectList(
new LambdaQueryWrapper<OperationJob>()
.eq(OperationJob::getOperationId, operationId)
.orderByDesc(OperationJob::getStartTime)
);
// 使用一个集合来存储唯一的任务
Set<String> uniqueJobKeys = new HashSet<>();
List<OperationJob> jobsToDelete = new ArrayList<>();
for (OperationJob job : jobs) {
String jobKey = job.getStartTime().toString() + "_" + job.getEndTime().toString();
if (uniqueJobKeys.contains(jobKey)) {
jobsToDelete.add(job);
} else {
uniqueJobKeys.add(jobKey);
}
}
// 删除重复的任务
for (OperationJob job : jobsToDelete) {
operationJobMapper.deleteById(job.getId());
}
}
private void createOneJob(OperationDoEntity operation, LocalDate startDate, int durationDays) {
private void createOneJob(OperationDoEntity operation, Date startDate, int durationDays) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
if (operationEntity == null || operationEntity.getRunlogOrOperation() != 0) {
return;
}
LocalDate jobStart = startDate;
LocalDate jobEnd = jobStart.plusDays(durationDays);
Date jobStart = startDate;
Date jobEnd = addDays(jobStart, durationDays);
int finishStatus = 0; // 任务状态为0(未开始)
insertJob(operation, jobStart, jobEnd, finishStatus);
}
private void createTwoJobs(OperationDoEntity operation, LocalDate startDate,
private void createTwoJobs(OperationDoEntity operation, Date startDate,
int cycleDays, int durationDays) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
......@@ -104,21 +135,21 @@ public class OperationDoTask {
return;
}
LocalDate now = LocalDate.now();
Date now = new Date();
// 只有当operation状态为0(进行中)时才创建任务
if ("0".equals(operation.getStatus())) {
// 生成第一条任务
LocalDate job1Start = startDate;
LocalDate job1End = job1Start.plusDays(durationDays);
int job1Status = job1Start.isEqual(now) ? 1 : 0;
Date job1Start = startDate;
Date job1End = addDays(job1Start, durationDays);
int job1Status = job1Start.equals(now) ? 1 : 0;
insertJob(operation, job1Start, job1End, job1Status);
// 生成第二条任务(下一周期)
LocalDate job2Start = job1Start.plusDays(cycleDays);
LocalDate job2End = job2Start.plusDays(durationDays);
Date job2Start = addDays(job1Start, cycleDays);
Date job2End = addDays(job2Start, durationDays);
// 确保第二条任务开始时间在当前时间之后
if (job2Start.isAfter(now)) {
if (job2Start.after(now)) {
int job2Status = 0;
insertJob(operation, job2Start, job2End, job2Status);
}
......@@ -126,7 +157,7 @@ public class OperationDoTask {
}
private void maintainTwoValidJobs(OperationDoEntity operation, List<OperationJob> existingJobs,
int cycleDays, int durationDays, LocalDate now) {
int cycleDays, int durationDays, Date now) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
if (operationEntity == null || operationEntity.getRunlogOrOperation() != 0) {
......@@ -148,13 +179,24 @@ public class OperationDoTask {
// 只有当operation状态为0(进行中)时才创建新任务
if ("0".equals(operation.getStatus())) {
// 检查最新任务是否已过期
if (latestJob.getEndTime().isBefore(now)) {
if (latestJob.getEndTime().before(now)) {
// 计算新任务开始时间(跳过当前周期)
LocalDate newStart = latestJob.getStartTime().plusDays(cycleDays);
LocalDate newEnd = newStart.plusDays(durationDays);
Date newStart = addDays(latestJob.getStartTime(), cycleDays);
Date newEnd = addDays(newStart, durationDays);
// 确保新任务开始时间在当前时间之后
if (newStart.isAfter(now)) {
if (newStart.after(now)) {
int finishStatus = 0;
insertJob(operation, newStart, newEnd, finishStatus);
return; // 插入新任务后立即返回,避免重复处理
}
} else if (latestJob.getStartTime().equals(now)) {
// 如果最新任务的开始时间等于当前时间,则创建新的任务
Date newStart = addDays(latestJob.getStartTime(), cycleDays);
Date newEnd = addDays(newStart, durationDays);
// 确保新任务开始时间在当前时间之后
if (newStart.after(now)) {
int finishStatus = 0;
insertJob(operation, newStart, newEnd, finishStatus);
return; // 插入新任务后立即返回,避免重复处理
......@@ -163,7 +205,7 @@ public class OperationDoTask {
}
}
private void insertJob(OperationDoEntity operation, LocalDate start, LocalDate end, int finishStatus) {
private void insertJob(OperationDoEntity operation, Date start, Date end, int finishStatus) {
// 创建一个OperationJob实例来安排或记录某个操作的执行
OperationJob job = new OperationJob();
// 设置操作的唯一标识符,以便跟踪和管理
......@@ -178,7 +220,7 @@ public class OperationDoTask {
operationJobMapper.insert(job);
}
private void updateJobStatusAndSendReminder(OperationDoEntity operation, LocalDate now) {
private void updateJobStatusAndSendReminder(OperationDoEntity operation, Date now) {
List<OperationJob> allJobs = operationJobMapper.selectList(
new LambdaQueryWrapper<OperationJob>()
.eq(OperationJob::getOperationId, operation.getId())
......@@ -197,81 +239,79 @@ public class OperationDoTask {
operationJobMapper.updateById(job);
}
// 检查是否需要发送提醒(开始前7天内且任务未完成)
if (shouldSendReminder(job, now)) {
// 检查是否需要发送提醒(开始前7天内或已经开始但未完成)
if (shouldSendReminder(job, now) || (job.getStartTime().before(now) && job.getFinishStatus() != 2 && job.getFinishStatus() != 4)) {
if (job.getRunlogOrOperation() == 0) {
sendTaskNotificationSms(job.getOperationId());
sendTaskNotificationSms(job.getId());
}
}
}
}
private int calculateStatus(OperationJob job, LocalDate now) {
if (job.getEndTime().isBefore(now)) {
private int calculateStatus(OperationJob job, Date now) {
if (job.getEndTime().before(now)) {
return 3; // 已过期
} else if (job.getStartTime().isAfter(now)) {
} else if (job.getStartTime().after(now)) {
return 0; // 未开始
} else {
return 1; // 进行中(start <= now < end)
}
}
private void checkAndSendSms(OperationJob job, LocalDate now) {
LocalDate reminderDate = job.getStartTime().minusDays(7);
// 精确匹配提醒日期,避免重复发送
if (now.isEqual(reminderDate)) {
if (job.getRunlogOrOperation() == 0) {
sendTaskNotificationSms(job.getOperationId());
}
}
}
// private void checkAndSendSms(OperationJob job, Date now) {
// Date reminderDate = addDays(job.getStartTime(), -7);
// // 精确匹配提醒日期,避免重复发送
// if (reminderDate.equals(now)) {
// if (job.getRunlogOrOperation() == 0) {
// sendTaskNotificationSms(job.getOperationId());
// }
// }
// }
private boolean shouldSendReminder(OperationJob job, LocalDate now) {
private boolean shouldSendReminder(OperationJob job, Date now) {
// 任务已被人工完成(状态2或4)则不发送
if (job.getFinishStatus() == 2 || job.getFinishStatus() == 4) {
return false;
}
// 计算距离任务开始时间的天数
long daysUntilStart = ChronoUnit.DAYS.between(now, job.getStartTime());
long daysUntilStart = ChronoUnit.DAYS.between(now.toInstant(), job.getStartTime().toInstant());
// 在开始前7天内(包括当天)发送提醒
return daysUntilStart <= 7 && daysUntilStart >= 0;
}
// 定时任务手动触发方法
public void runScheduleOperationJobsNow() {
scheduleOperationJobs();
}
//阿里云短信服务
/**
* 发送任务通知短信
*
* @param operationId 操作ID
* @param operationJobId 操作ID
*/
private void sendTaskNotificationSms(Integer operationId) {
private void sendTaskNotificationSms(Integer operationJobId) {
// 调用 querymessage 方法获取 MessageNeedDataVo 对象
MessageNeedDataVo messageNeedDataVo = operationDoMapper.querymessage(operationId);
MessageNeedDataVo messageNeedDataVo = operationDoMapper.querymessage(operationJobId);
if (messageNeedDataVo == null) {
logger.error("获取消息数据失败: 找不到操作ID={}的记录", operationId);
logger.error("获取消息数据失败: 找不到操作ID={}的记录", messageNeedDataVo.getOperationId());
return;
}
List<String> phones = getPhoneByOperation(operationId);
for (String phone : phones){
List<String> phones = getPhoneByOperation(messageNeedDataVo.getOperationId());
for (String phone : phones) {
// 构建短信模板参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("stationName", messageNeedDataVo.getStationName());
jsonObject.put("device", messageNeedDataVo.getRobotName());
jsonObject.put("task", messageNeedDataVo.getOperationType());
jsonObject.put("task", "'" + messageNeedDataVo.getOperationType() + "'");
jsonObject.put("time", messageNeedDataVo.getStartTime());
aliSmsUtil.sendSms(phone, jsonObject, "SMS_481630372");
aliSmsUtil.sendSms(phone, jsonObject, "SMS_483275444");
}
}
/**
......@@ -336,4 +376,11 @@ public class OperationDoTask {
.collect(Collectors.toList());
}
// 辅助方法:增加天数
private Date addDays(Date date, int days) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, days);
return cal.getTime();
}
}
package com.example.operation_platform.task;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.operation_platform.mapper.MessageMapper;
import com.example.operation_platform.mapper.OperationDoMapper;
......@@ -18,6 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
......@@ -57,7 +61,7 @@ public class RunLogTask {
/**
* 每日状态检查(每天0点执行)
*/
@Scheduled(cron = "0 0 0 * * ?")
@Scheduled(cron = "0 0 7 * * ?")//每天七点触发
public void dailyStatusCheck() {
// 1. 获取需要检查的完整数据列表
List<RunLogWarnMessageVO> alertJobs = runLogService.getAlertLogs();
......@@ -80,22 +84,29 @@ public class RunLogTask {
*/
private void sendAlertSms(RunLogWarnMessageVO job) {
List<String> phones = getPhoneByOperation(job.getId());
phones.forEach(phone -> {
for (String phone : phones) {
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");
params.put("alert", "'"+job.getWarnMessage()+"'");
// 将 Date 类型的 startTime 转换为保留到分钟的字符串
LocalDateTime startTimeLocal = job.getStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
String startTimeStr = startTimeLocal.format(formatter);
params.put("time", startTimeStr);
SendSmsResponse sms483225093 = aliSmsUtil.sendSms(phone, params, "SMS_483170116");
System.out.println("-----------------------------------------------------");
System.out.println(sms483225093);
System.out.println("-----------------------------------------------------");
logger.info("已发送短信至 {} | 操作ID: {} | 设备: {} | 告警: {}",
phone, job.getId(), job.getRobotName(), job.getWarnMessage());
} catch (Exception e) {
logger.error("发送失败: {} | 错误: {}", phone, e.getMessage());
}
});
}
}
/**
......
......@@ -18,6 +18,10 @@ spring:
username: ruzhoukj
password: ruzhoukj@2023
authentication-database: admin
servlet:
multipart:
max-file-size: 50MB
max-request-size: 100MB
mybatis-plus:
# MyBatis Mapper所对应的XML文件位置
......
......@@ -9,6 +9,7 @@
tw.operation_guide operationGuide
from
tb_operation_item tw
order by tw.create_time desc
</select>
<select id="queryByIdList" resultType="com.example.operation_platform.model.entity.OperationItem">
......
......@@ -3,9 +3,8 @@
<mapper namespace="com.example.operation_platform.mapper.OperationDoMapper">
<select id="queryDoList" resultType="com.example.operation_platform.model.vo.OperationDoVO">
SELECT
SELECT DISTINCT
top.id AS id,
tj.id AS operationJobId,
top.operation_cycle AS operationCycle,
top.start_time AS startTime,
COALESCE(br.name, dr.name) AS robotName,
......@@ -19,8 +18,8 @@
top.finish_time AS finishTime,
top.drone_id AS droneId,
top.create_time AS createTime,
latest_job.start_time AS lastTime,
latest_record.operation_date AS nearTime,
job_max_time.max_start_time AS lastTime,
latest_record.latest_operation_date AS nearTime,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
......@@ -35,18 +34,18 @@
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
LEFT JOIN tb_operation_job tj ON top.id = tj.operation_id
LEFT JOIN (
SELECT operation_id, MAX(start_time) AS start_time
SELECT
operation_id,
MAX(start_time) AS max_start_time
FROM tb_operation_job
GROUP BY operation_id
) latest_job ON top.id = latest_job.operation_id
) job_max_time ON top.id = job_max_time.operation_id
LEFT JOIN (
SELECT rd1.operation_id, rd1.operation_date
FROM tb_operation_record rd1
INNER JOIN (
SELECT operation_id, MAX(operation_date) AS max_date
SELECT
operation_id,
MAX(operation_date) AS latest_operation_date
FROM tb_operation_record
GROUP BY operation_id
) rd2 ON rd1.operation_id = rd2.operation_id AND rd1.operation_date = rd2.max_date
) latest_record ON top.id = latest_record.operation_id
<where>
top.runlog_or_operation = 0
......@@ -67,16 +66,22 @@
AND top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null">
AND top.start_time &lt;= #{endTime} <!-- 注意字段名是finish_time还是end_time -->
AND top.start_time &lt;= #{endTime}
</if>
<if test="id != null ">
AND top.id = #{id}
</if>
<if test="stationId != null and stationId != ''">
AND top.station_id = #{stationId}
</if>
<if test="username != null and username != ''">
and bw.username = #{username}
</if>
</where>
ORDER BY top.start_time DESC
ORDER BY
CASE WHEN top.status = 0 THEN 0 ELSE 1 END, -- Status 0 comes first
CASE WHEN top.status = 0 THEN top.create_time END DESC, -- Status 0 records ordered by start_time DESC
CASE WHEN top.status = 1 THEN top.create_time END DESC
</select>
<update id="stopDo" parameterType="com.example.operation_platform.model.vo.OperationDoVO">
UPDATE tb_operation
......@@ -85,24 +90,24 @@
</update>
<select id="querymessage" resultType="com.example.operation_platform.model.vo.MessageNeedDataVo">
select
top.start_time AS startTime,
tb.start_time AS startTime,
COALESCE(br.name, dr.name) AS robotName,
bs.name AS stationName,
top.operation_type AS operationType
top.operation_type AS operationType,
top.id AS operationId
from tb_operation top
LEFT JOIN bs_robot br ON top.robot_id = br.id
LEFT JOIN bs_station bs ON top.station_id = bs.id
LEFT JOIN tb_operation_job tb ON top.id = tb.operation_id
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
where
top.id = #{id}
tb.id = #{id}
and top.runlog_or_operation = 0
and tb.start_time > CURRENT_TIMESTAMP
</select>
<select id="queryDoRunLog" resultType="com.example.operation_platform.model.vo.OperationDoVO">
WITH ranked_operations AS (
SELECT
top.id AS id,
tj.id AS operationJobId,
top.operation_cycle AS operationCycle,
top.start_time AS startTime,
COALESCE(br.name, dr.name) AS robotName,
......@@ -116,13 +121,20 @@
top.finish_time AS finishTime,
top.drone_id AS droneId,
top.create_time AS createTime,
latest_job.start_time AS lastTime,
latest_record.operation_date AS nearTime,
job_max_time.max_start_time AS lastTime,
latest_record.latest_operation_date AS nearTime,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
WHERE FIND_IN_SET(bti.id, top.item_id) > 0
) AS operationItems
) AS operationItems,
-- Rank records by create_time within each station/device group
ROW_NUMBER() OVER (
PARTITION BY
top.station_id,
COALESCE(top.robot_id, top.drone_id)
ORDER BY top.create_time DESC
) AS rn
FROM tb_operation top
LEFT JOIN bs_robot br ON top.robot_id = br.id
LEFT JOIN bs_station bs ON top.station_id = bs.id
......@@ -132,24 +144,23 @@
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
LEFT JOIN tb_operation_job tj ON top.id = tj.operation_id
LEFT JOIN (
SELECT operation_id, MAX(start_time) AS start_time
SELECT
operation_id,
MAX(start_time) AS max_start_time
FROM tb_operation_job
GROUP BY operation_id
) latest_job ON top.id = latest_job.operation_id
) job_max_time ON top.id = job_max_time.operation_id
LEFT JOIN (
SELECT rd1.operation_id, rd1.operation_date
FROM tb_operation_record rd1
INNER JOIN (
SELECT operation_id, MAX(operation_date) AS max_date
SELECT
operation_id,
MAX(operation_date) AS latest_operation_date
FROM tb_operation_record
GROUP BY operation_id
) rd2 ON rd1.operation_id = rd2.operation_id AND rd1.operation_date = rd2.max_date
) latest_record ON top.id = latest_record.operation_id
<where>
top.runlog_or_operation = 1
WHERE top.runlog_or_operation = 1
<if test="robotName != null and robotName != ''">
and br.name LIKE CONCAT('%', #{robotName}, '%')
or dr.name LIKE CONCAT('%', #{robotName}, '%')
AND (br.name LIKE CONCAT('%', #{robotName}, '%')
OR dr.name LIKE CONCAT('%', #{robotName}, '%'))
</if>
<if test="stationName != null and stationName != ''">
AND bs.name LIKE CONCAT('%', #{stationName}, '%')
......@@ -164,16 +175,25 @@
AND top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null">
AND top.start_time &lt;= #{endTime} <!-- 注意字段名是finish_time还是end_time -->
AND top.start_time &lt;= #{endTime}
</if>
<if test="id != null ">
AND top.id = #{id}
</if>
<if test="stationId != null and stationId != ''">
AND top.station_id = #{stationId}
</if>
<if test="username != null and username != ''">
and bw.username = #{username}
AND bw.username = #{username}
</if>
</where>
ORDER BY top.start_time DESC
)
SELECT
id, operationCycle, startTime, robotName, stationName, workerName,
operationType, status, robotId, stationId, itemId, finishTime,
droneId, createTime, lastTime, nearTime, operationItems
FROM ranked_operations
WHERE rn = 1 -- Only keep the most recent record for each station/device
ORDER BY startTime DESC
</select>
<select id="queryRunLogIdList" resultType="java.lang.Integer">
select
......@@ -203,12 +223,13 @@
INNER JOIN tb_message tb ON top.station_id = tb.station_id
AND (top.robot_id = tb.robot_id OR (top.robot_id IS NULL AND top.drone_id = tb.drone_id))
INNER JOIN tb_worker bw ON tb.operation_worker = bw.id
WHERE top.runlog_or_operation = 1 AND bw.username = #{username}) AS warnCount
INNER JOIN tb_operation_job tot ON top.id = tot.operation_id
WHERE top.runlog_or_operation = 1 AND tot.finish_status=1 AND bw.username = #{username}) AS warnCount
</select>
<!-- 查询运行告警信息,且在进行中的任务-->
<select id="queryNeedMessageRunLog" resultType="com.example.operation_platform.model.vo.RunLogWarnMessageVO">
select
top.start_time AS startTime,
tr.start_time AS startTime,
top.tb_run_log_id AS runLogId,
COALESCE(br.name, dr.name) AS robotName,
bs.name AS stationName,
......@@ -218,6 +239,7 @@
LEFT JOIN bs_station bs ON top.station_id = bs.id
LEFT JOIN tb_operation_job tb ON top.id = tb.operation_id
LEFT JOIN uav_drone dr ON top.drone_id = dr.id
LEFT JOIN tb_run_log tr ON top.tb_run_log_id = tr.id
where
top.runlog_or_operation = 1
AND tb.finish_status NOT IN (2, 4)
......
......@@ -5,7 +5,10 @@
<select id="queryJobList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
tp.operation_type AS operationType,
tp.item_id AS itemId,
tp.station_id AS stationId,
bs.name AS stationName,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
......@@ -70,9 +73,12 @@
<select id="queryJobListByDate" resultType="com.example.operation_platform.model.vo.OperationJobVO">
SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
tp.item_id AS itemId,
tp.operation_type AS operationType,
top.operation_id AS operationId,
bs.name AS stationName,
tp.station_id AS stationId,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
......@@ -113,8 +119,8 @@
<if test="username != null and username != ''">
and bw.username = #{username}
</if>
<if test="finishStatus != null and finishStatus != ''">
and top.finish_status = #{finishStatus}
<if test="status != null ">
and top.finish_status = #{status}
</if>
</where>
ORDER BY top.start_time DESC
......@@ -122,6 +128,7 @@
<select id="queryAllJobList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
SELECT
top.id,
tp.item_id AS itemId,
tp.operation_type AS operationType,
top.operation_id AS operationId,
bs.name AS stationName,
......@@ -137,7 +144,7 @@
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 runLogOrOperation,
tp.tb_run_log_id AS runLogId,
tp.station_id AS stationId
FROM
......@@ -167,7 +174,7 @@
</where>
ORDER BY
top.runlog_or_operation DESC, -- 1在前,0在后
top.start_time DESC
top.start_time ASC
</select>
<!-- 查询告警日志列表-->
<select id="queryRunLogJobList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
......@@ -210,6 +217,7 @@
LEFT JOIN tb_worker bw ON tm.operation_worker = bw.id
<where>
top.runlog_or_operation = 1
and top.finish_status = 1
<if test="robotName != null and robotName != ''">
and br.name like concat('%',#{robotName},'%')
or ud.name like concat('%',#{robotName},'%')
......@@ -310,18 +318,14 @@
<select id="queryJobAndOperationTypeList" resultType="com.example.operation_platform.model.vo.OperationJobVO">
SELECT
top.id,
top.runlog_or_operation AS runlogOrOperation,
top.operation_id operationId,
tp.operation_type AS operationType,
bs.name AS stationName,
bs.address address,
bs.lon,
bs.lat,
-- 合并 robot 和 drone 的 name 到 robotName(优先取 robot)
COALESCE(
br.name, -- 来自 bs_robot 的机器人名称
ud.name, -- 来自 uav_drone 的无人机名称
'未知设备' -- 默认值
) AS robotName,
COALESCE(br.name, ud.name, '未知设备') AS robotName,
top.start_time AS startTime,
top.end_time AS endTime,
top.finish_status AS finishStatus,
......@@ -333,21 +337,25 @@
WHERE FIND_IN_SET(bti.id, tp.item_id) > 0
) AS operationItems,
tp.item_id AS itemId,
tp.station_id AS stationId
tp.station_id AS stationId,
-- 新增lastTime字段:查找相同operation_id记录中的最大开始时间
(
SELECT MAX(t.start_time)
FROM tb_operation_job t
WHERE t.operation_id = top.operation_id
) AS lastTime
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},'%')
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},'%')
......@@ -358,11 +366,11 @@
<if test="status != null and status != ''">
and top.status like concat('%',#{status},'%')
</if>
<if test="startTime != null ">
<if test="startTime != null">
and top.start_time &gt;= #{startTime}
</if>
<if test="endTime != null ">
and top.endTime &lt;= #{endTime}
<if test="endTime != null">
and top.end_time &lt;= #{endTime}
</if>
<if test="operationType != null and operationType != ''">
and tp.operation_type like concat('%',#{operationType},'%')
......
......@@ -5,8 +5,16 @@
<select id="queryrecordList" resultType="com.example.operation_platform.model.vo.OperationRecordVO">
SELECT
tor.id AS id,
tor.operation_job_id AS operationJobId,
COALESCE(br.name, dr.name) AS robotName,
tor.content AS content,
top.tb_run_log_id AS runLogId,
top.item_id AS itemId,
(
SELECT GROUP_CONCAT(DISTINCT bti.operation_item SEPARATOR ', ')
FROM tb_operation_item bti
WHERE FIND_IN_SET(bti.id, top.item_id) > 0
) AS operationItems,
top.operation_type AS operationType,
tor.img AS img,
tor.operation_date AS operationDate,
......@@ -34,7 +42,6 @@
operation_id
) latest_job ON top.id = latest_job.operation_id
<where>
tor.runlog_or_operation = 0
<if test="operationId != null and operationId != ''">
and tor.operation_id= #{operationId}
</if>
......
......@@ -4,16 +4,18 @@
<select id="queryLogList" resultType="com.example.operation_platform.model.vo.RunLogVO">
select
id id,
start_time startTime,
end_time endTime,
status status,
robot_id robotId,
station_id stationId,
run_log_num runLogNum,
type type
trl.id id,
trl.start_time startTime,
trl.end_time endTime,
trl.status status,
trl.robot_id robotId,
trl.station_id stationId,
trl.run_log_num runLogNum,
trl.type type,
ud.name droneName
from
tb_run_log
tb_run_log trl
left join uav_drone ud on trl.robot_id = ud.id
<where>
<if test="runLogNum != null and runLogNum != ''">
and run_log_num like CONCAT('%',#{runLogNum},'%')
......@@ -28,6 +30,7 @@
and station_id = #{stationId}
</if>
</where>
order by start_time desc
</select>
</mapper>
\ No newline at end of file
......@@ -18,6 +18,7 @@
tb_workertype typ
on
tw.type = typ.id
order by tw.create_time desc
</select>
<select id="queryMyMessage" resultType="com.example.operation_platform.model.vo.WorkerVO">
select
......
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