8 changed files with 347 additions and 18 deletions
@ -0,0 +1,163 @@ |
|||
package org.nl.system.service.quartz.task; |
|||
|
|||
import cn.hutool.core.date.DateUtil; |
|||
import cn.hutool.core.util.IdUtil; |
|||
import cn.hutool.core.util.StrUtil; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.ObjectUtils; |
|||
import org.nl.acs.common.base.CommonFinalParam; |
|||
import org.nl.acs.device.device.service.DeviceAppService; |
|||
import org.nl.acs.instruction.domain.Instruction; |
|||
import org.nl.acs.instruction.enums.InstructionStatusEnum; |
|||
import org.nl.acs.instruction.service.InstructionService; |
|||
import org.nl.acs.route.service.RouteLineService; |
|||
import org.nl.acs.route.service.dto.RouteLineDto; |
|||
import org.nl.acs.task.enums.InstTypeEnum; |
|||
import org.nl.acs.task.enums.TaskStatusEnum; |
|||
import org.nl.acs.task.enums.TaskTypeEnum; |
|||
import org.nl.acs.task.service.TaskService; |
|||
import org.nl.acs.task.service.dto.TaskDto; |
|||
import org.nl.common.utils.SecurityUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Arrays; |
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 自动创建AGV指令 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
public class AutoCreateYkInst { |
|||
|
|||
@Autowired |
|||
private TaskService taskService; |
|||
@Autowired |
|||
private InstructionService instructionService; |
|||
@Autowired |
|||
private RouteLineService routeLineService; |
|||
@Autowired |
|||
private DeviceAppService deviceAppService; |
|||
|
|||
/** |
|||
* 根据任务状态创建指令、生成下一条指令 |
|||
* 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 |
|||
*/ |
|||
public void run() throws Exception { |
|||
List<TaskDto> list = taskService.findReadyByTaskType(TaskTypeEnum.YK_TASK.getCode()); |
|||
for (int i = 0; i < list.size(); i++) { |
|||
TaskDto acsTask = list.get(i); |
|||
String taskid = acsTask.getTask_id(); |
|||
String taskcode = acsTask.getTask_code(); |
|||
String task_type = acsTask.getTask_type(); |
|||
String vehiclecode = acsTask.getVehicle_code(); |
|||
String storage_task_type = acsTask.getStorage_task_type(); |
|||
String priority = acsTask.getPriority(); |
|||
String is_send = acsTask.getIs_send(); |
|||
|
|||
String start_device_code = acsTask.getStart_device_code(); |
|||
String start_point_code = acsTask.getStart_point_code(); |
|||
|
|||
String put_device_code = acsTask.getPut_device_code(); |
|||
String put_point_code = acsTask.getPut_point_code(); |
|||
|
|||
String next_device_code = acsTask.getNext_device_code(); |
|||
String next_point_code = acsTask.getNext_point_code(); |
|||
|
|||
String start_point_code2 = acsTask.getStart_point_code2(); |
|||
String start_device_code2 = acsTask.getStart_device_code2(); |
|||
|
|||
String next_point_code2 = acsTask.getNext_point_code2(); |
|||
String next_device_code2 = acsTask.getNext_device_code2(); |
|||
|
|||
String route_plan_code = acsTask.getRoute_plan_code(); |
|||
String vehicleType = acsTask.getVehicle_type(); |
|||
String agv_system_type = acsTask.getAgv_system_type(); |
|||
|
|||
String start_height = acsTask.getStart_height(); |
|||
String next_height = acsTask.getNext_height(); |
|||
|
|||
|
|||
if (StrUtil.equals(is_send, "0")) { |
|||
continue; |
|||
} |
|||
|
|||
//校验路由关系
|
|||
List<RouteLineDto> shortPathsList = routeLineService.getShortPathLines(start_device_code, next_device_code, route_plan_code); |
|||
if (ObjectUtils.isEmpty(shortPathsList)) { |
|||
acsTask.setRemark("路由不通无法生成指令"); |
|||
taskService.updateByCodeFromCache(acsTask); |
|||
continue; |
|||
} |
|||
|
|||
if (!StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.ONE) && !StrUtil.equals(shortPathsList.get(0).getType(), CommonFinalParam.TWO)) { |
|||
continue; |
|||
} |
|||
|
|||
RouteLineDto routeLineDto = shortPathsList.get(0); |
|||
String path = routeLineDto.getPath(); |
|||
String type = routeLineDto.getType(); |
|||
String[] str = path.split("->"); |
|||
List<String> pathlist = Arrays.asList(str); |
|||
int index = 0; |
|||
for (int m = 0; m < pathlist.size(); m++) { |
|||
if (pathlist.get(m).equals(start_device_code)) { |
|||
index = m + 1; |
|||
break; |
|||
} |
|||
} |
|||
next_device_code = pathlist.get(index); |
|||
|
|||
if (StrUtil.equals(deviceAppService.findDeviceTypeByCode(next_device_code), "storage")) { |
|||
next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); |
|||
} else { |
|||
next_point_code = next_device_code; |
|||
} |
|||
|
|||
Instruction instdto = new Instruction(); |
|||
instdto.setInstruction_type(InstTypeEnum.STACKER_TASK.getCode()); |
|||
instdto.setInstruction_id(IdUtil.simpleUUID()); |
|||
instdto.setRoute_plan_code(route_plan_code); |
|||
instdto.setRemark(acsTask.getRemark()); |
|||
instdto.setMaterial(acsTask.getMaterial()); |
|||
instdto.setQuantity(acsTask.getQuantity()); |
|||
instdto.setTask_id(taskid); |
|||
instdto.setTask_code(taskcode); |
|||
instdto.setVehicle_code(vehiclecode); |
|||
String now = DateUtil.now(); |
|||
instdto.setCreate_time(now); |
|||
instdto.setCreate_by(SecurityUtils.getCurrentNickName()); |
|||
|
|||
instdto.setStart_device_code(start_device_code); |
|||
instdto.setStart_point_code(start_point_code); |
|||
instdto.setPut_device_code(put_device_code); |
|||
instdto.setPut_point_code(put_point_code); |
|||
instdto.setNext_device_code(next_device_code); |
|||
instdto.setNext_point_code(next_point_code); |
|||
|
|||
instdto.setStart_point_code2(start_point_code2); |
|||
instdto.setStart_device_code2(start_device_code2); |
|||
instdto.setNext_point_code2(next_point_code2); |
|||
instdto.setNext_device_code2(next_device_code2); |
|||
|
|||
instdto.setPriority(priority); |
|||
instdto.setInstruction_status(InstructionStatusEnum.READY.getIndex()); |
|||
instdto.setExecute_device_code(start_point_code); |
|||
instdto.setVehicle_type(vehicleType); |
|||
instdto.setAgv_system_type(agv_system_type); |
|||
instdto.setStart_height(start_height); |
|||
instdto.setNext_height(next_height); |
|||
|
|||
try { |
|||
instructionService.create(instdto); |
|||
} catch (Exception e) { |
|||
acsTask.setRemark("指令创建失败:" + e.getMessage()); |
|||
taskService.updateByCodeFromCache(acsTask); |
|||
} |
|||
//创建指令后修改任务状态
|
|||
acsTask.setTask_status(TaskStatusEnum.BUSY.getIndex()); |
|||
taskService.update(acsTask); |
|||
} |
|||
} |
|||
} |
Loading…
Reference in new issue