Ver código fonte

抽检模块动态插入抽检节点功能

oyq28 3 anos atrás
pai
commit
b5262331c8

+ 1 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/InspectionService.java

@@ -25,6 +25,6 @@ public interface InspectionService extends SuperService<Inspection> {
 
     Boolean check(InspectionSaveDTO model);
 
-    TaskNode createTaskNode(InspectionSaveDTO model);
+    Boolean createTaskNode(InspectionSaveDTO model);
 
 }

+ 48 - 9
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/InspectionServiceImpl.java

@@ -1,6 +1,8 @@
 package com.github.zuihou.business.operationManagementCenter.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.authority.utils.TimeUtils;
 import com.github.zuihou.base.service.SuperServiceImpl;
 import com.github.zuihou.business.operationManagementCenter.dao.InspectionMapper;
 import com.github.zuihou.business.operationManagementCenter.dto.InspectionSaveDTO;
@@ -8,10 +10,7 @@ import com.github.zuihou.business.operationManagementCenter.entity.Inspection;
 import com.github.zuihou.business.operationManagementCenter.entity.TTask;
 import com.github.zuihou.business.operationManagementCenter.entity.TWorkpiece;
 import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
-import com.github.zuihou.business.operationManagementCenter.service.InspectionService;
-import com.github.zuihou.business.operationManagementCenter.service.PlanService;
-import com.github.zuihou.business.operationManagementCenter.service.TaskService;
-import com.github.zuihou.business.operationManagementCenter.service.WorkpieceService;
+import com.github.zuihou.business.operationManagementCenter.service.*;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
 import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
@@ -30,8 +29,11 @@ import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -41,6 +43,8 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
 
     private final String INSPECTION_RESOURCE_NAME = "三坐标_质检";
 
+    private final Long INSPECTION_INTERVAL_MIN = 5L;
+
     @Autowired
     private TaskService taskService;
 
@@ -62,6 +66,9 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
     @Autowired
     private WorkpieceService workpieceService;
 
+    @Autowired
+    private TaskNodeService taskNodeService;
+
     @Override
     public IPage<Inspection> pageList(IPage page, LbqWrapper<Inspection> wrapper) {
         return baseMapper.pageList(page, wrapper, new DataScope());
@@ -69,6 +76,20 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
 
     @Override
     public Boolean check(InspectionSaveDTO model) {
+        //当前零件的状况
+        TWorkpiece tWorkpiece = workpieceService.getById(model.getWorkpieceId());
+        Long procedureId = tWorkpiece.getProcedureId();
+        Long currentNodeId = tWorkpiece.getTaskNodeId();
+        if(null!=procedureId && null!=currentNodeId){
+            TaskNode currentTaskNode = taskNodeService.getById(currentNodeId);
+            TTask currentTask = taskService.getById(currentTaskNode.getTaskId());
+            TTask inspectionTask = taskService.getById(model.getTaskId());
+            //计算抽检任务预计开始时间与当前任务预计结束时间之间分钟的差值大于五分钟
+            //Long gap = ChronoUnit.MINUTES.between(DateUtils.date2LocalDateTime(inspectionTask.getExpectStartTime()), DateUtils.date2LocalDateTime(currentTask.getExpectEndTime()));
+            //return gap > INSPECTION_INTERVAL_MIN ? true : false;
+            //抽检工序还未执行且当前工序任务优先级大于抽检工序优先级
+            return procedureId!=inspectionTask.getProcedureId() && currentTask.getPrority() > inspectionTask.getPrority() ? true : false;
+        }
         return true;
     }
 
@@ -86,12 +107,21 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
 
 
     @Override
-    public TaskNode createTaskNode(InspectionSaveDTO model) {
+    public Boolean createTaskNode(InspectionSaveDTO model) {
 
         List<TaskNode> taskNodeList = Lists.newArrayList();
 
         TTask task = taskService.getById(model.getTaskId());
 
+        //获取零件完整bom流程任务节点ID
+        List<Long> taskIds = taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getCompleteBatchNo, task.getCompleteBatchNo()).orderByAsc(TaskNode::getCompleteBatchSort)).stream().map(TaskNode::getId).collect(Collectors.toList());
+
+        //获取抽检序节点
+        List<TaskNode> inspectionList = taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getTaskId, task.getId()).orderByDesc(TaskNode::getPrority));
+
+        //获取抽检序最后一个节点(优先级递增排列)
+        TaskNode lastNode = inspectionList.get(0);
+
         //在零件抽检工序末尾新增三坐标检测序节点
         LbqWrapper<TTask> lbqWrapper = new LbqWrapper<TTask>();
         lbqWrapper.eq(TTask::getProcedureId, task.getProcedureId()).eq(TTask::getPlanId, model.getPlanId());
@@ -110,6 +140,7 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
 
         List<ResourceAutoCode> parentResourceAutoCodeList = autoCodeList.stream().filter(a->a.getParentId().longValue()==0L).collect(Collectors.toList());
 
+
         for (int parentCount = 0; parentCount< parentResourceAutoCodeList.size(); parentCount++) {
             //父节点
             ResourceAutoCode pautoCode = parentResourceAutoCodeList.get(parentCount);
@@ -132,7 +163,7 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
                 taskNode.setTaskId(task.getId()).setOrderId(task.getOrderId())
                         .setTaskNodeNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_TASK_NODE));
                 taskNode.setAutoNode(autoCode).setNodeNo(autoCode.getNo()).setCompleteBatchNo(task.getCompleteBatchNo())
-                        .setExeStatus("1").setPrority(autoCode.getWeight()).setNodeName(autoCode.getName());
+                        .setExeStatus("1").setPrority(lastNode.getPrority()+1+taskNodeList.size()).setNodeName("抽检:"+autoCode.getName()).setCreateTime(LocalDateTime.now());
 
                 //依据设备类型判断调用接口类型
                 if("1".equals(taskNode.getAutoNode().getCategory())){
@@ -176,11 +207,19 @@ public class InspectionServiceImpl extends SuperServiceImpl<InspectionMapper, In
                         taskNode.setNodeType("0");
                     }
                 }
-                //taskNode.setCompleteBatchSort(i);
+                taskNode.setCompleteBatchSort(lastNode.getCompleteBatchSort()+taskNodeList.size()+1);
                 taskNodeList.add(taskNode);
             }
         }
-        taskNodeList.forEach(System.out::println);
-        return null;
+        //System.out.println(taskNodeList.size());
+        //taskNodeList.forEach(System.out::println);
+
+        //批量更新节点的次序值
+        UpdateWrapper<TaskNode> updateWrapper = new UpdateWrapper<TaskNode>();
+        updateWrapper.lambda().in(TaskNode::getId, taskIds.toArray()).gt(TaskNode::getCompleteBatchSort, lastNode.getCompleteBatchSort()).setSql("complete_batch_sort = complete_batch_sort + "+taskNodeList.size());
+
+        boolean bool= taskNodeService.update(updateWrapper);
+
+        return (bool)? taskNodeService.saveBatch(taskNodeList) : false;
     }
 }

+ 4 - 2
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/InspectionController.java

@@ -119,8 +119,10 @@ public class InspectionController extends SuperController<InspectionService, Lon
     public R<Inspection> save(@RequestBody InspectionSaveDTO model) {
         Inspection inspection = BeanUtil.toBean(model, Inspection.class);
         if (baseService.check(model)) {
-            baseService.createTaskNode(model);
-            //return baseService.save(inspection) ? success(inspection) : fail("新增失败");
+            if(baseService.createTaskNode(model)) {
+                return baseService.save(inspection) ? success(inspection) : fail("新增失败");
+            }
+            return fail("插入抽检节点失败");
         }
         return fail("新增条件判断失败");
     }