<?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.dsk.system.mapper.CustomerMapper">

    <sql id="Base_Bean">
        ct.customer_id, ct.company_id, ct.company_name, ct.legal_person, ct.credit_code,
        ct.register_capital, ct.company_nature, ct.company_level, ct.credit_level, ct.super_company,
        ct.is_on, ct.is_major, ct.company_attribute, ct.main_business, ct.business_scope,
        ct.business_characteristic, ct.decision_chain, ct.bid_characteristic, ct.performance_characteristic,
        ct.other_ms_characteistic, ct.create_id, ct.create_time, ct.update_id, ct.update_time
    </sql>

    <select id="selectList" resultType="com.dsk.system.domain.customer.vo.CustomerListVo">
        select
             u.nick_name followUser,
             <include refid="Base_Bean"></include>
        from customer ct
        join customer_user ctu on ct.customer_id = ctu.customer_id
        join sys_user u on ctu.user_id = u.user_id
        where ctu.user_id = #{dto.userId}
        <if test="dto.companyName != null and dto.companyName != '' "> and ct.company_name like concat('%',#{dto.companyName},'%')</if>
    </select>

    <select id="selectUserList" resultType="com.dsk.system.domain.customer.Customer">
        select
            ct.customer_id, ct.company_name
        from customer ct
        join customer_user ctu on ct.customer_id = ctu.customer_id
        where ctu.user_id = #{userId}
    </select>

    <select id="selectByCompanyIdAndUserId" resultType="com.dsk.system.domain.customer.Customer">
        select
        <include refid="Base_Bean"></include>
        from customer ct
        join customer_user ctu on ct.customer_id = ctu.customer_id
        where ct.company_id = ${companyId} and ctu.user_id = #{userId}
    </select>

</mapper>

