巡检计划定时任务补充(未完成)

dev2.0
anthonywj 2 years ago
parent ba5731260b
commit e16a34bc39

@ -1,6 +1,7 @@
package com.glxp.api.dao.inv;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.glxp.api.dao.BaseMapperPlus;
import com.glxp.api.entity.inv.DeviceInspectPlanEntity;
import com.glxp.api.req.inv.FilterDeviceInspectPlanRequest;
import com.glxp.api.res.inv.DeviceInspectPlanResponse;
@ -11,7 +12,7 @@ import java.util.List;
/**
* Dao
*/
public interface DeviceInspectPlanDao extends BaseMapper<DeviceInspectPlanEntity> {
public interface DeviceInspectPlanDao extends BaseMapperPlus<DeviceInspectPlanDao, DeviceInspectPlanEntity, DeviceInspectPlanEntity> {
/**
*
@ -28,4 +29,4 @@ public interface DeviceInspectPlanDao extends BaseMapper<DeviceInspectPlanEntity
* @return
*/
List<DeviceInspectPlanResponse> filterList(FilterDeviceInspectPlanRequest filterDeviceInspectPlanRequest);
}
}

@ -126,4 +126,9 @@ public class DeviceInspectPlanEntity {
private Date nextTime;
/**
* 使
*/
private Integer useFrequency;
}

@ -53,7 +53,7 @@ public interface DeviceInspectPlanService {
* @param status
* @return
*/
BaseResponse updateStatus(String orderId, Integer status, String inspectUser, Date expectedTime,Integer planStatus);
BaseResponse updateStatus(String orderId, Integer status, String inspectUser, Date expectedTime, Integer planStatus);
/**
*
@ -63,4 +63,7 @@ public interface DeviceInspectPlanService {
*/
BaseResponse deletePlan(String id);
void genTaskDev(DeviceInspectPlanEntity deviceInspectPlanEntity);
}

@ -107,7 +107,7 @@ public class DeviceInspectPlanServiceImpl implements DeviceInspectPlanService {
}
@Override
public BaseResponse updateStatus(String orderId, Integer status, String inspectUser,Date expectedTime,Integer planStatus) {
public BaseResponse updateStatus(String orderId, Integer status, String inspectUser, Date expectedTime, Integer planStatus) {
if (StrUtil.isBlank(orderId) || null == status) {
return ResultVOUtils.paramVerifyFail();
}
@ -122,7 +122,7 @@ public class DeviceInspectPlanServiceImpl implements DeviceInspectPlanService {
// //审核通过,生成任务单
// deviceInspectOrderService.addByPlanOrderId(orderId);
//生成计划主表
DeviceInspectTaskEntity deviceInspectTaskEntity = getDeviceInspectTaskEntity(orderId,expectedTime);
DeviceInspectTaskEntity deviceInspectTaskEntity = getDeviceInspectTaskEntity(orderId, expectedTime);
//生成计划详情主表
getDeviceInspectTaskDetailEntity(orderId, deviceInspectTaskEntity.getOrderId());
}
@ -139,8 +139,16 @@ public class DeviceInspectPlanServiceImpl implements DeviceInspectPlanService {
return ResultVOUtils.success();
}
@Override
public void genTaskDev(DeviceInspectPlanEntity deviceInspectPlanEntity) {
//生成计划主表
DeviceInspectTaskEntity deviceInspectTaskEntity = getDeviceInspectTaskEntity(deviceInspectPlanEntity.getOrderId(), null);
//生成计划详情主表
getDeviceInspectTaskDetailEntity(deviceInspectPlanEntity.getOrderId(), deviceInspectTaskEntity.getOrderId());
}
//组装任务实体
public DeviceInspectTaskEntity getDeviceInspectTaskEntity(String orderId,Date expectedTime) {
public DeviceInspectTaskEntity getDeviceInspectTaskEntity(String orderId, Date expectedTime) {
//查询计划单
DeviceInspectPlanEntity deviceInspectPlanEntity = deviceInspectPlanDao.selectByOrderId(orderId);
if (deviceInspectPlanEntity == null) {

@ -0,0 +1,122 @@
package com.glxp.api.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.glxp.api.dao.inv.DeviceInspectPlanDao;
import com.glxp.api.dao.schedule.ScheduledDao;
import com.glxp.api.entity.inv.DeviceInspectPlanEntity;
import com.glxp.api.entity.system.ScheduledEntity;
import com.glxp.api.req.system.ScheduledRequest;
import com.glxp.api.service.inv.DeviceInspectPlanService;
import com.glxp.api.util.IntUtil;
import com.glxp.api.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
@Slf4j
@Component
@EnableScheduling
public class DevicePlanTask implements SchedulingConfigurer {
@Resource
private ScheduledDao scheduledDao;
@Resource
RedisUtil redisUtil;
@Resource
private DeviceInspectPlanService deviceInspectPlanService;
@Resource
private DeviceInspectPlanDao deviceInspectPlanDao;
@Override
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
scheduledTaskRegistrar.addTriggerTask(() -> process(),
triggerContext -> {
ScheduledRequest scheduledRequest = new ScheduledRequest();
scheduledRequest.setCronName("devPlanTask");
ScheduledEntity scheduledEntity = scheduledDao.findScheduled(scheduledRequest);
if (scheduledEntity == null)
return null;
String cron = scheduledEntity.getCron();
if (cron.isEmpty()) {
log.error("cron is null");
}
return new CronTrigger(cron).nextExecutionTime(triggerContext);
});
}
private void process() {
//查询已运行巡检计划
List<DeviceInspectPlanEntity> deviceInspectTaskEntities =
deviceInspectPlanDao.selectList(new QueryWrapper<DeviceInspectPlanEntity>().eq("planStatus", 2));
if (CollUtil.isNotEmpty(deviceInspectTaskEntities)) {
for (DeviceInspectPlanEntity deviceInspectPlanEntity : deviceInspectTaskEntities) {
//计划已结束
if (deviceInspectPlanEntity.getEndTime().compareTo(new Date()) < 0) {
deviceInspectPlanEntity.setPlanStatus(3);
deviceInspectPlanDao.updateById(deviceInspectPlanEntity);
continue;
}
if (deviceInspectPlanEntity.getLastTime() == null) {
genTask(deviceInspectPlanEntity);
} else if (StrUtil.isNotEmpty(deviceInspectPlanEntity.getFrequency())) {
long time = 0;
//按时间频率生成任务
switch (deviceInspectPlanEntity.getFrequencyUnit()) {
case 1://年
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 365 * 24 * 60 * 60 * 1000 * 1l;
break;
case 2://月
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 30 * 24 * 60 * 60 * 1000 * 1l;
break;
case 3://日
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 24 * 60 * 60 * 1000 * 1l;
break;
case 4://小时
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 60 * 60 * 1000 * 1l;
break;
case 5://分
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 60 * 1000 * 1l;
break;
case 6://秒
time = IntUtil.value(deviceInspectPlanEntity.getFrequency()) * 1000 * 1l;
break;
default:
break;
}
long interval = new Date().getTime() - deviceInspectPlanEntity.getLastTime().getTime();
if (interval > time) {
genTask(deviceInspectPlanEntity);
}
} else if (deviceInspectPlanEntity.getUseFrequency() != null) {
//按使用频率生成任务
}
}
}
}
/**
*
*/
public void genTask(DeviceInspectPlanEntity deviceInspectPlanEntity) {
deviceInspectPlanService.genTaskDev(deviceInspectPlanEntity);
}
}

@ -1,5 +1,7 @@
package com.glxp.api.util;
import cn.hutool.core.util.StrUtil;
public class IntUtil {
public static int value(Integer value) {
@ -23,4 +25,13 @@ public class IntUtil {
else return value;
}
public static int value(String value) {
if (StrUtil.isEmpty(value))
return 0;
else
return Integer.parseInt(value);
}
}

@ -3,7 +3,7 @@
<mapper namespace="com.glxp.api.dao.basic.BasicProductCategoryMapper">
<resultMap id="BaseResultMap" type="com.glxp.api.entity.basic.BasicProductCategory">
<!--@mbg.generated-->
<!--@Table wms_cs.basic_product_category-->
<!--@Table basic_product_category-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="code" jdbcType="VARCHAR" property="code" />
<result column="parentCode" jdbcType="VARCHAR" property="parentCode" />

Loading…
Cancel
Save