WeUserMapper.xml 11.1 KB
Newer Older
1 2
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
孙喜旺 已提交
3 4
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
5
<mapper namespace="com.linkwechat.wecom.mapper.WeUserMapper">
孙喜旺 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

    <resultMap type="com.linkwechat.wecom.domain.WeUser" id="WeUserResult">
        <result property="id" column="id"/>
        <result property="corpId" column="corp_id"/>
        <result property="headImageUrl" column="head_image_url"/>
        <result property="name" column="user_name"/>
        <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"/>
        <result property="department" column="department"/>
        <result property="position" column="position"/>
        <result property="isLeaderInDept" column="is_leader_in_dept"/>
        <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"/>
水库浪子 已提交
28
        <result property="isActivate" column="is_activate"/>
孙喜旺 已提交
29 30 31 32 33
        <result property="isOpenChat" column="is_open_chat"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
34 35 36
    </resultMap>

    <sql id="selectWeUserVo">
孙喜旺 已提交
37 38 39 40 41
        select id,corp_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,
        is_open_chat,create_by,update_by,create_time,update_time from we_user
42 43
    </sql>

孙喜旺 已提交
44
    <select id="getList" parameterType="WeUser" resultMap="WeUserResult">
45
        <include refid="selectWeUserVo"/>
孙喜旺 已提交
46
        <where>
孙喜旺 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59
            <if test="id != null">and id = #{id}</if>
            <if test="name != null  and name != ''">and user_name like concat('%', #{name}, '%')</if>
            <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>
            <if test="department != null  and department != ''  ">and FIND_IN_SET(#{department},department)</if>
            <if test="position != null  and position != ''">and position = #{position}</if>
            <if test="isLeaderInDept != null ">and is_leader_in_dept = #{isLeaderInDept}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(join_time,'%Y-%m-%d') &gt;= date_format(#{beginTime},'%Y-%m-%d')
水库浪子 已提交
60
            </if>
孙喜旺 已提交
61 62 63 64 65 66 67 68 69 70 71 72
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(join_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
            </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>
            <if test="birthday != null ">and birthday = #{birthday}</if>
            <if test="corpId != null ">and corp_id = #{corpId}</if>
            <if test="isActivate != null ">and is_activate = #{isActivate}</if>
            <if test="isOpenChat != null ">and is_open_chat = #{isOpenChat}</if>
水库浪子 已提交
73 74

            <if test="neWeUserId != null and neWeUserId !=''">and user_id != #{neWeUserId}</if>
水库浪子 已提交
75 76 77
        </where>
    </select>

78
    <insert id="insertBatch">
孙喜旺 已提交
79
        insert into we_user (head_image_url, user_name, alias,
孙喜旺 已提交
80 81 82 83 84
        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,create_by,update_by,create_time,update_time)
85
        values
孙喜旺 已提交
86 87 88 89 90 91 92 93 94
        <foreach collection="weUserList" item="weUser" index="index" separator=",">
            (
            #{weUser.headImageUrl},#{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}
            ,#{weUser.createBy},#{weUser.updateBy},#{weUser.createTime},#{weUser.updateTime}
95 96 97 98 99 100 101 102 103 104 105
            )
        </foreach>
        on duplicate key update head_image_url= values(head_image_url),
        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),
孙喜旺 已提交
106 107 108
        is_activate= values(is_activate),
        update_by= values(update_by),
        update_time= values(update_time)
109 110 111
    </insert>


孙喜旺 已提交
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
    <select id="leaveNoAllocateUserList" parameterType="WeLeaveUserVo"
            resultType="com.linkwechat.wecom.domain.vo.WeLeaveUserVo">
        SELECT
        *
        FROM
        (
        SELECT
        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
        FROM
        we_user wu
        <where>
            <if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(wu.dimission_time,'%Y-%m-%d') &gt;= date_format(#{beginTime},'%Y-%m-%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(wu.dimission_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
            </if>
            <if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
            <if test="isAllocate != null ">and wu.is_allocate = #{isAllocate}</if>
        </where>
        )wuu WHERE allocateCustomerNum >0 and allocateGroupNum>0
    </select>


    <select id="leaveAllocateUserList" parameterType="WeLeaveUserVo"
            resultType="com.linkwechat.wecom.domain.vo.WeLeaveUserVo">
        SELECT
        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_allocate_customer wac WHERE wac.handover_userid=wu.user_id) as allocateCustomerNum,
        (SELECT COUNT(*) FROM we_allocate_group wag WHERE wag.old_owner=wu.user_id) as allocateGroupNum
        FROM we_user wu
        <where>
            <if test="userName != null and userName !=''">and wu.user_name=#{userName}</if>
            <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
                AND date_format(wu.dimission_time,'%Y-%m-%d') &gt;= date_format(#{beginTime},'%Y-%m-%d')
            </if>
            <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
                AND date_format(wu.dimission_time,'%Y-%m-%d') &lt;= date_format(#{endTime},'%Y-%m-%d')
            </if>
            <if test="isActivate != null ">and wu.is_activate = #{isActivate}</if>
            <if test="isAllocate != null ">and wu.is_allocate = #{isAllocate}</if>
        </where>
    </select>
164

孙喜旺 已提交
165 166 167 168 169 170 171
    <select id="getAllocateCustomers" parameterType="WeAllocateCustomersVo"
            resultType="com.linkwechat.wecom.domain.vo.WeAllocateCustomersVo">
        SELECT
        wc.`name` as customerName,
        wu.user_name as takeUserName,
        wac.allocate_time,
        (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department
水库浪子 已提交
172
        FROM
孙喜旺 已提交
173
        we_allocate_customer wac
水库浪子 已提交
174 175 176 177 178
        LEFT JOIN we_customer wc ON wac.external_userid=wc.external_userid
        LEFT JOIN we_user wu ON wu.user_id=wac.takeover_userid
        <where>
            <if test="handoverUserId != null and handoverUserId !=''">and wac.handover_userid=#{handoverUserId}</if>
            <if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
孙喜旺 已提交
179
                DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
水库浪子 已提交
180 181 182 183 184
            </if>
        </where>
    </select>


孙喜旺 已提交
185 186 187 188 189 190 191 192 193
    <select id="getAllocateGroups" parameterType="WeAllocateGroupsVo"
            resultType="com.linkwechat.wecom.domain.vo.WeAllocateGroupsVo">
        SELECT
        wu.user_name as newOwnerName,
        wg.chat_id,
        wg.group_name,
        (SELECT count(*) FROM we_group_member wgm WHERE wgm.chat_id=wg.chat_id) as memberNum,
        (SELECT GROUP_CONCAT(wd.`name`) FROM we_department wd WHERE wd.id=wu.department) as department,
        wag.allocate_time
水库浪子 已提交
194
        FROM
孙喜旺 已提交
195
        we_allocate_group wag
水库浪子 已提交
196 197 198 199 200
        LEFT JOIN we_group wg ON wag.chat_id=wg.chat_id
        LEFT JOIN we_user wu ON wu.user_id=wag.new_owner
        <where>
            <if test="oldOwner != null and oldOwner !=''">and wag.old_owner=#{oldOwner}</if>
            <if test="beginTime != null and beginTime !='' and endTime != null and endTime !=''">
孙喜旺 已提交
201
                DATE_FORMAT(wu.dimission_time,'%Y-%m-%d') BETWEEN #{beginTime} AND #{endTime}
水库浪子 已提交
202 203 204 205
            </if>
        </where>

    </select>
水库浪子 已提交
206 207


208 209 210 211 212 213 214 215
    <select id="findWeUserByCutomerId" resultType="com.linkwechat.wecom.domain.WeCustomerAddUser">
            SELECT
                wu.user_name,
                wu.user_id,
                wu.head_image_url,
                wfcr.create_time
            FROM
                `we_flower_customer_rel` wfcr
216
            INNER JOIN we_user wu ON wfcr.user_id = wu.user_id
217 218 219
            WHERE wfcr.external_userid=#{externalUserid}
    </select>

1
13003003657 已提交
220

221
</mapper>