|
@@ -2,6 +2,8 @@ package com.github.zuihou.business.productionResourceCenter.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baidubce.services.tsdb.model.GroupBy;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.github.zuihou.business.DemoLine.DemoLineConstant;
|
|
|
import com.github.zuihou.business.DemoLine.YunjianConstant;
|
|
@@ -22,8 +24,10 @@ import com.github.zuihou.business.productionResourceCenter.service.Productionres
|
|
|
import com.github.zuihou.business.util.MsgUtil;
|
|
|
import com.github.zuihou.common.constant.DictionaryKey;
|
|
|
import com.github.zuihou.common.util.DateUtil;
|
|
|
+import com.github.zuihou.database.mybatis.conditions.Wraps;
|
|
|
import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
|
|
|
import com.google.common.collect.Maps;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.compress.utils.Lists;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -70,133 +74,106 @@ public class AsyncServiceImpl implements AsyncService {
|
|
|
@Async
|
|
|
public Boolean asyncTaskSchedule() {
|
|
|
log.warn("[线边库加工设备重调度]");
|
|
|
- LbqWrapper<Productionresource> lbqWrapper = new LbqWrapper<com.github.zuihou.business.productionResourceCenter.entity.Productionresource>();
|
|
|
- lbqWrapper.eq(com.github.zuihou.business.productionResourceCenter.entity.Productionresource::getStatus, "1").ne(com.github.zuihou.business.productionResourceCenter.entity.Productionresource::getOnlineStatus, "0").isNotNull(com.github.zuihou.business.productionResourceCenter.entity.Productionresource::getModeSpecification);
|
|
|
- //获取全部加工在线的加工设备
|
|
|
- List<Productionresource> macProductionResources = productionresourceBizMapper.selectList(lbqWrapper);
|
|
|
- //获取未处于加工状态的加工设备
|
|
|
- List<com.github.zuihou.business.productionResourceCenter.entity.Productionresource> bizProductionResources = macProductionResources.stream().filter(item -> item.getOnlineStatus().equals("1")).collect(Collectors.toList());
|
|
|
-
|
|
|
- if (bizProductionResources.size() > 0) {
|
|
|
- List<Long> macResourceIds = macProductionResources.stream().map(com.github.zuihou.business.productionResourceCenter.entity.Productionresource::getId).collect(Collectors.toList());
|
|
|
- //获取线边库加工任务列表(模糊匹配舱体和框体线边库)
|
|
|
- List<Long> storgeIds = storgeService.list(new LbqWrapper<Storge>().eq(Storge::getLockStatus, "1").like(Storge::getName, "T_库位")).stream().map(Storge::getId).collect(Collectors.toList());
|
|
|
- //获取线边库零件编号
|
|
|
+ LbqWrapper<Productionresource> lbqWrapper = new LbqWrapper<Productionresource>();
|
|
|
+ lbqWrapper.eq(Productionresource::getStatus, "1").eq(Productionresource::getOnlineStatus, "1").isNotNull(Productionresource::getModeSpecification);
|
|
|
+ //获取当前处于空闲状态的设备(排除正在加工以及报错的机床)
|
|
|
+ List<Productionresource> bizProductionResources = productionresourceBizMapper.selectList(lbqWrapper);
|
|
|
+ //判断库位空闲机床
|
|
|
+ bizProductionResources = bizProductionResources.stream().filter(device->{
|
|
|
+ List targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{device.getId().toString()});
|
|
|
+ return targetList.size() > 0;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ //1. 判断空闲机床
|
|
|
+ if(bizProductionResources.size() > 0){
|
|
|
+ Map<Long, String> devicesMap = bizProductionResources.stream().collect(Collectors.toMap(Productionresource::getId, Productionresource::getModeSpecification));
|
|
|
+ //设备机床类型分组
|
|
|
+ List<Long> macResourceIds = devicesMap.keySet().stream().collect(Collectors.toList());
|
|
|
+ //获取线边库库位(排除保障中心线边库)
|
|
|
+ List<Long> storgeIds = storgeService.list(new LbqWrapper<Storge>().eq(Storge::getLockStatus, "1").like(Storge::getName, "_库位").notLike(Storge::getName, "bz")).stream().map(Storge::getId).collect(Collectors.toList());
|
|
|
+ //获取线边库加工零件批次号
|
|
|
List<String> completeBatchNos = stockInfoService.list(new LbqWrapper<StockInfo>().eq(StockInfo::getGoodsType, "4").in(StockInfo::getStorgeId, storgeIds)).stream().map(StockInfo::getCompleteBatchNo).collect(Collectors.toList());
|
|
|
- //获取线边库满足条件的节点
|
|
|
- List<TaskNode> taskNodeList = completeBatchNos.size() > 0 ? taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getExeStatus, "2").in(TaskNode::getTargetResourceId, macResourceIds).in(TaskNode::getCompleteBatchNo, completeBatchNos).eq(TaskNode::getNodeName, "放本序设备").orderByAsc(TaskNode::getStartTime)) : Lists.newArrayList();
|
|
|
- //获得线边库加工设备列表
|
|
|
- //Map<Long, List<TaskNode>> taskNodeMap = taskNodeList.stream().filter(item-> resourceIds.contains(item.getTargetResourceId())).collect(Collectors.groupingBy(TaskNode::getResourceId, LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
|
+ List<TaskNode> taskNodeList = completeBatchNos.size() > 0 ? taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getExeStatus, "2").in(TaskNode::getTargetResourceId, macResourceIds).in(TaskNode::getCompleteBatchNo, completeBatchNos).eq(TaskNode::getNodeName, "放本序设备").orderByAsc(TaskNode::getStartTime)) : Lists.newArrayList();
|
|
|
+ // 2. 判断线边库任务节点是否存在
|
|
|
if (taskNodeList != null && taskNodeList.size() > 0) {
|
|
|
- //判断任务是否已经变更(线边库同类型加工设备只允许变更一次)
|
|
|
List<Long> ids = taskNodeList.stream().map(TaskNode::getTaskId).distinct().collect(Collectors.toList());
|
|
|
-
|
|
|
- Map paramMap = Maps.newHashMap();
|
|
|
- String strIds = CollectionUtil.isNotEmpty(ids) ? CollectionUtil.join(ids, ",") : "";
|
|
|
- paramMap.put("ids", strIds);
|
|
|
- //判断节点处于执行阶段且未放入加工设备
|
|
|
- List<Map> taskLists = taskService.getXbkChangeStatus(paramMap);
|
|
|
- Map<Integer, String> taskMaps = null;
|
|
|
- if (taskLists.size() > 0) {
|
|
|
- taskMaps = taskLists.stream().collect(Collectors.toMap(item -> (Integer) item.get("isReload"), item -> item.get("cnt").toString()));
|
|
|
- } else {
|
|
|
- taskMaps = Maps.newHashMap();
|
|
|
+ //获取线边库任务
|
|
|
+ List<TTask> taskList = taskService.listByIds(ids);
|
|
|
+ List<Long> procedureIdList = taskList.stream().map(TTask::getProcedureId).collect(Collectors.toList());
|
|
|
+ Map<Long, List<BomProcedureProductionresource>> procedureCntMap = bomProcedureProductionresourceService.list(new LambdaQueryWrapper<BomProcedureProductionresource>().in(BomProcedureProductionresource::getProcedureId, procedureIdList)).stream().collect(Collectors.groupingBy(BomProcedureProductionresource::getProcedureId));
|
|
|
+ //获取工艺配置中允许变换加工设备的任务
|
|
|
+ final List<Long> procedureIdFinalList = procedureCntMap.entrySet().stream().filter(item->item.getValue().size()>1).map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
+ if(procedureIdList.size()>1){
|
|
|
+ taskList = taskList.stream().filter(item->procedureIdFinalList.contains(item.getProcedureId())).collect(Collectors.toList());
|
|
|
}
|
|
|
- //taskMaps.entrySet().stream().forEach(entry-> System.out.println("key="+entry.getKey()+", value="+entry.getValue()));
|
|
|
- //获取可执行的设备类型
|
|
|
- Map<Integer, String> finalTaskMaps = taskMaps;
|
|
|
- List<String> deviceTypes = DictionaryKey.YJ_DEVICE_TYPE.entrySet().stream().filter(map -> !finalTaskMaps.containsKey(map.getValue())).distinct().map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
- if (finalTaskMaps.entrySet().size() >= DictionaryKey.YJ_DEVICE_TYPE.size() || deviceTypes.size() == 0) {
|
|
|
- //获取已调度任务进行重刷判断处理
|
|
|
- List<Integer> reloadLists = finalTaskMaps.keySet().stream().collect(Collectors.toList());
|
|
|
- List<Long> taskIdList = taskService.list(new LbqWrapper<TTask>().eq(TTask::getStatus, "2").in(TTask::getIsReload, reloadLists)).stream().filter(item -> {
|
|
|
- com.github.zuihou.business.productionResourceCenter.entity.Productionresource productionresource = productionresourceBizMapper.selectById(item.getResourceId());
|
|
|
- return productionresource.getOnlineStatus().equals("2") || productionresource.getOnlineStatus().equals("3");
|
|
|
- }).map(TTask::getId).collect(Collectors.toList());
|
|
|
- if (taskIdList.size() > 0) {
|
|
|
- LambdaUpdateWrapper<TTask> updateWrapper = new LambdaUpdateWrapper<TTask>();
|
|
|
- updateWrapper.set(TTask::getIsReload, 0).in(TTask::getId, taskIdList);
|
|
|
- taskService.update(null, updateWrapper);
|
|
|
- log.warn("线边库任务{}二次调度", StringUtils.join(taskIdList, ","));
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- List<TaskNode> updatedTaskNodeList = taskNodeList.stream().filter(item -> bizProductionResources.stream().anyMatch(productionresource -> {
|
|
|
- //线边库节点的目标设备
|
|
|
- com.github.zuihou.business.productionResourceCenter.entity.Productionresource device = productionresourceBizMapper.selectById(item.getTargetResourceId());
|
|
|
- List targetList = productionresourcePositionService.getFreeProductionresourcePositionByIds(new String[]{productionresource.getId().toString()});
|
|
|
- //判断任务节点已被动态变更
|
|
|
- TTask task = taskService.getById(item.getTaskId());
|
|
|
- //限定加工设备在工艺配置设备的范围内
|
|
|
- List<BomProcedureProductionresource> bomProcedureProductionresourceList = bomProcedureProductionresourceService.list(new LbqWrapper<BomProcedureProductionresource>().eq(BomProcedureProductionresource::getProcedureId, task.getProcedureId()));
|
|
|
- List<Long> productionresourceIds = bomProcedureProductionresourceList.stream().map(BomProcedureProductionresource::getResourceId).distinct().collect(Collectors.toList());
|
|
|
- //判断加工设备类型和当前点位可用
|
|
|
- //判断过滤原设备和已被锁定变更的设备
|
|
|
- //判断设备的类型是否已变更
|
|
|
- if (device.getModeSpecification().equals(productionresource.getModeSpecification()) && targetList.size() > 0 && !device.getId().equals(productionresource.getId()) && task.getIsReload().equals(0) && productionresourceIds.contains(productionresource.getId())
|
|
|
- && deviceTypes.contains(productionresource.getModeSpecification())) {
|
|
|
- item.setTargetResourceId(productionresource.getId());
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- })).collect(Collectors.toList());
|
|
|
-
|
|
|
- // 执行任务和节点设备更新
|
|
|
- if (updatedTaskNodeList.size() > 0) {
|
|
|
- TaskNode updatedNode = updatedTaskNodeList.stream().sorted(Comparator.comparing(TaskNode::getStartTime)).collect(Collectors.toList()).get(0);
|
|
|
- //只默认取当前第一条任务
|
|
|
- TTask updatedTask = taskService.getById(updatedNode.getTaskId());
|
|
|
- com.github.zuihou.business.productionResourceCenter.entity.Productionresource targetDevice = productionresourceBizMapper.selectById(updatedNode.getTargetResourceId());
|
|
|
- //更新缓存中哈默上传文件路径IP信息
|
|
|
- if (null != targetDevice && targetDevice.getModeSpecification().equals("HEIDENHAIN")) {
|
|
|
- String uploadInfo = msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + updatedTask.getId()) != null ? msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + updatedTask.getId()).toString() : null;
|
|
|
- if (StringUtils.isNotEmpty(uploadInfo)) {
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(uploadInfo);
|
|
|
- jsonObject.put("url", targetDevice.getIp());
|
|
|
- msgUtil.redis_set(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + updatedTask.getId(), jsonObject.toJSONString(), 30, TimeUnit.DAYS);
|
|
|
- }
|
|
|
- } else if (null == targetDevice) {
|
|
|
- log.warn("节点{}目标设备不存在", updatedNode);
|
|
|
- msgUtil.redis_del(YunjianConstant.YUNJIAN_XBK_SCHEDULE);
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- // 执行任务和节点设备更新
|
|
|
- if (updatedTask != null && updatedTask.getResourceId() != null) {
|
|
|
- //设定任务加工设备状态变更
|
|
|
- int isReload = DictionaryKey.YJ_DEVICE_TYPE.containsKey(targetDevice.getModeSpecification()) ? DictionaryKey.YJ_DEVICE_TYPE.get(targetDevice.getModeSpecification()) : 0;
|
|
|
- updatedTask.setResourceId(updatedNode.getTargetResourceId()).setIsReload(isReload);
|
|
|
- JSONObject dyChangedInfo = new JSONObject();
|
|
|
- List<TaskNode> taskNodes = taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getTaskId, updatedTask.getId()));
|
|
|
- //更新节点目的设备
|
|
|
- taskNodes.stream().forEach(taskNode -> {
|
|
|
- if (null != taskNode.getTargetResourceId()) {
|
|
|
- if (taskNode.getResourceId().equals(taskNode.getTargetResourceId())) {
|
|
|
- if (!dyChangedInfo.containsKey("fromResource")) {
|
|
|
- dyChangedInfo.put("fromResource", taskNode.getResourceId());
|
|
|
+ //3. 判断自动调度任务是否存在
|
|
|
+ if(taskList.size()>0){
|
|
|
+ //以加工机床分类判断是否某类线边库任务已经执行动态调度
|
|
|
+ Map<Integer, List<TTask>> taskMaps = taskList.stream().collect(Collectors.groupingBy(item->{
|
|
|
+ String deviceType = devicesMap.get(item.getResourceId());
|
|
|
+ return DictionaryKey.YJ_DEVICE_TYPE.get(deviceType);
|
|
|
+ }));
|
|
|
+ //过滤已经执行动态调度
|
|
|
+ List<Integer> upDeviceTypes = DictionaryKey.YJ_DEVICE_TYPE.entrySet().stream().filter(map -> !taskMaps.containsKey(map.getValue())).distinct().map(Map.Entry::getValue).collect(Collectors.toList());
|
|
|
+ //3.判断是否有品牌机床可以执行调度 =0表明所有品牌机床都已执行了动态调度
|
|
|
+ if(upDeviceTypes.size()>0){
|
|
|
+ //获取可以去允许机床品牌的任务,并按时间升序获取等待时间最长任务
|
|
|
+ List<TTask> updatedTaskList = taskMaps.entrySet().stream().filter(item->upDeviceTypes.contains(item.getKey())).map(item->item.getValue().stream().sorted(Comparator.comparing(TTask::getCreateTime)).collect(Collectors.toList()).get(0)).collect(Collectors.toList());
|
|
|
+ //4.判断可调度任务是否存在
|
|
|
+ if(updatedTaskList.size()>0){
|
|
|
+ updatedTaskList.stream().forEach(runTask->{
|
|
|
+ List<BomProcedureProductionresource> bomProcedureProductionresourceList = procedureCntMap.get(runTask.getProcedureId()).stream().filter(bomDevice->(bomDevice.getResourceId() != runTask.getResourceId()) && (devicesMap.containsKey(bomDevice.getResourceId()))).collect(Collectors.toList());
|
|
|
+ //工艺配置调度可选设备
|
|
|
+ if(bomProcedureProductionresourceList.size()>0) {
|
|
|
+ //任务调度处理
|
|
|
+ Long dyDeviceId = bomProcedureProductionresourceList.get(0).getResourceId();
|
|
|
+ LambdaUpdateWrapper<TTask> updateWrapper = new LambdaUpdateWrapper<TTask>();
|
|
|
+ updateWrapper.set(TTask::getIsReload, devicesMap.get(runTask.getResourceId())).set(TTask::getResourceId, dyDeviceId).eq(TTask::getId, runTask.getId());
|
|
|
+ taskService.update(null, updateWrapper);
|
|
|
+
|
|
|
+ Productionresource targetDevice = productionresourceBizMapper.selectById(dyDeviceId);
|
|
|
+ //哈默上传文件缓存更新
|
|
|
+ if (null != targetDevice && targetDevice.getModeSpecification().equals("HEIDENHAIN")) {
|
|
|
+ String uploadInfo = msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + runTask.getId()) != null ? msgUtil.redis_get(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + runTask.getId()).toString() : null;
|
|
|
+ if (StringUtils.isNotEmpty(uploadInfo)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(uploadInfo);
|
|
|
+ jsonObject.put("url", targetDevice.getIp());
|
|
|
+ msgUtil.redis_set(DemoLineConstant.DEMOLINE_HEIDENHAIN_FILE_URL + "_" + runTask.getId(), jsonObject.toJSONString(), 30, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
}
|
|
|
- taskNode.setResourceId(updatedTask.getResourceId());
|
|
|
+
|
|
|
+ //任务节点调度处理
|
|
|
+ JSONObject dyChangedInfo = new JSONObject();
|
|
|
+ List<TaskNode> updatedTaskNodeList = taskNodeService.list(new LbqWrapper<TaskNode>().eq(TaskNode::getTaskId, runTask.getId()).orderByAsc(TaskNode::getCompleteBatchSort));
|
|
|
+ //更新节点目的设备
|
|
|
+ updatedTaskNodeList.stream().forEach(taskNode -> {
|
|
|
+ if (null != taskNode.getTargetResourceId()) {
|
|
|
+ if (taskNode.getResourceId().equals(taskNode.getTargetResourceId())) {
|
|
|
+ if (!dyChangedInfo.containsKey("fromResource")) {
|
|
|
+ dyChangedInfo.put("fromResource", taskNode.getResourceId());
|
|
|
+ }
|
|
|
+ taskNode.setResourceId(dyDeviceId);
|
|
|
+ }
|
|
|
+ taskNode.setTargetResourceId(dyDeviceId);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ taskNodeService.updateBatchById(updatedTaskNodeList);
|
|
|
+
|
|
|
+ dyChangedInfo.put("toResource", dyDeviceId);
|
|
|
+ dyChangedInfo.put("time", DateUtil.formatTime(new Date()));
|
|
|
+
|
|
|
+ msgUtil.redis_set(DemoLineConstant.DEMOLINE_RESOURCE_DY_CHANGE + "_" + runTask.getId(), dyChangedInfo.toJSONString(), 1, TimeUnit.DAYS);
|
|
|
+ msgUtil.redis_del(YunjianConstant.YUNJIAN_XBK_SCHEDULE);
|
|
|
}
|
|
|
- taskNode.setTargetResourceId(updatedTask.getResourceId());
|
|
|
- }
|
|
|
- });
|
|
|
- // 更新零件地址
|
|
|
- taskService.updateById(updatedTask);
|
|
|
- taskNodeService.updateBatchById(taskNodes);
|
|
|
-
|
|
|
- dyChangedInfo.put("toResource", updatedTask.getResourceId());
|
|
|
- dyChangedInfo.put("time", DateUtil.formatTime(new Date()));
|
|
|
-
|
|
|
- // 缓存数据更新
|
|
|
- //TaskNode currTaskNode = taskNodeService.getOne(new LbqWrapper<TaskNode>().eq(TaskNode::getTaskId,updatedTask.getId()).eq(TaskNode::getExeStatus,"2"));
|
|
|
- msgUtil.redis_set(DemoLineConstant.DEMOLINE_RESOURCE_DY_CHANGE + "_" + updatedTask.getId(), dyChangedInfo.toJSONString(), 1, TimeUnit.DAYS);
|
|
|
- msgUtil.redis_del(YunjianConstant.YUNJIAN_XBK_SCHEDULE);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
return true;
|
|
|
}
|