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

优化

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