|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.github.zuihou.base.R;
|
|
|
import com.github.zuihou.business.DemoLine.DemoCacheKey;
|
|
|
import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
+import com.github.zuihou.business.DemoLine.YunjianConstant;
|
|
|
import com.github.zuihou.business.edgeLibrary.dao.StockInfoMapper;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
@@ -71,6 +72,8 @@ import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
+import static java.util.stream.Collectors.groupingBy;
|
|
|
+
|
|
|
@Component
|
|
|
public class TaskWorkNode {
|
|
|
@Autowired
|
|
@@ -435,90 +438,187 @@ public class TaskWorkNode {
|
|
|
|
|
|
/**
|
|
|
* 线边库条件处理判断
|
|
|
- * @param map
|
|
|
+ * @param dataMap
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
- public Map checkXbkCon(TaskNode taskNode,TTask task, Map<String, Object> map){
|
|
|
-// if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(taskNode.))){
|
|
|
-//
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ public Map checkXbkCon(TaskNode taskNode,TTask task, Map<String, Object> dataMap){
|
|
|
+ ZZone zone = dataMap.get("zone")==null?null:(ZZone)dataMap.get("zone");
|
|
|
+ int count = Integer.parseInt (dataMap.get(taskNode.getId().toString() + "count") == null ? "0" : dataMap.get(taskNode.getId().toString() + "count").toString());
|
|
|
+
|
|
|
+ Storge jqrStorge = null;
|
|
|
+
|
|
|
+ Storge targetStorge = null;
|
|
|
+
|
|
|
+ List<ProductionresourcePosition> robotList = null;
|
|
|
+ if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(zone.getName()))){//有缓存位的机器人
|
|
|
+ //执行到第几步
|
|
|
+ dataMap.put(taskNode.getId().toString() + "count", count);
|
|
|
+ dataMap.put(YunjianConstant.YUNJIAN_XBK_CACHE_FLAG, "1");
|
|
|
+
|
|
|
+ if (count == 0) {//第一步的时候锁定资源
|
|
|
+ //判断机器人是否为空
|
|
|
+ Map<String, List<ProductionresourcePosition>> jqrMap = robotList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
|
|
|
+
|
|
|
+ robotList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {taskNode.getResourceId().toString()});
|
|
|
+ //目标地址和类型
|
|
|
+ targetStorge = workpieceService.getWorkPieceTargetStock(taskNode.getId());
|
|
|
+
|
|
|
+ jqrStorge = storgeService.getById(robotList.get(0).getStorgeId());
|
|
|
+
|
|
|
+ Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
|
|
|
+
|
|
|
+ //机器人手抓没被锁定,并且有空闲未知
|
|
|
+ if (logical(robotList,targetStorge,zone)!=null) {
|
|
|
+ jqrStorge = storgeService.getById(jqrMap.get(DemoLineConstant.DEMOLINE_RJQR_ZS).get(0).getStorgeId());
|
|
|
+ jqrStorge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(jqrStorge, taskNode.getId());
|
|
|
+ //锁定一个缓存位
|
|
|
+ List<ProductionresourcePosition> hcwList = jqrMap.get(jqrMap.keySet().stream().filter(p -> !DemoLineConstant.DEMOLINE_RJQR_ZS.equals(p)).findFirst().get());
|
|
|
+ Storge hcwStorge = storgeService.getById(hcwList.get(0).getStorgeId());
|
|
|
+ hcwStorge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(hcwStorge, taskNode.getId());
|
|
|
+
|
|
|
+ //锁定目标库位
|
|
|
+ targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(targetStorge, taskNode.getId());
|
|
|
+
|
|
|
+ //抓手缓存
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId(), jqrStorge, 1, TimeUnit.DAYS);
|
|
|
+ //缓存位缓存
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + taskNode.getId(), hcwStorge, 1, TimeUnit.DAYS);
|
|
|
+ //目标缓存
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 1, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ //满足条件--机器人空闲,设备或线边库有一个空闲
|
|
|
+ dataMap.put("Data", startStore);
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
|
|
|
+ }
|
|
|
+ dataMap.put("result", logical(robotList,targetStorge,zone));
|
|
|
+ } else if (count == 1) {
|
|
|
+ jqrStorge = (Storge) msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
|
|
|
+ Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
|
|
|
+ dataMap.put("fromStorge", currentStore);
|
|
|
+ dataMap.put("Data", currentStore);
|
|
|
+ //出入库类型
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
|
|
|
+ //目的地为机器人手臂
|
|
|
+ dataMap.put("toStorge", jqrStorge);
|
|
|
+ dataMap.put("result", true);
|
|
|
+ } else if (count == 2) {
|
|
|
+ Storge currentStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "putMaterial");
|
|
|
+ dataMap.put("fromStorge", currentStore);
|
|
|
+ //出入库类型
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
|
|
|
+ //目的地为机器人手臂
|
|
|
+ Storge hcwStorge = (Storge) msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + taskNode.getId());
|
|
|
+ dataMap.put("Data", hcwStorge);
|
|
|
+ dataMap.put("toStorge", hcwStorge);
|
|
|
+ dataMap.put("result", true);
|
|
|
+ }if(count==3) {
|
|
|
+ dataMap.put("Data", targetStorge);
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "moveMaterial");
|
|
|
+ }else if(count == 4){//从缓存位拿出来
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"fetchMaterial");
|
|
|
+ Storge hcwStorge = (Storge)msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + YunjianConstant.YUNJIAN_HCW + taskNode.getId());
|
|
|
+ dataMap.put("Data", hcwStorge);
|
|
|
+ dataMap.put("fromStorge", hcwStorge);
|
|
|
+ Storge handStorge = (Storge)msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
|
|
|
+ dataMap.put("toStorge", handStorge);
|
|
|
+ //出入库类型
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
|
|
|
+ }else if(count == 5){
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"putMaterial");
|
|
|
+ //出入库类型
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE,DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
|
|
|
+ dataMap.put("Data", targetStorge);
|
|
|
+ dataMap.put("toStorge", targetStorge);
|
|
|
+
|
|
|
+ Storge handStorge = (Storge)msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId());
|
|
|
+ dataMap.put("fromStorge", handStorge);
|
|
|
+ }
|
|
|
+ }else {//没缓存位的机器人,伺服陀机
|
|
|
+
|
|
|
+ if (count == 0) {//第一步的时候锁定资源
|
|
|
+ //目标地址和类型
|
|
|
+ targetStorge = workpieceService.getWorkPieceTargetStock(taskNode.getId());
|
|
|
+ robotList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[] {taskNode.getResourceId().toString()});
|
|
|
+ //目标地址和类型
|
|
|
+ jqrStorge = storgeService.getById(robotList.get(0).getStorgeId());
|
|
|
+
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE, "fetchMaterial");
|
|
|
+ if (logical(robotList,targetStorge,zone)!=null) {
|
|
|
+ Storge startStore = workpieceService.getWorkPieceStock(taskNode.getId(), false);
|
|
|
+
|
|
|
+ dataMap.put("fromStorge", startStore);
|
|
|
+ dataMap.put("Data", startStore);
|
|
|
+ //出入库类型
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_ALL_CRK);
|
|
|
+ //目的地为机器人手臂
|
|
|
+ dataMap.put("toStorge", jqrStorge);
|
|
|
+ //锁定机器人
|
|
|
+ jqrStorge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(jqrStorge, taskNode.getId());
|
|
|
+
|
|
|
+ //锁定目标库位
|
|
|
+ targetStorge.setCompleteBatchNo(task.getCompleteBatchNo());
|
|
|
+ storgeService.lockStorge(targetStorge, taskNode.getId());
|
|
|
+
|
|
|
+ //抓手缓存
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.JQR3 + taskNode.getId(), jqrStorge, 1, TimeUnit.DAYS);
|
|
|
+ //目标缓存
|
|
|
+ msgUtil.redis_set(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId(), targetStorge, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
+ }else if(count==1){
|
|
|
+ targetStorge = msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId())==null?null:(Storge) msgUtil.redis_get(DemoCacheKey.YUNJIAN_CAMP + "_" + DemoLineConstant.YUNJIAN_TARGET_STORE + taskNode.getId());
|
|
|
+ dataMap.put(DemoLineConstant.DEMOLINE_BIZ_TYPE,"putMaterial");
|
|
|
+ dataMap.put("toStorge", targetStorge);
|
|
|
+ dataMap.put("Data", targetStorge);
|
|
|
+ }
|
|
|
+ dataMap.put("result", true);
|
|
|
+ }
|
|
|
+ return dataMap;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
+ * 设备动态逻辑判断处理
|
|
|
+ *
|
|
|
+ * @param robotList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ProductionresourcePosition logical(List<ProductionresourcePosition> robotList,Storge targetStorge,ZZone zone){
|
|
|
+ //设备不存在
|
|
|
+ if(checkRobot(robotList,zone.getName())){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //资源临界判断
|
|
|
+ int current_running_num = storgeService.getstorgeByZone(zone.getId().toString());
|
|
|
+ if(current_running_num == DictionaryKey.RESOURCE_MAX_NUM){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- Storge xbkStorage = workpieceService.getWorkPieceStock(taskNode.getId(),false);
|
|
|
- //判断线边库是否被锁定占用
|
|
|
- if(xbkStorage.getLockStatus()=="1"){
|
|
|
- //线边库已经释放锁定 不需要相关操作
|
|
|
- map.put("msg", DictionaryKey.NodeException.RUNNING_FALSE);
|
|
|
- map.put("result", false);
|
|
|
- }else{
|
|
|
- // 获取锁定节点ID
|
|
|
- Long campId = xbkStorage.getCampId();
|
|
|
- // 获取锁定节点
|
|
|
- TWorkpiece workpiece = workpieceService.getWorkPiece(campId);
|
|
|
- // 锁定节点对应设备ID
|
|
|
- Long targetId = Long.parseLong(workpiece.getTpointId());
|
|
|
- if(!taskNodeService.getRunStatus(targetId)){
|
|
|
- map.put("result", false);
|
|
|
- map.put("msg", DictionaryKey.NodeException.RUNNING_FALSE);
|
|
|
- return map;
|
|
|
- }
|
|
|
- //获取目标设备的点位信息
|
|
|
- ProductionresourcePosition resourcePosition = productionresourcePositionService.getOne(new LbqWrapper<ProductionresourcePosition>().eq(ProductionresourcePosition::getResourceId, targetId));
|
|
|
- Productionresource productionresource = productionresourceBizMapper.selectOne(new LbqWrapper<Productionresource>().eq(Productionresource::getId, targetId));
|
|
|
- //任意设备条件判断
|
|
|
- boolean bool = resourcePosition!=null && resourcePosition.getLockStatus() == "1" && resourcePosition.getStatus() == "1" && resourcePosition.getHaveGoods() == "0";
|
|
|
- Storge storge = null;
|
|
|
- if(productionresource.getModuleDesc()=="接驳位"){
|
|
|
- //目标对象是接驳位上托盘的库位
|
|
|
- String[] jbwarr = new String[]{productionresource.getCode()};
|
|
|
- //获取托盘的库位
|
|
|
-// Map plateMap = storgeService.getPlateStorgeByNo(jbwarr, task.getCompleteBatchNo());
|
|
|
-// storge = plateMap.get("storge") == null ? null : (Storge) plateMap.get("storge");
|
|
|
-// bool = bool && (storge!=null );
|
|
|
- }else{
|
|
|
- //目标地址是加工设备
|
|
|
- storge = storgeService.getById(resourcePosition.getStorgeId());
|
|
|
- bool = bool && (storge!=null && storge.getLockStatus() == "1" && storge.getId() == workpiece.getTaskNodeId());
|
|
|
- }
|
|
|
- if(bool){
|
|
|
- //预先锁定目标设备
|
|
|
- storgeService.lockStorge(storge, taskNode.getId());
|
|
|
- //实现移动操作到具体设备
|
|
|
+ if(targetStorge==null){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- //线边库解锁
|
|
|
- storgeService.unlockStorge(xbkStorage);
|
|
|
- //更新workpiece的库位信息
|
|
|
+ return robotList.get(0);
|
|
|
+ }
|
|
|
|
|
|
- }else{
|
|
|
- map.put("msg", DictionaryKey.NodeException.RESOURCE_LOCK);
|
|
|
- }
|
|
|
- map.put("result", bool);
|
|
|
+ /**
|
|
|
+ * 判断机器人是否可用
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean checkRobot(List<ProductionresourcePosition> robotList,String zoneName){
|
|
|
+ if(BizConstant.ROBOT_TYPE_NOCACHE.equals(zoneService.getRobotTypebyZone(zoneName))){
|
|
|
+ return CollectionUtil.isNotEmpty(robotList) && robotList.size() == 1;
|
|
|
+ }else if(BizConstant.ROBOT_TYPE_CACHE.equals(zoneService.getRobotTypebyZone(zoneName))){//手抓必须空闲。
|
|
|
+ Map<String, List<ProductionresourcePosition>> jqrMap = robotList.stream().collect(groupingBy(ProductionresourcePosition::getPointId));
|
|
|
+ return CollectionUtil.isNotEmpty(robotList) && robotList.size() >1&&jqrMap.containsKey(DemoLineConstant.DEMOLINE_RJQR_ZS);
|
|
|
}
|
|
|
- return map;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|
|
|
|