<?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.shinsoft.sto.mapper.main.CustomerMapper">

    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Customer">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="process_instance_id" property="processInstanceId" jdbcType="VARCHAR"/>
        <result column="process_instance_status" property="processInstanceStatus" jdbcType="VARCHAR"/>
        <result column="add_id" property="addId" jdbcType="VARCHAR"/>
        <result column="add_code" property="addCode" jdbcType="VARCHAR"/>
        <result column="add_name" property="addName" jdbcType="VARCHAR"/>
        <result column="add_dept_code" property="addDeptCode" jdbcType="VARCHAR"/>
        <result column="add_dept_name" property="addDeptName" jdbcType="VARCHAR"/>
        <result column="add_time" property="addTime" jdbcType="TIMESTAMP"/>
        <result column="modify_id" property="modifyId" jdbcType="VARCHAR"/>
        <result column="modify_code" property="modifyCode" jdbcType="VARCHAR"/>
        <result column="modify_name" property="modifyName" jdbcType="VARCHAR"/>
        <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
        <result column="cancel_id" property="cancelId" jdbcType="VARCHAR"/>
        <result column="cancel_code" property="cancelCode" jdbcType="VARCHAR"/>
        <result column="cancel_name" property="cancelName" jdbcType="VARCHAR"/>
        <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP"/>
        <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR"/>
        <result column="belong_id" property="belongId" jdbcType="VARCHAR"/>
        <result column="customer_name" property="customerName" jdbcType="VARCHAR"/>
        <result column="customer_abbreviation" property="customerAbbreviation" jdbcType="VARCHAR"/>
        <result column="customer_contact" property="customerContact" jdbcType="VARCHAR"/>
        <result column="contact_information" property="contactInformation" jdbcType="VARCHAR"/>
        <result column="default_address" property="defaultAddress" jdbcType="VARCHAR"/>
        <result column="remarks" property="remarks" jdbcType="VARCHAR"/>
        <result column="active_status" property="activeStatus" jdbcType="VARCHAR"/>
        <result column="operation" property="operation" jdbcType="VARCHAR"/>
        <result column="test" property="test" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, process_instance_id, process_instance_status, add_id, add_code, add_name, add_dept_code,
        add_dept_name, add_time, modify_id, modify_code, modify_name, modify_time, cancel_id,
        cancel_code, cancel_name, cancel_time, cancel_flag, belong_id, customer_name, customer_abbreviation,
        customer_contact, contact_information, default_address, remarks, active_status, operation, test
    </sql>

    <select id="selectCustomerPage" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from STO_MAIN_CUSTOMER
        where nvl(cancel_flag,'0') = '0'
        and belong_id = #{belongId}
        <if test="query != null and query != ''">
            and (customer_name like '%' || #{query} || '%'
            or customer_abbreviation like '%' || #{query} || '%'
            or customer_contact like '%' || #{query} || '%'
            or contact_information like '%' || #{query} || '%')
        </if>
        order by add_time desc
    </select>

    <select id="selectByCustomerName" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from STO_MAIN_CUSTOMER
        where nvl(cancel_flag,'0') = '0'
        and belong_id = #{belongId}
        and customer_name = #{customerName}
    </select>

</mapper>