<?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.dbcapp.mapper.jly.BelowGradeNoticeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.nantian.cloud.dbcapp.entity.BelowGradeNotice">
        <id column="id" property="id"/>
        <id column="pid" property="pid"/>
        <result column="topic" property="topic"/>
        <result column="enterprise_code" property="enterpriseCode"/>
        <result column="content" property="content"/>
        <result column="remarks" property="remarks"/>
        <result column="file" property="file"/>
        <result column="status" property="status"/>
        <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="cmpName" property="cmpName"/>
    </resultMap>

    <insert id="insertSysNotice">
        insert into jnjc.t_notice(topic, content, remarks, sender_dept, sender, epc_str, file, userid, update_time,
                                  del_flag, dept_id, user_dept, zf_dept_str)
        select topic
             , #{belowGradeNotice.content}
             , remarks
             , "云南省重点用能单位能耗在线监测平台"
             , "云南省重点用能单位能耗在线监测平台"
             , #{belowGradeNotice.enterpriseCode}
             , #{belowGradeNotice.file}
             , #{belowGradeNotice.userid}
             , #{belowGradeNotice.updateTime}
             , #{belowGradeNotice.delFlag}
             , #{belowGradeNotice.deptId}
             , #{userDept}
             , #{zfDeptStr}
        from below_grade_notice
        where id = #{belowGradeNotice.pid}
    </insert>

    <select id="getManageInfo" resultType="com.nantian.cloud.dbcapp.entity.BelowGradeNotice">
        select id, pid, topic, enterprise_code, content, remarks, file, status, userid, update_time, del_flag, dept_id
        from below_grade_notice where del_flag = 1 and pid = 0
        <if test="query.topic != null and query.topic != ''">
            and topic like concat('%',#{query.topic},'%')
        </if>
        <if test="query.content != null and query.content != ''">
            and content like concat('%',#{query.content},'%')
        </if>
        <if test="query.remarks != null and query.remarks != ''">
            and remarks like concat('%',#{query.remarks},'%')
        </if>
    </select>

    <select id="getDetailInfo" resultType="com.nantian.cloud.dbcapp.entity.BelowGradeNotice">
        select id, pid, topic, enterprise_code, content, remarks, file, status, userid, update_time, del_flag, dept_id,
        (select cmpName from enterprise_id where enterpriseCode = enterprise_code limit 0,1) cmpName
        from below_grade_notice t where del_flag = 1 and pid != 0
        <if test="query.pid != null and query.pid != ''">
            and pid = #{query.pid}
        </if>
        <if test="query.topic != null and query.topic != ''">
            and topic like concat('%',#{query.topic},'%')
        </if>
        <if test="query.content != null and query.content != ''">
            and content like concat('%',#{query.content},'%')
        </if>
        <if test="query.remarks != null and query.remarks != ''">
            and remarks like concat('%',#{query.remarks},'%')
        </if>
        <if test="query.enterpriseCode != null and query.enterpriseCode != ''">
            and enterprise_code like concat('%',#{query.enterpriseCode},'%')
        </if>
        <if test="query.cmpName != null and query.cmpName != ''">
            having cmpName like concat('%',#{query.cmpName},'%')
        </if>
    </select>

    <select id="getBelowGradeNoticeList" parameterType="string" resultMap="BaseResultMap">
        select content,
               enterprise_code,
               file,
               (select cmp_name from enterprise_info t where t.enterprise_code = e.enterprise_code limit 0,1) cmpName
        from below_grade_notice e
        where e.pid = (select id from below_grade_notice where topic = #{topic})
        and e.enterprise_code is not null
    </select>


</mapper>
