<?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.hw.mes.mapper.MesBaseProdlineInfoMapper">

    <resultMap type="MesBaseProdlineInfo" id="MesBaseProdlineInfoResult">
        <result property="prodlineId" column="prodline_id"/>
        <result property="prodlineCode" column="prodline_code"/>
        <result property="prodlineName" column="prodline_name"/>
        <result property="prodlineType" column="prodline_type"/>
        <result property="factoryId" column="factory_id"/>
        <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"/>
        <result property="factoryName" column="factory_name"/>
    </resultMap>

    <sql id="selectMesBaseProdlineInfoVo">
        select mbpi.prodline_id,
               mbpi.prodline_code,
               mbpi.prodline_name,
               mbpi.prodline_type,
               mbpi.factory_id,
               mbfi.factory_name,
               mbpi.is_flag,
               mbpi.remark,
               mbpi.create_by,
               mbpi.create_time,
               mbpi.update_by,
               mbpi.update_time
        from mes_base_prodline_info mbpi
                 left join mes_base_factory_info mbfi on mbfi.factory_id = mbpi.factory_id
    </sql>

    <select id="selectMesBaseProdlineInfoList" parameterType="MesBaseProdlineInfo"
            resultMap="MesBaseProdlineInfoResult">
        <include refid="selectMesBaseProdlineInfoVo"/>
        <where>
            <if test="prodlineCode != null  and prodlineCode != ''">and mbpi.prodline_code = #{prodlineCode}</if>
            <if test="prodlineName != null  and prodlineName != ''">and mbpi.prodline_name like concat('%', #{prodlineName},
                '%')
            </if>
            <if test="prodlineType != null  and prodlineType != ''">and mbpi.prodline_type = #{prodlineType}</if>
            <if test="factoryId != null  and factoryId != ''">and mbpi.factory_id = #{factoryId}</if>
            <if test="isFlag != null  and isFlag != ''">and mbpi.is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectMesBaseProdlineInfoByProdlineId" parameterType="Long" resultMap="MesBaseProdlineInfoResult">
        <include refid="selectMesBaseProdlineInfoVo"/>
        where mbpi.prodline_id = #{prodlineId}
    </select>

    <insert id="insertMesBaseProdlineInfo" parameterType="MesBaseProdlineInfo" useGeneratedKeys="true"
            keyProperty="prodlineId">
        insert into mes_base_prodline_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="prodlineCode != null and prodlineCode != ''">prodline_code,</if>
            <if test="prodlineName != null and prodlineName != ''">prodline_name,</if>
            <if test="prodlineType != null">prodline_type,</if>
            <if test="factoryId != null">factory_id,</if>
            <if test="isFlag != null and isFlag != ''">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="prodlineCode != null and prodlineCode != ''">#{prodlineCode},</if>
            <if test="prodlineName != null and prodlineName != ''">#{prodlineName},</if>
            <if test="prodlineType != null">#{prodlineType},</if>
            <if test="factoryId != null">#{factoryId},</if>
            <if test="isFlag != null and isFlag != ''">#{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="updateMesBaseProdlineInfo" parameterType="MesBaseProdlineInfo">
        update mes_base_prodline_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="prodlineCode != null and prodlineCode != ''">prodline_code = #{prodlineCode},</if>
            <if test="prodlineName != null and prodlineName != ''">prodline_name = #{prodlineName},</if>
            <if test="prodlineType != null">prodline_type = #{prodlineType},</if>
            <if test="factoryId != null">factory_id = #{factoryId},</if>
            <if test="isFlag != null and isFlag != ''">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 prodline_id = #{prodlineId}
    </update>

    <delete id="deleteMesBaseProdlineInfoByProdlineId" parameterType="Long">
        delete
        from mes_base_prodline_info
        where prodline_id = #{prodlineId}
    </delete>

    <delete id="deleteMesBaseProdlineInfoByProdlineIds" parameterType="String">
        delete from mes_base_prodline_info where prodline_id in
        <foreach item="prodlineId" collection="array" open="(" separator="," close=")">
            #{prodlineId}
        </foreach>
    </delete>
</mapper>