|
@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fuint.common.Constants;
|
|
|
import com.fuint.common.dto.*;
|
|
|
+import com.fuint.common.dto.ext.*;
|
|
|
import com.fuint.common.enums.*;
|
|
|
import com.fuint.common.param.OrderListParam;
|
|
|
import com.fuint.common.param.SettlementParam;
|
|
@@ -15,6 +16,7 @@ import com.fuint.framework.annoation.OperationServiceLog;
|
|
|
import com.fuint.framework.exception.BusinessCheckException;
|
|
|
import com.fuint.framework.pagination.PaginationResponse;
|
|
|
import com.fuint.framework.web.ResponseObject;
|
|
|
+import com.fuint.repository.bean.RevenueResult;
|
|
|
import com.fuint.repository.mapper.*;
|
|
|
import com.fuint.repository.model.*;
|
|
|
import com.fuint.utils.PropertiesUtil;
|
|
@@ -35,8 +37,10 @@ import weixin.popular.util.JsonUtil;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.time.LocalDate;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.IntStream;
|
|
|
|
|
|
/**
|
|
|
* 订单接口实现类
|
|
@@ -2321,4 +2325,57 @@ public class OrderServiceImpl extends ServiceImpl<MtOrderMapper, MtOrder> implem
|
|
|
public List<MtOrder> getTobeCommissionOrderList(String dateTime) {
|
|
|
return mtOrderMapper.getTobeCommissionOrderList(dateTime);
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public EchartsBarResponse getYearlyRevenue(Integer startYear, Integer endYear) {
|
|
|
+ // 1. 查询数据库获取原始数据
|
|
|
+ List<RevenueResult> dbData = mtOrderMapper.selectYearlyRevenue(startYear, endYear);
|
|
|
+
|
|
|
+ // 2. 提取所有年份(确保连续)
|
|
|
+ List<String> years = IntStream.rangeClosed(startYear, endYear)
|
|
|
+ .mapToObj(String::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 3. 按店铺分组并填充缺失年份数据
|
|
|
+ Map<String, Map<Integer, BigDecimal>> storeYearMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 初始化所有店铺的年度金额为0
|
|
|
+ List<String> allStores = dbData.stream()
|
|
|
+ .map( RevenueResult::getStoreName)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ allStores.forEach(store -> {
|
|
|
+ Map<Integer, BigDecimal> yearAmount = new HashMap<>();
|
|
|
+ IntStream.rangeClosed(startYear, endYear)
|
|
|
+ .forEach(year -> yearAmount.put(year, BigDecimal.ZERO));
|
|
|
+ storeYearMap.put(store, yearAmount);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 填充实际数据
|
|
|
+ dbData.forEach(dto -> {
|
|
|
+ storeYearMap.get(dto.getStoreName())
|
|
|
+ .put( dto.getYear(), dto.getTotalAmount());
|
|
|
+ });
|
|
|
+
|
|
|
+ // 4. 转换为 ECharts 系列格式
|
|
|
+ List<SeriesData> series = allStores.stream()
|
|
|
+ .map(store -> {
|
|
|
+ List<BigDecimal> data = years.stream()
|
|
|
+ .map(yearStr -> {
|
|
|
+ int year = Integer.parseInt(yearStr);
|
|
|
+ return storeYearMap.get(store).get(year);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return new SeriesData(store, "bar", data);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 5. 构建响应对象
|
|
|
+ EchartsBarResponse response = new EchartsBarResponse();
|
|
|
+ response.setYears(years);
|
|
|
+ response.setSeries(series);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|