|
@@ -8,6 +8,7 @@ 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;
|
|
@@ -41,6 +42,8 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
|
|
|
import com.ruoyi.common.utils.wrapper.SqlField;
|
|
|
import com.ruoyi.system.service.ISysDeptService;
|
|
|
import com.ruoyi.system.utils.UserUtil;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.collections4.ListUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -740,6 +743,51 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
return baseMapper.statisticsProduct();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 产品库统计(根据产品库类型进行分类统计)
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String,Object> productInfoStatistics(ProductInfoSelectDto dto) {
|
|
|
+ //存放产品库统计数据
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+
|
|
|
+ //存放产品分类统计数据
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
+ QueryWrapper<ProductInfo> wrapper = Wrappers.query();
|
|
|
+ wrapper.groupBy("type");
|
|
|
+ wrapper.select("count(*) count, ifNull(type,-1)");
|
|
|
+ List<ProductInfo> productInfos = baseMapper.selectList(wrapper);
|
|
|
+ Map<String, List<ProductInfo>> productInfoMap = productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
+
|
|
|
+ //计算统计合计
|
|
|
+ Integer amount = productInfos.stream().map(productInfo -> productInfo.getCount()).reduce(Integer::sum).orElse(0);
|
|
|
+
|
|
|
+ map.put("amount",amount);
|
|
|
+ //获取产品类型统计数据
|
|
|
+ List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
|
|
|
+
|
|
|
+ if (dictTenantDataVoList.size()==0){
|
|
|
+ throw new ServiceException("数据异常:产品没有设置产品类型字典,请先添加");
|
|
|
+ }
|
|
|
+
|
|
|
+ for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
+ Map typeMap = new HashMap();
|
|
|
+ //设置初始值
|
|
|
+ typeMap.put("type",dictTenantDataVo.getDictValue());
|
|
|
+ typeMap.put("count",0);
|
|
|
+
|
|
|
+ //赋值
|
|
|
+ List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
|
|
|
+ if (CollectionUtils.isNotEmpty(productInfoList)){
|
|
|
+ typeMap.put("count",productInfoList.get(0).getCount());
|
|
|
+ }
|
|
|
+ list.add(typeMap);
|
|
|
+
|
|
|
+ }
|
|
|
+ map.put("typeList",list);
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
//根据字典编码获取字典的数据
|
|
|
private List<DictTenantDataVo> getDict(String code) {
|