|
@@ -46,12 +46,15 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static java.util.stream.Collectors.groupingBy;
|
|
|
+
|
|
|
@Component("CACHE")
|
|
|
@Slf4j
|
|
|
public class CacheRobotStrategy implements RobotStrategy {
|
|
@@ -108,7 +111,6 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
|
|
|
com.github.zuihou.business.productionResourceCenter.entity.Productionresource robot = productionresourceBizMapper.selectById(taskNode.getResourceId());
|
|
|
ZZoneProductionresource zoneProductionresource = zZoneProductionresourceMapper.selectOne(Wraps.<ZZoneProductionresource>lbQ().eq(ZZoneProductionresource::getResourceId, taskNode.getResourceId()));
|
|
|
- List<ProductionresourcePosition> robotList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{taskNode.getResourceId().toString()});
|
|
|
ZZone zZone = zoneService.getOne(new LbqWrapper<ZZone>().eq(ZZone::getName, zoneName).last("limit 1"));
|
|
|
Plan orderPlan = planService.getById(task.getPlanId());
|
|
|
BBom bom = bBomMapper.selectById(task.getBomId());
|
|
@@ -124,7 +126,7 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
robotInfo.put("bomzZone", bomzZone);
|
|
|
robotInfo.put("plcInfo", plcInfo);
|
|
|
robotInfo.put("singleRunFlag", orderPlan.getSingleRunFlag());
|
|
|
- robotInfo.put("robotList", robotList);
|
|
|
+ //robotInfo.put("robotList", robotList);
|
|
|
//robotInfo.put("xbkList", xbkList);
|
|
|
|
|
|
return robotInfo;
|
|
@@ -156,7 +158,7 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
Storge targetStorge = !returnMap.containsKey("store") ? null : (Storge) returnMap.get("store");
|
|
|
Long targetStorgeResourceId = !returnMap.containsKey("storeResourceId") ? null : Long.valueOf(returnMap.get("storeResourceId").toString());
|
|
|
|
|
|
- if (targetStorge == null) {
|
|
|
+ if (ObjectUtil.isEmpty(targetStorge)) {
|
|
|
dataMap.put("result", false);
|
|
|
dataMap.put("resultmsg","目标点位不满足,线边库不符合要求存放");
|
|
|
return dataMap;
|
|
@@ -164,7 +166,7 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
String targetXbk = !returnMap.containsKey("targetxbk") ? null : returnMap.get("targetxbk").toString();
|
|
|
|
|
|
//处理机器人库位
|
|
|
- List<ProductionresourcePosition> robotList = (List<ProductionresourcePosition>) robotInfo.get("robotList");
|
|
|
+ List<ProductionresourcePosition> robotList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{taskNode.getResourceId().toString()});
|
|
|
Map putMap = this.robotPut(returnMap, taskNode, startStore, targetStorge, robotList, targetXbk, targetStorgeResourceId);
|
|
|
return putMap;
|
|
|
}
|
|
@@ -173,73 +175,96 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
public Map robotPut(Map returnMap, TaskNode taskNode, Storge startStorge, Storge targetStorge, List<ProductionresourcePosition> robotList, String targetXbk, Long targetStorgeResourceId) {
|
|
|
|
|
|
Map<String, List<ProductionresourcePosition>> jqrMap = robotList.stream().collect(Collectors.groupingBy(ProductionresourcePosition::getPointId));
|
|
|
- //Storge jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
|
|
|
- //TaskNode nextTaskNode = taskNodeService.getNextNTaskNode(taskNode,1);
|
|
|
|
|
|
//锁定机器人抓手
|
|
|
Storge jqrStorge = null;
|
|
|
- try {
|
|
|
- jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
|
|
|
-
|
|
|
- if(jqrStorge == null){
|
|
|
- throw new BizException("没有查询到可执行的关节机器人");
|
|
|
- }
|
|
|
- }catch (Exception e){
|
|
|
- throw new BizException("没有查询到可执行的关节机器人");
|
|
|
+ List<ProductionresourcePosition> jqrList = jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS);
|
|
|
+ if(jqrList.size() == 0){
|
|
|
+ returnMap.put("result", false);
|
|
|
+ return returnMap;
|
|
|
+ }else {
|
|
|
+ jqrStorge = storgeService.getById(jqrList.get(0).getStorgeId());
|
|
|
+ if (null == jqrStorge) {
|
|
|
+ returnMap.put("result", false);
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- jqrStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
- storgeService.lockStorge(jqrStorge, taskNode.getId());
|
|
|
-
|
|
|
- List<ProductionresourcePosition> hcwList = jqrMap.get(jqrMap.keySet().stream().filter(p -> !DemoLineConstant.DEMOLINE_RJQR_ZS.equals(p) && !DemoLineConstant.DEMOLINE_RJQR_SIX.equals(p)).findFirst().get());
|
|
|
+ List<ProductionresourcePosition> hcwList = robotList.stream().filter(p -> !DemoLineConstant.DEMOLINE_RJQR_ZS.equals(p.getPointId())).collect(Collectors.toList());
|
|
|
if (hcwList.size() == 0) {
|
|
|
//限定抓手交换功能
|
|
|
- boolean hasJqrhcwPartFlag = false;
|
|
|
- List<Long> hcwStorgeIdList = hcwList.stream().map(ProductionresourcePosition::getStorgeId).collect(Collectors.toList());
|
|
|
+ List<Long> hcwStorgeIdList = productionresourcePositionService.list(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getResourceId, taskNode.getResourceId()).ne(ProductionresourcePosition::getPointId, DemoLineConstant.DEMOLINE_RJQR_ZS)).stream().map(ProductionresourcePosition::getStorgeId).collect(Collectors.toList());
|
|
|
List<TWorkpiece> workpieceList = workpieceService.list(new LbqWrapper<TWorkpiece>().eq(TWorkpiece::getIsEnd, "0").in(TWorkpiece::getStorgeId, hcwStorgeIdList));
|
|
|
if (workpieceList.size() > 2 || workpieceList.size() == 0) {
|
|
|
msgUtil.createWarnLog("机器人设备暂存位数据有误", "DataException");
|
|
|
returnMap.put("result", false);
|
|
|
}
|
|
|
-
|
|
|
- for (TWorkpiece item : workpieceList) {
|
|
|
- long jqrHcwStorgeTaskNodeId = item.getTaskNodeId();
|
|
|
- Object hcwStorgeFlag = msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + jqrHcwStorgeTaskNodeId);
|
|
|
- TaskNode hcwTaskNode = taskNodeService.getById(jqrHcwStorgeTaskNodeId);
|
|
|
- boolean bool = ObjectUtil.isNotEmpty(hcwStorgeFlag) && hcwTaskNode.getTargetResourceId().equals(taskNode.getTargetResourceId()) && taskNode.getCompleteBatchNo() != hcwTaskNode.getCompleteBatchNo();
|
|
|
- if (bool) {
|
|
|
- hasJqrhcwPartFlag = true;
|
|
|
- msgUtil.redis_set(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + jqrHcwStorgeTaskNodeId, "1");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (hasJqrhcwPartFlag) {
|
|
|
+ Object jqrPriotyFlag = msgUtil.redis_get(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + taskNode.getId());
|
|
|
+ if(ObjectUtil.isNotEmpty(jqrPriotyFlag)){
|
|
|
returnMap.put("result", false);
|
|
|
return returnMap;
|
|
|
}
|
|
|
+
|
|
|
+ TWorkpiece workpiece = workpieceList.stream().filter(item->!item.getTaskNodeId().equals(taskNode.getId())).collect(Collectors.toList()).get(0);
|
|
|
+ Object hcwStorgeFlag = msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + workpiece.getTaskNodeId());
|
|
|
+ if(ObjectUtil.isEmpty(hcwStorgeFlag)){
|
|
|
+ Object hcwPriotyFlag = msgUtil.redis_get(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + workpiece.getTaskNodeId());
|
|
|
+ TTask task = taskService.getById(taskNode.getTaskId());
|
|
|
+ //判断交换位目标设备是否与暂存位任务设备一致
|
|
|
+ if(ObjectUtil.isEmpty(hcwPriotyFlag) && taskNode.getTargetResourceId().equals(task.getResourceId())) {
|
|
|
+ msgUtil.redis_set(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + workpiece.getTaskNodeId(), "1");
|
|
|
+ returnMap.put("result", false);
|
|
|
+ return returnMap;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
//锁定暂存缓存位库位
|
|
|
- Storge hcwStorge = storgeService.getById(hcwList.get(0).getStorgeId());
|
|
|
- hcwStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
startStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
- storgeService.lockStorge(hcwStorge, taskNode.getId());
|
|
|
storgeService.lockStorge(startStorge, taskNode.getId());
|
|
|
+ //锁定抓手
|
|
|
+ jqrStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(jqrStorge, taskNode.getId());
|
|
|
|
|
|
- if (hcwList.size() > 1) {
|
|
|
+ //暂存库位作为库位起始位不需重复锁定暂存位
|
|
|
+ ProductionresourcePosition startPosition = productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getStorgeId, startStorge.getId()).last("limit 1"));
|
|
|
+ List<ProductionresourcePosition> hcwFilter = hcwList.stream().filter(p -> p.getResourceId().equals(startPosition.getResourceId())).collect(Collectors.toList());
|
|
|
+ Storge hcwStorge = null;
|
|
|
+ if(hcwFilter.size() == 0 && hcwList.size()>0) {
|
|
|
+ hcwStorge = storgeService.getById(hcwList.get(0).getStorgeId());
|
|
|
+ hcwStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(hcwStorge, taskNode.getId());
|
|
|
+ }else{
|
|
|
+ hcwStorge = startStorge;
|
|
|
+ }
|
|
|
+ Object hcwExecFlag = msgUtil.redis_get(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + taskNode.getId());
|
|
|
+
|
|
|
+ //暂存位判断(暂存位无占用目标位占用 或者 暂存位被占用一个需进行优先级处理判断)
|
|
|
+ if (hcwList.size() > 1 && targetXbk.equals("1")) {
|
|
|
//锁定暂存缓存位库位
|
|
|
targetStorge = hcwStorge;
|
|
|
msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + taskNode.getId(), "1");
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_XBKFLAG, "1");
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_HCW_XBKFLAG, "1");
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 10, TimeUnit.DAYS);
|
|
|
+ }else if(hcwList.size() == 1 && ObjectUtil.isEmpty(hcwExecFlag)){
|
|
|
+ targetStorge = hcwStorge;
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_XBKFLAG, "1");
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_HCW_XBKFLAG, "1");
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 10, TimeUnit.DAYS);
|
|
|
} else {
|
|
|
- //锁定目标线边库库位
|
|
|
- targetStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
- storgeService.lockStorge(targetStorge, taskNode.getId());
|
|
|
+ //暂存位无占用直接处理(即size>1或者size=0)
|
|
|
if (targetXbk.equals("0")) {
|
|
|
//目标缓存
|
|
|
msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 10, TimeUnit.DAYS);
|
|
|
} else {
|
|
|
//目标是线边库
|
|
|
msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_XBK_FLAG + taskNode.getId(), targetXbk, 10, TimeUnit.DAYS);
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_XBKFLAG, "1");
|
|
|
+ returnMap.remove(taskNode.getId().toString()+"count");
|
|
|
}
|
|
|
+ //锁定目标线边库库位
|
|
|
+ targetStorge.setCompleteBatchNo(taskNode.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(targetStorge, taskNode.getId());
|
|
|
}
|
|
|
// 放入线边库或机器人缓存位
|
|
|
log.info("节点{}提前占用机器人抓手{},缓存位{},目标库位{}", taskNode.getId(), jqrStorge.getPointId(), hcwStorge.getPointId(), targetStorge.getPointId());
|
|
@@ -271,12 +296,14 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
locationMap.put("destLocation", targetStorge.getPointId()); //机器人缓存位
|
|
|
locationMap.put("taskType", DictionaryKey.TASK_TYPE.get("CARRY"));
|
|
|
locationMap.put("carryType", "1");
|
|
|
+ returnMap.put(YunjianConstant.YUNJIAN_ROBORT_CACHE_FLAG, "1");
|
|
|
returnMap.put("data", locationMap);
|
|
|
returnMap.put("method", "RobotAction");
|
|
|
returnMap.put("result", true);
|
|
|
returnMap.put("fromStorge", startStorge);
|
|
|
returnMap.put("toStorge", targetStorge);
|
|
|
|
|
|
+
|
|
|
// 机器人移动到redis记录实时位子
|
|
|
msgUtil.redis_set(taskNode.getResourceId() + "postion", startStorge.getPointId());
|
|
|
|
|
@@ -289,25 +316,36 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
@Override
|
|
|
public Map robotXbk(Map dataMap, Map robotInfo, TaskNode taskNode, Storge startStorge, Storge goalStorge, List<ProductionresourcePosition> robotList) {
|
|
|
//暂存位线边库处理
|
|
|
- Object targetHcwXbk = msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + taskNode.getId());
|
|
|
- if(ObjectUtil.isNotEmpty(targetHcwXbk)){
|
|
|
+ //Object targetHcwXbk = msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_HCW_XBK_FLAG + taskNode.getId());
|
|
|
+ //if(ObjectUtil.isNotEmpty(targetHcwXbk)){
|
|
|
Object jqrHcwPartPriotyExec = (null == msgUtil.redis_get(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + taskNode.getId())) ? null : msgUtil.redis_get(DemoLineConstant.JQR_HCW_PART_PRIOTY_EXEC_FLAG + taskNode.getId());
|
|
|
if(ObjectUtil.isNotEmpty(jqrHcwPartPriotyExec)){
|
|
|
robotList = robotList.stream().filter(item->item.getPointId().equals(DemoLineConstant.DEMOLINE_RJQR_ZS) && item.getStatus().equals("0")).collect(Collectors.toList());
|
|
|
}
|
|
|
- }
|
|
|
+ //}
|
|
|
if(robotList.size() == 0 ) {
|
|
|
dataMap.put("result", false);
|
|
|
return dataMap;
|
|
|
}
|
|
|
TTask task = taskService.getById(taskNode.getTaskId());
|
|
|
BomProcedure bomProcedure = bomProcedureMapper.selectOne(Wraps.<BomProcedure>lbQ().eq(BomProcedure::getId,task.getProcedureId()));
|
|
|
- String zoneName = robotInfo.get("zoneName").toString();
|
|
|
+ ZZone zZone = (ZZone) robotInfo.get("zZone");
|
|
|
+ String zoneName = zZone.getName();
|
|
|
List<ProductionresourcePosition> xbkList = productionresourcePositionService.getFreeProductionresourcePositionByNos(DictionaryKey.YJ_ZONE_XBK.get(zoneName).split(","));
|
|
|
|
|
|
Map returnMap = this.robotTarget(taskNode, robotInfo, xbkList, bomProcedure, dataMap);
|
|
|
//线边库处理
|
|
|
- return returnMap;
|
|
|
+ Storge targetStorge = !returnMap.containsKey("store") ? null : (Storge) returnMap.get("store");
|
|
|
+ Long targetStorgeResourceId = !returnMap.containsKey("storeResourceId") ? null : Long.valueOf(returnMap.get("storeResourceId").toString());
|
|
|
+ String targetXbk = !returnMap.containsKey("targetxbk") ? null : returnMap.get("targetxbk").toString();
|
|
|
+ if (ObjectUtil.isNotEmpty(targetXbk) && targetXbk.equals("1")) {
|
|
|
+ dataMap.put("result", false);
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
+ Storge startStore = workpieceService.getWorkPieceStock(taskNode.getCompleteBatchNo(), false);
|
|
|
+ List<ProductionresourcePosition> robotXbkList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{taskNode.getResourceId().toString()});
|
|
|
+ Map putMap = this.robotPut(returnMap, taskNode, startStore, targetStorge, robotXbkList, targetXbk, targetStorgeResourceId);
|
|
|
+ return putMap;
|
|
|
}
|
|
|
|
|
|
public Map robotTarget(TaskNode taskNode, Map robotInfo, List<ProductionresourcePosition> xbkList, BomProcedure bomProcedure, Map<String, Object> returnMap) {
|
|
@@ -389,6 +427,8 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
}
|
|
|
} else {
|
|
|
targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{targetResourceId.toString()});
|
|
|
+ //排除刀具库位
|
|
|
+ targetList = targetList.stream().filter(p->!p.getPointId().contains("CNCT")).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
if (CollectionUtil.isNotEmpty(targetList)) {
|
|
@@ -427,5 +467,4 @@ public class CacheRobotStrategy implements RobotStrategy {
|
|
|
return returnMap;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|