From fddb7b7951238b5c70cee251459f6effb3b42c26 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 30 三月 2026 16:06:13 +0800
Subject: [PATCH] 销售看板统计的新增客户趋势分析
---
src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java | 130 ++++++++++++++++++++++++++++++++++++++++---
1 files changed, 121 insertions(+), 9 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 f09323d..e496507 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() {
@@ -185,28 +192,31 @@
LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ge(PurchaseLedger::getEntryDate, currentMonth.atDay(1).atStartOfDay()) // 澶т簬绛変簬鏈湀绗竴澶�
.lt(PurchaseLedger::getEntryDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // 灏忎簬涓嬫湀绗竴澶�
- // 鎵ц鏌ヨ骞惰绠楁�诲拰
+
List<PurchaseLedger> purchaseLedgers = purchaseLedgerMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(purchaseLedgers)) {
- LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductMapperLambdaQueryWrapperCopy = new LambdaQueryWrapper<SalesLedgerProduct>();
- salesLedgerProductMapperLambdaQueryWrapperCopy.eq(SalesLedgerProduct::getType, 2)
+ LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductMapperLambdaQueryWrapperCopy = new LambdaQueryWrapper<>();
+ salesLedgerProductMapperLambdaQueryWrapperCopy.eq(SalesLedgerProduct::getType, 2) // 閲囪喘绫诲瀷
.in(SalesLedgerProduct::getSalesLedgerId,
purchaseLedgers.stream().map(PurchaseLedger::getId).collect(Collectors.toList()));
+
List<SalesLedgerProduct> salesLedgerProductsCopy = salesLedgerProductMapper
.selectList(salesLedgerProductMapperLambdaQueryWrapperCopy);
- // 鍚堣鍚堝悓閲戦
+
+ // 鍚堣鍚堝悓鎬婚噾棰�
BigDecimal receiveAmount = purchaseLedgers.stream()
.map(PurchaseLedger::getContractAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
- // 鏈紑绁ㄩ噾棰�
+
+ // 寰呬粯娆炬�婚噾棰�
BigDecimal unReceiptPaymentAmount = salesLedgerProductsCopy.stream()
- .map(SalesLedgerProduct::getNoInvoiceAmount)
+ .map(SalesLedgerProduct::getPendingTicketsTotal)
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
+
homeBusinessDto.setMonthPurchaseMoney(receiveAmount.setScale(2, RoundingMode.HALF_UP).toString());
- homeBusinessDto
- .setMonthPurchaseHaveMoney(unReceiptPaymentAmount.setScale(2, RoundingMode.HALF_UP).toString());
+ homeBusinessDto.setMonthPurchaseHaveMoney(unReceiptPaymentAmount.setScale(2, RoundingMode.HALF_UP).toString());
}
// 缁熻搴撳瓨
BigDecimal stockQuantityTotal = stockInventoryMapper.selectTotal();
@@ -2509,4 +2519,106 @@
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);
+ long sum = salesDeliveries.stream().mapToLong(value -> Long.parseLong(value.getPrice().toString())).sum();
+ map.put("price",sum/1000);//鍗曚綅w
+ //鎬诲彂璐у崟
+ map.put("delivery",salesDeliveries.stream().count());
+ //鎬婚攢鍞尯?
+ //绱瀹㈡埛
+ Long count = customerMapper.selectCount(null);
+ map.put("customer",count);
+ return map;
+ }
+
+ @Override
+ public String salesAnalysis(SalesDeliveryDto salesDeliveryDto) {
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ return null;
+ }
+
+ @Override
+ public String salesRanking(SalesDeliveryDto salesDeliveryDto) {
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ return null;
+ }
+
+ @Override
+ public String salesAmount(SalesDeliveryDto salesDeliveryDto) {
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ return null;
+ }
+
+ @Override
+ public String salesDataRanking(SalesDeliveryDto salesDeliveryDto) {
+ List<LocalDate> dates = convertDateList(salesDeliveryDto.getDays());
+ return null;
+ }
+
+ @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());
+ 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())
+ .filter(addressRegionEnum -> addressRegionEnum.getRegionName().equals("SELF_PICKUP"))
+ .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("ALLIN",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