<?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.manage.mapper.BaseManufacturerMapper">
    
    <resultMap type="BaseManufacturer" id="BaseManufacturerResult">
        <result property="manufacturerId"    column="manufacturer_id"    />
        <result property="manufacturerCode"    column="manufacturer_code"    />
        <result property="manufacturerName"    column="manufacturer_name"    />
        <result property="address"    column="address"    />
        <result property="phoneNumber"    column="phone_number"    />
        <result property="emileAddr"    column="emile_addr"    />
        <result property="businessNature"    column="business_nature"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="remark"    column="remark"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBaseManufacturerVo">
        select manufacturer_id, manufacturer_code, manufacturer_name, address, phone_number, emile_addr, business_nature, is_enable, remark, update_by, update_time from base_manufacturer
    </sql>

    <select id="selectBaseManufacturerList" parameterType="BaseManufacturer" resultMap="BaseManufacturerResult">
        <include refid="selectBaseManufacturerVo"/>
        <where>  
            <if test="manufacturerCode != null  and manufacturerCode != ''"> and manufacturer_code = #{manufacturerCode}</if>
            <if test="manufacturerName != null  and manufacturerName != ''"> and manufacturer_name like concat('%', #{manufacturerName}, '%')</if>
            <if test="businessNature != null  and businessNature != ''"> and business_nature = #{businessNature}</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
        </where>
    </select>
    
    <select id="selectBaseManufacturerByManufacturerId" parameterType="Long" resultMap="BaseManufacturerResult">
        <include refid="selectBaseManufacturerVo"/>
        where manufacturer_id = #{manufacturerId}
    </select>
        
    <insert id="insertBaseManufacturer" parameterType="BaseManufacturer" useGeneratedKeys="true" keyProperty="manufacturerId">
        insert into base_manufacturer
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="manufacturerCode != null">manufacturer_code,</if>
            <if test="manufacturerName != null">manufacturer_name,</if>
            <if test="address != null">address,</if>
            <if test="phoneNumber != null">phone_number,</if>
            <if test="emileAddr != null">emile_addr,</if>
            <if test="businessNature != null">business_nature,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="remark != null">remark,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="manufacturerCode != null">#{manufacturerCode},</if>
            <if test="manufacturerName != null">#{manufacturerName},</if>
            <if test="address != null">#{address},</if>
            <if test="phoneNumber != null">#{phoneNumber},</if>
            <if test="emileAddr != null">#{emileAddr},</if>
            <if test="businessNature != null">#{businessNature},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="remark != null">#{remark},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBaseManufacturer" parameterType="BaseManufacturer">
        update base_manufacturer
        <trim prefix="SET" suffixOverrides=",">
            <if test="manufacturerCode != null">manufacturer_code = #{manufacturerCode},</if>
            <if test="manufacturerName != null">manufacturer_name = #{manufacturerName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="phoneNumber != null">phone_number = #{phoneNumber},</if>
            <if test="emileAddr != null">emile_addr = #{emileAddr},</if>
            <if test="businessNature != null">business_nature = #{businessNature},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where manufacturer_id = #{manufacturerId}
    </update>

    <delete id="deleteBaseManufacturerByManufacturerId" parameterType="Long">
        delete from base_manufacturer where manufacturer_id = #{manufacturerId}
    </delete>

    <delete id="deleteBaseManufacturerByManufacturerIds" parameterType="String">
        delete from base_manufacturer where manufacturer_id in 
        <foreach item="manufacturerId" collection="array" open="(" separator="," close=")">
            #{manufacturerId}
        </foreach>
    </delete>

</mapper>