<?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.MesBaseAttachInfoMapper">

    <resultMap type="MesBaseAttachInfo" id="MesBaseAttachInfoResult">
        <result property="attachId" column="attach_id"/>
        <result property="attachCode" column="attach_code"/>
        <result property="attachName" column="attach_name"/>
        <result property="attachType" column="attach_type"/>
        <result property="attachPath" column="attach_path"/>
        <result property="processId" column="process_id"/>
        <result property="activeFlag" column="active_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="selectMesBaseAttachInfoVo">
        select attach_id,
               attach_code,
               attach_name,
               attach_type,
               attach_path,
               process_id,
               active_flag,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from mes_base_attach_info
    </sql>

    <select id="selectMesBaseAttachInfoList" parameterType="MesBaseAttachInfo" resultMap="MesBaseAttachInfoResult">
        <include refid="selectMesBaseAttachInfoVo"/>
        <where>
            <if test="attachCode != null  and attachCode != ''">and attach_code = #{attachCode}</if>
            <if test="attachName != null  and attachName != ''">and attach_name like concat('%', #{attachName}, '%')
            </if>
            <if test="attachType != null  and attachType != ''">and attach_type = #{attachType}</if>
            <if test="attachPath != null  and attachPath != ''">and attach_path = #{attachPath}</if>
            <if test="processId != null ">and process_id = #{processId}</if>
            <if test="activeFlag != null  and activeFlag != ''">and active_flag = #{activeFlag}</if>
        </where>
    </select>

    <select id="selectMesBaseAttachInfoByAttachId" parameterType="Long" resultMap="MesBaseAttachInfoResult">
        <include refid="selectMesBaseAttachInfoVo"/>
        where attach_id = #{attachId}
    </select>

    <insert id="insertMesBaseAttachInfo" parameterType="MesBaseAttachInfo" useGeneratedKeys="true"
            keyProperty="attachId">
        insert into mes_base_attach_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="attachCode != null">attach_code,</if>
            <if test="attachName != null and attachName != ''">attach_name,</if>
            <if test="attachType != null and attachType != ''">attach_type,</if>
            <if test="attachPath != null and attachPath != ''">attach_path,</if>
            <if test="processId != null">process_id,</if>
            <if test="activeFlag != null">active_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="attachCode != null">#{attachCode},</if>
            <if test="attachName != null and attachName != ''">#{attachName},</if>
            <if test="attachType != null and attachType != ''">#{attachType},</if>
            <if test="attachPath != null and attachPath != ''">#{attachPath},</if>
            <if test="processId != null">#{processId},</if>
            <if test="activeFlag != null">#{activeFlag},</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="updateMesBaseAttachInfo" parameterType="MesBaseAttachInfo">
        update mes_base_attach_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="attachCode != null">attach_code = #{attachCode},</if>
            <if test="attachName != null and attachName != ''">attach_name = #{attachName},</if>
            <if test="attachType != null and attachType != ''">attach_type = #{attachType},</if>
            <if test="attachPath != null and attachPath != ''">attach_path = #{attachPath},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="activeFlag != null">active_flag = #{activeFlag},</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 attach_id = #{attachId}
    </update>

    <delete id="deleteMesBaseAttachInfoByAttachId" parameterType="Long">
        delete
        from mes_base_attach_info
        where attach_id = #{attachId}
    </delete>

    <delete id="deleteMesBaseAttachInfoByAttachIds" parameterType="String">
        delete from mes_base_attach_info where attach_id in
        <foreach item="attachId" collection="array" open="(" separator="," close=")">
            #{attachId}
        </foreach>
    </delete>
</mapper>