From b572e82dcafea0fd893d908c7bb0e048483a1dd3 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 01 四月 2026 13:38:54 +0800
Subject: [PATCH] fix: 生产计划下发时产品类型ID未保存
---
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 249 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 248 insertions(+), 1 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 2d3e608..b6cc70e 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.mapper.AccountIncomeMapper;
import com.ruoyi.account.pojo.AccountExpense;
@@ -41,6 +42,9 @@
import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
import com.ruoyi.production.pojo.ProductProcess;
import com.ruoyi.production.pojo.ProductWorkOrder;
+import com.ruoyi.productionPlan.enums.AddressRegionEnum;
+import com.ruoyi.productionPlan.mapper.SalesDeliveryMapper;
+import com.ruoyi.productionPlan.pojo.SalesDelivery;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.purchase.mapper.PaymentRegistrationMapper;
@@ -145,12 +149,15 @@
@Autowired
private ProductProcessMapper productProcessMapper;
-
+
@Autowired
private AccountExpenseMapper accountExpenseMapper;
@Autowired
private AccountIncomeMapper accountIncomeMapper;
+
+ @Autowired
+ private SalesDeliveryMapper salesDeliveryMapper;
@Override
public HomeBusinessDto business() {
@@ -2512,4 +2519,244 @@
return productProcessMapper.calculateProductionStatistics(startDateTime, endDateTime, userId, processIds);
}
+
+ @Override
+ public Map<String, Long> total() {
+ Map<String, Long> map = new HashMap<>();
+ List<SalesDelivery> salesDeliveries = salesDeliveryMapper.selectList(null);
+ //鎬婚攢鍞噾棰�
+ BigDecimal sum = salesDeliveries.stream()
+ .map(item -> item.getPrice() != null ? new BigDecimal(item.getPrice().toString()) : BigDecimal.ZERO)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ long finalPrice = sum.divide(new BigDecimal("1000"), 0, RoundingMode.HALF_UP).longValue();
+ map.put("price", finalPrice);//鍗曚綅w
+ //鎬诲彂璐у崟
+ map.put("delivery", (long) salesDeliveries.size());
+ //鎬婚攢鍞柟鏁�
+ BigDecimal volume = salesDeliveries.stream()
+ .map(item -> item.getVolume() != null ? new BigDecimal(item.getVolume().toString()) : BigDecimal.ZERO)
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+ long finalVolume = volume.divide(new BigDecimal("1000"), 0, RoundingMode.HALF_UP).longValue();
+ map.put("volume",finalVolume);
+ //绱瀹㈡埛
+ Long count = customerMapper.selectCount(null);
+ map.put("customer",count);
+ return map;
+ }
+
+ @Override
+ public SalesTotalDto salesAnalysis(SalesDeliveryDto salesDeliveryDto) {
+ SalesTotalDto salesTotalDto = new SalesTotalDto();
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ List<Map<String, Long>> maps = new ArrayList<>();
+ List<SalesDelivery> salesDeliveries = salesDeliveryMapper.selectList(Wrappers.<SalesDelivery>lambdaQuery()
+ .eq(SalesDelivery::getProductName,salesDeliveryDto.getType()));
+ for (LocalDate date : dates) {
+ LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+ if (salesDeliveryDto.getDays().equals("骞�")){
+ lastDay = date.with(TemporalAdjusters.lastDayOfYear());
+ }
+ LocalDate finalLastDay = lastDay;
+ salesDeliveries = salesDeliveries
+ .stream()
+ .filter(delivery -> {
+ LocalDate deliveryDate = delivery.getDeliveryDate();
+ return !deliveryDate.isBefore(firstDay) && !deliveryDate.isAfter(finalLastDay);
+ })
+ .collect(Collectors.toList());
+ Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values())
+ .collect(Collectors.toMap(
+ AddressRegionEnum::getRegionName, // 鍖哄煙鍚嶄綔涓簁ey
+ enumItem -> 0L // 鍒濆鍊煎叏閮ㄤ负0
+ ));
+ if (!CollectionUtils.isEmpty(salesDeliveries)) {
+ // 鎸夊尯鍩熷垎缁勶紝缁熻姣忎釜鍖哄煙鐨勯攢閲忔�诲拰
+ regionCountMap = salesDeliveries.stream()
+ .filter(delivery -> delivery.getDeliveryPlace() != null)
+ .collect(Collectors.groupingBy(
+ delivery -> {
+ AddressRegionEnum regionEnum = AddressRegionEnum.matchRegion(delivery.getDeliveryPlace());
+ return regionEnum != null ? regionEnum.getRegionName() : null;
+ },
+ Collectors.summingLong(delivery -> delivery.getVolume() != null ? delivery.getVolume().longValue() : 0L)
+ ));
+ }
+ regionCountMap.put("鍏ㄩ儴", salesDeliveries.stream()
+ .mapToLong(item -> item.getVolume() != null ? item.getVolume().longValue() : 0L)
+ .sum());
+ maps.add(regionCountMap);
+ }
+ salesTotalDto.setDates(dates);
+ salesTotalDto.setCustomerTrends(maps);
+ return salesTotalDto;
+ }
+
+ @Override
+ public List<SalesTotalDetailDto> salesRanking(SalesDeliveryDto salesDeliveryDto) {
+ List<SalesTotalDetailDto> salesTotalDetailDtos = new ArrayList<>();
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ List<SalesDelivery> salesDeliveries = salesDeliveryMapper.selectList(Wrappers.<SalesDelivery>lambdaQuery()
+ .eq(SalesDelivery::getProductName,salesDeliveryDto.getType()));
+ for (LocalDate date : dates) {
+ LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+ if (salesDeliveryDto.getDays().equals("骞�")){
+ lastDay = date.with(TemporalAdjusters.lastDayOfYear());
+ }
+ LocalDate finalLastDay = lastDay;
+ salesDeliveries = salesDeliveries
+ .stream()
+ .filter(delivery -> {
+ LocalDate deliveryDate = delivery.getDeliveryDate();
+ return !deliveryDate.isBefore(firstDay) && !deliveryDate.isAfter(finalLastDay);
+ })
+ .collect(Collectors.toList());
+ Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values())
+ .collect(Collectors.toMap(
+ AddressRegionEnum::getRegionName, // 鍖哄煙鍚嶄綔涓簁ey
+ enumItem -> 0L // 鍒濆鍊煎叏閮ㄤ负0
+ ));
+ if (!CollectionUtils.isEmpty(salesDeliveries)) {
+ // 鎸夊尯鍩熷垎缁勶紝缁熻姣忎釜鍖哄煙鐨勯攢閲忔�诲拰
+ regionCountMap = salesDeliveries.stream()
+ .filter(delivery -> delivery.getDeliveryPlace() != null)
+ .collect(Collectors.groupingBy(
+ delivery -> {
+ AddressRegionEnum regionEnum = AddressRegionEnum.matchRegion(delivery.getDeliveryPlace());
+ return regionEnum != null ? regionEnum.getRegionName() : null;
+ },
+ Collectors.summingLong(delivery -> delivery.getVolume() != null ? delivery.getVolume().longValue() : 0L)
+ ));
+ }
+ regionCountMap.put("鍏ㄩ儴", salesDeliveries.stream()
+ .mapToLong(item -> item.getVolume() != null ? item.getVolume().longValue() : 0L)
+ .sum());
+ SalesTotalDetailDto salesTotalDetailDto = new SalesTotalDetailDto();
+ salesTotalDetailDto.setDate(date);
+ salesTotalDetailDto.setType(salesDeliveryDto.getType());
+ salesTotalDetailDtos.add(salesTotalDetailDto);
+ }
+ return salesTotalDetailDtos;
+ }
+
+ @Override
+ public SalesTotalDto salesAmount(SalesDeliveryDto salesDeliveryDto) {
+ SalesTotalDto salesTotalDto = new SalesTotalDto();
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ List<Map<String, Long>> maps = new ArrayList<>();
+ List<SalesDelivery> salesDeliveries = salesDeliveryMapper.selectList(Wrappers.<SalesDelivery>lambdaQuery()
+ .eq(SalesDelivery::getProductName,salesDeliveryDto.getType()));
+ for (LocalDate date : dates) {
+ LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+ if (salesDeliveryDto.getDays().equals("骞�")){
+ lastDay = date.with(TemporalAdjusters.lastDayOfYear());
+ }
+ LocalDate finalLastDay = lastDay;
+ salesDeliveries = salesDeliveries
+ .stream()
+ .filter(delivery -> {
+ LocalDate deliveryDate = delivery.getDeliveryDate();
+ return !deliveryDate.isBefore(firstDay) && !deliveryDate.isAfter(finalLastDay);
+ })
+ .collect(Collectors.toList());
+ Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values())
+ .collect(Collectors.toMap(
+ AddressRegionEnum::getRegionName, // 鍖哄煙鍚嶄綔涓簁ey
+ enumItem -> 0L // 鍒濆鍊煎叏閮ㄤ负0
+ ));
+ if (!CollectionUtils.isEmpty(salesDeliveries)) {
+ // 鎸夊尯鍩熷垎缁勶紝缁熻姣忎釜鍖哄煙鐨勯攢閲忔�诲拰
+ regionCountMap = salesDeliveries.stream()
+ .filter(delivery -> delivery.getDeliveryPlace() != null)
+ .collect(Collectors.groupingBy(
+ delivery -> {
+ AddressRegionEnum regionEnum = AddressRegionEnum.matchRegion(delivery.getDeliveryPlace());
+ return regionEnum != null ? regionEnum.getRegionName() : null;
+ },
+ Collectors.summingLong(delivery -> delivery.getPrice() != null ? delivery.getPrice().longValue() : 0L)
+ ));
+ }
+ regionCountMap.put("鍏ㄩ儴", salesDeliveries.stream()
+ .mapToLong(item -> item.getPrice() != null ? item.getPrice().longValue() : 0L)
+ .sum());
+ maps.add(regionCountMap);
+ }
+ salesTotalDto.setDates(dates);
+ salesTotalDto.setCustomerTrends(maps);
+ return salesTotalDto;
+ }
+
+ @Override
+ public List<SalesTotalDetailDto> salesDataRanking(SalesDeliveryDto salesDeliveryDto) {
+ List<SalesTotalDetailDto> salesTotalDetailDtos = new ArrayList<>();
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+
+ return salesTotalDetailDtos;
+ }
+
+ @Override
+ public SalesTotalDto customerTrends(SalesDeliveryDto salesDeliveryDto) {
+ SalesTotalDto salesTotalDto = new SalesTotalDto();
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ List<Map<String, Long>> maps = new ArrayList<>();
+ for (LocalDate date : dates) {
+ LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth());
+ LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth());
+ if (salesDeliveryDto.getDays().equals("骞�")){
+ lastDay = date.with(TemporalAdjusters.lastDayOfYear());
+ }
+ Date startDate = Date.from(firstDay.atStartOfDay(ZoneId.systemDefault()).toInstant());
+ Date endDate = Date.from(lastDay.atTime(23, 59, 59).atZone(ZoneId.systemDefault()).toInstant());
+ List<Customer> customers = customerMapper.selectList(Wrappers.<Customer>lambdaQuery()
+ .between(Customer::getMaintenanceTime, startDate, endDate));
+ Map<String, Long> regionCountMap = Arrays.stream(AddressRegionEnum.values())
+ .collect(Collectors.toMap(
+ AddressRegionEnum::getRegionName, // 鍖哄煙鍚嶄綔涓簁ey
+ enumItem -> 0L // 鍒濆鍊煎叏閮ㄤ负0
+ ));
+ if (!CollectionUtils.isEmpty(customers)) {
+ regionCountMap = customers.stream()
+ // 璋冪敤鏂规硶灏嗗師濮嬪湴鍧�杞崲涓虹洰鏍囧尯鍩�
+ .map(customer -> AddressRegionEnum.matchRegion(customer.getCompanyAddress()).getRegionName())
+ // 杩囨护鎺夎浆鎹㈠け璐�/绌虹殑鍖哄煙锛堝彲閫夛紝鏍规嵁涓氬姟闇�姹傦級
+ .filter(region -> region != null && !region.isEmpty())
+ // 鎸夊尯鍩熷垎缁勶紝缁熻姣忎釜鍖哄煙鐨勬暟閲�
+ .collect(Collectors.groupingBy(
+ region -> region, // 鍒嗙粍渚濇嵁锛氳浆鎹㈠悗鐨勫尯鍩�
+ Collectors.counting() // 璁℃暟
+ ));
+ }
+ regionCountMap.put("鍏ㄩ儴",customers.stream().count());
+ maps.add(regionCountMap);
+ }
+ salesTotalDto.setDates(dates);
+ salesTotalDto.setCustomerTrends(maps);
+ return salesTotalDto;
+ }
+
+ /**
+ * 鏍规嵁鍓嶇浼犲弬 骞�/鏈� 杞崲涓哄搴擫ocalDate鍒楄〃
+ * @param days 鍓嶇鍙傛暟锛�"骞�" / "鏈�"
+ * @return List<LocalDate>
+ */
+ public static List<LocalDate> convertDateList(String days) {
+ List<LocalDate> resultList = new ArrayList<>();
+ LocalDate now = LocalDate.now();
+ int currentYear = now.getYear();
+
+ if ("骞�".equals(days)) {
+ // 闇�姹傦細杩�5骞� 鈫� 姣忓勾鐨� 1鏈�1鏃�
+ for (int i = 0; i < 5; i++) {
+ resultList.add(LocalDate.of(currentYear - i, 1, 1));
+ }
+ } else if ("鏈�".equals(days)) {
+ // 闇�姹傦細褰撳勾12涓湀 鈫� 姣忔湀1鏃�
+ for (int month = 1; month <= 12; month++) {
+ resultList.add(LocalDate.of(currentYear, month, 1));
+ }
+ }
+ return resultList;
+ }
}
--
Gitblit v1.9.3