浏览代码

Merge remote-tracking branch 'origin/master' into master

yejian 3 年之前
父节点
当前提交
4e0c6c7cc4

+ 34 - 6
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/mq/TaskWorkNode.java

@@ -10,10 +10,7 @@ import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
 import com.github.zuihou.business.edgeLibrary.entity.Storge;
 import com.github.zuihou.business.edgeLibrary.service.StorgeService;
 import com.github.zuihou.business.externalApi.service.AgvHikOrderInfoService;
-import com.github.zuihou.business.operationManagementCenter.dao.OrderMapper;
-import com.github.zuihou.business.operationManagementCenter.dao.PlanMapper;
-import com.github.zuihou.business.operationManagementCenter.dao.TTaskMapper;
-import com.github.zuihou.business.operationManagementCenter.dao.TaskNodeMapper;
+import com.github.zuihou.business.operationManagementCenter.dao.*;
 import com.github.zuihou.business.operationManagementCenter.entity.TTask;
 import com.github.zuihou.business.operationManagementCenter.entity.TWorkpiece;
 import com.github.zuihou.business.operationManagementCenter.entity.TaskNode;
@@ -97,6 +94,9 @@ public class TaskWorkNode {
     @Autowired
     private WorkpieceService workpieceService;
 
+    @Autowired
+    private WorkpieceMapper workpieceMapper;
+
     @Autowired
     private ProductionresourcePositionService productionresourcePositionService;
 
@@ -282,8 +282,8 @@ public class TaskWorkNode {
                 String code = retJson.getString("result").trim();
                 if (code.equals("true")) {
                     //回调处理
-                    taskNode.setExeStatus("3").setEndTime(new Date()).setExeResult("1");
-                    taskNodeService.updateAllById(taskNode);
+//                    taskNode.setExeStatus("3").setEndTime(new Date()).setExeResult("1");
+//                    taskNodeService.updateAllById(taskNode);
                     log.setExeStatus("3").setEndTime(new Date()).setExeResult("1").setFeedback("");
                     msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE_CONDITION + "_" + taskNode.getId());
                     msgUtil.redis_del(CacheKey.TASK_CURRENT_NODE_PARAMS + "_" + taskNode.getId());
@@ -565,6 +565,13 @@ public class TaskWorkNode {
             //业务序列节点
             //ResourceAutoCode parentAutoCode = resourceAutoCodeService.getById(resourceAutoCode.getParentId());
             logger.info("=============进入自动化节点条件检测==============" + resourceAutoCode.getName());
+
+            //判断是不是在切换模式,重新排产等特殊情况下
+            map = checkPreCondition(taskNode, task, map);
+            Object o = map.get("result");
+            if(o!=null&&o.toString().equals("false")){
+                return map;
+            }
             map = nodeOperationService.checkCondition(taskNode, task, map);
         } else {
             logger.info("=============进入线边库条件检测==============" + resourceAutoCode.getName());
@@ -843,5 +850,26 @@ public class TaskWorkNode {
         }
         return true;
     }
+
+
+    /**
+     * 前置条件验证,目前主要验证是不是在重新排产
+     * @param taskNode
+     * @param task
+     * @param dataMap
+     * @return
+     */
+    public Map checkPreCondition(TaskNode taskNode, TTask task, Map<String, Object> dataMap){
+        TWorkpiece workpiece = workpieceMapper.selectOne(Wraps.<TWorkpiece>lbQ().eq(TWorkpiece::getCompleteBatchNo,taskNode.getCompleteBatchNo()));
+        String exchangeZoneFlag = workpiece.getExchangeZoneFlag();
+        Long exchangeProcedureId = workpiece.getExchangeProcedureId();
+        if(StringUtil.isNotEmpty(exchangeZoneFlag)&&exchangeProcedureId!=null){//正在切换产线
+            if(exchangeProcedureId.longValue()!=taskNode.getProcedureId().longValue()){
+                dataMap.put("result", false);
+                dataMap.put("msg", DictionaryKey.NodeException.RE_SCHEDURE);
+            }
+        }
+        return dataMap;
+    }
 }
 

+ 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;
     }
 }

+ 7 - 7
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/MsgUtil.java

@@ -98,13 +98,13 @@ public class MsgUtil implements ApplicationContextAware {
         if(n<taskNodeList.size()-1){//尚未执行到最后一个
             TaskNode nextTaskNode = taskNodeList.get(n+1);
 
-            //如果切换了产线,则只把当前工序走完
-            if(currWorkpiece!=null&&"1".equals(currWorkpiece.getExchangeZoneFlag())){
-                Long exchangeProcedureId = currWorkpiece.getExchangeProcedureId();
-                if(exchangeProcedureId.longValue()!=nextTaskNode.getProcedureId().longValue()){
-                    return;
-                }
-            }
+//            //如果切换了产线,则只把当前工序走完
+//            if(currWorkpiece!=null&&"1".equals(currWorkpiece.getExchangeZoneFlag())){
+//                Long exchangeProcedureId = currWorkpiece.getExchangeProcedureId();
+//                if(exchangeProcedureId.longValue()!=nextTaskNode.getProcedureId().longValue()){
+//                    return;
+//                }
+//            }
 
             jsonObject.put("taskNodeId",nextTaskNode.getId().toString());
             if(callBackJson.containsKey(DemoLineConstant.DEMOLINE_XBKFLAG)){//临时存放到了线边库,向虚拟线边库发一个MQ。

+ 42 - 0
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/operationManagementCenter/InspectionMapper.xml

@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.github.zuihou.business.operationManagementCenter.dao.InspectionMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.github.zuihou.business.operationManagementCenter.entity.Inspection">
+        <id column="id" jdbcType="BIGINT" property="id"/>
+        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
+        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
+        <result column="bom_id" jdbcType="BIGINT" property="bomId"/>
+        <result column="order_id" jdbcType="BIGINT" property="orderId"/>
+        <result column="plan_id" jdbcType="BIGINT" property="planId"/>
+        <result column="zone_id" jdbcType="BIGINT" property="zoneId"/>
+        <result column="workpiece_id" jdbcType="BIGINT" property="workpieceId"/>
+        <result column="task_id" jdbcType="BIGINT" property="taskId"/>
+        <result column="create_user" jdbcType="VARCHAR" property="createUser"/>
+        <result column="result" jdbcType="INTEGER" property="result"/>
+        <result column="update_user" jdbcType="VARCHAR" property="updateUser"/>
+        <result column="report" jdbcType="VARCHAR" property="report"/>
+    </resultMap>
+
+    <!-- 通用查询结果列 -->
+    <sql id="Base_Column_List">
+        id,create_time,update_time,create_user, update_user, bom_id,zone_id,task_id,order_id,plan_id, workpiece_id, result,report,org_id,
+        bomName, partsNo, startTime, endTime,procedureNo, procedureName, zoneNo
+    </sql>
+
+    <!-- 分页 -->
+    <select id="pageList" parameterType="String" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List"/>
+        from (
+           select a.*, b.name as bomName, b.parts_no as partsNo, o.start_time as startTime, o.end_time as endTime, p.name as procedureName, p.no as procedureNo, z.org_id, z.no as zoneNo from imcs_o_order_inspection a
+           left join imcs_p_plan o on a.plan_id = o.id
+           left join imcs_b_bom b on a.bom_id = b.id
+           left join imcs_z_zone z on a.zone_id = z.id
+           left join imcs_t_task k on a.task_id = k.id
+           left join imcs_b_bom_procedure p on k.procedure_id = p.id
+        ) s ${ew.customSqlSegment}
+    </select>
+
+</mapper>

+ 0 - 1
imcs-admin-boot/imcs-business-biz/src/main/resources/mapper_business/base/operationManagementCenter/PlanMapper.xml

@@ -37,7 +37,6 @@
         from (
         select a.*,b.order_no as orderNo,b.order_name orderName,b.source,b.order_status as orderStatus,c.bomDesc,ifnull(b.produce_num,0) as produceNum, c.bomId, c.partsNo,c.partsAlias,c.bomAlias,c.pdeliveryTime,b.delivery_time deliveryTime,c.order_product_id,d.id as zoneId, d.org_id,
         ifnull(v.completeCount ,0) as completeNum,unqualifiedBomNum,
---         group_concat(t.id) as workpieceIds,
         CASE WHEN ifnull(w.taskCount,0)=0 then 0 else  round(100 *( wcCount / taskCount),2) end process,ifnull(c.plan_bom_num,0) as planBomNum,d.name as zoenDesc from imcs_p_plan a
         left join (
         select ord.* from imcs_o_order ord

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

@@ -95,11 +95,6 @@ public class InspectionController extends SuperController<InspectionService, Lon
             //在当前零件加工工序之后
             wrapper.le(BomProcedure::getSort, sort);
         }
-        Inspection inspection = baseService.getOne(new LbqWrapper<Inspection>().eq(Inspection::getWorkpieceId, workPiece.getId()));
-        //排除已经提交抽检的工序
-        if (null != inspection && null != inspection.getProcedureId()) {
-            wrapper.ne(BomProcedure::getId, inspection.getProcedureId());
-        }
 
         List<Long> idList = bomProcedureService.list(wrapper).stream().filter(data -> {
             //排除保障中心设备序
@@ -107,7 +102,15 @@ public class InspectionController extends SuperController<InspectionService, Lon
             return zZoneService.getById(zone_id).getNo() != "safeguard";
         }).map(BomProcedure::getId).collect(Collectors.toList());
         //获取已存在的工序的任务节点
-        List<TTask> dataList = taskService.list(new LbqWrapper<TTask>().eq(TTask::getCompleteBatchNo, workPiece.getCompleteBatchNo()).eq(TTask::getPlanId, map.get("planId").toString()).in(TTask::getProcedureId, idList.toArray()));
+        LbqWrapper<TTask> taskLbqWrapper = new LbqWrapper<TTask>();
+        taskLbqWrapper.eq(TTask::getCompleteBatchNo, workPiece.getCompleteBatchNo()).eq(TTask::getPlanId, map.get("planId").toString()).in(TTask::getProcedureId, idList.toArray());
+
+        Inspection inspection = baseService.getOne(new LbqWrapper<Inspection>().eq(Inspection::getWorkpieceId, workPiece.getId()));
+        //排除已经提交抽检的工序
+        if (null != inspection && null != inspection.getTaskId()) {
+            taskLbqWrapper.ne(TTask::getId, inspection.getTaskId());
+        }
+        List<TTask> dataList = taskService.list(taskLbqWrapper);
         return success(dataList);
     }
 
@@ -116,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("新增条件判断失败");
     }

+ 1 - 1
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/WorkpieceController.java

@@ -78,7 +78,7 @@ public class WorkpieceController extends SuperController<WorkpieceService, Long,
                 workpiece.getOrderNo()).eq(TWorkpiece::getBomId, workpiece.getBomId()).like(TWorkpiece::getBomNo,
                 workpiece.getBomNo()).eq(TWorkpiece::getBomName, workpiece.getBomName()).like(TWorkpiece::getOrderNo, workpiece.getOrderNo()).eq(
                 TWorkpiece::getPlanId, workpiece.getPlanId()).like(TWorkpiece::getPlanNo, workpiece.getPlanNo()).eq(TWorkpiece::getProduceStatus,
-                workpiece.getProduceStatus()).eq(TWorkpiece::getTestResult, workpiece.getTestResult()).like(TWorkpiece::getUniqueCode, workpiece.getUniqueCode());
+                workpiece.getProduceStatus()).eq(TWorkpiece::getTestResult, workpiece.getTestResult()).like(TWorkpiece::getUniqueCode, workpiece.getUniqueCode()).orderByAsc(TWorkpiece::getCreateTime);
 
         baseService.pageList(page, wrapper);
     }

+ 0 - 5
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/operationManagementCenter/entity/Plan.java

@@ -325,17 +325,12 @@ public class Plan extends Entity<Long> {
     @Excel(name = "订单明细ID")
     private Long orderProductId;
 
-    @ApiModelProperty(value = "工件IDs")
-    @TableField(exist = false)
-    private String workpieceIds;
-
     @ApiModelProperty(value = "计划IDs")
     @Length(max = 128, message = "计划IDs不能超过128")
     @TableField(exist = false)
     private String planIds;
 
 
-
     @Builder
     public Plan(Long id, LocalDateTime createTime, LocalDateTime updateTime, 
                     String planNo, Long orderId, String auditStatus, String remark,

+ 1 - 0
imcs-admin-boot/imcs-common/src/main/java/com/github/zuihou/common/constant/DictionaryKey.java

@@ -31,6 +31,7 @@ public interface DictionaryKey {
     //节点枚举异常
     enum NodeException {
        TIME_OUT("超时", 1), RUNNING_FALSE("设备运行不正常", 2),
+        RE_SCHEDURE("正在重新排产", 6),
        NO_RESOURCE("无可运行资源", 3), RESOURCE_LOCK("设备已锁定", 4),NO_COMPLETE("设备不完整", 5);
        private String name;
        private int index;