diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/KMReServiceImpl.java b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/KMReServiceImpl.java index ee472d5..89a3a52 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/KMReServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/KMReServiceImpl.java @@ -153,7 +153,7 @@ public class KMReServiceImpl implements KMReService { * @param json 接口json */ @Override - public synchronized void sendAgvTaskToContainer(String url, String json) { + public void sendAgvTaskToContainer(String url, String json) { Dict dict = dictRepository.findDictByDescription("OPEN"); if (dict != null) { String resultJson = HttpPostUtil.sendPostReq(url, json); @@ -179,7 +179,7 @@ public class KMReServiceImpl implements KMReService { * @param agvTasks 任务 */ @Override - public synchronized String sendAgvTaskCcJson(AgvTask agvTasks) { + public String sendAgvTaskCcJson(AgvTask agvTasks) { JSONObject jsonObject = new JSONObject(new LinkedHashMap<>()); Map objMap = new LinkedHashMap<>(); @@ -231,7 +231,7 @@ public class KMReServiceImpl implements KMReService { * @param agvTasks 任务 */ @Override - public synchronized String sendAgvTaskHjJson(AgvTask agvTasks) { + public String sendAgvTaskHjJson(AgvTask agvTasks) { JSONObject jsonObject = new JSONObject(new LinkedHashMap<>()); Map objMap = new LinkedHashMap<>(); @@ -260,7 +260,7 @@ public class KMReServiceImpl implements KMReService { } @Override - public synchronized String sendAgvTaskGtJson(AgvTask agvTask) { + public String sendAgvTaskGtJson(AgvTask agvTask) { JSONObject jsonObject = new JSONObject(new LinkedHashMap<>()); Map objMap = new LinkedHashMap<>(); objMap.put("orgId", agvTask.getId());//库存组织 ID(或工厂代码,供应商代码) @@ -321,7 +321,7 @@ public class KMReServiceImpl implements KMReService { } @Override - public synchronized void sendAgvTask(AgvTask agvTasks, String json) { + public void sendAgvTask(AgvTask agvTasks, String json) { Dict dict = dictRepository.findDictByName("OPEN"); String resultJson = ""; if (dict != null) { diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/MesServiceImpl.java b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/MesServiceImpl.java index 2c651ef..face6c7 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/MesServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/MesServiceImpl.java @@ -250,7 +250,7 @@ public class MesServiceImpl implements MesService { return pickDetail; } - private synchronized void moveCpOffUp(String pointCode) { + private void moveCpOffUp(String pointCode) { // 从成品入库缓存区查询空车;没有在从成品入库区查询空车; List emptyStockList = stockService.findByFreeOrUsedStock(AreaNameDic.CPRKHCQ, BaseStatus.FREE); if (emptyStockList.isEmpty()) { @@ -273,12 +273,14 @@ public class MesServiceImpl implements MesService { //创建Agv任务 AgvTask agvTask = agvTaskService.createAgvTask(BizStatus.Cp_Off_Up, emptyStock, srcPoint.getCode(), endPoint.getCode(), "RACK_MOVE"); // 更新点位状态 - pointService.usedPoint(endPoint); + synchronized (this) { + pointService.usedPoint(endPoint); + } //下发任务 kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskHjJson(agvTask)); } - private synchronized void moveCpOffLine(TransTask transTask) { + private void moveCpOffLine(TransTask transTask) { //查询下线缓存区是否有满货架; List fullStockList = stockService.findByFreeOrUsedStock(AreaNameDic.CPXXHC, BaseStatus.USED); if (!fullStockList.isEmpty()) { @@ -294,10 +296,13 @@ public class MesServiceImpl implements MesService { if (agvTaskService.findByEndSlotCode(endPoint.getCode(), BizStatus.Cp_Off_Line, "RACK_MOVE")) { //创建Agv任务 AgvTask agvTask = agvTaskService.createAgvTask(BizStatus.Cp_Off_Line, fullStock, srcPoint.getCode(), endPoint.getCode(), "RACK_MOVE"); - // 更新点位状态 - pointService.usedPoint(endPoint); - //占用容器 - stockService.usedStock(fullStock, srcPoint, BaseStatus.USED); + synchronized (this) { + // 更新点位状态 + pointService.usedPoint(endPoint); + //占用容器 + stockService.usedStock(fullStock, srcPoint, BaseStatus.USED); + } + //下发任务 kmReService.sendAgvTask(agvTask, kmReService.sendAgvTaskHjJson(agvTask)); } diff --git a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/TaskServiceImpl.java b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/TaskServiceImpl.java index 71cff54..3c4df2a 100644 --- a/youchain-system/src/main/java/com/youchain/businessdata/service/impl/TaskServiceImpl.java +++ b/youchain-system/src/main/java/com/youchain/businessdata/service/impl/TaskServiceImpl.java @@ -159,7 +159,7 @@ public class TaskServiceImpl implements TaskService { @Override @Transactional(rollbackFor = Exception.class) - public synchronized void allocatePick(Pick pick) { + public void allocatePick(Pick pick) { //目标库位 Point endPoint = null; @@ -192,15 +192,17 @@ public class TaskServiceImpl implements TaskService { } /* 更新出库单状态*/ - pickService.refreshPickStatus(pick); + synchronized (this) { + pickService.refreshPickStatus(pick); - if (BizStatus.ALLOCATE.equals(pick.getStatus()) || BizStatus.ASSIGN.equals(pick.getStatus())) { - //绑定点位 - pick.setPoint(endPoint); - pickService.update(pick); + if (BizStatus.ALLOCATE.equals(pick.getStatus()) || BizStatus.ASSIGN.equals(pick.getStatus())) { + //绑定点位 + pick.setPoint(endPoint); + pickService.update(pick); - //占用点位 - pointService.usedPoint(endPoint); + //占用点位 + pointService.usedPoint(endPoint); + } } @@ -213,29 +215,35 @@ public class TaskServiceImpl implements TaskService { public void materialPick(Pick pick) { AgvTask agvTask = null; List taskList = this.findByPickNotAllTask(pick.getId()); - for (Task task : taskList) { - /*生成搬运任务*/ - List agvTaskList = agvTaskService.findRepeat(task.getSrcStockCode(), task.getSrcPointCode(), task.getDstPointCode()); - if (agvTaskList.isEmpty()) { - //创建任务 - agvTask = agvTaskService.createAgvTask(BizStatus.PICK, task.getSrcStock(), task.getSrcPoint().getCode(), task.getDstPoint().getCode(), "FORKLIFT_MOVE"); + synchronized (this) { + for (Task task : taskList) { + /*生成搬运任务*/ + List agvTaskList = agvTaskService.findRepeat(task.getSrcStockCode(), task.getSrcPointCode(), task.getDstPointCode()); + if (agvTaskList.isEmpty()) { + //创建任务 + agvTask = agvTaskService.createAgvTask(BizStatus.PICK, task.getSrcStock(), task.getSrcPoint().getCode(), task.getDstPoint().getCode(), "FORKLIFT_MOVE"); - //终点占用 - pointService.usedPoint(task.getDstPoint()); - } else { - agvTask = agvTaskList.get(0); - } - task.setAgvTask(agvTask); - task.setTaskStatus(agvTask.getStatus()); - taskRepository.save(task); + //终点占用 + pointService.usedPoint(task.getDstPoint()); + } else { + agvTask = agvTaskList.get(0); + } + task.setAgvTask(agvTask); + task.setTaskStatus(agvTask.getStatus()); + taskRepository.save(task); /* //叫料区是否有空车,呼叫到备料缓存区 this.callEmptyStock(task.getPickDetail().getItem().getGoodType());*/ + } } + /*更新出库单状态*/ - pick.setStatus(BizStatus.PICKUP); - pickService.update(pick); + synchronized (this) { + pick.setStatus(BizStatus.PICKUP); + pickService.update(pick); + } + } @Override @@ -263,18 +271,19 @@ public class TaskServiceImpl implements TaskService { Point endPoint = pointList.get(0); //有任务则直接返回 - if(!agvTaskService.findByEndSlotCode(endPoint.getCode(),BizStatus.CALL_RETURN,"RACK_MOVE")){ + if (!agvTaskService.findByEndSlotCode(endPoint.getCode(), BizStatus.CALL_RETURN, "RACK_MOVE")) { return; } //终点占用 - pointService.usedPoint(endPoint); + synchronized (this) { + pointService.usedPoint(endPoint); + } + //创建任务 agvTaskService.createAgvTask(BizStatus.CALL_RETURN, stock, srcPoint.getCode(), endPoint.getCode(), "RACK_MOVE"); - - } @Override @@ -286,7 +295,6 @@ public class TaskServiceImpl implements TaskService { if (pick.getCallPoint() == null) { throw new BadRequestException(pick.getGdCode() + "工单没有叫料请求!"); } - //起点 Point srcPoint = pick.getStock().getPoint(); @@ -303,25 +311,28 @@ public class TaskServiceImpl implements TaskService { //绑定任务 List taskList = this.findByPickAllTask(pick.getId()); - for (Task task : taskList) { - task.setCallAgvTaskId(agvTask.getId()); - taskRepository.save(task); + synchronized (this) { + for (Task task : taskList) { + task.setCallAgvTaskId(agvTask.getId()); + taskRepository.save(task); + } + + //起点占用 + pointService.usedPoint(srcPoint); + + //终点占用 + pointService.usedPoint(endPoint); + + //更新出库单状态为叫料中 + pick.setStatus(BizStatus.SHIP_PART); + pickService.update(pick); } - //起点占用 - pointService.usedPoint(srcPoint); - - //终点占用 - pointService.usedPoint(endPoint); - - //更新出库单状态为叫料中 - pick.setStatus(BizStatus.SHIP_PART); - pickService.update(pick); } @Override @Transactional(rollbackFor = Exception.class) - public synchronized String allocate(long id, double quantity, Point endPoint) { + public String allocate(long id, double quantity, Point endPoint) { //出库明细 PickDetail pickDetail = pickDetailService.findById(id); @@ -343,37 +354,40 @@ public class TaskServiceImpl implements TaskService { //未分配数量 double unQty = quantity; Set tps = new HashSet<>(); - for (Inventory inv : inventoryList) { - //判断托盘是否有任务 - if (this.existsByStock(pick.getCode(), inv.getStockCode()) >= 1) { - tps.add(inv.getStockCode()); - continue; - } - //起点 - Point startPoint = inv.getPoint(); - if (unQty == 0) { - break; - } - //库存可用数量 - allocateQty = inv.getQuantity() - inv.getQueuedQty(); - if (allocateQty <= 0) { - continue; - } + synchronized (this) { + for (Inventory inv : inventoryList) { + //判断托盘是否有任务 + if (this.existsByStock(pick.getCode(), inv.getStockCode()) >= 1) { + tps.add(inv.getStockCode()); + continue; + } + //起点 + Point startPoint = inv.getPoint(); + if (unQty == 0) { + break; + } + //库存可用数量 + allocateQty = inv.getQuantity() - inv.getQueuedQty(); + if (allocateQty <= 0) { + continue; + } + + if (unQty < allocateQty) { + allocateQty = unQty; + } + inv.setQueuedQty(inv.getQueuedQty() + allocateQty); + inventoryService.update(inv); + unQty -= allocateQty; + /* 更新出库单明细状态*/ + pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty); + pickDetailService.update(pickDetail); + + //生成Task任务 + this.createTask(item, allocateQty, inv.getItemKey(), null, BizStatus.PICK, pickDetail, inv.getId(), inv.getStock(), startPoint, endPoint, null); - if (unQty < allocateQty) { - allocateQty = unQty; } - inv.setQueuedQty(inv.getQueuedQty() + allocateQty); - inventoryService.update(inv); - unQty -= allocateQty; - /* 更新出库单明细状态*/ - pickDetail.setAllocatedQty(pickDetail.getAllocatedQty() + allocateQty); - pickDetailService.update(pickDetail); - - //生成Task任务 - this.createTask(item, allocateQty, inv.getItemKey(), null, BizStatus.PICK, pickDetail, inv.getId(), inv.getStock(), startPoint, endPoint, null); - } + if (tps.isEmpty()) { return pick.getCode() + "出库单中" + item.getCode() + "物料分配成功!"; } @@ -382,62 +396,68 @@ public class TaskServiceImpl implements TaskService { @Override @Transactional(rollbackFor = Exception.class) - public synchronized void cancelAllocate(long id, double quantity) { + public void cancelAllocate(long id, double quantity) { PickDetail pd = pickDetailService.findById(id); List tasks = this.findByPickDetailNotAllTask(id); - for (Task task : tasks) { - //根据task找到对应的库存 - Inventory inv = inventoryService.findById(task.getInvId()); - inv.setQueuedQty(inv.getQueuedQty() - pd.getAllocatedQty()); - inventoryService.update(inv); + synchronized (this) { + for (Task task : tasks) { + //根据task找到对应的库存 + Inventory inv = inventoryService.findById(task.getInvId()); + inv.setQueuedQty(inv.getQueuedQty() - pd.getAllocatedQty()); + inventoryService.update(inv); - //删除Task - taskRepository.delete(task); + //删除Task + taskRepository.delete(task); + + pd.setAllocatedQty(pd.getAllocatedQty() - quantity); + if (pd.getAllocatedQty() == 0) { + pd.setStatus(BizStatus.OPEN); + } + pickDetailService.update(pd); - pd.setAllocatedQty(pd.getAllocatedQty() - quantity); - if (pd.getAllocatedQty() == 0) { - pd.setStatus(BizStatus.OPEN); } - pickDetailService.update(pd); - } + } @Override @Transactional(rollbackFor = Exception.class) - public synchronized void pickConfirm(Long taskId, double pickedQuantity) { + public void pickConfirm(Long taskId, double pickedQuantity) { Task task = this.findById(taskId); + if (task.getInvId() == null) { + throw new BadRequestException("未找到库存相应记录!"); + } if (task.getPlanQty() > task.getMoveQty()) { PickDetail pickDetail = task.getPickDetail(); - task.setMoveQty(pickedQuantity); - task.setTaskStatus(BizStatus.FINISH); - taskRepository.save(task); - - if (task.getInvId() == null) { - throw new BadRequestException("未找到库存相应记录!"); - } Inventory inv = inventoryService.findById(task.getInvId()); - inv.setQuantity(inv.getQuantity() - pickedQuantity); - inv.setQueuedQty(inv.getQueuedQty() - pickedQuantity); - inventoryService.update(inv); + synchronized (this) { + task.setMoveQty(pickedQuantity); + task.setTaskStatus(BizStatus.FINISH); + taskRepository.save(task); - //释放容器 - stockService.usedStock(inv.getStock(), inv.getPoint(), BaseStatus.FREE); + inv.setQuantity(inv.getQuantity() - pickedQuantity); + inv.setQueuedQty(inv.getQueuedQty() - pickedQuantity); + inventoryService.update(inv); - if (inv.getQuantity() <= 0) { - inventoryService.deleteAll(new Long[]{inv.getId()}); + //释放容器 + stockService.usedStock(inv.getStock(), inv.getPoint(), BaseStatus.FREE); + + if (inv.getQuantity() <= 0) { + inventoryService.deleteAll(new Long[]{inv.getId()}); + } + + //回写拣货数量 + pickDetail.setPickedQty(pickDetail.getPickedQty() + pickedQuantity); + pickDetailService.update(pickDetail); + + //刷新状态 + pickService.refreshPickStatus(pickDetail.getPick()); } //添加库存日志 inventoryLogService.createInventoryLog(BizStatus.PICK_DOWN, BizStatus.REDUCE, task.getPickDetail().getPo(), task.getItemKey(), task.getSrcPoint(), task.getDstPoint(), task.getSrcStock(), task.getDstStock(), inv.getQuantity(), pickedQuantity, BizStatus.PICK, task.getId(), inv.getId(), ""); - //回写拣货数量 - pickDetail.setPickedQty(pickDetail.getPickedQty() + pickedQuantity); - pickDetailService.update(pickDetail); - - //刷新状态 - pickService.refreshPickStatus(pickDetail.getPick()); } @@ -445,7 +465,7 @@ public class TaskServiceImpl implements TaskService { @Override @Transactional(rollbackFor = Exception.class) - public synchronized void pickBarBack(long taskId, double pickedQuantity) { + public void pickBarBack(long taskId, double pickedQuantity) { Task task = findById(taskId); PickDetail pickDetail = task.getPickDetail(); if (task.getInvId() == null) { @@ -455,28 +475,30 @@ public class TaskServiceImpl implements TaskService { //退回库存 double srcQty = inv.getQueuedQty(); - inv.setQueuedQty(inv.getQueuedQty() + pickedQuantity); - inv.setQuantity(inv.getQuantity() + pickedQuantity); - inventoryService.update(inv); + synchronized (this) { + inv.setQueuedQty(inv.getQueuedQty() + pickedQuantity); + inv.setQuantity(inv.getQuantity() + pickedQuantity); + inventoryService.update(inv); + + //退回Task + task.setMoveQty(task.getMoveQty() - pickedQuantity); + taskRepository.save(task); + + //退回拣货数量 + pickDetail.setPickedQty(pickDetail.getPickedQty() - pickedQuantity); + pickDetailService.update(pickDetail); + + //更新出库单状态 + pickService.refreshPickStatus(pickDetail.getPick()); + + } //添加库存日志 inventoryLogService.createInventoryLog(BizStatus.PICK_CANCEL, BizStatus.ADD, task.getPickDetail().getPo(), task.getItemKey(), task.getDstPoint(), task.getSrcPoint(), task.getSrcStock(), task.getDstStock(), srcQty, pickedQuantity, BizStatus.PICK, task.getId(), inv.getId(), ""); - - //退回Task - task.setMoveQty(task.getMoveQty() - pickedQuantity); - taskRepository.save(task); - - //退回拣货数量 - pickDetail.setPickedQty(pickDetail.getPickedQty() - pickedQuantity); - pickDetailService.update(pickDetail); - - //更新出库单状态 - pickService.refreshPickStatus(pickDetail.getPick()); } @Override - @Transactional(rollbackFor = Exception.class) public Task createTask(Item item, Double quantity, ItemKey itemKey, AsnDetail asnDetail, String taskType, PickDetail pickDetail, Long invId, Stock stock, Point srcPoint, Point dstPoint, AgvTask agvTask) { Task task = new Task(); task.setItem(item); @@ -515,13 +537,17 @@ public class TaskServiceImpl implements TaskService { throw new BadRequestException(orderNumber + "箱号库存数量不足,请更换箱号!"); } Inventory srcinventory = inventoryService.findById(task.getInvId()); - srcinventory.setQueuedQty(srcinventory.getQueuedQty() - task.getPlanQty()); - inventoryService.update(srcinventory); - dstinventory.setQueuedQty(dstinventory.getQueuedQty() + task.getPlanQty()); - inventoryService.update(dstinventory); - task.setInvId(dstinventory.getId()); - task.setItemKey(dstinventory.getItemKey()); - taskRepository.save(task); + synchronized (srcinventory) { + synchronized (dstinventory) { + srcinventory.setQueuedQty(srcinventory.getQueuedQty() - task.getPlanQty()); + inventoryService.update(srcinventory); + dstinventory.setQueuedQty(dstinventory.getQueuedQty() + task.getPlanQty()); + inventoryService.update(dstinventory); + task.setInvId(dstinventory.getId()); + task.setItemKey(dstinventory.getItemKey()); + taskRepository.save(task); + } + } return task; } @@ -530,9 +556,16 @@ public class TaskServiceImpl implements TaskService { public void moveInventory(Task task, Stock dstStock, double moveQty) { //将占用数量移位,原库存回库内 Inventory inventory = inventoryService.findById(task.getInvId()); - inventory.setQueuedQty(inventory.getQueuedQty() - moveQty); - inventory.setQuantity(inventory.getQuantity() - moveQty); - inventoryService.update(inventory); + synchronized (inventory) { + inventory.setQueuedQty(inventory.getQueuedQty() - moveQty); + inventory.setQuantity(inventory.getQuantity() - moveQty); + inventoryService.update(inventory); + + //删除库存 + if (inventory.getQuantity() <= 0) { + inventoryService.deleteAll(new Long[]{inventory.getId()}); + } + } //生成新库存 Inventory newInventory = inventoryService.createInventory(inventory.getItemKey(), dstStock.getPoint(), dstStock, inventory.getDept(), moveQty); @@ -549,13 +582,11 @@ public class TaskServiceImpl implements TaskService { pickDetail.setPickedQty(pickDetail.getPickedQty() + moveQty); pickDetailService.update(pickDetail); - //删除库存 - if (inventory.getQuantity() <= 0) { - inventoryService.deleteAll(new Long[]{inventory.getId()}); - } //容器占用 - stockService.usedStock(dstStock, dstStock.getPoint(), BaseStatus.USED); + synchronized (dstStock) { + stockService.usedStock(dstStock, dstStock.getPoint(), BaseStatus.USED); + } //库存日志 inventoryLogService.createInventoryLog(BizStatus.MOVE, BizStatus.ADD, task.getPickDetail().getPo(), task.getItemKey(), task.getDstPoint(), dstStock.getPoint(), task.getSrcStock(), dstStock, 0d, moveQty, BizStatus.PICK, task.getId(), newInventory.getId(), "");