From c11bce150d6e702f41ce247a0c62ea03401318f1 Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期一, 26 一月 2026 18:34:08 +0800
Subject: [PATCH] 经销商管理

---
 server/dmmall_service/src/main/java/com/doumee/service/business/impl/WorkbenchServiceImpl.java |  144 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 104 insertions(+), 40 deletions(-)

diff --git a/server/dmmall_service/src/main/java/com/doumee/service/business/impl/WorkbenchServiceImpl.java b/server/dmmall_service/src/main/java/com/doumee/service/business/impl/WorkbenchServiceImpl.java
index b619893..0a6262c 100644
--- a/server/dmmall_service/src/main/java/com/doumee/service/business/impl/WorkbenchServiceImpl.java
+++ b/server/dmmall_service/src/main/java/com/doumee/service/business/impl/WorkbenchServiceImpl.java
@@ -45,6 +45,7 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.time.LocalDate;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -60,12 +61,71 @@
     private GoodsorderMapper goodsorderMapper;
     @Autowired
     private GoodsorderDetailMapper goodsorderDetailMapper;
+    @Override
+    public List<BusinessDataCountVO> shopRankList10(CountDataDTO param) {
+        Date startDate = null,endDate = null;
+        if(param.getYear()!=null && param.getMonth()!=null){
+            List<Date> dList = DateUtil.getDatePeriodByYearAndMonth(param.getYear(),param.getMonth()-1);
+            startDate = dList.get(0);
+            endDate = dList.get(1);
+        }else if(param.getYear()!=null && param.getMonth()==null){
+            List<Date> dList = DateUtil.getDatePeriodByYear(param.getYear());
+            startDate = dList.get(0);
+            endDate = dList.get(1);
+        }
+        //缁熻璁㈠崟閿�閲忓拰閿�鍞闆嗗悎
+        List<BusinessDataCountVO> list1 =  goodsorderMapper.selectJoinList(BusinessDataCountVO.class,new MPJLambdaWrapper<Goodsorder>()
+                .selectAs(Shop::getName,BusinessDataCountVO::getName)
+                .select("(select count(distinct(t.member_id)) )",BusinessDataCountVO::getNum1)
+                .select("(select count(t.id) )",BusinessDataCountVO::getNum)
+                .select("(select sum(t.total_price) )",BusinessDataCountVO::getPrice)
+                .leftJoin(Shop.class,Shop::getId,Goodsorder::getDistributionShopId)
+                .ge(startDate!=null,Goodsorder::getCreateDate,startDate)
+                .ne(endDate!=null,Goodsorder::getCreateDate,endDate)
+                .eq(Goodsorder::getIsdeleted,Constants.ZERO)
+                .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey())
+                .groupBy(Goodsorder::getDistributionShopId)
+                .orderByDesc(Constants.equalsInteger(param.getType() ,0),"sum(t.total_price) ")
+                .orderByDesc(Constants.equalsInteger(param.getType() ,1),"count(t.id) ")
+                .orderByDesc(Constants.equalsInteger(param.getType() ,2),"count(distinct(t.member_id))")
+                .last("limit 10")) ;
+        return list1;
 
+    }
+    @Override
+    public List<BusinessDataCountVO> goodsRankList10(CountDataDTO param) {
+        Date startDate = null,endDate = null;
+        if(param.getYear()!=null && param.getMonth()!=null){
+            List<Date> dList = DateUtil.getDatePeriodByYearAndMonth(param.getYear(),param.getMonth()-1);
+            startDate = dList.get(0);
+            endDate = dList.get(1);
+        }else if(param.getYear()!=null && param.getMonth()==null){
+            List<Date> dList = DateUtil.getDatePeriodByYear(param.getYear());
+            startDate = dList.get(0);
+            endDate = dList.get(1);
+        }
+        //缁熻璁㈠崟閿�閲忓拰閿�鍞闆嗗悎
+        List<BusinessDataCountVO> list1 =  goodsorderDetailMapper.selectJoinList(BusinessDataCountVO.class,new MPJLambdaWrapper<GoodsorderDetail>()
+                .selectAs(Goods::getName,BusinessDataCountVO::getName)
+                .select("(select sum(t.goods_num) )",BusinessDataCountVO::getNum)
+                .select("(select  sum(ifnull(t.price,0) * ifnull(t.goods_num,0)))",BusinessDataCountVO::getPrice)
+                .leftJoin(Goodsorder.class,Goodsorder::getId,GoodsorderDetail::getOrderId)
+                .leftJoin(Goods.class,Goods::getId,GoodsorderDetail::getGoodsId)
+                .ge(startDate!=null,Goodsorder::getCreateDate,startDate)
+                .ne(endDate!=null,Goodsorder::getCreateDate,endDate)
+                .eq(Goodsorder::getIsdeleted,Constants.ZERO)
+                .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey())
+                .groupBy(GoodsorderDetail::getGoodsId)
+                .orderByDesc(Constants.equalsInteger(param.getType() ,1),"sum(ifnull(t.price,0) * ifnull(t.goods_num,0)) ")
+                .orderByDesc(Constants.equalsInteger(param.getType() ,0),"sum(t.goods_num) ")
+                .last("limit 10")) ;
+        return list1;
+    }
     @Override
     public BusinessDataCountVO businessData(CountDataDTO param) {
         BusinessDataCountVO data = new BusinessDataCountVO();
         int dataType = param.getDateType();//0浠婃棩 1杩戜竷鏃� 2杩�30鏃� 3杩�1骞�
-        String name = "HOUR(CREATE_DATE)";
+        String name = "HOUR(t.CREATE_DATE)";
         List<String> dateList = new ArrayList<>();
         Date date = Utils.Date.getEnd(new Date());//浠婃棩 23:59:59
         Date startDate = DateUtil.addDaysToDate(date,-1);
@@ -73,22 +133,23 @@
             case 1: {
                 name = "DATE_FORMAT(t.CREATE_DATE, '%Y-%m-%d')";
                 for(int i=1;i<=7;i++){
-                    dateList.add(DateUtil.getPlusTime2(DateUtil.addDaysToDate(date,7-i)));
+                    dateList.add(DateUtil.getShortTime(DateUtil.addDaysToDate(date,i-7)));
                 }
-                startDate = DateUtil.addDaysToDate(date,7);
+                startDate = DateUtil.addDaysToDate(date,-7);
                 break;
             } case 2: {
-                name = "DATE_FORMAT(GoodsCREATE_DATE, '%Y-%m-%d')";
+                name = "DATE_FORMAT(t.CREATE_DATE, '%Y-%m-%d')";
                 for(int i=1;i<=30;i++){
-                    dateList.add(DateUtil.getPlusTime2(DateUtil.addDaysToDate(date,30-i)));
+                    dateList.add(DateUtil.getShortTime(DateUtil.addDaysToDate(date,i-30)));
                 }
-                startDate = DateUtil.addDaysToDate(date,30);
+                startDate = DateUtil.addDaysToDate(date,-30);
                 break;
             } case 3: {
-                startDate = DateUtil.increaseMonth(date,-12);
-                name = "DATE_FORMAT(GoodsCREATE_DATE, '%Y-%m')";
+                LocalDate now = LocalDate.now();
+                startDate = DateUtil.increaseYear(date,-1);
+                name = "DATE_FORMAT(t.CREATE_DATE, '%Y-%m')";
                 for(int i=1;i<=12;i++){
-                    dateList.add(DateUtil.getPlusTime2(DateUtil.increaseMonth(date,12-i)));
+                    dateList.add(DateUtil.minusMonthToDate(now,12-i));
                 }
                 break;
             } default:{
@@ -98,10 +159,12 @@
                 break;
             }
         }
+
+        data.setDateStrList(dateList);
         //璁㈠崟閿�閲�
         CountDataVO r =  goodsorderMapper.selectJoinOne(CountDataVO.class,new MPJLambdaWrapper<Goodsorder>()
                         .select("(select count(t.id) )",CountDataVO::getNum)
-                        .select("(select sum(t.totalPrice) )",CountDataVO::getPrice)
+                        .select("(select sum(t.total_Price) )",CountDataVO::getPrice)
                 .ge(Goodsorder::getCreateDate,startDate)
                 .eq(Goodsorder::getIsdeleted,Constants.ZERO)
                 .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey()) );
@@ -112,7 +175,7 @@
         //閫�娆剧粺璁�
         CountDataVO r1 =  goodsorderMapper.selectJoinOne(CountDataVO.class,new MPJLambdaWrapper<Goodsorder>()
                         .select("(select count(t.id) )",CountDataVO::getNum)
-                        .select("(select sum(t.reundMoney) )",CountDataVO::getPrice)
+                        .select("(select sum(t.refund_money) )",CountDataVO::getPrice)
                 .ge(Goodsorder::getRefundTime,startDate)
                 .eq(Goodsorder::getIsdeleted,Constants.ZERO)
                 .in(Goodsorder::getStatus,Constants.OrderStatus.REFUND.getKey())  );
@@ -127,76 +190,77 @@
         List<CountDataVO> list1 =  goodsorderMapper.selectJoinList(CountDataVO.class,new MPJLambdaWrapper<Goodsorder>()
                 .select("(select "+name+")",CountDataVO::getDateStr)
                 .select("(select count(t.id) )",CountDataVO::getNum)
-                .select("(select sum(t.totalPrice) )",CountDataVO::getPrice)
-                .ge(Goodsorder::getRefundTime,startDate)
+                .select("(select sum(t.total_price) )",CountDataVO::getPrice)
+                .ge(Goodsorder::getCreateDate,startDate)
                 .eq(Goodsorder::getIsdeleted,Constants.ZERO)
                 .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey())
                 .groupBy(name) );
 
-        List<CountDataVO> datalist1 = new ArrayList<>();
+        List<Long> datalist1 = new ArrayList<>();
+        List<BigDecimal> datalistPrice = new ArrayList<>();
         for(String str : dateList){
-            CountDataVO tmp = new CountDataVO();
-            tmp.setDateStr(str);
-            tmp.setNum(0l);
-            tmp.setPrice(new BigDecimal(0));
+            long tnum =0;
+            BigDecimal tprice = new BigDecimal(0);
             if(list1!=null){
                 for(CountDataVO p : list1){
                     if(StringUtils.equals(p.getDateStr(),str)){
-                        tmp.setNum(Constants.formatLongNum(p.getNum()));
-                        tmp.setPrice(Constants.formatBigdecimal(p.getPrice()));
+                        tnum =(Constants.formatLongNum(p.getNum()));
+                        tprice = (Constants.formatBigdecimal(p.getPrice()));
+                        break;
                     }
                 }
             }
-            datalist1.add(tmp);
+            datalist1.add( tnum );
+            datalistPrice.add(tprice);
         }
         data.setDataList(datalist1 );
+        data.setDataList2(datalistPrice );
 
+        String name1 =name.replace("t.","t3.");
         //缁熻鍚勭被鍟嗗搧鏁版嵁闆嗗悎
         List<CountDataVO> list2 =  goodsorderDetailMapper.selectJoinList(CountDataVO.class,new MPJLambdaWrapper<GoodsorderDetail>()
-                .select("(select "+name+")",CountDataVO::getDateStr)
+                .select("(select "+name1+")",CountDataVO::getDateStr)
                 .selectAs(Labels::getName,CountDataVO::getName)
-                .select("(select sum(t.totalPrice) )",CountDataVO::getPrice)
-                 .leftJoin(Goods.class,Goods::getId,GoodsorderDetail::getGoodsId)
-                 .leftJoin(Labels.class,Labels::getId,Goods::getCategoryId)
-                 .leftJoin(Goodsorder.class,Goodsorder::getId,GoodsorderDetail::getOrderId)
-                .ge(Goodsorder::getRefundTime,startDate)
+                .select("(select sum(ifnull(t.price,0) * ifnull(t.goods_num,0)) )",CountDataVO::getPrice)
+                .leftJoin(Goods.class,Goods::getId,GoodsorderDetail::getGoodsId)
+                .leftJoin(Labels.class,Labels::getId,Goods::getCategoryId)
+                .leftJoin(Goodsorder.class,Goodsorder::getId,GoodsorderDetail::getOrderId)
+                .ge(Goodsorder::getCreateDate,startDate)
                 .eq(Goodsorder::getIsdeleted,Constants.ZERO)
                 .in(Goodsorder::getStatus,Constants.OrderStatus.DONE.getKey(),Constants.OrderStatus.REFUND.getKey())
-                .groupBy(name +",t2.category_id"));
+                .groupBy(name1+",t1.category_id"));
 
-        List<BigDecimal[]> datalist2 = new ArrayList<>();
-        List<String> cateList = getCateListFromDataList(list2);
+        List<CountDataVO> cateList = getCateListFromDataList(list2);
         if(list2!=null &&list2.size()>0 && cateList!=null && cateList.size()>0){
             BigDecimal[] temp = new BigDecimal[dateList.size()];
-            for(String cate : cateList){
+            for(CountDataVO cate : cateList){
                 for(int i=0;i<dateList.size();i++){
                     temp[i] = new BigDecimal(0);
                     for(CountDataVO model : list2){
-                        if(StringUtils.equals(model.getDateStr(),dateList.get(i)) && StringUtils.equals(model.getName(),cate)){
-                            temp[i] = temp[i].add(Constants.formatBigdecimal(model.getPrice()));
+                        if(StringUtils.equals(model.getDateStr(),dateList.get(i)) && StringUtils.equals(model.getName(),cate.getName())){
+                            temp[i] = Constants.formatBigdecimal(model.getPrice());
                         }
                     }
                 }
-                datalist2.add(temp);
+                cate.setData(temp);
             }
         }
         data.setCateList(cateList);
-        data.setNumList(datalist2 );
         return data;
     }
 
-    private List<String> getCateListFromDataList(List<CountDataVO> list2) {
-        List<String> list = new ArrayList<>();
+    private List<CountDataVO> getCateListFromDataList(List<CountDataVO> list2) {
+        List<CountDataVO> list = new ArrayList<>();
         for(CountDataVO model :list2){
             boolean isnew = true;
-            for(String str :list){
-                if(StringUtils.equals(str,model.getName())){
+            for(CountDataVO str :list){
+                if(StringUtils.equals(str.getName(),model.getName())){
                     isnew = false;
                 }
 
             }
             if(isnew ){
-                list.add(model.getName());
+                list.add(model);
             }
         }
         return list;

--
Gitblit v1.9.3