|
|
@ -1,12 +1,17 @@ |
|
|
|
package org.nl.modules.quartz.task; |
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil; |
|
|
|
import cn.hutool.core.collection.CollectionUtil; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
import org.nl.acs.device_driver.basedriver.standard_ordinary_site.StandardOrdinarySiteDeviceDriver; |
|
|
|
import org.nl.acs.instruction.service.InstructionService; |
|
|
|
import org.nl.acs.instruction.service.dto.Instruction; |
|
|
|
import org.nl.acs.opc.Device; |
|
|
|
import org.nl.acs.opc.DeviceAppService; |
|
|
|
import org.nl.acs.opc.DeviceAppServiceImpl; |
|
|
|
import org.nl.acs.route.service.RouteLineService; |
|
|
@ -16,8 +21,9 @@ import org.nl.acs.task.service.dto.TaskDto; |
|
|
|
import org.nl.modules.wql.util.SpringContextHolder; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicReference; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
* 自动创建指令 |
|
|
@ -26,6 +32,8 @@ import java.util.List; |
|
|
|
@Component |
|
|
|
public class AutoCreateInst { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 根据任务状态创建指令、生成下一条指令 |
|
|
|
* 创建指令前需要判断是否条件具备:起始位置是否有货、目标位置是否有货 |
|
|
@ -35,13 +43,120 @@ public class AutoCreateInst { |
|
|
|
InstructionService instructionService = SpringContextHolder.getBean(InstructionService.class); |
|
|
|
RouteLineService routeLineService = SpringContextHolder.getBean(RouteLineService.class); |
|
|
|
DeviceAppService appService = SpringContextHolder.getBean(DeviceAppServiceImpl.class); |
|
|
|
|
|
|
|
List<TaskDto> list = taskserver.queryAll("task_status = '0'"); |
|
|
|
List<TaskDto> list = taskserver.queryAll("task_status = '0' ORDER BY create_time ASC"); |
|
|
|
List<TaskDto> list2 = taskserver.queryAll("task_status = '1' ORDER BY create_time ASC"); |
|
|
|
Map<String, List<TaskDto>> collect = list.stream().sorted(Comparator.comparing(TaskDto::getCreate_time)) |
|
|
|
.collect(Collectors.groupingBy(TaskDto::getPriority)); |
|
|
|
TreeMap<String, List<TaskDto>> treeMap = new TreeMap<>(new Comparator<String>() { |
|
|
|
@Override |
|
|
|
public int compare(String o1, String o2) { |
|
|
|
return o2.compareTo(o1); |
|
|
|
} |
|
|
|
}); |
|
|
|
treeMap.putAll(collect); |
|
|
|
for (List<TaskDto> value : treeMap.values()) { |
|
|
|
list = value; |
|
|
|
if(CollUtil.isNotEmpty(list)){ |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
for (int i = 0; i < list.size(); i++) { |
|
|
|
TaskDto acsTask = list.get(i); |
|
|
|
if (StrUtil.equals(acsTask.getTask_type(), "7") && !StrUtil.startWith(acsTask.getTask_code(), "-")) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
Device startDevice = appService.findDeviceByCode(acsTask.getStart_device_code()); |
|
|
|
Device nextDevice = appService.findDeviceByCode(acsTask.getNext_device_code()); |
|
|
|
StandardOrdinarySiteDeviceDriver standardOrdinarySiteDeviceDriver; |
|
|
|
if (i > 0 && acsTask.getTask_type().equals(list.get(i - 1).getTask_type())) { |
|
|
|
if (startDevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
|
|
|
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) startDevice.getDeviceDriver(); |
|
|
|
List<String> link_device_code = standardOrdinarySiteDeviceDriver.getExtraDeviceCodes("link_device_code"); |
|
|
|
Boolean flag = false; |
|
|
|
for (String s : link_device_code) { |
|
|
|
if (s.equals(list.get(i - 1).getStart_device_code())) { |
|
|
|
flag = true; |
|
|
|
log.error("当前任务号{},已创建同列起点导致创建指令失败,起点为{},终点为{}", acsTask.getTask_code(), acsTask.getStart_device_code(), acsTask.getNext_device_code()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag) { |
|
|
|
acsTask.setRemark("同列起点已存在,创建指令失败"); |
|
|
|
taskserver.update(acsTask); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} else if (nextDevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
|
|
|
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextDevice.getDeviceDriver(); |
|
|
|
List<String> link_device_code = standardOrdinarySiteDeviceDriver.getExtraDeviceCodes("link_device_code"); |
|
|
|
Boolean flag = false; |
|
|
|
for (String s : link_device_code) { |
|
|
|
if (s.equals(list.get(i - 1).getNext_device_code())) { |
|
|
|
flag = true; |
|
|
|
log.error("当前任务号{},已创建同列起点导致创建指令失败,起点为{},终点为{}", acsTask.getTask_code(), acsTask.getStart_device_code(), acsTask.getNext_device_code()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag) { |
|
|
|
acsTask.setRemark("同列起点已存在,创建指令失败"); |
|
|
|
taskserver.update(acsTask); |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Boolean flag2 = false; |
|
|
|
if (CollUtil.isNotEmpty(list2)) { |
|
|
|
for (TaskDto taskDto : list2) { |
|
|
|
if (taskDto.getTask_type().equals(acsTask.getTask_type())) { |
|
|
|
if (startDevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
|
|
|
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) startDevice.getDeviceDriver(); |
|
|
|
List<String> link_device_code = standardOrdinarySiteDeviceDriver.getExtraDeviceCodes("link_device_code"); |
|
|
|
Boolean flag = false; |
|
|
|
for (String s : link_device_code) { |
|
|
|
if (s.equals(taskDto.getStart_device_code())) { |
|
|
|
Instruction instruction = instructionService.findByTaskid(taskDto.getTask_id(), "instruction_status < 2"); |
|
|
|
if (ObjectUtil.isEmpty(instruction) || (Integer.parseInt(StrUtil.isNotBlank |
|
|
|
(instruction.getExecute_status()) ? instruction.getExecute_status() : "0") < 2)) { |
|
|
|
flag = true; |
|
|
|
log.error("当前任务号{},已创建同列起点导致创建指令失败,起点为{},终点为{}", acsTask.getTask_code(), acsTask.getStart_device_code(), acsTask.getNext_device_code()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag) { |
|
|
|
acsTask.setRemark("同列起点已存在,创建指令失败"); |
|
|
|
taskserver.update(acsTask); |
|
|
|
flag2 = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} else if (nextDevice.getDeviceDriver() instanceof StandardOrdinarySiteDeviceDriver) { |
|
|
|
standardOrdinarySiteDeviceDriver = (StandardOrdinarySiteDeviceDriver) nextDevice.getDeviceDriver(); |
|
|
|
List<String> link_device_code = standardOrdinarySiteDeviceDriver.getExtraDeviceCodes("link_device_code"); |
|
|
|
Boolean flag = false; |
|
|
|
for (String s : link_device_code) { |
|
|
|
if (s.equals(taskDto.getNext_device_code())) { |
|
|
|
Instruction instruction = instructionService.findByTaskid(taskDto.getTask_id(), "instruction_status < 2"); |
|
|
|
if (ObjectUtil.isEmpty(instruction) || (Integer.parseInt(StrUtil.isNotBlank |
|
|
|
(instruction.getExecute_status()) ? instruction.getExecute_status() : "0") <4)) { |
|
|
|
flag = true; |
|
|
|
log.error("当前任务号{},已创建同列起点导致创建指令失败,起点为{},终点为{}", acsTask.getTask_code(), acsTask.getStart_device_code(), acsTask.getNext_device_code()); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag) { |
|
|
|
acsTask.setRemark("同列起点已存在,创建指令失败"); |
|
|
|
taskserver.update(acsTask); |
|
|
|
flag2 = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (flag2) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
acsTask.setRemark(""); |
|
|
|
String taskid = acsTask.getTask_id(); |
|
|
|
String taskcode = acsTask.getTask_code(); |
|
|
|
String task_type = acsTask.getTask_type(); |
|
|
@ -92,14 +207,14 @@ public class AutoCreateInst { |
|
|
|
String type = routeLineDto.getType(); |
|
|
|
String[] str = path.split("->"); |
|
|
|
List<String> pathlist = Arrays.asList(str); |
|
|
|
int index = 0; |
|
|
|
int index1 = 0; |
|
|
|
for (int m = 0; m < pathlist.size(); m++) { |
|
|
|
if (pathlist.get(m).equals(start_device_code)) { |
|
|
|
index = m + 1; |
|
|
|
index1 = m + 1; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
next_device_code = pathlist.get(index); |
|
|
|
next_device_code = pathlist.get(index1); |
|
|
|
|
|
|
|
if (StrUtil.equals(appService.findDeviceTypeByCode(next_device_code), "storage")) { |
|
|
|
next_point_code = next_device_code + "-" + acsTask.getTo_y() + "-" + acsTask.getTo_z(); |
|
|
@ -151,8 +266,8 @@ public class AutoCreateInst { |
|
|
|
} |
|
|
|
//创建指令后修改任务状态
|
|
|
|
acsTask.setTask_status("1"); |
|
|
|
acsTask.setRemark(""); |
|
|
|
taskserver.update(acsTask); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |