|
|
|
@ -3,7 +3,10 @@ package org.dromara.dms.service.impl;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.github.yulichang.toolkit.JoinWrappers;
|
|
|
|
|
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|
|
|
|
import io.seata.spring.annotation.GlobalTransactional;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
|
|
import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.core.utils.uuid.Seq;
|
|
|
|
@ -21,12 +24,20 @@ import org.dromara.dms.utils.CronUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import com.aizuda.snailjob.client.job.core.enums.AllocationAlgorithmEnum;
|
|
|
|
|
import com.aizuda.snailjob.client.job.core.enums.TriggerTypeEnum;
|
|
|
|
|
import com.aizuda.snailjob.client.job.core.openapi.SnailJobOpenApi;
|
|
|
|
|
import com.aizuda.snailjob.common.core.enums.JobBlockStrategyEnum;
|
|
|
|
|
import com.aizuda.snailjob.client.job.core.dto.JobResponseVO;
|
|
|
|
|
import com.aizuda.snailjob.common.core.enums.StatusEnum;
|
|
|
|
|
import org.dromara.job.api.model.DmsJobEntity;
|
|
|
|
|
import org.dromara.job.api.RemoteJobService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 润滑计划Service业务层处理
|
|
|
|
|
*
|
|
|
|
@ -41,6 +52,9 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
|
|
|
|
|
private final DmsBillsLubeInstanceMapper dmsBillsLubeInstanceMapper;
|
|
|
|
|
|
|
|
|
|
@DubboReference
|
|
|
|
|
private final RemoteJobService remoteJobService;
|
|
|
|
|
|
|
|
|
|
private static final Long SECONDS_PER_DAY = 24 * 60 * 60L;
|
|
|
|
|
private static final Long SECONDS_PER_HOUR = 60 * 60L;
|
|
|
|
|
|
|
|
|
@ -160,7 +174,7 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
* @return 是否新增成功
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@GlobalTransactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean insertByBo(DmsPlanLubeBo bo) {
|
|
|
|
|
// 生成新的润滑计划编号
|
|
|
|
|
String planLubeCode = Seq.getId(Seq.dmsPlanLubeSeqType, Seq.dmsPlanLubeCode);
|
|
|
|
@ -179,6 +193,23 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
// 添加任务到远程服务并获取任务ID
|
|
|
|
|
R<Integer> jobIdR = remoteJobService.add(SecurityConstants.INNER, job);*/
|
|
|
|
|
|
|
|
|
|
if(bo.getActiveFlag().equals("1")){//激活标识(1是 0否)
|
|
|
|
|
DmsJobEntity dmsJobEntity = new DmsJobEntity();
|
|
|
|
|
dmsJobEntity.setRouteKey(AllocationAlgorithmEnum.ROUND)//路由策略:轮询
|
|
|
|
|
.setJobName("润滑计划编号" + planLubeCode + "工单任务")
|
|
|
|
|
.setExecutorInfo("stanceLube")//执行器名称
|
|
|
|
|
.setExecutorTimeout(30)//执行超时时间
|
|
|
|
|
.setBlockStrategy(JobBlockStrategyEnum.CONCURRENCY)//阻塞策略:并发
|
|
|
|
|
.setMaxRetryTimes(2)//最大重试次数
|
|
|
|
|
.setTriggerType(TriggerTypeEnum.CRON)//触发器类型:cron
|
|
|
|
|
.setTriggerInterval(bo.getCronExpression())//间隔时长: cron表达式
|
|
|
|
|
.setRetryInterval(3)//重试间隔时长
|
|
|
|
|
.setArgsStr("planLubeCode")
|
|
|
|
|
.setExtAttrs(planLubeCode);
|
|
|
|
|
R<Long> longR = remoteJobService.addClusterJob(dmsJobEntity);
|
|
|
|
|
Long jobId = longR.getData();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 通过cron表达式获取下一次执行时间
|
|
|
|
|
String cronExpression = bo.getCronExpression();
|
|
|
|
|
if (StringUtils.isNotEmpty(cronExpression)) {
|
|
|
|
@ -187,7 +218,9 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置润滑计划的任务ID
|
|
|
|
|
/* bo.setJobId(jobIdR.getData().longValue());*/
|
|
|
|
|
bo.setJobId(jobId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 计算润滑计划的时间限制(天和小时)
|
|
|
|
|
Long timeLimitDays = bo.getTimeLimitDays() == null ? 0L : bo.getTimeLimitDays();
|
|
|
|
@ -214,7 +247,7 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public Boolean updateByBo(DmsPlanLubeBo bo) {
|
|
|
|
|
/* Long jobId = bo.getJobId();*/
|
|
|
|
|
Long jobId = bo.getJobId();
|
|
|
|
|
String cronExpression = bo.getCronExpression();
|
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(cronExpression)) {
|
|
|
|
@ -222,9 +255,9 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
Date nextExecution = CronUtils.getNextExecution(cronExpression);
|
|
|
|
|
bo.setLubeTime(nextExecution);
|
|
|
|
|
|
|
|
|
|
/* if (jobId == null) {
|
|
|
|
|
// 如果没有关联任务,创建新任务
|
|
|
|
|
String planLubeCode = bo.getPlanLubeCode();
|
|
|
|
|
if (bo.getActiveFlag().equals("1")){//激活标识(1是 0否)
|
|
|
|
|
if (jobId == null ) {// 如果没有关联任务,创建新任务
|
|
|
|
|
/* String planLubeCode = bo.getPlanLubeCode();
|
|
|
|
|
SysJob job = new SysJob();
|
|
|
|
|
job.setJobName("润滑计划编号" + planLubeCode + "工单任务");
|
|
|
|
|
job.setJobGroup("DEFAULT");
|
|
|
|
@ -234,15 +267,59 @@ public class DmsPlanLubeServiceImpl implements IDmsPlanLubeService {
|
|
|
|
|
job.setConcurrent("1");
|
|
|
|
|
job.setStatus("1");
|
|
|
|
|
R<Integer> jobIdR = remoteJobService.add(SecurityConstants.INNER, job);
|
|
|
|
|
bo.setJobId(jobIdR.getData().longValue());
|
|
|
|
|
} else {
|
|
|
|
|
// 更新现有任务
|
|
|
|
|
bo.setJobId(jobIdR.getData().longValue());*/
|
|
|
|
|
String planLubeCode = bo.getPlanLubeCode();
|
|
|
|
|
Long newJobId = SnailJobOpenApi.addClusterJob()
|
|
|
|
|
.setRouteKey(AllocationAlgorithmEnum.ROUND)//路由策略:轮询
|
|
|
|
|
.setJobName("润滑计划编号" + planLubeCode + "工单任务")
|
|
|
|
|
.setExecutorInfo("stanceLube")//执行器名称
|
|
|
|
|
.addArgsStr("planLubeCode", planLubeCode)//执行任务参数
|
|
|
|
|
.setExecutorTimeout(30)//执行超时时间
|
|
|
|
|
.setBlockStrategy(JobBlockStrategyEnum.CONCURRENCY)//阻塞策略:并发
|
|
|
|
|
.setMaxRetryTimes(2)//最大重试次数
|
|
|
|
|
.setTriggerType(TriggerTypeEnum.CRON)//触发器类型:cron
|
|
|
|
|
.setTriggerInterval(bo.getCronExpression())//间隔时长: cron表达式
|
|
|
|
|
.setRetryInterval(3)//重试间隔时长
|
|
|
|
|
.execute();
|
|
|
|
|
bo.setJobId(newJobId);
|
|
|
|
|
} else {// 如果有关联任务,更新状态
|
|
|
|
|
/* // 更新现有任务
|
|
|
|
|
SysJob sysJob = remoteJobService.getJobInfo(jobId, SecurityConstants.INNER);
|
|
|
|
|
if (sysJob != null) {
|
|
|
|
|
sysJob.setCronExpression(bo.getCronExpression());
|
|
|
|
|
remoteJobService.update(SecurityConstants.INNER, sysJob);
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
String planLubeCode = bo.getPlanLubeCode();
|
|
|
|
|
JobResponseVO execute = SnailJobOpenApi.getJobDetail(jobId).execute();
|
|
|
|
|
if (execute != null) {
|
|
|
|
|
SnailJobOpenApi
|
|
|
|
|
.updateJobStatus(jobId)
|
|
|
|
|
.setStatus(StatusEnum.YES)
|
|
|
|
|
.execute();
|
|
|
|
|
SnailJobOpenApi.updateClusterJob(jobId)
|
|
|
|
|
.setRouteKey(AllocationAlgorithmEnum.ROUND)//路由策略:轮询
|
|
|
|
|
.setJobName("润滑计划编号" + planLubeCode + "工单任务")
|
|
|
|
|
.setExecutorInfo("stanceLube")//执行器名称
|
|
|
|
|
.addArgsStr("planLubeCode", planLubeCode)//执行任务参数
|
|
|
|
|
.setExecutorTimeout(30)//执行超时时间
|
|
|
|
|
.setBlockStrategy(JobBlockStrategyEnum.CONCURRENCY)//阻塞策略:并发
|
|
|
|
|
.setMaxRetryTimes(2)//最大重试次数
|
|
|
|
|
.setTriggerType(TriggerTypeEnum.CRON)//触发器类型:cron
|
|
|
|
|
.setTriggerInterval(bo.getCronExpression())//间隔时长: cron表达式
|
|
|
|
|
.setRetryInterval(3)//重试间隔时长
|
|
|
|
|
.execute();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}else{//如果激活状态为0(1是 0否)
|
|
|
|
|
if (jobId != null) {//如果关联了任务,则任务状态为关闭
|
|
|
|
|
SnailJobOpenApi
|
|
|
|
|
.updateJobStatus(jobId)
|
|
|
|
|
.setStatus(StatusEnum.NO)//任务状态(0:关闭;1:开启)
|
|
|
|
|
.execute();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算润滑计划的时间限制(天和小时)
|
|
|
|
|