|
|
@@ -0,0 +1,206 @@
|
|
|
+package com.github.zuihou.node;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.github.zuihou.base.R;
|
|
|
+import com.github.zuihou.business.edgeLibrary.dao.StockInfoMapper;
|
|
|
+import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.dao.TaskNodeMapper;
|
|
|
+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.BomProcedureTray;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureTrayService;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.Productionresource;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
|
|
|
+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 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.Collections;
|
|
|
+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 StockInfoTest {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionresourceBizMapper productionresourceBizMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionresourcePositionMapper productionresourcePositionMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomProcedureTrayService procedureTrayService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockInfoMapper stockInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskNodeService taskNodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskNodeMapper taskNodeMapper;
|
|
|
+
|
|
|
+ @Before
|
|
|
+ public void setTenant() {
|
|
|
+ BaseContextHandler.setUserId(3L);
|
|
|
+ BaseContextHandler.setTenant("0000");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void test() {
|
|
|
+ TTask task = taskService.getById("1601028032724729857");
|
|
|
+ List<StockInfo> returnList = null;
|
|
|
+ List<StockInfo> oneTray = null;
|
|
|
+
|
|
|
+ List<Productionresource> productionresources = productionresourceBizMapper.selectList(Wraps.<Productionresource>lbQ().like(Productionresource::getCode, DictionaryKey.YJ_ZONE_XBK.get("plateAndClamp")));
|
|
|
+ List<Long> productionresourceIds = productionresources.stream().map(t->t.getId()).collect(Collectors.toList());
|
|
|
+ List<ProductionresourcePosition> startProductionresourcePositions = productionresourcePositionMapper.selectList(Wraps.<ProductionresourcePosition>lbQ().in(ProductionresourcePosition::getResourceId, productionresourceIds).eq(ProductionresourcePosition::getStatus,"0"));
|
|
|
+ List<Long> startProductionresourcePositionIds = startProductionresourcePositions.stream().map(t->t.getStorgeId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<BomProcedureTray>trayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().in(BomProcedureTray::getProcedureId, task.getProcedureId()));
|
|
|
+ List<Long>trayIdList = trayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
|
|
|
+ // 判断夹具是否有可用的,查询330个库位信息中是否还有夹具
|
|
|
+
|
|
|
+ List<StockInfo> allStockInfos = stockInfoMapper.selectList(Wraps.<StockInfo>lbQ().in(StockInfo::getGoodsId,trayIdList).in(StockInfo::getStorgeId,startProductionresourcePositionIds).orderByAsc(StockInfo::getWeight, StockInfo::getStorgeId));
|
|
|
+ if(CollectionUtil.isNotEmpty(allStockInfos)) {
|
|
|
+ //List<StockInfo> stockInfoList = stockInfoMapper.selectList(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, allStockList.get(0).getStorgeId()));
|
|
|
+ //List<StockInfo> allStockInfos = stockInfoMapper.selectList(Wraps.<StockInfo>lbQ().in(StockInfo::getStorgeId,allStockList.get(0).getStorgeId()).orderByAsc(StockInfo::getGoodsType));
|
|
|
+ if(allStockInfos.size() == 2){
|
|
|
+ boolean bool = allStockInfos.get(0).getStorgeId().equals(allStockInfos.get(1).getStorgeId());
|
|
|
+ if(bool){
|
|
|
+ returnList = allStockInfos;
|
|
|
+ }else{
|
|
|
+ returnList = stockInfoMapper.selectList(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, allStockInfos.get(1).getStorgeId()));
|
|
|
+ }
|
|
|
+ }else if(allStockInfos.size() == 1){
|
|
|
+ if(allStockInfos.get(0).getGoodsType().equals("2")){
|
|
|
+ returnList = stockInfoMapper.selectList(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, allStockInfos.get(0).getStorgeId()));;
|
|
|
+ }else{
|
|
|
+ returnList = allStockInfos;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ if(CollectionUtil.isNotEmpty(allStockList)){
|
|
|
+ Map<Long,List<StockInfo>>map = allStockList.stream().collect(groupingBy(StockInfo::getStorgeId));
|
|
|
+ Long k = null;
|
|
|
+ for(Long key:map.keySet()){
|
|
|
+ k = key;
|
|
|
+ //优先有托盘夹具的
|
|
|
+ List<StockInfo> stockInfoList = map.get(key);
|
|
|
+ if(stockInfoList!=null && stockInfoList.size()>0){
|
|
|
+ List<StockInfo> allStockInfos = stockInfoMapper.selectList(Wraps.<StockInfo>lbQ().in(StockInfo::getStorgeId,stockInfoList.get(0).getStorgeId()).orderByAsc(StockInfo::getGoodsType));
|
|
|
+ if(allStockInfos.size() == 2){
|
|
|
+ boolean bool = allStockInfos.get(0).getStorgeId().equals(allStockInfos.get(1).getStorgeId());
|
|
|
+ if(bool){
|
|
|
+ returnList = stockInfoList;
|
|
|
+ }else{
|
|
|
+ returnList = stockInfoMapper.selectList(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, allStockInfos.get(1).getStorgeId()));
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }else if(allStockInfos.size() == 1){
|
|
|
+ if(allStockInfos.get(0).getGoodsType().equals("2")){
|
|
|
+ oneTray = stockInfoMapper.selectList(new LbqWrapper<StockInfo>().eq(StockInfo::getStorgeId, allStockInfos.get(0).getStorgeId()));;
|
|
|
+ }else{
|
|
|
+ oneTray = stockInfoList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //只有托盘的
|
|
|
+ if(returnList == null){
|
|
|
+ returnList = oneTray;
|
|
|
+ } */
|
|
|
+ returnList.stream().forEach(System.out::println);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ @Test
|
|
|
+ public void test2(){
|
|
|
+ TaskNode hisTask = taskNodeService.getById("1598617863466070021");
|
|
|
+
|
|
|
+ List<BomProcedureTray>trayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().eq(BomProcedureTray::getProcedureId, hisTask.getProcedureId()));
|
|
|
+ List<Long> trayIdList = trayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ TaskNode beforeNode = taskNodeService.getNextNTaskNode(hisTask, (hisTask.getCompleteBatchSort()-1)*(-1));
|
|
|
+ List<BomProcedureTray> oldTrayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().eq(BomProcedureTray::getProcedureId, beforeNode.getProcedureId()));
|
|
|
+ List<Long> oldTrayIdList = oldTrayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ System.out.println(CollectionUtil.join(trayIdList,"").toString());
|
|
|
+ System.out.println(CollectionUtil.join(oldTrayIdList,"").toString());
|
|
|
+ if(CollectionUtil.join(trayIdList,"").toString().equals(CollectionUtil.join(oldTrayIdList,"").toString())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<TaskNode> allNodes = this.getFanManNodes(hisTask);
|
|
|
+ allNodes.stream().forEach(System.out::println);
|
|
|
+
|
|
|
+ /*
|
|
|
+ List<TaskNode> taskNodeList = taskNodeMapper.selectList(Wraps.<TaskNode>lbQ().eq(TaskNode::getCompleteBatchNo, hisTask.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort));
|
|
|
+ TaskNode firstTaskNode = taskNodeList.get(0);
|
|
|
+ List<BomProcedureTray> firsttrayList = procedureTrayService.list(Wraps.<BomProcedureTray>lbQ().in(BomProcedureTray::getProcedureId, firstTaskNode.getProcedureId()));
|
|
|
+ List<Long> firsttrayIdList = firsttrayList.stream().map(t->t.getTrayId()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //判断翻面得托盘工装和翻面前得是否一致
|
|
|
+ if(containAll(trayIdList,firsttrayIdList)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } */
|
|
|
+
|
|
|
+ private List<TaskNode> getFanManNodes(TaskNode taskNode) {
|
|
|
+ List<TaskNode> headNodes = new ArrayList<TaskNode>();
|
|
|
+ List<TaskNode> tailNodes = new ArrayList<TaskNode>();
|
|
|
+ //获取最终回立库的两个节点
|
|
|
+ List<TaskNode> backStockNodes = taskNodeService.list(new LbqWrapper<TaskNode>().gt(TaskNode::getCompleteBatchSort,
|
|
|
+ taskNode.getCompleteBatchSort()).eq(TaskNode::getCompleteBatchNo, taskNode.getCompleteBatchNo()).orderByDesc(TaskNode::getCompleteBatchSort).last("limit 2"));
|
|
|
+
|
|
|
+ Collections.reverse(backStockNodes);
|
|
|
+ backStockNodes.stream().forEach(node -> {
|
|
|
+ TaskNode backNode = new TaskNode();
|
|
|
+ BeanUtil.copyProperties(node, backNode, "id");
|
|
|
+ backNode.setProcedureId(taskNode.getProcedureId()).setTaskId(taskNode.getTaskId()).setNodeType("4");
|
|
|
+ tailNodes.add(backNode);
|
|
|
+ });
|
|
|
+
|
|
|
+ //重建最初获取工装节点
|
|
|
+ List<TaskNode> switchNodes = taskNodeService.list(new LbqWrapper<TaskNode>().lt(TaskNode::getCompleteBatchSort,
|
|
|
+ taskNode.getCompleteBatchSort()).eq(TaskNode::getCompleteBatchNo, taskNode.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort).last("limit 3"));
|
|
|
+ switchNodes.stream().forEach(node -> {
|
|
|
+ TaskNode headNode = new TaskNode();
|
|
|
+ BeanUtil.copyProperties(node, headNode, "id");
|
|
|
+ headNode.setProcedureId(taskNode.getProcedureId()).setTaskId(taskNode.getTaskId()).setExeStatus("1").setExeResult(null).setStartTime(null).setEndTime(null).setFeedback("");
|
|
|
+ if(!headNode.getNodeType().equals("1")){
|
|
|
+ headNode.setNodeType("4");
|
|
|
+ }
|
|
|
+ headNodes.add(headNode);
|
|
|
+ });
|
|
|
+
|
|
|
+ tailNodes.addAll(headNodes);
|
|
|
+ for (int count = 0; count < tailNodes.size(); count++) {
|
|
|
+ tailNodes.get(count).setCompleteBatchSort(taskNode.getCompleteBatchSort() + (count + 1)).setPrority(count + 2).setTaskNodeNo(taskNode.getTaskNodeNo() + "_" + (count + 1));
|
|
|
+ }
|
|
|
+ return tailNodes;
|
|
|
+ }
|
|
|
+}
|