|
|
@@ -0,0 +1,224 @@
|
|
|
+package com.github.zuihou.business.operationManagementCenter.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.github.zuihou.base.service.SuperServiceImpl;
|
|
|
+import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
+import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
|
|
|
+import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
|
+import com.github.zuihou.business.edgeLibrary.service.StockInfoService;
|
|
|
+import com.github.zuihou.business.edgeLibrary.service.StorgeService;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.dao.OrderTaskMapper;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.entity.*;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.service.*;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureProductionresourceService;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.dao.ResourceBusinessMapper;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.entity.ResourceBusiness;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.service.ProductionresourceBizService;
|
|
|
+import com.github.zuihou.business.productionResourceCenter.service.ProductionresourcePositionService;
|
|
|
+import com.github.zuihou.business.util.DynamicRabbitMq;
|
|
|
+import com.github.zuihou.business.util.MsgUtil;
|
|
|
+import com.github.zuihou.common.constant.BizConstant;
|
|
|
+import com.github.zuihou.common.constant.CodeRuleModule;
|
|
|
+import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
+import com.github.zuihou.tenant.service.CodeRuleService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.UUID;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class OrderTaskServiceImpl extends SuperServiceImpl<OrderTaskMapper, OrderTask> implements OrderTaskService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderService orderService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PlanService planService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskService taskService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TaskNodeService taskNodeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StorgeService storgeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionresourceBizService productionresourceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductionresourcePositionService productionresourcePositionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private MsgUtil msgUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DynamicRabbitMq dynamicRabbitMq;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ResourceBusinessMapper resourceBusinessMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private WorkpieceService tWorkpieceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomProcedureProductionresourceService bomProcedureProductionresourceService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CodeRuleService codeRuleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OrderProductService orderProductService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private BomProcedureService bomProcedureService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private StockInfoService stockInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean prodNode(OrderTask orderTask, String planId) {
|
|
|
+
|
|
|
+ //依据配置动态更新节点
|
|
|
+ String[] startNameCondition = orderTask.getStart().split("_");
|
|
|
+ String[] goalNameCondition = orderTask.getGoal().split("_");
|
|
|
+ if(startNameCondition.length != 2 || goalNameCondition.length != 2) return false;
|
|
|
+ Storge startStorge = storgeService.getOne(new LbqWrapper<Storge>().likeLeft(Storge::getNo, startNameCondition[1]).eq(Storge::getPointId, startNameCondition[1]));
|
|
|
+ if(null == startStorge) return false;
|
|
|
+ Storge goalStorge = storgeService.getOne(new LbqWrapper<Storge>().likeLeft(Storge::getNo, goalNameCondition[1]).eq(Storge::getPointId, goalNameCondition[1]));
|
|
|
+
|
|
|
+ Long startResourceId = productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getStorgeId, startStorge.getId()).last("limit 1")).getResourceId();
|
|
|
+ Long endResourceId = (null==goalStorge) ? null : productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getStorgeId, goalStorge.getId()).last("limit 1")).getResourceId();
|
|
|
+
|
|
|
+ if(startNameCondition[0].equals(goalNameCondition[0])){
|
|
|
+ //同产线内简易搬运处理
|
|
|
+ this.inLineHandle(orderTask, startStorge, goalStorge, startNameCondition[0], startResourceId, endResourceId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isOneLine(String startName, String goalName) {
|
|
|
+ String[] startNameCondition = startName.split("_");
|
|
|
+ String[] goalNameCondition = goalName.split("_");
|
|
|
+ if(startNameCondition.length != 2 || goalNameCondition.length != 2) return false;
|
|
|
+ return startNameCondition[0].equals(goalNameCondition[0]);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化简易订单任务
|
|
|
+ *
|
|
|
+ * @param currentSort
|
|
|
+ * @param order
|
|
|
+ * @param resourceBusinessId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ public TTask getSimpleTask(int currentSort, Order order, Long resourceBusinessId, Long endResourceId){
|
|
|
+ TTask simpleTask = taskService.getOne(new LambdaQueryWrapper<TTask>().eq(TTask::getResourceBusinessId, resourceBusinessId).eq(TTask::getProcedureSort, currentSort).orderByDesc(TTask::getCreateTime).last("limit 1"));
|
|
|
+ Plan plan = planService.getOne(new LambdaQueryWrapper<Plan>().eq(Plan::getProduceStatus, "4").orderByDesc(Plan::getCreateTime).last("limit 1"));
|
|
|
+ TTask initTask = TTask.builder().build();
|
|
|
+ //OrderProduct initProduct = OrderProduct.builder().build();
|
|
|
+ Plan initPlan = Plan.builder().build();
|
|
|
+ if(simpleTask == null){
|
|
|
+ //初始化默认简易任务
|
|
|
+ //默认目的位置作为搬运任务的主设备
|
|
|
+ Long resourceId = endResourceId;
|
|
|
+ BomProcedure bomProcedure = bomProcedureService.getById(1L);
|
|
|
+ Long procedureId = bomProcedure!=null? bomProcedure.getId() : bomProcedureService.getOne(new LbqWrapper<BomProcedure>().eq(BomProcedure::getNo, "OP10").orderByDesc(BomProcedure::getCreateTime).last("limit 1")).getId();
|
|
|
+ Long bomId = 1L;
|
|
|
+ initTask.setCompleteBatchNo(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ initTask.setOrderNo(order.getOrderNo()).setProcedureNo("OP05").setProcedureName(bomProcedure.getName()).setResourceId(resourceId).setProcedureId(procedureId).setTaskNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_TASK)).
|
|
|
+ setOrderId(order.getId()).setProcedureSort(0).setFirstProcedureFlag("1").setLastProcedureFlag("1").setDraftFlag("0").setResourceBusinessId(resourceBusinessId).setBomId(bomId);
|
|
|
+ }else{
|
|
|
+ initTask = TTask.builder().build();
|
|
|
+ BeanUtil.copyProperties(simpleTask, initTask, "id");
|
|
|
+ initTask.setOrderId(order.getId()).setOrderNo(order.getOrderNo()).setPlanId(order.getPlanId()).setCompleteBatchNo(UUID.randomUUID().toString().replace("-", "")).setTaskNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_TASK));
|
|
|
+ }
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(plan, initPlan, "id");
|
|
|
+ initPlan.setOrderId(order.getId()).setOrderNo(order.getOrderNo()).setPlanNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_PLAN));
|
|
|
+ //orderProductService.save(initProduct);
|
|
|
+ planService.save(initPlan);
|
|
|
+ initTask.setPlanId(initPlan.getId());
|
|
|
+ return initTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 同产线内简易搬运处理
|
|
|
+ *
|
|
|
+ * @param orderTask
|
|
|
+ * @param startStorge
|
|
|
+ * @param goalStorge
|
|
|
+ * @param conditionName
|
|
|
+ */
|
|
|
+ public void inLineHandle(OrderTask orderTask, Storge startStorge, Storge goalStorge, String conditionName, Long startResourceId, Long endResourceId){
|
|
|
+ //线内提出多余的task任务
|
|
|
+ List<StockInfo> stockInfoList = stockInfoService.getStockInfoByType(startStorge.getId(), "1");
|
|
|
+ if(stockInfoList.size() == 0){
|
|
|
+ msgUtil.createWarnLog("当前库位工装信息不存在,请检查数据", "DataException");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int currentSort = conditionName.equals("BZ")? 0:1;
|
|
|
+ Order order = orderService.getById(orderTask.getOrderId());
|
|
|
+
|
|
|
+ String businessName = DemoLineConstant.DEMOLINE_CT_LINE_MOVE;
|
|
|
+
|
|
|
+ ResourceBusiness resourceBusiness = resourceBusinessMapper.selectOne(new LbqWrapper<ResourceBusiness>().eq(ResourceBusiness::getName, businessName));
|
|
|
+ //初始化任务
|
|
|
+ TTask simpleTask = this.getSimpleTask(currentSort, order, resourceBusiness.getId(), endResourceId);
|
|
|
+ taskService.save(simpleTask);
|
|
|
+ //初始化任务节点
|
|
|
+ List<TaskNode> switchNodes = taskNodeService.getCreateTaskNode(resourceBusiness.getId(), simpleTask);
|
|
|
+ List<TaskNode> taskNodes = new ArrayList<TaskNode>();
|
|
|
+ switchNodes.stream().forEach(node -> {
|
|
|
+ TaskNode taskNode = new TaskNode();
|
|
|
+ BeanUtil.copyProperties(node, taskNode, "id");
|
|
|
+ taskNode.setProcedureId(simpleTask.getProcedureId()).setTaskId(simpleTask.getId()).setExeStatus("1").setExeResult(null).setStartTime(null).setEndTime(null).setFeedback("").setNodeType("0").setCreateTime(simpleTask.getCreateTime());
|
|
|
+ taskNode.setCompleteBatchSort(taskNode.getCompleteBatchSort()+1);
|
|
|
+ if(taskNode.getPrority().equals(2)){
|
|
|
+ //线边库区分处理
|
|
|
+ taskNode.setTargetResourceId(endResourceId);
|
|
|
+ }
|
|
|
+ if(taskNode.getInterfaceType().equals("04") && taskNode.getResourceId()==null){
|
|
|
+ taskNode.setResourceId(endResourceId);
|
|
|
+ }
|
|
|
+ taskNodes.add(taskNode);
|
|
|
+ });
|
|
|
+ taskNodeService.saveBatch(taskNodes);
|
|
|
+
|
|
|
+ StockInfo stockInfo = stockInfoList.get(0);
|
|
|
+
|
|
|
+ //更新零件信息
|
|
|
+ TWorkpiece tWorkpiece = TWorkpiece.builder().build();
|
|
|
+ tWorkpiece.setOrderId(orderTask.getOrderId()).setOrderNo(order.getOrderNo()).setOrderName(order.getOrderName()).setCompleteBatchNo(simpleTask.getCompleteBatchNo()).setSerialNo(1).setIsEnd("0").setPlanId(simpleTask.getPlanId());
|
|
|
+ tWorkpiece.setPointId(startStorge.getPointId()).setStorgeId(startStorge.getId()).setCompleteBatchSort(0).setUniqueCode("").setTrayNo(stockInfo.getTrayNo());
|
|
|
+ tWorkpieceService.save(tWorkpiece);
|
|
|
+
|
|
|
+ //更新订单状态
|
|
|
+ order.setOrderStatus("2");
|
|
|
+ orderService.updateById(order);
|
|
|
+
|
|
|
+ TaskNode firstNode = taskNodes.get(0);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("taskNodeId",firstNode.getId().toString());
|
|
|
+ jsonObject.put("bizType", BizConstant.MQ_TASK_NODE_TYPE_COMMON);
|
|
|
+ jsonObject.put("handMode",0);
|
|
|
+ log.info("推送mq队列{}消息{}",firstNode.getResourceId().toString(),jsonObject.toString());
|
|
|
+ dynamicRabbitMq.sendMsg(firstNode.getResourceId().toString(),jsonObject.toString());
|
|
|
+ }
|
|
|
+}
|