<?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.project.sems.mapper.TSpecReportMapper">

    <resultMap type="TSpecReport" id="TSpecReportResult">
        <result property="id"    column="id"    />
        <result property="reportName"    column="report_name"    />
        <result property="reportUrl"    column="report_url"    />
        <result property="detailUrl"    column="detail_url"    />
        <result property="reportType"    column="report_type"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTSpecReportVo">
        select d.id, d.report_name, d.report_url, d.detail_url, d.report_type, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_spec_report d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSpecReportList" parameterType="TSpecReport" resultMap="TSpecReportResult">
        <include refid="selectTSpecReportVo"/>
        <where>
            <if test="reportName != null  and reportName != ''"> and report_name like concat(concat('%', #{reportName}), '%')</if>
            <if test="reportUrl != null  and reportUrl != ''"> and report_url = #{reportUrl}</if>
            <if test="detailUrl != null  and detailUrl != ''"> and detail_url = #{detailUrl}</if>
            <if test="reportType != null "> and report_type = #{reportType}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        order by d.createdate desc
    </select>

    <select id="selectExpriedYlrq" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum ,Max(id) AS id
        FROM T_SPECDEV_YLRQ
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedYlgd" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum,Max(id) AS id
        FROM T_SPECDEV_YLGD
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedGl" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum,Max(id) AS id
        FROM T_SPECDEV_GL
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedDt" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum,Max(id) AS id
        FROM T_SPECDEV_DT
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedDzsb" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum,Max(id) AS id
        FROM T_SPECDEV_DZSB
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedCc" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum,Max(id) AS id
        FROM T_SPECDEV_CC
        WHERE SYSDATE  >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>


    <select id="selectExpriedYlrq3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_YLRQ
        WHERE SYSDATE + INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedYlgd3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_YLGD
        WHERE SYSDATE + INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedGl3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_GL
        WHERE SYSDATE+ INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedDt3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_DT
        WHERE SYSDATE+ INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedDzsb3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_DZSB
        WHERE SYSDATE+ INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>
    <select id="selectExpriedCc3" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code as plantCode, COUNT(*) as devNum
        FROM T_SPECDEV_CC
        WHERE SYSDATE+ INTERVAL '3' MONTH   >  NEXT_WARN_DATE and DEL_FLAG = 0 and STATUS = 1
        GROUP BY plant_code
    </select>

    <select id="selectExpriedYlrqHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_YLRQ
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>
    <select id="selectExpriedYlgdHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_YLGD
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>
    <select id="selectExpriedGlHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_GL
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>
    <select id="selectExpriedDtHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_DT
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM')  and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>
    <select id="selectExpriedDzsbHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_DZSB
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>
    <select id="selectExpriedCcHi" parameterType="TSpecReport" resultMap="TSpecReportResult">
        SELECT plant_code AS plantCode, COUNT(*) AS devNum, OPER_TYPE AS remarks
        FROM T_SPECHI_CC
        WHERE OPER_TIME >= TRUNC(ADD_MONTHS(SYSDATE, -1), 'MM') and OPER_TYPE in ('新增-通过','删除-通过','停用批准','注销批准')
        GROUP BY plant_code,OPER_TYPE
    </select>


    <select id="selectTSpecReportById" parameterType="Long" resultMap="TSpecReportResult">
        <include refid="selectTSpecReportVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSpecReport" parameterType="TSpecReport">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_spec_report.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_spec_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="reportName != null">report_name,</if>
            <if test="reportUrl != null">report_url,</if>
            <if test="detailUrl != null">detail_url,</if>
            <if test="reportType != null">report_type,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="reportName != null">#{reportName},</if>
            <if test="reportUrl != null">#{reportUrl},</if>
            <if test="detailUrl != null">#{detailUrl},</if>
            <if test="reportType != null">#{reportType},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTSpecReport" parameterType="TSpecReport">
        update t_spec_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="reportName != null">report_name = #{reportName},</if>
            <if test="reportUrl != null">report_url = #{reportUrl},</if>
            <if test="detailUrl != null">detail_url = #{detailUrl},</if>
            <if test="reportType != null">report_type = #{reportType},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTSpecReportById" parameterType="Long">
        update t_spec_report set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTSpecReportByIds" parameterType="String">
        update t_spec_report set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
