<?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.njzscloud.dispose.cst.customer.mapper.CustomerMapper">

    <sql id="searchCustomer">
        SELECT a.id,
               a.user_id,
               a.identity_category,
               a.org_id,
               a.customer_name,
               a.phone,
               a.settlement_way,
               a.manager,
               b.nickname,
               b.avatar,
               c.id account_id,
               c.username,
               c.wechat_openid,
               c.regdate,
               c.client_code,
               d.org_category,
               d.uscc,
               d.org_name,
               d.business_license,
               d.license_start_time,
               d.license_end_time,
               d.legal_representative,
               d.idcard,
               d.idcard_start_time,
               d.idcard_end_time,
               d.idcard_front,
               d.idcard_back,
               d.province,
               d.city,
               d.area,
               d.town,
               d.province_name,
               d.city_name,
               d.area_name,
               d.town_name,
               d.address,
               d.lng,
               d.lat
        FROM cst_customer a
                 INNER JOIN sys_user b ON b.id = a.user_id AND b.deleted = 0
                 INNER JOIN sys_user_account c ON c.user_id = b.id AND b.deleted = 0
                 INNER JOIN cst_org d ON d.id = a.org_id AND d.deleted = 0
    </sql>

    <resultMap id="searchCustomerResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.customer.pojo.result.SearchCustomerResult">
    </resultMap>

    <select id="paging" resultMap="searchCustomerResultMap">
        <include refid="searchCustomer"/>
        <if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
            ${ew.customSqlSegment}
        </if>
    </select>

    <select id="detail" resultMap="searchCustomerResultMap">
        <include refid="searchCustomer"/>
        WHERE a.deleted = 0
        AND a.id = #{id}
    </select>
</mapper>
