<?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.zhyc.module.sale.mapper.SxCustomerMapper">

    <resultMap type="SxCustomer" id="SxCustomerResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="phone" column="phone"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="district" column="district"/>
        <result property="address" column="address"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectSxCustomerVo">
        SELECT id, name, phone, province, city, district, address, remark
        FROM sx_customer
    </sql>

    <select id="selectSxCustomerList" parameterType="SxCustomer" resultMap="SxCustomerResult">
        <include refid="selectSxCustomerVo"/>
        <where>
            <if test="name != null and name != ''"> AND name LIKE CONCAT('%', #{name}, '%')</if>
        </where>
    </select>

    <select id="selectSxCustomerById" parameterType="Long" resultMap="SxCustomerResult">
        <include refid="selectSxCustomerVo"/>
        WHERE id = #{id}
    </select>

    <insert id="insertSxCustomer" parameterType="SxCustomer" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO sx_customer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="phone != null">phone,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="district != null">district,</if>
            <if test="address != null">address,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="VALUES (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="phone != null">#{phone},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="district != null">#{district},</if>
            <if test="address != null">#{address},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateSxCustomer" parameterType="SxCustomer">
        UPDATE sx_customer
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="district != null">district = #{district},</if>
            <if test="address != null">address = #{address},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        WHERE id = #{id}
    </update>

    <delete id="deleteSxCustomerById" parameterType="Long">
        DELETE FROM sx_customer WHERE id = #{id}
    </delete>

    <delete id="deleteSxCustomerByIds" parameterType="Long">
        DELETE FROM sx_customer WHERE id IN
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
