<?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="hw.tagApi.system.mapper.SysAttachInfoMapper">
    
    <resultMap type="SysAttachInfo" id="SysAttachInfoResult">
        <result property="attachId"    column="attach_id"    />
        <result property="attachName"    column="attach_name"    />
        <result property="attachType"    column="attach_type"    />
        <result property="attachUrl"    column="attach_url"    />
        <result property="attachAddress"    column="attach_address"    />
        <result property="expirationTime"    column="expiration_time"    />
        <result property="delFlag"    column="del_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="selectSysAttachInfoVo">
        select attach_id, attach_name, attach_type, attach_url, attach_address, expiration_time, del_flag, remark, create_by, create_time, update_by, update_time from sys_attach_info
    </sql>

    <select id="selectSysAttachInfoList" parameterType="SysAttachInfo" resultMap="SysAttachInfoResult">
        <include refid="selectSysAttachInfoVo"/>
        <where>  
            <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="attachUrl != null  and attachUrl != ''"> and attach_url = #{attachUrl}</if>
            <if test="attachAddress != null  and attachAddress != ''"> and attach_address = #{attachAddress}</if>
            <if test="expirationTime != null "> and expiration_time = #{expirationTime}</if>
        </where>
    </select>
    
    <select id="selectSysAttachInfoByAttachId" parameterType="Long" resultMap="SysAttachInfoResult">
        <include refid="selectSysAttachInfoVo"/>
        where attach_id = #{attachId}
    </select>

    <insert id="insertSysAttachInfo" parameterType="SysAttachInfo" useGeneratedKeys="true" keyProperty="attachId">
        insert into sys_attach_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="attachName != null and attachName != ''">attach_name,</if>
            <if test="attachType != null and attachType != ''">attach_type,</if>
            <if test="attachUrl != null and attachUrl != ''">attach_url,</if>
            <if test="attachAddress != null and attachAddress != ''">attach_address,</if>
            <if test="expirationTime != null">expiration_time,</if>
            <if test="delFlag != null">del_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="attachName != null and attachName != ''">#{attachName},</if>
            <if test="attachType != null and attachType != ''">#{attachType},</if>
            <if test="attachUrl != null and attachUrl != ''">#{attachUrl},</if>
            <if test="attachAddress != null and attachAddress != ''">#{attachAddress},</if>
            <if test="expirationTime != null">#{expirationTime},</if>
            <if test="delFlag != null">#{delFlag},</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="updateSysAttachInfo" parameterType="SysAttachInfo">
        update sys_attach_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="attachName != null and attachName != ''">attach_name = #{attachName},</if>
            <if test="attachType != null and attachType != ''">attach_type = #{attachType},</if>
            <if test="attachUrl != null and attachUrl != ''">attach_url = #{attachUrl},</if>
            <if test="attachAddress != null and attachAddress != ''">attach_address = #{attachAddress},</if>
            <if test="expirationTime != null">expiration_time = #{expirationTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</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="deleteSysAttachInfoByAttachId" parameterType="Long">
        delete from sys_attach_info where attach_id = #{attachId}
    </delete>

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