From f54f8a92c09a2cd76b3bbb796df680215b63ab8a Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 21 Feb 2022 14:16:41 +0800
Subject: [PATCH] fix 50 to 40

---
 gc-user/src/main/resources/mapper/user/AccountMapper.xml |  394 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 393 insertions(+), 1 deletions(-)

diff --git a/gc-user/src/main/resources/mapper/user/AccountMapper.xml b/gc-user/src/main/resources/mapper/user/AccountMapper.xml
index 14f9d3d..a417c05 100644
--- a/gc-user/src/main/resources/mapper/user/AccountMapper.xml
+++ b/gc-user/src/main/resources/mapper/user/AccountMapper.xml
@@ -161,10 +161,402 @@
             1=1
             <if test="record.queryCol != null and record.queryCol != ''">
                 and (b.nick_name like concat('%',#{record.name},'%')
-                or mobile_phone like concat('%',#{record.phone},'%') )
+                or b.mobile_phone like concat('%',#{record.phone},'%') )
             </if>
         </where>
         order by id desc
     </select>
 
+    <select id="selectDsitribInfoListByQueryCol" resultType="com.xzx.gc.user.vo.DistribInfoListVo">
+        SELECT
+        a.account_id id,
+        b.nick_name nickname,
+        b.mobile_phone phone,
+        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,
+        a.is_prohibit isProhibit
+        FROM
+        xzx_account_info a
+        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
+        <where>
+            1=1
+            and a.is_head = 1
+            <if test="record.name != null and record.name != ''">
+                and b.nick_name like concat('%',#{record.name},'%')
+            </if>
+            <if test="record.phone != null and record.phone != ''">
+                and b.mobile_phone like concat('%',#{record.phone},'%')
+            </if>
+            <if test="record.isProhibit != null and record.isProhibit != ''">
+                and  a.is_prohibit = #{record.isProhibit}
+            </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="selectDistribByAccountId" resultType="com.xzx.gc.user.vo.ViewDistribInfoVo">
+        SELECT
+        a.account_id id,
+        b.nick_name nickname,
+        b.mobile_phone phone,
+        b.regist_time registTime,
+        (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
+        FROM
+        xzx_account_info a
+        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
+        where a.account_id = #{id}
+    </select>
+
+    <select id="selectUserHeadInfoByAccountId" resultType="com.xzx.gc.user.vo.UserHeadInfoVo">
+        SELECT
+            b.nick_name nickname,
+            b.mobile_phone phone,
+            a.CREATED_TIME createTime,
+            (select IFNULL(count(1), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) orderCnt,
+            (select IFNULL(sum(amount), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) amount,
+            (select IFNULL(sum(score), 0) from xzx_user_head_details where user_id = a.user_id and head_user_id = #{id}) score,
+            (SELECT
+                IFNULL(SUM(score),0) as kg
+            FROM
+                xzx_jhy_order_items WHERE order_id in ( SELECT
+                        id
+                    FROM
+                        xzx_jhy_order WHERE order_no in ( SELECT
+                                order_no
+                            FROM
+                                xzx_user_head_details WHERE
+                                user_id = a.user_id and head_user_id = #{id} ) )) orderScore
+        FROM
+            xzx_user_head_relate a
+                LEFT JOIN xzx_user_info b on a.user_id = b.user_id
+        where a.head_user_id = #{id}
+    </select>
+
+    <select id="selectOrderItemsByUserId" resultType="com.xzx.gc.user.vo.OrderItemsVo">
+        SELECT
+            b.id orderId,
+            a.order_no orderNo,
+            a.score scoreReward,
+            a.amount amountReward,
+            c.nick_name nickname,
+            c.mobile_phone phone,
+            (select sum(score) from xzx_jhy_order_items where b.id = order_id) score,
+            (select sum(score/ 40) from xzx_jhy_order_items where b.id = order_id) amount
+        FROM
+            xzx_user_head_details a
+                LEFT JOIN xzx_jhy_order b ON a.order_no = b.order_no
+                LEFT JOIN xzx_user_info c on a.user_id = c.user_id
+        WHERE
+            a.head_user_id = #{userId}
+        order by b.CREATED_TIME desc
+    </select>
+
+
+
+    <select id="selectOrderById" resultType="com.xzx.gc.entity.JhyOrderItems">
+        SELECT
+               *
+        FROM
+            xzx_jhy_order_items a
+        where a.order_id = #{orderId}
+    </select>
+
+    <select id="distribDataList" resultType="com.xzx.gc.user.vo.DistribDataListVo">
+        SELECT
+        a.account_id id,
+        b.nick_name nickname,
+        b.mobile_phone phone,
+        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
+            <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
+        LEFT JOIN xzx_user_info b on a.user_id = b.user_id
+        <where>
+            1=1
+            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>
+        </where>
+        order by id desc
+    </select>
+
+    <select id="selectOrderByHeadUserId" 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="selectJDSLByHeadUserId" 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>
+
+    <select id="selectDistribDataInfoVo" resultType="com.xzx.gc.user.vo.DistribDataInfoVo">
+        SELECT
+        IFNULL(count(1), 0) cnt,
+        SUM((select IFNULL(count(1), 0) from xzx_user_head_details where head_user_id = a.user_id) ) orderCnt,
+        SUM((select IFNULL(sum(amount), 0) from xzx_user_head_details where head_user_id = a.user_id) ) amount,
+        SUM((select IFNULL(sum(score), 0) from xzx_user_head_details where head_user_id = a.user_id) ) score
+        FROM
+        xzx_account_info a
+        where
+            1=1
+            and a.is_head = 1
+    </select>
+
+    <select id="distribDataExport" resultType="com.xzx.gc.user.vo.DistribDataListVo">
+    SELECT
+    a.account_id id,
+    b.nick_name nickname,
+    b.mobile_phone phone,
+    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
+        <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
+    LEFT JOIN xzx_user_info b on a.user_id = b.user_id
+    <where>
+        1=1
+        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>
+    </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>
+
+    <select id="selectAccountInfoByIds" resultType="com.xzx.gc.entity.AccountInfo">
+        select * from xzx_account_info
+        where account_id in
+        <foreach collection="list" index="index" item="id" separator="," open="(" close=")">
+            #{id}
+        </foreach>
+    </select>
+
+    <select id="selectAccountInfoByPhone" resultType="com.xzx.gc.entity.AccountInfo">
+        select a.* from xzx_account_info a, xzx_user_info b
+        where a.user_id=b.user_id and b.mobile_phone=#{phone}
+    </select>
 </mapper>

--
Gitblit v1.9.1