<?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.xinelu.manage.mapper.propagandamaterials.PropagandaMaterialsMapper">

    <resultMap type="com.xinelu.manage.domain.propagandamaterials.PropagandaMaterials" id="PropagandaMaterialsResult">
        <result property="id" column="id"/>
        <result property="propagandaId" column="propaganda_id"/>
        <result property="propagandaTitle" column="propaganda_title"/>
        <result property="materialsId" column="materials_id"/>
        <result property="materialsName" column="materials_name"/>
	    <result property="delFlag" column="del_flag"/>
        <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="selectPropagandaMaterialsVo">
        select id, propaganda_id, propaganda_title, materials_id, materials_name, del_flag, create_by, create_time, update_by, update_time from propaganda_materials
    </sql>

    <select id="selectPropagandaMaterialsList" parameterType="com.xinelu.manage.domain.propagandamaterials.PropagandaMaterials" resultMap="PropagandaMaterialsResult">
        <include refid="selectPropagandaMaterialsVo"/>
        <where>
			del_flag = 0
            <if test="propagandaId != null ">
                and propaganda_id = #{propagandaId}
            </if>
            <if test="propagandaTitle != null  and propagandaTitle != ''">
                and propaganda_title = #{propagandaTitle}
            </if>
            <if test="materialsId != null ">
                and materials_id = #{materialsId}
            </if>
            <if test="materialsName != null  and materialsName != ''">
                and materials_name like concat('%', #{materialsName}, '%')
            </if>
        </where>
    </select>

    <select id="selectPropagandaMaterialsById" parameterType="Long"
            resultMap="PropagandaMaterialsResult">
            <include refid="selectPropagandaMaterialsVo"/>
            where id = #{id}
    </select>

    <insert id="insertPropagandaMaterials" parameterType="com.xinelu.manage.domain.propagandamaterials.PropagandaMaterials" useGeneratedKeys="true"
            keyProperty="id">
        insert into propaganda_materials
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="propagandaId != null">propaganda_id,
            </if>
            <if test="propagandaTitle != null">propaganda_title,
            </if>
            <if test="materialsId != null">materials_id,
            </if>
            <if test="materialsName != null">materials_name,
            </if>
	        <if test="delFlag != null">del_flag,
	        </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="propagandaId != null">#{propagandaId},
            </if>
            <if test="propagandaTitle != null">#{propagandaTitle},
            </if>
            <if test="materialsId != null">#{materialsId},
            </if>
            <if test="materialsName != null">#{materialsName},
            </if>
	        <if test="delFlag != null">#{delFlag},
	        </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="updatePropagandaMaterials" parameterType="com.xinelu.manage.domain.propagandamaterials.PropagandaMaterials">
        update propaganda_materials
        <trim prefix="SET" suffixOverrides=",">
            <if test="propagandaId != null">propaganda_id =
                #{propagandaId},
            </if>
            <if test="propagandaTitle != null">propaganda_title =
                #{propagandaTitle},
            </if>
            <if test="materialsId != null">materials_id =
                #{materialsId},
            </if>
            <if test="materialsName != null">materials_name =
                #{materialsName},
            </if>
	        <if test="delFlag != null">del_flag =
		        #{delFlag},
	        </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 id = #{id}
    </update>

    <update id="deleteByPropagandaId" parameterType="Long">
        update propaganda_materials set del_flag = 1 where propaganda_id = #{propagandaId}
    </update>

	<update id="deleteByPropagandaIds" parameterType="Long">
		update propaganda_materials set del_flag = 1 where propaganda_id in
		<foreach item="propagandaId" collection="array" open="(" separator="," close=")">
			#{propagandaId}
		</foreach>
	</update>

	<update id="deletePropagandaMaterialsById" parameterType="Long">
		update propaganda_materials set del_flag = 1 where id = #{id}
	</update>
    <update id="deletePropagandaMaterialsByIds" parameterType="String">
	    update propaganda_materials set del_flag = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>