|
@@ -1,6 +1,8 @@
|
|
|
package com.github.zuihou.business.operationManagementCenter.service.impl;
|
|
|
|
|
|
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.authority.dao.auth.StationUserLoginInfoMapper;
|
|
|
import com.github.zuihou.authority.dao.auth.UserMapper;
|
|
@@ -15,26 +17,23 @@ import com.github.zuihou.business.aps.algorithm.ga.GAScheduler;
|
|
|
import com.github.zuihou.business.aps.instance.domain.basicdata.*;
|
|
|
import com.github.zuihou.business.classSchedule.dao.ScheduleUserDateMapper;
|
|
|
import com.github.zuihou.business.edgeLibrary.dao.StockInfoMapper;
|
|
|
+import com.github.zuihou.business.edgeLibrary.dao.StockLogMapper;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.StockInfo;
|
|
|
import com.github.zuihou.business.edgeLibrary.entity.Storge;
|
|
|
import com.github.zuihou.business.edgeLibrary.service.StockInfoService;
|
|
|
import com.github.zuihou.business.edgeLibrary.service.StockLogService;
|
|
|
import com.github.zuihou.business.edgeLibrary.service.StorgeService;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.dao.OrderMapper;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.dao.PlanMapper;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.dao.TTaskMapper;
|
|
|
-import com.github.zuihou.business.operationManagementCenter.dao.WorkpieceMapper;
|
|
|
+import com.github.zuihou.business.operationManagementCenter.dao.*;
|
|
|
import com.github.zuihou.business.operationManagementCenter.entity.*;
|
|
|
import com.github.zuihou.business.operationManagementCenter.service.TaskService;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.AutoNodeMapper;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureProductionresourceMapper;
|
|
|
-import com.github.zuihou.business.productionReadyCenter.dao.BomProcedureProgramMapper;
|
|
|
+import com.github.zuihou.business.productionReadyCenter.dao.*;
|
|
|
import com.github.zuihou.business.productionReadyCenter.entity.*;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourceBizMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ProductionresourcePositionMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.dao.ZZoneMapper;
|
|
|
import com.github.zuihou.business.productionResourceCenter.entity.*;
|
|
|
import com.github.zuihou.business.productionResourceCenter.service.RepairService;
|
|
|
+import com.github.zuihou.business.util.MsgUtil;
|
|
|
import com.github.zuihou.common.constant.BizConstant;
|
|
|
import com.github.zuihou.common.constant.CacheKey;
|
|
|
import com.github.zuihou.common.constant.CodeRuleModule;
|
|
@@ -47,12 +46,16 @@ import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
|
|
|
import com.github.zuihou.tenant.service.CodeRuleService;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.text.NumberFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -112,6 +115,19 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
|
|
|
|
|
|
@Autowired
|
|
|
private PlanMapper planMapper;
|
|
|
+ @Autowired
|
|
|
+ private StockLogMapper stockLogMapper;
|
|
|
+ @Autowired
|
|
|
+ private MToolClampMapper mToolClampMapper;
|
|
|
+ @Autowired
|
|
|
+ private StockInfoMapper stockInfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private TaskNodeMapper taskNodeMapper;
|
|
|
+ @Autowired
|
|
|
+ private MsgUtil msgUtil;
|
|
|
+ @Autowired
|
|
|
+ private AAutoNodeLogMapper autoNodeLogMapper;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public List<TTask> createTaskByPlan(List<PlanProduct> planProductList, Map<Long,List<BomProcedure>> bomProcedureMap,String taskBatchNo) {
|
|
@@ -857,6 +873,7 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
|
|
|
return task;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
public TTask assignResource(TTask task,Map<Long,BomProcedure>bpMap){
|
|
|
BomProcedure bp = bpMap.get(task.getProcedureId());
|
|
|
List<BomProcedureProductionresource> rsList = bp.getProductionresourceList();
|
|
@@ -1020,15 +1037,136 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
|
|
|
baseMapper.updateById(tTask);
|
|
|
}
|
|
|
}else if("end".equals(type)) {
|
|
|
+ TaskNode taskNode = taskNodeMapper.selectOne(Wraps.<TaskNode>lbQ().eq(TaskNode::getTaskId, tTask.getId()).eq(TaskNode::getExeStatus,"2"));
|
|
|
+ String id = taskNode.getId().toString();
|
|
|
+ //验证是否重复回调
|
|
|
+ String cacheId = msgUtil.redis_get(id) == null ? "" : msgUtil.redis_get(id).toString();
|
|
|
+ if (StringUtil.isNotEmpty(cacheId)) {//排除掉重复回调
|
|
|
+ log.info("上下料重复了======================" + cacheId);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ //把当前id存放入缓存
|
|
|
+ msgUtil.redis_set(id, id, 1, TimeUnit.HOURS);
|
|
|
+
|
|
|
if(null == tTask.getEndTime()) {
|
|
|
tTask.setEndTime(Calendar.getInstance().getTime());
|
|
|
tTask.setStatus("3");
|
|
|
baseMapper.updateById(tTask);
|
|
|
}
|
|
|
+ // 调用rfid读取接口判断rfid里面是否子盘信息,写入原材料信息
|
|
|
+ String meterialId = map.get("meterialId").toString();
|
|
|
+ String uniqueCode = map.get("uniqueCode").toString();
|
|
|
+ // 判断当前工件是否存在夹具,没有夹具stock表插入夹具信息
|
|
|
+ List<StockInfo> stockInfos = stockInfoService.list(Wraps.<StockInfo>lbQ().eq(StockInfo::getCompleteBatchNo, tTask.getCompleteBatchNo()));
|
|
|
+
|
|
|
+ // 先插入夹具信息
|
|
|
+ StockInfo meterialIdStockInfo = new StockInfo();
|
|
|
+ meterialIdStockInfo.setStorgeId(stockInfos.get(0).getStorgeId());
|
|
|
+ meterialIdStockInfo.setLockStatus("1");
|
|
|
+ meterialIdStockInfo.setGoodsType("3");
|
|
|
+ meterialIdStockInfo.setGoodsId(Long.valueOf(meterialId));
|
|
|
+ meterialIdStockInfo.setUniqueCode(String.valueOf(uniqueCode));
|
|
|
+ meterialIdStockInfo.setCompleteBatchNo(tTask.getCompleteBatchNo());
|
|
|
+ stockInfoMapper.insert(meterialIdStockInfo);
|
|
|
+ stockLogService.saveLog(meterialIdStockInfo,BizConstant.STOCK_TYPE_IN);
|
|
|
+
|
|
|
+ // 组织参数回调任务完成
|
|
|
+ List<AAutoNodeLog> autoNodeLogList = autoNodeLogMapper.selectList(Wraps.<AAutoNodeLog>lbQ().eq(AAutoNodeLog::getTaskNodeId, taskNode.getId()));
|
|
|
+ AAutoNodeLog lg = autoNodeLogList.get(0);
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ //根据任务查出所有的自动化节点
|
|
|
+ List<TaskNode> taskNodeList = taskNodeMapper.selectList(Wraps.<TaskNode>lbQ().eq(TaskNode::getCompleteBatchNo, tTask.getCompleteBatchNo()));
|
|
|
+
|
|
|
+ Storge jbwFromStorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CIRCULATION_STORAGE + "_" + tTask.getCompleteBatchNo());
|
|
|
+ //2、取出上下料站
|
|
|
+ Storge sxlzstorge = (Storge) msgUtil.redis_get(DemoCacheKey.DEMOLINE_CAMP + "_" + DemoLineConstant.SXLZ + taskNode.getId());
|
|
|
+ jsonObject.put("srcPosition", jbwFromStorge.getId());
|
|
|
+ jsonObject.put("targetPostion", sxlzstorge.getId());
|
|
|
+ jsonObject.put(DemoLineConstant.DEMOLINE_STOCK_TYPE, DemoLineConstant.DEMOLINE_STOCK_TYPE_METERIAL_CRK);
|
|
|
+
|
|
|
+ msgUtil.redis_set(DemoCacheKey.DEMOLINE_CIRCULATION_STORAGE + "_" + tTask.getCompleteBatchNo(), sxlzstorge, 1, TimeUnit.DAYS);
|
|
|
+
|
|
|
+ //节点完成业务
|
|
|
+ this.taskNodeCallbackBiz(taskNode, tTask, taskNodeList, lg, jsonObject.toJSONString());
|
|
|
+
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_STATUS + "_" + taskNode.getId(), "1");
|
|
|
+
|
|
|
}
|
|
|
return R.success();
|
|
|
}
|
|
|
|
|
|
+ private void taskNodeCallbackBiz(TaskNode taskNode, TTask task, List<TaskNode> taskNodeList, AAutoNodeLog lg, String bizCallBackData) {
|
|
|
+ //回调的参数
|
|
|
+ JSONObject callBackJson = JSONObject.parseObject(bizCallBackData);
|
|
|
+
|
|
|
+ //获取当前自动化节点的顺序
|
|
|
+ int n = taskNode.getCompleteBatchSort() - 1;
|
|
|
+
|
|
|
+ updateBizStatus(taskNode, task, taskNodeList, lg, callBackJson);
|
|
|
+
|
|
|
+ //websocket推送TODO临时注释
|
|
|
+// msgUtil.pushTask(task);
|
|
|
+
|
|
|
+ //推送到消息队列
|
|
|
+ msgUtil.pushToNextMq(taskNode, task, taskNodeList, n, callBackJson);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateBizStatus(TaskNode taskNode, TTask task, List<TaskNode> taskNodeList, AAutoNodeLog lg, JSONObject callBackJson) {
|
|
|
+ //如果是推送当前节点到mq(一个节点执行多次。就不需要更新数据状态)
|
|
|
+ if (this.checkPushNextNode(taskNode, callBackJson)){
|
|
|
+ //获取当前自动化节点的顺序
|
|
|
+ int n = taskNode.getCompleteBatchSort() - 1;
|
|
|
+ //插入执行日志
|
|
|
+ lg.setExeStatus("3");
|
|
|
+ lg.setExeResult("1").setEndTime(new Date());
|
|
|
+ autoNodeLogMapper.updateAllById(lg);
|
|
|
+ //更新节点任务
|
|
|
+ taskNode.setExeStatus("3").setExeResult("1").setEndTime(new Date());
|
|
|
+ taskNodeMapper.updateById(taskNode);
|
|
|
+ //把当前完成的节点放入缓存,用于推送任务完成的百分比
|
|
|
+ NumberFormat numberFormat = NumberFormat.getInstance();
|
|
|
+ numberFormat.setMaximumFractionDigits(2);
|
|
|
+
|
|
|
+ msgUtil.redis_set(CacheKey.TASK_CURRENT_NODE_PERCENT + "_" + task.getResourceId(), numberFormat.format(100 * (float) (n + 1) / (float) taskNodeList.size()));
|
|
|
+ task.setProcess(Double.parseDouble(numberFormat.format(100 * (float) (n + 1) / (float) taskNodeList.size())));
|
|
|
+
|
|
|
+ //更新订单表里的完成数量等等字段
|
|
|
+ if (n == 0 && "1".equals(task.getFirstProcedureFlag())) {
|
|
|
+ Order order = orderMapper.selectById(task.getOrderId());
|
|
|
+ order.setProduceNum((order.getProduceNum() == null ? 0 : order.getProduceNum()) + 1);
|
|
|
+ orderMapper.updateAllById(order);
|
|
|
+ }
|
|
|
+ //解锁相关资源
|
|
|
+ unlockResource(taskNode, task);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void unlockResource(TaskNode taskNode, TTask task) {
|
|
|
+ //删除当前节点的锁定
|
|
|
+ List<Storge> storgeList = storgeService.list(Wraps.<Storge>lbQ().eq(Storge::getCampId, taskNode.getId()));
|
|
|
+ if (CollectionUtil.isNotEmpty(storgeList)) {
|
|
|
+ storgeService.unlockStorgeList(storgeList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean checkPushNextNode(TaskNode taskNode, JSONObject callBackJson) {
|
|
|
+ if (callBackJson.containsKey(DemoLineConstant.DEMOLINE_RXJQR_FLAG)) {//柔性机器人的多步骤执行
|
|
|
+ int count = callBackJson.getString(taskNode.getId().toString() + "count") == null ? 0 : Integer.parseInt(callBackJson.getString(taskNode.getId().toString() + "count"));
|
|
|
+ if (count < 2) {//
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } else if (callBackJson.containsKey(DemoLineConstant.DEMOLINE_CHANGEHAND_FLAG) || callBackJson.containsKey(DemoLineConstant.DEMOLINE_RXJQR_NOMOVE_FLAG)) {//机器人换手或无需移动的柔性机器人
|
|
|
+ int count = callBackJson.getString(taskNode.getId().toString() + "count") == null ? 0 : Integer.parseInt(callBackJson.getString(taskNode.getId().toString() + "count"));
|
|
|
+ if (count < 1) {//
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public R releaseClamp(Map<String, Object> map){
|
|
|
TTask tTask = baseMapper.selectById(Long.valueOf(map.get("id").toString()));
|
|
@@ -1057,10 +1195,46 @@ public class TaskServiceImpl extends SuperServiceImpl<TTaskMapper, TTask> implem
|
|
|
|
|
|
@Override
|
|
|
public R procesRfid(Map<String, Object> map){
|
|
|
- // 先读取rfid内容是否有子盘信息
|
|
|
+ // TODO 先读取rfid内容是否有子盘信息
|
|
|
// 第一次使用子盘写入子盘唯一编码
|
|
|
TTask tTask = baseMapper.selectById(Long.valueOf(map.get("id").toString()));
|
|
|
// 调用rfid读取接口判断rfid里面是否子盘信息,第一次内容为空,写入自盘信息,后续只需更新夹具、和原材料信息
|
|
|
+
|
|
|
+ // 判断当前工件是否存在夹具,没有夹具stock表插入夹具信息
|
|
|
+ List<StockInfo> stockInfos = stockInfoService.list(Wraps.<StockInfo>lbQ().eq(StockInfo::getCompleteBatchNo, tTask.getCompleteBatchNo()));
|
|
|
+ // 只有子盘
|
|
|
+ if(stockInfos.size() ==1){
|
|
|
+ String goodsId = map.get("clampId").toString();
|
|
|
+ Map queryMap = new HashMap();
|
|
|
+ queryMap.put("goodsId", goodsId);
|
|
|
+
|
|
|
+ MToolClamp mToolClamp = mToolClampMapper.selectById(goodsId);
|
|
|
+ String maxMToolClamp = stockInfoMapper.selectMaxNoByProductId(queryMap);
|
|
|
+ int maxMToolClampNo = 0;
|
|
|
+ if(StringUtils.isBlank(maxMToolClamp)){
|
|
|
+ maxMToolClampNo = 0;
|
|
|
+ }else{
|
|
|
+ maxMToolClampNo = Integer.parseInt(maxMToolClamp);
|
|
|
+ }
|
|
|
+ int sumMToolClamp = stockInfoMapper.selectSumInStockByProductId(queryMap);
|
|
|
+ BigDecimal uniqueCode;
|
|
|
+ if(sumMToolClamp < mToolClamp.getNum()){
|
|
|
+ uniqueCode = BigDecimal.valueOf(maxMToolClampNo).add(new BigDecimal(1));;
|
|
|
+ }else{
|
|
|
+ return R.fail("当前夹具数量已用完");
|
|
|
+ }
|
|
|
+ StockInfo trayStockInfo = stockInfos.get(0);
|
|
|
+ // 先插入夹具信息
|
|
|
+ StockInfo clamStockInfo = new StockInfo();
|
|
|
+ clamStockInfo.setStorgeId(trayStockInfo.getStorgeId());
|
|
|
+ clamStockInfo.setLockStatus("1");
|
|
|
+ clamStockInfo.setGoodsType("1");
|
|
|
+ clamStockInfo.setGoodsId(Long.valueOf(goodsId));
|
|
|
+ clamStockInfo.setUniqueCode(String.valueOf(uniqueCode));
|
|
|
+ clamStockInfo.setCompleteBatchNo(tTask.getCompleteBatchNo());
|
|
|
+ stockInfoMapper.insert(clamStockInfo);
|
|
|
+ stockLogService.saveLog(clamStockInfo,BizConstant.STOCK_TYPE_IN);
|
|
|
+ }
|
|
|
return R.success();
|
|
|
}
|
|
|
}
|