WorkUserMapper.xml 6.75 KB
Newer Older
nie'hong's avatar
nie'hong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
<?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="cn.wisenergy.mapper.WorkUserMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="cn.wisenergy.model.app.WorkUser">
        <id column="id" property="id" />
        <result column="oa_user_id" property="oaUserId" />
        <result column="dept_id" property="deptId" />
        <result column="name" property="name" />
        <result column="login_name" property="loginName" />
        <result column="password" property="password" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="role" property="role" />
        <result column="type" property="type" />
        <result column="status" property="status" />
        <result column="wx_id" property="wxId" />
cq990612's avatar
cq990612 committed
19
        <result column="submit_order" property="submitOrder"/>
nie'hong's avatar
nie'hong committed
20 21 22 23
        <result column="create_time" property="createTime" />
        <result column="modify_time" property="modifyTime" />
    </resultMap>

cq990612's avatar
cq990612 committed
24

cq990612's avatar
cq990612 committed
25

nie'hong's avatar
nie'hong committed
26 27 28 29 30 31 32 33 34 35
    <sql id="table">
        work_user
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
cq990612's avatar
cq990612 committed
36
        name, oa_user_id, login_name, phone, dept_id, email, role ,type,status,wx_id,submit_order,create_time,modify_time
nie'hong's avatar
nie'hong committed
37 38 39
    </sql>

    <sql id="values">
cq990612's avatar
cq990612 committed
40
        #{name},#{oaUserId},#{loginName},#{phone},#{deptId},#{email},#{role},#{type},#{status},#{wxId},#{submitOrder},now(),now()
nie'hong's avatar
nie'hong committed
41 42 43 44 45 46
    </sql>

    <sql id="updateCondition">
        <if test="name != null">name = #{name},</if>
        <if test="oaUserId != null">oa_user_id = #{oaUserId},</if>
        <if test="loginName != null">login_name = #{loginName},</if>
nie'hong's avatar
nie'hong committed
47
        <if test="password != null">password = #{password},</if>
nie'hong's avatar
nie'hong committed
48 49 50 51 52 53 54
        <if test="phone != null">phone =#{phone},</if>
        <if test="deptId != null">dept_id = #{deptId},</if>
        <if test="email != null">email = #{email},</if>
        <if test="role != null">role = #{role},</if>
        <if test="type != null">type =#{type},</if>
        <if test="status != null">status = #{status},</if>
        <if test="wxId != null">wx_id =#{wxId},</if>
cq990612's avatar
cq990612 committed
55
        <if test="submitOrder != null">submit_order = #{submitOrder},</if>
nie'hong's avatar
nie'hong committed
56 57 58 59 60 61 62 63
        modify_time =now()
    </sql>

    <sql id="criteria">
        <if test="id != null">and id = #{id}</if>
        <if test="oaUserId != null">and oa_user_id = #{oaUserId}</if>
        <if test="name != null">and name = #{name}</if>
        <if test="loginName != null">and login_name = #{loginName}</if>
nie'hong's avatar
nie'hong committed
64
        <if test="password != null">and password = #{password}</if>
nie'hong's avatar
nie'hong committed
65 66 67 68 69 70
        <if test="phone != null">and phone =#{phone}</if>
        <if test="deptId != null">and dept_id = #{deptId}</if>
        <if test="email != null">and email = #{email}</if>
        <if test="role != null">and role = #{role}</if>
        <if test="type != null">and type =#{type}</if>
        <if test="status != null">and status = #{status}</if>
cq990612's avatar
cq990612 committed
71 72
        <if test="wxId != null">and wx_id =#{wxId}</if>
        <if test="submitOrder != null">and submit_order = #{submitOrder}</if>
nie'hong's avatar
nie'hong committed
73 74 75 76 77 78 79 80 81 82 83 84
        <if test="createTime != null">and create_time &gt;= #{createTime}</if>
        <if test="modifyTime != null">and #{modifyTime} &gt;= modify_time</if>
    </sql>

    <select id="getUserInfo" resultMap="BaseResultMap" parameterType="map" >
        select <include refid="cols_all"/>
        from <include refid="table"/>
        <where>
            <include refid="criteria"/>
        </where>
    </select>

nie'hong's avatar
nie'hong committed
85
    <select id="getUserById" resultMap="BaseResultMap" parameterType="integer" >
nie'hong's avatar
nie'hong committed
86 87 88 89
        select <include refid="cols_all"/>
        from <include refid="table"/>
        where id = #{userId}
    </select>
nie'hong's avatar
nie'hong committed
90
    <select id="getStatisticsTableDtos" resultType="cn.wisenergy.model.dto.StatisticsTableDto">
nie'hong's avatar
nie'hong committed
91
        select u.id AS user_id, u.name AS user_name, d.dept_name
nie'hong's avatar
nie'hong committed
92 93 94 95 96 97
        from work_user u join work_dept d on u.dept_id=d.id
        where u.id in
        <foreach collection="list" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>
nie'hong's avatar
nie'hong committed
98

cq990612's avatar
cq990612 committed
99

nie'hong's avatar
nie'hong committed
100 101 102 103 104
    <update id="updateUserInfo" parameterType="cn.wisenergy.model.app.WorkUser">
        update <include refid="table"/>
        set <include refid="updateCondition"/>
        where id = #{id}
    </update>
cq990612's avatar
cq990612 committed
105
    <update id="updateStatusAndSubmitOrderById">
cq990612's avatar
cq990612 committed
106
        update <include refid="table"/>
cq990612's avatar
cq990612 committed
107 108 109 110 111 112 113 114
        <set>
            <if test="status !=null">
                status = #{status},
            </if>
            <if test="submitOrder !=null">
                submit_order = #{submitOrder}
            </if>
        </set>
cq990612's avatar
cq990612 committed
115 116
        where id = #{userId}
    </update>
nie'hong's avatar
nie'hong committed
117

cq990612's avatar
cq990612 committed
118

cq990612's avatar
cq990612 committed
119 120 121 122
    <resultMap id="UserRoleMap" type="cn.wisenergy.model.dto.UserRoleDto">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="status" property="status"/>
cq990612's avatar
cq990612 committed
123 124 125
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="submit_order" property="submitOrder"/>
cq990612's avatar
cq990612 committed
126
        <collection property="workRoles" column="id" javaType="List" select="getUserRole" ofType="cn.wisenergy.model.app.WorkRole"/>
cq990612's avatar
cq990612 committed
127

cq990612's avatar
cq990612 committed
128
    </resultMap>
cq990612's avatar
cq990612 committed
129 130

    <select id="getUserRoleDto" resultMap="UserRoleMap">
cq990612's avatar
cq990612 committed
131

cq990612's avatar
cq990612 committed
132
      select u.id as 'id',u.name as 'name',u.status as 'status',if(r.id is null,0,r.id) as 'role_id',r.name as 'role_name',d.id as 'dept_id',d.dept_name,u.submit_order
cq990612's avatar
cq990612 committed
133
from work_user u LEFT JOIN (select role_id,user_id FROM work_user_role GROUP BY user_id) ur ON u.id = ur.user_id
cq990612's avatar
cq990612 committed
134
LEFT JOIN work_dept d ON u.dept_id = d.id
cq990612's avatar
cq990612 committed
135
LEFT JOIN work_role r on ur.role_id = r.id
cq990612's avatar
cq990612 committed
136 137
        <where>
            <if test="null !=status">
cq990612's avatar
cq990612 committed
138 139
            AND  u.status = #{status}
            </if>
cq990612's avatar
cq990612 committed
140
            <if test="null !=key and ''!=key">
cq990612's avatar
cq990612 committed
141
            AND  u.name like concat('%',#{key},'%')
cq990612's avatar
cq990612 committed
142
            </if>
cq990612's avatar
cq990612 committed
143 144 145 146 147 148 149
            <if test="null != deptId">
            AND  u.dept_id = #{deptId}
            </if>
            <if test="null !=roleId and roleId != 0">
            AND  r.id = #{roleId}
            </if>
            <if test="null !=roleId and roleId == 0">
cq990612's avatar
cq990612 committed
150
            AND  r.id is null
cq990612's avatar
cq990612 committed
151
            </if>
cq990612's avatar
cq990612 committed
152
        </where>
cq990612's avatar
cq990612 committed
153 154
    </select>

cq990612's avatar
cq990612 committed
155 156 157 158 159 160 161
    <select id="getUserRole" resultType="cn.wisenergy.model.app.WorkRole">
      SELECT r.id ,r.name
      FROM  work_user_role ur LEFT JOIN work_role r
      ON ur.role_id = r.id
      WHERE ur.user_id = #{id}
    </select>

cq990612's avatar
cq990612 committed
162 163 164 165 166
    <select id="getUserSortByStatus" resultType="cn.wisenergy.model.app.WorkUser">
        select  <include refid="cols_all"/>
        from <include refid="table"/>
        <where>
            <if test="null != status">
cq990612's avatar
cq990612 committed
167
            AND    status = #{status}
cq990612's avatar
cq990612 committed
168 169 170 171 172
            </if>
        </where>
        ORDER BY CONVERT( `name` USING gbk )
    </select>

nie'hong's avatar
nie'hong committed
173
</mapper>