Explorar o código

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

laoyao %!s(int64=3) %!d(string=hai) anos
pai
achega
5fa7940e56

+ 5 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/dao/PlanMapper.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.github.zuihou.base.mapper.SuperMapper;
+import com.github.zuihou.business.operationManagementCenter.entity.Order;
 import com.github.zuihou.business.operationManagementCenter.entity.Plan;
 
 import org.apache.ibatis.annotations.Param;
@@ -45,4 +46,8 @@ public interface PlanMapper extends SuperMapper<Plan> {
     List<Map<String, String>> checkPlanCuttingTools(Map<String, Object> params);
 
     List<Map<String, String>> checkPlanDetailCuttingTools(Map<String, Object> params);
+
+    int updatePlanStatus(Order model);
+
+    int updatePlanProduceStatus(Order model);
 }

+ 231 - 39
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/OrderServiceImpl.java

@@ -1,23 +1,32 @@
 package com.github.zuihou.business.operationManagementCenter.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.zuihou.base.service.SuperServiceImpl;
 import com.github.zuihou.business.DemoLine.DemoCacheKey;
 import com.github.zuihou.business.DemoLine.DemoLineConstant;
+import com.github.zuihou.business.aps.algorithm.ga.GAScheduler;
+import com.github.zuihou.business.aps.instance.domain.basicdata.*;
 import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
 import com.github.zuihou.business.operationManagementCenter.dao.*;
 import com.github.zuihou.business.operationManagementCenter.dto.OrderProductUpdateDTO;
 import com.github.zuihou.business.operationManagementCenter.dto.OrderUpdateDTO;
 import com.github.zuihou.business.operationManagementCenter.entity.*;
 import com.github.zuihou.business.operationManagementCenter.service.*;
+import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureProductionresourceMapper;
+import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureProgramMapper;
 import com.github.zuihou.business.productionReadyCenter.entity.AutoNode;
 import com.github.zuihou.business.productionReadyCenter.entity.BomProcedure;
+import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureProductionresource;
+import com.github.zuihou.business.productionReadyCenter.entity.BomProcedureProgram;
 import com.github.zuihou.business.productionReadyCenter.service.AutoNodeService;
 import com.github.zuihou.business.productionReadyCenter.service.BBomService;
 import com.github.zuihou.business.productionReadyCenter.service.BomProcedureService;
+import com.github.zuihou.business.productionResourceCenter.entity.Repair;
+import com.github.zuihou.business.productionResourceCenter.service.RepairService;
 import com.github.zuihou.business.util.DynamicRabbitMq;
 import com.github.zuihou.common.constant.BizConstant;
 import com.github.zuihou.common.constant.CacheKey;
@@ -39,6 +48,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.sql.Timestamp;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -98,6 +108,14 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
     @Autowired
     private DynamicRabbitMq dynamicRabbitMq;
 
+    @Autowired
+    private BomProcedureProductionresourceMapper procedureProductionresourceMapper;
+
+    @Autowired
+    private RepairService repairService;
+    @Autowired
+    private BomProcedureProgramMapper bomProcedureProgramMapper;
+
     @Override
     public IPage<Order> pageList(IPage page,String sustDesc, LbqWrapper<Order> wrapper) {
         return baseMapper.pageList(page,sustDesc, wrapper);
@@ -421,60 +439,234 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Order orderSuspend(Order model){
-
+        // 默认只有一键生产过后的订单可以暂停和启用,未一键生产过的订单无需暂停和启用
         // 暂停订单,根据订单id找到相应的task,tasknode相应的信息,删除相应未执行的工序结点
         // TODO 等代码稳定后增加资源锁,防止一边在加工,一边在暂停订单造成数据的不一致
-        QueryWrapper<TWorkpiece> queryTWorkpieceWrapper = new QueryWrapper<TWorkpiece>();
-        queryTWorkpieceWrapper.eq("planId", model.getId());
-        queryTWorkpieceWrapper.in("produceStatus",new ArrayList<String>(Arrays.asList("1", "2")));
-        List<TWorkpiece> tWorkpieces = workpieceMapper.selectList(queryTWorkpieceWrapper);
-        // 依次根据工件id删除相应的数据
-        for(TWorkpiece tWorkpiece : tWorkpieces){
-            if("1".equals(tWorkpiece.getProduceStatus())){
-                // 未开始加工,全量删除,先删除结点表,在删除task表
-                // 删除tasknode表中除下料的未执行结点
-                Map param = new HashMap();
-                param.put("completeBatchNo", tWorkpiece.getCompleteBatchNo());
-                taskNodeService.deleteByWorkpieceId(param);
-
-                QueryWrapper<TTask> tTaskWrapper = new QueryWrapper<TTask>();
-                tTaskWrapper.eq("completeBatchNo", tWorkpiece.getCompleteBatchNo());
-                taskMapper.delete(tTaskWrapper);
-
-            }else if("2".equals(tWorkpiece.getProduceStatus())){
-                // 已开始加工,只删除未开始的工序
-                // 找到当前在工工序的最后的一个结点序号
-                Map param = new HashMap();
-                param.put("completeBatchNo", tWorkpiece.getCompleteBatchNo());
-                int completeBatchSort = taskNodeService.selectCurrentProduceSort(param);
-
-                param.clear();
-                param.put("completeBatchNo", param.get("completeBatchNo"));
-                param.put("completeBatchSort", completeBatchSort);
-                taskNodeService.deleteByWorkpieceSort(param);
-
-                // 删除task表的数据
-                QueryWrapper<TTask> tTaskWrapper = new QueryWrapper<TTask>();
-                tTaskWrapper.eq("completeBatchNo", tWorkpiece.getCompleteBatchNo());
-                tTaskWrapper.eq("status","1");
-                taskMapper.delete(tTaskWrapper);
-            }
-        }
+//        QueryWrapper<TWorkpiece> queryTWorkpieceWrapper = new QueryWrapper<TWorkpiece>();
+//        queryTWorkpieceWrapper.eq("planId", model.getId());
+//        queryTWorkpieceWrapper.in("produceStatus",new ArrayList<String>(Arrays.asList("1", "2")));
+//        List<TWorkpiece> tWorkpieces = workpieceMapper.selectList(queryTWorkpieceWrapper);
+//        // 依次根据工件id删除相应的数据
+//        for(TWorkpiece tWorkpiece : tWorkpieces){
+//            if("1".equals(tWorkpiece.getProduceStatus())){
+//                // 未开始加工,全量删除,先删除结点表,在删除task表
+//                // 删除tasknode表中除下料的未执行结点
+//                Map param = new HashMap();
+//                param.put("completeBatchNo", tWorkpiece.getCompleteBatchNo());
+//                taskNodeService.deleteByWorkpieceId(param);
+//
+//                QueryWrapper<TTask> tTaskWrapper = new QueryWrapper<TTask>();
+//                tTaskWrapper.eq("completeBatchNo", tWorkpiece.getCompleteBatchNo());
+//                taskMapper.delete(tTaskWrapper);
+//
+//            }else if("2".equals(tWorkpiece.getProduceStatus())){
+//                // 已开始加工,只删除未开始的工序
+//                // 找到当前在工工序的最后的一个结点序号
+//                Map param = new HashMap();
+//                param.put("completeBatchNo", tWorkpiece.getCompleteBatchNo());
+//                int completeBatchSort = taskNodeService.selectCurrentProduceSort(param);
+//
+//                param.clear();
+//                param.put("completeBatchNo", param.get("completeBatchNo"));
+//                param.put("completeBatchSort", completeBatchSort);
+//                taskNodeService.deleteByWorkpieceSort(param);
+//
+//                // 删除task表的数据
+//                QueryWrapper<TTask> tTaskWrapper = new QueryWrapper<TTask>();
+//                tTaskWrapper.eq("completeBatchNo", tWorkpiece.getCompleteBatchNo());
+//                tTaskWrapper.eq("status","1");
+//                taskMapper.delete(tTaskWrapper);
+//            }
+//        }
+        model.setProduceStatus("3");
+        planMapper.updatePlanProduceStatus(model);
+
         return model;
     }
 
     @Override
     public Order orderEnable(Order model){
-        // 启用订单后判断如果当前计划未加工,直接
+        // 默认只有一键生产过后的订单可以暂停和启用,未一键生产过的订单无需暂停和启用,启用是找出所有的所有未加工的工件重新排序
+        model.setProduceStatus("2");
+        planMapper.updatePlanProduceStatus(model);
+
+        // 找出当前所有的订单计划还未开始加工的工件进行重排
+        QueryWrapper<Plan> planWrapper = new QueryWrapper<Plan>();
+        planWrapper.eq("planStatus", "2");
+        List<Plan> plans = planMapper.selectList(planWrapper);
+        Map<Long,Plan> plansMap = plans.stream().collect(Collectors.toMap(Plan::getId, t->t));
+
+        List<Long> planIds = plans.stream().map(p -> p.getId()).collect(Collectors.toList());
+        List<Long> orderIds = plans.stream().map(p -> p.getOrderId()).collect(Collectors.toList());
+
+        // 未生产工件表
+        QueryWrapper<TWorkpiece> tWorkpieceWrapper = new QueryWrapper<TWorkpiece>();
+        tWorkpieceWrapper.in("planId", planIds);
+        tWorkpieceWrapper.in("produceStatus", "1");
+        List<TWorkpiece> tWorkpieces = workpieceMapper.selectList(tWorkpieceWrapper);
 
+        List<OrderProduct> orderProductList = orderProductService.list(Wraps.<OrderProduct>lbQ().in(OrderProduct::getOrderId,orderIds));
+        Map<Long,OrderProduct> orderProductListMap = orderProductList.stream().collect(Collectors.toMap(OrderProduct::getBomId, t->t));
+
+        //查出所有产品ID
+        List<PlanProduct> productList = planProductMapper.selectList(Wraps.<PlanProduct>lbQ().in(PlanProduct::getPlanId, planIds));
+        Map<Long,Long> planProductMap = productList.stream().collect(Collectors.toMap(PlanProduct::getPlanId, t->t.getBomId()));
+
+        List<Long> bomIdList = productList.stream().map(p -> p.getBomId()).collect(Collectors.toList());
+        //查出本次需要得工艺信息
+        Map<Long, List<BomProcedure>> bomProcedureMap = bomProcedureService.getBomProcedureMap(bomIdList);
+
+        // 可选设备集合(工序名称+可选设备列表)
+        Map<String, List<CandidateProcess>> candidateProMap = new HashMap<>(); // 可选处理集合(可选设备以及对应的加工时间)
+        // 工序集合(工序名+工序)
+        Map<String, Operation> operationMap = new HashMap<>();
+        // 设备集合(设备名+设备)
+        Map<String, Machine> machineMap = new HashMap<>();
+        // 零件集合(零件名称+零件)
+        Map<String, Part> partMap = new HashMap<>();
+        Map<Long,OrderProduct> orderProductMap = orderProductList.stream().collect(Collectors.toMap(OrderProduct::getId, t->t));
+
+        List<TTask> taskList = new ArrayList<TTask>();
+        //设置completeBatchNo
+        Map<String,String> completeBatchNoMap = new HashMap<String,String>();
+        double totalOpNum = 0.0;
 
+        for(TWorkpiece tWorkpiece : tWorkpieces){
+            Long bomId = planProductMap.get(tWorkpiece.getPlanId());
+            List<BomProcedure> bomProcedureList = bomProcedureMap.get(bomId);
+            Map<Long,BomProcedure> bomProcedureListMap = bomProcedureList.stream().collect(Collectors.toMap(BomProcedure::getId, t->t));
+            Part part = new Part();
+            List<CandidateProcess> candidateProcesses = new ArrayList<CandidateProcess>();
+            // 根据工件id查找未加工的任务
+            QueryWrapper<TTask> tTaskWrapper = new QueryWrapper<TTask>();
+            planWrapper.in("completeBatchNo", tWorkpiece.getCompleteBatchNo());
+            planWrapper.eq("status", "1");
+            List<TTask> tTasks = taskMapper.selectList(tTaskWrapper);
+            List<Operation> opList = new ArrayList<Operation>();
+
+            for(TTask tTask : tTasks){
+                BomProcedure bomProcedure = bomProcedureListMap.get(tTask.getProcedureId());
+                if (bomProcedure.getProductionresourceList().size() > 0){
+                    Machine machine = new Machine();
+                    CandidateProcess candidateProcess = new CandidateProcess();
+                    for(BomProcedureProductionresource bomProcedureProductionresource : bomProcedure.getProductionresourceList()){
+                        if(!machineMap.containsKey(bomProcedureProductionresource.getResourceId())){
+                            machine.setId(bomProcedureProductionresource.getResourceId().longValue());
+                            // 添加设备维保时间片
+                            LbqWrapper<Repair> repairWrapper = new LbqWrapper<Repair>().eq(Repair::getProductionresourceId, bomProcedureProductionresource.getResourceId()).gt(Repair::getRepairStartTime, cn.hutool.core.date.DateUtil.toLocalDateTime(cn.hutool.core.date.DateUtil.date()));
+                            List<Repair> repairs = repairService.list(repairWrapper);
+                            for(Repair repair : repairs){
+                                machine.getNoUseTime().add(Timestamp.valueOf(repair.getRepairStartTime()).getTime() + "-" + Timestamp.valueOf(repair.getRepairEndTime()).getTime());
+                            }
+                            machineMap.put("M" + bomProcedureProductionresource.getResourceId(), machine);
+                        }
+
+                        if(!candidateProMap.containsKey(tWorkpiece.getCompleteBatchNo() + "_" + bomProcedure.getNo())){
+                            candidateProcess.setMachineId(bomProcedureProductionresource.getResourceId());
+                            LbqWrapper<BomProcedureProgram> bomProcedureProgramWrapper = new LbqWrapper<BomProcedureProgram>().eq(BomProcedureProgram::getResourceId, bomProcedureProductionresource.getResourceId()).eq(BomProcedureProgram::getProcedureId,bomProcedureProductionresource.getProcedureId());
+                            BomProcedureProgram bomProcedureProgram = bomProcedureProgramMapper.selectOne(bomProcedureProgramWrapper);
+                            // 人工上下料没有程序的情况直接用工序时间
+                            if(null != bomProcedureProgram && null != bomProcedureProgram.getRunTime()){
+                                candidateProcess.setProcedureId(bomProcedureProgram.getProcedureId());
+                                candidateProcess.setDuration(bomProcedureProgram.getRunTime().intValue());
+                                candidateProcess.setRunTime(bomProcedureProgram.getRunTime());
+                            }else{
+                                candidateProcess.setProcedureId(bomProcedure.getId());
+                                //candidateProcess.setDuration(bomProcedure.getPrepareWorkhours().intValue() + bomProcedure.getRatedWorkhours().intValue());
+                                candidateProcess.setDuration(bomProcedure.getRatedWorkhours().intValue());
+                                candidateProcess.setRunTime( bomProcedure.getRatedWorkhours());
+                            }
+                            if(!candidateProcesses.contains(candidateProcess)){
+                                candidateProcesses.add(candidateProcess);
+                            }
+                            candidateProMap.put(tWorkpiece.getCompleteBatchNo() + "_" + bomProcedure.getNo(),candidateProcesses);
+                        }
+                    }
+                }
+                // 组装排产所以的工序信息
+                Operation operation = new Operation();
+                operation.setId(String.valueOf(tTask.getId()));
+                operation.setPartId(tTask.getCompleteBatchNo());
+                operation.setName(tTask.getProcedureNo());
+                operation.setSeq(tTask.getProcedureSort()+1);
+                operation.setDueDate(orderProductListMap.get(tWorkpiece.getBomId()).getDeliveryTime().getTime());
+                operation.setPlanQty(1);
+                String operationKey = tTask.getCompleteBatchNo() + "_" + tTask.getProcedureNo();
+                operationMap.put(operationKey,operation);
+                opList.add(operation);
+                totalOpNum ++;
+            }
+
+            part.setId(tWorkpiece.getCompleteBatchNo());
+            part.setOperationNum(bomProcedureList.size());
+            part.setOpList(opList);
+            // 根据最终版本调整交互日期及优先级
+            part.setDueDate(orderProductListMap.get(tWorkpiece.getBomId()).getDeliveryTime().getTime());
+            part.setPartPrority(plansMap.get(tWorkpiece.getPlanId()).getPrority());
+            partMap.put(tWorkpiece.getCompleteBatchNo(),part);
+
+        }
+
+        // 调用java简易排产
+        Instance instance = new Instance();
+        instance.setTotalOpNum(totalOpNum);
+        // 赋值设备map
+        instance.setMachineMap(machineMap);
+        // 创造零件map
+        instance.setPartMap(partMap);
+        // 创造工序map
+        instance.setOperationMap(operationMap);
+        // 创造工序可选设备集合map
+        instance.setCandidateProMap(candidateProMap);
+
+        GAScheduler gaScheduler = new GAScheduler(instance, GAScheduler.PRIORITY_CODE);
+        try{
+            gaScheduler.schedule();
+        }catch(Exception e){
+            e.printStackTrace();
+        }
+        // 更新task表人工序任务的预计开始时间及结束时间
+        Iterator<Map.Entry<String, Operation>> it = instance.getOperationMap().entrySet().iterator();
+        while(it.hasNext()){
+            Operation operation = it.next().getValue();
+            for(TTask task : taskList){
+                if(task.getTmpId().equals(operation.getId())){
+                    List<BomProcedureProductionresource> procedureProductionresourceList = procedureProductionresourceMapper.selectList(Wraps.<BomProcedureProductionresource>lbQ().eq(BomProcedureProductionresource::getProcedureId,task.getProcedureId()).eq(BomProcedureProductionresource::getResourceId,operation.getMachineId()));
+                    task.setExpectStartTime(new Date(operation.getStart()));
+                    task.setExpectEndTime(new Date(operation.getFinish()));
+                    task.setResourceId(operation.getMachineId());
+                    if(CollectionUtil.isNotEmpty(procedureProductionresourceList)){
+                        task.setResourceBusinessId(procedureProductionresourceList.get(0).getResourceBusinessId());
+                    }
+                    taskMapper.updateAllById(task);
+                    break;
+                }
+            }
+        }
         return model;
     }
 
     @Override
     public Boolean deleteOrder(Order model){
+        // 判断计划是否在生产中,如果是在生产中不可删除
+        isFalse(checkPlan(model) > 0, "订单已生产,不可删除");
+        int count = planMapper.updatePlanStatus(model);
+        if(count == 1){
+            return true;
+        }else{
+            return false;
+        }
+    }
 
-        return true;
+    /**
+     * 检查订单计划状态
+     * @param model
+     * @return
+     */
+    private int checkPlan(Order model) {
+        List<String> planStatusList = new ArrayList<>(Arrays.asList("2,3"));
+        int count = planMapper.selectCount(Wraps.<Plan>lbQ().in(Plan::getPlanStatus, planStatusList));
+        return  count;
     }
 
     //任务运行起点

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

@@ -283,4 +283,16 @@
             )
     </update>
 
+    <update id="updatePlanStatus">
+        UPDATE imcs_p_plan o
+            SET o.status = '-1'
+            WHERE id =  #{planId}
+    </update>
+
+    <update id="updatePlanProduceStatus">
+        UPDATE imcs_p_plan o
+            SET o.produce_status = #{produceStatus}
+            WHERE id =  #{planId}
+    </update>
+
 </mapper>

+ 6 - 2
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/operationManagementCenter/entity/Order.java

@@ -244,10 +244,14 @@ public class Order extends Entity<Long> {
     @TableField(exist = false)
     private Integer process;
 
+    @ApiModelProperty(value = "订单计划id")
+    @TableField(exist = false)
+    private Long planId;
+
 
     @Builder
-    public Order(Long id, LocalDateTime createTime, LocalDateTime updateTime, 
-                    String orderNo, Long custId, String source, String orderStatus, String auditStatus, 
+    public Order(Long id, LocalDateTime createTime, LocalDateTime updateTime,
+                    String orderNo, Long custId, String source, String orderStatus, String auditStatus,
                     String status, String planStatus, Date orderTime, Date deliveryTime, String remark,
                     Integer prority, String schedulingStatus, String rhythmType, String produceStatus) {
         this.id = id;