<?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.bonus.zlpt.equip.mapper.FileInfoMapper">
    
    <resultMap type="com.bonus.zlpt.common.core.domain.equip.FileInfo" id="FileInfoResult">
        <result property="id"    column="id"    />
        <result property="maId"    column="ma_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectFileInfoVo">
        select id, ma_id, file_name, file_url, type from ma_file_info
    </sql>

    <select id="selectFileInfoList" parameterType="com.bonus.zlpt.common.core.domain.equip.FileInfo" resultMap="FileInfoResult">
        <include refid="selectFileInfoVo"/>
        <where>  
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="fileName != null  and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
    </select>
    
    <select id="selectFileInfoById" parameterType="Long" resultMap="FileInfoResult">
        <include refid="selectFileInfoVo"/>
        where id = #{id}
    </select>

    <select id="selectByMaId" resultType="com.bonus.zlpt.common.core.domain.equip.FileInfo">
        select f.* from ma_dev_info d,ma_file_info f where d.ma_id=f.ma_id
    </select>

    <insert id="insertFileInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.FileInfo">
        insert into ma_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="maId != null">#{maId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <update id="updateFileInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.FileInfo">
        update ma_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFileInfoById" parameterType="Long">
        delete from ma_file_info where id = #{id}
    </delete>

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