Commit 7b817d2a authored by 王蔡翾's avatar 王蔡翾
Browse files

初始化

parent 42848b59
...@@ -6,11 +6,11 @@ import lombok.EqualsAndHashCode; ...@@ -6,11 +6,11 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
@Data @Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OperationJobVO extends OperationJob { public class OperationJobVO extends OperationJob {
private String robotName; private String robotName;
private String stationName; private String stationName;
private String operationType; private String operationType;
private String workerName; private String workerName;
private Integer id; private Integer id;
private String robotId;
} }
package com.example.operation_platform.model.vo;
import lombok.Data;
@Data
public class RobotAndDrone {
private String robotName;
private String robotId;
private String droneId;
}
...@@ -15,5 +15,6 @@ public class WorkerVO { ...@@ -15,5 +15,6 @@ public class WorkerVO {
private Integer id; private Integer id;
private String img; private String img;
private String password; private String password;
private Integer typeId;
} }
...@@ -23,4 +23,5 @@ public interface GuideService extends IService<GuideEntity> { ...@@ -23,4 +23,5 @@ public interface GuideService extends IService<GuideEntity> {
* @return GuideVO * @return GuideVO
*/ */
List<GuideVO> queryguidelist(GuideDTO guideDTO); List<GuideVO> queryguidelist(GuideDTO guideDTO);
void updateall(GuideDTO guideDTO);
} }
...@@ -5,6 +5,9 @@ import com.example.operation_platform.model.dto.MessageDTO; ...@@ -5,6 +5,9 @@ import com.example.operation_platform.model.dto.MessageDTO;
import com.example.operation_platform.model.entity.MessageEntity; import com.example.operation_platform.model.entity.MessageEntity;
import com.example.operation_platform.model.vo.MessageVO; import com.example.operation_platform.model.vo.MessageVO;
import com.example.operation_platform.model.vo.PeopleMessageVO; import com.example.operation_platform.model.vo.PeopleMessageVO;
import com.example.operation_platform.model.vo.RobotAndDrone;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
...@@ -27,7 +30,7 @@ public interface MessageService extends IService<MessageEntity> { ...@@ -27,7 +30,7 @@ public interface MessageService extends IService<MessageEntity> {
* 根据泵站查询人员信息列表 * 根据泵站查询人员信息列表
* @param stationId stationId * @param stationId stationId
*/ */
PeopleMessageVO queryPeople(Long stationId,Long robotId); PeopleMessageVO queryPeople(Long stationId);
/** /**
* 查询泵站人员信息列表 * 查询泵站人员信息列表
* *
...@@ -35,5 +38,11 @@ public interface MessageService extends IService<MessageEntity> { ...@@ -35,5 +38,11 @@ public interface MessageService extends IService<MessageEntity> {
* @return List<PeopleMessageVO> * @return List<PeopleMessageVO>
*/ */
List<PeopleMessageVO> querymessageList(MessageDTO messageDTO); List<PeopleMessageVO> querymessageList(MessageDTO messageDTO);
MessageVO querypeopleId(@Param("stationId") String stationId, @Param("robotId") @RequestParam(required = false)Long robotId, @Param("droneId") @RequestParam(required = false) Long droneId);
/*
* 根据泵站id查询智能设备信息
* @param stationId stationId
* @return List<MessageVO>
*/
List<RobotAndDrone> queryrobotBystationId(String stationId);
} }
...@@ -5,6 +5,7 @@ import com.example.operation_platform.model.dto.OperationItemDTO; ...@@ -5,6 +5,7 @@ import com.example.operation_platform.model.dto.OperationItemDTO;
import com.example.operation_platform.model.entity.OperationItem; import com.example.operation_platform.model.entity.OperationItem;
import com.example.operation_platform.model.vo.OperationItemVO; import com.example.operation_platform.model.vo.OperationItemVO;
import java.util.ArrayList;
import java.util.List; import java.util.List;
public interface OperationItemService extends IService<OperationItem> { public interface OperationItemService extends IService<OperationItem> {
...@@ -15,4 +16,12 @@ public interface OperationItemService extends IService<OperationItem> { ...@@ -15,4 +16,12 @@ public interface OperationItemService extends IService<OperationItem> {
* @return List<OperationItemVO> * @return List<OperationItemVO>
*/ */
List<OperationItemVO> queryItemList(OperationItemDTO operationItemDTO); List<OperationItemVO> queryItemList(OperationItemDTO operationItemDTO);
/**
* 通过itemId数组查看item信息
*
* @param strings strings
* @return List<OperationItem>
*/
List<OperationItem> queryByIdList(List<String> strings);
} }
...@@ -47,4 +47,5 @@ public interface WorkerService extends IService<WorkerEntity> { ...@@ -47,4 +47,5 @@ public interface WorkerService extends IService<WorkerEntity> {
List<WorkerVO> queryByType(Integer id); List<WorkerVO> queryByType(Integer id);
boolean isUsernameEmpty(Integer workerId);
} }
...@@ -21,4 +21,8 @@ public class GuideServiceImpl extends ServiceImpl<GuideMapper, GuideEntity> impl ...@@ -21,4 +21,8 @@ public class GuideServiceImpl extends ServiceImpl<GuideMapper, GuideEntity> impl
public List<GuideVO> queryguidelist(GuideDTO guideDTO) { public List<GuideVO> queryguidelist(GuideDTO guideDTO) {
return baseMapper.queryguidelist(guideDTO); return baseMapper.queryguidelist(guideDTO);
} }
@Override
public void updateall(GuideDTO guideDTO) {
baseMapper.updateall(guideDTO);
}
} }
...@@ -6,6 +6,7 @@ import com.example.operation_platform.model.dto.MessageDTO; ...@@ -6,6 +6,7 @@ import com.example.operation_platform.model.dto.MessageDTO;
import com.example.operation_platform.model.entity.MessageEntity; import com.example.operation_platform.model.entity.MessageEntity;
import com.example.operation_platform.model.vo.MessageVO; import com.example.operation_platform.model.vo.MessageVO;
import com.example.operation_platform.model.vo.PeopleMessageVO; import com.example.operation_platform.model.vo.PeopleMessageVO;
import com.example.operation_platform.model.vo.RobotAndDrone;
import com.example.operation_platform.service.MessageService; import com.example.operation_platform.service.MessageService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -23,11 +24,22 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessageEntity ...@@ -23,11 +24,22 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessageEntity
this.baseMapper.resetmessage(messageDTO); this.baseMapper.resetmessage(messageDTO);
} }
@Override @Override
public PeopleMessageVO queryPeople(Long stationId,Long robotId) { public PeopleMessageVO queryPeople(Long stationId) {
return this.baseMapper.queryPeople(stationId,robotId); return this.baseMapper.queryPeople(stationId);
} }
@Override @Override
public List<PeopleMessageVO> querymessageList(MessageDTO messageDTO) { public List<PeopleMessageVO> querymessageList(MessageDTO messageDTO) {
return this.baseMapper.querymessageList(messageDTO); return this.baseMapper.querymessageList(messageDTO);
} }
@Override
public MessageVO querypeopleId(String stationId, Long robotId, Long droneId) {
if (robotId == null && droneId == null) {
throw new IllegalArgumentException("Either robotId or droneId must be provided");
}
return this.baseMapper.querypeopleId(stationId, robotId, droneId);
}
@Override
public List<RobotAndDrone> queryrobotBystationId(String stationId) {
return this.baseMapper.queryrobotBystationId(stationId);
}
} }
...@@ -6,30 +6,61 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -6,30 +6,61 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.operation_platform.mapper.OperationDoMapper; import com.example.operation_platform.mapper.OperationDoMapper;
import com.example.operation_platform.model.dto.OperationDoDTO; import com.example.operation_platform.model.dto.OperationDoDTO;
import com.example.operation_platform.model.entity.OperationDoEntity; import com.example.operation_platform.model.entity.OperationDoEntity;
import com.example.operation_platform.model.entity.OperationItem;
import com.example.operation_platform.model.vo.OperationDoVO; import com.example.operation_platform.model.vo.OperationDoVO;
import com.example.operation_platform.service.OperationDoService; import com.example.operation_platform.service.OperationDoService;
import com.example.operation_platform.service.OperationItemService;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.platform.utils.DateUtil; import com.platform.utils.DateUtil;
import com.platform.utils.StringUtils; import com.platform.utils.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Date; import javax.annotation.Resource;
import java.util.List; import java.util.*;
@Service @Service
public class OperationDoServiceImpl extends ServiceImpl<OperationDoMapper, OperationDoEntity> implements OperationDoService { public class OperationDoServiceImpl extends ServiceImpl<OperationDoMapper, OperationDoEntity> implements OperationDoService {
@Resource
private OperationItemService operationItemService;
@Override @Override
public List<OperationDoVO> queryDoList(OperationDoDTO operationDoDTO) { public List<OperationDoVO> queryDoList(OperationDoDTO operationDoDTO) {
//查看机器人运维项目 //查看机器人运维项目
List<OperationDoVO> operationVOList = baseMapper.queryDoList(operationDoDTO); List<OperationDoVO> operationVOList = baseMapper.queryDoList(operationDoDTO);
//处理items
Set<String> items = new HashSet<>();
operationVOList.forEach(operationDoVO -> {
if (StringUtils.isNotEmpty(operationDoVO.getItemId())) {
List<String> itemIdList = Arrays.asList(operationDoVO.getItemId().split(","));
itemIdList.forEach(itemId -> items.add(itemId));
}
});
//通过itemId数组查看item信息
List<OperationItem> operationItemList = operationItemService.queryByIdList(Lists.newArrayList(items));
operationVOList.forEach(operationDoVO -> {
if (StringUtils.isNotEmpty(operationDoVO.getItemId())) {
List<String> itemIdList = Arrays.asList(operationDoVO.getItemId().split(","));
itemIdList.forEach(itemId -> {
for (OperationItem operationItem : operationItemList) {
String itemName = null;
if (itemId.equals(operationItem.getId())) {
if (StringUtils.isEmpty(itemName)) {
itemName = operationItem.getOperationItem();
} else {
itemName = itemName + "," + operationItem.getOperationItem();
}
operationDoVO.setOperationItems(itemName);
}
}
});
}
});
return operationVOList; return operationVOList;
} }
@Override @Override
public void stopDo(OperationDoDTO operationDoDTO) { public void stopDo(OperationDoDTO operationDoDTO) {
this.baseMapper.stopDo(operationDoDTO); this.baseMapper.stopDo(operationDoDTO);
......
...@@ -8,6 +8,7 @@ import com.example.operation_platform.model.vo.OperationItemVO; ...@@ -8,6 +8,7 @@ import com.example.operation_platform.model.vo.OperationItemVO;
import com.example.operation_platform.service.OperationItemService; import com.example.operation_platform.service.OperationItemService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Service @Service
public class OperationItemServiceImpl extends ServiceImpl<OperationItemMapper, OperationItem> implements OperationItemService { public class OperationItemServiceImpl extends ServiceImpl<OperationItemMapper, OperationItem> implements OperationItemService {
...@@ -16,4 +17,9 @@ public class OperationItemServiceImpl extends ServiceImpl<OperationItemMapper, O ...@@ -16,4 +17,9 @@ public class OperationItemServiceImpl extends ServiceImpl<OperationItemMapper, O
return this.baseMapper.queryItemList(operationItemDTO); return this.baseMapper.queryItemList(operationItemDTO);
} }
@Override
public List<OperationItem> queryByIdList(List<String> itemIdList) {
return baseMapper.queryByIdList(itemIdList);
}
} }
...@@ -15,7 +15,12 @@ import org.springframework.stereotype.Service; ...@@ -15,7 +15,12 @@ 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.ParseException;
import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@Service @Service
public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> implements RunLogService { public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> implements RunLogService {
...@@ -35,13 +40,44 @@ public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> i ...@@ -35,13 +40,44 @@ public class RunLogServiceImpl extends ServiceImpl<RunLogMapper, RunLogEntity> i
//查看机器人操作日志 //查看机器人操作日志
if (runLogEntity.getType().equals("uav")) { if (runLogEntity.getType().equals("uav")) {
uavOperateLogList = operateLogService.queryListByRunLogId(runLogEntity.getId()); uavOperateLogList = operateLogService.queryListByRunLogId(runLogEntity.getId());
// 过滤出纯中文部分
uavOperateLogList = uavOperateLogList.stream()
.map(log -> {
String chineseMessage = extractChinese(log.getContent()); // 提取中文
log.setContent(chineseMessage); // 更新日志信息
return log;
})
.filter(log -> !log.getContent().isEmpty()) // 过滤掉空日志
.collect(Collectors.toList());
} }
return uavOperateLogList; return uavOperateLogList;
} }
// 使用正则表达式提取中文
private String extractChinese(String text) {
// 正则表达式匹配中文字符
Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]+");
Matcher matcher = pattern.matcher(text);
// 提取所有匹配的中文字符
StringBuilder chineseText = new StringBuilder();
while (matcher.find()) {
chineseText.append(matcher.group());
}
return chineseText.toString();
}
@Override @Override
public void download(String id, HttpServletResponse httpServletResponse) { public void download(String id, HttpServletResponse httpServletResponse) {
List<UavOperateLogEntity> uavOperateLogList = getInfoById(id); List<UavOperateLogEntity> uavOperateLogList = getInfoById(id);
// 手动转换时间格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
uavOperateLogList.forEach(log -> {
if (log.getDataTime() != null) {
log.setDataTimeStr(dateFormat.format(log.getDataTime())); // 使用临时字段存储格式化后的时间
}
});
ExcelUtil<UavOperateLogEntity> uavOperateLogExcelUtil = new ExcelUtil<>(UavOperateLogEntity.class); ExcelUtil<UavOperateLogEntity> uavOperateLogExcelUtil = new ExcelUtil<>(UavOperateLogEntity.class);
uavOperateLogExcelUtil.exportExcel(uavOperateLogList, uavOperateLogExcelUtil.exportExcel(uavOperateLogList,
"机器人运行日志.xlsx", "机器人运行日志.xlsx",
......
...@@ -35,4 +35,9 @@ public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, WorkerEntity> i ...@@ -35,4 +35,9 @@ public class WorkerServiceImpl extends ServiceImpl<WorkerMapper, WorkerEntity> i
public List<WorkerVO> queryByType(Integer id) { public List<WorkerVO> queryByType(Integer id) {
return this.baseMapper.queryByType(id); return this.baseMapper.queryByType(id);
} }
@Override
public boolean isUsernameEmpty(Integer workerId) {
WorkerEntity workerEntity = baseMapper.selectById(workerId);
return workerEntity == null || workerEntity.getUsername() == null || workerEntity.getUsername().isEmpty();
}
} }
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.OperationDoMapper; import com.example.operation_platform.mapper.OperationDoMapper;
import com.example.operation_platform.mapper.OperationJobMapper; import com.example.operation_platform.mapper.OperationJobMapper;
import com.example.operation_platform.mapper.WorkerMapper;
import com.example.operation_platform.model.entity.MessageEntity;
import com.example.operation_platform.model.entity.OperationDoEntity; import com.example.operation_platform.model.entity.OperationDoEntity;
import com.example.operation_platform.model.entity.OperationJob; import com.example.operation_platform.model.entity.OperationJob;
import com.example.operation_platform.model.entity.WorkerEntity;
import com.example.operation_platform.model.vo.MessageNeedDataVo;
import com.platform.utils.AliSmsUtil;
import org.slf4j.Logger;
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.LocalDate;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import org.json.JSONObject;
@Component @Component
public class OperationDoTask { public class OperationDoTask {
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
private MessageMapper messageMapper;
@Autowired
private WorkerMapper workerMapper;
@Autowired
private AliSmsUtil aliSmsUtil;
@Scheduled(cron = "0 0 0 * * ?") // 每天午夜执行 @Scheduled(cron = "0 0 0 * * ?") // 每天午夜执行
public void scheduleOperationJobs() { public void scheduleOperationJobs() {
...@@ -30,10 +47,16 @@ public class OperationDoTask { ...@@ -30,10 +47,16 @@ public class OperationDoTask {
LocalDate now = LocalDate.now(); // 改用 LocalDate 类型 LocalDate now = LocalDate.now(); // 改用 LocalDate 类型
for (OperationDoEntity operation : operations) { for (OperationDoEntity operation : operations) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
if (operationEntity == null || operationEntity.getRunlogOrOperation() != 0) {
continue;
}
// 1. 获取计划参数 // 1. 获取计划参数
LocalDate planStartDate = operation.getStartTime(); // 直接使用 LocalDate LocalDate planStartDate = operation.getStartTime(); // 直接使用 LocalDate
int cycleDays = operation.getOperationCycle(); int cycleDays = operation.getOperationCycle();
int durationDays = operation.getCompletionTime(); int durationDays = operation.getFinishTime();
// 2. 查询当前计划下的所有任务(按时间倒序) // 2. 查询当前计划下的所有任务(按时间倒序)
List<OperationJob> existingJobs = operationJobMapper.selectList( List<OperationJob> existingJobs = operationJobMapper.selectList(
...@@ -44,7 +67,13 @@ public class OperationDoTask { ...@@ -44,7 +67,13 @@ public class OperationDoTask {
// 3. 自动生成新任务逻辑 // 3. 自动生成新任务逻辑
if (existingJobs.isEmpty()) { if (existingJobs.isEmpty()) {
if (now.isBefore(planStartDate)) {
// 如果当前时间在计划开始时间之前,只创建一条任务
createOneJob(operation, planStartDate, durationDays);
} else {
// 如果当前时间等于或在计划开始时间之后,创建两条任务
createTwoJobs(operation, planStartDate, cycleDays, durationDays); createTwoJobs(operation, planStartDate, cycleDays, durationDays);
}
} else { } else {
maintainTwoValidJobs(operation, existingJobs, cycleDays, durationDays, now); maintainTwoValidJobs(operation, existingJobs, cycleDays, durationDays, now);
} }
...@@ -54,49 +83,97 @@ public class OperationDoTask { ...@@ -54,49 +83,97 @@ public class OperationDoTask {
} }
} }
private void createOneJob(OperationDoEntity operation, LocalDate 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);
int finishStatus = 0; // 任务状态为0(未开始)
insertJob(operation, jobStart, jobEnd, finishStatus);
}
private void createTwoJobs(OperationDoEntity operation, LocalDate startDate, private void createTwoJobs(OperationDoEntity operation, LocalDate startDate,
int cycleDays, int durationDays) { int cycleDays, int durationDays) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
if (operationEntity == null || operationEntity.getRunlogOrOperation() != 0) {
return;
}
LocalDate now = LocalDate.now();
// 只有当operation状态为0(进行中)时才创建任务
if ("0".equals(operation.getStatus())) {
// 生成第一条任务 // 生成第一条任务
LocalDate job1Start = startDate; LocalDate job1Start = startDate;
LocalDate job1End = job1Start.plusDays(durationDays); LocalDate job1End = job1Start.plusDays(durationDays);
insertJob(operation, job1Start, job1End); int job1Status = job1Start.isEqual(now) ? 1 : 0;
insertJob(operation, job1Start, job1End, job1Status);
// 生成第二条任务(下一周期) // 生成第二条任务(下一周期)
LocalDate job2Start = job1Start.plusDays(cycleDays); LocalDate job2Start = job1Start.plusDays(cycleDays);
LocalDate job2End = job2Start.plusDays(durationDays); LocalDate job2End = job2Start.plusDays(durationDays);
insertJob(operation, job2Start, job2End); // 确保第二条任务开始时间在当前时间之后
if (job2Start.isAfter(now)) {
int job2Status = 0;
insertJob(operation, job2Start, job2End, job2Status);
}
}
} }
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, LocalDate now) {
// 获取 OperationEntity 实体
OperationDoEntity operationEntity = operationDoMapper.selectById(operation.getId());
if (operationEntity == null || operationEntity.getRunlogOrOperation() != 0) {
return;
}
// 检查所有任务的状态并更新
for (OperationJob job : existingJobs) {
int newStatus = calculateStatus(job, now);
if (newStatus != job.getFinishStatus()) {
job.setFinishStatus(newStatus);
operationJobMapper.updateById(job);
}
}
// 获取最新的任务
OperationJob latestJob = existingJobs.get(0); OperationJob latestJob = existingJobs.get(0);
// 只有当operation状态为0(进行中)时才创建新任务
if ("0".equals(operation.getStatus())) {
// 检查最新任务是否已过期 // 检查最新任务是否已过期
if (latestJob.getEndTime().isBefore(now)) { if (latestJob.getEndTime().isBefore(now)) {
// 计算新任务开始时间(跳过当前周期) // 计算新任务开始时间(跳过当前周期)
LocalDate newStart = latestJob.getStartTime().plusDays(cycleDays * 2L); LocalDate newStart = latestJob.getStartTime().plusDays(cycleDays);
LocalDate newEnd = newStart.plusDays(durationDays); LocalDate newEnd = newStart.plusDays(durationDays);
insertJob(operation, newStart, newEnd);
// 确保新任务开始时间在当前时间之后
if (newStart.isAfter(now)) {
int finishStatus = 0;
insertJob(operation, newStart, newEnd, finishStatus);
return; // 插入新任务后立即返回,避免重复处理
}
}
} }
} }
private void insertJob(OperationDoEntity operation, LocalDate start, LocalDate end) { private void insertJob(OperationDoEntity operation, LocalDate start, LocalDate end, int finishStatus) {
//builder模式实现插入
// OperationJob job = OperationJob.builder()
// .operationId(operation.getId())
// .startTime(start)
// .endTime(end)
// .finishStatus(0).build();
// 创建一个OperationJob实例来安排或记录某个操作的执行 // 创建一个OperationJob实例来安排或记录某个操作的执行
OperationJob job = new OperationJob(); OperationJob job = new OperationJob();
// 设置操作的唯一标识符,以便跟踪和管理 // 设置操作的唯一标识符,以便跟踪和管理
job.setOperationId(operation.getId()); job.setOperationId(operation.getId());
// 设置操作的开始时间,标志着操作执行的起始时刻 // 设置操作的开始时间,标志着操作执行的起始时刻
job.setStartTime(start); job.setStartTime(start);
// 设置操作的结束时间,标志着操作执行的结束时刻 // 设置操作的结束时间,标志着操作执行的结束时刻
job.setEndTime(end); job.setEndTime(end);
// 初始化操作的完成状态为0,通常表示操作尚未完成或正在等待执行 // 初始化操作的完成状态
job.setFinishStatus(0); job.setFinishStatus(finishStatus);
operationJobMapper.insert(job); operationJobMapper.insert(job);
} }
...@@ -108,53 +185,155 @@ public class OperationDoTask { ...@@ -108,53 +185,155 @@ public class OperationDoTask {
); );
for (OperationJob job : allJobs) { for (OperationJob job : allJobs) {
// 首先检查任务是否已被人工完成(状态2或4)
if (job.getFinishStatus() == 2 || job.getFinishStatus() == 4) {
continue; // 跳过已完成的任务
}
// 计算当前状态
int newStatus = calculateStatus(job, now); int newStatus = calculateStatus(job, now);
if (newStatus != job.getFinishStatus()) { if (newStatus != job.getFinishStatus()) {
job.setFinishStatus(newStatus); job.setFinishStatus(newStatus);
operationJobMapper.updateById(job); operationJobMapper.updateById(job);
} }
// 发送提前3天提醒(任务开始前3天的0点触发) // 检查是否需要发送提醒(开始前7天内且任务未完成)
if (newStatus == 0) { if (shouldSendReminder(job, now)) {
checkAndSendSms(job, now); if (job.getRunlogOrOperation() == 0) {
sendTaskNotificationSms(job.getOperationId());
}
} }
} }
} }
private int calculateStatus(OperationJob job, LocalDate now) { private int calculateStatus(OperationJob job, LocalDate now) {
if (job.getEndTime().isBefore(now)) { if (job.getEndTime().isBefore(now)) {
return 1; // 已过期 return 3; // 已过期
} else if (job.getStartTime().isAfter(now)) { } else if (job.getStartTime().isAfter(now)) {
return 0; // 未开始 return 0; // 未开始
} else { } else {
return 0; // 进行中(start <= now < end) return 1; // 进行中(start <= now < end)
} }
} }
private void checkAndSendSms(OperationJob job, LocalDate now) { private void checkAndSendSms(OperationJob job, LocalDate now) {
LocalDate reminderDate = job.getStartTime().minusDays(7); LocalDate reminderDate = job.getStartTime().minusDays(7);
if (now.isEqual(reminderDate)) { // 精确在提前3天的0点触发 // 精确匹配提醒日期,避免重复发送
sendAliyunSms(job.getOperationId(), job.getStartTime()); if (now.isEqual(reminderDate)) {
} if (job.getRunlogOrOperation() == 0) {
} sendTaskNotificationSms(job.getOperationId());
//阿里云短信服务(示例伪代码) }
private void sendAliyunSms(Integer operationId, LocalDate startTime) { }
// // 1. 获取关联手机号(需根据业务逻辑实现) }
// String phone = getPhoneByOperation(operationId);
// private boolean shouldSendReminder(OperationJob job, LocalDate now) {
// // 2. 构造请求参数 // 任务已被人工完成(状态2或4)则不发送
// SendSmsRequest request = new SendSmsRequest() if (job.getFinishStatus() == 2 || job.getFinishStatus() == 4) {
// .setPhoneNumbers(phone) return false;
// .setSignName("YourSignName") }
// .setTemplateCode("SMS_123456789")
// .setTemplateParam("{\"date\":\"" + startTime.toLocalDate() + "\"}"); // 计算距离任务开始时间的天数
// long daysUntilStart = ChronoUnit.DAYS.between(now, job.getStartTime());
// // 3. 发送请求
// try { // 在开始前7天内(包括当天)发送提醒
// SendSmsResponse response = aliyunClient.getAcsResponse(request); return daysUntilStart <= 7 && daysUntilStart >= 0;
// log.info("短信发送结果:{}", response.getCode()); }
// } catch (ClientException e) {
// log.error("短信发送失败", e);
// } // 定时任务手动触发方法
public void runScheduleOperationJobsNow() {
scheduleOperationJobs();
}
//阿里云短信服务
/**
* 发送任务通知短信
*
* @param operationId 操作ID
*/
private void sendTaskNotificationSms(Integer operationId) {
// 调用 querymessage 方法获取 MessageNeedDataVo 对象
MessageNeedDataVo messageNeedDataVo = operationDoMapper.querymessage(operationId);
if (messageNeedDataVo == null) {
logger.error("获取消息数据失败: 找不到操作ID={}的记录", operationId);
return;
}
List<String> phones = getPhoneByOperation(operationId);
for (String phone : phones){
// 构建短信模板参数
JSONObject jsonObject = new JSONObject();
jsonObject.put("stationName", messageNeedDataVo.getStationName());
jsonObject.put("device", messageNeedDataVo.getRobotName());
jsonObject.put("alert", messageNeedDataVo.getOperationType());
jsonObject.put("time", messageNeedDataVo.getStartTime());
aliSmsUtil.sendSms(phone, jsonObject, "SMS_481685150");
}
}
/**
* 获取操作关联的手机号列表
*
* @param operationId 操作ID
* @return 手机号列表
*/
private List<String> getPhoneByOperation(Integer operationId) {
// 1. 获取操作记录
OperationDoEntity operation = operationDoMapper.selectById(operationId);
if (operation == null) {
logger.error("获取手机号失败: 找不到操作ID={}的记录", operationId);
return Collections.emptyList();
}
// 2. 获取站点相关的所有消息记录(使用selectList代替selectOne)
List<MessageEntity> messages = messageMapper.selectList(
new LambdaQueryWrapper<MessageEntity>()
.eq(MessageEntity::getStationId, operation.getStationId())
);
if (messages == null || messages.isEmpty()) {
logger.error("获取手机号失败: 找不到站点ID={}的消息记录", operation.getStationId());
return Collections.emptyList();
}
// 3. 收集所有有效的workerId
Set<Integer> workerIds = new HashSet<>();
for (MessageEntity message : messages) {
if (message.getOperationMessage() != null && !message.getOperationMessage().isEmpty()) {
try {
Arrays.stream(message.getOperationMessage().split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.map(Integer::parseInt)
.forEach(workerIds::add);
} catch (NumberFormatException e) {
logger.error("解析操作消息失败: {}", message.getOperationMessage(), e);
continue;
} }
}
}
if (workerIds.isEmpty()) {
logger.error("获取手机号失败: 站点ID={}的消息记录中没有有效的workerId", operation.getStationId());
return Collections.emptyList();
}
// 4. 获取所有worker的电话号码
List<WorkerEntity> workers = workerMapper.selectList(
new LambdaQueryWrapper<WorkerEntity>()
.in(WorkerEntity::getId, workerIds)
.isNotNull(WorkerEntity::getPhoneNumber)
);
// 5. 返回去重后的电话号码列表
return workers.stream()
.map(WorkerEntity::getPhoneNumber)
.filter(phone -> phone != null && !phone.isEmpty())
.distinct()
.collect(Collectors.toList());
}
} }
\ No newline at end of file
package com.example.operation_platform.task;
public class RunLogTask {
// public static void main(String[] args) {
// while (true) {
// try {
// checkStatusAndSendSMS();
// Thread.sleep(60000); // 每分钟检查一次
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// }
}
package com.example.operation_platform.util;
public class OperationUtil {
}
...@@ -31,3 +31,9 @@ mybatis-plus: ...@@ -31,3 +31,9 @@ mybatis-plus:
logging: logging:
level: level:
com.example.operation_platform.mapper: debug # 这里的包路径需要指向你的 MyBatis Plus mapper 接口所在的包 com.example.operation_platform.mapper: debug # 这里的包路径需要指向你的 MyBatis Plus mapper 接口所在的包
ruzhou:
ali:
sms:
accessKeyId: LTAI5t9ynUemSWiT8rTgg1uh
accessKeySecret: biWNg6CI2EEwhXfsTmj4NZuxaWLnaf
signName: 南京如昼信息科技
\ No newline at end of file
...@@ -14,11 +14,16 @@ ...@@ -14,11 +14,16 @@
</select> </select>
<select id = "queryguidelist" resultType="com.example.operation_platform.model.vo.GuideVO"> <select id = "queryguidelist" resultType="com.example.operation_platform.model.vo.GuideVO">
select select
tg.id id, tg.robotcontent robotcontent,
tg.name name, tg.stationcontent stationcontent
tg.content content,
tg.img img
from from
tb_guide tg tb_guide tg
</select> </select>
<update id="updateall" parameterType="com.example.operation_platform.model.vo.GuideVO">
update tb_guide
set robotcontent = #{robotcontent},
stationcontent = #{stationcontent}
where id = 1
</update>
</mapper> </mapper>
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
select select
tm.id id, tm.id id,
tor.name stationName, tor.name stationName,
br.name robotName, COALESCE(br.name, dr.name) robotName,
tw.worker_name peopleName, tor.contact_phone phoneNumber,
tm.phone_number phoneNumber, tor.contact peopleName,
tor.address address, tor.address address,
tm.station_id stationId, tm.station_id stationId,
tm.robot_id robotId tm.robot_id robotId ,
tm.drone_id droneId
from from
tb_message tm tb_message tm
left join left join
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
bs_robot br bs_robot br
on br.id = tm.robot_id on br.id = tm.robot_id
left join left join
tb_worker tw uav_drone dr
on tw.id = tm.people_id on dr.id = tm.drone_id
<where> <where>
<if test="robotName != null and robotName != ''"> <if test="robotName != null and robotName != ''">
and br.name like concat('%',#{robotName},'%') and br.name like concat('%',#{robotName},'%')
...@@ -46,17 +46,17 @@ ...@@ -46,17 +46,17 @@
<select id="queryPeople" resultType="com.example.operation_platform.model.vo.PeopleMessageVO"> <select id="queryPeople" resultType="com.example.operation_platform.model.vo.PeopleMessageVO">
SELECT SELECT
tm.id id, tm.id id,
tw.worker_name peopleName, tor.contact_phone phoneNumber,
tp.worker_name softwareWorker, tp.worker_name softwareWorker,
ta.worker_name hardwareWorker, ta.worker_name hardwareWorker,
tq.worker_name operationWorker, tq.worker_name operationWorker,
tw.phone_number peopleNumber, tor.contact peopleName,
tp.phone_number softwareNumber, tp.phone_number softwareNumber,
ta.phone_number hardwareNumber, ta.phone_number hardwareNumber,
tq.phone_number operationNumber tq.phone_number operationNumber
FROM FROM
tb_message tm tb_message tm
LEFT JOIN tb_worker tw ON tm.people_id = tw.id LEFT JOIN bs_station tor ON tm.station_id = tor.id
LEFT JOIN tb_worker tp ON tm.software_worker = tp.id LEFT JOIN tb_worker tp ON tm.software_worker = tp.id
LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id
LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id
...@@ -64,9 +64,6 @@ ...@@ -64,9 +64,6 @@
<if test="stationId != null and stationId != ''"> <if test="stationId != null and stationId != ''">
tm.station_id = #{stationId} tm.station_id = #{stationId}
</if> </if>
<if test="robotId != null and robotId != ''">
tm.robot_id = #{robotId}
</if>
</select> </select>
<select id="querymessageList" resultType="com.example.operation_platform.model.vo.PeopleMessageVO"> <select id="querymessageList" resultType="com.example.operation_platform.model.vo.PeopleMessageVO">
SELECT SELECT
...@@ -82,7 +79,6 @@ ...@@ -82,7 +79,6 @@
tq.phone_number operationNumber tq.phone_number operationNumber
FROM FROM
tb_message tm tb_message tm
LEFT JOIN tb_worker tw ON tm.people_id = tw.id
LEFT JOIN tb_worker tp ON tm.software_worker = tp.id LEFT JOIN tb_worker tp ON tm.software_worker = tp.id
LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id LEFT JOIN tb_worker ta ON tm.hardware_worker = ta.id
LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id LEFT JOIN tb_worker tq ON tm.operation_worker = tq.id
...@@ -101,5 +97,73 @@ ...@@ -101,5 +97,73 @@
<!-- OR m.hardware_worker = #{worker_id}--> <!-- OR m.hardware_worker = #{worker_id}-->
<!-- OR m.operation_worker = #{worker_id};--> <!-- OR m.operation_worker = #{worker_id};-->
<!-- </select>--> <!-- </select>-->
<select id="querypeopleId" resultType="com.example.operation_platform.model.vo.MessageVO">
SELECT
tm.id,
sw.worker_name AS softwareWorker,
hw.worker_name AS hardwareWorker,
ow.worker_name AS operationWorker,
tm.warn_message AS warnMessage,
tm.operation_message AS operationMessage,
tm.software_worker AS softwareWorkerId,
tm.hardware_worker AS hardwareWorkerId,
tm.operation_worker AS operationWorkerId,
GROUP_CONCAT(DISTINCT warn_worker.worker_name SEPARATOR ', ') AS warnMessageNames,
GROUP_CONCAT(DISTINCT operation_worker.worker_name SEPARATOR ', ') AS operationMessageNames
FROM
tb_message tm
LEFT JOIN tb_worker sw ON sw.id = tm.software_worker
LEFT JOIN tb_worker hw ON hw.id = tm.hardware_worker
LEFT JOIN tb_worker ow ON ow.id = tm.operation_worker
LEFT JOIN (
SELECT
tm.id,
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(tm.warn_message, ',', numbers.n), ',', -1)) AS warn_id
FROM
tb_message tm
CROSS JOIN (
SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) numbers
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
AND numbers.n &lt;= (LENGTH(tm.warn_message) - LENGTH(REPLACE(tm.warn_message, ',', '')) + 1)
) AS split_warn ON split_warn.id = tm.id
LEFT JOIN tb_worker warn_worker ON warn_worker.id = split_warn.warn_id
LEFT JOIN (
SELECT
tm.id,
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(tm.operation_message, ',', numbers.n), ',', -1)) AS operation_id
FROM
tb_message tm
CROSS JOIN (
SELECT 1 AS n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL SELECT 5
) numbers
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
AND numbers.n &lt;= (LENGTH(tm.operation_message) - LENGTH(REPLACE(tm.operation_message, ',', '')) + 1)
) AS split_operation ON split_operation.id = tm.id
LEFT JOIN tb_worker operation_worker ON operation_worker.id = split_operation.operation_id
WHERE
(#{stationId} IS NULL OR tm.station_id = #{stationId})
AND (tm.robot_id = #{robotId} OR tm.drone_id = #{droneId})
GROUP BY
tm.id, sw.worker_name, hw.worker_name, ow.worker_name, tm.warn_message, tm.operation_message
</select>
<select id="queryrobotBystationId" resultType="com.example.operation_platform.model.vo.RobotAndDrone">
select
COALESCE(br.name, ud.name) robotName,
tm.robot_id robotId,
tm.drone_id droneId
from tb_message tm
left join
bs_robot br on tm.robot_id = br.id
left join
bs_station bs on tm.station_id = bs.id
left join
uav_drone ud on tm.drone_id = ud.id
where
tm.station_id = #{stationId}
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -11,6 +11,22 @@ ...@@ -11,6 +11,22 @@
tb_operation_item tw tb_operation_item tw
</select> </select>
<select id="queryByIdList" resultType="com.example.operation_platform.model.entity.OperationItem">
select
tw.id id,
tw.operation_item operationItem,
tw.operation_guide operationGuide
from
tb_operation_item tw
<where>
<if test="itemIdList != null and itemIdList.size() > 0">
tw.id in
<foreach collection="itemIdList" item="item" open="(" separator="," close=")">
#{itemIdList}
</foreach>
</if>
</where>
</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