feat(dms): 完善定时任务生成巡检和保养工单功能

- 新增countByPlanIdAndToday方法检查计划今日是否已生成工单
- 实现insertCompletedInspectInstance方法创建已完成巡检工单
- 实现insertCompletedMaintInstance方法创建已完成保养工单
- 添加selectDeviceIdsByRouteId和selectDeviceIdsByPlanId查询设备ID列表
- 更新巡检计划表结构增加cron_expression字段
- 重构定时任务使用Mapper替代JdbcTemplate提高性能
- 优化巡检计划下次执行时间计算支持cron表达式
- 修复序列名称前缀问题统一使用HAIWEI前缀
- 添加日志记录和异常处理增强系统稳定性
master
zangch@mesnac.com 2 months ago
parent f56a6d03a6
commit 9d60b0cd78

@ -84,4 +84,11 @@ public interface DmsBillsInspectInstanceMapper
int selectUnCompletedInstance(@Param("inspectInstanceId") Long inspectInstanceId);
int selectAllInstance(@Param("inspectInstanceId")Long inspectInstanceId);
/**
*
* @param planInspectId ID
* @return
*/
int countByPlanIdAndToday(@Param("planInspectId") Long planInspectId);
}

@ -4,6 +4,7 @@ import com.aucma.dms.domain.DmsBillsMaintDetail;
import com.aucma.dms.domain.DmsBillsMaintDetailProject;
import com.aucma.dms.domain.DmsBillsMaintInstance;
import com.aucma.dms.domain.DmsMaintInstanceActivity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -84,4 +85,11 @@ public interface DmsBillsMaintInstanceMapper {
int batchDmsProject(List<DmsBillsMaintDetailProject> list);
List<DmsMaintInstanceActivity> selectDmsMaintInfo(Long maintInstanceId);
/**
*
* @param planMaintId ID
* @return
*/
int countByPlanIdAndToday(@Param("planMaintId") Long planMaintId);
}

@ -1,6 +1,7 @@
package com.aucma.dms.mapper;
import com.aucma.dms.domain.DmsInspectRouteDetail;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -62,4 +63,11 @@ public interface DmsInspectRouteDetailMapper
List<DmsInspectRouteDetail> selectInspectRouteListByInspectRouteId(Long inspectRouteId);
/**
* 线ID
* @param inspectRouteId 线ID
* @return IDmachine_id
*/
List<Long> selectDeviceIdsByRouteId(@Param("inspectRouteId") Long inspectRouteId);
}

@ -1,7 +1,9 @@
package com.aucma.dms.mapper;
import com.aucma.dms.domain.DmsPlanInspect;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -63,4 +65,19 @@ public interface DmsPlanInspectMapper
DmsPlanInspect selectPlanInspectJoinJobByInspectId(Long planInspectId);
DmsPlanInspect selectPlanInspectJoinJobByInspectId1(String planInspectId);
/**
*
* @return
*/
List<DmsPlanInspect> selectPendingInspectPlans();
/**
*
* @param planInspectId ID
* @param planTime
* @return
*/
int updatePlanNextTime(@Param("planInspectId") Long planInspectId,
@Param("planTime") Date planTime);
}

@ -77,4 +77,11 @@ public interface DmsPlanMaintDetailMapper
Long selectStandardId(@Param("stationId") Long stationId);
/**
* ID
* @param planMaintId ID
* @return ID
*/
List<Long> selectDeviceIdsByPlanId(@Param("planMaintId") Long planMaintId);
}

@ -2,7 +2,9 @@ package com.aucma.dms.mapper;
import com.aucma.dms.domain.DmsPlanMaint;
import com.aucma.dms.domain.DmsPlanMaintDetail;
import org.apache.ibatis.annotations.Param;
import java.util.Date;
import java.util.List;
/**
@ -106,4 +108,19 @@ public interface DmsPlanMaintMapper
*/
public DmsPlanMaint selectPlanMaintJoinJobByPlanMaintId(Long planMaintId);
/**
*
* @return
*/
List<DmsPlanMaint> selectPendingMaintPlans();
/**
*
* @param planMaintId ID
* @param maintTime
* @return
*/
int updatePlanNextTime(@Param("planMaintId") Long planMaintId,
@Param("maintTime") Date maintTime);
}

@ -106,4 +106,12 @@ public interface IDmsBillsInspectInstanceService
* @return
*/
public int updateDeviceStatus(DmsInspectInstanceDetail detail);
/**
* 线
*
* @param dmsBillsInspectInstance planInspectIdinspectRouteIdinspectType
* @return
*/
int insertCompletedInspectInstance(DmsBillsInspectInstance dmsBillsInspectInstance);
}

@ -105,4 +105,12 @@ public interface IDmsBillsMaintInstanceService
* @return
*/
public int updateDeviceStatus(DmsBillsMaintDetail detail);
/**
*
*
* @param planMaintCode
* @return
*/
int insertCompletedMaintInstance(String planMaintCode);
}

@ -1,18 +1,5 @@
package com.aucma.dms.service.impl;
//import com.hw.common.core.constant.DmsConstants;
//import com.hw.common.core.constant.SecurityConstants;
//import com.hw.common.core.exception.ServiceException;
//import com.hw.common.core.utils.DateUtils;
//import com.hw.common.core.utils.StringUtils;
//import com.hw.common.security.utils.SecurityUtils;
//import com.aucma.dms.domain.*;
//import com.aucma.dms.domain.vo.DmsBillsInspectInstanceScanVo;
//import com.aucma.dms.mapper.*;
//import com.aucma.dms.service.IDmsBillsInspectInstanceService;
//import com.hw.system.api.RemoteSysCommonService;
//import com.hw.system.api.model.LoginUser;
import com.aucma.common.constant.DmsConstants;
import com.aucma.common.core.domain.model.LoginUser;
import com.aucma.common.exception.ServiceException;
@ -402,6 +389,70 @@ public class DmsBillsInspectInstanceServiceImpl implements IDmsBillsInspectInsta
}
/**
* 线
* SecurityUtils
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int insertCompletedInspectInstance(DmsBillsInspectInstance dmsBillsInspectInstance) {
Date now = new Date();
// 1. 设置工单为已完成状态
dmsBillsInspectInstance.setCreateTime(now);
dmsBillsInspectInstance.setIsFlag("1");
dmsBillsInspectInstance.setInspectStatus(DmsConstants.DMS_BILLS_INSPECT_INSTANCE_INSPECT_STATUS_FINISH); // 3=已完成
dmsBillsInspectInstance.setPlanBeginTime(now);
dmsBillsInspectInstance.setPlanEndTime(now);
dmsBillsInspectInstance.setRealBeginTime(now);
dmsBillsInspectInstance.setRealEndTime(now);
if (dmsBillsInspectInstance.getCreateBy() == null) {
dmsBillsInspectInstance.setCreateBy(-1L);
}
int i = dmsBillsInspectInstanceMapper.insertDmsBillsInspectInstance(dmsBillsInspectInstance);
// 2. 创建工单实例节点(第一步)
DmsBillsInspectInstanceActivity activity = new DmsBillsInspectInstanceActivity();
activity.setInspectInstanceId(dmsBillsInspectInstance.getInspectInstanceId());
activity.setInspectRouteId(dmsBillsInspectInstance.getInspectRouteId());
activity.setDeviceAmount(dmsBillsInspectInstance.getDeviceAmount());
activity.setPerformer(dmsBillsInspectInstance.getPerformer());
activity.setProcessStepOrder(1L);
activity.setProcessHandleStatus("3"); // 已完成
dmsBillsInspectInstanceActivityMapper.insertDmsBillsInspectInstanceActivity(activity);
// 3. 创建巡检工单明细:路线所有设备均为正常/已完成状态
if (dmsBillsInspectInstance.getInspectRouteId() != null) {
DmsInspectRouteDetail queryRouteDetail = new DmsInspectRouteDetail();
queryRouteDetail.setInspectRouteId(dmsBillsInspectInstance.getInspectRouteId());
List<DmsInspectRouteDetail> routeDetails = dmsInspectRouteDetailMapper.selectDmsInspectRouteDetailList(queryRouteDetail);
for (DmsInspectRouteDetail routeDetail : routeDetails) {
DmsInspectInstanceDetail detail = new DmsInspectInstanceDetail();
Long deviceId = routeDetail.getDeviceId();
detail.setInspectInstanceId(dmsBillsInspectInstance.getInspectInstanceId());
detail.setLineStep(routeDetail.getLineStep());
detail.setDeviceId(deviceId);
detail.setInstanceDetailStatus(DmsConstants.DMS_INSPECT_INSTANCE_DETAIL_STATUS_FINISH); // 3=已完成
detail.setInspectStandard(routeDetail.getInspectStandard());
detail.setInspectStatus(DmsConstants.DMS_INSPECT_INSTANCE_DETAIL_INSPECT_STATUS_PASS); // 1=正常/合格
dmsInspectInstanceDetailMapper.insertDmsInspectInstanceDetail(detail);
// 创建明细项目记录
Long projectId = dmsInspectInstanceDetailMapper.selectProjectId(routeDetail.getInspectStandard());
DmsInspectInstanceDetailProject detailProject = new DmsInspectInstanceDetailProject();
detailProject.setInstanceDetailId(detail.getInstanceDetailId());
detailProject.setInspectProjectId(projectId);
detailProject.setCreateTime(now);
detailProject.setInspectProjectStatus(DmsConstants.DMS_INSPECT_INSTANCE_DETAIL_PROJECT_STATUS_PASS); // 1=合格
dmsInspectInstanceDetailProjectMapper.insertDmsInspectInstanceDetailProject(detailProject);
}
}
return i;
}
/**
*
*/

@ -8,10 +8,13 @@ import com.aucma.common.utils.uuid.Seq;
import com.aucma.dms.domain.*;
import com.aucma.dms.mapper.*;
import com.aucma.dms.service.IDmsBillsMaintInstanceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@ -26,6 +29,8 @@ import java.util.stream.Collectors;
*/
@Service
public class DmsBillsMaintInstanceServiceImpl implements IDmsBillsMaintInstanceService {
private static final Logger log = LoggerFactory.getLogger(DmsBillsMaintInstanceServiceImpl.class);
@Autowired
private DmsBillsMaintInstanceMapper dmsBillsMaintInstanceMapper;
@Autowired
@ -399,4 +404,84 @@ public class DmsBillsMaintInstanceServiceImpl implements IDmsBillsMaintInstanceS
return result;
}
/**
*
* SecurityUtils
*/
@Override
@Transactional(rollbackFor = Exception.class)
public int insertCompletedMaintInstance(String planMaintCode) {
String planMaintCodeS = planMaintCode.replaceAll("\"", "");
DmsPlanMaint dmsPlanMaint = dmsPlanMaintMapper.selectDmsPlanMaintJoinByPlanMaintCode(planMaintCodeS);
List<DmsPlanMaintDetail> planMaintDetails = dmsPlanMaint.getDmsPlanMaintDetailList();
if (planMaintDetails == null || planMaintDetails.isEmpty()) {
log.warn("保养计划[{}]无明细数据,跳过生成工单", planMaintCode);
return 0;
}
Date now = new Date();
DmsBillsMaintInstance instance = new DmsBillsMaintInstance();
instance.setCreateTime(now);
instance.setPlanBeginTime(now);
instance.setPlanEndTime(now);
instance.setRealBeginTime(now);
instance.setRealEndTime(now);
instance.setPlanMaintId(dmsPlanMaint.getPlanMaintId());
instance.setBillsMaintCode(Seq.getId(Seq.maintInstanceSeqType, Seq.maintInstanceCode));
instance.setMaintStatus(DmsConstants.DMS_BILLS_MAINT_INSTANCE_STATUS_COMPLETE); // 已完成
instance.setMaintCompRate(BigDecimal.valueOf(100)); // 完成率100%
instance.setMaintGroup(dmsPlanMaint.getMaintGroup());
instance.setMaintSupervisor(dmsPlanMaint.getMaintSupervisor());
instance.setMaintLevel(dmsPlanMaint.getMaintLevel());
instance.setIsFlag(1L);
instance.setCreateBy(-1L);
int i = dmsBillsMaintInstanceMapper.insertDmsBillsMaintInstance(instance);
// 创建工单实例节点(第一步)
DmsMaintInstanceActivity activity = new DmsMaintInstanceActivity();
activity.setMaintInstanceId(instance.getMaintInstanceId());
activity.setProcessStepOrder(1L);
activity.setProcessHandleStatus("3"); // 已完成
dmsMaintInstanceActivityMapper.insertDmsMaintInstanceActivity(activity);
// 创建保养工单明细(所有设备均为已完成状态)
List<DmsBillsMaintDetail> billsMaintDetails = new ArrayList<>();
for (DmsPlanMaintDetail planDetail : planMaintDetails) {
DmsBillsMaintDetail detail = new DmsBillsMaintDetail();
detail.setMaintInstanceId(instance.getMaintInstanceId());
detail.setDeviceId(planDetail.getDeviceId());
detail.setStationId(planDetail.getMaintStationId());
detail.setMaintStandardId(planDetail.getMaintStandardId());
detail.setIsFlag(1L);
detail.setMaintStatus(DmsConstants.DMS_BILLS_MAINT_INSTANCE_STATUS_COMPLETE); // 已完成
detail.setCreateTime(now);
billsMaintDetails.add(detail);
}
dmsBillsMaintInstanceMapper.batchDmsBillsMaintDetail(billsMaintDetails);
// 创建保养工单明细项目(所有项目均为已完成状态)
List<DmsBillsMaintDetail> insertedDetails = dmsBillsMaintDetailMapper.selectDetailList(instance.getMaintInstanceId());
ArrayList<DmsBillsMaintDetailProject> projectList = new ArrayList<>();
for (DmsBillsMaintDetail detail : insertedDetails) {
List<DmsBaseMaintProject> projects = dmsBillsMaintDetailMapper.selectPrjectIds(detail.getStationId());
for (DmsBaseMaintProject project : projects) {
DmsBillsMaintDetailProject detailProject = new DmsBillsMaintDetailProject();
detailProject.setBillsMaintDetailId(detail.getBillsMaintDetailId());
detailProject.setMaintProjectId(project.getMaintProjectId());
detailProject.setMaintProjectName(project.getMaintProjectName());
detailProject.setMaintProjectDesc(project.getMaintProjectDesc());
detailProject.setMaintProjectStatus(DmsConstants.DMS_MAINT_PROJECT_STATUS_COMPLETE); // 已完成
detailProject.setCreateTime(now);
projectList.add(detailProject);
}
}
if (!projectList.isEmpty()) {
dmsBillsMaintInstanceMapper.batchDmsProject(projectList);
}
return i;
}
}

@ -57,6 +57,8 @@ public class DmsInspectRouteDetailServiceImpl implements IDmsInspectRouteDetailS
@Override
public int insertDmsInspectRouteDetail(DmsInspectRouteDetail dmsInspectRouteDetail)
{
// 避免外部传入固定主键导致序列失效,强制使用序列生成
dmsInspectRouteDetail.setRouteDetailId(null);
fillMachineIdIfAbsent(dmsInspectRouteDetail);
return dmsInspectRouteDetailMapper.insertDmsInspectRouteDetail(dmsInspectRouteDetail);
}

@ -4,19 +4,20 @@ import com.aucma.common.core.domain.model.LoginUser;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.SecurityUtils;
import com.aucma.common.utils.uuid.Seq;
import com.aucma.dms.domain.DmsBillsInspectInstance;
import com.aucma.dms.domain.DmsPlanInspect;
import com.aucma.dms.mapper.DmsBaseInspectRouteMapper;
import com.aucma.dms.mapper.DmsBillsInspectInstanceMapper;
import com.aucma.dms.mapper.DmsPlanInspectMapper;
import com.aucma.dms.service.IDmsBillsInspectInstanceService;
import com.aucma.dms.service.IDmsPlanInspectService;
import com.aucma.quartz.util.CronUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import java.util.Map;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
@ -38,9 +39,12 @@ public class DmsPlanInspectServiceImpl implements IDmsPlanInspectService
private RemoteJobService remoteJobService;*/
@Autowired
private DmsBaseInspectRouteMapper dmsBaseInspectRouteMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
private DmsBillsInspectInstanceMapper dmsBillsInspectInstanceMapper;
@Autowired
private IDmsBillsInspectInstanceService dmsBillsInspectInstanceService;
/**
*
@ -157,6 +161,7 @@ public class DmsPlanInspectServiceImpl implements IDmsPlanInspectService
//通过cron表达式获取下一次执行时间
Date nextExecution = CronUtils.getNextExecution(time);
dmsPlanInspect.setPlanTime(nextExecution);
dmsPlanInspect.setCronExpression(cron);
dmsPlanInspect.setPlanInspectCode(planInspectCode);
// dmsPlanInspect.setJobId(jobIdR.getData().longValue());
@ -222,74 +227,87 @@ public class DmsPlanInspectServiceImpl implements IDmsPlanInspectService
/**
* 0
* 使MapperJdbcTemplate
*
* cron
*/
@Scheduled(cron = "0 0 0 * * ?")
@Transactional(rollbackFor = Exception.class)
public void generateDailyInspectWorkOrders() {
log.info("========== 开始执行巡检工单生成任务 ==========");
int count = 0;
int skipCount = 0;
try {
// 查询今天需要执行的巡检计划plan_time <= 今天)
String sql = "SELECT plan_inspect_id, plan_inspect_code, inspect_type, inspect_route_id, " +
"device_amount, time_limit, cycle_period, performer " +
"FROM dms_plan_inspect " +
"WHERE (is_flag = '1' OR is_flag IS NULL) " +
"AND plan_time <= TRUNC(SYSDATE) + 1";
List<Map<String, Object>> plans = jdbcTemplate.queryForList(sql);
for (Map<String, Object> plan : plans) {
// 通过Mapper查询今天需要执行的巡检计划plan_time <= 今天)
List<DmsPlanInspect> plans = dmsPlanInspectMapper.selectPendingInspectPlans();
for (DmsPlanInspect plan : plans) {
try {
Long planInspectId = ((Number) plan.get("PLAN_INSPECT_ID")).longValue();
String planInspectCode = (String) plan.get("PLAN_INSPECT_CODE");
Long inspectRouteId = plan.get("INSPECT_ROUTE_ID") != null ?
((Number) plan.get("INSPECT_ROUTE_ID")).longValue() : null;
// 检查今天是否已生成工单(避免重复)
String checkSql = "SELECT COUNT(1) FROM dms_bills_inspect_instance " +
"WHERE plan_inspect_code = ? AND TRUNC(create_time) = TRUNC(SYSDATE)";
Integer existCount = jdbcTemplate.queryForObject(checkSql, Integer.class, planInspectCode);
if (existCount != null && existCount > 0) {
Long planInspectId = plan.getPlanInspectId();
String planInspectCode = plan.getPlanInspectCode();
Long inspectRouteId = plan.getInspectRouteId();
if (planInspectCode == null || planInspectCode.isEmpty()) {
log.warn("巡检计划ID[{}]编号为空,跳过", planInspectId);
skipCount++;
continue;
}
// 通过Mapper检查今天是否已生成工单避免重复
int existCount = dmsBillsInspectInstanceMapper.countByPlanIdAndToday(planInspectId);
if (existCount > 0) {
log.debug("巡检计划[{}]今天已生成工单,跳过", planInspectCode);
continue;
}
// 生成巡检工单
// 构建巡检工单对象(工单中所有设备状态默认为正常,异常可在网页端维护)
String billsCode = Seq.getId(Seq.dmsBillsFaultInstanceSeqType, "XJ");
String insertSql = "INSERT INTO dms_bills_inspect_instance " +
"(inspect_instance_id, bills_inspect_code, plan_inspect_code, plan_inspect_id, " +
"inspect_route_id, bills_status, is_flag, create_time, create_by) " +
"VALUES (SEQ_DMS_BILLS_INSPECT_INSTANCE.NEXTVAL, ?, ?, ?, ?, '0', '1', SYSDATE, -1)";
jdbcTemplate.update(insertSql, billsCode, planInspectCode, planInspectId, inspectRouteId);
DmsBillsInspectInstance instance = new DmsBillsInspectInstance();
instance.setBillsInspectCode(billsCode);
instance.setPlanInspectId(planInspectId);
instance.setInspectRouteId(inspectRouteId);
instance.setInspectType(plan.getInspectType());
instance.setDeviceAmount(plan.getDeviceAmount());
instance.setPerformer(plan.getPerformer());
instance.setCreateBy(-1L);
// 通过Service创建已完成状态的巡检工单含明细路线所有设备正常
dmsBillsInspectInstanceService.insertCompletedInspectInstance(instance);
count++;
log.info("已为巡检计划[{}]生成工单[{}]", planInspectCode, billsCode);
// 更新计划的下次执行时间(根据周期计算)
updateInspectPlanNextTime(planInspectId);
log.info("已为巡检计划[{}]生成已完成工单[{}]", planInspectCode, billsCode);
// 更新计划的下次执行时间(根据cron表达式或默认+1天
updateInspectPlanNextTime(plan);
} catch (Exception e) {
log.error("为巡检计划生成工单失败: {}", e.getMessage());
log.error("为巡检计划[{}]生成工单失败: {}", plan.getPlanInspectCode(), e.getMessage(), e);
}
}
} catch (Exception e) {
log.error("查询巡检计划失败", e);
}
log.info("========== 巡检工单生成任务完成,生成数量: {} ==========", count);
log.info("========== 巡检工单生成任务完成,生成数量: {},跳过数量: {} ==========", count, skipCount);
}
/**
*
* 使croncron+1
*/
private void updateInspectPlanNextTime(Long planInspectId) {
private void updateInspectPlanNextTime(DmsPlanInspect plan) {
try {
// 根据周期计算下次执行时间(默认+1天
String updateSql = "UPDATE dms_plan_inspect SET plan_time = TRUNC(SYSDATE) + 1, update_time = SYSDATE WHERE plan_inspect_id = ?";
jdbcTemplate.update(updateSql, planInspectId);
log.debug("更新巡检计划[{}]下次执行时间", planInspectId);
Date nextTime = null;
String cronExpression = plan.getCronExpression();
if (cronExpression != null && !cronExpression.isEmpty()) {
nextTime = CronUtils.getNextExecution(cronExpression);
}
if (nextTime == null) {
// 默认下次执行时间为明天
nextTime = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000L);
}
dmsPlanInspectMapper.updatePlanNextTime(plan.getPlanInspectId(), nextTime);
log.debug("更新巡检计划[{}]下次执行时间: {}", plan.getPlanInspectCode(), nextTime);
} catch (Exception e) {
log.warn("更新巡检计划下次执行时间失败: {}", e.getMessage());
log.warn("更新巡检计划[{}]下次执行时间失败: {}", plan.getPlanInspectCode(), e.getMessage());
}
}
}

@ -1,12 +1,5 @@
package com.aucma.dms.service.impl;
//import com.hw.common.core.exception.ServiceException;
//import com.hw.common.core.utils.DateUtils;
//import com.hw.common.security.utils.SecurityUtils;
//import com.aucma.dms.domain.DmsPlanMaintDetail;
//import com.aucma.dms.mapper.DmsPlanMaintDetailMapper;
//import com.aucma.dms.service.IDmsPlanMaintDetailService;
import com.aucma.common.exception.ServiceException;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.SecurityUtils;

@ -8,19 +8,18 @@ import com.aucma.common.utils.StringUtils;
import com.aucma.common.utils.uuid.Seq;
import com.aucma.dms.domain.DmsPlanMaint;
import com.aucma.dms.domain.DmsPlanMaintDetail;
import com.aucma.dms.mapper.DmsBillsMaintInstanceMapper;
import com.aucma.dms.mapper.DmsPlanMaintMapper;
import com.aucma.dms.service.IDmsBillsMaintInstanceService;
import com.aucma.dms.service.IDmsPlanMaintService;
import com.aucma.quartz.util.CronUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -38,9 +37,12 @@ public class DmsPlanMaintServiceImpl implements IDmsPlanMaintService {
@Autowired
private DmsPlanMaintMapper dmsPlanMaintMapper;
@Autowired
private JdbcTemplate jdbcTemplate;
private DmsBillsMaintInstanceMapper dmsBillsMaintInstanceMapper;
@Autowired
private IDmsBillsMaintInstanceService dmsBillsMaintInstanceService;
/* @Autowired
private RemoteJobService remoteJobService;*/
@ -138,6 +140,7 @@ public class DmsPlanMaintServiceImpl implements IDmsPlanMaintService {
//通过cron表达式获取下一次执行时间
Date nextExecution = CronUtils.getNextExecution(time);
dmsPlanMaint.setMaintTime(nextExecution);
dmsPlanMaint.setCronExpression(cron);
// dmsPlanMaint.setJobId(jobIdR.getData().longValue());
dmsPlanMaint.setPlanMaintCode(planMaintCode);
Long timeLimitDays = dmsPlanMaint.getTimeLimitDays()==null?0L:dmsPlanMaint.getTimeLimitDays();
@ -285,63 +288,75 @@ public class DmsPlanMaintServiceImpl implements IDmsPlanMaintService {
/**
* 0
* 使MapperJdbcTemplate
*
* cron
*/
@Scheduled(cron = "0 0 0 * * ?")
@Transactional(rollbackFor = Exception.class)
public void generateDailyMaintWorkOrders() {
log.info("========== 开始执行保养工单生成任务 ==========");
int count = 0;
int skipCount = 0;
try {
// 查询今天需要执行的保养计划maint_time <= 今天)
String sql = "SELECT plan_maint_id, plan_maint_code, maint_level, maint_group, " +
"maint_supervisor, time_limit, cycle_period, cron_expression " +
"FROM dms_plan_maint " +
"WHERE (is_flag = 0 OR is_flag IS NULL) " +
"AND maint_time <= TRUNC(SYSDATE) + 1";
List<Map<String, Object>> plans = jdbcTemplate.queryForList(sql);
for (Map<String, Object> plan : plans) {
// 通过Mapper查询今天需要执行的保养计划maint_time <= 今天)
List<DmsPlanMaint> plans = dmsPlanMaintMapper.selectPendingMaintPlans();
for (DmsPlanMaint plan : plans) {
try {
Long planMaintId = ((Number) plan.get("PLAN_MAINT_ID")).longValue();
String planMaintCode = (String) plan.get("PLAN_MAINT_CODE");
// 检查今天是否已生成工单(避免重复)
String checkSql = "SELECT COUNT(1) FROM dms_bills_maint_instance " +
"WHERE plan_maint_code = ? AND TRUNC(create_time) = TRUNC(SYSDATE)";
Integer existCount = jdbcTemplate.queryForObject(checkSql, Integer.class, planMaintCode);
if (existCount != null && existCount > 0) {
Long planMaintId = plan.getPlanMaintId();
String planMaintCode = plan.getPlanMaintCode();
if (planMaintCode == null || planMaintCode.isEmpty()) {
log.warn("保养计划ID[{}]编号为空,跳过", planMaintId);
skipCount++;
continue;
}
// 通过Mapper检查今天是否已生成工单避免重复
int existCount = dmsBillsMaintInstanceMapper.countByPlanIdAndToday(planMaintId);
if (existCount > 0) {
log.debug("保养计划[{}]今天已生成工单,跳过", planMaintCode);
continue;
}
// 生成保养工单
String billsCode = Seq.getId(Seq.dmsBillsFaultInstanceSeqType, "BY");
String insertSql = "INSERT INTO dms_bills_maint_instance " +
"(maint_instance_id, bills_maint_code, plan_maint_code, plan_maint_id, " +
"bills_status, is_flag, create_time, create_by) " +
"VALUES (SEQ_DMS_BILLS_MAINT_INSTANCE.NEXTVAL, ?, ?, ?, '0', '1', SYSDATE, -1)";
jdbcTemplate.update(insertSql, billsCode, planMaintCode, planMaintId);
// 通过Service创建已完成状态的保养工单含明细工单中所有设备默认保养完成异常可在网页端维护
dmsBillsMaintInstanceService.insertCompletedMaintInstance(planMaintCode);
count++;
log.info("已为保养计划[{}]生成工单[{}]", planMaintCode, billsCode);
// 更新计划的下次执行时间
String cronExpression = (String) plan.get("CRON_EXPRESSION");
if (cronExpression != null && !cronExpression.isEmpty()) {
Date nextTime = CronUtils.getNextExecution(cronExpression);
String updateSql = "UPDATE dms_plan_maint SET maint_time = ?, update_time = SYSDATE WHERE plan_maint_id = ?";
jdbcTemplate.update(updateSql, nextTime, planMaintId);
}
log.info("已为保养计划[{}]生成已完成工单", planMaintCode);
// 更新计划的下次执行时间根据cron表达式或默认+1天
updateMaintPlanNextTime(plan);
} catch (Exception e) {
log.error("为保养计划生成工单失败: {}", e.getMessage());
log.error("为保养计划[{}]生成工单失败: {}", plan.getPlanMaintCode(), e.getMessage(), e);
}
}
} catch (Exception e) {
log.error("查询保养计划失败", e);
}
log.info("========== 保养工单生成任务完成,生成数量: {} ==========", count);
log.info("========== 保养工单生成任务完成,生成数量: {},跳过数量: {} ==========", count, skipCount);
}
/**
*
* 使croncron+1
*/
private void updateMaintPlanNextTime(DmsPlanMaint plan) {
try {
Date nextTime = null;
String cronExpression = plan.getCronExpression();
if (cronExpression != null && !cronExpression.isEmpty()) {
nextTime = CronUtils.getNextExecution(cronExpression);
}
if (nextTime == null) {
// 默认下次执行时间为明天
nextTime = new Date(System.currentTimeMillis() + 24 * 60 * 60 * 1000L);
}
dmsPlanMaintMapper.updatePlanNextTime(plan.getPlanMaintId(), nextTime);
log.debug("更新保养计划[{}]下次执行时间: {}", plan.getPlanMaintCode(), nextTime);
} catch (Exception e) {
log.warn("更新保养计划[{}]下次执行时间失败: {}", plan.getPlanMaintCode(), e.getMessage());
}
}
}

@ -284,4 +284,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
x.inspect_instance_id = #{inspectInstanceId}
</select>
<!-- 检查指定计划今天是否已生成工单 -->
<select id="countByPlanIdAndToday" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM dms_bills_inspect_instance
WHERE plan_inspect_id = #{planInspectId}
AND TRUNC(create_time) = TRUNC(SYSDATE)
</select>
</mapper>

@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsBillsMaintDetail" parameterType="DmsBillsMaintDetail">
<selectKey keyProperty="billsMaintDetailId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_MAINT_DETAIL.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_MAINT_DETAIL.NEXTVAL FROM DUAL
</selectKey>
insert into dms_bills_maint_detail
<trim prefix="(" suffix=")" suffixOverrides=",">

@ -40,7 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsBillsMaintDetailProject" parameterType="DmsBillsMaintDetailProject">
<selectKey keyProperty="maintDetailProjectId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_MAINT_DTL_PROJ.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_MAINT_DTL_PROJ.NEXTVAL FROM DUAL
</selectKey>
insert into dms_bills_maint_detail_project
<trim prefix="(" suffix=")" suffixOverrides=",">

@ -85,7 +85,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsBillsMaintInstance" parameterType="DmsBillsMaintInstance">
<selectKey keyProperty="maintInstanceId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_MAINT_INST.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_MAINT_INST.NEXTVAL FROM DUAL
</selectKey>
insert into dms_bills_maint_instance
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -220,4 +220,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where
x.maint_instance_id = 25
</select>
<!-- 检查指定计划今天是否已生成工单 -->
<select id="countByPlanIdAndToday" resultType="java.lang.Integer">
SELECT COUNT(1)
FROM dms_bills_maint_instance
WHERE plan_maint_id = #{planMaintId}
AND TRUNC(create_time) = TRUNC(SYSDATE)
</select>
</mapper>

@ -44,7 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsInspectRouteDetail" parameterType="DmsInspectRouteDetail">
<selectKey keyProperty="routeDetailId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_INSPECT_RTE_DTL.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_INSPECT_RTE_DTL.NEXTVAL FROM DUAL
</selectKey>
insert into dms_inspect_route_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -93,4 +93,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join dms_base_inspect_standard c on a.inspect_standard = c.inspect_standard_id
where a.inspect_route_id = #{inspectRouteId}
</select>
<!-- 查询巡检路线下的所有设备ID列表 -->
<select id="selectDeviceIdsByRouteId" resultType="java.lang.Long">
SELECT machine_id
FROM dms_inspect_route_detail
WHERE inspect_route_id = #{inspectRouteId}
</select>
</mapper>

@ -27,7 +27,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectDmsPlanInspectVo">
select plan_inspect_id, plan_inspect_code, plan_inspect_name, inspect_type, inspect_route_id, device_amount, plan_time, cycle_period,time_limit,job_id, performer, is_flag, remark, create_by, create_time, update_by, update_time from dms_plan_inspect
select plan_inspect_id, plan_inspect_code, plan_inspect_name, inspect_type, inspect_route_id, device_amount, plan_time, cycle_period,time_limit,job_id, performer, is_flag, remark, create_by, create_time, update_by, update_time, cron_expression from dms_plan_inspect
</sql>
<select id="selectDmsPlanInspectList" parameterType="DmsPlanInspect" resultMap="DmsPlanInspectResult">
@ -55,7 +55,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsPlanInspect" parameterType="DmsPlanInspect">
<selectKey keyProperty="planInspectId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_PLAN_INSPECT.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_PLAN_INSPECT.NEXTVAL FROM DUAL
</selectKey>
insert into dms_plan_inspect
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -76,6 +76,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="planInspectId != null">#{planInspectId,jdbcType=NUMERIC},</if>
@ -95,6 +96,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateBy != null">#{updateBy,jdbcType=NUMERIC},</if>
<if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
<if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
</trim>
</insert>
@ -117,6 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time = #{createTime,jdbcType=TIMESTAMP},</if>
<if test="updateBy != null">update_by = #{updateBy,jdbcType=BIGINT},</if>
<if test="updateTime != null">update_time = #{updateTime,jdbcType=TIMESTAMP},</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
</trim>
where plan_inspect_id = #{planInspectId,jdbcType=BIGINT}
</update>
@ -135,7 +138,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPlanInspectJoinJobByInspectId" parameterType="Long" resultMap="DmsPlanInspectResult">
select plan_inspect_id, plan_inspect_code, plan_inspect_name, inspect_type,
inspect_route_id, device_amount, plan_time, cycle_period, time_limit, job_id,
performer, is_flag, remark, create_by, create_time, update_by, update_time
performer, is_flag, remark, create_by, create_time, update_by, update_time, cron_expression
from dms_plan_inspect
where plan_inspect_id = #{planInspectId}
</select>
@ -143,8 +146,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
parameterType="java.lang.String">
select plan_inspect_id, plan_inspect_code, plan_inspect_name, inspect_type,
inspect_route_id, device_amount, plan_time, cycle_period, time_limit, job_id,
performer, is_flag, remark, create_by, create_time, update_by, update_time
performer, is_flag, remark, create_by, create_time, update_by, update_time, cron_expression
from dms_plan_inspect
where plan_inspect_code = #{planInspectCode}
</select>
<!-- 查询待执行的巡检计划列表 -->
<select id="selectPendingInspectPlans" resultMap="DmsPlanInspectResult">
SELECT a.plan_inspect_id, a.plan_inspect_code, a.plan_inspect_name, a.inspect_type,
a.inspect_route_id, a.device_amount, a.plan_time, a.cycle_period,
a.time_limit, a.job_id, a.performer, a.is_flag, a.remark,
a.create_by, a.create_time, a.update_by, a.update_time,
a.cron_expression
FROM dms_plan_inspect a
WHERE (a.is_flag = '1' OR a.is_flag IS NULL)
AND a.plan_time &lt;= TRUNC(SYSDATE) + 1
</select>
<!-- 更新巡检计划的下次执行时间 -->
<update id="updatePlanNextTime">
UPDATE dms_plan_inspect
SET plan_time = #{planTime}, update_time = SYSDATE
WHERE plan_inspect_id = #{planInspectId}
</update>
</mapper>

@ -49,7 +49,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsPlanMaintDetail" parameterType="DmsPlanMaintDetail">
<selectKey keyProperty="planMaintDetailId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_PLAN_MAINT_DETAIL.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_PLAN_MAINT_DETAIL.NEXTVAL FROM DUAL
</selectKey>
insert into dms_plan_maint_detail
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -176,4 +176,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
x.maint_station_id = #{stationId}
</select>
<!-- 查询保养计划下的所有设备ID列表 -->
<select id="selectDeviceIdsByPlanId" resultType="java.lang.Long">
SELECT device_id
FROM dms_plan_maint_detail
WHERE plan_maint_id = #{planMaintId}
</select>
</mapper>

@ -46,7 +46,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectDmsPlanMaintVo">
select plan_maint_id, plan_maint_code, maint_level, maint_group, maint_supervisor, maint_time,job_id,time_limit, cycle_period, maint_status, create_method, is_flag, remark, create_by, create_time, update_by, update_time from dms_plan_maint
select plan_maint_id, plan_maint_code, maint_level, maint_group, maint_supervisor, maint_time,job_id,time_limit, cycle_period, maint_status, create_method, is_flag, remark, create_by, create_time, update_by, update_time, cron_expression from dms_plan_maint
</sql>
<select id="selectDmsPlanMaintList" parameterType="DmsPlanMaint" resultMap="DmsPlanMaintResult">
@ -67,8 +67,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectDmsPlanMaintByPlanMaintId" parameterType="Long" resultMap="DmsPlanMaintDmsPlanMaintDetailResult">
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group, a.maint_supervisor, a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status, a.create_method, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
b.plan_maint_detail_id as sub_plan_maint_detail_id, b.plan_maint_id as sub_plan_maint_id, b.OBJ_ID as sub_device_id, b.maint_station_id as sub_maint_station_id, b.maint_standard_id as sub_maint_protocol, b.operation_description as sub_operation_description, b.is_flag as sub_is_flag, b.remark as sub_remark, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group, a.maint_supervisor,
a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status, a.create_method, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time, a.cron_expression,
b.plan_maint_detail_id as sub_plan_maint_detail_id,
b.plan_maint_id as sub_plan_maint_id, b.device_id as sub_device_id,
b.maint_station_id as sub_maint_station_id, b.maint_standard_id as sub_maint_standard_id,
b.operation_description as sub_operation_description, b.is_flag as sub_is_flag,
b.remark as sub_remark, b.create_by as sub_create_by, b.create_time as sub_create_time,
b.update_by as sub_update_by, b.update_time as sub_update_time
from dms_plan_maint a
left join dms_plan_maint_detail b on b.plan_maint_id = a.plan_maint_id
where a.plan_maint_id = #{planMaintId}
@ -76,7 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsPlanMaint" parameterType="DmsPlanMaint">
<selectKey keyProperty="planMaintId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_PLAN_MAINT.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_PLAN_MAINT.NEXTVAL FROM DUAL
</selectKey>
insert into dms_plan_maint
<trim prefix="(" suffix=")" suffixOverrides=",">
@ -97,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="planMaintId != null">#{planMaintId,jdbcType=NUMERIC},</if>
@ -116,6 +123,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="cronExpression != null and cronExpression != ''">#{cronExpression},</if>
</trim>
</insert>
@ -138,6 +146,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="cronExpression != null and cronExpression != ''">cron_expression = #{cronExpression},</if>
</trim>
where plan_maint_id = #{planMaintId}
</update>
@ -165,7 +174,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</delete>
<insert id="batchDmsPlanMaintDetail">
insert into dms_plan_maint_detail( plan_maint_detail_id, plan_maint_id, device_id, maint_station_id, maint_protocol, operation_description, is_flag, remark, create_by, create_time, update_by, update_time) values
insert into dms_plan_maint_detail( plan_maint_detail_id, plan_maint_id,
device_id, maint_station_id, maint_protocol, operation_description, is_flag, remark,
create_by, create_time, update_by, update_time) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.planMaintDetailId}, #{item.planMaintId}, #{item.deviceId}, #{item.maintStationId}, #{item.maintProtocol}, #{item.operationDescription}, #{item.isFlag}, #{item.remark}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime})
</foreach>
@ -176,8 +187,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectDmsPlanMaintJoinByPlanMaintCode" parameterType="String" resultMap="DmsPlanMaintDmsPlanMaintDetailResult">
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group, a.maint_supervisor, a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status, a.create_method, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
b.plan_maint_detail_id as sub_plan_maint_detail_id, b.plan_maint_id as sub_plan_maint_id, b.OBJ_ID as sub_device_id, b.maint_station_id as sub_maint_station_id, b.maint_standard_id as sub_maint_standard_id, b.operation_description as sub_operation_description, b.is_flag as sub_is_flag, b.remark as sub_remark, b.create_by as sub_create_by, b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group,
a.maint_supervisor, a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status, a.create_method,
a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time, a.cron_expression,
b.plan_maint_detail_id as sub_plan_maint_detail_id, b.plan_maint_id as sub_plan_maint_id,
b.device_id as sub_device_id, b.maint_station_id as sub_maint_station_id,
b.maint_standard_id as sub_maint_standard_id, b.operation_description as sub_operation_description,
b.is_flag as sub_is_flag, b.remark as sub_remark, b.create_by as sub_create_by,
b.create_time as sub_create_time, b.update_by as sub_update_by, b.update_time as sub_update_time
from dms_plan_maint a
left join dms_plan_maint_detail b on b.plan_maint_id = a.plan_maint_id
where a.plan_maint_code = #{planMaintCode}
@ -185,11 +202,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectPlanMaintJoinJobByPlanMaintId" parameterType="Long" resultMap="DmsPlanMaintResult">
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group, a.maint_supervisor, a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status, a.create_method, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
sj.cron_expression
select a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group,
a.maint_supervisor, a.maint_time,a.time_limit,a.job_id, a.cycle_period, a.maint_status,
a.create_method, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
a.cron_expression
from dms_plan_maint a
left join sys_job sj on a.job_id = sj.job_id
where a.plan_maint_id = #{planMaintId}
</select>
<!-- 查询待执行的保养计划列表 -->
<select id="selectPendingMaintPlans" resultMap="DmsPlanMaintResult">
SELECT a.plan_maint_id, a.plan_maint_code, a.maint_level, a.maint_group,
a.maint_supervisor, a.maint_time, a.time_limit, a.job_id,
a.cycle_period, a.maint_status, a.create_method, a.is_flag,
a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
a.cron_expression
FROM dms_plan_maint a
WHERE (a.is_flag = 0 OR a.is_flag IS NULL)
AND a.maint_time &lt;= TRUNC(SYSDATE) + 1
</select>
<!-- 更新保养计划的下次执行时间 -->
<update id="updatePlanNextTime">
UPDATE dms_plan_maint
SET maint_time = #{maintTime}, update_time = SYSDATE
WHERE plan_maint_id = #{planMaintId}
</update>
</mapper>

@ -71,7 +71,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertDmsPlanRepair" parameterType="DmsPlanRepair">
<selectKey keyProperty="planRepairId" resultType="long" order="BEFORE">
SELECT SEQ_DMS_PLAN_REPAIR.NEXTVAL FROM DUAL
SELECT HAIWEI.SEQ_DMS_PLAN_REPAIR.NEXTVAL FROM DUAL
</selectKey>
insert into dms_plan_repair
<trim prefix="(" suffix=")" suffixOverrides=",">

Loading…
Cancel
Save