<?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.ruoyi.system.mapper.BomanMaterialMapper">
    
    <resultMap type="BomanMaterial" id="BomanMaterialResult">
        <result property="materialId"    column="material_id"    />
        <result property="materialUrl"    column="material_url"    />
        <result property="materialName"    column="material_name"    />
        <result property="type"    column="type"    />
        <result property="keywords"    column="keywords"    />
        <result property="isLunbo"    column="is_lunbo"    />
        <result property="releaseTime"    column="release_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectBomanMaterialVo">
        select material_id, material_url, material_name, type, keywords, is_lunbo, release_time, create_time, create_by, update_by, update_time from boman_material
    </sql>

    <select id="selectBomanMaterialList" parameterType="BomanMaterial" resultMap="BomanMaterialResult">
        <include refid="selectBomanMaterialVo"/>
        <where>  
            <if test="materialUrl != null  and materialUrl != ''"> and material_url = #{materialUrl}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="isLunbo != null  and isLunbo != ''"> and is_lunbo = #{isLunbo}</if>
            <if test="releaseTime != null "> and release_time = #{releaseTime}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectBomanMaterialByMaterialId" parameterType="Long" resultMap="BomanMaterialResult">
        <include refid="selectBomanMaterialVo"/>
        where material_id = #{materialId}
    </select>
        
    <insert id="insertBomanMaterial" parameterType="BomanMaterial" useGeneratedKeys="true" keyProperty="materialId">
        insert into boman_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="materialUrl != null and materialUrl != ''">material_url,</if>
            <if test="materialName != null">material_name,</if>
            <if test="type != null">type,</if>
            <if test="keywords != null">keywords,</if>
            <if test="isLunbo != null">is_lunbo,</if>
            <if test="releaseTime != null">release_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="materialUrl != null and materialUrl != ''">#{materialUrl},</if>
            <if test="materialName != null">#{materialName},</if>
            <if test="type != null">#{type},</if>
            <if test="keywords != null">#{keywords},</if>
            <if test="isLunbo != null">#{isLunbo},</if>
            <if test="releaseTime != null">#{releaseTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateBomanMaterial" parameterType="BomanMaterial">
        update boman_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="materialUrl != null and materialUrl != ''">material_url = #{materialUrl},</if>
            <if test="materialName != null">material_name = #{materialName},</if>
            <if test="type != null">type = #{type},</if>
            <if test="keywords != null">keywords = #{keywords},</if>
            <if test="isLunbo != null">is_lunbo = #{isLunbo},</if>
            <if test="releaseTime != null">release_time = #{releaseTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where material_id = #{materialId}
    </update>

    <delete id="deleteBomanMaterialByMaterialId" parameterType="Long">
        delete from boman_material where material_id = #{materialId}
    </delete>

    <delete id="deleteBomanMaterialByMaterialIds" parameterType="String">
        delete from boman_material where material_id in 
        <foreach item="materialId" collection="array" open="(" separator="," close=")">
            #{materialId}
        </foreach>
    </delete>

    <insert id="batchBomanMaterial">
        insert into boman_material(material_url, material_name,type,keywords,is_lunbo,release_time,create_time) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.materialUrl},#{item.materialName},#{item.type},#{item.keywords},#{item.isLunbo},#{item.releaseTime},sysdate())
        </foreach>
    </insert>
</mapper>