|
@@ -0,0 +1,204 @@
|
|
|
|
|
+package com.github.zuihou;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import com.github.zuihou.business.operationManagementCenter.entity.TTask;
|
|
|
|
|
+import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
|
|
|
|
|
+import com.github.zuihou.business.operationManagementCenter.service.TaskNodeService;
|
|
|
|
|
+import com.github.zuihou.business.operationManagementCenter.service.TaskService;
|
|
|
|
|
+import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
|
|
|
|
|
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
|
|
|
|
|
+import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
|
|
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.Productionresource;
|
|
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
|
|
|
|
|
+import com.github.zuihou.business.productionResourceCenter.service.ResourceAutoCodeService;
|
|
|
|
|
+import com.github.zuihou.business.util.CommonUtil;
|
|
|
|
|
+import com.github.zuihou.common.constant.CodeRuleModule;
|
|
|
|
|
+import com.github.zuihou.common.constant.DictionaryKey;
|
|
|
|
|
+import com.github.zuihou.context.BaseContextHandler;
|
|
|
|
|
+import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
|
|
|
+import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
|
|
+import com.github.zuihou.tenant.service.CodeRuleService;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.junit.Before;
|
|
|
|
|
+import org.junit.Test;
|
|
|
|
|
+import org.junit.runner.RunWith;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+import static java.util.stream.Collectors.groupingBy;
|
|
|
|
|
+
|
|
|
|
|
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
|
|
|
+@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+public class DyTaskNode {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TaskService taskService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private BomProcedureService bomProcedureService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ResourceAutoCodeService resourceAutoCodeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CodeRuleService codeRuleService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProductionresourceBizMapper productionresourceBizMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private TaskNodeService taskNodeService;
|
|
|
|
|
+
|
|
|
|
|
+ @Before
|
|
|
|
|
+ public void setTenant() {
|
|
|
|
|
+ BaseContextHandler.setUserId(3L);
|
|
|
|
|
+ BaseContextHandler.setTenant("0000");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private Long getResourceIdByAutoCode(String resourceType) {
|
|
|
|
|
+ String robotName = DictionaryKey.YJ_ROBOT_NODES.get(resourceType);
|
|
|
|
|
+ //String robotName = DictionaryKey.LINE_ROBOT_NODES.get(resourceType);
|
|
|
|
|
+ Productionresource productionresource =
|
|
|
|
|
+ productionresourceBizMapper.selectOne(new LbqWrapper<Productionresource>().eq(Productionresource::getName,
|
|
|
|
|
+ robotName));
|
|
|
|
|
+ return productionresource.getId();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Test
|
|
|
|
|
+ public void createNode(){
|
|
|
|
|
+ /*
|
|
|
|
|
+ String[] ids = {"1623916114629099520","1623916114633293824","1623916114645876736","1623916114687819776","1623916114687819779","1623916114700402688","1623916114738151424","1623916114738151427","1623916114750734336"};
|
|
|
|
|
+
|
|
|
|
|
+ List<TTask> taskList = taskService.list(new LbqWrapper<TTask>().in(TTask::getId, ids).orderByDesc(TTask::getPrority));
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, List<TTask>> taskMap = taskList.stream().collect(groupingBy(TTask::getCompleteBatchNo));
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> procedureList = taskList.stream().map(p -> p.getProcedureId()).collect(Collectors.toList());
|
|
|
|
|
+ List<BomProcedure> bomProcedureList =
|
|
|
|
|
+ bomProcedureService.list(Wraps.<BomProcedure>lbQ().in(BomProcedure::getId, procedureList));
|
|
|
|
|
+
|
|
|
|
|
+ Map<Long, BomProcedure> bpMap = bomProcedureList.stream().collect(Collectors.toMap(BomProcedure::getId,
|
|
|
|
|
+ t -> t));
|
|
|
|
|
+
|
|
|
|
|
+ List<ResourceAutoCode> resourceAutoCodeList =
|
|
|
|
|
+ resourceAutoCodeService.list(Wraps.<ResourceAutoCode>lbQ().orderByAsc(ResourceAutoCode::getWeight));
|
|
|
|
|
+ Map<Long, List<ResourceAutoCode>> resourceAutoCodeMap =
|
|
|
|
|
+ resourceAutoCodeList.stream().collect(groupingBy(ResourceAutoCode::getBusinessId));
|
|
|
|
|
+
|
|
|
|
|
+ List<TaskNode> taskNodeList = new ArrayList<TaskNode>();
|
|
|
|
|
+
|
|
|
|
|
+ for (String key : taskMap.keySet()) {
|
|
|
|
|
+ int i = 1;
|
|
|
|
|
+ for (TTask t : taskList) {
|
|
|
|
|
+ //taskList里面包含了所有的一次勾选的所有任务
|
|
|
|
|
+ if (!key.equals(t.getCompleteBatchNo())) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //取出resrouceId
|
|
|
|
|
+ Long resourceBusinessId = t.getResourceBusinessId();
|
|
|
|
|
+ List<ResourceAutoCode> autoCodeList = resourceAutoCodeMap.get(resourceBusinessId);
|
|
|
|
|
+
|
|
|
|
|
+ //查询所有的父节点
|
|
|
|
|
+ List<ResourceAutoCode> parentResourceAutoCodeList =
|
|
|
|
|
+ autoCodeList.stream().filter(a -> a.getParentId().longValue() == 0L).collect(Collectors.toList());
|
|
|
|
|
+// for (ResourceAutoCode pautoCode : parentResourceAutoCodeList) {//父节点
|
|
|
|
|
+ for (int parentCount = 0; parentCount < parentResourceAutoCodeList.size(); parentCount++) { //父节点
|
|
|
|
|
+ ResourceAutoCode pautoCode = parentResourceAutoCodeList.get(parentCount);
|
|
|
|
|
+ List<ResourceAutoCode> childResourceAutoCodeList =
|
|
|
|
|
+ autoCodeList.stream().filter(a -> pautoCode.getId().toString().equals(a.getParentId().toString())).collect(Collectors.toList());
|
|
|
|
|
+ List<ResourceAutoCode> agvlist =
|
|
|
|
|
+ childResourceAutoCodeList.stream().filter(a -> "2".equals(a.getCategory())).collect(Collectors.toList());
|
|
|
|
|
+ for (int count = 0; count < childResourceAutoCodeList.size(); count++) { //子节点
|
|
|
|
|
+ ResourceAutoCode autoCode = childResourceAutoCodeList.get(count);
|
|
|
|
|
+ ResourceAutoCode nextAutoCode = null;
|
|
|
|
|
+ if (count < childResourceAutoCodeList.size() - 1) {
|
|
|
|
|
+ nextAutoCode = childResourceAutoCodeList.get(count + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ TaskNode taskNode = new TaskNode();
|
|
|
|
|
+ // 包含agv动作
|
|
|
|
|
+ if (count == 0 && agvlist.size() > 0) {
|
|
|
|
|
+ taskNode.setFindAgvFlag("1");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ taskNode.setFindAgvFlag("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ taskNode.setTaskId(t.getId()).setOrderId(t.getOrderId())
|
|
|
|
|
+ .setTaskNodeNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_TASK_NODE));
|
|
|
|
|
+ taskNode.setAutoNode(autoCode).setNodeNo(autoCode.getNo()).setCompleteBatchNo(t.getCompleteBatchNo())
|
|
|
|
|
+ .setExeStatus("1").setPrority(autoCode.getWeight()).setNodeName(autoCode.getName()).setProcedureId(t.getProcedureId());
|
|
|
|
|
+
|
|
|
|
|
+ String taskType = bpMap.get(t.getProcedureId()).getType();
|
|
|
|
|
+ //依据设备类型判断调用接口类型
|
|
|
|
|
+ if ("1".equals(taskNode.getAutoNode().getCategory())) {
|
|
|
|
|
+ taskNode.setInterfaceType(DictionaryKey.INTERFACETYPE_PLC);
|
|
|
|
|
+ //加工设备的设备ID来源于加工任务设备
|
|
|
|
|
+ taskNode.setResourceId(t.getResourceId());
|
|
|
|
|
+ taskNode.setTargetResourceId(t.getResourceId());
|
|
|
|
|
+ } else if ("3".equals(taskNode.getAutoNode().getCategory())) {
|
|
|
|
|
+ String command = autoCode.getCommand();
|
|
|
|
|
+ taskNode.setInterfaceType(DictionaryKey.INTERFACETYPE_PLC);
|
|
|
|
|
+ //根据配置确定操作设备ID
|
|
|
|
|
+ //String resourceType = autoCode.getResourceId()!=null? autoCode.getResourceId().toString
|
|
|
|
|
+ // () : null;
|
|
|
|
|
+ // 放,判断后一个动作节点是否是agv搬运,如果是,这个targetResourceId设置成空
|
|
|
|
|
+ if ("2".equals(command)) {
|
|
|
|
|
+ // 最后一个节点
|
|
|
|
|
+ if (count == childResourceAutoCodeList.size() - 1) {
|
|
|
|
|
+ taskNode.setTargetResourceId(t.getResourceId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ if (null == nextAutoCode.getResourceId()) {
|
|
|
|
|
+ taskNode.setTargetResourceId(null);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (null != autoCode.getResourceId()) {
|
|
|
|
|
+ taskNode.setResourceId(getResourceIdByAutoCode(autoCode.getResourceId().toString()));
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("2".equals(taskNode.getAutoNode().getCategory())) {
|
|
|
|
|
+ taskNode.setInterfaceType(DictionaryKey.INTERFACETYPE_AGV);
|
|
|
|
|
+ } else if ("4".equals(taskNode.getAutoNode().getCategory())) {
|
|
|
|
|
+ taskNode.setInterfaceType(DictionaryKey.INTERFACETYPE_WMS);
|
|
|
|
|
+
|
|
|
|
|
+ if (taskType.contains("上料") || taskType.contains("换料")) {
|
|
|
|
|
+ taskNode.setNodeType("1");
|
|
|
|
|
+ taskNode.setResourceId(t.getResourceId());
|
|
|
|
|
+ } else if (taskType.contains("下料")) {
|
|
|
|
|
+ taskNode.setNodeType("2");
|
|
|
|
|
+ taskNode.setResourceId(t.getResourceId());
|
|
|
|
|
+ } else if (taskType.contains("翻面")) {
|
|
|
|
|
+ taskNode.setNodeType("4");
|
|
|
|
|
+ taskNode.setResourceId(t.getResourceId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ taskNode.setNodeType("0");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ taskNode.setCompleteBatchSort(i);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ taskNodeList.add(taskNode);
|
|
|
|
|
+ i++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ //批量更新操作
|
|
|
|
|
+ //taskNodeService.saveOrUpdateBatch(taskNodeList);
|
|
|
|
|
+ taskNodeList.stream().forEach(item->System.out.println(item));
|
|
|
|
|
+ taskNodeService.saveOrUpdateBatch(taskNodeList); */
|
|
|
|
|
+ //taskNodeService.
|
|
|
|
|
+ TaskNode taskNode = taskNodeService.getById(1635272408348585995L);
|
|
|
|
|
+ List<TaskNode> taskNodeList = taskNodeService.getFanManNodes(taskNode, "3");
|
|
|
|
|
+ taskNodeList.stream().forEach(item->{
|
|
|
|
|
+ System.out.println(item.toString());
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+}
|