package com.zy.asrs.task;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.exception.CoolException;
|
import com.zy.asrs.domain.enums.TaskStatusType;
|
import com.zy.asrs.entity.LocMast;
|
import com.zy.asrs.entity.TaskWrk;
|
import com.zy.asrs.entity.TaskWrkLog;
|
import com.zy.asrs.service.LocMastService;
|
import com.zy.asrs.service.TaskWrkLogService;
|
import com.zy.asrs.service.TaskWrkService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
@Slf4j
|
@Component
|
public class AgvTaskLogScheduler {
|
|
@Autowired
|
private TaskWrkService taskWrkService;
|
@Autowired
|
private TaskWrkLogService taskWrkLogService;
|
@Autowired
|
private LocMastService locMastService;
|
|
/**
|
* AGV任务转历史
|
*/
|
@Scheduled(cron = "0/3 * * * * ? ")
|
public void execute() {
|
List<TaskWrk> taskWrkList = taskWrkService.selectList(new EntityWrapper<TaskWrk>()
|
.eq("status", TaskStatusType.COMPLETE.id));
|
for (TaskWrk taskWrk : taskWrkList) {
|
Date now = new Date();
|
String originPoint = taskWrk.getStartPoint();
|
String targetPoint = taskWrk.getTargetPoint();
|
LocMast startLocMast = locMastService.selectByLocNo(originPoint);
|
if(startLocMast == null){
|
throw new CoolException("取货点库位不存在");
|
}
|
|
if (!startLocMast.getLocSts().equals("R")) {
|
throw new CoolException("取货点不处于出库预约");
|
}
|
|
LocMast targetLocMast = locMastService.selectByLocNo(targetPoint);
|
if(targetLocMast == null){
|
throw new CoolException("放货点库位不存在");
|
}
|
|
if (!targetLocMast.getLocSts().equals("S")) {
|
throw new CoolException("放货点不处于入库预约");
|
}
|
|
startLocMast.setLocSts("O");
|
startLocMast.setModiTime(now);
|
locMastService.updateById(startLocMast);
|
|
targetLocMast.setLocSts("F");
|
targetLocMast.setModiTime(now);
|
locMastService.updateById(targetLocMast);
|
|
TaskWrkLog taskWrkLog = new TaskWrkLog(taskWrk);
|
if (!taskWrkLogService.insert(taskWrkLog)) {
|
throw new CoolException("转历史档失败" + taskWrkLog);
|
}
|
if (!taskWrkService.deleteById(taskWrk)) {
|
throw new CoolException("任务档删除失败" + taskWrkLog);
|
}
|
}
|
}
|
}
|