<?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="net.lab1024.sa.admin.module.business.notice.NoticeDao">
    <update id="updateWatchAmount">
        UPDATE t_notice
        SET watch_amount = watch_amount + 1
        WHERE notice_id = #{noticeId}
    </update>
    <update id="batchDeleteNotice">
        UPDATE t_notice
        SET deleted_flag = #{deletedFlag}
        WHERE notice_id IN
        <foreach collection="noticeIdList" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </update>
    <update id="updateNotice">
        UPDATE t_notice
        SET notice_type         = #{noticeType},
            notice_belong_type  = #{noticeBelongType},
            notice_title        = #{noticeTitle},
            notice_content      = #{noticeContent},
            link_address        = #{linkAddress},
            cover_file_key      = #{coverFileKey},
            accessory_file_keys = #{accessoryFileKeys},
            top_flag            = #{topFlag},
            publish_time        = #{publishTime},
            disabled_flag       = #{disabledFlag}
        WHERE notice_id = #{noticeId}
    </update>
    <select id="queryPage" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
        SELECT tn.*,
        e.actual_name AS createUserName
        FROM t_notice tn
        LEFT JOIN t_employee e ON tn.create_user_id = e.employee_id
        <where>
            tn.deleted_flag = #{queryForm.deletedFlag}
            <if test="queryForm.keywords != null and queryForm.keywords != ''">
                AND (INSTR(tn.notice_title,#{queryForm.keywords}) OR INSTR(e.actual_name,#{queryForm.keywords}))
            </if>
            <if test="queryForm.noticeType != null">
                AND tn.notice_type = #{queryForm.noticeType}
            </if>
            <if test="queryForm.noticeBelongType != null">
                AND tn.notice_belong_type = #{queryForm.noticeBelongType}
            </if>
            <if test="queryForm.startTime != null">
                AND DATE_FORMAT(tn.publish_time, '%Y-%m-%d') &gt;= #{queryForm.startTime}
            </if>
            <if test="queryForm.endTime != null">
                AND DATE_FORMAT(tn.publish_time, '%Y-%m-%d') &lt;= #{queryForm.endTime}
            </if>
            <if test="queryForm.disabledFlag != null">
                AND tn.disabled_flag = #{queryForm.disabledFlag}
            </if>
        </where>
        <if test="queryForm.sortItemList == null or queryForm.sortItemList.size == 0">
            ORDER BY tn.top_flag DESC,tn.publish_time DESC
        </if>
    </select>
    <select id="getDetail" resultType="net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeVO">
        SELECT tn.*,
               e.actual_name AS createUserName
        FROM t_notice tn
                 LEFT JOIN t_employee e ON tn.create_user_id = e.employee_id
        WHERE tn.notice_id = #{noticeId}
          AND tn.deleted_flag = #{deletedFlag}
    </select>
</mapper>