<?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.cms.mapper.NoticeMapper">

    <sql id="selectNoticeleVo">
        select notice_id, title,sub_title, notice_type, notice_content, is_read,user_id,not_read_count,date, del_flag, create_by, create_time, update_by, remark,bussiness_id from notice
    </sql>

    <select id="getNoticlist" parameterType="com.ruoyi.cms.domain.Notice" resultType="com.ruoyi.cms.domain.Notice">
        <include refid="selectNoticeleVo"/>
        <where>  del_flag = '0'
            <if test="noticeType != null "> and notice_type = #{noticeType}</if>
            <if test="isRead != null "> and is_read = #{isRead}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="bussinessId != null "> and bussiness_id = #{bussinessId}</if>
            <if test="remark != null "> and remark = #{remark}</if>
        </where>
        order by is_read,create_time desc
    </select>

    <select id="noticTotal" parameterType="com.ruoyi.cms.domain.Notice" resultType="com.ruoyi.cms.domain.vo.NoticeTotal">
        select count(user_id) qbxx,sum(case when is_read='0' then 1 else 0 end)
            wdxx from notice where del_flag='0'
           <if test="userId!=null">
               and user_id=#{userId}
           </if>
    </select>

    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO notice (
        title, notice_type, notice_content,is_read,user_id,sub_title,not_read_count,date,bussiness_id,
        create_by, create_time, del_flag,remark
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.title}, #{item.noticeType}, #{item.noticeContent},#{item.isRead},#{item.userId},#{item.subTitle},
            #{item.notReadCount},sysdate(),#{item.bussinessId},
            #{item.createBy}, #{item.createTime}, #{item.delFlag},#{item.remark}
            )
        </foreach>
    </insert>
</mapper>