<?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.shcd.mapper.SpStatementInlandLowMapper">

  <resultMap id="BaseResultMap" type="com.shcd.entity.SpStatementInlandLow">
    <result property="id" column="ID" jdbcType="VARCHAR"/>
    <result property="district" column="DISTRICT" jdbcType="VARCHAR"/>
    <result property="boatUseNumberMonth" column="BOAT_USE_NUMBER_MONTH" jdbcType="DECIMAL"/>
    <result property="boatUseNumberChain" column="BOAT_USE_NUMBER_CHAIN" jdbcType="DECIMAL"/>
    <result property="boatUseNumberYearTotal" column="BOAT_USE_NUMBER_YEAR_TOTAL"
      jdbcType="DECIMAL"/>
    <result property="powerConnHoursMonth" column="POWER_CONN_HOURS_MONTH" jdbcType="DECIMAL"/>
    <result property="powerConnHoursYearTotal" column="POWER_CONN_HOURS_YEAR_TOTAL"
      jdbcType="DECIMAL"/>
    <result property="electricityUsageMonth" column="ELECTRICITY_USAGE_MONTH" jdbcType="DECIMAL"/>
    <result property="electricityUsageYearTotal" column="ELECTRICITY_USAGE_YEAR_TOTAL"
      jdbcType="DECIMAL"/>
    <result property="sort" column="SORT" jdbcType="DECIMAL"/>
    <result property="owningArea" column="OWNING_AREA" jdbcType="VARCHAR"/>
    <result property="deleteFlag" column="DELETE_FLAG" jdbcType="DECIMAL"/>
    <result property="createUser" column="CREATE_USER" jdbcType="VARCHAR"/>
    <result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
    <result property="reportDate" column="REPORT_DATE" jdbcType="TIMESTAMP"/>
    <result property="type" column="TYPE" jdbcType="DECIMAL"/>
    <result property="column2" column="COLUMN2" jdbcType="VARCHAR"/>
    <result property="column3" column="COLUMN3" jdbcType="VARCHAR"/>
    <result property="column4" column="COLUMN4" jdbcType="VARCHAR"/>
  </resultMap>
  <delete id="deleteAllCurrentMonthReport1" parameterType="String">
    DELETE
    FROM GHJG_PORT_MANAGE.SP_STATEMENT_INLAND_LOW T
    WHERE T.TYPE = 1
      AND T.REPORT_DATE = TO_DATE(#{reportDate}, 'yyyy-MM')
  </delete>
  <delete id="deleteAllCurrentMonthReport2">
    DELETE
    FROM GHJG_PORT_MANAGE.SP_STATEMENT_INLAND_LOW T
    WHERE T.TYPE = 2
      AND T.REPORT_DATE = TO_DATE(#{reportDate}, 'yyyy-MM')
  </delete>

  <select id="getOriginDataFromPage" resultType="com.shcd.entity.ShorePowerDeviceUsage">
    select T.* from GHJG_PORT_MANAGE.SHORE_POWER_DEVICE_USAGE T
    where T.Delete_Flag = 0
    <if test="district != '' and district != null">
      and T.DISTRICT = #{district}
    </if>
    <if test="owningArea != '' and owningArea != null">
      and T.Owning_Area = #{owningArea}
    </if>
    <if test="reportDateStart != '' and reportDateStart != null">
      and T.Report_Date &gt;= to_date(#{reportDateStart},'yyyy-MM')
    </if>
    <if test="reportDateEnd != '' and reportDateEnd != null">
      and T.Report_Date &lt;= to_Date(#{reportDateEnd},'yyyy-MM')
    </if>
    order by T.Sort asc,T.OWNING_AREA desc
  </select>


  <select id="getCurrentYearOriginDataFromPage" resultType="com.shcd.entity.ShorePowerDeviceUsage">
    SELECT T.DISTRICT                         district,
           SUM(T.SHORE_POWER_BOAT_USE_NUMBER) shorePowerBoatUseNumber,
           SUM(T.POWER_CONN_HOURS)            powerConnHours,
           SUM(T.ELECTRICITY_CONSUMPTION)     electricityConsumption
    FROM GHJG_PORT_MANAGE.SHORE_POWER_DEVICE_USAGE T
    WHERE EXTRACT(YEAR FROM T.REPORT_DATE) = EXTRACT(YEAR FROM SYSDATE)
    GROUP BY T.DISTRICT
  </select>

  <select id="getLastMonthReportData" parameterType="String"
    resultType="com.shcd.entity.SpStatementInlandLow">
    SELECT T.*
    FROM GHJG_PORT_MANAGE.SP_STATEMENT_INLAND_LOW T
    WHERE T.DELETE_FLAG = 0
    AND T.DISTRICT = '合计'
    <if test="date != '' and date != null">
      and T.Report_Date &gt;= to_date(#{date},'yyyy-MM') and T.Report_Date &lt;=
      to_Date(#{date},'yyyy-MM')
    </if>
    <if test="type != '' and type != null">
      AND T.TYPE = ${type}
    </if>
  </select>


  <select id="selectDataFromShorePower" resultType="com.shcd.vo.ShorePowerConnRecordInfoVo">
    SELECT PORT.AREA area,
    SUM(T.ELECT) elect,
    SUM(ROUND((T.ENDTIME - T.STARTTIME) * 24, 2)) duration,
    COUNT(T.CONNRECORDSEQ) total
    FROM GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO T
    LEFT JOIN GHJG_PORT_MANAGE.SHORE_POWER_PORT_INFO_NEW PORT
    ON PORT.PORTID = T.PORTID
    WHERE (T.CONNTYPE = '低压(标准化)'
    AND PORT.AREA is not null
    and PORT.AREA != 1
    AND PORT.PORTID != '1146')
    AND ((T.ENDTIME &lt;=
    TO_DATE(#{reportDateEnd}, 'yyyy-MM-dd HH24:mi:ss')
    AND T.ENDTIME &gt;=
    TO_DATE(#{reportDateStart}, 'yyyy-MM-dd HH24:mi:ss'))
    <if
      test="lastReportDateEnd != '' and lastReportDateEnd != null and lastReportDateStart != '' and lastReportDateStart != null">
      OR (T.ENDTIME &lt;= TO_DATE(#{lastReportDateEnd}, 'yyyy-MM-dd HH24:mi:ss') AND
      T.ENDTIME &gt;=
      TO_DATE(#{lastReportDateStart}, 'yyyy-MM-dd HH24:mi:ss') AND T.MODIFYTIME &lt;=
      TO_DATE(#{reportDateEnd}, 'yyyy-MM-dd HH24:mi:ss')
      AND T.MODIFYTIME &gt;=
      TO_DATE(#{reportDateStart}, 'yyyy-MM-dd HH24:mi:ss') AND T.CONNTYPE != '低压(标准化)')
    </if>
    )
    GROUP BY PORT.AREA
  </select>

  <select id="selectDataFromShorePowerV2" resultType="com.shcd.vo.ShorePowerConnRecordInfoVo">
    SELECT PORT.AREA area,
    SUM(T.ELECT) elect,
    SUM(ROUND(DURATION / 60,2)) duration,
    COUNT(T.CONNRECORDSEQ) total
    FROM GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO T
    LEFT JOIN GHJG_PORT_MANAGE.SHORE_POWER_PORT_INFO_NEW PORT
    ON PORT.PORTID = T.PORTID
    WHERE (T.CONNTYPE = '低压(标准化)'
    AND PORT.AREA is not null
    and PORT.AREA != 1
    AND PORT.PORTID != '1146')
    AND ((T.ENDTIME &lt;=
    TO_DATE(#{reportDateEnd}, 'yyyy-MM-dd HH24:mi:ss')
    AND T.ENDTIME &gt;=
    TO_DATE(#{reportDateStart}, 'yyyy-MM-dd HH24:mi:ss'))
    )
    GROUP BY PORT.AREA
  </select>


  <select id="selectCurrentYearDataFromShorePower"
    resultType="com.shcd.vo.ShorePowerConnRecordInfoVo">
    SELECT PORT.AREA              area,
           SUM(T.ELECT)           elect,
           SUM(T.DURATION)        duration,
           COUNT(T.CONNRECORDSEQ) total
    FROM GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO T
           LEFT JOIN GHJG_PORT_MANAGE.SHORE_POWER_PORT_INFO_NEW PORT ON PORT.PORTID = T.PORTID
    WHERE EXTRACT(YEAR FROM T.Modifytime) = EXTRACT(YEAR FROM SYSDATE)
      and T.CONNTYPE = '低压'
    GROUP BY PORT.AREA
  </select>


    <select id="getAllLastMonthReportData" parameterType="String"
    resultType="com.shcd.entity.SpStatementInlandLow">
      SELECT T.*
      FROM GHJG_PORT_MANAGE.SP_STATEMENT_INLAND_LOW T
      WHERE T.DELETE_FLAG = 0
      <if test="date != '' and date != null">
        and T.Report_Date &gt;= to_date(#{date},'yyyy-MM') and T.Report_Date &lt;=
        to_Date(#{date},'yyyy-MM')
      </if>
      <if test="type != '' and type != null">
        AND T.TYPE = ${type}
      </if>
    </select>

</mapper>
