|
@@ -40,6 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -473,17 +474,47 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
* @param productInfoDto
|
|
* @param productInfoDto
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public List<ProductInfo> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
|
|
|
+ public List<Map<String,Object>> productDistribution(ProductInfoDto productInfoDto) {
|
|
if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
- && StringUtils.isNotEmpty(productInfoDto.getEndTime())) {
|
|
|
|
- throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
|
|
|
+ && StringUtils.isNotEmpty(productInfoDto.getEndTime())){
|
|
|
|
+ throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
}
|
|
}
|
|
|
|
+ //存放产品分布列表
|
|
|
|
+ List<Map<String,Object>> list = new ArrayList<>();
|
|
|
|
+
|
|
QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
- query.select("count(*) count,type");
|
|
|
|
|
|
+ query.select("count(*) count,ifnull(type,999) type");
|
|
query.groupBy("type");
|
|
query.groupBy("type");
|
|
//查询每个类型的总计
|
|
//查询每个类型的总计
|
|
List<ProductInfo> productInfos = baseMapper.selectList(query);
|
|
List<ProductInfo> productInfos = baseMapper.selectList(query);
|
|
- return productInfos;
|
|
|
|
|
|
+ if (productInfos.size()==0){
|
|
|
|
+ new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ Map<String, List<ProductInfo>> productInfoMap= productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
|
+ //获取产品类型的字典数据
|
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
|
+ List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
|
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
|
+
|
|
|
|
+ if (dictTenantDataVoList.size()==0){
|
|
|
|
+ new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //赋值
|
|
|
|
+ for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ //初始化
|
|
|
|
+ map.put("type",dictTenantDataVo.getDictKey());
|
|
|
|
+ map.put("name",dictTenantDataVo.getDictValue());
|
|
|
|
+ map.put("count",0);
|
|
|
|
+
|
|
|
|
+ List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
|
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoList)){
|
|
|
|
+ map.put("count",productInfoList.get(0).getCount());
|
|
|
|
+ }
|
|
|
|
+ list.add(map);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -492,17 +523,51 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
* @param productInfoDto
|
|
* @param productInfoDto
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public Page<ProductInfoVo> productTypeRanking(ProductInfoSelectDto productInfoDto) {
|
|
|
|
|
|
+ public List<Map<String,Object>> productTypeRanking(ProductInfoSelectDto productInfoDto) {
|
|
|
|
+ //存放产品类型排行数据
|
|
|
|
+ List<Map<String,Object>> list = new ArrayList<>();
|
|
|
|
+
|
|
QueryWrapper<Object> query = Wrappers.query();
|
|
QueryWrapper<Object> query = Wrappers.query();
|
|
- query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", productInfoDto.getBeginTime());
|
|
|
|
- query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
|
|
|
|
- query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()), "bc.buy_country_id", productInfoDto.getCountryId());
|
|
|
|
- sort(query, productInfoDto);
|
|
|
|
|
|
+ query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",productInfoDto.getBeginTime());
|
|
|
|
+ query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",productInfoDto.getEndTime());
|
|
|
|
+ query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()),"bc.buy_country_id",productInfoDto.getCountryId());
|
|
|
|
+ sort(query,productInfoDto);
|
|
query.groupBy("pi.type");
|
|
query.groupBy("pi.type");
|
|
- Page<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(productInfoDto.getPage(), query);
|
|
|
|
- return productInfoVos;
|
|
|
|
|
|
+ //查询产品类型排行数据
|
|
|
|
+ List<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(query);
|
|
|
|
+ if (productInfoVos.size()==0){
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ Map<String, List<ProductInfoVo>> productInfoVoMap = productInfoVos.stream().collect(Collectors.groupingBy(ProductInfoVo::getType));
|
|
|
|
+ //获取产品类型的字典数据
|
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
|
+ List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
|
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
|
+
|
|
|
|
+ //赋值
|
|
|
|
+ for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
|
+ //初始化
|
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
|
+ map.put("type",dictTenantDataVo.getDictKey());
|
|
|
|
+ map.put("name",dictTenantDataVo.getDictValue());
|
|
|
|
+ map.put("contractAmount",new BigDecimal(0));
|
|
|
|
+ map.put("contractQuantity",new BigDecimal(0));
|
|
|
|
+ map.put("purchaseAmount",new BigDecimal(0));
|
|
|
|
+ map.put("purchaseQuantity",new BigDecimal(0));
|
|
|
|
+ //赋值
|
|
|
|
+ List<ProductInfoVo> productInfoVos1 = productInfoVoMap.get(dictTenantDataVo.getDictKey());
|
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoVos1)){
|
|
|
|
+ map.put("contractAmount",productInfoVos1.get(0).getContractAmount());
|
|
|
|
+ map.put("contractQuantity",productInfoVos1.get(0).getContractQuantity());
|
|
|
|
+ map.put("purchaseAmount",productInfoVos1.get(0).getPurchaseAmount());
|
|
|
|
+ map.put("purchaseQuantity",productInfoVos1.get(0).getPurchaseQuantity());
|
|
|
|
+ }
|
|
|
|
+ list.add(map);
|
|
|
|
+ }
|
|
|
|
+ return list;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 产品排行(数据看板-产品分析页面)
|
|
* 产品排行(数据看板-产品分析页面)
|
|
*
|
|
*
|