<?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.ruoyi.business.mapper.TCusCustomerMapper">
    
    <resultMap type="TCusCustomer" id="TCusCustomerResult">
        <result property="customerId"    column="CUSTOMER_ID"    />
        <result property="customerName"    column="CUSTOMER_NAME"    />
        <result property="customerShortName"    column="CUSTOMER_SHORT_NAME"    />
        <result property="pyName"    column="PY_NAME"    />
        <result property="cusTypeId"    column="CUS_TYPE_ID"    />
        <result property="linkman"    column="LINKMAN"    />
        <result property="telephone"    column="TELEPHONE"    />
        <result property="phone"    column="PHONE"    />
        <result property="fax"    column="FAX"    />
        <result property="sex"    column="SEX"    />
        <result property="email"    column="EMAIL"    />
        <result property="birthday"    column="BIRTHDAY"    />
        <result property="province"    column="PROVINCE"    />
        <result property="city"    column="CITY"    />
        <result property="distirct"    column="DISTIRCT"    />
        <result property="postcode"    column="POSTCODE"    />
        <result property="address"    column="ADDRESS"    />
        <result property="status"    column="STATUS"    />
        <result property="remark"    column="REMARK"    />
        <result property="version"    column="VERSION"    />
        <result property="operatorid"    column="OPERATORID"    />
        <result property="operatedate"    column="OPERATEDATE"    />
        <result property="provinceId"    column="PROVINCE_ID"    />
        <result property="cityId"    column="CITY_ID"    />
        <result property="townId"    column="TOWN_ID"    />
        <result property="guid"    column="GUID"    />
        <result property="updateDate"    column="UPDATE_DATE"    />
        <result property="updateBy"    column="UPDATE_BY"    />
        <result property="port"    column="PORT"    />
        <result property="sts"    column="STS"    />
    </resultMap>

    <sql id="selectTCusCustomerVo">
        select CUSTOMER_ID, CUSTOMER_NAME, CUSTOMER_SHORT_NAME, PY_NAME, CUS_TYPE_ID, LINKMAN, TELEPHONE, PHONE, FAX, SEX, EMAIL, BIRTHDAY, PROVINCE, CITY, DISTIRCT, POSTCODE, ADDRESS, STATUS, REMARK, VERSION, OPERATORID, OPERATEDATE, PROVINCE_ID, CITY_ID, TOWN_ID, GUID, UPDATE_DATE, UPDATE_BY, PORT, STS from t_cus_customer
    </sql>

    <select id="selectTCusCustomerList" parameterType="TCusCustomer" resultMap="TCusCustomerResult">
        <include refid="selectTCusCustomerVo"/>
        <where>  
            <if test="customerId != null  and customerId != ''"> and CUSTOMER_ID = #{customerId}</if>
            <if test="customerName != null  and customerName != ''"> and CUSTOMER_NAME like concat('%', #{customerName}, '%')</if>
            <if test="customerShortName != null  and customerShortName != ''"> and CUSTOMER_SHORT_NAME like concat('%', #{customerShortName}, '%')</if>
            <if test="pyName != null  and pyName != ''"> and PY_NAME like concat('%', #{pyName}, '%')</if>
            <if test="cusTypeId != null  and cusTypeId != ''"> and CUS_TYPE_ID = #{cusTypeId}</if>
            <if test="linkman != null  and linkman != ''"> and LINKMAN = #{linkman}</if>
            <if test="telephone != null  and telephone != ''"> and TELEPHONE = #{telephone}</if>
            <if test="phone != null  and phone != ''"> and PHONE = #{phone}</if>
            <if test="fax != null  and fax != ''"> and FAX = #{fax}</if>
            <if test="sex != null  and sex != ''"> and SEX = #{sex}</if>
            <if test="email != null  and email != ''"> and EMAIL = #{email}</if>
            <if test="birthday != null "> and BIRTHDAY = #{birthday}</if>
            <if test="province != null  and province != ''"> and PROVINCE = #{province}</if>
            <if test="city != null  and city != ''"> and CITY = #{city}</if>
            <if test="distirct != null  and distirct != ''"> and DISTIRCT = #{distirct}</if>
            <if test="postcode != null  and postcode != ''"> and POSTCODE = #{postcode}</if>
            <if test="address != null  and address != ''"> and ADDRESS = #{address}</if>
            <if test="status != null  and status != ''"> and STATUS = #{status}</if>
            <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
            <if test="version != null  and version != ''"> and VERSION = #{version}</if>
            <if test="operatorid != null  and operatorid != ''"> and OPERATORID = #{operatorid}</if>
            <if test="operatedate != null "> and OPERATEDATE = #{operatedate}</if>
            <if test="provinceId != null  and provinceId != ''"> and PROVINCE_ID = #{provinceId}</if>
            <if test="cityId != null  and cityId != ''"> and CITY_ID = #{cityId}</if>
            <if test="townId != null  and townId != ''"> and TOWN_ID = #{townId}</if>
            <if test="guid != null  and guid != ''"> and GUID = #{guid}</if>
            <if test="updateDate != null "> and UPDATE_DATE = #{updateDate}</if>
            <if test="updateBy != null  and updateBy != ''"> and UPDATE_BY = #{updateBy}</if>
            <if test="port != null  and port != ''"> and PORT = #{port}</if>
            <if test="sts != null  and sts != ''"> and STS = #{sts}</if>
        </where>
    </select>
    
    <select id="selectTCusCustomerByCustomerId" parameterType="String" resultMap="TCusCustomerResult">
        <include refid="selectTCusCustomerVo"/>
        where CUSTOMER_ID = #{customerId}
    </select>
        
    <insert id="insertTCusCustomer" parameterType="TCusCustomer">
        insert into t_cus_customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="customerId != null">CUSTOMER_ID,</if>
            <if test="customerName != null">CUSTOMER_NAME,</if>
            <if test="customerShortName != null">CUSTOMER_SHORT_NAME,</if>
            <if test="pyName != null">PY_NAME,</if>
            <if test="cusTypeId != null">CUS_TYPE_ID,</if>
            <if test="linkman != null">LINKMAN,</if>
            <if test="telephone != null">TELEPHONE,</if>
            <if test="phone != null">PHONE,</if>
            <if test="fax != null">FAX,</if>
            <if test="sex != null">SEX,</if>
            <if test="email != null">EMAIL,</if>
            <if test="birthday != null">BIRTHDAY,</if>
            <if test="province != null">PROVINCE,</if>
            <if test="city != null">CITY,</if>
            <if test="distirct != null">DISTIRCT,</if>
            <if test="postcode != null">POSTCODE,</if>
            <if test="address != null">ADDRESS,</if>
            <if test="status != null">STATUS,</if>
            <if test="remark != null">REMARK,</if>
            <if test="version != null">VERSION,</if>
            <if test="operatorid != null">OPERATORID,</if>
            <if test="operatedate != null">OPERATEDATE,</if>
            <if test="provinceId != null">PROVINCE_ID,</if>
            <if test="cityId != null">CITY_ID,</if>
            <if test="townId != null">TOWN_ID,</if>
            <if test="guid != null">GUID,</if>
            <if test="updateDate != null">UPDATE_DATE,</if>
            <if test="updateBy != null">UPDATE_BY,</if>
            <if test="port != null">PORT,</if>
            <if test="sts != null">STS,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="customerId != null">#{customerId},</if>
            <if test="customerName != null">#{customerName},</if>
            <if test="customerShortName != null">#{customerShortName},</if>
            <if test="pyName != null">#{pyName},</if>
            <if test="cusTypeId != null">#{cusTypeId},</if>
            <if test="linkman != null">#{linkman},</if>
            <if test="telephone != null">#{telephone},</if>
            <if test="phone != null">#{phone},</if>
            <if test="fax != null">#{fax},</if>
            <if test="sex != null">#{sex},</if>
            <if test="email != null">#{email},</if>
            <if test="birthday != null">#{birthday},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="distirct != null">#{distirct},</if>
            <if test="postcode != null">#{postcode},</if>
            <if test="address != null">#{address},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</if>
            <if test="version != null">#{version},</if>
            <if test="operatorid != null">#{operatorid},</if>
            <if test="operatedate != null">#{operatedate},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="townId != null">#{townId},</if>
            <if test="guid != null">#{guid},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="port != null">#{port},</if>
            <if test="sts != null">#{sts},</if>
         </trim>
    </insert>

    <update id="updateTCusCustomer" parameterType="TCusCustomer">
        update t_cus_customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="customerName != null">CUSTOMER_NAME = #{customerName},</if>
            <if test="customerShortName != null">CUSTOMER_SHORT_NAME = #{customerShortName},</if>
            <if test="pyName != null">PY_NAME = #{pyName},</if>
            <if test="cusTypeId != null">CUS_TYPE_ID = #{cusTypeId},</if>
            <if test="linkman != null">LINKMAN = #{linkman},</if>
            <if test="telephone != null">TELEPHONE = #{telephone},</if>
            <if test="phone != null">PHONE = #{phone},</if>
            <if test="fax != null">FAX = #{fax},</if>
            <if test="sex != null">SEX = #{sex},</if>
            <if test="email != null">EMAIL = #{email},</if>
            <if test="birthday != null">BIRTHDAY = #{birthday},</if>
            <if test="province != null">PROVINCE = #{province},</if>
            <if test="city != null">CITY = #{city},</if>
            <if test="distirct != null">DISTIRCT = #{distirct},</if>
            <if test="postcode != null">POSTCODE = #{postcode},</if>
            <if test="address != null">ADDRESS = #{address},</if>
            <if test="status != null">STATUS = #{status},</if>
            <if test="remark != null">REMARK = #{remark},</if>
            <if test="version != null">VERSION = #{version},</if>
            <if test="operatorid != null">OPERATORID = #{operatorid},</if>
            <if test="operatedate != null">OPERATEDATE = #{operatedate},</if>
            <if test="provinceId != null">PROVINCE_ID = #{provinceId},</if>
            <if test="cityId != null">CITY_ID = #{cityId},</if>
            <if test="townId != null">TOWN_ID = #{townId},</if>
            <if test="guid != null">GUID = #{guid},</if>
            <if test="updateDate != null">UPDATE_DATE = #{updateDate},</if>
            <if test="updateBy != null">UPDATE_BY = #{updateBy},</if>
            <if test="port != null">PORT = #{port},</if>
            <if test="sts != null">STS = #{sts},</if>
        </trim>
        where CUSTOMER_ID = #{customerId}
    </update>

    <delete id="deleteTCusCustomerByCustomerId" parameterType="String">
        delete from t_cus_customer where CUSTOMER_ID = #{customerId}
    </delete>

    <delete id="deleteTCusCustomerByCustomerIds" parameterType="String">
        delete from t_cus_customer where CUSTOMER_ID in 
        <foreach item="customerId" collection="array" open="(" separator="," close=")">
            #{customerId}
        </foreach>
    </delete>

</mapper>