<?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.nantian.cloud.jljc.mapper.TNoticeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.jljc.entity.TNotice">
        <id column="id" property="id"/>
        <result column="topic" property="topic"/>
        <result column="content" property="content"/>
        <result column="remarks" property="remarks"/>
        <result column="file" property="file"/>
        <result column="sender" property="sender"/>
        <result column="sender_dept" property="senderDept"/>
        <result column="epc_str" property="epcStr"/>
        <result column="zf_dept_str" property="zfDeptStr"/>
        <result column="over_date" property="overDate"/>
        <result column="userid" property="userid"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="dept_id" property="deptId"/>
        <result column="user_dept" property="userDept"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, topic, content, remarks, file, sender, sender_dept, epc_str, zf_dept_str, over_date, userid, update_time, del_flag, dept_id, user_dept
    </sql>

    <select id="pageManager" resultType="com.nantian.cloud.jljc.entity.TNotice">
        select <include refid="Base_Column_List"></include>
        from t_notice
        where del_flag = "1"
        <if test="userDept != null and userDept != '' and userDept != '0'.toString()">
            AND user_dept = #{userDept}
        </if>
        <if test="query.topic != null and query.topic != ''">
            AND topic like concat("%",#{query.topic},"%")
        </if>
        <if test="query.sender != null and query.sender != ''">
            AND sender like concat("%",#{query.sender},"%")
        </if>
        <if test="query.senderDept != null and query.senderDept != ''">
            AND sender_dept like concat("%",#{query.senderDept},"%")
        </if>
        <if test="query.overDate != null and query.overDate != ''">
            AND #{query.overDate} > over_date
        </if>
        ORDER BY id DESC
    </select>

    <select id="pageCmp" resultType="com.nantian.cloud.jljc.entity.TNotice">
        select n.id, n.topic, n.content, n.remarks, n.file, n.sender, n.epc_str, n.over_date, n.userid, n.update_time,
        n.del_flag, n.dept_id, g.state, n.sender_dept, n.zf_dept_str
        from t_notice n
        left join t_notice_log g on n.id = g.notice_id and g.epc = #{epc} and g.del_flag = "1"
        where n.del_flag = "1" and n.epc_str like concat("%",#{epc},"%")
        <if test="query.delFlag != null and query.delFlag != ''">
            AND n.del_flag = #{query.delFlag}
        </if>
        <if test="query.topic != null and query.topic != ''">
            AND n.topic like concat("%",#{query.topic},"%")
        </if>
        <if test="query.sender != null and query.sender != ''">
            AND n.sender like concat("%",#{query.sender},"%")
        </if>
        <if test="query.senderDept != null and query.senderDept != ''">
            AND n.sender_dept like concat("%",#{query.senderDept},"%")
        </if>
        <if test="query.overDate != null and query.overDate != ''">
            AND #{query.overDate} > n.over_date
        </if>
        ORDER BY n.id DESC
    </select>

    <select id="pageGov" resultType="com.nantian.cloud.jljc.entity.TNotice">
        select n.id, n.topic, n.content, n.remarks, n.file, n.sender, n.epc_str, n.over_date, n.userid, n.update_time,
        n.del_flag, n.dept_id, g.state, n.sender_dept, n.zf_dept_str
        f from t_notice n
        left join t_notice_log g on n.id = g.notice_id and g.zf_dept_id = #{deptId} and g.zf_userid = #{userid} and
        g.del_flag = "1"
        where n.del_flag = "1" and n.zf_dept_str like concat("%",#{deptId},"%")
        <if test="userDept != null and userDept != '' and userDept != '0'.toString()">
            AND n.user_dept like concat("%",#{userDept},"%")
        </if>
        <if test="query.topic != null and query.topic != ''">
            AND n.topic like concat("%",#{query.topic},"%")
        </if>
        <if test="query.sender != null and query.sender != ''">
            AND n.sender like concat("%",#{query.sender},"%")
        </if>
        <if test="query.senderDept != null and query.senderDept != ''">
            AND n.sender_dept like concat("%",#{query.senderDept},"%")
        </if>
        <if test="query.overDate != null and query.overDate != ''">
            AND #{query.overDate} > n.over_date
        </if>
        ORDER BY n.id DESC
    </select>

    <select id="getByIdCmp" resultType="com.nantian.cloud.jljc.entity.TNotice">
        select n.id, n.topic, n.content, n.remarks, n.file, n.sender, n.epc_str, n.over_date, n.userid, n.update_time,
               n.del_flag, n.dept_id, g.state, n.sender_dept, n.zf_dept_str
        from t_notice n
        left join t_notice_log g on n.id = g.notice_id and g.epc = #{epc} and g.del_flag = "1"
        where n.id = #{id}
    </select>

    <select id="getByIdGov" resultType="com.nantian.cloud.jljc.entity.TNotice">
        select n.id, n.topic, n.content, n.remarks, n.file, n.sender, n.epc_str, n.over_date, n.userid, n.update_time,
               n.del_flag, n.dept_id, IFNULL(g.state,"F"), n.sender_dept, n.zf_dept_str
        from t_notice n
        left join t_notice_log g on n.id = g.notice_id and  g.zf_dept_id = #{deptId} and g.zf_userid = #{userid} and g.del_flag = "1"
        where n.id = #{id}
        <if test="userDept != null and userDept != '' and userDept != '0'.toString()">
            and n.user_dept = #{userDept}
        </if>
    </select>

    <select id="noCount" resultType="java.lang.Integer">
		select IFNULL(sum( case g.state when "T" then 0 else 1 end ),0) count
        from t_notice n
        left join t_notice_log g on n.id = g.notice_id and  g.epc = #{epc} and g.del_flag = "1"
        where n.del_flag = "1" and n.epc_str like concat("%",#{epc},"%")
    </select>

    <select id="noCountGov" resultType="java.lang.Integer">
        select IFNULL(sum( case g.state when "T" then 0 else 1 end ),0) count
        from t_notice n
        left join t_notice_log g on n.id = g.notice_id and  g.zf_dept_id = #{deptId} and g.zf_userid = #{userid} and g.del_flag = "1"
        where n.del_flag = "1" and n.zf_dept_str like concat("%",#{deptId},"%")
        <if test="userDept != null and userDept != '' and userDept != '0'.toString()">
            AND n.user_dept = #{userDept}
        </if>
    </select>


</mapper>
