<?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.project.zcustom.mapper.unit.PlatBuildingMapper">

    <resultMap type="com.project.zcustom.domain.addional.LargeBuildingControl" id="LargeBuildingControlResult">
        <result property="id"    column="id"    />
        <result property="weekElectricity"    column="week_electricity"    />
        <result property="roomElectricity"    column="room_electricity"    />
        <result property="todayElectricity"    column="today_electricity"    />
        <result property="monthElectricityOne"    column="month_electricity_one"    />
        <result property="monthElectricityTwo"    column="month_electricity_two"    />
        <result property="monthElectricityThree"    column="month_electricity_three"    />
        <result property="roomLoadOne"    column="room_load_one"    />
        <result property="roomLoadTwo"    column="room_load_two"    />
        <result property="roomLoadThree"    column="room_load_three"    />
        <result property="warnDevice"    column="warn_device"    />
        <result property="waterDeviceAirNum"    column="water_device_air_num"    />
        <result property="waterControlNormalNum"    column="water_control_normal_num"    />
        <result property="waterControlAbnormalNum"    column="water_control_abnormal_num"    />
        <result property="warnEventStatistics"    column="warn_event_statistics"    />
        <result property="waterStateOne"    column="water_state_one"    />
        <result property="waterStateTwo"    column="water_state_two"    />
    </resultMap>

    <resultMap type="com.project.zcustom.domain.addional.LargeBuildingLoadDetail" id="LargePlatBuildingLoadDetailResult">
        <result property="id"    column="id"    />
        <result property="number"    column="number"    />
        <result property="deviceName"    column="device_name"    />
        <result property="type"    column="type"    />
        <result property="state"    column="state"    />
        <result property="kind"    column="kind"    />
    </resultMap>

    <select id="getCount" resultType="int">
        select count(*) from large_plat_building
    </select>

    <select id="getPowerAndWaterMonth" resultType="String">
        select json_power_water_month from large_plat_building
    </select>

    <select id="getAirCondition" resultType="String">
        select json_air from large_plat_building
    </select>

    <select id="getTarget" resultType="String">
        select json_target from large_plat_building
    </select>

    <select id="useElectricity" resultType="String">
        select json_use_electricity from large_plat_building
    </select>

    <select id="greenElectricity" resultType="String">
        select json_green_electricity from large_plat_building
    </select>

    <select id="carbon" resultType="String">
        select json_carbon from large_plat_building
    </select>

    <select id="energyYear" resultType="String">
        select json_energy_year from large_plat_building
    </select>

    <select id="powerYear" resultType="String">
        select json_power_year from large_plat_building
    </select>

    <select id="waterYear" resultType="String">
        select json_water_year from large_plat_building
    </select>

    <select id="frequency" resultType="String">
        select json_frequency from large_plat_building
    </select>

    <select id="patrol" resultType="String">
        select json_patrol from large_plat_building
    </select>

    <select id="patrolPoint" resultType="String">
        select json_patrol_point from large_plat_building
    </select>




    <select id="getThisWeekElectricity" resultMap="LargeBuildingControlResult">
        select week_electricity, room_electricity from large_plat_building_control
    </select>

    <select id="getControlElevator" resultType="String">
        select control_elevator from large_plat_building_control
    </select>

    <select id="getThisAmmeterDetail" parameterType="String" resultType="String">
        select ammeter_detail from large_plat_building_ammeter_detail
    </select>

    <select id="getTodayElectricity" resultType="String">
        select today_electricity from large_plat_building_control
    </select>

    <select id="getMonthElectricity" resultMap="LargeBuildingControlResult">
        select month_electricity_one, month_electricity_two, month_electricity_three from large_plat_building_control
    </select>

    <select id="getRoomLoad" resultMap="LargeBuildingControlResult">
        select room_load_one, room_load_two, room_load_three from large_plat_building_control
    </select>

    <select id="getRoomLoadDetail" resultMap="LargePlatBuildingLoadDetailResult">
        select * from large_plat_building_load_detail
        where state = #{state}
        <if test="kind != 0"> and kind = #{kind} </if>
    </select>

    <select id="getWarnDevice" resultMap="LargeBuildingControlResult">
        select warn_device, water_device_air_num, water_control_normal_num, water_control_abnormal_num from large_plat_building_control
    </select>

    <select id="getAbnormalPoint" resultMap="LargeBuildingControlResult">
        select abnormal_point_one, abnormal_point_two, abnormal_point_three, abnormal_point_four from large_plat_building_control
    </select>

    <select id="getWarnEvent" resultType="String">
        select warn_event_statistics from large_plat_building_control
    </select>

    <select id="getWarnState" resultMap="LargeBuildingControlResult">
        select water_state_one, water_state_two from large_plat_building_control
    </select>

    <select id="getPhotovoltaicPower" resultType="String">
        select photovoltaic_power from large_plat_building_control
    </select>




    <update id="updatePowerAndWaterMonth" parameterType="String">
        update large_plat_building
        set json_power_water_month = #{res}
    </update>

    <update id="updateAirCondition" parameterType="String">
        update large_plat_building
        set json_air = #{res}
    </update>

    <update id="updateTarget" parameterType="String">
        update large_plat_building
        set json_target = #{res}
    </update>

    <update id="updateUseElectricity" parameterType="String">
        update large_plat_building
        set json_use_electricity = #{res}
    </update>

    <update id="updateGreenElectricity" parameterType="String">
        update large_plat_building
        set json_green_electricity = #{res}
    </update>

    <update id="updateCarbon" parameterType="String">
        update large_plat_building
        set json_carbon = #{res}
    </update>

    <update id="updateEnergyYear" parameterType="String">
        update large_plat_building
        set json_energy_year = #{res}
    </update>

    <update id="updatePowerYear" parameterType="String">
        update large_plat_building
        set json_power_year = #{res}
    </update>

    <update id="updateWaterYear" parameterType="String">
        update large_plat_building
        set json_water_year = #{res}
    </update>

    <update id="updateFrequency" parameterType="String">
        update large_plat_building
        set json_frequency = #{res}
    </update>

    <update id="updatePatrol" parameterType="String">
        update large_plat_building
        set json_patrol = #{res}
    </update>

    <update id="updatePatrolPoint" parameterType="String">
        update large_plat_building
        set json_patrol_point = #{res}
    </update>

    <update id="updateBuilding" parameterType="LargeBuilding">
        update large_plat_building
        <set>
            <if test="jsonFrequency != null and jsonFrequency != '' ">json_frequency = #{jsonFrequency},</if>
            <if test="jsonPatrol != null and jsonPatrol != '' ">json_patrol = #{jsonPatrol},</if>
            <if test="jsonPatrolPoint != null and jsonPatrolPoint != '' ">json_patrol_point = #{jsonPatrolPoint},</if>
            <if test="jsonPowerWaterMonth != null and jsonPowerWaterMonth != '' ">json_power_water_month = #{jsonPowerWaterMonth},</if>
            <if test="jsonAir != null and jsonAir != ''">json_air = #{jsonAir},</if>
            <if test="jsonTarget != null and jsonTarget != ''">json_target = #{jsonTarget},</if>
            <if test="jsonUseElectricity != null and jsonUseElectricity != '' ">json_use_electricity = #{jsonUseElectricity},</if>
            <if test="jsonGreenElectricity != null and jsonGreenElectricity != '' ">json_green_electricity = #{jsonGreenElectricity},</if>
            <if test="jsonCarbon != null and jsonCarbon != ''">json_carbon = #{jsonCarbon},</if>
            <if test="jsonEnergyYear != null and jsonEnergyYear != ''">json_energy_year = #{jsonEnergyYear},</if>
            <if test="jsonPowerYear != null and jsonPowerYear != ''">json_power_year = #{jsonPowerYear},</if>
            <if test="jsonWaterYear != null and jsonWaterYear != ''">json_water_year = #{jsonWaterYear},</if>
            update_time = sysdate()
        </set>
        where del_flag = '0'
    </update>


    <insert id="insertBuilding" parameterType="LargeBuilding">
        insert into large_plat_building (
        <if test="jsonFrequency != null and jsonFrequency != '' ">json_frequency,</if>
        <if test="jsonPatrol != null and jsonPatrol != '' ">json_patrol,</if>
        <if test="jsonPatrolPoint != null and jsonPatrolPoint != '' ">json_patrol_point,</if>
        <if test="jsonPowerWaterMonth != null and jsonPowerWaterMonth != '' ">json_power_water_month,</if>
        <if test="jsonAir != null and jsonAir != ''">json_air,</if>
        <if test="jsonTarget != null and jsonTarget != ''">json_target,</if>
        <if test="jsonUseElectricity != null and jsonUseElectricity != '' ">json_use_electricity,</if>
        <if test="jsonGreenElectricity != null and jsonGreenElectricity != '' ">json_green_electricity,</if>
        <if test="jsonCarbon != null and jsonCarbon != ''">json_carbon,</if>
        <if test="jsonEnergyYear != null and jsonEnergyYear != ''">json_energy_year,</if>
        <if test="jsonPowerYear != null and jsonPowerYear != ''">json_power_year,</if>
        <if test="jsonWaterYear != null and jsonWaterYear != ''">json_water_year,</if>
        del_flag, create_time
        )values(
        <if test="jsonFrequency != null and jsonFrequency != '' ">#{jsonFrequency},</if>
        <if test="jsonPatrol != null and jsonPatrol != '' ">#{jsonPatrol},</if>
        <if test="jsonPatrolPoint != null and jsonPatrolPoint != '' ">#{jsonPatrolPoint},</if>
        <if test="jsonPowerWaterMonth != null and jsonPowerWaterMonth != '' ">#{jsonPowerWaterMonth},</if>
        <if test="jsonAir != null and jsonAir != ''">#{jsonAir},</if>
        <if test="jsonTarget != null and jsonTarget != ''">#{jsonTarget},</if>
        <if test="jsonUseElectricity != null and jsonUseElectricity != '' ">#{jsonUseElectricity},</if>
        <if test="jsonGreenElectricity != null and jsonGreenElectricity != '' ">#{jsonGreenElectricity},</if>
        <if test="jsonCarbon != null and jsonCarbon != ''">#{jsonCarbon},</if>
        <if test="jsonEnergyYear != null and jsonEnergyYear != ''">#{jsonEnergyYear},</if>
        <if test="jsonPowerYear != null and jsonPowerYear != ''">#{jsonPowerYear},</if>
        <if test="jsonWaterYear != null and jsonWaterYear != ''">#{jsonWaterYear},</if>
        '0', sysdate()
        )
    </insert>

    <select id="getExist" resultType="int">
        select count(*) from large_plat_building_control
    </select>

    <update id="updateAirNum" parameterType="Long">
        update large_plat_building_control
        set water_device_air_num = #{num}
    </update>

    <select id="getAirNum" resultType="Long">
        select water_device_air_num from large_plat_building_control
    </select>

    <insert id="addBuildingControl" parameterType="LargeBuildingControl">
        insert into large_plat_building_control (week_electricity,
                                                 control_elevator,
                                                 room_electricity,
                                                 today_electricity,
                                                 month_electricity_one,
                                                 month_electricity_two,
                                                 month_electricity_three,
                                                 room_load_one,
                                                 room_load_two,
                                                 room_load_three,
                                                 warn_device,
                                                 water_device_air_num,
                                                 water_control_normal_num,
                                                 water_control_abnormal_num,
                                                 warn_event_statistics,
                                                 water_state_one,
                                                 water_state_two)
        values (
                   #{weekElectricity},
                   #{controlElevator},
                   #{roomElectricity},
                   #{todayElectricity},
                   #{monthElectricityOne},
                   #{monthElectricityTwo},
                   #{monthElectricityThree},
                   #{roomLoadOne},
                   #{roomLoadTwo},
                   #{roomLoadThree},
                   #{warnDevice},
                   #{waterDeviceAirNum},
                   #{waterControlNormalNum},
                   #{waterControlAbnormalNum},
                   #{warnEventStatistics},
                   #{waterStateOne},
                   #{waterStateTwo}
               )
    </insert>

    <update id="updateBuildingControl" parameterType="LargeBuildingControl">
        UPDATE large_plat_building_control
        SET week_electricity = #{weekElectricity},
            control_elevator = #{controlElevator},
            room_electricity = #{roomElectricity},
            today_electricity = #{todayElectricity},
            month_electricity_one = #{monthElectricityOne},
            month_electricity_two = #{monthElectricityTwo},
            month_electricity_three = #{monthElectricityThree},
            room_load_one = #{roomLoadOne},
            room_load_two = #{roomLoadTwo},
            room_load_three = #{roomLoadThree},
            warn_device = #{warnDevice},
            water_device_air_num = #{waterDeviceAirNum},
            water_control_normal_num = #{waterControlNormalNum},
            water_control_abnormal_num = #{waterControlAbnormalNum},
            warn_event_statistics = #{warnEventStatistics},
            water_state_one = #{waterStateOne},
            water_state_two = #{waterStateTwo}
    </update>

    <delete id="deleteAmmeterDetails">
        delete from large_plat_building_ammeter_detail
    </delete>

    <insert id="addAmmeterDetails" parameterType="com.project.zcustom.domain.addional.LargeBuildingControlAmmeterDetail">
        insert into large_plat_building_ammeter_detail (ammeter_detail, type)
        values
        <foreach collection="list" item="item" separator="," close=";">
            <trim prefix="(" suffix=")" suffixOverrides=",">
                #{item.ammeterDetail},
                #{item.type}
            </trim>
        </foreach>
    </insert>

</mapper>
