ソースを参照

后台节点操作功能

oyq28 3 年 前
コミット
23937b6a6c

+ 1 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/edgeLibrary/service/impl/StorgeServiceImpl.java

@@ -195,7 +195,7 @@ public class StorgeServiceImpl extends SuperCacheServiceImpl<StorgeMapper, Storg
     @Override
     public Storge unlockStorge(Storge storge) {
         storge.setCampId(null);
-        storge.setLockStatus("0");
+        storge.setLockStatus("1");
         this.updateById(storge);
         return storge;
     }

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

@@ -243,6 +243,8 @@ public class TaskWorkNode {
         logger.info("===============================接口返回" + returnData);
         JSONObject retJson = JSONObject.parseObject(returnData);
         if(jsonObject.getString("Code").trim() == "1") {
+            taskNode.setExeStatus("3").setEndTime(new Date()).setExeResult("1");
+            taskNodeService.updateAllById(taskNode);
             log.setExeStatus("3").setEndTime(new Date()).setExeResult("1");
         }else{
             log.setExeResult("0").setFeedback(jsonObject.getString("Msg"));
@@ -259,17 +261,26 @@ public class TaskWorkNode {
      */
     public String getInterfaceUrl(TaskNode taskNode) {
         String autoProgrameUrl = "";
-        if (DictionaryKey.INTERFACETYPE_PLC.equals(taskNode.getInterfaceType())) {//总控
-            autoProgrameUrl = UrlConfConstant.plcURL;
-        } else if (DictionaryKey.INTERFACETYPE_PRO.equals(taskNode.getInterfaceType())) {
-//            autoProgrameUrl = parameterService.getValue(ParameterKey.AUTOPROGRAMEURL, null);
+//        if (DictionaryKey.INTERFACETYPE_PLC.equals(taskNode.getInterfaceType())) {//总控
+//            autoProgrameUrl = UrlConfConstant.plcURL;
+//        } else if (DictionaryKey.INTERFACETYPE_PRO.equals(taskNode.getInterfaceType())) {
+////            autoProgrameUrl = parameterService.getValue(ParameterKey.AUTOPROGRAMEURL, null);
+//            autoProgrameUrl = UrlConfConstant.plcURL;
+//        } else if (DictionaryKey.INTERFACETYPE_AGV.equals(taskNode.getInterfaceType())) {
+////            autoProgrameUrl = parameterService.getValue(ParameterKey.AGVPROGRAMEURL, null);
+//            autoProgrameUrl = UrlConfConstant.agvURL;
+//        } else if (DictionaryKey.INTERFACETYPE_WMS.equals(taskNode.getInterfaceType())) {
+////            autoProgrameUrl = parameterService.getValue(ParameterKey.AGVPROGRAMEURL, null);
+//            // autoProgrameUrl = agvURL;
+//            autoProgrameUrl = UrlConfConstant.url;
+//        }
+        //根据设备类型关联接口
+        if("1".equals(taskNode.getAutoNode().getCategory()) || "3".equals(taskNode.getAutoNode().getCategory())){
             autoProgrameUrl = UrlConfConstant.plcURL;
-        } else if (DictionaryKey.INTERFACETYPE_AGV.equals(taskNode.getInterfaceType())) {
-//            autoProgrameUrl = parameterService.getValue(ParameterKey.AGVPROGRAMEURL, null);
+        }else if("2".equals(taskNode.getAutoNode().getCategory())){
             autoProgrameUrl = UrlConfConstant.agvURL;
-        } else if (DictionaryKey.INTERFACETYPE_WMS.equals(taskNode.getInterfaceType())) {
-//            autoProgrameUrl = parameterService.getValue(ParameterKey.AGVPROGRAMEURL, null);
-            // autoProgrameUrl = agvURL;
+        }else if("4".equals(taskNode.getAutoNode().getCategory())){
+            //目前默认是wms
             autoProgrameUrl = UrlConfConstant.url;
         }
         //正式调试的时候注释掉
@@ -390,7 +401,8 @@ public class TaskWorkNode {
             Map map = nodeOperationService.operation(jsonObject, bizJsonObject, conMap);
             jsonObject = (JSONObject) map.get("jsonObject");
             bizJsonObject = (JSONObject) map.get("bizJsonObject");
-        } else if (DictionaryKey.INTERFACETYPE_AGV.equals(taskNode.getInterfaceType())) {
+        }
+        else if (DictionaryKey.INTERFACETYPE_AGV.equals(taskNode.getInterfaceType())) {
             //AGV取料
             nodeOperationService = new AGVNodeServiceImpl();
             Map map = nodeOperationService.operation(jsonObject, bizJsonObject,conMap);
@@ -507,6 +519,8 @@ public class TaskWorkNode {
         } else if("4" == category){
             nodeOperationService  = new OtherNodeServiceImpl();
         }
+        //初始化设备资源
+        nodeOperationService.initResource(taskNode, task, map);
 
         //线边库轮询两个机械手和接驳位资源。如果两个都有空则从线边库搬运到接驳位
         if (BizConstant.MQ_TASK_NODE_TYPE_STORAGE_WAIT_ZLZX.equals(bizType)) {
@@ -554,7 +568,8 @@ public class TaskWorkNode {
                     }
                     //机器人和托板有空位
                     map.put("result", plantStorge != null && CollectionUtil.isNotEmpty(jqrList));
-                } else if (currCount == 2) {
+                }
+                else if (currCount == 2) {
                     Storge jqrStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CIRCULATION_STORAGE + "_" + task.getCompleteBatchNo());
                     Object plantStorge = msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.TB + taskNode.getId());
                     map.put("fromStorge", jqrStorge);

+ 6 - 7
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/TaskNodeServiceImpl.java

@@ -233,7 +233,7 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
                             //.setNodeNo(autoNode.getNodeNo())
                             .setExeStatus("1").setPrority(autoNode.getWeight());
                     //if (autoNode.getInterfaceType() != null) {
-                      //  taskNode.setInterfaceType(autoNode.getInterfaceType().getKey());
+                     //   taskNode.setInterfaceType();
                     //}
                     //是否延迟
                     taskNode
@@ -280,7 +280,7 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
 //        List<ResourceBusiness>resourceBusinessList = resourceBusinessService.list();
 //        Map<Long, ResourceBusiness> resourceBusinessMap = resourceBusinessList.stream().collect(Collectors.toMap(ResourceBusiness::getId, t->t));
 
-        List<ResourceAutoCode> resourceAutoCodeList = resourceAutoCodeService.list(Wraps.<ResourceAutoCode>lbQ().orderByDesc(ResourceAutoCode::getWeight));
+        List<ResourceAutoCode> resourceAutoCodeList = resourceAutoCodeService.list(Wraps.<ResourceAutoCode>lbQ().orderByAsc(ResourceAutoCode::getWeight));
         Map<Long, List<ResourceAutoCode>> resourceAutoCodeMap = resourceAutoCodeList.stream().collect(groupingBy(ResourceAutoCode::getBusinessId));
 
         List<TaskNode> taskNodeList = new ArrayList<TaskNode>();
@@ -300,10 +300,9 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
 //                    taskNode.setAutoNode(autoNode).setAutoNodeCode(autoNode.getCode()).setCompleteBatchNo(t.getCompleteBatchNo())
 //                            .setNodeNo(autoNode.getNodeNo()).setExeStatus("1").setPrority(autoCode.getWeight());
                         taskNode.setTaskId(t.getId()).setOrderId(t.getOrderId())
-                                .setResourceId(getResourceIdByAutoCode(autoCode))
+                                .setResourceId(getResourceIdByAutoCode(t, autoCode))
                                 .setTaskNodeNo(codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_TASK_NODE));
-                        taskNode.setNodeNo(autoCode.getNo());
-                        taskNode.setCompleteBatchNo(t.getCompleteBatchNo())
+                        taskNode.setAutoNode(autoCode).setNodeNo(autoCode.getNo()).setCompleteBatchNo(t.getCompleteBatchNo())
                                 .setExeStatus("1").setPrority(autoCode.getWeight());
 //                    if (autoNode.getInterfaceType() != null) {
 //                        taskNode.setInterfaceType(autoNode.getInterfaceType().getKey());
@@ -354,8 +353,8 @@ public class TaskNodeServiceImpl extends SuperServiceImpl<TaskNodeMapper, TaskNo
      * @param autoCode
      * @return
      */
-    private Long getResourceIdByAutoCode(ResourceAutoCode autoCode){
-        Long resourceId = 0L;
+    private Long getResourceIdByAutoCode(TTask task, ResourceAutoCode autoCode){
+        Long resourceId = autoCode.getCategory()=="1"? task.getResourceId(): 0L;
         return resourceId;
     }
 

+ 0 - 2
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/NodeOperationService.java

@@ -28,6 +28,4 @@ public interface NodeOperationService {
 
     public boolean confirmStatus(TaskNode taskNode);
 
-    public void move(Storge fromStorge, Storge toStorage);
-
 }

+ 103 - 29
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/productionResourceCenter/service/impl/OtherNodeServiceImpl.java

@@ -5,8 +5,10 @@ import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.zuihou.business.DemoLine.DemoLineConstant;
 import com.github.zuihou.business.edgeLibrary.entity.Storge;
+import com.github.zuihou.business.edgeLibrary.service.StorgeService;
 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.productionResourceCenter.dao.ResourceAutoCodeMapper;
 import com.github.zuihou.business.productionResourceCenter.entity.ProductionresourcePosition;
 import com.github.zuihou.business.productionResourceCenter.entity.ResourceAutoCode;
@@ -27,6 +29,8 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Collectors;
 
 
@@ -43,7 +47,7 @@ public class OtherNodeServiceImpl implements NodeOperationService {
     private ProductionresourcePositionService productionresourcePositionService;
 
     @Autowired
-    private ResourceAutoCodeMapper resourceAutoCodeMapper;
+    private TaskNodeService taskNodeService;
 
     private String[] jbwArr;
 
@@ -53,6 +57,11 @@ public class OtherNodeServiceImpl implements NodeOperationService {
 
     private List<ProductionresourcePosition> jbwList;
 
+    @Autowired
+    private StorgeService storgeService;
+
+    private final ReentrantLock lock = new ReentrantLock(true);
+    private final Condition condition = lock.newCondition();
 
     @Override
     public void initResource(TaskNode taskNode, TTask task, Map dataMap) {
@@ -65,17 +74,17 @@ public class OtherNodeServiceImpl implements NodeOperationService {
             }
         }
         //初始化默认设定(后期动态获取)
-        xbkArr = new String[]{DemoLineConstant.NODE_RESOURCE_ZLZX_XBK};
+        xbkArr = dataMap.get("bizType")!=null? new String[]{dataMap.get("bizType").toString()}: new String[]{DemoLineConstant.NODE_RESOURCE_ZLZX_XBK};
         xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(xbkArr);
     }
 
     @Override
     public Map checkCondition(TaskNode taskNode, TTask task, Map<String, Object> dataMap) {
-        //判断
         ResourceAutoCode resourceAutoCode = taskNode.getAutoNode();
         String command = resourceAutoCode.getCommand();
         String moduleName = dataMap.get("moduleName") == null ? "" : dataMap.get("moduleName").toString();
         boolean bool = true;
+        Storge storge = null;
         //List<ModuleInstruction> instructions = dataMap.get("instructions") == null ? Lists.newArrayList() : (List<ModuleInstruction>)dataMap.get("instructions");
         switch(moduleName){
             case "WMS":
@@ -90,40 +99,75 @@ public class OtherNodeServiceImpl implements NodeOperationService {
                     bool =  productionresourcePosition!=null ? true : false;
                     //更新后续节点设备ID
                     if(bool){
-                        ResourceAutoCode autoCode = new ResourceAutoCode();
-                        autoCode.setWeight(resourceAutoCode.getWeight()+ 1);
-                        autoCode.setBusinessId(autoCode.getBusinessId());
-                        ResourceAutoCode nextAutoCode = resourceAutoCodeMapper.getNextCode(autoCode);
-                        if(nextAutoCode!=null && !nextAutoCode.isFinal()){
-                            nextAutoCode.setResourceId(productionresourcePosition.getResourceId());
-                            resourceAutoCodeMapper.updateById(nextAutoCode);
+                        TaskNode nextCode = taskNodeService.getNextNTaskNode(taskNode, 1);
+                        //锁定后续节点
+                        if(nextCode!=null && nextCode.getResourceId() == 0L) {
+                            //锁定后续接驳位
+                            nextCode.setResourceId(productionresourcePosition.getResourceId());
+                            taskNodeService.updateById(nextCode);
                         }
+                        //锁定点位
+                        storge = storgeService.getById(productionresourcePosition.getStorgeId());
+                        if("1".equals(storge.getLockStatus())) {
+                            storge.setCompleteBatchNo(task.getCompleteBatchNo());
+                            //同步更新库位锁定
+                            this.syncStorage(storge, true, nextCode.getId());
+                            map.put("toStorge", storge);
+                        }
+                    }else{
+                        map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
                     }
+
                 }
                 else if("WMS_IN".equals(command)){
                     //获取当前节点设备ID
-                    String resourceId = resourceAutoCode.getResourceId().toString();
+                    long resourceId = taskNode.getResourceId();
                     ProductionresourcePosition resourcePosition = productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getResourceId, resourceId));
-                    bool = resourcePosition.getLockStatus() == "1" && resourcePosition.getStatus() == "1";
-                    //判断是否存有产品 待定
+                    bool = resourcePosition.getLockStatus() == "1" && resourcePosition.getStatus() == "1" && resourcePosition.getHaveGoods() == "1";
 
-                    if(!bool){
-                        map.put("msg", DictionaryKey.NodeException.NO_RESROURCE);
+                    if(bool){
+                        storge = storgeService.getById(resourcePosition.getStorgeId());
+                        this.syncStorage(storge, false, null);
+                        map.put("fromStorge", storge);
+                    }else{
+                        map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
                     }
                 }
                 map.put("result", bool);
                 break;
         }
+        map.put("command", command);
         map.put("moduleName", moduleName);
         return map;
     }
 
     @Override
     public Map operation(JSONObject jsonObject, JSONObject bizJsonObject, Map<String, Object> map) {
+        //调用接口执行操作指令
+        String  moduleName = map.get("moduleName") == null ? "" : map.get("moduleName").toString();
+        String  command = map.get("command") == null ? "" : map.get("command").toString();
+        TTask task = (TTask) map.get("task");
+        switch(moduleName) {
+            case "WMS":
+                jsonObject.put("jobType", command);
+                if("WMS_OUT".equals(command)){
+                    //毛坯出库
+                    jsonObject.put("goodsId", task.getMeterialId());
+                }else{
+                    //成品入库
+                    jsonObject.put("goodsId", task.getBomId());
+                }
+                Storge fstorge = (Storge) map.get("fromStorge");
+                Storge tstorge = (Storge) map.get("toStorge");
+                bizJsonObject.put("srcPosition", fstorge == null ? "" : fstorge.getId().toString());
+                bizJsonObject.put("targetPosition", tstorge == null ? "" : tstorge.getId().toString());
+            break;
+        }
+        //调用指令操作 处理返回值  待定
 
-
-
-        return null;
+        map.put("jsonObject", jsonObject);
+        map.put("bizJsonObject", bizJsonObject);
+        return map;
     }
 
     @Override
@@ -131,10 +175,6 @@ public class OtherNodeServiceImpl implements NodeOperationService {
         return false;
     }
 
-    @Override
-    public void move(Storge fromStorge, Storge toStorage) {
-
-    }
 
     /**
      *  设备动态逻辑判断处理
@@ -144,22 +184,26 @@ public class OtherNodeServiceImpl implements NodeOperationService {
      * @return
      */
     private ProductionresourcePosition logical(List<ProductionresourcePosition> deviceList, boolean useXbk){
-        boolean bool = true;
         //设备不存在
         if(deviceList == null || deviceList.size() == 0){
-            map.put("msg", DictionaryKey.NodeException.NO_RESROURCE);
+            map.put("msg", DictionaryKey.NodeException.NO_RESOURCE);
             return null;
         }
-        deviceList = deviceList.stream().filter(position->position.getStatus() =="1" && position.getLockStatus()=="0").collect(Collectors.toList());
+        deviceList = deviceList.stream().filter(position->position.getStatus()=="1" && position.getLockStatus()=="1").collect(Collectors.toList());
         //设备被锁定
-        if(deviceList == null || deviceList.size() == 0){
+        if(deviceList.size() == 0) {
+            if(useXbk){
+                if(xbkList.size() == 0){
+                    map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
+                    return null;
+                }
+                return xbkList.get(0);
+            }
             map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
             return null;
         }
-        //线边库判断处理
-        if(useXbk){
+        //设备托盘、夹具条件不满足  待定
 
-        }
         return deviceList.get(0);
     }
 
@@ -176,4 +220,34 @@ public class OtherNodeServiceImpl implements NodeOperationService {
       return true;
     }
 
+    /**
+     * 库位处理
+     *
+     * @param storge
+     * @param isLock
+     * @param storgeId
+     */
+    private void syncStorage(Storge storge, boolean isLock, Long storgeId){
+        lock.lock();
+        try {
+            if(isLock){
+                if (storge == null){
+                    //等待
+                    condition.await();
+                }
+                storgeService.lockStorge(storge, storgeId);
+            }else{
+                if(storge == null || storge.getLockStatus() == "1"){
+                    condition.await();
+                }
+                storgeService.unlockStorge(storge);
+            }
+        }
+        catch(InterruptedException ex){
+            ex.getStackTrace();
+        }
+        finally {
+            lock.unlock();
+        }
+    }
 }

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

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