From 100f5e484fcd148fc763eed40af5ce930f113b65 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 28 一月 2026 11:09:49 +0800
Subject: [PATCH] refactor(home): 修改首页当日入库数量查询逻辑 refactor(quality): 更新质量检验控制器依赖注入和删除逻辑 feat(stock): 添加按日期统计库存总量的数据访问方法
---
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 182 ++++++++++++++-------------------------------
1 files changed, 56 insertions(+), 126 deletions(-)
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index cb5d600..b66def3 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -16,6 +16,7 @@
import com.ruoyi.basic.pojo.SupplierManage;
import com.ruoyi.collaborativeApproval.mapper.NoticeMapper;
import com.ruoyi.collaborativeApproval.pojo.Notice;
+import com.ruoyi.common.enums.ApproveTypeEnum;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.device.mapper.DeviceRepairMapper;
import com.ruoyi.device.pojo.DeviceRepair;
@@ -32,9 +33,11 @@
import com.ruoyi.production.mapper.ProductWorkOrderMapper;
import com.ruoyi.production.pojo.ProductWorkOrder;
import com.ruoyi.project.system.domain.SysDept;
+import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.domain.SysUserDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserDeptMapper;
+import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PaymentRegistration;
@@ -44,8 +47,6 @@
import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
-import com.ruoyi.project.system.domain.SysUser;
-import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.sales.pojo.ReceiptPayment;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
@@ -124,6 +125,7 @@
private SysUserMapper sysUserMapper;
@Autowired
private SysUserDeptMapper sysUserDeptMapper;
+ @Autowired
private StockInventoryMapper stockInventoryMapper;
@Override
@@ -178,38 +180,13 @@
homeBusinessDto.setMonthPurchaseHaveMoney(unReceiptPaymentAmount.setScale(2, RoundingMode.HALF_UP).toString());
}
// 缁熻搴撳瓨
-// List<ProcurementRecordStorage> procurementRecordStorages = procurementRecordStorageMapper.selectList(null);
-// BigDecimal stockAmount = procurementRecordStorages.stream()
-// .map(ProcurementRecordStorage::getInboundNum)
-// .filter(Objects::nonNull)
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
-// // 鑷畾涔夊簱瀛�
-// List<CustomStorage> customStorages = customStorageMapper.selectList(null);
-// BigDecimal customStockAmount = customStorages.stream()
-// .map(CustomStorage::getInboundNum)
-// .filter(Objects::nonNull)
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
-// List<ProcurementRecordOut> procurementRecordOuts = procurementRecordOutMapper.selectList(null);
-// BigDecimal outboundAmount = procurementRecordOuts.stream()
-// .map(ProcurementRecordOut::getInboundNum)
-// .filter(Objects::nonNull)
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
-// BigDecimal stock = stockAmount.add(customStockAmount).subtract(outboundAmount);
BigDecimal stockQuantityTotal = stockInventoryMapper.selectTotal();
homeBusinessDto.setInventoryNum(stockQuantityTotal.setScale(2, RoundingMode.HALF_UP).toString());
// 鑾峰彇褰撳ぉ鍏ュ簱鏁伴噺
- LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>();
- procurementRecordStorageLambdaQueryWrapper.ge(ProcurementRecordStorage::getCreateTime, now) // 澶т簬绛変簬褰撳ぉ
- .lt(ProcurementRecordStorage::getCreateTime, now.plusDays(1)); // 灏忎簬鏄庡ぉ
- List<ProcurementRecordStorage> procurementRecordStorages1 = procurementRecordStorageMapper.selectList(procurementRecordStorageLambdaQueryWrapper);
- BigDecimal stockAmount1 = procurementRecordStorages1.stream()
- .map(ProcurementRecordStorage::getInboundNum)
- .filter(Objects::nonNull)
- .reduce(BigDecimal.ZERO, BigDecimal::add);
-// homeBusinessDto.setInventoryNum(stock.setScale(2, RoundingMode.HALF_UP).toString());
- homeBusinessDto.setTodayInventoryNum(stockAmount1.setScale(2, RoundingMode.HALF_UP).toString());
+ BigDecimal bigDecimal = stockInventoryMapper.selectTotalByDate(LocalDate.now());
+ homeBusinessDto.setTodayInventoryNum(bigDecimal.setScale(2, RoundingMode.HALF_UP).toString());
return homeBusinessDto;
}
@@ -399,6 +376,12 @@
if (CollectionUtils.isEmpty(approveProcesses)) {
approveProcesses = new ArrayList<>();
}
+
+ approveProcesses.forEach(a -> {
+ if (a.getApproveType() != null) {
+ a.setApproveTypeName(ApproveTypeEnum.getNameByCode(a.getApproveType()));
+ }
+ });
// // 鏌ヨ鏈鐢ㄥ姵淇濊褰�
// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//
@@ -416,6 +399,8 @@
// approveProcesses.add(approveProcess);
// }
// }
+
+
return approveProcesses;
}
@@ -695,15 +680,15 @@
LocalDate startDate;
LocalDate endDate;
switch (type) {
- case 0: // 鍛�
+ case 1: // 鍛�
startDate = today.with(DayOfWeek.MONDAY);
endDate = today.with(DayOfWeek.SUNDAY);
break;
- case 1: // 鏈�
+ case 2: // 鏈�
startDate = today.with(TemporalAdjusters.firstDayOfMonth());
endDate = today.with(TemporalAdjusters.lastDayOfMonth());
break;
- case 2: // 瀛e害
+ case 3: // 瀛e害
Month currentMonth = today.getMonth();
Month firstMonthOfQuarter = currentMonth.firstMonthOfQuarter();
Month lastMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
@@ -745,15 +730,15 @@
boolean groupByMonth = false;
switch (type) {
- case 0: // 鍛�
+ case 1: // 鍛�
start = today.with(DayOfWeek.MONDAY);
end = today.with(DayOfWeek.SUNDAY);
break;
- case 1: // 鏈�
+ case 2: // 鏈�
start = today.with(TemporalAdjusters.firstDayOfMonth());
end = today.with(TemporalAdjusters.lastDayOfMonth());
break;
- case 2: // 瀛e害
+ case 3: // 瀛e害
Month firstMonthOfQuarter = today.getMonth().firstMonthOfQuarter();
start = today.withMonth(firstMonthOfQuarter.getValue()).with(TemporalAdjusters.firstDayOfMonth());
end = today.withMonth(firstMonthOfQuarter.plus(2).getValue()).with(TemporalAdjusters.lastDayOfMonth());
@@ -814,109 +799,54 @@
ProductCategoryDistributionDto dto = new ProductCategoryDistributionDto();
List<ProductCategoryDistributionDto.MajorCategoryDto> majorItems = new ArrayList<>();
- // 鎵�鏈夌殑浜у搧澶х被鍜屽皬绫�
- List<Product> allProducts = productMapper.selectList(new LambdaQueryWrapper<Product>());
+ // 鏌ヨ鎵�鏈夌殑浜у搧绫诲埆
+ List<Product> allProducts = productMapper.selectList(new LambdaQueryWrapper<>());
if (CollectionUtils.isEmpty(allProducts)) {
dto.setItems(majorItems);
return dto;
}
- List<Product> majorCategories = allProducts.stream().filter(p -> p.getParentId() == null).collect(Collectors.toList());
- List<Product> minorCategories = allProducts.stream().filter(p -> p.getParentId() != null).collect(Collectors.toList());
+ // 鍒嗙澶х被鍜屽皬绫�
+ List<Product> majorCategories = allProducts.stream()
+ .filter(p -> p.getParentId() == null)
+ .collect(Collectors.toList());
+ List<Product> minorCategories = allProducts.stream()
+ .filter(p -> p.getParentId() != null)
+ .collect(Collectors.toList());
- // 浠� sales_ledger_product 鎷垮埌姣忎釜浜у搧鐨勫瀷鍙峰簱瀛�
- // 闇�鍖呭惈瑙勬牸鍨嬪彿浠ユ敮鎸佷笁绾у垎甯�
- List<Map<String, Object>> quantityMaps = salesLedgerProductMapper.selectMaps(new QueryWrapper<SalesLedgerProduct>()
- .select("product_id", "specification_model", "type", "SUM(quantity) as sum_qty")
- .isNotNull("product_id")
- .groupBy("product_id", "specification_model", "type"));
+ // 鎸夌埗绫籌D瀵瑰皬绫昏繘琛屽垎缁�
+ Map<Long, List<Product>> minorGroupMap = minorCategories.stream()
+ .collect(Collectors.groupingBy(Product::getParentId));
- Map<Long, Map<String, Map<Integer, BigDecimal>>> modelStockGroups = new HashMap<>();
- for (Map<String, Object> map : quantityMaps) {
- Long productId = Long.parseLong(map.get("product_id").toString());
- String model = map.get("specification_model") != null ? map.get("specification_model").toString() : "鏈煡鍨嬪彿";
- Integer type = Integer.parseInt(map.get("type").toString());
- BigDecimal sum = map.get("sum_qty") != null ? new BigDecimal(map.get("sum_qty").toString()) : BigDecimal.ZERO;
+ int totalMinorCount = minorCategories.size();
- modelStockGroups.computeIfAbsent(productId, k -> new HashMap<>())
- .computeIfAbsent(model, k -> new HashMap<>())
- .put(type, sum);
- }
-
- // 搴撳瓨骞舵眹鎬�
- Map<Long, List<MapDto>> productModelsMap = new HashMap<>();
- Map<Long, BigDecimal> productTotalStockMap = new HashMap<>();
-
- for (Long pid : modelStockGroups.keySet()) {
- Map<String, Map<Integer, BigDecimal>> models = modelStockGroups.get(pid);
- BigDecimal productStock = BigDecimal.ZERO;
- List<MapDto> modelDtos = new ArrayList<>();
-
- for (String modelName : models.keySet()) {
- Map<Integer, BigDecimal> types = models.get(modelName);
- BigDecimal procurement = types.getOrDefault(2, BigDecimal.ZERO);
- BigDecimal sales = types.getOrDefault(1, BigDecimal.ZERO);
- BigDecimal stock = procurement.subtract(sales);
- if (stock.compareTo(BigDecimal.ZERO) < 0) stock = BigDecimal.ZERO;
-
- MapDto modelDto = new MapDto();
- modelDto.setName(modelName);
- modelDto.setValue(stock.stripTrailingZeros().toPlainString());
- modelDtos.add(modelDto);
- productStock = productStock.add(stock);
- }
- productModelsMap.put(pid, modelDtos);
- productTotalStockMap.put(pid, productStock);
- }
-
- BigDecimal totalInventory = productTotalStockMap.values().stream().reduce(BigDecimal.ZERO, BigDecimal::add);
-
- // 鍨嬪彿鍗犳瘮
- if (totalInventory.compareTo(BigDecimal.ZERO) > 0) {
- for (List<MapDto> dtos : productModelsMap.values()) {
- for (MapDto m : dtos) {
- BigDecimal val = new BigDecimal(m.getValue());
- m.setRate(val.multiply(new BigDecimal("100"))
- .divide(totalInventory, 2, RoundingMode.HALF_UP).toString());
- }
- }
- }
-
- // 鍒嗗眰鏁版嵁
for (Product major : majorCategories) {
ProductCategoryDistributionDto.MajorCategoryDto majorDto = new ProductCategoryDistributionDto.MajorCategoryDto();
majorDto.setName(major.getProductName());
- List<ProductCategoryDistributionDto.MinorCategoryDto> minorDtos = new ArrayList<>();
- BigDecimal majorStock = BigDecimal.ZERO;
+ List<Product> children = minorGroupMap.getOrDefault(major.getId(), new ArrayList<>());
+ int childrenSize = children.size();
+ // 璁剧疆灏忕被鐨勬�绘暟
+ majorDto.setValue(String.valueOf(childrenSize));
- for (Product minor : minorCategories) {
- if (major.getId().equals(minor.getParentId())) {
- BigDecimal stock = productTotalStockMap.getOrDefault(minor.getId(), BigDecimal.ZERO);
- ProductCategoryDistributionDto.MinorCategoryDto minorDto = new ProductCategoryDistributionDto.MinorCategoryDto();
- minorDto.setName(minor.getProductName());
- minorDto.setValue(stock.stripTrailingZeros().toPlainString());
-
- if (totalInventory.compareTo(BigDecimal.ZERO) > 0) {
- minorDto.setRate(stock.multiply(new BigDecimal("100"))
- .divide(totalInventory, 2, RoundingMode.HALF_UP).toString());
- } else {
- minorDto.setRate("0.00");
- }
-
- minorDto.setChildren(productModelsMap.getOrDefault(minor.getId(), new ArrayList<>()));
- minorDtos.add(minorDto);
- majorStock = majorStock.add(stock);
- }
- }
-
- majorDto.setValue(majorStock.stripTrailingZeros().toPlainString());
-
- if (totalInventory.compareTo(BigDecimal.ZERO) > 0) {
- majorDto.setRate(majorStock.multiply(new BigDecimal("100"))
- .divide(totalInventory, 2, RoundingMode.HALF_UP).toString());
+ // 璁$畻鍗犳瘮
+ if (totalMinorCount > 0) {
+ BigDecimal rate = BigDecimal.valueOf(childrenSize)
+ .multiply(new BigDecimal("100"))
+ .divide(BigDecimal.valueOf(totalMinorCount), 2, RoundingMode.HALF_UP);
+ majorDto.setRate(rate.toString());
} else {
majorDto.setRate("0.00");
+ }
+
+ List<ProductCategoryDistributionDto.MinorCategoryDto> minorDtos = new ArrayList<>();
+ for (Product minor : children) {
+ ProductCategoryDistributionDto.MinorCategoryDto minorDto = new ProductCategoryDistributionDto.MinorCategoryDto();
+ minorDto.setName(minor.getProductName());
+ minorDto.setValue("0");
+ minorDto.setRate("0.00");
+ minorDto.setChildren(new ArrayList<>());
+ minorDtos.add(minorDto);
}
majorDto.setChildren(minorDtos);
majorItems.add(majorDto);
@@ -932,15 +862,15 @@
LocalDate startDate = null;
LocalDate endDate = null;
switch (type) {
- case 0:
+ case 1:
startDate = today.with(DayOfWeek.MONDAY);
endDate = today.with(DayOfWeek.SUNDAY);
break;
- case 1:
+ case 2:
startDate = today.with(TemporalAdjusters.firstDayOfMonth());
endDate = today.with(TemporalAdjusters.lastDayOfMonth());
break;
- case 2:
+ case 3:
Month currentMonth = today.getMonth();
Month firstMonthOfQuarter = currentMonth.firstMonthOfQuarter();
Month lastMonthOfQuarter = Month.of(firstMonthOfQuarter.getValue() + 2);
--
Gitblit v1.9.3