From f5ee8e7afb178179c1d1d078cf42fe33dc7607f9 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期三, 20 五月 2026 16:02:59 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_pro' into dev_New_pro
---
src/main/java/com/ruoyi/sales/service/impl/MetricStatisticsServiceImpl.java | 106 +++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 78 insertions(+), 28 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/MetricStatisticsServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/MetricStatisticsServiceImpl.java
index c70bbe1..22b9b66 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/MetricStatisticsServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/MetricStatisticsServiceImpl.java
@@ -2,7 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.framework.web.domain.R;
import com.ruoyi.sales.dto.SalesTrendDto;
import com.ruoyi.sales.dto.StatisticsTableDto;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
@@ -11,8 +11,8 @@
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShippingInfo;
+import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
@@ -25,20 +25,16 @@
*/
@Service
@Slf4j
+@RequiredArgsConstructor
public class MetricStatisticsServiceImpl {
- @Autowired
- private SalesLedgerMapper salesLedgerMapper;
+ private final SalesLedgerMapper salesLedgerMapper;
+ private final SalesLedgerProductMapper salesLedgerProductMapper;
+ private final ShippingInfoMapper shippingInfoMapper;
- @Autowired
- private SalesLedgerProductMapper salesLedgerProductMapper;
-
- @Autowired
- private ShippingInfoMapper shippingInfoMapper;
-
- public AjaxResult total() {
+ public R<?> total() {
List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(null);
- if(CollectionUtils.isEmpty(salesLedgers)) return AjaxResult.success(salesLedgers);
+ if(CollectionUtils.isEmpty(salesLedgers)) return R.ok(salesLedgers);
Map<String, Object> map = new HashMap<>();
// 閿�鍞
map.put("contractAmountTotal", salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add));
@@ -48,31 +44,85 @@
List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>()
.eq(SalesLedgerProduct::getType, 1));
map.put("shipRate", "0%");
- if(CollectionUtils.isEmpty(salesLedgerProducts)) return AjaxResult.success(map);
+ if(CollectionUtils.isEmpty(salesLedgerProducts)) return R.ok(map);
// 鍙戣揣鏁伴噺
long count = shippingInfoMapper.selectCount(new LambdaQueryWrapper<ShippingInfo>()
.in(ShippingInfo::getSalesLedgerProductId, salesLedgerProducts.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList()))
.eq(ShippingInfo::getStatus,"宸插彂璐�"));
map.put("shipRate", String.format("%.2f", count * 100.0 / salesLedgerProducts.size()) + "%");
- return AjaxResult.success(map);
+ return R.ok(map);
}
- public AjaxResult statisticsTable(StatisticsTableDto statisticsTableDto) {
+ public R<?> statisticsTable(StatisticsTableDto statisticsTableDto) {
Map<String, Object> map = new HashMap<>();
- if (statisticsTableDto.getEntryDateStart() == null || statisticsTableDto.getEntryDateEnd() == null) {
- Calendar calendar = Calendar.getInstance();
- // 缁撴潫鏃堕棿榛樿鏄綋鍓嶆椂闂�
- statisticsTableDto.setEntryDateEnd(new Date());
- // 寮�濮嬫椂闂撮粯璁ゆ槸6涓湀鍓�
- calendar.add(Calendar.MONTH, -6);
- statisticsTableDto.setEntryDateStart(calendar.getTime());
+ Calendar calendar = Calendar.getInstance();
+
+ // 缁撴潫鏃堕棿榛樿鏄綋鍓嶆椂闂�
+ Date endDate = statisticsTableDto.getEntryDateEnd() != null ? statisticsTableDto.getEntryDateEnd() : new Date();
+ statisticsTableDto.setEntryDateEnd(endDate);
+
+ // 寮�濮嬫椂闂撮粯璁ゆ槸12涓湀鍓�
+ Date startDate;
+ if (statisticsTableDto.getEntryDateStart() != null) {
+ startDate = statisticsTableDto.getEntryDateStart();
+ } else {
+ calendar.setTime(endDate);
+ calendar.add(Calendar.MONTH, -11); // 鍑�11涓湀锛屽姞涓婂綋鍓嶆湀鍏�12涓湀
+ calendar.set(Calendar.DAY_OF_MONTH, 1); // 璁句负鏈堝垵
+ startDate = calendar.getTime();
}
+ statisticsTableDto.setEntryDateStart(startDate);
+
+ // 鏌ヨ鏁版嵁搴撹幏鍙栨湁鏁版嵁鐨勬湀浠�
List<SalesTrendDto> salesTrendDtos = salesLedgerMapper.statisticsTable(statisticsTableDto);
- if(CollectionUtils.isEmpty(salesTrendDtos)) return AjaxResult.success(map);
- map.put("dateList", salesTrendDtos.stream().map(SalesTrendDto::getMonth).collect(Collectors.toList()));
- map.put("orderCountList", salesTrendDtos.stream().map(SalesTrendDto::getOrderCount).collect(Collectors.toList()));
- map.put("salesAmountList", salesTrendDtos.stream().map(SalesTrendDto::getSalesAmount).collect(Collectors.toList()));
- map.put("shippingRateList", salesTrendDtos.stream().map(SalesTrendDto::getShipRate).collect(Collectors.toList()));
- return AjaxResult.success(map);
+
+ // 鍒涘缓鏈堜唤鍒版暟鎹殑鏄犲皠
+ Map<String, SalesTrendDto> trendMap = new HashMap<>();
+ if (!CollectionUtils.isEmpty(salesTrendDtos)) {
+ for (SalesTrendDto dto : salesTrendDtos) {
+ trendMap.put(dto.getMonth(), dto);
+ }
+ }
+
+ // 鐢熸垚鏈堜唤鍒楄〃
+ List<String> dateList = new ArrayList<>();
+ List<BigDecimal> orderCountList = new ArrayList<>();
+ List<BigDecimal> salesAmountList = new ArrayList<>();
+ List<BigDecimal> shippingRateList = new ArrayList<>();
+
+ Calendar tempCalendar = Calendar.getInstance();
+ tempCalendar.setTime(startDate);
+ tempCalendar.set(Calendar.DAY_OF_MONTH, 1); // 纭繚浠庢湀鍒濆紑濮�
+
+ Calendar endCalendar = Calendar.getInstance();
+ endCalendar.setTime(endDate);
+ endCalendar.set(Calendar.DAY_OF_MONTH, 1); // 纭繚鍒版湀鏈�
+
+ // 寰幆鐢熸垚鏈堜唤鍒楄〃锛岀洿鍒拌揪鍒扮粨鏉熸湀浠�
+ while (!tempCalendar.after(endCalendar)) {
+ String monthStr = String.format("%04d-%02d", tempCalendar.get(Calendar.YEAR), tempCalendar.get(Calendar.MONTH) + 1);
+ dateList.add(monthStr);
+
+ // 鑾峰彇褰撳墠鏈堜唤鐨勬暟鎹紝濡傛灉娌℃湁鍒欎娇鐢ㄩ粯璁ゅ��
+ SalesTrendDto dto = trendMap.get(monthStr);
+ if (dto != null) {
+ orderCountList.add(new BigDecimal(dto.getOrderCount()));
+ salesAmountList.add(dto.getSalesAmount() != null ? dto.getSalesAmount() : BigDecimal.ZERO);
+ shippingRateList.add(new BigDecimal(String.valueOf(dto.getShipRate())));
+ } else {
+ orderCountList.add(BigDecimal.ZERO);
+ salesAmountList.add(BigDecimal.ZERO);
+ shippingRateList.add(BigDecimal.ZERO);
+ }
+
+ // 涓嬩竴涓湀
+ tempCalendar.add(Calendar.MONTH, 1);
+ }
+
+ map.put("dateList", dateList);
+ map.put("orderCountList", orderCountList);
+ map.put("salesAmountList", salesAmountList);
+ map.put("shippingRateList", shippingRateList);
+ return R.ok(map);
}
}
--
Gitblit v1.9.3