<?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.xjrsoft.module.oa.mapper.NewsMapper">
    <select id="manageBox" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
            resultType="com.xjrsoft.module.oa.vo.NewsPageVo">
        select
        t.*,
        t2.name as classIdCN
        from xjr_oa_news t
        where t.delete_mark = 0
        <if test="dto.type != null and dto.type > 0">
            and t.type_id = #{dto.type}
        </if>
        <if test="dto.type != null and dto.type = 1">
            and t.wf_status = 1
        </if>
        <if test="dto.fullHead != null and dto.fullHead != ''">
            and t.full_head LIKE CONCAT('%',#{dto.fullHead},'%')
        </if>
        <if test="dto.loginId != null and dto.loginId > 0">
            and t.create_user_id = #{dto.loginId}
        </if>
        <if test="dto.keyword != null and dto.keyword != ''">
            and (t.full_head LIKE CONCAT('%',#{dto.keyword},'%')
            or t.news_content LIKE CONCAT('%',#{dto.keyword},'%'))
        </if>
        order by t.release_time desc
    </select>

    <select id="receiptBox" parameterType="com.xjrsoft.module.oa.dto.NewsPageDto"
            resultType="com.xjrsoft.module.oa.vo.NewsPageVo">
        select
        t.*,t2.name as create_user_name
        from xjr_oa_news t
        left join xjr_user t2 on t.create_user_id = t2.id
        where t.delete_mark = 0 and
        (t.send_end_date > now() or t.send_end_date is null)
          and t.status = 2
        <if test="dto.type != null and dto.type == 2 and dto.loginId != null">
            and (t.send_range = 1 or t.id in (select news_id from xjr_oa_news_relation t1 where user_id = #{dto.loginId}))
        </if>
        <if test="dto.type != null and dto.type == 1">
            and t.wf_status = 1
        </if>
        <if test="dto.type != null and dto.type > 0">
            and t.type_id = #{dto.type}
        </if>
        <if test="dto.fullHead != null and dto.fullHead != ''">
            and t.full_head LIKE CONCAT('%',#{dto.fullHead},'%')
        </if>
        <if test="dto.keyword != null and dto.keyword != ''">
            and (t.full_head LIKE CONCAT('%',#{dto.keyword},'%')
                or t.news_content LIKE CONCAT('%',#{dto.keyword},'%'))
        </if>
        order by
        t.release_time desc
    </select>

    <select id="getDeptIdOrClassId" parameterType="java.util.List"
            resultType="com.xjrsoft.module.oa.vo.DeptIdOrClassIdVo">
        select
            t.id as userId,
            t2.id as deptId,
            t3.id as classId
        from xjr_user t
                 left join xjr_user_dept_relation t1 on t1.user_id = t.id
                 LEFT JOIN xjr_department t2 ON t2.id = t1.dept_id
                 left join base_student_school_roll t3 on t3.user_id = t.id
                 left join base_class t4 on t4.id = t3.class_id
        where t.delete_mark = 0
        <if test="personalIdList != null and personalIdList.size() > 0">
            and t.id in
            <foreach item="userId" index="index" collection="personalIdList" open="(" close=")"
                     separator=",">
                #{userId}
            </foreach>
        </if>
    </select>
</mapper>