From cc287798f6cd25203ff9017cb17cd3be955a09ce Mon Sep 17 00:00:00 2001
From: yaowanxin <3588231647@qq.com>
Date: 星期二, 13 一月 2026 10:17:01 +0800
Subject: [PATCH] 库存管理统计
---
src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java | 224 ++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 187 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java b/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
index ff534de..fecbc59 100644
--- a/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/procurementrecord/service/impl/ProcurementRecordServiceImpl.java
@@ -4,6 +4,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.utils.OrderUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.security.LoginUser;
@@ -110,6 +111,8 @@
procurementRecordStorageById.setWarnNum(procurementDto.getWarnNum());
procurementRecordStorageById.setUpdateUser(SecurityUtils.getLoginUser().getUserId());
procurementRecordStorageById.setUpdateTime(LocalDateTime.now());
+ procurementRecordStorageById.setUnitPrice(procurementDto.getUnitPrice());
+ procurementRecordStorageById.setTotalPrice(procurementDto.getTotalPrice());
return procurementRecordMapper.updateById(procurementRecordStorageById);
}
@@ -193,15 +196,28 @@
if(salesLedgerProduct == null){
throw new RuntimeException("閿�鍞彴璐︿骇鍝佷笉瀛樺湪");
}
+ // 鏍规嵁澶х被锛岃鏍兼煡璇㈡墍鏈変骇鍝乮d
+ LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ salesLedgerProductLambdaQueryWrapper.eq(SalesLedgerProduct::getProductCategory, salesLedgerProduct.getProductCategory())
+ .eq(SalesLedgerProduct::getSpecificationModel, salesLedgerProduct.getSpecificationModel())
+ .eq(SalesLedgerProduct::getType, 1);
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(salesLedgerProductLambdaQueryWrapper);
+ if(CollectionUtils.isEmpty(salesLedgerProducts)){
+ throw new RuntimeException("娌℃湁鎵惧埌瀵瑰簲鐨勪骇鍝�");
+ }
salesLedgerProduct.setMinStock(procurementDto.getMinStock());
salesLedgerProductMapper.updateById(salesLedgerProduct);
- ProcurementRecordStorage procurementRecordStorageById = getProcurementRecordById(procurementDto.getId());
- procurementRecordStorageById.setCreateBy(sysUser.getNickName());
- procurementRecordStorageById.setCreateUser(sysUser.getUserId());
- procurementRecordStorageById.setUpdateTime(LocalDateTime.parse(entryDateStr,df));
- procurementRecordStorageById.setUpdateUser(loginUser.getUserId());
- procurementRecordStorageById.setCreateTime(LocalDateTime.parse(createTimeStr,df));
- procurementRecordMapper.updateById(procurementRecordStorageById);
+ LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ procurementRecordStorageLambdaQueryWrapper.in(ProcurementRecordStorage::getSalesLedgerProductId, salesLedgerProducts.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList()));
+ ProcurementRecordStorage procurementRecordStorage = ProcurementRecordStorage.builder().build();
+ procurementRecordStorage.setUnitPrice(procurementDto.getUnitPrice());
+ procurementRecordStorage.setTotalPrice(procurementDto.getTotalPrice());
+ procurementRecordStorage.setCreateBy(sysUser.getNickName());
+ procurementRecordStorage.setCreateUser(sysUser.getUserId());
+ procurementRecordStorage.setUpdateTime(LocalDateTime.parse(entryDateStr,df));
+ procurementRecordStorage.setUpdateUser(loginUser.getUserId());
+ procurementRecordStorage.setCreateTime(LocalDateTime.parse(createTimeStr,df));
+ procurementRecordMapper.update(procurementRecordStorage,procurementRecordStorageLambdaQueryWrapper);
return 0;
}
@@ -400,6 +416,68 @@
}
@Override
+ public InventoryInformationDto getReportList() {
+ InventoryInformationDto inventoryInformationDto = new InventoryInformationDto();
+ IPage<ProcurementPageDto> procurementPageDtoIPage = this.listPage(new Page<>(1, -1), new ProcurementPageDto());
+ if(CollectionUtils.isEmpty(procurementPageDtoIPage.getRecords())){
+ return inventoryInformationDto;
+ }
+ // 璁$畻鎬诲簱瀛樻暟閲�
+ inventoryInformationDto.setTotalInventoryCount(procurementPageDtoIPage.getRecords().stream()
+ .map(ProcurementPageDto::getInboundNum0)
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
+ .intValue());
+ // 璁$畻鎬诲簱瀛橀噾棰�-ProcurementPageDto閲屾瘡涓璞$殑inboundNum0鍊煎拰taxInclusiveUnitPrice鐨勪箻绉紝涔嬪悗鐩稿姞寰楀埌鎬诲簱瀛橀噾棰�
+ BigDecimal totalInventoryValue = procurementPageDtoIPage.getRecords().stream()
+ // 杩囨护绌哄璞★紝閬垮厤NPE
+ .filter(Objects::nonNull)
+ // 澶勭悊姣忎釜瀵硅薄鐨勭┖鍊硷細null杞负0
+ .map(dto -> {
+ // 鍏ュ簱鏁伴噺锛歯ull 鈫� 0
+ BigDecimal inboundNum0 = Optional.ofNullable(dto.getInboundNum0()).orElse(BigDecimal.ZERO);
+ // 鍚◣鍗曚环锛歯ull 鈫� 0
+ BigDecimal taxInclusiveUnitPrice = Optional.ofNullable(dto.getTaxInclusiveUnitPrice()).orElse(BigDecimal.ZERO);
+ // 璁$畻鍗曚釜瀵硅薄鐨勫簱瀛橀噾棰濓細鏁伴噺 脳 鍚◣鍗曚环
+ return inboundNum0.multiply(taxInclusiveUnitPrice);
+ })
+ // 鎵�鏈夊崟涓噾棰濇眰鍜岋紝鍒濆鍊间负0
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ // 璁剧疆鎬诲簱瀛橀噾棰�
+ inventoryInformationDto.setTotalInventoryValue(totalInventoryValue);
+ // 璁$畻搴撳瓨鍙樺姩鏁伴噺-ProcurementPageDto閲屾瘡涓璞$殑inboundNum鍊煎拰inboundNum0鍊肩殑宸�硷紝涔嬪悗鐩稿姞寰楀埌搴撳瓨鍙樺姩鏁伴噺
+ inventoryInformationDto.setInventoryChangeCount(procurementPageDtoIPage.getRecords().stream()
+ // 杩囨护绌哄璞★紝閬垮厤NPE
+ .filter(Objects::nonNull)
+ // 澶勭悊姣忎釜瀵硅薄鐨勭┖鍊硷細null杞负0
+ .map(dto -> {
+ // 鍏ュ簱鏁伴噺锛歯ull 鈫� 0
+ BigDecimal inboundNum = Optional.ofNullable(dto.getInboundNum()).orElse(BigDecimal.ZERO);
+ // 寰呭嚭搴撴暟閲忥細null 鈫� 0
+ BigDecimal inboundNum0 = Optional.ofNullable(dto.getInboundNum0()).orElse(BigDecimal.ZERO);
+ // 璁$畻鍗曚釜瀵硅薄鐨勫簱瀛樺彉鍔ㄦ暟閲忥細鏁伴噺 - 寰呭嚭搴撴暟閲�
+ return inboundNum.subtract(inboundNum0);
+ })
+ // 鎵�鏈夊崟涓彉鍔ㄦ暟閲忔眰鍜岋紝鍒濆鍊间负0
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
+ .intValue());
+ // 璁$畻搴撳瓨鍙樺姩閲戦ProcurementPageDto閲屾瘡涓璞$殑taxInclusiveTotalPrice鍊肩殑鍜�
+ BigDecimal inventoryChangeValue = procurementPageDtoIPage.getRecords().stream()
+ // 杩囨护绌哄璞★紝閬垮厤NPE
+ .filter(Objects::nonNull)
+ // 澶勭悊姣忎釜瀵硅薄鐨勭┖鍊硷細null杞负0
+ .map(dto -> {
+ // 鍚◣鎬讳环锛歯ull 鈫� 0
+ BigDecimal taxInclusiveTotalPrice = Optional.ofNullable(dto.getTaxInclusiveTotalPrice()).orElse(BigDecimal.ZERO);
+ // 璁$畻鍗曚釜瀵硅薄鐨勫叆搴撳簱瀛橀噾棰濓細鍚◣鎬讳环
+ return taxInclusiveTotalPrice;
+ })
+ // 鎵�鏈夊崟涓彉鍔ㄩ噾棰濇眰鍜岋紝鍒濆鍊间负0
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ // 璁剧疆搴撳瓨鍙樺姩閲戦
+ inventoryInformationDto.setInventoryChangeValue(inventoryChangeValue.subtract(totalInventoryValue));
+ return inventoryInformationDto;
+ }
+ @Override
public IPage<ProcurementPageDto> listPageByProduction(Page page, ProcurementPageDto procurementDto) {
IPage<ProcurementPageDto> procurementPageDtoIPage = procurementRecordMapper.listPageByProduction(page, procurementDto);
List<ProcurementPageDto> procurementPageDtos = procurementPageDtoIPage.getRecords();
@@ -452,6 +530,7 @@
Long aLong = customStorageMapper.selectCount(null);
item.setInboundBatches(aLong.equals(0L) ? "绗�1鎵规(鑷畾涔夊叆搴�)" : "绗�"+ (aLong + 1) + "鎵规(鑷畾涔夊叆搴�)" );
item.setCreateBy(loginUser.getNickName());
+ item.setCode(OrderUtils.countTodayByCreateTime(customStorageMapper, ""));
customStorageMapper.insert(item);
});
return AjaxResult.success("鑷畾涔夊叆搴撴垚鍔�");
@@ -514,7 +593,7 @@
@Override
public IPage<ProcurementPageDtoCopy> listPageCopyByProduction(Page page, ProcurementPageDto procurementDto) {
- IPage<ProcurementPageDtoCopy> procurementPageDtoCopyIPage = procurementRecordMapper.listPageCopyByProduction(page, procurementDto);
+ IPage<ProcurementPageDtoCopy> procurementPageDtoCopyIPage = procurementRecordMapper.listPagePRS(page, procurementDto);
List<ProcurementPageDtoCopy> procurementPageDtoCopyList = procurementPageDtoCopyIPage.getRecords();
// 璁$畻寰呭叆搴撴暟閲�
// 鏌ヨ閲囪喘璁板綍宸插叆搴撴暟閲�
@@ -522,38 +601,80 @@
if(CollectionUtils.isEmpty( collect)){
return procurementPageDtoCopyIPage;
}
- LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
- procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
- procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, 2);
- List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
- if(CollectionUtils.isEmpty( procurementRecords)){
- return procurementPageDtoCopyIPage;
- }
+// LambdaQueryWrapper<ProcurementRecordOut> procurementRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+// procurementRecordLambdaQueryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
+// procurementRecordLambdaQueryWrapper.eq(ProcurementRecordOut::getType, 2);
+// List<ProcurementRecordOut> procurementRecords = procurementRecordOutMapper.selectList(procurementRecordLambdaQueryWrapper);
+// if(CollectionUtils.isEmpty(procurementRecords)){
+// return procurementPageDtoCopyIPage;
+// }
+// for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) {
+// // 鏍规嵁閲囪喘鍙拌处ID绛涢�夊搴旂殑鍑哄簱璁板綍
+// List<ProcurementRecordOut> collect1 = procurementRecords.stream()
+// .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId()))
+// .collect(Collectors.toList());
+//
+// // 濡傛灉娌℃湁鐩稿叧鐨勫嚭搴撹褰曪紝璺宠繃璇ユ潯鏁版嵁
+// if(CollectionUtils.isEmpty(collect1)){
+// dto.setInboundNum0(dto.getInboundNum());
+// dto.setTotalInboundNum(BigDecimal.ZERO);
+// continue;
+// }
+//
+// // 璁$畻宸插嚭搴撴暟閲忔�诲拰锛屽苟璁剧疆寰呭嚭搴撴暟閲�
+// BigDecimal totalInboundNum = collect1.stream()
+// .map(ProcurementRecordOut::getInboundNum)
+// .reduce(BigDecimal.ZERO, BigDecimal::add);
+// // 鍑哄簱鏁伴噺 = 鎬绘暟閲� - 寰呭嚭搴撴暟閲�
+// dto.setTotalInboundNum(totalInboundNum);
+// // 寰呭嚭搴撴暟閲� = 鎬绘暟閲� - 宸插嚭搴撴暟閲�
+// dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum));
+// // 搴撳瓨浠峰��
+// if(dto.getUnitPrice() != null){
+// dto.setTotalPrice(dto.getTotalInboundNum().multiply(dto.getUnitPrice()));
+// }
+// }
+ // 1. 鏌ヨ閲囪喘璁板綍宸插叆搴撶殑鍑哄簱璁板綍锛堟寜storageId鍒嗙粍锛�
+ LambdaQueryWrapper<ProcurementRecordOut> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.in(ProcurementRecordOut::getProcurementRecordStorageId, collect);
+ List<ProcurementRecordOut> recordOutList = procurementRecordOutMapper.selectList(queryWrapper);
+
+ // 2. 鎸塖alesLedgerProductId鍒嗙粍锛岀粺璁℃瘡涓猧d瀵瑰簲鐨勫凡鍑哄簱鏁伴噺鎬诲拰-宸插嚭搴撴暟閲�
+ Map<Integer, BigDecimal> storageIdToTotalOutNumMap = recordOutList.stream()
+ .collect(Collectors.groupingBy(
+ ProcurementRecordOut::getSalesLedgerProductId,
+ Collectors.reducing(
+ BigDecimal.ZERO,
+ ProcurementRecordOut::getInboundNum,
+ (a, b) -> a.add(b == null ? BigDecimal.ZERO : b)
+ )
+ ));
+ // 2. procurementPageDtoCopyList鎸塖alesLedgerProductId鍒嗙粍锛岀粺璁℃瘡涓猧d瀵瑰簲鐨勫凡鍑哄簱鏁伴噺鎬诲拰-鍏ュ簱搴撴暟閲�
+ Map<Long, BigDecimal> storageIdToTotalintNumMap = procurementPageDtoCopyList.stream()
+ .collect(Collectors.groupingBy(
+ ProcurementPageDtoCopy::getSalesLedgerProductId,
+ Collectors.reducing(
+ BigDecimal.ZERO,
+ ProcurementPageDtoCopy::getInboundNum,
+ (a, b) -> a.add(b == null ? BigDecimal.ZERO : b)
+ )
+ ));
+ // 3. 寰幆缁檇to璧嬪��
for (ProcurementPageDtoCopy dto : procurementPageDtoCopyList) {
- // 鏍规嵁閲囪喘鍙拌处ID绛涢�夊搴旂殑鍑哄簱璁板綍
- List<ProcurementRecordOut> collect1 = procurementRecords.stream()
- .filter(ProcurementRecordOut -> ProcurementRecordOut.getProcurementRecordStorageId().equals(dto.getId()))
- .collect(Collectors.toList());
+ Integer storageId = dto.getId();
+ Integer salesLedgerProductId = Integer.valueOf(Math.toIntExact(dto.getSalesLedgerProductId()));
+ // 鑾峰彇褰撳墠salesLedgerProductId瀵瑰簲鐨勫凡鍑哄簱鎬绘暟锛堥粯璁�0锛�
+ BigDecimal totalInboundNum = storageIdToTotalOutNumMap.getOrDefault(salesLedgerProductId, BigDecimal.ZERO);
- // 濡傛灉娌℃湁鐩稿叧鐨勫嚭搴撹褰曪紝璺宠繃璇ユ潯鏁版嵁
- if(CollectionUtils.isEmpty(collect1)){
- dto.setInboundNum0(dto.getInboundNum());
- dto.setTotalInboundNum(BigDecimal.ZERO);
- continue;
- }
-
- // 璁$畻宸插嚭搴撴暟閲忔�诲拰锛屽苟璁剧疆寰呭嚭搴撴暟閲�
- BigDecimal totalInboundNum = collect1.stream()
- .map(ProcurementRecordOut::getInboundNum)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
- // 鍑哄簱鏁伴噺 = 鎬绘暟閲� - 寰呭嚭搴撴暟閲�
+ // 寰呭嚭搴撴暟閲� = 鎬绘暟閲� - 宸插嚭搴撴暟閲忥紙鎬绘暟閲忕┖鍊煎垯榛樿0锛�
+// BigDecimal totalNum = dto.getInboundNum() == null ? BigDecimal.ZERO : dto.getInboundNum();
+ BigDecimal totalNum = storageIdToTotalintNumMap.getOrDefault(salesLedgerProductId, BigDecimal.ZERO);
+ dto.setInboundNum0(totalNum.subtract(totalInboundNum));
+ // 宸插嚭搴撴暟閲�
dto.setTotalInboundNum(totalInboundNum);
- // 寰呭嚭搴撴暟閲� = 鎬绘暟閲� - 宸插嚭搴撴暟閲�
- dto.setInboundNum0(dto.getInboundNum().subtract(totalInboundNum));
- // 搴撳瓨浠峰��
- if(dto.getUnitPrice() != null){
- dto.setTotalPrice(dto.getTotalInboundNum().multiply(dto.getUnitPrice()));
- }
+ // 搴撳瓨浠峰�� = 宸插嚭搴撴暟閲� * 鍗曚环锛堝崟浠风┖鍊煎垯榛樿0锛�
+ BigDecimal unitPrice = dto.getUnitPrice() == null ? BigDecimal.ZERO : dto.getUnitPrice();
+ dto.setTotalPrice(totalInboundNum.multiply(unitPrice));
}
return procurementPageDtoCopyIPage;
}
@@ -632,6 +753,35 @@
}
@Override
+ public int updateManagementByCustom(ProcurementManagementUpdateDto procurementDto) {
+ CustomStorage customStorage = customStorageMapper.selectById(procurementDto.getId());
+ if(customStorage == null){
+ throw new RuntimeException("鏉愭枡搴撳瓨涓嶅瓨鍦�");
+ }
+ LambdaQueryWrapper<CustomStorage> customStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ customStorageLambdaQueryWrapper.eq(CustomStorage::getProductCategory, customStorage.getProductCategory())
+ .eq(CustomStorage::getSpecificationModel, customStorage.getSpecificationModel());
+ CustomStorage one = new CustomStorage();
+ one.setTaxInclusiveUnitPrice(procurementDto.getTaxInclusiveUnitPrice());
+ one.setTaxInclusiveTotalPrice(procurementDto.getTaxInclusiveTotalPrice());
+ return customStorageMapper.update(one,customStorageLambdaQueryWrapper);
+ }
+
+ @Override
+ public BigDecimal getProcurementAmount(Long salesProductId) {
+ LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ procurementRecordStorageLambdaQueryWrapper.eq(ProcurementRecordStorage::getSalesLedgerProductId, salesProductId)
+ .eq(ProcurementRecordStorage::getType, 2);
+ List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordMapper.selectList(procurementRecordStorageLambdaQueryWrapper);
+ if(CollectionUtils.isEmpty( procurementRecordStorages)){
+ return BigDecimal.ZERO;
+ }
+ return procurementRecordStorages.stream()
+ .map(ProcurementRecordStorage::getInboundNum)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ }
+
+ @Override
public int add(ProcurementAddDto procurementDto) {
LoginUser loginUser = SecurityUtils.getLoginUser();
// 鎵归噺鏂板
--
Gitblit v1.9.3