Commit ef21025b by 蔡茜

产值排名

1 parent ac6300a3
......@@ -2,11 +2,13 @@ package cn.com.glsx.dj.peanalysis.service;
import cn.com.glsx.dj.peanalysis.dto.DataBizQueryParamsDTO;
import cn.com.glsx.dj.peanalysis.dto.DataBusinessDTO;
import cn.com.glsx.dj.peanalysis.dto.job.BiRecord;
import cn.com.glsx.dj.peanalysis.dto.req.output.RegionalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.req.output.TotalOutputReq;
import cn.com.glsx.dj.peanalysis.dto.res.output.*;
import cn.com.glsx.dj.peanalysis.enums.LoginRoleEnum;
import cn.com.glsx.dj.peanalysis.enums.ProvinceEnum;
import cn.com.glsx.dj.peanalysis.mapper.BusinessIntelligenceMapper;
import cn.com.glsx.dj.peanalysis.mapper.ServiceMerchantMapper;
import cn.com.glsx.dj.peanalysis.utils.DateUtils;
import cn.com.glsx.dj.peanalysis.utils.response.DataResp;
......@@ -21,6 +23,7 @@ import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
......@@ -49,6 +52,11 @@ public class BusinessAnalysisService {
private GetDataStatsService getDataStatsService;
@Resource
private MerchantRemote merchantRemote;
@Resource
private BusinessIntelligenceMapper businessIntelligenceMapper;
@Resource
@Lazy
private UsedCarDataStatsService usedCarDataStatsService;
public TotalOutputResponse totalOutput(TotalOutputReq request) {
TotalOutputResponse result = new TotalOutputResponse();
......@@ -98,23 +106,33 @@ public class BusinessAnalysisService {
}
//设置省份排行
List<ProvinceOutputResponse> provinceOutputResponses = provinceOutput(totalOutputGroupByMerchant, merchantIds);
List<ProvinceOutputResponse> provinceOutputResponses = provinceOutput(totalOutputGroupByMerchant, request);
result.setProvinceOutput(provinceOutputResponses);
return result;
}
public List<ProvinceOutputResponse> provinceOutput(List<DataBusinessDTO> totalOutputGroupByMerchant, List<Integer> merchantIds) {
public List<ProvinceOutputResponse> provinceOutput(List<DataBusinessDTO> totalOutputGroupByMerchant, TotalOutputReq req) {
List<ProvinceOutputResponse> result = new ArrayList<>();
TotalOutputResponse totalOutput = getTotalOutput(totalOutputGroupByMerchant);
merchantIds = totalOutputGroupByMerchant.stream().map(DataBusinessDTO::getMerchantId).collect(Collectors.toList());
List<Integer> merchantIds = totalOutputGroupByMerchant.stream().map(DataBusinessDTO::getMerchantId).collect(Collectors.toList());
List<MerchantProvinceDTO> provinceByMerchantIdConcurrent = getProvinceByMerchantIdConcurrent(merchantIds);
Map<Integer, Integer> merchantProvinceCodeMap = new HashMap<>();
Map<Integer, MerchantProvinceDTO> merchantProvinceMap = new HashMap<>();
Map<Integer, List<BiRecord>> biRecordProvinceMap = new HashMap<>();
List<BiRecord> biRecords = businessIntelligenceMapper.getBiRecords(null, merchantIds, req.getStartTime(), req.getEndTime());
for (MerchantProvinceDTO dto : provinceByMerchantIdConcurrent) {
merchantProvinceCodeMap.put(dto.getMerchantId(), dto.getProvinceCode());
merchantProvinceMap.put(dto.getMerchantId(), dto);
biRecordProvinceMap.put(dto.getProvinceCode(), new ArrayList<>());
List<BiRecord> temp = biRecordProvinceMap.get(dto.getProvinceCode());
if (CollectionUtils.isEmpty(temp)) {
temp = new ArrayList<>();
biRecordProvinceMap.put(dto.getProvinceCode(), temp);
}
}
for (BiRecord biRecord : biRecords) {
List<BiRecord> records = biRecordProvinceMap.get(merchantProvinceCodeMap.get(biRecord.getMerchantId()));
records.add(biRecord);
}
for (DataBusinessDTO dto : totalOutputGroupByMerchant) {
......@@ -136,6 +154,7 @@ public class BusinessAnalysisService {
provinceOutput.setProvinceId(provinceCode);
provinceOutput.setProvinceName(ProvinceEnum.getProvinceName(provinceCode));
provinceOutput.setTotalOutput(BigDecimal.ZERO);
provinceOutput.setStoreNumber(0);
result.add(provinceOutput);
}
......@@ -151,20 +170,18 @@ public class BusinessAnalysisService {
}
// 计算门店总数
int totalStores = result.stream()
.mapToInt(ProvinceOutputResponse::getStoreNumber)
.sum();
for (ProvinceOutputResponse provinceOutputResponse : result) {
Integer storeNumber = provinceOutputResponse.getStoreNumber();
BigDecimal avgOutput = provinceOutputResponse.getTotalOutput()
.multiply(new BigDecimal("100"))
.divide(BigDecimal.valueOf(storeNumber), 2, RoundingMode.HALF_UP);
provinceOutputResponse.setAvgOutput(avgOutput);
}
// 计算门店总数
int totalStores = totalOutput.getStoreCount();
// 计算各项指标
for (ProvinceOutputResponse province : result) {
// 计算店均产值
if (province.getStoreNumber() > 0) {
BigDecimal avgOutput = province.getTotalOutput()
.divide(BigDecimal.valueOf(province.getStoreNumber()), 2, RoundingMode.HALF_UP);
province.setAvgOutput(avgOutput);
}
// 计算门店占比
if (totalStores > 0) {
BigDecimal storeRatio = BigDecimal.valueOf(province.getStoreNumber())
......@@ -174,7 +191,17 @@ public class BusinessAnalysisService {
}
// 计算多品类门店占比
List<BiRecord> records = biRecordProvinceMap.getOrDefault(
province.getProvinceId(),
Collections.emptyList()
);
int multiCategoryStoreCount = usedCarDataStatsService.countMultiCategoryStores(records);
if (province.getStoreNumber() > 0) {
BigDecimal multiCategoryStoreNumberRate = new BigDecimal(multiCategoryStoreCount)
.multiply(new BigDecimal("100"))
.divide(BigDecimal.valueOf(province.getStoreNumber()), 2, RoundingMode.HALF_UP);
province.setMultiCategoryStoreNumberRate(multiCategoryStoreNumberRate);
}
}
result.sort(Comparator.comparing(ProvinceOutputResponse::getTotalOutput).reversed());
......@@ -232,8 +259,7 @@ public class BusinessAnalysisService {
public List<DataBusinessDTO> getTotalOutputGroupByMerchant(DataBizQueryParamsDTO queryDataBiz) {
String jsonBody = JSONUtil.toJsonStr(queryDataBiz);
DataResp<List<DataBusinessDTO>> dataResp = getDataStatsService.getListDataResp(jsonBody);
List<DataBusinessDTO> content = dataResp.getContent();
return content;
return dataResp.getContent();
}
public TotalOutputResponse getTotalOutput(DataBizQueryParamsDTO queryDataBiz) {
......@@ -270,10 +296,8 @@ public class BusinessAnalysisService {
try {
for (int i = 0; i < merchantIds.size(); i += batchSize) {
int start = i;
int end = Math.min(start + batchSize, merchantIds.size());
List<Integer> batchIds = merchantIds.subList(start, end);
int end = Math.min(i + batchSize, merchantIds.size());
List<Integer> batchIds = new ArrayList<>(merchantIds.subList(i, end));
CompletableFuture<List<MerchantProvinceDTO>> future =
CompletableFuture.supplyAsync(() -> {
try {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!