<?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.sgzb.base.mapper.MaTypeFileMapper">
    
    <resultMap type="com.bonus.sgzb.base.domain.MaTypeFile" id="MaTypeFileResult">
        <result property="typeId"    column="type_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileType"    column="file_type"    />
        <result property="userId"    column="user_id"    />
        <result property="status"    column="status"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectMaTypeFileVo">
        select type_id, ma_id, file_name, file_url, file_type, user_id, status, company_id from ma_type_file
    </sql>

    <select id="selectMaTypeFileList" parameterType="com.bonus.sgzb.base.domain.MaTypeFile" resultMap="MaTypeFileResult">
        <include refid="selectMaTypeFileVo"/>
        <where>  
            <if test="maId != null  and maId != ''"> 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="fileType != null  and fileType != ''"> and file_type = #{fileType}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="companyId != null  and companyId != ''"> and company_id = #{companyId}</if>
        </where>
    </select>
    
    <select id="selectMaTypeFileByTypeId" parameterType="Long" resultMap="MaTypeFileResult">
        <include refid="selectMaTypeFileVo"/>
        where type_id = #{typeId}
    </select>
        
    <insert id="insertMaTypeFile" parameterType="com.bonus.sgzb.base.domain.MaTypeFile">
        insert into ma_type_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeId != null">type_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="fileName != null and fileName != ''">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="fileType != null">file_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="companyId != null">company_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeId != null">#{typeId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="fileName != null and fileName != ''">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="companyId != null">#{companyId},</if>
         </trim>
    </insert>

    <update id="updateMaTypeFile" parameterType="com.bonus.sgzb.base.domain.MaTypeFile">
        update ma_type_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="fileName != null and fileName != ''">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="userId != null">user_id = #{userId},</if>
            update_time = now(),
            <if test="status != null">status = #{status},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
        </trim>
        where type_id = #{typeId} and file_type = #{fileType}
    </update>

    <delete id="deleteMaTypeFileByTypeId">
        delete from ma_type_file where type_id = #{typeId} and file_type = #{fileType}
    </delete>

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