<?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.yeejoin.amos.fas.business.dao.mapper.FireRectificationMapper">
    <select id="queryFiresAndCount" resultType="com.yeejoin.amos.fas.business.bo.FireRectificationBo">
        SELECT * FROM (
        SELECT
        BILL_NO AS billno,
        STATION_SEQ AS stationNum,
        STATION_NAME AS stationName,
        ( SELECT COUNT(1) FROM ELEC_BILLS_ALARM_INFO WHERE EBD.SEQUENCE_NBR = SEQUENCE_NBR ) AS warnning,
        ( SELECT COUNT(1) FROM ELEC_BILLS_RISK_INFO WHERE EBD.SEQUENCE_NBR = SEQUENCE_NBR) AS danger,
        ( SELECT COUNT(1) FROM ELEC_BILLS_DANGER_INFO WHERE EBD.SEQUENCE_NBR = SEQUENCE_NBR ) AS hiddenTrouble,
        ( SELECT COUNT(1) FROM ELEC_BILLS_FIRE_SAFETY_CONTROL WHERE EBD.SEQUENCE_NBR = SEQUENCE_NBR ) AS adminOfFire,
        SAFETY_CHARGE_PERSON AS chargePerson,
        SAFETY_PERSON_PHONE AS chargePersonTel,
        date_format(REQUIREMENT_DATE,'%Y / %m / %d') AS completionDate,
        REQUIREMENT_DATE,
        date_format(ACTUAL_FINISH_DATE,'%Y / %m / %d') AS reCompletionDate,
        STATUS AS statuscode,
        if(STATUS=1,'未处理','已完成') AS status
        FROM
        ELEC_BILLS_BASIC_INFO  EBD
        where STATUS = 1 or STATUS = 2
        ORDER BY REQUIREMENT_DATE) BDATA
        where 1=1
        <if test="nameLike != null ">
            and billno like CONCAT('%',#{nameLike},'%')
        </if>
        <if test="sDate != 'null'  and sDate != '1970-1-1' ">
            and   STR_TO_DATE(REQUIREMENT_DATE,'%Y-%m-%d') >= STR_TO_DATE(#{sDate},'%Y-%m-%d')
        </if>
        <if test="eDate  != 'null' and eDate != '1970-1-1' ">
            and   STR_TO_DATE(#{eDate},'%Y-%m-%d') >=STR_TO_DATE(REQUIREMENT_DATE,'%Y-%m-%d')
        </if>
        <if test="states != 0 ">
            and statuscode = #{states}
        </if>
        LIMIT #{spage},#{pageSize}
    </select>
    <select id="countQueryFireList" resultType="long">
        SELECT COUNT(1) FROM (
        SELECT
        BILL_NO AS billno,
        REQUIREMENT_DATE,
        STATUS
        FROM
        ELEC_BILLS_BASIC_INFO  EBD
        where STATUS = 1 or STATUS = 2
        ORDER BY REQUIREMENT_DATE) BDATA
        where 1=1
        <if test="nameLike != null ">
            and billno like CONCAT('%',#{nameLike},'%')
        </if>
        <if test="sDate != 'null'  and sDate != '1970-1-1' ">
            and   STR_TO_DATE(REQUIREMENT_DATE,'%Y-%m-%d') >= STR_TO_DATE(#{sDate},'%Y-%m-%d')
        </if>
        <if test="eDate  != 'null' and eDate != '1970-1-1' ">
            and   STR_TO_DATE(#{eDate},'%Y-%m-%d') >=STR_TO_DATE(REQUIREMENT_DATE,'%Y-%m-%d')
        </if>
        <if test="states != 0 ">
            and STATUS = #{states}
        </if>
    </select>
    <select id="selectOneForBase" resultType="com.yeejoin.amos.fas.business.bo.FireRectificationBo">
        select
            BILL_NO AS billNo,
            STATION_NAME AS stationName,
            DISTRIBUTION_USER_NAME AS disUser,
            DISTRIBUTION_DATE AS disDate,
            STATION_CHARGE_PERSON AS stationUser,
            CHARGE_PERSON_PHONE AS stationUserTel,
            SAFETY_CHARGE_PERSON AS safeUser,
            SAFETY_PERSON_PHONE AS safeUserTel,
            REQUIREMENT_DATE AS reqDate,
            if(ACTUAL_FINISH_DATE is null, date_format(sysdate(),'%Y-%m-%d')  ,ACTUAL_FINISH_DATE) AS finishDate,
            REFORM_RESULT AS refResult,
            VIEWS_AND_SUGGESTIONS AS viewsAndSuggestions,
            FEEDBACK_RESULT AS backResult,
            STATUS AS status
         from
         elec_bills_basic_info EBD
         where BILL_NO = #{billNo}
    </select>
    <select id="selectOneForEmergency" resultType="com.yeejoin.amos.fas.business.bo.FireMoreDataBo">
        select
             SEQUENCE_NBR as req,
             FIRE_EQUIPMENT_NAME AS name,
             ALARM_DESC AS persent,
             HANDLE_STATE AS doneResult,
              FILE_PATH as filePath
             from
             elec_bills_alarm_info
              where BILL_SEQ = (select SEQUENCE_NBR from elec_bills_basic_info where BILL_NO=#{billNo})
    </select>
    <select id="selectOneForDanger" resultType="com.yeejoin.amos.fas.business.bo.FireMoreDataBo">
         select
                    SEQUENCE_NBR as req,
                    LEVEL_NAME AS lvl,
                    POINT_NAME AS persent,
                    RISK_FACTOR_NAME AS affect,
                    FEEDBACK AS backResult
                    from
                    elec_bills_risk_info
                     where BILL_SEQ = (select SEQUENCE_NBR from elec_bills_basic_info where BILL_NO=#{billNo})
    </select>
    <select id="selectOneForHidden" resultType="com.yeejoin.amos.fas.business.bo.FireMoreDataBo">
        select
                    SEQUENCE_NBR as req,
                    if(DANGER_LEVEL=1,'一般隐患','重大隐患') AS lvl,
                    DANGER_NAME AS persent,
                    INPUT_ITEM_NAME AS affect,
                   HANDLE_STATE  AS doneResult,
                   FILE_PATH as filePath
                    from
                    elec_bills_danger_info
                    where BILL_SEQ = (select SEQUENCE_NBR from elec_bills_basic_info where BILL_NO=#{billNo})
    </select>
    <select id="selectOneForfire" resultType="com.yeejoin.amos.fas.business.bo.FireInfoBo">
         select
                 TYPE AS type,
                 ACTUAL_NUMBER AS realNum,
                 THRESHOLD AS threshold
                 from
                 elec_bills_fire_safety_control
                where BILL_SEQ = (select SEQUENCE_NBR from elec_bills_basic_info where BILL_NO=#{billNo})
                and type =${id}
    </select>
    <update id="updateBill">
         UPDATE
             ELEC_BILLS_BASIC_INFO
             SET STATUS = 2,
              REFORM_RESULT =#{refResult} ,
              FEEDBACK_RESULT =#{backResult}
             where BILL_NO = #{billNo}
    </update>
    <update id="updateWarnning">
         UPDATE
             ELEC_BILLS_ALARM_INFO
             SET
              HANDLE_STATE =#{doneResult} ,
              FILE_PATH =#{filePath}
             where SEQUENCE_NBR = #{req}
    </update>
    <update id="updateHidden">
        UPDATE
             ELEC_BILLS_DANGER_INFO
             SET
              HANDLE_STATE =#{doneResult} ,
              FILE_PATH =#{filePath}
             where SEQUENCE_NBR = #{req}

    </update>
    <update id="updateDanger">
   UPDATE
             ELEC_BILLS_RISK_INFO
             SET
              FEEDBACK =#{backResult}
             where SEQUENCE_NBR = #{req}

    </update>
</mapper>