Przeglądaj źródła

添加了产品看板

wxf 2 lat temu
rodzic
commit
a39c9a2e3f

+ 70 - 8
hx-item/src/main/java/com/fjhx/item/service/product/impl/ProductInfoServiceImpl.java

@@ -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;
@@ -411,15 +412,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());
         //查询每个类型的新增数量
@@ -485,6 +483,8 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
         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);
         if (productInfos.size()==0){
@@ -528,10 +528,12 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
         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");
         //查询产品类型排行数据
         List<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(query);
@@ -564,6 +566,10 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
             }
             list.add(map);
         }
+        if (ObjectUtil.isNotEmpty(list)){
+            //排序
+            list= typeSort(list,productInfoDto);
+        }
         return list;
     }
 
@@ -576,8 +582,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");
@@ -609,4 +617,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;
+    }
+
 }