From dcf4a8720456796974ee1e460d89b54cf0143abc Mon Sep 17 00:00:00 2001 From: liangzhou <594755172@qq.com> Date: Tue, 22 Oct 2024 18:50:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9B=B4=E6=96=B0=EF=BC=9A?= =?UTF-8?q?=201.=20=E4=BF=AE=E5=A4=8Dbug=202.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E7=9B=91=E6=8E=A7=203.=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E4=BB=BB=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=B7=B2=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/wms/controller/MonitorController.java | 191 +++++ .../com/wms/controller/TaskController.java | 38 +- .../wms/entity/app/monitor/Analysis7Days.java | 20 + .../wms/entity/app/monitor/FinishDetail.java | 20 + .../entity/app/monitor/LocationUseDetail.java | 18 + .../entity/app/monitor/WorkInfoByStand.java | 31 + .../WmsTaskServiceImplements.java | 5 + .../WorkServiceImplements.java | 722 +++++++++--------- 8 files changed, 667 insertions(+), 378 deletions(-) create mode 100644 src/main/java/com/wms/controller/MonitorController.java create mode 100644 src/main/java/com/wms/entity/app/monitor/Analysis7Days.java create mode 100644 src/main/java/com/wms/entity/app/monitor/FinishDetail.java create mode 100644 src/main/java/com/wms/entity/app/monitor/LocationUseDetail.java create mode 100644 src/main/java/com/wms/entity/app/monitor/WorkInfoByStand.java diff --git a/src/main/java/com/wms/controller/MonitorController.java b/src/main/java/com/wms/controller/MonitorController.java new file mode 100644 index 0000000..13a1f07 --- /dev/null +++ b/src/main/java/com/wms/controller/MonitorController.java @@ -0,0 +1,191 @@ +package com.wms.controller; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.wms.entity.app.monitor.Analysis7Days; +import com.wms.entity.app.monitor.FinishDetail; +import com.wms.entity.app.monitor.LocationUseDetail; +import com.wms.entity.app.monitor.WorkInfoByStand; +import com.wms.entity.table.Location; +import com.wms.entity.table.Stand; +import com.wms.entity.table.WorkFlow; +import com.wms.entity.table.WorkSummary; +import com.wms.service.LocationService; +import com.wms.service.StandService; +import com.wms.service.WorkFlowService; +import com.wms.service.WorkSummaryService; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.CrossOrigin; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import static com.wms.utils.StringUtils.convertJsonString; + +/** + * 大屏监控类 + */ +@Controller +@CrossOrigin +@RequestMapping(value = "/monitor") +@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +public class MonitorController { + private final LocationService locationService; + private final WorkFlowService workFlowService; + private final WorkSummaryService workSummaryService; + private final StandService standService; + + /** + * 请求库位使用情况 + * @return 库位使用情况 + */ + @GetMapping("/getLocationUseDetail") + @ResponseBody + public String getLocationUseDetail() { + LocationUseDetail response = new LocationUseDetail(); + try { + int allSize = (int) locationService.count(); + int emptySize = (int) locationService.count(new LambdaQueryWrapper() + .eq(Location::getIsLock, 0) + .eq(Location::getLocationStatus, 0)); + response.setUsed(allSize - emptySize); + response.setEmpty(emptySize); + } catch (Exception e) { + response.setUsed(0); + response.setEmpty(0); + } + return convertJsonString(response); + } + + /** + * 请求最近7天的工作量统计 + * @return 最近7天的工作量统计 + */ + @GetMapping("/getAnalysis7Days") + @ResponseBody + public String getAnalysis7Days() { + Analysis7Days response = new Analysis7Days(); + List dateList = new ArrayList<>(); + WorkInfoByStand works = new WorkInfoByStand(); + try { + // 获取当前日期 + LocalDate now = LocalDate.now(); + // 创建一个列表来存储日期 + List dates = new ArrayList<>(); + // 添加最近7天的日期到列表中 + for (int i = 6; i >= 0; i--) { + dates.add(now.minusDays(i)); + } + // 9个站台的信息 + List stand1 = new ArrayList<>(); + List stand2 = new ArrayList<>(); + List stand3 = new ArrayList<>(); + List stand4 = new ArrayList<>(); + List stand5 = new ArrayList<>(); + List stand6 = new ArrayList<>(); + List stand7 = new ArrayList<>(); + List stand8 = new ArrayList<>(); + List stand9 = new ArrayList<>(); + // 获取所有的工作总结 + List allWorkSummaries = workSummaryService.list(); + // 循环日期 + for (LocalDate date : dates) { + dateList.add(date.format(DateTimeFormatter.ofPattern("MM-dd"))); + // 获取当日的工作总结 + List dayWorkSummaryList = allWorkSummaries.stream().filter(workSummary -> Objects.equals(workSummary.getWorkDate().toLocalDate(), date)).toList(); + // 获取1号站台当日的工作总结 + List stand1WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#1")).toList(); + stand1.add(stand1WorkSummaryList.size()); + // 获取2号站台当日的工作总结 + List stand2WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#2")).toList(); + stand2.add(stand2WorkSummaryList.size()); + // 获取3号站台当日的工作总结 + List stand3WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#3")).toList(); + stand3.add(stand3WorkSummaryList.size()); + // 获取4号站台当日的工作总结 + List stand4WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#4")).toList(); + stand4.add(stand4WorkSummaryList.size()); + // 获取5号站台当日的工作总结 + List stand5WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#5")).toList(); + stand5.add(stand5WorkSummaryList.size()); + // 获取6号站台当日的工作总结 + List stand6WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#6")).toList(); + stand6.add(stand6WorkSummaryList.size()); + // 获取7号站台当日的工作总结 + List stand7WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#7")).toList(); + stand7.add(stand7WorkSummaryList.size()); + // 获取8号站台当日的工作总结 + List stand8WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#8")).toList(); + stand8.add(stand8WorkSummaryList.size()); + // 获取9号站台当日的工作总结 + List stand9WorkSummaryList = dayWorkSummaryList.stream().filter(workSummary -> workSummary.getWorkStation().contains("#9")).toList(); + stand9.add(stand9WorkSummaryList.size()); + } + // 设定站台信息 + works.setStand1(stand1); + works.setStand2(stand2); + works.setStand3(stand3); + works.setStand4(stand4); + works.setStand5(stand5); + works.setStand6(stand6); + works.setStand7(stand7); + works.setStand8(stand8); + works.setStand9(stand9); + } catch (Exception e) { + dateList = Collections.emptyList(); + works = new WorkInfoByStand(); + } + response.setWorks(works); + response.setDate(dateList); + return convertJsonString(response); + } + + /** + * 请求工单完成情况 + * @return 工单完成情况 + */ + @GetMapping("/getFinishDetail") + @ResponseBody + public String getFinishDetail() { + FinishDetail response = new FinishDetail(); + List total = new ArrayList<>(); + List complete = new ArrayList<>(); + try { + // 获取当前站台所有的工作流信息 + List allWorkFlows = workFlowService.list(); + List stands = standService.list(new LambdaQueryWrapper() + .eq(Stand::getStandType, 2) + .orderByAsc(Stand::getStandId)); + for (Stand workStation : stands) { + // 查询到当前的工作量 + List currentStationWorkFlowList = allWorkFlows.stream().filter(workFlow -> Objects.equals(workFlow.getWorkStation(), workStation.getStandId())).toList(); + int finishingRows = 0; + for (WorkFlow workFlow : currentStationWorkFlowList) { + if (workFlow.getWorkStatus() == 2) { + finishingRows++; + } + } + total.add(currentStationWorkFlowList.size()); + complete.add(finishingRows); + } + } catch (Exception e) { + total = Collections.emptyList(); + complete = Collections.emptyList(); + } + + response.setComplete(complete); + response.setTotal(total); + return convertJsonString(response); + } +} diff --git a/src/main/java/com/wms/controller/TaskController.java b/src/main/java/com/wms/controller/TaskController.java index c1e23f5..34c3d77 100644 --- a/src/main/java/com/wms/controller/TaskController.java +++ b/src/main/java/com/wms/controller/TaskController.java @@ -1422,6 +1422,7 @@ public class TaskController { // 更新流转载具表剩余数量 if (currentGoodsVehicle != null) { currentGoodsVehicle.setRemainNum(BigDecimal.ZERO); + currentGoodsVehicle.setOutStatus(2); outsideVehiclesService.updateById(currentGoodsVehicle); } } else { @@ -1446,22 +1447,24 @@ public class TaskController { .eq(OutsideVehicles::getGoodsId, workConfirmRequest.getGoodsId()) .last("limit 1")); currentGoodsVehicle.setRemainNum(BigDecimal.ZERO); + currentGoodsVehicle.setOutStatus(2); outsideVehiclesService.updateById(currentGoodsVehicle); } } } - // 查询当前载具上的流转中的物料 - List outsideVehicles = outsideVehiclesService.list(new LambdaQueryWrapper() - .eq(OutsideVehicles::getVehicleId, pickTask.getVehicleId())); List goodsIdList = new ArrayList<>(); - if (outsideVehicles != null && !outsideVehicles.isEmpty()) { - for (OutsideVehicles outsideVehicle : outsideVehicles) { + // 查询库存 + List stockList = stockService.list(new LambdaQueryWrapper() + .eq(Stock::getVehicleId, pickTask.getVehicleId())); + if (stockList != null && !stockList.isEmpty()) { + for (Stock tempStock : stockList) { // 当前确认料号 - if (Objects.equals(outsideVehicle.getGoodsId(), workConfirmRequest.getGoodsId())) { + if (Objects.equals(tempStock.getGoodsRelated().getGoodsId(), workConfirmRequest.getGoodsId())) { continue; } - if (!goodsIdList.contains(outsideVehicle.getGoodsId())) { - goodsIdList.add(outsideVehicle.getGoodsId()); + if (!goodsIdList.contains(tempStock.getGoodsRelated().getGoodsId()) + && tempStock.getGoodsRelated().getRemainNum().compareTo(BigDecimal.ZERO) > 0) { + goodsIdList.add(tempStock.getGoodsRelated().getGoodsId()); } } } @@ -1629,18 +1632,19 @@ public class TaskController { response.setCode(ResponseCode.OK.getCode()); response.setMessage("确认成功,放行"); } else { - // 查询当前载具上的流转中的物料 - List outsideVehicles = outsideVehiclesService.list(new LambdaQueryWrapper() - .eq(OutsideVehicles::getVehicleId, pickTask.getVehicleId())); List goodsIdList = new ArrayList<>(); - if (outsideVehicles != null && !outsideVehicles.isEmpty()) { - for (OutsideVehicles outsideVehicle : outsideVehicles) { - if (Objects.equals(outsideVehicle.getGoodsId(), targetStand.getPickGoods())) { - // 正在拣货的物料除外 + // 查询库存 + List stockList = stockService.list(new LambdaQueryWrapper() + .eq(Stock::getVehicleId, pickTask.getVehicleId())); + if (stockList != null && !stockList.isEmpty()) { + for (Stock tempStock : stockList) { + // 当前确认料号 + if (Objects.equals(tempStock.getGoodsRelated().getGoodsId(), targetStand.getPickGoods())) { continue; } - if (!goodsIdList.contains(outsideVehicle.getGoodsId())) { - goodsIdList.add(outsideVehicle.getGoodsId()); + if (!goodsIdList.contains(tempStock.getGoodsRelated().getGoodsId()) + && tempStock.getGoodsRelated().getRemainNum().compareTo(BigDecimal.ZERO) > 0) { + goodsIdList.add(tempStock.getGoodsRelated().getGoodsId()); } } } diff --git a/src/main/java/com/wms/entity/app/monitor/Analysis7Days.java b/src/main/java/com/wms/entity/app/monitor/Analysis7Days.java new file mode 100644 index 0000000..385a835 --- /dev/null +++ b/src/main/java/com/wms/entity/app/monitor/Analysis7Days.java @@ -0,0 +1,20 @@ +package com.wms.entity.app.monitor; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class Analysis7Days { + /** + * 日期 + */ + @JsonProperty("date") + private List date; + /** + * 工作量 + */ + @JsonProperty("works") + private WorkInfoByStand works; +} diff --git a/src/main/java/com/wms/entity/app/monitor/FinishDetail.java b/src/main/java/com/wms/entity/app/monitor/FinishDetail.java new file mode 100644 index 0000000..ca22188 --- /dev/null +++ b/src/main/java/com/wms/entity/app/monitor/FinishDetail.java @@ -0,0 +1,20 @@ +package com.wms.entity.app.monitor; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +@Data +public class FinishDetail { + /** + * 总量 + */ + @JsonProperty("total") + private List total; + /** + * 完成 + */ + @JsonProperty("complete") + private List complete; +} diff --git a/src/main/java/com/wms/entity/app/monitor/LocationUseDetail.java b/src/main/java/com/wms/entity/app/monitor/LocationUseDetail.java new file mode 100644 index 0000000..29fdf94 --- /dev/null +++ b/src/main/java/com/wms/entity/app/monitor/LocationUseDetail.java @@ -0,0 +1,18 @@ +package com.wms.entity.app.monitor; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +public class LocationUseDetail { + /** + * 占用 + */ + @JsonProperty("used") + private Integer used; + /** + * 空闲 + */ + @JsonProperty("empty") + private Integer empty; +} diff --git a/src/main/java/com/wms/entity/app/monitor/WorkInfoByStand.java b/src/main/java/com/wms/entity/app/monitor/WorkInfoByStand.java new file mode 100644 index 0000000..bb54275 --- /dev/null +++ b/src/main/java/com/wms/entity/app/monitor/WorkInfoByStand.java @@ -0,0 +1,31 @@ +package com.wms.entity.app.monitor; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.util.List; + +/** + * 每个站台工作量 + */ +@Data +public class WorkInfoByStand { + @JsonProperty("stand1") + private List stand1; + @JsonProperty("stand2") + private List stand2; + @JsonProperty("stand3") + private List stand3; + @JsonProperty("stand4") + private List stand4; + @JsonProperty("stand5") + private List stand5; + @JsonProperty("stand6") + private List stand6; + @JsonProperty("stand7") + private List stand7; + @JsonProperty("stand8") + private List stand8; + @JsonProperty("stand9") + private List stand9; +} diff --git a/src/main/java/com/wms/service/business/serviceImplements/WmsTaskServiceImplements.java b/src/main/java/com/wms/service/business/serviceImplements/WmsTaskServiceImplements.java index db8db88..1fd89cc 100644 --- a/src/main/java/com/wms/service/business/serviceImplements/WmsTaskServiceImplements.java +++ b/src/main/java/com/wms/service/business/serviceImplements/WmsTaskServiceImplements.java @@ -330,6 +330,11 @@ public class WmsTaskServiceImplements implements IWmsTaskService { outsideVehicle.setRemainNum(BigDecimal.ZERO); outsideVehiclesService.updateById(outsideVehicle); } else { + // 库存状态为正常 + if (Objects.equals(stock.getStockStatus(), StockStatus.OK.getCode())) { + outsideVehiclesService.removeById(outsideVehicle); + continue; + } if (outsideVehicle.getRemainNum().compareTo(needNum) > 0) { // 当前箱子剩余物料数量多于需求数量 needNum = BigDecimal.ZERO; diff --git a/src/main/java/com/wms/service/business/serviceImplements/WorkServiceImplements.java b/src/main/java/com/wms/service/business/serviceImplements/WorkServiceImplements.java index 0dc84f6..722743f 100644 --- a/src/main/java/com/wms/service/business/serviceImplements/WorkServiceImplements.java +++ b/src/main/java/com/wms/service/business/serviceImplements/WorkServiceImplements.java @@ -53,135 +53,6 @@ public class WorkServiceImplements implements IWorkService { private final List workDoingStations = new ArrayList<>();// 当前正在执行任务的站台 private final List workFinishingStations = new ArrayList<>();// 当前正在完成任务的站台 - @Override - @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) - public void createWork(String workStation) throws Exception { - if (workCreatingStations.contains(workStation)) { - // 当前站台正在创建任务 - return; - } else { - // 添加站台 - workCreatingStations.add(workStation); - } - if (StringUtils.isEmpty(workStation)) { - // 站台号为空 - return; - } - try { - // 先判断当日是否是工作日 - if (!localWorkDateList.contains(LocalDate.now())) { - return; - } - // 先查看当前站台已经生成的工作流是否为空 - List currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper() - .eq(WorkFlow::getWorkStation, workStation)); - // 当前站台的工作流中还存在其他任务 - if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) { - return; - } - // 当前站台分配的工位 - List currentStationWorkFlows = new ArrayList<>(); - // 先找MWL机型 - findWorks(workStation, currentStationWorkFlows, "MWL"); - if (currentStationWorkFlows.isEmpty()) { - // 找非MWL机型 - findWorks(workStation, currentStationWorkFlows, "NOT_MWL"); - } - // 如果当前站台有任务 - if (!currentStationWorkFlows.isEmpty()) { - // 将工作流列表添加进数据库 - workFlowService.saveBatch(currentStationWorkFlows); - // 获得工单列表 - List workOrderList = new ArrayList<>(); - // 获得工单以及小工位列表 - List boxNoList = new ArrayList<>(); - // 要料Map - Map needGoodsMap = new HashMap<>(); - for (WorkFlow tempWorkflow : currentStationWorkFlows) { - // 添加工单 - if (!workOrderList.contains(tempWorkflow.getWorkOrder())) { - workOrderList.add(tempWorkflow.getWorkOrder()); - } - // 添加盒子配置 - String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter(); - if (!boxNoList.contains(boxNo)) { - boxNoList.add(boxNo); - } - // 添加要料信息 - if (!needGoodsMap.containsKey(tempWorkflow.getGoodsId())) { - // 添加物料信息 - needGoodsMap.put(tempWorkflow.getGoodsId(), tempWorkflow.getNeedNum()); - } else { - // 增加需求数量 - needGoodsMap.replace(tempWorkflow.getGoodsId(), needGoodsMap.get(tempWorkflow.getGoodsId()).add(tempWorkflow.getNeedNum())); - } - } - // 站台要料 - List goodsToStationList = new ArrayList<>(); - for (String goodsId : needGoodsMap.keySet()) { - GoodsToStation goodsToStation = new GoodsToStation(); - goodsToStation.setGoodsId(goodsId); - goodsToStation.setWorkStation(workStation); - goodsToStation.setDistributeStatus(0); - goodsToStation.setDistributedNum(BigDecimal.ZERO); - goodsToStation.setTotalNum(needGoodsMap.get(goodsId)); - goodsToStationList.add(goodsToStation); - } - // 将站台要料列表存进数据库 - goodsToStationService.saveBatch(goodsToStationList); - // 更新工单表 - List orderIds = currentStationWorkFlows.stream().map(WorkFlow::getOrderId).distinct().toList(); - if (!orderIds.isEmpty()) { - kateOrdersService.update(new LambdaUpdateWrapper() - .set(KateOrders::getOrderStatus, 1) - .in(KateOrders::getOrderId, orderIds) - .eq(KateOrders::getOrderStatus, 0)); - } - // 更新dbs表 - if (!workOrderList.isEmpty()) { - kateDBSService.update(new LambdaUpdateWrapper() - .set(KateDBS::getDbsStatus, 1) - .in(KateDBS::getWorkOrder, workOrderList) - .eq(KateDBS::getDbsStatus, 0)); - } - // 电子标签库位配置 - List eLocationConfigList = new ArrayList<>(); - // 查找到当前站台所有可用的电子标签 - List eTagLocationList = eTagLocationService.list(new LambdaQueryWrapper() - .eq(ETagLocation::getWorkStation, workStation) - .eq(ETagLocation::getELocationStatus, 0) - .orderByAsc(ETagLocation::getSequenceId)); - if (eTagLocationList.isEmpty() || eTagLocationList.size() < boxNoList.size()) { - throw new Exception("站台:" + workStation + "没有足够可用的电子标签位!"); - } - for (ETagLocation eTagLocation : eTagLocationList) { - if (!boxNoList.isEmpty()) { - String tempBoxNo = boxNoList.get(0); - ELocationConfig eLocationConfig = new ELocationConfig(); - eLocationConfig.setWorkOrder(tempBoxNo.split("@")[0]); - eLocationConfig.setWorkCenter(tempBoxNo.split("@")[1]); - eLocationConfig.setWorkStation(workStation); - eLocationConfig.setELocationId(eTagLocation.getELocationId()); - eLocationConfig.setOrderBoxNo(tempBoxNo); - // 添加配置 - eLocationConfigList.add(eLocationConfig); - // 移除已经分配的盒子 - boxNoList.remove(tempBoxNo); - } - } - // 将电子标签库位配置存进数据库 - eLocationConfigService.saveBatch(eLocationConfigList); - } - } catch (Exception e) { - logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e)); - // 回滚事务 - TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); - } finally { - // 当前站台创建任务完成 - workCreatingStations.remove(workStation); - } - } - // @Override // @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) // public void createWork(String workStation) throws Exception { @@ -197,31 +68,40 @@ public class WorkServiceImplements implements IWorkService { // return; // } // try { +// // 先判断当日是否是工作日 +// if (!localWorkDateList.contains(LocalDate.now())) { +// return; +// } // // 先查看当前站台已经生成的工作流是否为空 // List currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper() -// .eq(WorkFlow::getWorkStation, workStation) -// .ne(WorkFlow::getWorkStatus, 0)); +// .eq(WorkFlow::getWorkStation, workStation)); // // 当前站台的工作流中还存在其他任务 // if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) { // return; // } -// // 查询是否有已经分配好的电子标签库位信息 -// List oldELocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper() -// .eq(ELocationConfig::getWorkStation, workStation)); -// if (oldELocationConfigList != null && !oldELocationConfigList.isEmpty()) { -// return; +// // 当前站台分配的工位 +// List currentStationWorkFlows = new ArrayList<>(); +// // 先找MWL机型 +// findWorks(workStation, currentStationWorkFlows, "MWL"); +// if (currentStationWorkFlows.isEmpty()) { +// // 找非MWL机型 +// findWorks(workStation, currentStationWorkFlows, "NOT_MWL"); // } -// // 查询所有待下发的 -// List currentStationWorkFlows = workFlowService.list(new LambdaQueryWrapper() -// .eq(WorkFlow::getWorkStatus, 0) -// .eq(WorkFlow::getWorkStation, workStation)); // // 如果当前站台有任务 // if (!currentStationWorkFlows.isEmpty()) { +// // 将工作流列表添加进数据库 +// workFlowService.saveBatch(currentStationWorkFlows); +// // 获得工单列表 +// List workOrderList = new ArrayList<>(); // // 获得工单以及小工位列表 // List boxNoList = new ArrayList<>(); // // 要料Map // Map needGoodsMap = new HashMap<>(); // for (WorkFlow tempWorkflow : currentStationWorkFlows) { +// // 添加工单 +// if (!workOrderList.contains(tempWorkflow.getWorkOrder())) { +// workOrderList.add(tempWorkflow.getWorkOrder()); +// } // // 添加盒子配置 // String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter(); // if (!boxNoList.contains(boxNo)) { @@ -240,7 +120,6 @@ public class WorkServiceImplements implements IWorkService { // List goodsToStationList = new ArrayList<>(); // for (String goodsId : needGoodsMap.keySet()) { // GoodsToStation goodsToStation = new GoodsToStation(); -// goodsToStation.setConfigId(goodsId + "_" + workStation); // goodsToStation.setGoodsId(goodsId); // goodsToStation.setWorkStation(workStation); // goodsToStation.setDistributeStatus(0); @@ -249,7 +128,22 @@ public class WorkServiceImplements implements IWorkService { // goodsToStationList.add(goodsToStation); // } // // 将站台要料列表存进数据库 -// goodsToStationService.saveOrUpdateBatch(goodsToStationList); +// goodsToStationService.saveBatch(goodsToStationList); +// // 更新工单表 +// List orderIds = currentStationWorkFlows.stream().map(WorkFlow::getOrderId).distinct().toList(); +// if (!orderIds.isEmpty()) { +// kateOrdersService.update(new LambdaUpdateWrapper() +// .set(KateOrders::getOrderStatus, 1) +// .in(KateOrders::getOrderId, orderIds) +// .eq(KateOrders::getOrderStatus, 0)); +// } +// // 更新dbs表 +// if (!workOrderList.isEmpty()) { +// kateDBSService.update(new LambdaUpdateWrapper() +// .set(KateDBS::getDbsStatus, 1) +// .in(KateDBS::getWorkOrder, workOrderList) +// .eq(KateDBS::getDbsStatus, 0)); +// } // // 电子标签库位配置 // List eLocationConfigList = new ArrayList<>(); // // 查找到当前站台所有可用的电子标签 @@ -277,12 +171,6 @@ public class WorkServiceImplements implements IWorkService { // } // // 将电子标签库位配置存进数据库 // eLocationConfigService.saveBatch(eLocationConfigList); -// // 更新工作流状态 -// List workFlowIds = currentStationWorkFlows.stream().map(WorkFlow::getWorkFlowId).distinct().toList(); -// workFlowService.update(new LambdaUpdateWrapper() -// .set(WorkFlow::getWorkStatus, 1) -// .in(WorkFlow::getWorkFlowId, workFlowIds) -// .eq(WorkFlow::getWorkStatus, 0)); // } // } catch (Exception e) { // logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e)); @@ -296,148 +184,113 @@ public class WorkServiceImplements implements IWorkService { @Override @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) - public void doWork(String workStation) throws Exception { - if (workDoingStations.contains(workStation)) { + public void createWork(String workStation) throws Exception { + if (workCreatingStations.contains(workStation)) { // 当前站台正在创建任务 return; } else { // 添加站台 - workDoingStations.add(workStation); + workCreatingStations.add(workStation); + } + if (StringUtils.isEmpty(workStation)) { + // 站台号为空 + return; } try { - // 查找当前站台未开始的工作流 + // 先查看当前站台已经生成的工作流是否为空 List currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper() .eq(WorkFlow::getWorkStation, workStation) - .ne(WorkFlow::getWorkStatus, 2)); - // 没有可做的任务 - if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) { + .ne(WorkFlow::getWorkStatus, 0)); + // 当前站台的工作流中还存在其他任务 + if (currentWorkFlowList != null && !currentWorkFlowList.isEmpty()) { return; } - // 查站台要料表---未分配以及分配但未完全分配 - List goodsToStationList = goodsToStationService.list(new LambdaQueryWrapper() - .eq(GoodsToStation::getWorkStation, workStation)); - List notFinishedGoodsList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() < 2).toList(); - if (notFinishedGoodsList.isEmpty()) { - // 查询是否还有这个站台的拣选任务 - if (!pickTaskService.exists(new LambdaQueryWrapper() - .eq(PickTask::getStandId, workStation))) { - // 需要重新分配的goodsToStationsList - Map needDistributeGoodsMap = new HashMap<>(); - // 需要完成的工作流 - List needFinishWorkFlowList = new ArrayList<>(); - // 所有缺料的分配 - List lackGoodsIdList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 3).map(GoodsToStation::getGoodsId).distinct().toList(); - // 不缺料的分配 - Map noLackGoodsMap = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 2).collect(Collectors.toMap(GoodsToStation::getGoodsId, goodsToStation -> goodsToStation)); - // 查询当前工作流中所有缺料的数据行 - for (WorkFlow notFinishedWorkFlow : currentWorkFlowList) { - if (notFinishedWorkFlow.getPickedNum().compareTo(notFinishedWorkFlow.getNeedNum()) < 0) { - // 缺料时,判断是否当前物料在缺料列表中 - if (lackGoodsIdList.contains(notFinishedWorkFlow.getGoodsId())) { - // 缺料,添加到需要分配的列表中 - notFinishedWorkFlow.setWorkStatus(2); - notFinishedWorkFlow.setFinishTime(LocalDateTime.now()); - notFinishedWorkFlow.setOpUser("系统自动完成"); - needFinishWorkFlowList.add(notFinishedWorkFlow); - } else { - BigDecimal needNum = notFinishedWorkFlow.getNeedNum().subtract(notFinishedWorkFlow.getPickedNum()); - if (needDistributeGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) { - // 减少分配数量 - GoodsToStation oldGoodsToStation = needDistributeGoodsMap.get(notFinishedWorkFlow.getGoodsId()); - oldGoodsToStation.setDistributedNum(oldGoodsToStation.getDistributedNum().subtract(needNum)); - oldGoodsToStation.setDistributeStatus(1); - needDistributeGoodsMap.replace(notFinishedWorkFlow.getGoodsId(), oldGoodsToStation); - } else { - if (noLackGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) { - GoodsToStation newGoodsToStation = noLackGoodsMap.get(notFinishedWorkFlow.getGoodsId()); - newGoodsToStation.setDistributedNum(newGoodsToStation.getDistributedNum().subtract(needNum)); - newGoodsToStation.setDistributeStatus(1); - needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), newGoodsToStation); - } else { - GoodsToStation goodsToStation = new GoodsToStation(); - goodsToStation.setConfigId(notFinishedWorkFlow.getGoodsId() + "_" + workStation); - goodsToStation.setGoodsId(notFinishedWorkFlow.getGoodsId()); - goodsToStation.setWorkStation(workStation); - goodsToStation.setDistributeStatus(0); - goodsToStation.setDistributedNum(BigDecimal.ZERO); - goodsToStation.setTotalNum(needNum); - needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), goodsToStation); - } - } - } - } else { - // 不缺料,直接完成 - notFinishedWorkFlow.setWorkStatus(2); - notFinishedWorkFlow.setFinishTime(LocalDateTime.now()); - notFinishedWorkFlow.setOpUser("系统自动完成"); - needFinishWorkFlowList.add(notFinishedWorkFlow); - } + // 查询是否有已经分配好的电子标签库位信息 + List oldELocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper() + .eq(ELocationConfig::getWorkStation, workStation)); + if (oldELocationConfigList != null && !oldELocationConfigList.isEmpty()) { + return; + } + // 查询所有待下发的 + List currentStationWorkFlows = workFlowService.list(new LambdaQueryWrapper() + .eq(WorkFlow::getWorkStatus, 0) + .eq(WorkFlow::getWorkStation, workStation)); + // 如果当前站台有任务 + if (!currentStationWorkFlows.isEmpty()) { + // 获得工单以及小工位列表 + List boxNoList = new ArrayList<>(); + // 要料Map + Map needGoodsMap = new HashMap<>(); + for (WorkFlow tempWorkflow : currentStationWorkFlows) { + // 添加盒子配置 + String boxNo = tempWorkflow.getWorkOrder() + "@" + tempWorkflow.getWorkCenter(); + if (!boxNoList.contains(boxNo)) { + boxNoList.add(boxNo); } - // 保存重新分配的goodsToStationList - goodsToStationService.saveOrUpdateBatch(needDistributeGoodsMap.values()); - // 保存需要完成的工作流 - workFlowService.updateBatchById(needFinishWorkFlowList); - } - return; - } - for (GoodsToStation goodsToStation : notFinishedGoodsList) { - // 当前物料当前站台需求数量 - BigDecimal needNum = goodsToStation.getTotalNum().subtract(goodsToStation.getDistributedNum()); - if (needNum.compareTo(BigDecimal.ZERO) == 0) { - // 需求数量为0 - continue; - } - // 判断实际库存是否充足 - List stockList = stockService.list(new LambdaQueryWrapper() - .apply("goods_related ->> '$.goodsId' = {0}" + MYSQL_JSON_CI, goodsToStation.getGoodsId()) - .apply("goods_related ->> '$.remainNum' > 0")); - if (stockList == null || stockList.isEmpty()) { - goodsToStation.setDistributeStatus(3); - continue; - } - // 判断当前物料是否在流转中 - needNum = wmsTaskService.callGoods(goodsToStation.getGoodsId(), needNum, workStation); - // 判断此时需求数量是否为0 - if (needNum.compareTo(BigDecimal.ZERO) <= 0) { - // 分配完成 - goodsToStation.setDistributeStatus(2); - } else { - needNum = wmsTaskService.callStocks(goodsToStation.getGoodsId(), needNum, workStation); - if (needNum.compareTo(BigDecimal.ZERO) > 0) { - // 已分配但未完全分配 - goodsToStation.setDistributeStatus(1); + // 添加要料信息 + if (!needGoodsMap.containsKey(tempWorkflow.getGoodsId())) { + // 添加物料信息 + needGoodsMap.put(tempWorkflow.getGoodsId(), tempWorkflow.getNeedNum()); } else { - // 分配完成 - goodsToStation.setDistributeStatus(2); + // 增加需求数量 + needGoodsMap.replace(tempWorkflow.getGoodsId(), needGoodsMap.get(tempWorkflow.getGoodsId()).add(tempWorkflow.getNeedNum())); } } - // 更新已分配数量 - goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum)); + // 站台要料 + List goodsToStationList = new ArrayList<>(); + for (String goodsId : needGoodsMap.keySet()) { + GoodsToStation goodsToStation = new GoodsToStation(); + goodsToStation.setConfigId(goodsId + "_" + workStation); + goodsToStation.setGoodsId(goodsId); + goodsToStation.setWorkStation(workStation); + goodsToStation.setDistributeStatus(0); + goodsToStation.setDistributedNum(BigDecimal.ZERO); + goodsToStation.setTotalNum(needGoodsMap.get(goodsId)); + goodsToStationList.add(goodsToStation); + } + // 将站台要料列表存进数据库 + goodsToStationService.saveOrUpdateBatch(goodsToStationList); + // 电子标签库位配置 + List eLocationConfigList = new ArrayList<>(); + // 查找到当前站台所有可用的电子标签 + List eTagLocationList = eTagLocationService.list(new LambdaQueryWrapper() + .eq(ETagLocation::getWorkStation, workStation) + .eq(ETagLocation::getELocationStatus, 0) + .orderByAsc(ETagLocation::getSequenceId)); + if (eTagLocationList.isEmpty() || eTagLocationList.size() < boxNoList.size()) { + throw new Exception("站台:" + workStation + "没有足够可用的电子标签位!"); + } + for (ETagLocation eTagLocation : eTagLocationList) { + if (!boxNoList.isEmpty()) { + String tempBoxNo = boxNoList.get(0); + ELocationConfig eLocationConfig = new ELocationConfig(); + eLocationConfig.setWorkOrder(tempBoxNo.split("@")[0]); + eLocationConfig.setWorkCenter(tempBoxNo.split("@")[1]); + eLocationConfig.setWorkStation(workStation); + eLocationConfig.setELocationId(eTagLocation.getELocationId()); + eLocationConfig.setOrderBoxNo(tempBoxNo); + // 添加配置 + eLocationConfigList.add(eLocationConfig); + // 移除已经分配的盒子 + boxNoList.remove(tempBoxNo); + } + } + // 将电子标签库位配置存进数据库 + eLocationConfigService.saveBatch(eLocationConfigList); + // 更新工作流状态 + List workFlowIds = currentStationWorkFlows.stream().map(WorkFlow::getWorkFlowId).distinct().toList(); + workFlowService.update(new LambdaUpdateWrapper() + .set(WorkFlow::getWorkStatus, 1) + .in(WorkFlow::getWorkFlowId, workFlowIds) + .eq(WorkFlow::getWorkStatus, 0)); } - goodsToStationService.updateBatchById(notFinishedGoodsList); - // 更新工作流状态 - List workFlowIds = currentWorkFlowList.stream().map(WorkFlow::getWorkFlowId).distinct().toList(); - List orderIds = currentWorkFlowList.stream().map(WorkFlow::getOrderId).distinct().toList(); - List goodsIds = currentWorkFlowList.stream().map(WorkFlow::getGoodsId).distinct().toList(); - List smallBoxes = currentWorkFlowList.stream().map(WorkFlow::getWorkCenter).distinct().toList(); - workFlowService.update(new LambdaUpdateWrapper() - .set(WorkFlow::getWorkStatus, 1) - .in(WorkFlow::getWorkFlowId, workFlowIds) - .eq(WorkFlow::getWorkStatus, 0)); - // 更新工单表状态 - kateOrdersService.update(new LambdaUpdateWrapper() - .set(KateOrders::getOrderStatus, 2) - .in(KateOrders::getOrderId, orderIds) - .in(KateOrders::getGoodsId, goodsIds) - .in(KateOrders::getSupplyArea, smallBoxes) - .eq(KateOrders::getOrderStatus, 1)); } catch (Exception e) { - logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e)); + logger.error("创建站台:{}工作发生异常:{}", workStation, convertJsonString(e)); // 回滚事务 TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } finally { // 当前站台创建任务完成 - workDoingStations.remove(workStation); + workCreatingStations.remove(workStation); } } @@ -455,7 +308,7 @@ public class WorkServiceImplements implements IWorkService { // // 查找当前站台未开始的工作流 // List currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper() // .eq(WorkFlow::getWorkStation, workStation) -// .eq(WorkFlow::getWorkStatus, 1)); +// .ne(WorkFlow::getWorkStatus, 2)); // // 没有可做的任务 // if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) { // return; @@ -562,6 +415,22 @@ public class WorkServiceImplements implements IWorkService { // goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum)); // } // goodsToStationService.updateBatchById(notFinishedGoodsList); +// // 更新工作流状态 +// List workFlowIds = currentWorkFlowList.stream().map(WorkFlow::getWorkFlowId).distinct().toList(); +// List orderIds = currentWorkFlowList.stream().map(WorkFlow::getOrderId).distinct().toList(); +// List goodsIds = currentWorkFlowList.stream().map(WorkFlow::getGoodsId).distinct().toList(); +// List smallBoxes = currentWorkFlowList.stream().map(WorkFlow::getWorkCenter).distinct().toList(); +// workFlowService.update(new LambdaUpdateWrapper() +// .set(WorkFlow::getWorkStatus, 1) +// .in(WorkFlow::getWorkFlowId, workFlowIds) +// .eq(WorkFlow::getWorkStatus, 0)); +// // 更新工单表状态 +// kateOrdersService.update(new LambdaUpdateWrapper() +// .set(KateOrders::getOrderStatus, 2) +// .in(KateOrders::getOrderId, orderIds) +// .in(KateOrders::getGoodsId, goodsIds) +// .in(KateOrders::getSupplyArea, smallBoxes) +// .eq(KateOrders::getOrderStatus, 1)); // } catch (Exception e) { // logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e)); // // 回滚事务 @@ -573,105 +442,134 @@ public class WorkServiceImplements implements IWorkService { // } @Override - public String finishWork(String workStation) throws Exception { - if (workFinishingStations.contains(workStation)) { - // 当前站台正在完成工作 - return "当前站台正在完成工作,请勿重复操作"; + @Transactional(isolation = Isolation.REPEATABLE_READ, propagation = Propagation.REQUIRED) + public void doWork(String workStation) throws Exception { + if (workDoingStations.contains(workStation)) { + // 当前站台正在创建任务 + return; } else { // 添加站台 - workFinishingStations.add(workStation); + workDoingStations.add(workStation); } try { - if (workFlowService.exists(new LambdaQueryWrapper() + // 查找当前站台未开始的工作流 + List currentWorkFlowList = workFlowService.list(new LambdaQueryWrapper() .eq(WorkFlow::getWorkStation, workStation) - .ne(WorkFlow::getWorkStatus, 2))) { - // 当前站台工作未全部完成 - return "工作未全部做完,不允许确认完成。"; + .eq(WorkFlow::getWorkStatus, 1)); + // 没有可做的任务 + if (currentWorkFlowList == null || currentWorkFlowList.isEmpty()) { + return; } - if (eLocationConfigService.exists(new LambdaQueryWrapper() - .eq(ELocationConfig::getWorkStation, workStation) - .eq(ELocationConfig::getPrintStatus, 0))) { - // 有标签未打印 - return "有标签未打印"; - } - if (!eLocationConfigService.exists(new LambdaQueryWrapper() - .eq(ELocationConfig::getWorkStation, workStation))) { - // 没有标签,说明点过确认。 - return "没有可以确认完成的工作,请勿重复点击。"; - } - // 查找当前站台的标签配置 - List eLocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper() - .eq(ELocationConfig::getWorkStation, workStation)); - // 保存一下记录 - List eLocationConfigLastList = ELocationConfig.toLocationsConfigLastList(eLocationConfigList); - // 先清空之前的 - eLocationConfigLastService.remove(new LambdaQueryWrapper() - .eq(ELocationConfigLast::getWorkStation, workStation)); - eLocationConfigLastService.saveBatch(eLocationConfigLastList); - // 删除所有的标签配置 - eLocationConfigService.remove(new LambdaQueryWrapper() - .eq(ELocationConfig::getWorkStation, workStation)); - // 查询当前站台的所有工作流列表 - List workFlowList = workFlowService.list(new LambdaQueryWrapper() - .eq(WorkFlow::getWorkStation, workStation) - .eq(WorkFlow::getWorkStatus, 2)); - // workSummary列表 - List workSummaryList = new ArrayList<>(); - for (WorkFlow workFlow : workFlowList) { - WorkSummary summary = new WorkSummary(); - summary.setWorkFlowId(workFlow.getWorkFlowId()); - summary.setWorkStation(workFlow.getWorkStation()); - summary.setWorkOrder(workFlow.getWorkOrder()); - summary.setWorkCenter(workFlow.getWorkCenter()); - summary.setGoodsId(workFlow.getGoodsId()); - summary.setPickedNum(workFlow.getPickedNum()); - summary.setNeedNum(workFlow.getNeedNum()); - summary.setLackNum(workFlow.getNeedNum().subtract(workFlow.getPickedNum())); - summary.setWorkDate(workFlow.getCreateTime().toLocalDate().atStartOfDay()); - summary.setWorkStatus(workFlow.getWorkStatus()); - summary.setLackStatus(summary.getLackNum().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0); - summary.setFinishTime(workFlow.getFinishTime()); - summary.setOpUser(workFlow.getOpUser()); - // 设置电子标签位置 - List currentBoxELocationList = eLocationConfigList.stream().filter(e -> - e.getWorkOrder().equals(workFlow.getWorkOrder()) - && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList(); - summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : ""); - workSummaryList.add(summary); - // 更新工单表 - kateOrdersService.update(new LambdaUpdateWrapper() - .set(KateOrders::getOrderStatus, 4) - .set(KateOrders::getFinishTime, LocalDateTime.now()) - .set(KateOrders::getPickedQuantity, workFlow.getPickedNum()) - .set(KateOrders::getLackQuantity, workFlow.getNeedNum().subtract(workFlow.getPickedNum())) - .eq(KateOrders::getOrderId, workFlow.getOrderId()) - .eq(KateOrders::getSupplyArea, workFlow.getWorkCenter()) - .eq(KateOrders::getGoodsId, workFlow.getGoodsId())); - // 如果当前工单已经没有未完成的工作,更新DBS状态完成 - if (!kateOrdersService.exists(new LambdaQueryWrapper() - .eq(KateOrders::getOrderId, workFlow.getOrderId()) - .ne(KateOrders::getOrderStatus, 4))) { - kateDBSService.update(new LambdaUpdateWrapper() - .set(KateDBS::getDbsStatus, 2) - .set(KateDBS::getLastUpdateTime, LocalDateTime.now()) - .eq(KateDBS::getWorkOrder, workFlow.getOrderId())); - } - } - workSummaryService.saveBatch(workSummaryList); - // 移除工作流 - workFlowService.remove(new LambdaQueryWrapper() - .eq(WorkFlow::getWorkStation, workStation)); - // 移库站台要料 - goodsToStationService.remove(new LambdaQueryWrapper() + // 查站台要料表---未分配以及分配但未完全分配 + List goodsToStationList = goodsToStationService.list(new LambdaQueryWrapper() .eq(GoodsToStation::getWorkStation, workStation)); + List notFinishedGoodsList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() < 2).toList(); + if (notFinishedGoodsList.isEmpty()) { + // 查询是否还有这个站台的拣选任务 + if (!pickTaskService.exists(new LambdaQueryWrapper() + .eq(PickTask::getStandId, workStation))) { + // 需要重新分配的goodsToStationsList + Map needDistributeGoodsMap = new HashMap<>(); + // 需要完成的工作流 + List needFinishWorkFlowList = new ArrayList<>(); + // 所有缺料的分配 + List lackGoodsIdList = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 3).map(GoodsToStation::getGoodsId).distinct().toList(); + // 不缺料的分配 + Map noLackGoodsMap = goodsToStationList.stream().filter(goodsToStation -> goodsToStation.getDistributeStatus() == 2).collect(Collectors.toMap(GoodsToStation::getGoodsId, goodsToStation -> goodsToStation)); + // 查询当前工作流中所有缺料的数据行 + for (WorkFlow notFinishedWorkFlow : currentWorkFlowList) { + if (notFinishedWorkFlow.getPickedNum().compareTo(notFinishedWorkFlow.getNeedNum()) < 0) { + // 缺料时,判断是否当前物料在缺料列表中 + if (lackGoodsIdList.contains(notFinishedWorkFlow.getGoodsId())) { + // 缺料,添加到需要分配的列表中 + notFinishedWorkFlow.setWorkStatus(2); + notFinishedWorkFlow.setFinishTime(LocalDateTime.now()); + notFinishedWorkFlow.setOpUser("系统自动完成"); + needFinishWorkFlowList.add(notFinishedWorkFlow); + } else { + BigDecimal needNum = notFinishedWorkFlow.getNeedNum().subtract(notFinishedWorkFlow.getPickedNum()); + if (needDistributeGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) { + // 减少分配数量 + GoodsToStation oldGoodsToStation = needDistributeGoodsMap.get(notFinishedWorkFlow.getGoodsId()); + oldGoodsToStation.setDistributedNum(oldGoodsToStation.getDistributedNum().subtract(needNum)); + oldGoodsToStation.setDistributeStatus(1); + needDistributeGoodsMap.replace(notFinishedWorkFlow.getGoodsId(), oldGoodsToStation); + } else { + if (noLackGoodsMap.containsKey(notFinishedWorkFlow.getGoodsId())) { + GoodsToStation newGoodsToStation = noLackGoodsMap.get(notFinishedWorkFlow.getGoodsId()); + newGoodsToStation.setDistributedNum(newGoodsToStation.getDistributedNum().subtract(needNum)); + newGoodsToStation.setDistributeStatus(1); + needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), newGoodsToStation); + } else { + GoodsToStation goodsToStation = new GoodsToStation(); + goodsToStation.setConfigId(notFinishedWorkFlow.getGoodsId() + "_" + workStation); + goodsToStation.setGoodsId(notFinishedWorkFlow.getGoodsId()); + goodsToStation.setWorkStation(workStation); + goodsToStation.setDistributeStatus(0); + goodsToStation.setDistributedNum(BigDecimal.ZERO); + goodsToStation.setTotalNum(needNum); + needDistributeGoodsMap.put(notFinishedWorkFlow.getGoodsId(), goodsToStation); + } + } + } + } else { + // 不缺料,直接完成 + notFinishedWorkFlow.setWorkStatus(2); + notFinishedWorkFlow.setFinishTime(LocalDateTime.now()); + notFinishedWorkFlow.setOpUser("系统自动完成"); + needFinishWorkFlowList.add(notFinishedWorkFlow); + } + } + // 保存重新分配的goodsToStationList + goodsToStationService.saveOrUpdateBatch(needDistributeGoodsMap.values()); + // 保存需要完成的工作流 + workFlowService.updateBatchById(needFinishWorkFlowList); + } + return; + } + for (GoodsToStation goodsToStation : notFinishedGoodsList) { + // 当前物料当前站台需求数量 + BigDecimal needNum = goodsToStation.getTotalNum().subtract(goodsToStation.getDistributedNum()); + if (needNum.compareTo(BigDecimal.ZERO) == 0) { + // 需求数量为0 + continue; + } + // 判断实际库存是否充足 + List stockList = stockService.list(new LambdaQueryWrapper() + .apply("goods_related ->> '$.goodsId' = {0}" + MYSQL_JSON_CI, goodsToStation.getGoodsId()) + .apply("goods_related ->> '$.remainNum' > 0")); + if (stockList == null || stockList.isEmpty()) { + goodsToStation.setDistributeStatus(3); + continue; + } + // 判断当前物料是否在流转中 + needNum = wmsTaskService.callGoods(goodsToStation.getGoodsId(), needNum, workStation); + // 判断此时需求数量是否为0 + if (needNum.compareTo(BigDecimal.ZERO) <= 0) { + // 分配完成 + goodsToStation.setDistributeStatus(2); + } else { + needNum = wmsTaskService.callStocks(goodsToStation.getGoodsId(), needNum, workStation); + if (needNum.compareTo(BigDecimal.ZERO) > 0) { + // 已分配但未完全分配 + goodsToStation.setDistributeStatus(1); + } else { + // 分配完成 + goodsToStation.setDistributeStatus(2); + } + } + // 更新已分配数量 + goodsToStation.setDistributedNum(goodsToStation.getTotalNum().subtract(needNum)); + } + goodsToStationService.updateBatchById(notFinishedGoodsList); } catch (Exception e) { - logger.error("完成站台:{}工作发生异常:{}", workStation, convertJsonString(e)); - throw new Exception("完成站台:" + workStation + "工作发生异常!"); + logger.error("执行站台:{}工作发生异常:{}", workStation, convertJsonString(e)); + // 回滚事务 + TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); } finally { - // 当前站台工作完成 - workFinishingStations.remove(workStation); + // 当前站台创建任务完成 + workDoingStations.remove(workStation); } - return ""; } // @Override @@ -686,7 +584,7 @@ public class WorkServiceImplements implements IWorkService { // try { // if (workFlowService.exists(new LambdaQueryWrapper() // .eq(WorkFlow::getWorkStation, workStation) -// .eq(WorkFlow::getWorkStatus, 1))) { +// .ne(WorkFlow::getWorkStatus, 2))) { // // 当前站台工作未全部完成 // return "工作未全部做完,不允许确认完成。"; // } @@ -740,6 +638,24 @@ public class WorkServiceImplements implements IWorkService { // && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList(); // summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : ""); // workSummaryList.add(summary); +// // 更新工单表 +// kateOrdersService.update(new LambdaUpdateWrapper() +// .set(KateOrders::getOrderStatus, 4) +// .set(KateOrders::getFinishTime, LocalDateTime.now()) +// .set(KateOrders::getPickedQuantity, workFlow.getPickedNum()) +// .set(KateOrders::getLackQuantity, workFlow.getNeedNum().subtract(workFlow.getPickedNum())) +// .eq(KateOrders::getOrderId, workFlow.getOrderId()) +// .eq(KateOrders::getSupplyArea, workFlow.getWorkCenter()) +// .eq(KateOrders::getGoodsId, workFlow.getGoodsId())); +// // 如果当前工单已经没有未完成的工作,更新DBS状态完成 +// if (!kateOrdersService.exists(new LambdaQueryWrapper() +// .eq(KateOrders::getOrderId, workFlow.getOrderId()) +// .ne(KateOrders::getOrderStatus, 4))) { +// kateDBSService.update(new LambdaUpdateWrapper() +// .set(KateDBS::getDbsStatus, 2) +// .set(KateDBS::getLastUpdateTime, LocalDateTime.now()) +// .eq(KateDBS::getWorkOrder, workFlow.getOrderId())); +// } // } // workSummaryService.saveBatch(workSummaryList); // // 移除工作流 @@ -758,6 +674,90 @@ public class WorkServiceImplements implements IWorkService { // return ""; // } + @Override + public String finishWork(String workStation) throws Exception { + if (workFinishingStations.contains(workStation)) { + // 当前站台正在完成工作 + return "当前站台正在完成工作,请勿重复操作"; + } else { + // 添加站台 + workFinishingStations.add(workStation); + } + try { + if (workFlowService.exists(new LambdaQueryWrapper() + .eq(WorkFlow::getWorkStation, workStation) + .eq(WorkFlow::getWorkStatus, 1))) { + // 当前站台工作未全部完成 + return "工作未全部做完,不允许确认完成。"; + } + if (eLocationConfigService.exists(new LambdaQueryWrapper() + .eq(ELocationConfig::getWorkStation, workStation) + .eq(ELocationConfig::getPrintStatus, 0))) { + // 有标签未打印 + return "有标签未打印"; + } + if (!eLocationConfigService.exists(new LambdaQueryWrapper() + .eq(ELocationConfig::getWorkStation, workStation))) { + // 没有标签,说明点过确认。 + return "没有可以确认完成的工作,请勿重复点击。"; + } + // 查找当前站台的标签配置 + List eLocationConfigList = eLocationConfigService.list(new LambdaQueryWrapper() + .eq(ELocationConfig::getWorkStation, workStation)); + // 保存一下记录 + List eLocationConfigLastList = ELocationConfig.toLocationsConfigLastList(eLocationConfigList); + // 先清空之前的 + eLocationConfigLastService.remove(new LambdaQueryWrapper() + .eq(ELocationConfigLast::getWorkStation, workStation)); + eLocationConfigLastService.saveBatch(eLocationConfigLastList); + // 删除所有的标签配置 + eLocationConfigService.remove(new LambdaQueryWrapper() + .eq(ELocationConfig::getWorkStation, workStation)); + // 查询当前站台的所有工作流列表 + List workFlowList = workFlowService.list(new LambdaQueryWrapper() + .eq(WorkFlow::getWorkStation, workStation) + .eq(WorkFlow::getWorkStatus, 2)); + // workSummary列表 + List workSummaryList = new ArrayList<>(); + for (WorkFlow workFlow : workFlowList) { + WorkSummary summary = new WorkSummary(); + summary.setWorkFlowId(workFlow.getWorkFlowId()); + summary.setWorkStation(workFlow.getWorkStation()); + summary.setWorkOrder(workFlow.getWorkOrder()); + summary.setWorkCenter(workFlow.getWorkCenter()); + summary.setGoodsId(workFlow.getGoodsId()); + summary.setPickedNum(workFlow.getPickedNum()); + summary.setNeedNum(workFlow.getNeedNum()); + summary.setLackNum(workFlow.getNeedNum().subtract(workFlow.getPickedNum())); + summary.setWorkDate(workFlow.getCreateTime().toLocalDate().atStartOfDay()); + summary.setWorkStatus(workFlow.getWorkStatus()); + summary.setLackStatus(summary.getLackNum().compareTo(BigDecimal.ZERO) > 0 ? 1 : 0); + summary.setFinishTime(workFlow.getFinishTime()); + summary.setOpUser(workFlow.getOpUser()); + // 设置电子标签位置 + List currentBoxELocationList = eLocationConfigList.stream().filter(e -> + e.getWorkOrder().equals(workFlow.getWorkOrder()) + && e.getWorkCenter().equals(workFlow.getWorkCenter())).toList(); + summary.setELocationId(currentBoxELocationList.size() > 0 ? currentBoxELocationList.get(0).getELocationId() : ""); + workSummaryList.add(summary); + } + workSummaryService.saveBatch(workSummaryList); + // 移除工作流 + workFlowService.remove(new LambdaQueryWrapper() + .eq(WorkFlow::getWorkStation, workStation)); + // 移库站台要料 + goodsToStationService.remove(new LambdaQueryWrapper() + .eq(GoodsToStation::getWorkStation, workStation)); + } catch (Exception e) { + logger.error("完成站台:{}工作发生异常:{}", workStation, convertJsonString(e)); + throw new Exception("完成站台:" + workStation + "工作发生异常!"); + } finally { + // 当前站台工作完成 + workFinishingStations.remove(workStation); + } + return ""; + } + /** * 先找到MWL的小工位的配置 *