<?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.operatingmanage.TOperatingmanageNoticeMapper">

    <resultMap type="com.ruoyi.system.domain.operatingmanage.TOperatingmanageNotice" id="TOperatingmanageNoticeResult">
        <result property="noticeId"    column="notice_id"    />
        <result property="noticeTitle"    column="notice_title"    />
        <result property="noticeSource"    column="notice_source"    />
        <result property="noticeTop"    column="notice_top"    />
        <result property="noticeContent"    column="notice_content"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="valid"    column="valid"    />
        <result property="createCode"    column="create_code" />
    </resultMap>

    <sql id="selectTOperatingmanageNoticeVo">
        select notice_id, notice_title, notice_source, notice_top, notice_content, create_by, create_time, update_by, update_time,  valid, create_code from t_operatingmanage_notice notice
    </sql>

    <select id="list" parameterType="com.ruoyi.system.domain.operatingmanage.TOperatingmanageNotice" resultMap="TOperatingmanageNoticeResult">
        <include refid="selectTOperatingmanageNoticeVo"/>
        <where>
            <if test="noticeTitle != null  and noticeTitle != ''"> and notice_title like concat('%', #{noticeTitle}, '%')</if>
            <if test="noticeSource != null  and noticeSource != ''"> and notice_source = #{noticeSource}</if>
            <if test="noticeTop != null "> and notice_top = #{noticeTop}</if>
            <if test="noticeContent != null  and noticeContent != ''"> and notice_content = #{noticeContent}</if>
            <if test="createBy != null  and createBy != ''"> and create_by = #{createBy}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateBy != null  and updateBy != ''"> and update_by = #{updateBy}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="valid != null "> and valid = #{valid}</if>
            <if test="createCode != null "> and create_code = #{createCode}</if>
            <if test="noticeRange != null and noticeRange.size() > 0">
                and exists(
                    select 1
                    from t_operatingmanage_notice_range f
                    where notice.notice_id=f.notice_id
                    and grid_code in
                    <foreach collection="noticeRange" item="range" separator="," open="(" close=")">
                        #{range.gridCode}
                    </foreach>
                )
            </if>
        </where>
        order by notice_top desc, notice_id desc
    </select>

    <select id="getObjectById"  resultMap="TOperatingmanageNoticeResult">
        <include refid="selectTOperatingmanageNoticeVo"/>
        where notice_id = #{id}
    </select>

    <insert id="save" parameterType="com.ruoyi.system.domain.operatingmanage.TOperatingmanageNotice" useGeneratedKeys="true" keyProperty="noticeId">
        insert into t_operatingmanage_notice
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="noticeId != null">notice_id,</if>
            <if test="noticeTitle != null">notice_title,</if>
            <if test="noticeSource != null">notice_source,</if>
            <if test="noticeTop != null">notice_top,</if>
            <if test="noticeContent != null">notice_content,</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>
            <if test="valid != null">valid,</if>
            <if test="createCode != null">create_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="noticeId != null">#{noticeId},</if>
            <if test="noticeTitle != null">#{noticeTitle},</if>
            <if test="noticeSource != null">#{noticeSource},</if>
            <if test="noticeTop != null">#{noticeTop},</if>
            <if test="noticeContent != null">#{noticeContent},</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>
            <if test="valid != null">#{valid},</if>
            <if test="createCode != null">#{createCode},</if>
         </trim>
    </insert>

    <update id="update" parameterType="com.ruoyi.system.domain.operatingmanage.TOperatingmanageNotice">
        update t_operatingmanage_notice
        <trim prefix="SET" suffixOverrides=",">
            <if test="noticeTitle != null">notice_title = #{noticeTitle},</if>
            <if test="noticeSource != null">notice_source = #{noticeSource},</if>
            <if test="noticeTop != null">notice_top = #{noticeTop},</if>
            <if test="noticeContent != null">notice_content = #{noticeContent},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},update_time = NOW(),</if>
            <if test="valid != null">valid = #{valid},</if>
            <if test="createCode != null">create_code = #{createCode},</if>
        </trim>
        where notice_id = #{noticeId}
    </update>

    <delete id="remove">
        delete from t_operatingmanage_notice
        where notice_id = #{noticeId}
    </delete>

    <delete id="batchRemove">
        delete from t_operatingmanage_notice where
        notice_id in
        <foreach item="noticeId" collection="noticeId" open="(" separator="," close=")">
            #{noticeId}
        </foreach>
    </delete>

</mapper>
