|
@@ -1,6 +1,7 @@
|
|
|
package com.fjhx.item.service.product.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
@@ -18,13 +19,16 @@ import com.fjhx.item.entity.product.dto.ProductInfoDto;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
+import com.fjhx.item.entity.product.po.ProductInfoEhsdExcel;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfoEhsdJson;
|
|
|
import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
import com.fjhx.item.mapper.product.ProductInfoMapper;
|
|
|
import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.item.util.CodeEnum;
|
|
|
+import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictTenantData;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
@@ -40,6 +44,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -172,55 +177,27 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
@Override
|
|
|
public Page<ProductInfoVo> getCustomerProductList(ProductInfoSelectDto dto) {
|
|
|
IWrapper<ProductInfo> wrapper = getWrapper();
|
|
|
- wrapper.eq("json_unquote(pi.ehsd_json -> '$.status')", 0);//状态 启用
|
|
|
- wrapper.eq("json_unquote(pi.ehsd_json -> '$.assessStatus')", 3);//评估状态 具备
|
|
|
-// wrapper.ne("json_unquote(pi.ehsd_json -> '$.customerId')", 0);//客户id不等于0
|
|
|
wrapper.eq("json_unquote(pi.ehsd_json -> '$.type')", 2);//客户产品
|
|
|
- //根据产品名称/产品编号过滤
|
|
|
- wrapper.like("pi", ProductInfo::getCode, dto.getCode());
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getName())) {
|
|
|
- wrapper.and(q -> q.like("pi", ProductInfo::getName, dto.getName()))
|
|
|
- .or().like("json_unquote(pi.ehsd_json -> '$.englishName')", dto.getName());
|
|
|
- }
|
|
|
- //根据产品分类id过滤
|
|
|
- wrapper.eq("pi", ProductInfo::getProductClassifyId, dto.getProductClassifyId());
|
|
|
- //客户名称过滤
|
|
|
- wrapper.like("c.name", dto.getCustomerName());
|
|
|
-
|
|
|
- Page<ProductInfoVo> page = baseMapper.getCustomerProductList(dto.getPage(), wrapper);
|
|
|
- List<ProductInfoVo> records = page.getRecords();
|
|
|
- //赋值客户名称
|
|
|
- List<Long> customerIds = new ArrayList<>();
|
|
|
- for (ProductInfoVo record : records) {
|
|
|
- ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
- customerIds.add(productInfoEhsdJson.getCustomerId());
|
|
|
- }
|
|
|
- if (ObjectUtil.isNotEmpty(customerIds)) {
|
|
|
- Map<Long, String> customerMap = customerService.mapKV(Customer::getId, Customer::getName, q -> q.in(Customer::getId, customerIds));
|
|
|
- for (ProductInfoVo record : records) {
|
|
|
- ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
- String customerName = customerMap.get(productInfoEhsdJson.getCustomerId());
|
|
|
- productInfoEhsdJson.setCustomerName(customerName);
|
|
|
- record.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
|
- }
|
|
|
- }
|
|
|
- //赋值创建人名称
|
|
|
- UserUtil.assignmentNickName(page.getRecords(), ProductInfo::getCreateUser, ProductInfoVo::setCreateUserName);
|
|
|
- return page;
|
|
|
+ return getPageByEhsd(dto, wrapper);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Page<ProductInfoVo> getConditionProductList(ProductInfoSelectDto dto) {
|
|
|
IWrapper<ProductInfo> wrapper = getWrapper();
|
|
|
- wrapper.eq("json_unquote(pi.ehsd_json -> '$.status')", 0);//状态 启用
|
|
|
- wrapper.eq("json_unquote(pi.ehsd_json -> '$.assessStatus')", 3);//评估状态 具备
|
|
|
-// wrapper.eq("json_unquote(pi.ehsd_json -> '$.customerId')", 0);//客户id等于0
|
|
|
wrapper.eq("json_unquote(pi.ehsd_json -> '$.type')", 1);//公司产品
|
|
|
+ return getPageByEhsd(dto, wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 尔泓产品库分页公共代码
|
|
|
+ */
|
|
|
+ public Page<ProductInfoVo> getPageByEhsd(ProductInfoSelectDto dto, IWrapper<ProductInfo> wrapper) {
|
|
|
//根据产品名称/产品编号过滤
|
|
|
- wrapper.like("pi", ProductInfo::getCode, dto.getCode());
|
|
|
- if (ObjectUtil.isNotEmpty(dto.getName())) {
|
|
|
- wrapper.and(q -> q.like("pi", ProductInfo::getName, dto.getName()))
|
|
|
- .or().like("json_unquote(pi.ehsd_json -> '$.englishName')", dto.getName());
|
|
|
+ if (ObjectUtil.isNotEmpty(dto.getKeyword())) {
|
|
|
+ wrapper.and(q -> q.like("pi", ProductInfo::getName, dto.getKeyword()))
|
|
|
+ .or().like("json_unquote(pi.ehsd_json -> '$.nameEnglish')", dto.getKeyword())
|
|
|
+ .or().like("pi", ProductInfo::getCode, dto.getKeyword())//产品编号
|
|
|
+ .or().like("c.name", dto.getKeyword());//客户名称
|
|
|
}
|
|
|
//根据产品分类id过滤
|
|
|
wrapper.eq("pi", ProductInfo::getProductClassifyId, dto.getProductClassifyId());
|
|
@@ -231,7 +208,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
List<Long> customerIds = new ArrayList<>();
|
|
|
for (ProductInfoVo record : records) {
|
|
|
ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(record.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
- customerIds.add(productInfoEhsdJson.getCustomerId());
|
|
|
+ customerIds.add(Long.parseLong(productInfoEhsdJson.getCustomerId()));
|
|
|
}
|
|
|
if (ObjectUtil.isNotEmpty(customerIds)) {
|
|
|
Map<Long, String> customerMap = customerService.mapKV(Customer::getId, Customer::getName, q -> q.in(Customer::getId, customerIds));
|
|
@@ -270,11 +247,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
public void addByEhsd(ProductInfoDto productInfoDto) {
|
|
|
//赋值初始状态
|
|
|
ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(productInfoDto.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
- productInfoEhsdJson.setStatus(0);
|
|
|
- productInfoEhsdJson.setAssessStatus(3);
|
|
|
if (ObjectUtil.isEmpty(productInfoEhsdJson.getCustomerId())) {
|
|
|
//如果客户id为空就赋值为0 公司产品
|
|
|
- productInfoEhsdJson.setCustomerId(0l);
|
|
|
+ productInfoEhsdJson.setCustomerId("0");
|
|
|
productInfoEhsdJson.setType("1");//默认公司产品
|
|
|
}
|
|
|
productInfoDto.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
@@ -284,26 +259,28 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
// 排除名称重复
|
|
|
this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), "产品名称重复");
|
|
|
this.save(productInfoDto);
|
|
|
- //图片列表
|
|
|
- ObsFileUtil.saveFile(productInfoDto.getImgList(), productInfoDto.getId(), 1);
|
|
|
//附件列表
|
|
|
- ObsFileUtil.saveFile(productInfoDto.getMinorImgList(), productInfoDto.getId(), 2);
|
|
|
- //附件列表
|
|
|
- ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId(), 3);
|
|
|
+ ObsFileUtil.saveFile(productInfoDto.getFileList(), productInfoDto.getId());
|
|
|
}
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
public void editByEhsd(ProductInfoDto productInfoDto) {
|
|
|
- // 禁止产品编号修改
|
|
|
- productInfoDto.setCode(null);
|
|
|
- // 排除名称重复
|
|
|
- this.nameDuplication(ProductInfo::getName, productInfoDto.getName(), productInfoDto.getId(), "产品名称重复");
|
|
|
- this.updateById(productInfoDto);
|
|
|
- ObsFileUtil.editFile(productInfoDto.getImgList(), productInfoDto.getId(), 1);
|
|
|
- ObsFileUtil.editFile(productInfoDto.getMinorImgList(), productInfoDto.getId(), 2);
|
|
|
- ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId(), 3);
|
|
|
-
|
|
|
+ ProductInfoEhsdJson newProductInfoEhsdJson = JSONObject.parseObject(productInfoDto.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
+ //只允许修改以下字段 销售指导价、成本价、净重、图片、备注
|
|
|
+ ProductInfo productInfo = getById(productInfoDto.getId());
|
|
|
+ if (ObjectUtil.isEmpty(productInfo)) {
|
|
|
+ throw new ServiceException("无法查询到改产品的产品信息,产品id" + productInfoDto.getId());
|
|
|
+ }
|
|
|
+ ProductInfoEhsdJson productInfoEhsdJson = JSONObject.parseObject(productInfo.getEhsdJson(), ProductInfoEhsdJson.class);
|
|
|
+ productInfoEhsdJson.setPrice(newProductInfoEhsdJson.getPrice());//销售指导价
|
|
|
+ productInfoEhsdJson.setCostPrice(newProductInfoEhsdJson.getCostPrice());//成本价
|
|
|
+ productInfoEhsdJson.setNetWeight(newProductInfoEhsdJson.getNetWeight());//净重
|
|
|
+ productInfo.setRemark(productInfoDto.getRemark());//备注
|
|
|
+ productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
|
+ this.updateById(productInfo);
|
|
|
+ //修改图片
|
|
|
+ ObsFileUtil.editFile(productInfoDto.getFileList(), productInfoDto.getId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -316,7 +293,7 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
if (ObjectUtil.isNotEmpty(productInfoEhsdJson) && ObjectUtil.isNotEmpty(productInfoEhsdJson.getCustomerId())) {
|
|
|
//赋值客户名称
|
|
|
Customer customer = customerService.getById(productInfoEhsdJson.getCustomerId());
|
|
|
- if(ObjectUtil.isNotEmpty(customer)) {
|
|
|
+ if (ObjectUtil.isNotEmpty(customer)) {
|
|
|
productInfoEhsdJson.setCustomerName(customer.getName());
|
|
|
result.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
|
}
|
|
@@ -328,6 +305,75 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
+ public void excelImportByEhsd(MultipartFile file) {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ Map<String, String> unitMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "unit"));
|
|
|
+ Map<String, String> innerPackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "inner_packaging_method_ehsd"));
|
|
|
+ Map<String, String> outsidePackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "outside_packaging_method_ehsd"));
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+ List<ProductInfoEhsdExcel> read = ExcelUtil.read(file, ProductInfoEhsdExcel.class);
|
|
|
+ List<ProductInfo> productInfoList = new ArrayList<>();
|
|
|
+ for (ProductInfoEhsdExcel productInfoEhsdExcel : read) {
|
|
|
+ ProductInfo productInfo = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfo.class);
|
|
|
+ // 赋值产品编号
|
|
|
+ productInfo.setCode(CodeEnum.PRODUCT.getCode());
|
|
|
+ // 排除名称重复
|
|
|
+ this.nameDuplication(ProductInfo::getName, productInfo.getName(), "产品名称重复");
|
|
|
+
|
|
|
+ //产品分类名称转id
|
|
|
+ ProductClassify productClassify = productClassifyService.getOne(q -> q.eq(ProductClassify::getName, productInfoEhsdExcel.getProductClassifyName()));
|
|
|
+ if (ObjectUtil.isEmpty(productClassify)) {
|
|
|
+ throw new ServiceException("未知产品分类"+ productInfoEhsdExcel.getProductClassifyName());
|
|
|
+ }
|
|
|
+ productInfo.setProductClassifyId(productClassify.getId());
|
|
|
+ //单位名称转字典key
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfo.getUnit())) {
|
|
|
+ String unit = unitMap.get(productInfo.getUnit());
|
|
|
+ if (ObjectUtil.isEmpty(unit)) {
|
|
|
+ throw new ServiceException("未知单位" + productInfo.getUnit());
|
|
|
+ }
|
|
|
+ productInfo.setUnit(unit);
|
|
|
+ }
|
|
|
+ ProductInfoEhsdJson productInfoEhsdJson = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfoEhsdJson.class);
|
|
|
+ productInfoEhsdJson.setType("1");//公司产品
|
|
|
+ productInfoEhsdJson.setCustomerId("0");//客户id为0 公司产品
|
|
|
+ //内外包装方式名称转字典key
|
|
|
+ String innerPackMethod = productInfoEhsdJson.getInnerPackMethod();
|
|
|
+ if (ObjectUtil.isNotEmpty(innerPackMethod)) {
|
|
|
+ String[] split = innerPackMethod.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String key = innerPackMethodMap.get(split[i]);
|
|
|
+ if (ObjectUtil.isEmpty(key)) {
|
|
|
+ throw new ServiceException("未知内包装方式" + split[i]);
|
|
|
+ }
|
|
|
+ split[i] = key;
|
|
|
+ }
|
|
|
+ productInfoEhsdJson.setInnerPackMethod(String.join(",", split));
|
|
|
+ }
|
|
|
+ String outerPackMethod = productInfoEhsdJson.getOuterPackMethod();
|
|
|
+ if (ObjectUtil.isNotEmpty(outerPackMethod)) {
|
|
|
+ String[] split = outerPackMethod.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String key = outsidePackMethodMap.get(split[i]);
|
|
|
+ if (ObjectUtil.isEmpty(key)) {
|
|
|
+ throw new ServiceException("未知外包装方式" + split[i]);
|
|
|
+ }
|
|
|
+ split[i] = key;
|
|
|
+ }
|
|
|
+ productInfoEhsdJson.setOuterPackMethod(String.join(",", split));
|
|
|
+ }
|
|
|
+ productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
|
+ productInfoList.add(productInfo);
|
|
|
+ }
|
|
|
+ saveBatch(productInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
public void addByWdly(ProductInfoDto productInfoDto) {
|
|
|
//处理维多利亚扩展
|
|
|
String victoriatouristJson = productInfoDto.getVictoriatouristJson();
|
|
@@ -410,15 +456,12 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
//存放产品类型数据
|
|
|
List<Map<String, Object>> typeList = new ArrayList<>();
|
|
|
-
|
|
|
-
|
|
|
QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
|
query.select("count(*) count,ifNull(type,999) type");
|
|
|
query.groupBy("type");
|
|
|
//查询每个类型的总计
|
|
|
List<ProductInfo> productInfos = baseMapper.selectList(query);
|
|
|
Map<String, List<ProductInfo>> productInfoTotalMap = productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
-
|
|
|
query.ge("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getBeginTime());
|
|
|
query.le("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
|
|
|
//查询每个类型的新增数量
|
|
@@ -473,17 +516,49 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
* @param productInfoDto
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<ProductInfo> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
+ public List<Map<String, Object>> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
|
&& StringUtils.isNotEmpty(productInfoDto.getEndTime())) {
|
|
|
throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
}
|
|
|
+ //存放产品分布列表
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+
|
|
|
QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
|
- query.select("count(*) count,type");
|
|
|
+ query.select("count(*) count,ifnull(type,999) type");
|
|
|
query.groupBy("type");
|
|
|
+ query.ge("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getBeginTime());
|
|
|
+ query.le("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
|
|
|
//查询每个类型的总计
|
|
|
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 +567,57 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
* @param productInfoDto
|
|
|
*/
|
|
|
@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();
|
|
|
- query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", productInfoDto.getBeginTime());
|
|
|
- query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
|
|
|
+ String beginTime = DateUtil.format(productInfoDto.getBeginTime(), "yyyy-MM-dd");
|
|
|
+ String endTime = DateUtil.format(productInfoDto.getEndTime(), "yyyy-MM-dd");
|
|
|
+ query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", beginTime);
|
|
|
+ query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", endTime);
|
|
|
query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()), "bc.buy_country_id", productInfoDto.getCountryId());
|
|
|
- sort(query, productInfoDto);
|
|
|
+// sort(query,productInfoDto);
|
|
|
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);
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
+ //排序
|
|
|
+ list = typeSort(list, productInfoDto);
|
|
|
+ }
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 产品排行(数据看板-产品分析页面)
|
|
|
*
|
|
@@ -511,8 +626,10 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
@Override
|
|
|
public Page<ProductInfoVo> productRanking(ProductInfoSelectDto productInfoDto) {
|
|
|
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());
|
|
|
+ String beginTime = DateUtil.format(productInfoDto.getBeginTime(), "yyyy-MM-dd");
|
|
|
+ String endTime = DateUtil.format(productInfoDto.getEndTime(), "yyyy-MM-dd");
|
|
|
+ query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", beginTime);
|
|
|
+ query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", endTime);
|
|
|
query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()), "bc.buy_country_id", productInfoDto.getCountryId());
|
|
|
sort(query, productInfoDto);
|
|
|
query.groupBy("pi.name");
|
|
@@ -544,4 +661,58 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //产品类型排序
|
|
|
+ private List<Map<String, Object>> typeSort(List<Map<String, Object>> list, ProductInfoSelectDto productInfoSelectDto) {
|
|
|
+ if (productInfoSelectDto.getOrderBy() == 10) {
|
|
|
+ if (productInfoSelectDto.getSort() == 10) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 20) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 30) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 40) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (productInfoSelectDto.getSort() == 10) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Collections.reverse(list);
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 20) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Collections.reverse(list);
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 30) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Collections.reverse(list);
|
|
|
+ return list;
|
|
|
+ } else if (productInfoSelectDto.getSort() == 40) {
|
|
|
+ list = list.stream()
|
|
|
+ .sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Collections.reverse(list);
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
}
|