<?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.SpStatementShipUsageMonthMapper">

  <resultMap id="BaseResultMap" type="com.shcd.entity.SpStatementShipUsageMonth">
    <result property="reportDate" column="REPORT_DATE" jdbcType="TIMESTAMP"/>
    <result property="shipUsageYear" column="SHIP_USAGE_YEAR" jdbcType="DECIMAL"/>
    <result property="shorePowerTimeMonth" column="SHORE_POWER_TIME_MONTH" jdbcType="DECIMAL"/>
    <result property="shorePowerTimeYear" column="SHORE_POWER_TIME_YEAR" jdbcType="DECIMAL"/>
    <result property="shorePowerCountMonth" column="SHORE_POWER_COUNT_MONTH" jdbcType="DECIMAL"/>
    <result property="shorePowerCountYear" column="SHORE_POWER_COUNT_YEAR" jdbcType="DECIMAL"/>
    <result property="dataSource" column="DATA_SOURCE" jdbcType="DECIMAL"/>
    <result property="shipUsageMonth" column="SHIP_USAGE_MONTH" jdbcType="DECIMAL"/>
  </resultMap>
  <delete id="deleteByDate">
    delete
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    where trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
  </delete>
  <select id="selectOriginDataMonth" resultType="com.shcd.vo.SpStatementShipUsageDetail">
    select ENTERPRISESNAME enterprisesName,STARTTIME chargeStartDate, ENDTIME chargeEndDate, ELECT shorePowerCount, CONNTYPE connectType, DURATION duration
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO
    where (ENDTIME between #{lastDate} and #{thisDate})
  </select>
  <select id="selectGhDataMonth" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select decode(sum(SHORE_POWER_BOAT_USE_NUMBER), null, 0,
                  sum(SHORE_POWER_BOAT_USE_NUMBER))                      shipUsage,
           decode(sum(POWER_CONN_HOURS), null, 0, sum(POWER_CONN_HOURS)) shorePowerTime,
           decode(sum(ELECTRICITY_CONSUMPTION), null, 0,
                  sum(ELECTRICITY_CONSUMPTION))                          shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_DEVICE_USAGE
    where trunc(REPORT_DATE) = #{thisDate}
  </select>
  <select id="selectOriginDataYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SHIP_USAGE_YEAR        shipUsage,
           SHORE_POWER_COUNT_YEAR shorePowerCount,
           SHORE_POWER_TIME_YEAR  shorePowerTime
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    where trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
      and DATA_SOURCE = 0
  </select>
  <select id="selectGhDataYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SHIP_USAGE_YEAR        shipUsage,
           SHORE_POWER_COUNT_YEAR shorePowerCount,
           SHORE_POWER_TIME_YEAR  shorePowerTime
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    where trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
      and DATA_SOURCE = 10
  </select>
  <select id="getInRiverDataBeforeThisMonth" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SHIP_USAGE_YEAR        shipUsage,
           SHORE_POWER_COUNT_YEAR shorePowerCount,
           SHORE_POWER_TIME_YEAR  shorePowerTime
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    WHERE trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
      AND DATA_SOURCE = 1
  </select>
  <select id="getUnderLineMonthData" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select ship_usage shipUsage, power_time_use shorePowerTime, power_elec_use shorePowerCount
    from GHJG_PORT_MANAGE.SP_STATEMENT_UNDERLINE
    where trunc(REPORT_DATE) = #{toDate}
      and NAME = '上海市黄浦江码头岸线建设管理有限公司'
  </select>

    <select id="selectUnderLineYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
        select SHIP_USAGE_YEAR        shipUsage,
               SHORE_POWER_COUNT_YEAR shorePowerCount,
               SHORE_POWER_TIME_YEAR  shorePowerTime
        from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
        where trunc(REPORT_DATE) = to_date(#{lastDate}, 'yyyy-mm-dd')
          and DATA_SOURCE = 20
    </select>
  <select id="getUnderLineYearData" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SUM(ship_usage)     shipUsage,
           SUM(power_time_use) shorePowerTime,
           SUM(power_elec_use) shorePowerCount
    from GHJG_PORT_MANAGE.SP_STATEMENT_UNDERLINE
    where trunc(REPORT_DATE) >= #{yearCountBegin}
      and trunc(REPORT_DATE) &lt;= #{yearCountEnd}
      and NAME = '上海市黄浦江码头岸线建设管理有限公司'
  </select>
  <select id="selectOriginSelfDataMonth" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select sum(USE_COUNT)       shipUsage,
           sum(USE_ELECTRICITY) shorePowerCount,
           sum(ELE_TIME)        shorePowerTime
    from GHJG_PORT_MANAGE.Shore_Power_Blberthmonthuse
    where MODIFY_TIME >= #{lastDate}
      and MODIFY_TIME &lt;= #{thisDate}
  </select>
  <select id="selectOriginSelfDataYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select sum(USE_COUNT)       shipUsage,
           sum(ELE_TIME)        shorePowerCount,
           sum(USE_ELECTRICITY) shorePowerTime
    from GHJG_PORT_MANAGE.Shore_Power_Blberthmonthuse
    where MODIFY_TIME >= #{yearCountBegin}
      and MODIFY_TIME &lt;= #{yearCountEnd}
  </select>
  <select id="selectQuarterOrigin" resultType="com.shcd.vo.SpQuarterReportOriginVo">
    select b.BERTHTYPE, b.CAPACITY, i.STARTTIME, i.ENDTIME, i.ELECT
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO i
           left join GHJG_PORT_MANAGE.SHORE_POWER_BERTH_INFO_NEW b on i.BERTHID = b.BERTHID
    where b.BERTHTYPE is not null
      AND (i.ENDTIME >= #{startDate}
      AND i.ENDTIME &lt;= #{endDate})
  </select>
  <select id="selectQuarterBlBerth" resultType="com.shcd.vo.SpQuarterReportBlVo">
    select B.BERTH_TYPE      berthType,
           b.TONNAGE         capacity,
           m.USE_COUNT       useCount,
           m.ELE_TIME        elect,
           m.USE_ELECTRICITY useElectricity
    from GHJG_PORT_MANAGE.SHORE_POWER_BLBERTHMONTHUSE m
           left join
         GHJG_PORT_MANAGE.SHORE_POWER_CHDEVICEFBO b on m.USER_BERTH_ID = b.ID
    where m.MODIFY_TIME >= #{startDate}
      and m.MODIFY_TIME &lt;= #{endDate}
      AND b.BERTH_TYPE is not null
  </select>
  <select id="selectWgqMonth" resultType="com.shcd.vo.SpStatementShipUsageDetail">
    select STARTTIME chargeStartDate, ENDTIME chargeEndDate, ELECT shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO
    where ((ENDTIME between #{lastDate} and #{thisDate}) OR
           (ENDTIME between #{lastCycleStart} and #{lastCycleEnd} AND
            MODIFYTIME between #{lastDate} and #{thisDate}))
      and ENTERPRISESNAME in ('上海外高桥发电有限责任公司', '上海外高桥第二发电有限责任公司',
                              '上海外高桥第三发电有限责任公司')
  </select>
  <select id="selectWgqYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SHIP_USAGE_YEAR        shipUsage,
           SHORE_POWER_COUNT_YEAR shorePowerCount,
           SHORE_POWER_TIME_YEAR  shorePowerTime
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    where trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
      and DATA_SOURCE = 100
  </select>
    <select id="selectylgdrlYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
        select SHIP_USAGE_YEAR        shipUsage,
               SHORE_POWER_COUNT_YEAR shorePowerCount,
               SHORE_POWER_TIME_YEAR  shorePowerTime
        from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
        where trunc(REPORT_DATE) = to_date(#{toDate}, 'yyyy-mm-dd')
          and DATA_SOURCE = 103
    </select>
  <select id="getInRiverDataThisMonth" resultType="com.shcd.vo.SpStatementShipUsageDetail">
    select STARTTIME chargeStartDate, ENDTIME chargeEndDate, ELECT shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO i
           left join GHJG_PORT_MANAGE.SHORE_POWER_PORT_INFO_NEW b on B.PORTID = i.PORTID
    where ((ENDTIME between #{lastDate} and #{thisDate}) OR
           (ENDTIME between #{lastCycleStart} and #{lastCycleEnd} AND
            MODIFYTIME between #{lastDate} and #{thisDate}))
      and (CONNTYPE = '低压(标准化)' and area >= 2 AND b.AREA &lt;= 12)
  </select>
  <select id="getInRiverDataSelfThisMonth" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select sum(USE_COUNT)       shipUsage,
           sum(ELE_TIME)        shorePowerCount,
           sum(USE_ELECTRICITY) shorePowerTime
    from GHJG_PORT_MANAGE.Shore_Power_Blberthmonthuse b
           left join GHJG_PORT_MANAGE.SHORE_POWER_CHDEVICEFBO c on b.USER_BERTH_ID = c.ID
    where b.MODIFY_TIME >= #{lastDate}
      and b.MODIFY_TIME &lt;= #{thisDate}
      and c.AREA >= 2
      AND c.AREA &lt;= 12
  </select>
  <select id="getUnderLineMonthDataSg" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select ship_usage shipUsage, power_time_use shorePowerTime, power_elec_use shorePowerCount
    from GHJG_PORT_MANAGE.SP_STATEMENT_UNDERLINE
    where trunc(REPORT_DATE) = #{toDate}
      and NAME = '上海国际港务（集团）股份有限公司'
  </select>
  <select id="getUnderLineMonthDataSgNew" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SUM(T.ELECT)                                  shorePowerCount,
    SUM(ROUND((T.ENDTIME - T.STARTTIME) * 24, 2)) shorePowerTime,
    COUNT(T.CONNRECORDSEQ)                        shipUsage
    from ghjg_port_manage.shore_power_conn_record_info t
    where t.OPERATORID in
    ('sgldjzx','shgdjzxmt','shgjgwsd','shgjgwzd','shhdjzxmt','shmdjzxmt','shpdgjjzxmt','shsdjzxmt')
    AND t.conntype != '低压(标准化)'
    AND ((T.ENDTIME &lt;= #{thisDate}
    AND T.ENDTIME >= #{lastDate}))
  </select>
  <select id="selectThreeMonthsDataTotal" resultType="com.shcd.vo.SpShipUsageMonthQuarterVo">
    SELECT SUM(T.SHIP_USAGE_MONTH)        shipUsageMonth,
           MAX(T.SHIP_USAGE_YEAR)         shipUsageYear,
           SUM(T.SHORE_POWER_COUNT_MONTH) shorePowerCountMonth,
           MAX(T.SHORE_POWER_COUNT_YEAR)  shorePowerCountYear,
           SUM(T.SHORE_POWER_TIME_MONTH)  shorePowerTimeMonth,
           MAX(T.SHORE_POWER_TIME_YEAR)   shorePowerTimeYear
    FROM GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH T
    where T.DATA_SOURCE = 99
      AND T.REPORT_DATE >= #{start}
      AND T.REPORT_DATE &lt;= #{end}
  </select>
  <select id="selectNhAndWgMonth" resultType="com.shcd.vo.SpStatementShipUsageDetail">
    select STARTTIME chargeStartDate, ENDTIME chargeEndDate, ELECT shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO
    where CONNTYPE = '低压(标准化)'
      and (ENDTIME > #{lastDate} and ENDTIME &lt; #{thisDate}
      or
           (ENDTIME > #{lastCycleStart} and ENDTIME &lt; #{lastDate} and
            MODIFYTIME > #{lastCycleStart} and MODIFYTIME &lt; #{lastCycleEnd}))
  </select>
  <select id="selectNhAndWgLastMonthSum" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
    select SHIP_USAGE_YEAR        shipUsage,
           SHORE_POWER_TIME_YEAR  shorePowerTime,
           SHORE_POWER_COUNT_YEAR shorePowerCount
    from GHJG_PORT_MANAGE.SP_STATEMENT_SHIP_USAGE_MONTH
    where trunc(REPORT_DATE) = trunc(#{thisMonth})
      and DATA_SOURCE = 101
  </select>
  <select id="selectNhAndWgMonthV2" resultType="com.shcd.vo.SpStatementShipUsageDetailV2">
    select DURATION, ELECT shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO
    where CONNTYPE = '低压(标准化)'
      and (ENDTIME >= #{lastDate} and ENDTIME &lt; #{thisDate})
  </select>
  <select id="getInRiverDataThisMonthV2" resultType="com.shcd.vo.SpStatementShipUsageDetailV2">
    select DURATION, ELECT shorePowerCount
    from GHJG_PORT_MANAGE.SHORE_POWER_CONN_RECORD_INFO i
           left join GHJG_PORT_MANAGE.SHORE_POWER_PORT_INFO_NEW b on B.PORTID = i.PORTID
    where ((ENDTIME between #{lastDate} and #{thisDate}))
      and (CONNTYPE = '低压(标准化)' and area >= 2 AND b.AREA &lt;= 12)
  </select>

  <select id="selectPortIdEq1146" resultType="com.shcd.vo.ShorePowerDataVo">
    SELECT PORT.AREA                                     district,
           SUM(T.ELECT)                                  electCount,
           SUM(ROUND((T.ENDTIME - T.STARTTIME) * 24, 2)) electTime,
           COUNT(T.CONNRECORDSEQ)                        boatUse
    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(#{currentCycleEnd}, 'yyyy-MM-dd HH24:mi:ss')
      AND T.ENDTIME &gt;=
          TO_DATE(#{currentCycleStart}, 'yyyy-MM-dd HH24:mi:ss')))
    GROUP BY PORT.AREA
  </select>

    <select id="selectHandDataWithDate" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
        select
            sum(t.use_count) shipUsage,
            sum(t.ele_time) shorePowerTime,
            sum(t.use_electricity) shorePowerCount
        from ghjg_port_manage.shore_power_blberthmonthuse t
        where to_date(t.month,'yyyy-mm') = to_date(#{date},'yyyy-mm')
    </select>

    <select id="selectHandDataYear" resultType="com.shcd.vo.SpStatementShipUsageMonthVo">
        select
            sum(t.use_count) shipUsage,
            sum(t.ele_time) shorePowerTime,
            sum(t.use_electricity) shorePowerCount
        from ghjg_port_manage.shore_power_blberthmonthuse t
        where to_date(t.month,'yyyy-mm') >= to_date(#{start},'yyyy-mm')
          and to_date(t.month,'yyyy-mm') &lt;= to_date(#{end},'yyyy-mm')
    </select>
</mapper>
