|
@@ -6,6 +6,9 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
@@ -19,9 +22,14 @@ 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.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
+import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
+import com.obs.services.internal.ServiceException;
|
|
|
import com.ruoyi.common.core.domain.BaseIdPo;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
|
|
import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.common.utils.StringUtils;
|
|
|
import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
@@ -30,6 +38,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.function.Function;
|
|
@@ -53,6 +62,9 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
@Autowired
|
|
|
private ISysDeptService sysDeptService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DictTenantDataService dictTenantDataService;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<ProductInfoVo> getPage(ProductInfoSelectDto dto) {
|
|
|
IWrapper<ProductInfo> wrapper = getWrapper();
|
|
@@ -241,4 +253,150 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
updateById(productInfo);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 产品统计(数据看板-产品分析页面)
|
|
|
+ * @param productInfoDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> productStatistics(ProductInfoDto productInfoDto) {
|
|
|
+ if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
|
+ && StringUtils.isNotEmpty(productInfoDto.getEndTime())){
|
|
|
+ throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
+ }
|
|
|
+ //存放产品统计数据
|
|
|
+ Map map =new HashMap();
|
|
|
+
|
|
|
+ //存放产品类型数据
|
|
|
+ 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());
|
|
|
+ //查询每个类型的新增数量
|
|
|
+ List<ProductInfo> productInfoList = baseMapper.selectList(query);
|
|
|
+ Map<String, List<ProductInfo>> productInfoTypeMap = productInfoList.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
+ //计算新增总计
|
|
|
+ Integer newTotal = productInfoList.stream().map(ProductInfo::getCount).reduce(Integer::sum).orElse(0);
|
|
|
+ //总计
|
|
|
+ Integer total = productInfos.stream().map(ProductInfo::getCount).reduce(Integer::sum).orElse(0);
|
|
|
+
|
|
|
+ map.put("newTotal",newTotal);
|
|
|
+ map.put("total",total);
|
|
|
+
|
|
|
+ //获取产品类型的字典数据
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(dictTenantDataVoList)){
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
+ //存放每个类型的新增与总计
|
|
|
+ Map<String,Object> map1 = new HashMap<>();
|
|
|
+ //设置初使值
|
|
|
+ map1.put("type",dictTenantDataVo.getDictKey());
|
|
|
+ map1.put("typeNewTotal",0);
|
|
|
+ map1.put("typeTotal",0);
|
|
|
+
|
|
|
+ //赋值新增的款数
|
|
|
+ List<ProductInfo> productInfoNewList = productInfoTypeMap.get(dictTenantDataVo.getDictKey());
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoNewList)) {
|
|
|
+ map1.put("typeNewTotal",productInfoNewList.get(0).getCount());
|
|
|
+ }
|
|
|
+
|
|
|
+ //赋值类型总计
|
|
|
+ List<ProductInfo> productInfoTotalList = productInfoTotalMap.get(dictTenantDataVo.getDictKey());
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoTotalList)){
|
|
|
+ map1.put("typeTotal",productInfoTotalList.get(0).getCount());
|
|
|
+ }
|
|
|
+ typeList.add(map1);
|
|
|
+ }
|
|
|
+ map.put("typeList",typeList);
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品分布(数据看板-产品分析页面)
|
|
|
+ * @param productInfoDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<ProductInfo> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
+ if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
|
+ && StringUtils.isNotEmpty(productInfoDto.getEndTime())){
|
|
|
+ throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
+ }
|
|
|
+ QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
|
+ query.select("count(*) count,type");
|
|
|
+ query.groupBy("type");
|
|
|
+ //查询每个类型的总计
|
|
|
+ List<ProductInfo> productInfos = baseMapper.selectList(query);
|
|
|
+ return productInfos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品类型排行(数据看板-产品分析页面)
|
|
|
+ * @param productInfoDto
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Page<ProductInfoVo> productTypeRanking(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());
|
|
|
+ query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()),"bc.buy_country_id",productInfoDto.getCountryId());
|
|
|
+ sort(query,productInfoDto);
|
|
|
+ query.groupBy("pi.type");
|
|
|
+ Page<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(productInfoDto.getPage(),query);
|
|
|
+ return productInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 产品排行(数据看板-产品分析页面)
|
|
|
+ * @param productInfoDto
|
|
|
+ */
|
|
|
+ @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());
|
|
|
+ query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()),"bc.buy_country_id",productInfoDto.getCountryId());
|
|
|
+ sort(query,productInfoDto);
|
|
|
+ query.groupBy("pi.name");
|
|
|
+ Page<ProductInfoVo> productInfoVos = baseMapper.productRanking(productInfoDto.getPage(),query);
|
|
|
+ return productInfoVos;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //根据字典编码获取字典的数据
|
|
|
+ private List<DictTenantDataVo> getDict(String code){
|
|
|
+ DictTenantDataSelectDto dto = new DictTenantDataSelectDto();
|
|
|
+ dto.setDictCode(code);
|
|
|
+ List<DictTenantDataVo> dictTenantDataServiceList = dictTenantDataService.getList(dto);
|
|
|
+ return dictTenantDataServiceList;
|
|
|
+ }
|
|
|
+
|
|
|
+ //排序(添加排序条件)
|
|
|
+ private void sort( QueryWrapper<Object> query,ProductInfoSelectDto productInfoDto){
|
|
|
+ if (productInfoDto.getOrderBy() ==10){//正序
|
|
|
+ query.orderByAsc(productInfoDto.getSort() ==10,"contractQuantity");
|
|
|
+ query.orderByAsc(productInfoDto.getSort() ==20,"contractAmount");
|
|
|
+ query.orderByAsc(productInfoDto.getSort() ==30,"purchaseQuantity");
|
|
|
+ query.orderByAsc(productInfoDto.getSort() ==40,"purchaseAmount");
|
|
|
+ }else if (productInfoDto.getOrderBy() == 20){//倒序
|
|
|
+ query.orderByDesc(productInfoDto.getSort() ==10,"contractQuantity");
|
|
|
+ query.orderByDesc(productInfoDto.getSort() ==20,"contractAmount");
|
|
|
+ query.orderByDesc(productInfoDto.getSort() ==30,"purchaseQuantity");
|
|
|
+ query.orderByDesc(productInfoDto.getSort() ==40,"purchaseAmount");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|