From c15c5c9a096790a3b621e44329bc7caf961a0453 Mon Sep 17 00:00:00 2001 From: c Date: Tue, 10 Mar 2026 09:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E9=87=87=E8=B4=AD=E8=B0=83?= =?UTF-8?q?=E6=8B=A8=E5=8D=95=EF=BC=8C=E5=85=A5=E5=BA=93=E5=8D=95=EF=BC=8C?= =?UTF-8?q?=E9=83=A8=E5=88=86=E5=BA=93=E5=AD=98=E7=9B=98=E7=82=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/handler/CustomerTenantHandler.java | 1 + .../controller/InventoryCountController.java | 62 +------ .../WarehouseReceiptController.java | 42 +++-- .../controller/dto/WarehouseReceiptDto.java | 10 +- .../converter/InventoryCountConverter.java | 1 - .../service/WarehouseReceiptService.java | 4 +- .../impl/InventoryCountServiceImpl.java | 154 ++++++------------ .../impl/WarehouseReceiptServiceImpl.java | 125 ++++++++------ src/main/resources/i18n/messages.properties | 30 +++- 9 files changed, 183 insertions(+), 246 deletions(-) diff --git a/src/main/java/com/niuan/erp/common/handler/CustomerTenantHandler.java b/src/main/java/com/niuan/erp/common/handler/CustomerTenantHandler.java index 75f4bd7..f5ecdfc 100644 --- a/src/main/java/com/niuan/erp/common/handler/CustomerTenantHandler.java +++ b/src/main/java/com/niuan/erp/common/handler/CustomerTenantHandler.java @@ -23,6 +23,7 @@ public class CustomerTenantHandler implements TenantLineHandler { customerTables.add("storage_list"); customerTables.add("bom_list"); customerTables.add("vendor"); + customerTables.add("productionform"); } @Override diff --git a/src/main/java/com/niuan/erp/module/warehouse/controller/InventoryCountController.java b/src/main/java/com/niuan/erp/module/warehouse/controller/InventoryCountController.java index 47ddf25..ecce817 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/controller/InventoryCountController.java +++ b/src/main/java/com/niuan/erp/module/warehouse/controller/InventoryCountController.java @@ -24,6 +24,8 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; @Tag(name = "InventoryCount") @@ -41,15 +43,15 @@ public class InventoryCountController { public BaseResult> getInventoryCountPage(@Validated BasePageReqParams pageParams, @Validated(Get.class) InventoryCountDto searchParams) { var wrapper = new LambdaQueryWrapper(); - if (searchParams != null) { - if (StringUtils.hasText(searchParams.searchCode())) { - wrapper.like(Document::getFormCode, searchParams.searchCode()); - } + if (searchParams != null) { + if (StringUtils.hasText(searchParams.searchCode())) { + wrapper.like(Document::getFormCode, searchParams.searchCode()); } + } + wrapper.orderByDesc(Document::getCreateDate); return BaseResult.successWithData(inventoryCountService.getInventoryCountPage(pageParams, wrapper)); } - @ApiLog(type = OperationType.ADD, remark = "新增一条InventoryCount记录") @Operation(summary = "新增InventoryCount", operationId = "addInventoryCount") @PostMapping("/addInventoryCount") @@ -59,66 +61,20 @@ public class InventoryCountController { return BaseResult.success(); } - @ApiLog(type = OperationType.UPDATE, remark = "更新一条InventoryCount记录") - @Operation(summary = "更新InventoryCount", operationId = "updateInventoryCount") - @PostMapping("/updateInventoryCount") - @PreAuthorize("hasAuthority('inventory_count:update')") - public BaseResult updateInventoryCount(@Validated(Update.class) @RequestBody InventoryCountDto dto) { - inventoryCountService.updateInventoryCount(dto); - return BaseResult.success(); - } - @ApiLog(type = OperationType.DELETE, remark = "删除一条InventoryCount记录") @Operation(summary = "删除InventoryCount", operationId = "deleteInventoryCount") @PostMapping("/deleteInventoryCount") - @PreAuthorize("hasAuthority('inventory_count:delete')") + @PreAuthorize("hasAuthority('inventory_count:remove')") public BaseResult deleteInventoryCount(@Validated(DeleteOne.class) @RequestBody BaseDeleteBody req) { inventoryCountService.deleteInventoryCount(req.id()); return BaseResult.success(); } - @ApiLog(type = OperationType.DELETE, remark = "批量删除InventoryCount记录") - @Operation(summary = "批量删除InventoryCount", operationId = "deleteInventoryCountBatch") - @PostMapping("/deleteInventoryCountBatch") - @PreAuthorize("hasAuthority('inventory_count:deleteBatch')") - public BaseResult deleteInventoryCountBatch(@Validated(DeleteBatch.class) @RequestBody BaseDeleteBody req) { - inventoryCountService.deleteBatch(req.ids()); - return BaseResult.success(); - } - - @ApiLog(type = OperationType.UPDATE, remark = "审核InventoryCount") - @Operation(summary = "审核InventoryCount", operationId = "approveInventoryCount") - @PostMapping("/approveInventoryCount") - @PreAuthorize("hasAuthority('inventory_count:approve')") - public BaseResult approveInventoryCount( - @Parameter(description = "盘点单ID") @RequestParam Long id) { - inventoryCountService.approve(id); - return BaseResult.success(); - } - - @ApiLog(type = OperationType.UPDATE, remark = "反审核InventoryCount") - @Operation(summary = "反审核InventoryCount", operationId = "unapproveInventoryCount") - @PostMapping("/unapproveInventoryCount") - @PreAuthorize("hasAuthority('inventory_count:unapprove')") - public BaseResult unapproveInventoryCount( - @Parameter(description = "盘点单ID") @RequestParam Long id) { - inventoryCountService.unapprove(id); - return BaseResult.success(); - } - @Operation(summary = "获取InventoryCount明细", operationId = "getInventoryCountDetail") @GetMapping("/getInventoryCountDetail") - @PreAuthorize("hasAuthority('inventorycount:index')") + @PreAuthorize("hasAuthority('inventory_count:index')") public BaseResult> getInventoryCountDetail( @Parameter(description = "盘点单ID") @RequestParam Long id) { return BaseResult.successWithData(inventoryCountService.getDetail(id)); } - - @Operation(summary = "导入InventoryCount明细", operationId = "importInventoryCountItems") - @PostMapping("/importInventoryCountItems") - @PreAuthorize("hasAuthority('inventory_count:import')") - public BaseResult> importInventoryCountItems( - @Parameter(description = "Excel文件") @RequestParam("file") MultipartFile file) { - return BaseResult.successWithData(inventoryCountService.importItems(file)); - } } diff --git a/src/main/java/com/niuan/erp/module/warehouse/controller/WarehouseReceiptController.java b/src/main/java/com/niuan/erp/module/warehouse/controller/WarehouseReceiptController.java index 57d0145..8d625a8 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/controller/WarehouseReceiptController.java +++ b/src/main/java/com/niuan/erp/module/warehouse/controller/WarehouseReceiptController.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.niuan.erp.common.annotation.ApiLog; import com.niuan.erp.common.annotation.ModuleLog; +import com.niuan.erp.common.base.BaseApproveAndRejectDto; import com.niuan.erp.common.base.BaseDeleteBody; import com.niuan.erp.common.base.BasePageReqParams; import com.niuan.erp.common.base.BaseResult; @@ -41,11 +42,14 @@ public class WarehouseReceiptController { public BaseResult> getWarehouseReceiptPage(@Validated BasePageReqParams pageParams, @Validated(Get.class) WarehouseReceiptDto searchParams) { var wrapper = new LambdaQueryWrapper(); - if (searchParams != null) { - if (StringUtils.hasText(searchParams.searchCode())) { - wrapper.like(Document::getFormCode, searchParams.searchCode()); - } - } + if (searchParams != null && StringUtils.hasText(searchParams.searchCode())) { + String searchCode = searchParams.searchCode(); + wrapper.and(w -> w.like(Document::getFormCode, searchCode) + .or() + .like(Document::getFormName, searchCode) + .or() + .like(Document::getFormMark, searchCode)); + } return BaseResult.successWithData(warehouseReceiptService.getWarehouseReceiptPage(pageParams, wrapper)); } @@ -71,7 +75,7 @@ public class WarehouseReceiptController { @ApiLog(type = OperationType.DELETE, remark = "删除一条WarehouseReceipt记录") @Operation(summary = "删除WarehouseReceipt", operationId = "deleteWarehouseReceipt") @PostMapping("/deleteWarehouseReceipt") - @PreAuthorize("hasAuthority('warehouse_receipt:delete')") + @PreAuthorize("hasAuthority('warehouse_receipt:remove')") public BaseResult deleteWarehouseReceipt(@Validated(DeleteOne.class) @RequestBody BaseDeleteBody req) { warehouseReceiptService.deleteWarehouseReceipt(req.id()); return BaseResult.success(); @@ -91,34 +95,26 @@ public class WarehouseReceiptController { @PostMapping("/approveWarehouseReceipt") @PreAuthorize("hasAuthority('warehouse_receipt:approve')") public BaseResult approveWarehouseReceipt( - @Parameter(description = "入库单ID") @RequestParam Long id) { - warehouseReceiptService.approve(id); + @Validated @RequestBody BaseApproveAndRejectDto dto) { + warehouseReceiptService.approve(dto.id()); return BaseResult.success(); } @ApiLog(type = OperationType.UPDATE, remark = "反审核WarehouseReceipt") - @Operation(summary = "反审核WarehouseReceipt", operationId = "unapproveWarehouseReceipt") - @PostMapping("/unapproveWarehouseReceipt") - @PreAuthorize("hasAuthority('warehouse_receipt:unapprove')") - public BaseResult unapproveWarehouseReceipt( - @Parameter(description = "入库单ID") @RequestParam Long id) { - warehouseReceiptService.unapprove(id); + @Operation(summary = "反审核WarehouseReceipt", operationId = "rejectWarehouseReceipt") + @PostMapping("/rejectWarehouseReceipt") + @PreAuthorize("hasAuthority('warehouse_receipt:reject')") + public BaseResult rejectWarehouseReceipt( + @Validated @RequestBody BaseApproveAndRejectDto dto) { + warehouseReceiptService.reject(dto.id()); return BaseResult.success(); } @Operation(summary = "获取WarehouseReceipt明细", operationId = "getWarehouseReceiptDetail") @GetMapping("/getWarehouseReceiptDetail") - @PreAuthorize("hasAuthority('warehousereceipt:index')") + @PreAuthorize("hasAuthority('warehouse_receipt:index')") public BaseResult> getWarehouseReceiptDetail( @Parameter(description = "入库单ID") @RequestParam Long id) { return BaseResult.successWithData(warehouseReceiptService.getDetail(id)); } - - @Operation(summary = "导入WarehouseReceipt明细", operationId = "importWarehouseReceiptItems") - @PostMapping("/importWarehouseReceiptItems") - @PreAuthorize("hasAuthority('warehouse_receipt:add')") - public BaseResult> importWarehouseReceiptItems( - @Parameter(description = "Excel文件") @RequestParam("file") MultipartFile file) { - return BaseResult.successWithData(warehouseReceiptService.importItems(file)); - } } diff --git a/src/main/java/com/niuan/erp/module/warehouse/controller/dto/WarehouseReceiptDto.java b/src/main/java/com/niuan/erp/module/warehouse/controller/dto/WarehouseReceiptDto.java index f427b5d..d9a1771 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/controller/dto/WarehouseReceiptDto.java +++ b/src/main/java/com/niuan/erp/module/warehouse/controller/dto/WarehouseReceiptDto.java @@ -1,6 +1,7 @@ package com.niuan.erp.module.warehouse.controller.dto; import java.time.LocalDateTime; +import java.util.List; public record WarehouseReceiptDto( Long id, @@ -20,11 +21,6 @@ public record WarehouseReceiptDto( String formMark, Integer reserve1, String reserve2, - Integer vendorNo, - String vendorName, - Double totalValue, - Integer outStoreNo, - String outStoreName, - Integer groupId, Integer customerId, - String searchCode) {} \ No newline at end of file + String searchCode, + List receiptItems) {} \ No newline at end of file diff --git a/src/main/java/com/niuan/erp/module/warehouse/converter/InventoryCountConverter.java b/src/main/java/com/niuan/erp/module/warehouse/converter/InventoryCountConverter.java index 99c9b68..3de90bb 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/converter/InventoryCountConverter.java +++ b/src/main/java/com/niuan/erp/module/warehouse/converter/InventoryCountConverter.java @@ -22,7 +22,6 @@ public interface InventoryCountConverter { InventoryCountItem toEntity(InventoryCountItemAddDto dto); List toEntityList(List dtoList); - @Mapping(target = "productSpec", ignore = true) InventoryCountItemDto toItemDto(InventoryCountItem entity); List toItemDtoList(List entities); } \ No newline at end of file diff --git a/src/main/java/com/niuan/erp/module/warehouse/service/WarehouseReceiptService.java b/src/main/java/com/niuan/erp/module/warehouse/service/WarehouseReceiptService.java index cd2333b..3077c1e 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/service/WarehouseReceiptService.java +++ b/src/main/java/com/niuan/erp/module/warehouse/service/WarehouseReceiptService.java @@ -25,9 +25,7 @@ public interface WarehouseReceiptService { void approve(long id); - void unapprove(long id); + void reject(long id); List getDetail(long id); - - List importItems(MultipartFile file); } diff --git a/src/main/java/com/niuan/erp/module/warehouse/service/impl/InventoryCountServiceImpl.java b/src/main/java/com/niuan/erp/module/warehouse/service/impl/InventoryCountServiceImpl.java index 1ba026a..18c0617 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/service/impl/InventoryCountServiceImpl.java +++ b/src/main/java/com/niuan/erp/module/warehouse/service/impl/InventoryCountServiceImpl.java @@ -18,9 +18,9 @@ import com.niuan.erp.module.warehouse.controller.dto.InventoryCountItemAddDto; import com.niuan.erp.module.warehouse.controller.dto.InventoryCountItemDto; import com.niuan.erp.module.warehouse.converter.InventoryCountConverter; import com.niuan.erp.module.warehouse.entity.InventoryCountItem; -import com.niuan.erp.module.warehouse.entity.Stock; +import com.niuan.erp.module.warehouse.entity.WarehouseItem; import com.niuan.erp.module.warehouse.mapper.InventoryCountItemMapper; -import com.niuan.erp.module.warehouse.mapper.StockMapper; +import com.niuan.erp.module.warehouse.mapper.WarehouseItemMapper; import com.niuan.erp.module.warehouse.service.InventoryCountService; import lombok.RequiredArgsConstructor; import org.apache.poi.ss.usermodel.*; @@ -45,7 +45,7 @@ public class InventoryCountServiceImpl extends ServiceImpl getInventoryCountPage(BasePageReqParams pageParams, LambdaQueryWrapper wrapper) { @@ -87,20 +87,16 @@ public class InventoryCountServiceImpl extends ServiceImpl stockWrapper = new LambdaQueryWrapper<>(); - stockWrapper.eq(Stock::getStoreNo, dto.storeNo()) - .in(Stock::getPartNumber, partNumbers); - List stockList = stockMapper.selectList(stockWrapper); - Map stockMap = stockList.stream() - .collect(Collectors.toMap(Stock::getPartNumber, s -> s)); + Map> stockMaps = warehouseItemMapper.getWarehouseItemStockListByPartNumbers(partNumbers); + Map stockMap = new HashMap<>(); + for (Map.Entry> entry : stockMaps.entrySet()) { + stockMap.put(entry.getKey(), ((Number) entry.getValue().get("productCount")).intValue()); + } for (InventoryCountItem item : items) { - Stock stock = stockMap.get(item.getPartNumber()); - if (stock == null) { - throw new BusinessException("warehouse.inventory_count.exception.stock_not_found"); - } - item.setOriginalProductCount(stock.getProductCount()); - item.setDiffCount(item.getProductCount() - stock.getProductCount()); + Integer originalCount = stockMap.get(item.getPartNumber()); + item.setOriginalProductCount(originalCount != null ? originalCount : 0); + item.setDiffCount(item.getProductCount() - item.getOriginalProductCount()); } } else { for (InventoryCountItem item : items) { @@ -121,25 +117,6 @@ public class InventoryCountServiceImpl extends ServiceImpl newStocks = new ArrayList<>(); - for (InventoryCountItem item : items) { - Stock stock = new Stock(); - stock.setPartNumber(item.getPartNumber()); - stock.setProductCount(item.getProductCount()); - stock.setStoreNo(dto.storeNo()); - stock.setStoreName(dto.storeName()); - stock.setCreateDate(LocalDateTime.now()); - stock.setCreateUserId(SecurityUtils.getUserId()); - stock.setCreateUserName(SecurityUtils.getUserName()); - stock.setStatus(0); - newStocks.add(stock); - } - for (Stock stock : newStocks) { - stockMapper.insert(stock); - } - } } @Override @@ -214,47 +191,6 @@ public class InventoryCountServiceImpl extends ServiceImpl partNumbers = items.stream() - .map(InventoryCountItem::getPartNumber) - .toList(); - - LambdaQueryWrapper stockWrapper = new LambdaQueryWrapper<>(); - stockWrapper.eq(Stock::getStoreNo, storeNo) - .in(Stock::getPartNumber, partNumbers); - List existingStockList = stockMapper.selectList(stockWrapper); - Map existingStockMap = existingStockList.stream() - .collect(Collectors.toMap(Stock::getPartNumber, s -> s)); - - List newStocks = new ArrayList<>(); - for (InventoryCountItem item : items) { - Stock existingStock = existingStockMap.get(item.getPartNumber()); - if (existingStock == null) { - Stock newStock = new Stock(); - newStock.setPartNumber(item.getPartNumber()); - newStock.setProductCount(item.getProductCount()); - newStock.setStoreNo(storeNo); - newStock.setStoreName(entity.getStoreName()); - newStock.setCreateDate(LocalDateTime.now()); - newStock.setCreateUserId(SecurityUtils.getUserId()); - newStock.setCreateUserName(SecurityUtils.getUserName()); - newStock.setStatus(0); - newStocks.add(newStock); - } else { - existingStock.setProductCount(item.getProductCount()); - existingStock.setUpdateDate(LocalDateTime.now()); - existingStock.setUpdateUserId(SecurityUtils.getUserId()); - existingStock.setUpdateUserName(SecurityUtils.getUserName()); - stockMapper.updateById(existingStock); - } - } - - if (!newStocks.isEmpty()) { - for (Stock newStock : newStocks) { - stockMapper.insert(newStock); - } - } - entity.setFormStatus(FormStatus.APPROVE); entity.setUpdateDate(LocalDateTime.now()); entity.setUpdateUserId(SecurityUtils.getUserId()); @@ -281,31 +217,7 @@ public class InventoryCountServiceImpl extends ServiceImpl itemWrapper = new LambdaQueryWrapper<>(); itemWrapper.eq(InventoryCountItem::getDocumentNo, id); - List items = inventoryCountItemMapper.selectList(itemWrapper); - - Integer storeNo = entity.getStoreNo(); - List partNumbers = items.stream() - .map(InventoryCountItem::getPartNumber) - .toList(); - - LambdaQueryWrapper stockWrapper = new LambdaQueryWrapper<>(); - stockWrapper.eq(Stock::getStoreNo, storeNo) - .in(Stock::getPartNumber, partNumbers); - List existingStockList = stockMapper.selectList(stockWrapper); - Map existingStockMap = existingStockList.stream() - .collect(Collectors.toMap(Stock::getPartNumber, s -> s)); - - for (InventoryCountItem item : items) { - Stock existingStock = existingStockMap.get(item.getPartNumber()); - if (existingStock == null) { - throw new BusinessException("warehouse.inventory_count.exception.stock_not_found_for_unapprove"); - } - existingStock.setProductCount(item.getOriginalProductCount()); - existingStock.setUpdateDate(LocalDateTime.now()); - existingStock.setUpdateUserId(SecurityUtils.getUserId()); - existingStock.setUpdateUserName(SecurityUtils.getUserName()); - stockMapper.updateById(existingStock); - } + inventoryCountItemMapper.selectList(itemWrapper); entity.setFormStatus(FormStatus.NO_APPROVE); entity.setUpdateDate(LocalDateTime.now()); @@ -326,7 +238,47 @@ public class InventoryCountServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); wrapper.eq(InventoryCountItem::getDocumentNo, id); List items = inventoryCountItemMapper.selectList(wrapper); - return inventoryCountConverter.toItemDtoList(items); + + List partNumbers = items.stream() + .map(InventoryCountItem::getPartNumber) + .filter(Objects::nonNull) + .distinct() + .toList(); + + Map partNumberToSpecs = new HashMap<>(); + if (!partNumbers.isEmpty()) { + LambdaQueryWrapper itemWrapper = new LambdaQueryWrapper<>(); + itemWrapper.in(WarehouseItem::getPartNumber, partNumbers); + List warehouseItems = warehouseItemMapper.selectList(itemWrapper); + partNumberToSpecs = warehouseItems.stream() + .collect(Collectors.toMap(WarehouseItem::getPartNumber, WarehouseItem::getProductSpecs, (v1, v2) -> v1)); + } + + List dtoList = inventoryCountConverter.toItemDtoList(items); + Map finalPartNumberToSpecs = partNumberToSpecs; + return dtoList.stream() + .map(dto -> new InventoryCountItemDto( + dto.id(), + dto.status(), + dto.createDate(), + dto.createUserId(), + dto.createUserName(), + dto.updateDate(), + dto.updateUserId(), + dto.updateUserName(), + dto.storeNo(), + dto.storeName(), + dto.partNumber(), + dto.productCount(), + dto.diffCount(), + dto.stockTakingMark(), + dto.reserve1(), + dto.reserve2(), + dto.documentNo(), + dto.originalProductCount(), + finalPartNumberToSpecs.get(dto.partNumber()) + )) + .toList(); } @Override diff --git a/src/main/java/com/niuan/erp/module/warehouse/service/impl/WarehouseReceiptServiceImpl.java b/src/main/java/com/niuan/erp/module/warehouse/service/impl/WarehouseReceiptServiceImpl.java index c29a728..6c440b7 100644 --- a/src/main/java/com/niuan/erp/module/warehouse/service/impl/WarehouseReceiptServiceImpl.java +++ b/src/main/java/com/niuan/erp/module/warehouse/service/impl/WarehouseReceiptServiceImpl.java @@ -20,7 +20,9 @@ import com.niuan.erp.module.warehouse.controller.dto.WarehouseReceiptItemAddDto; import com.niuan.erp.module.warehouse.controller.dto.WarehouseReceiptItemDto; import com.niuan.erp.module.warehouse.converter.WarehouseReceiptConverter; import com.niuan.erp.module.warehouse.entity.Stock; +import com.niuan.erp.module.warehouse.entity.WarehouseItem; import com.niuan.erp.module.warehouse.mapper.StockMapper; +import com.niuan.erp.module.warehouse.mapper.WarehouseItemMapper; import com.niuan.erp.module.warehouse.service.WarehouseReceiptService; import lombok.RequiredArgsConstructor; import org.apache.poi.ss.usermodel.*; @@ -47,9 +49,12 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl getWarehouseReceiptPage(BasePageReqParams pageParams, LambdaQueryWrapper wrapper) { - wrapper.eq(Document::getFormType, DocumentType.WAREHOUSE_RECEIPT); + wrapper.eq(Document::getFormType, DocumentType.WAREHOUSE_RECEIPT) + .orderByDesc(Document::getCreateDate); IPage result = this.baseMapper.selectPage(new Page<>(pageParams.page(), pageParams.pageSize()), wrapper); return result.convert(warehouseReceiptConverter::toDto); } @@ -93,6 +98,24 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl materialWrapper = new LambdaQueryWrapper<>(); + materialWrapper.eq(DocumentMaterial::getDocumentNo, dto.id()); + documentMaterialMapper.delete(materialWrapper); + + // 插入新明细 + if (dto.receiptItems() != null && !dto.receiptItems().isEmpty()) { + List materials = warehouseReceiptConverter.toEntityList(dto.receiptItems()); + materials.forEach(m -> { + m.setDocumentNo(dto.id().intValue()); + m.setCreateUserId(SecurityUtils.getUserId()); + m.setCreateUserName(SecurityUtils.getUserName()); + m.setCreateDate(LocalDateTime.now()); + m.setStatus(0); + }); + documentMaterialMapper.insert(materials); + } } @Override @@ -162,6 +185,7 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl existingStockMap = existingStockList.stream() .collect(Collectors.toMap(Stock::getPartNumber, s -> s)); + String storeName = entity.getStoreName(); List newStocks = new ArrayList<>(); for (DocumentMaterial material : materialList) { Stock existingStock = existingStockMap.get(material.getPartNumber()); @@ -170,6 +194,7 @@ public class WarehouseReceiptServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); wrapper.eq(DocumentMaterial::getDocumentNo, id); List materials = documentMaterialMapper.selectList(wrapper); - return warehouseReceiptConverter.toItemDtoList(materials); - } - @Override - public List importItems(MultipartFile file) { - if (file == null || file.isEmpty()) { - throw new BusinessException("warehouse.warehouse_receipt.exception.file_empty"); + // 获取所有物料编号 + List partNumbers = materials.stream() + .map(DocumentMaterial::getPartNumber) + .filter(Objects::nonNull) + .distinct() + .toList(); + + // 查询物料规格信息 + Map partNumberToSpecs = new HashMap<>(); + if (!partNumbers.isEmpty()) { + LambdaQueryWrapper itemWrapper = new LambdaQueryWrapper<>(); + itemWrapper.in(WarehouseItem::getPartNumber, partNumbers); + List items = warehouseItemMapper.selectList(itemWrapper); + partNumberToSpecs = items.stream() + .collect(Collectors.toMap(WarehouseItem::getPartNumber, WarehouseItem::getProductSpecs, (v1, v2) -> v1)); } - try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) { - Sheet sheet = workbook.getSheetAt(0); - List items = new ArrayList<>(); - - for (int i = 1; i <= sheet.getLastRowNum(); i++) { - Row row = sheet.getRow(i); - if (row == null) continue; - - String partNumber = getCellValueAsString(row.getCell(0)); - String productSpec = getCellValueAsString(row.getCell(1)); - String countStr = getCellValueAsString(row.getCell(2)); - - if (!StringUtils.hasText(partNumber)) continue; - - int productCount = 0; - if (StringUtils.hasText(countStr)) { - try { - productCount = Integer.parseInt(countStr); - } catch (NumberFormatException e) { - productCount = 0; - } - } - - WarehouseReceiptItemDto item = new WarehouseReceiptItemDto( - null, null, null, null, null, null, null, null, - null, partNumber, null, productCount, null, null, null, null, null, null, productSpec - ); - items.add(item); - } - - return items; - } catch (IOException e) { - throw new BusinessException("warehouse.warehouse_receipt.exception.import_failed"); - } - } - - private String getCellValueAsString(Cell cell) { - if (cell == null) { - return ""; - } - return switch (cell.getCellType()) { - case STRING -> cell.getStringCellValue().trim(); - case NUMERIC -> String.valueOf((long) cell.getNumericCellValue()); - case BOOLEAN -> String.valueOf(cell.getBooleanCellValue()); - default -> ""; - }; + // 转换并填充 productSpec + List dtoList = warehouseReceiptConverter.toItemDtoList(materials); + Map finalPartNumberToSpecs = partNumberToSpecs; + return dtoList.stream() + .map(dto -> { + String specs = finalPartNumberToSpecs.get(dto.partNumber()); + return new WarehouseReceiptItemDto( + dto.id(), + dto.status(), + dto.createDate(), + dto.createUserId(), + dto.createUserName(), + dto.updateDate(), + dto.updateUserId(), + dto.updateUserName(), + dto.documentNo(), + dto.partNumber(), + dto.originalCount(), + dto.productCount(), + dto.productMark(), + dto.reserve1(), + dto.reserve2(), + dto.storeNo(), + dto.demandCount(), + dto.partId(), + specs + ); + }) + .toList(); } } \ No newline at end of file diff --git a/src/main/resources/i18n/messages.properties b/src/main/resources/i18n/messages.properties index d02d640..49f42ed 100644 --- a/src/main/resources/i18n/messages.properties +++ b/src/main/resources/i18n/messages.properties @@ -31,6 +31,28 @@ warehouse.stock_transfer_order.validate.product_count.min=调拨数量不能小 warehouse.stock_transfer_order.validate.part_id.not_null=物料 ID 不能为空 warehouse.stock_transfer_order.validate.order_id.not_null=调拨单 ID 不能为空 +warehouse.inventory_count.validate.form_code.not_null=盘点单编号不能为空 +warehouse.inventory_count.validate.form_name.not_null=盘点单名称不能为空 +warehouse.inventory_count.validate.store_no.not_null=仓库 ID 不能为空 +warehouse.inventory_count.validate.store_name.not_null=仓库名称不能为空 +warehouse.inventory_count.validate.count_items.not_null=盘点明细不能为空 +warehouse.inventory_count.validate.part_number.not_null=物料编号不能为空 +warehouse.inventory_count.validate.product_count.not_null=盘点数量不能为空 +warehouse.inventory_count.validate.product_count.min=盘点数量不能小于 0 +warehouse.inventory_count.exception.init_already_exists=当前仓库已有初始库存单 +warehouse.inventory_count.exception.stock_not_found=物料库存不存在 +warehouse.inventory_count.exception.not_found=盘点单不存在 +warehouse.inventory_count.exception.cannot_update_approved=已审核的盘点单不能修改 +warehouse.inventory_count.exception.cannot_delete_approved=已审核的盘点单不能删除 +warehouse.inventory_count.exception.cannot_delete_approved_batch=选中的盘点单中包含已审核的单据,不能删除 +warehouse.inventory_count.exception.ids_empty=请选择要删除的记录 +warehouse.inventory_count.exception.already_approved=盘点单已经审核 +warehouse.inventory_count.exception.not_approved=盘点单不是已审核状态,不能反审 +warehouse.inventory_count.exception.no_items=盘点单没有明细 +warehouse.inventory_count.exception.file_empty=文件不能为空 +warehouse.inventory_count.exception.import_failed=导入失败 +warehouse.inventory_count.exception.stock_not_found_for_unapprove=反审核时找不到对应库存记录 + # ==========>> 生产管理 @@ -86,7 +108,7 @@ password.notNull=密码不能为空 httpMessage.notNull=参数不能为空 validated.error=参数错误 -#jakarta.validation.constraints.NotNull.message=“{0}”不能为空 -#jakarta.validation.constraints.NotBlank.message=“{0}”不能为空 -#jakarta.validation.constraints.Size.message=“{0}”长度必须在{min}到{max}之间 -#jakarta.validation.constraints.Pattern.message=“{0}”格式不正确 \ No newline at end of file +#jakarta.validation.constraints.NotNull.message="{0}"不能为空 +#jakarta.validation.constraints.NotBlank.message="{0}"不能为空 +#jakarta.validation.constraints.Size.message="{0}"长度必须在{min}到{max}之间 +#jakarta.validation.constraints.Pattern.message="{0}"格式不正确