WeUserMapper.xml 12.6 KB
Newer Older
1 2 3 4 5 6 7 8
<?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.linkwechat.wecom.mapper.WeUserMapper">
    
    <resultMap type="WeUser" id="WeUserResult">
        <result property="id"    column="id"    />
9 10
        <result property="avatarMediaid"    column="head_image_url"    />
        <result property="name"    column="user_name"    />
11 12 13 14 15 16
        <result property="alias"    column="alias"    />
        <result property="userId"    column="user_id"    />
        <result property="gender"    column="gender"    />
        <result property="mobile"    column="mobile"    />
        <result property="email"    column="email"    />
        <result property="wxAccount"    column="wx_account"    />
17
        <result property="department"    column="department"  typeHandler="com.linkwechat.framework.handler.StringArrayJoinTypeHandler" />
18
        <result property="position"    column="position"    />
19
        <result property="isLeaderInDept"    column="is_leader_in_dept"  typeHandler="com.linkwechat.framework.handler.StringArrayJoinTypeHandler"  />
20 21 22 23 24 25 26
        <result property="joinTime"    column="join_time"    />
        <result property="idCard"    column="id_card"    />
        <result property="qqAccount"    column="qq_account"    />
        <result property="telephone"    column="telephone"    />
        <result property="address"    column="address"    />
        <result property="birthday"    column="birthday"    />
        <result property="remark"    column="remark"    />
水库浪子 已提交
27
        <result property="isActivate" column="is_activate"/>
28 29 30
    </resultMap>

    <sql id="selectWeUserVo">
水库浪子 已提交
31
        select is_activate,head_image_url as avatarMediaid, user_name, alias, user_id, gender, mobile, email, wx_account, department, position, is_leader_in_dept, join_time, enable, id_card, qq_account, telephone, address, birthday, remark from we_user
32 33 34 35
    </sql>

    <select id="selectWeUserList" parameterType="WeUser" resultMap="WeUserResult">
        <include refid="selectWeUserVo"/>
水库浪子 已提交
36 37
        WHERE
            is_activate !=6
38 39
            <if test="avatarMediaid != null  and avatarMediaid != ''"> and head_image_url = #{avatarMediaid}</if>
            <if test="name != null  and name != ''"> and user_name like concat('%', #{name}, '%')</if>
40 41 42 43 44 45
            <if test="alias != null  and alias != ''"> and alias = #{alias}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="gender != null "> and gender = #{gender}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="email != null  and email != ''"> and email = #{email}</if>
            <if test="wxAccount != null  and wxAccount != ''"> and wx_account = #{wxAccount}</if>
水库浪子 已提交
46
            <if test="department != null  and department.length > 0  "> and FIND_IN_SET(#{department},department)</if>
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
            <if test="position != null  and position != ''"> and position = #{position}</if>
            <if test="isLeaderInDept != null "> and is_leader_in_dept = #{isLeaderInDept}</if>
            <if test="joinTime != null "> and join_time = #{joinTime}</if>
            <if test="idCard != null  and idCard != ''"> and id_card = #{idCard}</if>
            <if test="qqAccount != null  and qqAccount != ''"> and qq_account = #{qqAccount}</if>
            <if test="telephone != null  and telephone != ''"> and telephone = #{telephone}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="birthday != null "> and birthday = #{birthday}</if>
    </select>
    
    <select id="selectWeUserById" parameterType="Long" resultMap="WeUserResult">
        <include refid="selectWeUserVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertWeUser" parameterType="WeUser">
        insert into we_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
66 67
            <if test="avatarMediaid != null">head_image_url,</if>
            <if test="name != null">user_name,</if>
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            <if test="alias != null">alias,</if>
            <if test="userId != null">user_id,</if>
            <if test="gender != null">gender,</if>
            <if test="mobile != null and mobile != ''">mobile,</if>
            <if test="email != null">email,</if>
            <if test="wxAccount != null">wx_account,</if>
            <if test="department != null">department,</if>
            <if test="position != null">position,</if>
            <if test="isLeaderInDept != null">is_leader_in_dept,</if>
            <if test="joinTime != null">join_time,</if>
            <if test="enable != null">enable,</if>
            <if test="idCard != null">id_card,</if>
            <if test="qqAccount != null">qq_account,</if>
            <if test="telephone != null">telephone,</if>
            <if test="address != null">address,</if>
            <if test="birthday != null">birthday,</if>
            <if test="remark != null">remark,</if>
            <if test="isActivate != null">is_activate,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
89 90
            <if test="avatarMediaid != null">#{avatarMediaid},</if>
            <if test="name != null">#{name},</if>
91 92 93 94 95 96
            <if test="alias != null">#{alias},</if>
            <if test="userId != null">#{userId},</if>
            <if test="gender != null">#{gender},</if>
            <if test="mobile != null and mobile != ''">#{mobile},</if>
            <if test="email != null">#{email},</if>
            <if test="wxAccount != null">#{wxAccount},</if>
97
            <if test="department != null" >#{department,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.StringArrayJoinTypeHandler},</if>
98
            <if test="position != null">#{position},</if>
99
            <if test="isLeaderInDept != null">#{isLeaderInDept,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.StringArrayJoinTypeHandler},</if>
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
            <if test="joinTime != null">#{joinTime},</if>
            <if test="enable != null">#{enable},</if>
            <if test="idCard != null">#{idCard},</if>
            <if test="qqAccount != null">#{qqAccount},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="address != null">#{address},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isActivate != null">#{isActivate},</if>
         </trim>
    </insert>

    <update id="updateWeUser" parameterType="WeUser">
        update we_user
        <trim prefix="SET" suffixOverrides=",">
115 116
            <if test="avatarMediaid != null">head_image_url = #{avatarMediaid},</if>
            <if test="name != null">user_name = #{name},</if>
117 118 119 120 121 122
            <if test="alias != null">alias = #{alias},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="mobile != null and mobile != ''">mobile = #{mobile},</if>
            <if test="email != null">email = #{email},</if>
            <if test="wxAccount != null">wx_account = #{wxAccount},</if>
H
HaoN 已提交
123
            <if test="department != null">department = #{department,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.StringArrayJoinTypeHandler},</if>
124
            <if test="position != null">position = #{position},</if>
H
HaoN 已提交
125
            <if test="isLeaderInDept != null">is_leader_in_dept = #{isLeaderInDept,jdbcType=OTHER,typeHandler=com.linkwechat.framework.handler.StringArrayJoinTypeHandler},</if>
126 127 128 129 130 131 132 133 134 135 136 137 138 139
            <if test="joinTime != null">join_time = #{joinTime},</if>
            <if test="enable != null">enable = #{enable},</if>
            <if test="idCard != null">id_card = #{idCard},</if>
            <if test="qqAccount != null">qq_account = #{qqAccount},</if>
            <if test="telephone != null">telephone = #{telephone},</if>
            <if test="address != null">address = #{address},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isActivate != null">is_activate = #{isActivate},</if>
        </trim>
        where id = #{id}
    </update>


140 141


水库浪子 已提交
142
    <select id="leaveNoAllocateUserList" parameterType="WeLeaveUserVo" resultType="com.linkwechat.wecom.domain.vo.WeLeaveUserVo">
1
13003003657 已提交
143
        SELECT
144 145 146 147 148 149
            wu.user_id,
            wu.user_name,
            wu.dimission_time,
            (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
            (SELECT COUNT(*) FROM we_flower_customer_rel  wfcr WHERE wfcr.user_id=wu.user_id) as allocateCustomerNum,
            (SELECT COUNT(*) FROM we_group wg WHERE wg.`owner`=wu.user_id) as allocateGroupNum
1
13003003657 已提交
150
        FROM
151
        we_user wu
1
13003003657 已提交
152
        <where>
153
            <if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
1
13003003657 已提交
154
            <if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
155
                DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime}  AND #{endTime}
1
13003003657 已提交
156
            </if>
157 158
            <if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
            <if test="isAllocate != null ">and  wu.is_allocate = #{isAllocate}</if>
1
13003003657 已提交
159 160 161 162
        </where>
    </select>


水库浪子 已提交
163 164 165 166
    <select id="leaveAllocateUserList" parameterType="WeLeaveUserVo" resultType="com.linkwechat.wecom.domain.vo.WeLeaveUserVo">
        SELECT
            wu.user_id,
            wu.user_name,
水库浪子 已提交
167
            wu.dimission_time,
水库浪子 已提交
168 169
            (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
            (SELECT COUNT(*) FROM we_allocate_customer wac WHERE wac.handover_userid=wu.user_id) as allocateCustomerNum,
水库浪子 已提交
170 171
            (SELECT COUNT(*) FROM we_allocate_group wag WHERE wag.old_owner=wu.user_id) as allocateGroupNum
        FROM we_user wu
水库浪子 已提交
172 173 174 175 176 177 178 179 180 181 182
        <where>
            <if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
            <if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
                DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime}  AND #{endTime}
            </if>
            <if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
            <if test="isAllocate != null ">and  wu.is_allocate = #{isAllocate}</if>
        </where>
    </select>


183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
    <delete id="deleteWeUser">
        delete from we_user
    </delete>


    <insert id="batchInsertWeUser" >
        insert into we_user (id, head_image_url, user_name, alias,
                             user_id, gender, mobile, email, wx_account,
                             department, position, is_leader_in_dept,
                             join_time, enable, id_card,
                             qq_account, telephone, address,
                             birthday, remark, is_activate)
        values
        <foreach collection="weUsers" item="weUser" index="index" separator=",">
            (   #{weUser.id},#{weUser.avatarMediaid},#{weUser.name},#{weUser.alias},
                #{weUser.userId},#{weUser.gender},#{weUser.mobile},#{weUser.email},#{weUser.wxAccount},
                #{weUser.department},#{weUser.position},#{weUser.isLeaderInDept},
                #{weUser.joinTime},#{weUser.enable},#{weUser.idCard},
                #{weUser.qqAccount},#{weUser.telephone},#{weUser.address},
                #{weUser.birthday},#{weUser.remark},#{weUser.isActivate}
            )
        </foreach>
        on duplicate key update head_image_url= values(head_image_url),
        id=values(id),
        user_name= values(user_name),alias= values(alias),
        mobile= values(mobile),email= values(email),
        wx_account= values(wx_account),department= values(department),
        position= values(position),is_leader_in_dept= values(is_leader_in_dept),
        join_time= values(join_time),enable= values(enable),
        id_card= values(id_card),qq_account= values(qq_account),
        telephone= values(telephone),address= values(address),
        birthday= values(birthday),remark= values(remark),
        is_activate= values(is_activate)
    </insert>



水库浪子 已提交
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
<!--    <select id="getAllocateCustomers">-->
<!--         SELECT-->
<!--	wc.`name`,-->
<!--  wu.user_name,-->
<!--  wac.allocate_time,-->
<!--  (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department-->
<!--FROM-->
<!--	we_allocate_customer wac-->
<!--LEFT JOIN we_customer wc ON wac.external_userid=wc.external_userid-->
<!--LEFT JOIN we_user wu ON wu.user_id=wac.takeover_userid-->
<!--        -->
<!--    </select>-->



235

1
13003003657 已提交
236 237 238



水库浪子 已提交
239 240 241 242 243 244 245







246
</mapper>