<?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.trade.admin.enterprise.customer.mapper.CustomerAssignMapper">

	<resultMap id="BaseResultMap" type="com.trade.admin.enterprise.customer.domain.CustomerAssign">
		<id column="bd_assign_status" property="bdAssignStatus" />
        <id column="rc_assign_status" property="rcAssignStatus" />
		<id column="bd_user_id" property="bdUserId" />
		<id column="bd_user_name" property="bdUserName" />
		<id column="customer_user_id" property="customerUserId" />
		<id column="gmt_create" property="gmtCreate" />
		<id column="gmt_modified" property="gmtModified" />
		<id column="id" property="id" />
		<id column="identifier_no" property="identifierNo" />
		<id column="rc_user_id" property="rcUserId" />
		<id column="rc_user_name" property="rcUserName" />
		<id column="remark" property="remark" />
        <id column="bd_assign_Way" property="bdAssignWay" />
        <id column="rc_assign_Way" property="rcAssignWay" />
        <id column="risk_time" property="riskTime" />
        <id column="bd_time" property="bdTime" />
	</resultMap>
	<sql id="Base_Column_List">
        bd_assign_status, rc_assign_status, bd_user_id, bd_user_name, customer_user_id, gmt_create, gmt_modified, id, identifier_no, rc_user_id, rc_user_name, remark,
        bd_assign_Way, rc_assign_Way, risk_time, bd_time
	</sql>

    <select id="findBySearch" parameterType="com.trade.admin.enterprise.customer.domain.SearchCustomerAssign" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"/>
        FROM  customer_assign
        <where>
            <if test="bdAssignStatus == null">
                AND bd_assign_status = #{bdAssignStatus}
            </if>
            <if test="rcAssignStatus == null">
                AND rc_assign_status = #{rcAssignStatus}
            </if>
            <if test="bdUserName != null and bdUserName !=''">
                AND (
                bd_user_name LIKE CONCAT( '%',#{bdUserName},'%' ) OR
                to_pinyin(bd_user_name) LIKE CONCAT( '%',#{bdUserName},'%')
                )
            </if>
            <if test="rcUserName != null and rcUserName !=''">
                AND (
                rc_user_name LIKE CONCAT( '%',#{rcUserName},'%' ) OR
                to_pinyin(rc_user_name) LIKE CONCAT( '%',#{rcUserName},'%')
                )
            </if>
        </where>
        ORDER BY assign_status ASC,
        gmt_create DESC
    </select>
    <select id="countByUserId" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM customer_assign
        WHERE bd_user_id = #{userId}
           OR rc_user_id = #{userId}
    </select>
</mapper>
