From d1068115eccec5ab657f3fcfd6750bb4028eda80 Mon Sep 17 00:00:00 2001
From: xiaoyong931011 <15274802129@163.com>
Date: Fri, 16 Jul 2021 17:03:35 +0800
Subject: [PATCH] 202107016

---
 gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java            |    8 +-
 gc-user/src/main/resources/mapper/user/AccountMapper.xml                     |  178 ++++++++++++++++++++++++++++++++++++++-----
 gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java              |    8 +
 gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java |    2 
 4 files changed, 166 insertions(+), 30 deletions(-)

diff --git a/gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java b/gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java
index da31405..0930fb6 100644
--- a/gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java
+++ b/gc-user/src/main/java/com/xzx/gc/user/controller/AdminDistribController.java
@@ -214,7 +214,7 @@
         return JsonResult.success(distribService.distribDataList(distribDataListDto));
     }
 
-    @ApiOperation(value = "团长数据--列表导出")
+    @ApiOperation(value = "团长数据--列表导出",produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
     @PostMapping(value = Constants.ADMIN_VIEW_PREFIX + "/distrib/distribDataExport.json")
     public void distribDataExport(@RequestBody ExportDistribDataListDto distribDataListDto, HttpServletRequest request, HttpServletResponse response) {
         List<List<String>> rows = new ArrayList<>();
diff --git a/gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java b/gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java
index 5f1d487..a6d127e 100644
--- a/gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java
+++ b/gc-user/src/main/java/com/xzx/gc/user/mapper/AccountMapper.java
@@ -65,12 +65,16 @@
 
     List<DistribDataListVo> distribDataList(@Param("record")DistribDataListDto distribDataListDto);
 
-    String selectOrderByHeadUserId(@Param("accountId")String accountId);
+    String selectOrderByHeadUserId(@Param("accountId")String accountId,@Param("record")DistribDataListDto distribDataListDto);
 
-    String selectJDSLByHeadUserId(@Param("accountId")String id);
+    String selectJDSLByHeadUserId(@Param("accountId")String id,@Param("record")DistribDataListDto distribDataListDto);
 
     DistribDataInfoVo selectDistribDataInfoVo();
 
     List<DistribDataListVo> distribDataExport(@Param("record")ExportDistribDataListDto distribDataListDto);
+
+    String selectOrderExportByHeadUserId(@Param("accountId")String id, @Param("record")ExportDistribDataListDto distribDataListDto);
+
+    String selectJDSLExportByHeadUserId(@Param("accountId")String id, @Param("record")ExportDistribDataListDto distribDataListDto);
 }
 
diff --git a/gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java b/gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java
index ef30097..83a4d6e 100644
--- a/gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java
+++ b/gc-user/src/main/java/com/xzx/gc/user/service/DistribService.java
@@ -349,9 +349,9 @@
                     String decode = StringUtils.decode(nickname);
                     distribDataListVo.setNickname(decode);
                     String id = distribDataListVo.getId();
-                    String kg = accountMapper.selectOrderByHeadUserId(id);
+                    String kg = accountMapper.selectOrderByHeadUserId(id,distribDataListDto);
                     distribDataListVo.setKg(kg);
-                    String jdsl = accountMapper.selectJDSLByHeadUserId(id);
+                    String jdsl = accountMapper.selectJDSLByHeadUserId(id,distribDataListDto);
                     distribDataListVo.setJdsl(jdsl);
                 }
             }
@@ -383,9 +383,9 @@
                     String decode = StringUtils.decode(nickname);
                     distribDataListVo.setNickname(decode);
                     String id = distribDataListVo.getId();
-                    String kg = accountMapper.selectOrderByHeadUserId(id);
+                    String kg = accountMapper.selectOrderExportByHeadUserId(id,distribDataListDto);
                     distribDataListVo.setKg(kg);
-                    String jdsl = accountMapper.selectJDSLByHeadUserId(id);
+                    String jdsl = accountMapper.selectJDSLExportByHeadUserId(id,distribDataListDto);
                     distribDataListVo.setJdsl(jdsl);
                 }
             }
diff --git a/gc-user/src/main/resources/mapper/user/AccountMapper.xml b/gc-user/src/main/resources/mapper/user/AccountMapper.xml
index c3ade75..3eff87a 100644
--- a/gc-user/src/main/resources/mapper/user/AccountMapper.xml
+++ b/gc-user/src/main/resources/mapper/user/AccountMapper.xml
@@ -283,9 +283,33 @@
         b.regist_time registTime,
         a.is_head isHead,
         (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id) cnt,
-        (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id) orderCnt,
-        (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id) amount,
-        (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id ) score,
+        (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id
+            <if test="record.reserveTimeStart != null">
+                and CREATED_TIME >= #{record.reserveTimeStart}
+            </if>
+
+            <if test="record.reserveTimeEnd != null">
+                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+            </if>
+        ) orderCnt,
+        (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>
+        ) amount,
+        (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>
+        ) score,
         a.is_prohibit isProhibit
         FROM
         xzx_account_info a
@@ -295,13 +319,6 @@
             and a.is_head = 1
             <if test="record.queryCol != null and record.queryCol != ''">
                 and (b.nick_name like concat('%',#{record.name},'%') or b.mobile_phone like concat('%',#{record.phone},'%'))
-            </if>
-            <if test="record.reserveTimeStart != null">
-                and b.regist_time >= #{record.reserveTimeStart}
-            </if>
-
-            <if test="record.reserveTimeEnd != null">
-                and b.regist_time &lt;= #{record.reserveTimeEnd}
             </if>
         </where>
         order by id desc
@@ -314,7 +331,8 @@
             xzx_jhy_order_items a
                  left join xzx_sys_environmental_info b on a.item_type = b.id
         WHERE
-            b.item_unit = 'kg' and a.order_id in (
+            b.item_unit = 'kg'
+        and a.order_id in (
                 SELECT
                     id
                 FROM
@@ -335,6 +353,15 @@
                                     account_id =  #{accountId}
                             )
                     )
+        <if test="record!= null">
+            <if test="record.reserveTimeStart != null">
+                and CREATED_TIME >= #{record.reserveTimeStart}
+            </if>
+
+            <if test="record.reserveTimeEnd != null">
+                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+            </if>
+        </if>
             )
     </select>
 
@@ -351,8 +378,7 @@
                     id
                 FROM
                     xzx_jhy_order
-                WHERE
-                        order_no in (
+                WHERE order_no in (
                         SELECT
                             order_no
                         FROM
@@ -367,6 +393,16 @@
                                     account_id = #{accountId}
                             )
                     )
+
+        <if test="record!= null">
+            <if test="record.reserveTimeStart != null">
+                and CREATED_TIME >= #{record.reserveTimeStart}
+            </if>
+
+            <if test="record.reserveTimeEnd != null">
+                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+            </if>
+        </if>
             )
     </select>
 
@@ -391,9 +427,30 @@
     b.regist_time registTime,
     a.is_head isHead,
     (select IFNULL(count(1), 0) from xzx_user_head_relate where head_user_id = a.user_id) cnt,
-    (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id) orderCnt,
-    (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id) amount,
-    (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id ) score,
+    (select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>) orderCnt,
+    (select IFNULL(sum(amount), 0) from xzx_user_head_relate where head_user_id = a.user_id
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>) amount,
+    (select IFNULL(sum(score), 0) from xzx_user_head_relate where head_user_id = a.user_id
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>) score,
     a.is_prohibit isProhibit
     FROM
     xzx_account_info a
@@ -404,15 +461,90 @@
         <if test="record.queryCol != null and record.queryCol != ''">
             and (b.nick_name like concat('%',#{record.name},'%') or b.mobile_phone like concat('%',#{record.phone},'%'))
         </if>
-        <if test="record.reserveTimeStart != null">
-            and b.regist_time >= #{record.reserveTimeStart}
-        </if>
-
-        <if test="record.reserveTimeEnd != null">
-            and b.regist_time &lt;= #{record.reserveTimeEnd}
-        </if>
     </where>
     order by id desc
 </select>
 
+    <select id="selectOrderExportByHeadUserId" resultType="java.lang.String">
+    SELECT
+    IFNULL(SUM(a.weight),0) as kg
+    FROM
+    xzx_jhy_order_items a
+    left join xzx_sys_environmental_info b on a.item_type = b.id
+    WHERE
+    b.item_unit = 'kg'
+    and a.order_id in (
+    SELECT
+    id
+    FROM
+    xzx_jhy_order
+    WHERE
+    order_no in (
+    SELECT
+    order_no
+    FROM
+    xzx_user_head_details
+    WHERE
+    head_user_id = (
+    SELECT
+    user_id
+    FROM
+    xzx_account_info
+    WHERE
+    account_id =  #{accountId}
+    )
+    )
+    <if test="record!= null">
+        <if test="record.reserveTimeStart != null">
+            and CREATED_TIME >= #{record.reserveTimeStart}
+        </if>
+
+        <if test="record.reserveTimeEnd != null">
+            and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+        </if>
+    </if>
+    )
+</select>
+
+    <select id="selectJDSLExportByHeadUserId" resultType="java.lang.String">
+        SELECT
+        IFNULL(SUM(a.weight),0) as jdsl
+        FROM
+        xzx_jhy_order_items a
+        left join xzx_sys_environmental_info b on a.item_type = b.id
+        WHERE
+        b.item_unit = '台' and
+        a.order_id in (
+        SELECT
+        id
+        FROM
+        xzx_jhy_order
+        WHERE order_no in (
+        SELECT
+        order_no
+        FROM
+        xzx_user_head_details
+        WHERE
+        head_user_id = (
+        SELECT
+        user_id
+        FROM
+        xzx_account_info
+        WHERE
+        account_id = #{accountId}
+        )
+        )
+
+        <if test="record!= null">
+            <if test="record.reserveTimeStart != null">
+                and CREATED_TIME >= #{record.reserveTimeStart}
+            </if>
+
+            <if test="record.reserveTimeEnd != null">
+                and CREATED_TIME &lt;= #{record.reserveTimeEnd}
+            </if>
+        </if>
+        )
+    </select>
+
 </mapper>

--
Gitblit v1.9.1