<?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.aucma.dms.mapper.DmsBaseDeviceSuplierMapper">

    <resultMap type="DmsBaseDeviceSuplier" id="DmsBaseDeviceSuplierResult">
        <result property="supplierId"    column="supplier_id"    />
        <result property="suplierCode"    column="suplier_code"    />
        <result property="suplierName"    column="suplier_name"    />
        <result property="suplierPerson"    column="suplier_person"    />
        <result property="suplierTel"    column="suplier_tel"    />
        <result property="suplierAddress"    column="suplier_address"    />
        <result property="suplierStatus"    column="suplier_status"    />
        <result property="isFlag"    column="is_flag"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDmsBaseDeviceSuplierVo">
        select supplier_id, suplier_code, suplier_name, suplier_person, suplier_tel, suplier_address, suplier_status, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_device_suplier
    </sql>

    <select id="selectDmsBaseDeviceSuplierList" parameterType="DmsBaseDeviceSuplier" resultMap="DmsBaseDeviceSuplierResult">
        select a.supplier_id, a.suplier_code, a.suplier_name, a.suplier_person, a.suplier_tel, a.suplier_address, a.suplier_status, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_device_suplier a
        <where>
            <if test="suplierCode != null  and suplierCode != ''"> and suplier_code = #{suplierCode}</if>
            <if test="suplierName != null  and suplierName != ''"> and suplier_name like concat('%', #{suplierName}, '%')</if>
            <if test="suplierPerson != null  and suplierPerson != ''"> and suplier_person = #{suplierPerson}</if>
            <if test="suplierTel != null  and suplierTel != ''"> and suplier_tel = #{suplierTel}</if>
            <if test="suplierAddress != null  and suplierAddress != ''"> and suplier_address = #{suplierAddress}</if>
            <if test="suplierStatus != null "> and suplier_status = #{suplierStatus}</if>
            <if test="isFlag != null "> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectDmsBaseDeviceSuplierBySupplierId" parameterType="Long" resultMap="DmsBaseDeviceSuplierResult">
        <include refid="selectDmsBaseDeviceSuplierVo"/>
        where supplier_id = #{supplierId}
    </select>

    <insert id="insertDmsBaseDeviceSuplier" parameterType="DmsBaseDeviceSuplier" useGeneratedKeys="true" keyProperty="supplierId">
        insert into dms_base_device_suplier
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="suplierCode != null and suplierCode != ''">suplier_code,</if>
            <if test="suplierName != null and suplierName != ''">suplier_name,</if>
            <if test="suplierPerson != null">suplier_person,</if>
            <if test="suplierTel != null">suplier_tel,</if>
            <if test="suplierAddress != null">suplier_address,</if>
            <if test="suplierStatus != null">suplier_status,</if>
            <if test="isFlag != null">is_flag,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="suplierCode != null and suplierCode != ''">#{suplierCode},</if>
            <if test="suplierName != null and suplierName != ''">#{suplierName},</if>
            <if test="suplierPerson != null">#{suplierPerson},</if>
            <if test="suplierTel != null">#{suplierTel},</if>
            <if test="suplierAddress != null">#{suplierAddress},</if>
            <if test="suplierStatus != null">#{suplierStatus},</if>
            <if test="isFlag != null">#{isFlag},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDmsBaseDeviceSuplier" parameterType="DmsBaseDeviceSuplier">
        update dms_base_device_suplier
        <trim prefix="SET" suffixOverrides=",">
            <if test="suplierCode != null and suplierCode != ''">suplier_code = #{suplierCode},</if>
            <if test="suplierName != null and suplierName != ''">suplier_name = #{suplierName},</if>
            <if test="suplierPerson != null">suplier_person = #{suplierPerson},</if>
            <if test="suplierTel != null">suplier_tel = #{suplierTel},</if>
            <if test="suplierAddress != null">suplier_address = #{suplierAddress},</if>
            <if test="suplierStatus != null">suplier_status = #{suplierStatus},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where supplier_id = #{supplierId}
    </update>

    <delete id="deleteDmsBaseDeviceSuplierBySupplierId" parameterType="Long">
        delete from dms_base_device_suplier where supplier_id = #{supplierId}
    </delete>

    <delete id="deleteDmsBaseDeviceSuplierBySupplierIds" parameterType="String">
        delete from dms_base_device_suplier where supplier_id in
        <foreach item="supplierId" collection="array" open="(" separator="," close=")">
            #{supplierId}
        </foreach>
    </delete>
    <select id="selectDmsBaseDeviceSuplierDeviceId" parameterType="Long" resultMap="DmsBaseDeviceSuplierResult">
        	 select * from dms_base_device_suplier where supplier_id =
        	 (	SELECT supplier_id from dms_base_device_ledger where device_id = #{deviceId}	)
    </select>
</mapper>
