xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.modular.system.dao.TUserMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TUser">
        <id column="id" property="id" />
        <result column="companyId" property="companyId" />
        <result column="registIp" property="registIp" />
        <result column="registAreaCode" property="registAreaCode" />
        <result column="phone" property="phone" />
        <result column="nickName" property="nickName" />
        <result column="avatar" property="avatar" />
        <result column="birthday" property="birthday" />
        <result column="sex" property="sex" />
        <result column="emergencyContact" property="emergencyContact" />
        <result column="emergencyContactNumber" property="emergencyContactNumber" />
        <result column="isAuth" property="isAuth" />
        <result column="name" property="name" />
        <result column="idCard" property="idCard" />
        <result column="idCardFront" property="idCardFront" />
        <result column="idCardReverse" property="idCardReverse" />
        <result column="consumption" property="consumption" />
        <result column="balance" property="balance" />
        <result column="integral" property="integral" />
        <result column="passWord" property="passWord" />
        <result column="openId" property="openId" />
        <result column="unionid" property="unionid" />
        <result column="remark" property="remark" />
        <result column="state" property="state" />
        <result column="flag" property="flag" />
        <result column="insertTime" property="insertTime" />
        <result column="insertUser" property="insertUser" />
        <result column="updateTime" property="updateTime" />
        <result column="updateUser" property="updateUser" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, companyId, registIp, registAreaCode, phone, nickName, avatar, birthday, sex, emergencyContact, emergencyContactNumber, isAuth, name, idCard, idCardFront, idCardReverse, consumption, balance, integral, passWord, openId, unionid, remark, state, flag, insertTime, insertUser, updateTime, updateUser
    </sql>
 
    <!--根据条件查询用户列表-->
    <select id="getUserList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT ci.`name` as companyName,IFNULL(ot.num,0) as historyNum,IFNULL(td.num,0) as consumptionNum,ui.* from t_user as ui
        LEFT JOIN (select * from t_company where flag != 3) as ci on ci.id = ui.companyId
        LEFT JOIN (SELECT
        COUNT( oi.id ) AS num,
        oi.userId
        FROM
        (SELECT id,userId,state from
        t_order_taxi WHERE isDelete = 1
        UNION all
        SELECT id,userId,state from t_order_private_car WHERE isDelete = 1
        ) oi
        WHERE
        FIND_IN_SET( oi.state, '8,9' )
        GROUP BY oi.userId) as ot on ot.userId = ui.id
        LEFT JOIN (SELECT sum(money) as num,userId from t_pub_transaction_details where userType = 1 and type = 1 and state = 2 GROUP BY userId) as td on td.userId = ui.id
        ) as o
        <where>
            o.flag != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="isAuth != null and isAuth != ''">
                and o.isAuth = #{isAuth}
            </if>
            <if test="state != null and state != ''">
                and o.state = #{state}
            </if>
            <if test="id != null and id != ''">
                and o.id  LIKE CONCAT('%',#{id},'%')
            </if>
            <if test="nickName != null and nickName != ''">
                and o.nickName  LIKE CONCAT('%',#{nickName},'%')
            </if>
            <if test="phone != null and phone != ''">
                and o.phone  LIKE CONCAT('%',#{phone},'%')
            </if>
            <if test="companyName != null and companyName != ''">
                and o.companyName  LIKE CONCAT('%',#{companyName},'%')
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{nowUserId} or FIND_IN_SET(o.companyId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{nowUserId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.companyId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
    <select id="getUserListCoupon" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT ci.`name` as companyName,IFNULL(ot.num,0) as historyNum,IFNULL(td.num,0) as consumptionNum,ui.* from t_user as ui
        LEFT JOIN (select * from t_company where flag != 3) as ci on ci.id = ui.companyId
        LEFT JOIN (SELECT COUNT(id) as num,userId from t_order_taxi where FIND_IN_SET(state,'8,9') GROUP BY userId) as ot on ot.userId = ui.id
        LEFT JOIN (SELECT sum(money) as num,userId from t_pub_transaction_details where userType = 1 and type = 1 and state = 2 GROUP BY userId) as td on td.userId = ui.id
        ) as o
        <where>
            o.flag != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="isAuth != null and isAuth != ''">
                and o.isAuth = #{isAuth}
            </if>
            <if test="state != null and state != ''">
                and o.state = #{state}
            </if>
            <if test="id != null and id != ''">
                and o.id  LIKE CONCAT('%',#{id},'%')
            </if>
            <if test="nickName != null and nickName != ''">
                and o.nickName  LIKE CONCAT('%',#{nickName},'%')
            </if>
            <if test="phone != null and phone != ''">
                and o.phone  LIKE CONCAT('%',#{phone},'%')
            </if>
            <if test="companyName != null and companyName != ''">
                and o.companyName  LIKE CONCAT('%',#{companyName},'%')
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--根据用户ID获取用户详情-->
    <select id="getUserDetailById" resultType="java.util.Map">
        SELECT DATE_FORMAT(ui.insertTime,'%Y-%m-%d %H:%i') as insertTimeStr,ci.`name` as companyName,
        case when ui.isAuth = 1 then '否' else '是' end as isAuthStr,
        IFNULL(0,0) as zcNum,
        IFNULL(ot.num,0) as czNum,
        IFNULL(0,0) as kcNum,
        IFNULL(0,0) as wlNum,
        IFNULL(td.num,0) as consumptionNum,
        IFNULL(ui.balance,0) as balanceStr,
        ui.* from t_user as ui
        LEFT JOIN (select * from t_company where flag != 3) as ci on ci.id = ui.companyId
        LEFT JOIN (SELECT sum(money) as num,userId from t_pub_transaction_details where userType = 1 and type = 1 and state = 2 GROUP BY userId) as td on td.userId = ui.id
        LEFT JOIN (SELECT COUNT(id) as num,userId from t_order_taxi where FIND_IN_SET(state,'8,9') GROUP BY userId) as ot on ot.userId = ui.id
        where ui.id = #{userId}
    </select>
 
    <!--根据条件查询用户列表-无分页-->
    <select id="getUserListNoPage" resultType="map" >
        SELECT * FROM (SELECT ci.`name` as companyName,IFNULL(ot.num,0) as historyNum,IFNULL(td.num,0) as consumptionNum,ui.* from t_user as ui
        LEFT JOIN (select * from t_company where flag != 3) as ci on ci.id = ui.companyId
        LEFT JOIN (SELECT COUNT(id) as num,userId from t_order_taxi where FIND_IN_SET(state,'8,9') GROUP BY userId) as ot on ot.userId = ui.id
        LEFT JOIN (SELECT sum(money) as num,userId from t_pub_transaction_details where userType = 1 and type = 1 and state = 2 GROUP BY userId) as td on td.userId = ui.id
        ) as o
        <where>
            o.flag != 3
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{nowUserId} or FIND_IN_SET(o.companyId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{nowUserId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.companyId = #{nowUserId}
            </if>
        </where>
        order by o.id desc
    </select>
 
 
</mapper>