From 62ad99ee2a374c1726730146335ed82cbcfacebb Mon Sep 17 00:00:00 2001 From: cuilei <ray_tsu1@163.com> Date: 星期三, 28 五月 2025 00:04:18 +0800 Subject: [PATCH] 工具管理-新增方式出库接口及部分查询调整 --- lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java | 122 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 117 insertions(+), 5 deletions(-) diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java index f5cdf56..603c545 100644 --- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java +++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java @@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -27,6 +28,7 @@ import org.jeecg.modules.flowable.service.IFlowTaskService; import org.jeecg.modules.system.service.ISysBusinessCodeRuleService; import org.jeecg.modules.tms.entity.*; +import org.jeecg.modules.tms.entity.dto.OutBoundAddDto; import org.jeecg.modules.tms.entity.dto.OutBoundOrderFlowDto; import org.jeecg.modules.tms.entity.dto.OutBoundRequestDto; import org.jeecg.modules.tms.entity.dto.OutboundOrderAndDetailDto; @@ -64,6 +66,8 @@ private IToolLedgerDetailService toolLedgerDetailService; @Autowired private IOutStoreDetailService outStoreDetailService; + @Autowired + private IBaseToolsService baseToolsService; @Autowired private ISysBusinessCodeRuleService businessCodeRuleService; @Autowired @@ -125,9 +129,13 @@ if (outStorehouseTypes != null && outStorehouseTypes.length > 0) { queryWrapper.eq("t.out_storehouse_type", outStorehouseTypes[0]); } - String[] statuses = parameterMap.get("orderStatus"); - if (statuses != null && statuses.length > 0) { - queryWrapper.eq("t.order_status", statuses[0]); + String[] orderStatuses = parameterMap.get("orderStatus"); + if (orderStatuses != null && orderStatuses.length > 0) { + queryWrapper.eq("t.order_status", orderStatuses[0]); + } + String[] outStatuses = parameterMap.get("outStatus"); + if (outStatuses != null && outStatuses.length > 0) { + queryWrapper.eq("t.out_status", outStatuses[0]); } String[] startTimes = parameterMap.get("startTime"); if (startTimes != null && startTimes.length > 0) { @@ -219,6 +227,11 @@ if (OutBillStatus.APPROVED.getValue().equals(outBoundOrderFlowDto.getStatus())) { outboundOrder.setOutStatus(OutBoundStatusEnum.NOT_OUTBOUND.getValue()); outboundOrder.setOrderStatus(OutBillStatus.APPROVED.getValue()); + //鍒濆鍖栫敵璇锋槑缁嗕俊鎭殑鍑哄簱鐘舵��/瀹為檯鍑哄簱鏁伴噺瀛楁 + outboundDetailService.update(new LambdaUpdateWrapper<OutboundDetail>() + .eq(OutboundDetail::getOutStorehouseId, outboundOrder.getId()) + .set(OutboundDetail::getStatus, OutBoundStatusEnum.NOT_OUTBOUND.getValue()) + .set(OutboundDetail::getOutActualCount, BigDecimal.ZERO)); } if (OutBillStatus.REJECTED.getValue().equals(outBoundOrderFlowDto.getStatus())) { //濡傛灉椹冲洖锛屽鎵瑰崟鐘舵�佸洖鍒拌崏绋� @@ -232,7 +245,7 @@ @Override @Transactional(rollbackFor = Exception.class) - public void outBound(List<OutBoundRequestDto> outBoundRequestList) { + public void outBoundByApply(List<OutBoundRequestDto> outBoundRequestList) { //鏍¢獙鏄惁鏉ヨ嚜涓�涓敵璇峰崟 if (!fromOneApply(outBoundRequestList)) { throw new JeecgBootException("鍑哄簱鏄庣粏蹇呴』鏉ヨ嚜鍚屼竴鍑哄簱鐢宠鍗曪紒"); @@ -259,7 +272,7 @@ queryWrapper.or(); } OutboundDetail detail = outboundDetailList.get(i); - queryWrapper.and(wrapper -> + queryWrapper.or(wrapper -> wrapper.eq(ToolLedgerDetail::getToolCode, detail.getToolCode()) .eq(ToolLedgerDetail::getToolId, detail.getToolId()) //濡傛灉涓嶇鍒版妸锛岃瀛楁涓虹┖ ); @@ -362,6 +375,105 @@ updateById(outboundOrder); } + @Override + @Transactional(rollbackFor = Exception.class) + public void outBoundByAdd(List<OutBoundAddDto> boundAddList) { + //鏍¢獙鍙拌处涓昏〃搴撳瓨鏁伴噺 + Map<String, BigDecimal> toolBoundQuantityMap = boundAddList.stream() + .collect(Collectors.groupingBy(OutBoundAddDto::getToolCode, + Collectors.mapping(OutBoundAddDto::getOutboundQuantity, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add)))); + Map<String, ToolLedger> toolLedgerMap = toolLedgerService.list(new LambdaQueryWrapper<ToolLedger>().in(ToolLedger::getToolId, toolBoundQuantityMap.keySet())) + .stream().collect(Collectors.toMap(ToolLedger::getToolId, item -> item, (k1, k2) -> k1)); + List<ToolLedger> toolLedgerUpdateList = CollectionUtil.newArrayList(); + for (String toolCode : toolBoundQuantityMap.keySet()) { + ToolLedger toolLedger = toolLedgerMap.get(toolCode); + BigDecimal outBoundQuantity = toolBoundQuantityMap.get(toolCode); + if (Objects.isNull(toolLedger) || toolLedger.getAvailableCount().compareTo(outBoundQuantity) < 0) { + BaseTools tools = baseToolsService.getById(toolCode); + throw new JeecgBootException("缂栫爜涓恒��" + tools.getToolCode() + "銆戠殑宸ュ叿锛屽簱瀛樹笉瓒筹紒"); + } else { + OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(boundAddList.get(0).getOutStorehouseType()); + switch (outStorehouseType) { + case TOOL_BORROW: + toolLedger.setLendCount(toolLedger.getLendCount().add(outBoundQuantity)); + break; + case MAINTENANCE_OUTBOUND: + toolLedger.setRepairCount(toolLedger.getRepairCount().add(outBoundQuantity)); + break; + case CALIBRATION_OUTBOUND: + toolLedger.setDetectionCount(toolLedger.getDetectionCount().add(outBoundQuantity)); + break; + case GRINDING_OUTBOUND: + toolLedger.setSharpeningCount(toolLedger.getSharpeningCount().add(outBoundQuantity)); + break; + default: + throw new JeecgBootException("鏈煡鐨勫嚭搴撶被鍨嬶紒"); + } + //鎵e噺鍙拌处涓昏〃鍙敤搴撳瓨 + toolLedger.setAvailableCount(toolLedger.getAvailableCount().subtract(outBoundQuantity)); + toolLedgerUpdateList.add(toolLedger); + } + } + //鏍¢獙鍙拌处鏄庣粏搴撳瓨鏁伴噺 + Map<String, OutBoundAddDto> boundAddDtoMap = boundAddList.stream().collect(Collectors + .toMap(OutBoundAddDto::getToolLedgerDetailId, item -> item, (k1, k2) -> k1)); + Map<String, ToolLedgerDetail> toolLedgerDetailMap = toolLedgerDetailService.listByIds(boundAddDtoMap.keySet()).stream() + .collect(Collectors.toMap(ToolLedgerDetail::getId, item -> item, (k1, k2) -> k1)); + List<ToolLedgerDetail> toolLedgerDetailUpdateList = CollectionUtil.newArrayList(); + for (String toolLedgerDetailId : boundAddDtoMap.keySet()) { + OutBoundAddDto outBoundAddDto = boundAddDtoMap.get(toolLedgerDetailId); + BigDecimal outboundQuantity = outBoundAddDto.getOutboundQuantity(); + ToolLedgerDetail toolLedgerDetail = toolLedgerDetailMap.get(toolLedgerDetailId); + if (Objects.isNull(toolLedgerDetail) || toolLedgerDetail.getQuantity().compareTo(outboundQuantity) < 0) { + BaseTools tools = baseToolsService.getById(outBoundAddDto.getToolCode()); + throw new JeecgBootException("缂栫爜涓恒��" + tools.getToolCode() + "銆戠殑宸ュ叿锛屽簱瀛樹笉瓒筹紒"); + } else { + //鎵e噺鍙拌处鏄庣粏搴撳瓨 + if (StrUtil.isBlank(toolLedgerDetail.getToolId())) { + //娌℃湁鍞竴缂栫爜锛屼笉绠″埌鎶婄殑 + toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().subtract(outboundQuantity)); + } else { + //鏈夊敮涓�缂栫爜锛岀閬撴妸鐨� + toolLedgerDetail.setQuantity(BigDecimal.ZERO);//鏁伴噺鍙細鏄�0鍜�1 + OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(boundAddList.get(0).getOutStorehouseType()); + switch (outStorehouseType) { + case TOOL_BORROW: + toolLedgerDetail.setStatus(ToolCirculationStatus.BORROWED.getValue()); + break; + case MAINTENANCE_OUTBOUND: + toolLedgerDetail.setStatus(ToolCirculationStatus.REPAIRING.getValue()); + break; + case CALIBRATION_OUTBOUND: + toolLedgerDetail.setStatus(ToolCirculationStatus.INSPECTING.getValue()); + break; + case GRINDING_OUTBOUND: + toolLedgerDetail.setStatus(ToolCirculationStatus.GRINDING.getValue()); + break; + default: + throw new JeecgBootException("鏈煡鐨勫嚭搴撶被鍨嬶紒"); + } + } + toolLedgerDetailUpdateList.add(toolLedgerDetail); + } + } + toolLedgerService.updateBatchById(toolLedgerUpdateList); + toolLedgerDetailService.updateBatchById(toolLedgerDetailUpdateList); + //璁板綍鍑哄簱娴佹按 + List<OutStoreDetail> outStoreAddList = CollectionUtil.newArrayList(); + for (OutBoundAddDto outBoundAddDto : boundAddList) { + OutStoreDetail outStoreDetail = new OutStoreDetail() + .setToolCode(outBoundAddDto.getToolCode()) + .setToolId(outBoundAddDto.getToolId()) + .setOutStorehouseType(outBoundAddDto.getOutStorehouseType()) + .setGoodsShelvesCode(outBoundAddDto.getOutboundLocation()) + .setOutNumber(outBoundAddDto.getOutboundQuantity()) + .setOperateType("2");//2锛氭墜宸ユ搷浣� + outStoreAddList.add(outStoreDetail); + } + outStoreDetailService.saveBatch(outStoreAddList); + } + + private boolean fromOneApply(List<OutBoundRequestDto> outBoundRequestList) { long count = outBoundRequestList.stream().map(OutBoundRequestDto::getOutBoundOrderId).distinct().count(); if (count > 1) { -- Gitblit v1.9.3