<?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.branch.mapper.TBranchPublicizeMapper">
    
    <resultMap type="TBranchPublicize" id="TBranchPublicizeResult">
        <result property="publicizeId"    column="publicize_id"    />
        <result property="publicizeTitle"    column="publicize_title"    />
        <result property="publicizeContent"    column="publicize_content"    />
        <result property="isPinned"    column="is_pinned"    />
        <result property="deptId"    column="dept_id"    />
        <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="selectTBranchPublicizeVo">
        select u.publicize_id, u.publicize_title, u.publicize_content, u.is_pinned, u.dept_id, u.del_flag, u.create_by, u.create_time, u.update_by, u.update_time from t_branch_publicize u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTBranchPublicizeList" parameterType="TBranchPublicize" resultMap="TBranchPublicizeResult">
        <include refid="selectTBranchPublicizeVo"/>
        <where>  
            <if test="publicizeId != null "> and u.publicize_id = #{publicizeId}</if>
            <if test="publicizeTitle != null  and publicizeTitle != ''"> and u.publicize_title like concat(concat('%', #{publicizeTitle}), '%')</if>
            <if test="publicizeContent != null  and publicizeContent != ''"> and u.publicize_content like concat(concat('%', #{publicizeContent}), '%')</if>
            <if test="isPinned != null  and isPinned != ''"> and u.is_pinned = #{isPinned}</if>
            <if test="deptId != null "> and u.dept_id = #{deptId}</if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        order by IS_PINNED desc
    </select>
    
    <select id="selectTBranchPublicizeByPublicizeId" parameterType="Long" resultMap="TBranchPublicizeResult">
        <include refid="selectTBranchPublicizeVo"/>
        where u.publicize_id = #{publicizeId}
        and u.del_flag = 0
    </select>
        
    <insert id="insertTBranchPublicize" parameterType="TBranchPublicize">
        <selectKey keyProperty="publicizeId" resultType="long" order="BEFORE">
            SELECT seq_t_branch_publicize.NEXTVAL as publicizeId FROM DUAL
        </selectKey>
        insert into t_branch_publicize
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="publicizeId != null">publicize_id,</if>
            <if test="publicizeTitle != null and publicizeTitle != ''">publicize_title,</if>
            <if test="publicizeContent != null">publicize_content,</if>
            <if test="isPinned != null">is_pinned,</if>
            <if test="deptId != null">dept_id,</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="publicizeId != null">#{publicizeId},</if>
            <if test="publicizeTitle != null and publicizeTitle != ''">#{publicizeTitle},</if>
            <if test="publicizeContent != null">#{publicizeContent},</if>
            <if test="isPinned != null">#{isPinned},</if>
            <if test="deptId != null">#{deptId},</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="updateTBranchPublicize" parameterType="TBranchPublicize">
        update t_branch_publicize
        <trim prefix="SET" suffixOverrides=",">
            <if test="publicizeTitle != null and publicizeTitle != ''">publicize_title = #{publicizeTitle},</if>
            <if test="publicizeContent != null">publicize_content = #{publicizeContent},</if>
            <if test="isPinned != null">is_pinned = #{isPinned},</if>
            <if test="deptId != null">dept_id = #{deptId},</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 publicize_id = #{publicizeId}
    </update>

    <update id="deleteTBranchPublicizeByPublicizeId" parameterType="Long">
        update t_branch_publicize set del_flag = 2 where publicize_id = #{publicizeId}
    </update>

    <update id="deleteTBranchPublicizeByPublicizeIds" parameterType="String">
        update t_branch_publicize set del_flag = 2 where publicize_id in
        <foreach item="publicizeId" collection="array" open="(" separator="," close=")">
            #{publicizeId}
        </foreach>
    </update>
</mapper>