浏览代码

楼宇接口---

zhanghao 4 月之前
父节点
当前提交
a6a5a2d6eb

+ 12 - 0
project-zcustom/src/main/java/com/project/zcustom/controller/crontab/PlatCrontabTaskController.java

@@ -100,6 +100,18 @@ public class PlatCrontabTaskController extends BaseController {
         }
         }
     }
     }
 
 
+
+    /**
+     * 楼宇运行监控
+     */
+    public void buildingData() {
+        synchronized (this) {
+            logger.info("开始楼宇运行获取接口数据");
+            dataTools.getBuildingData();
+            logger.info("楼宇运行获取接口数据完成");
+        }
+    }
+
     /**
     /**
      * 摄像头关流
      * 摄像头关流
      */
      */

+ 33 - 0
project-zcustom/src/main/java/com/project/zcustom/mapper/unit/PlatBuildingMapper.java

@@ -1,8 +1,12 @@
 package com.project.zcustom.mapper.unit;
 package com.project.zcustom.mapper.unit;
 
 
+import com.project.zcustom.domain.unit.LargeBuilding;
+
 import java.util.List;
 import java.util.List;
 
 
 public interface PlatBuildingMapper {
 public interface PlatBuildingMapper {
+    public int getCount();
+
     public String getPowerAndWaterMonth();
     public String getPowerAndWaterMonth();
 
 
     public String getAirCondition();
     public String getAirCondition();
@@ -26,4 +30,33 @@ public interface PlatBuildingMapper {
     public String patrol();
     public String patrol();
 
 
     public String patrolPoint();
     public String patrolPoint();
+
+
+
+    public int updatePowerAndWaterMonth(String res);
+
+    public int updateAirCondition(String res);
+
+    public int updateTarget(String res);
+
+    public int updateUseElectricity(String res);
+
+    public int updateGreenElectricity(String res);
+
+    public int updateCarbon(String res);
+
+    public int updateEnergyYear(String res);
+
+    public int updatePowerYear(String res);
+
+    public int updateWaterYear(String res);
+
+    public int updateFrequency(String res);
+
+    public int updatePatrol(String res);
+
+    public int updatePatrolPoint(String res);
+
+    public int updateBuilding(LargeBuilding largeBuilding);
+    public int insertBuilding(LargeBuilding largeBuilding);
 }
 }

+ 9 - 0
project-zcustom/src/main/java/com/project/zcustom/tools/ApiUrlConfig.java

@@ -123,6 +123,15 @@ public class ApiUrlConfig {
         ApiUrlConfig.buildUseHeatGas = buildUseHeatGas;
         ApiUrlConfig.buildUseHeatGas = buildUseHeatGas;
     }
     }
 
 
+    // 办公能耗情况接口 楼宇月用水电热信息接口
+    private static String buildUseWater;
+    public static String getBuildUseWater() {
+        return ApiUrlConfig.buildPrefix + buildUseWater;
+    }
+    public void setBuildUseWater(String buildUseWater) {
+        ApiUrlConfig.buildUseWater = buildUseWater;
+    }
+
     // 数据中心机房信息接口
     // 数据中心机房信息接口
     private static String buildDataCenterRoom;
     private static String buildDataCenterRoom;
     public static String getBuildDataCenterRoom() {
     public static String getBuildDataCenterRoom() {

+ 47 - 4
project-zcustom/src/main/java/com/project/zcustom/tools/DataTools.java

@@ -11,6 +11,8 @@ import com.project.common.utils.http.HttpUtils;
 import com.project.zcustom.domain.build.PlatBuildParams;
 import com.project.zcustom.domain.build.PlatBuildParams;
 import com.project.zcustom.domain.build.PlatBuildYearTrend;
 import com.project.zcustom.domain.build.PlatBuildYearTrend;
 import com.project.zcustom.domain.plat.PlatApiRecord;
 import com.project.zcustom.domain.plat.PlatApiRecord;
+import com.project.zcustom.domain.unit.LargeBuilding;
+import com.project.zcustom.mapper.unit.PlatBuildingMapper;
 import com.project.zcustom.service.access.IPlatAccessService;
 import com.project.zcustom.service.access.IPlatAccessService;
 import com.project.zcustom.service.basics.IPlatBasicsService;
 import com.project.zcustom.service.basics.IPlatBasicsService;
 import com.project.zcustom.service.build.IPlatBuildParamsService;
 import com.project.zcustom.service.build.IPlatBuildParamsService;
@@ -21,13 +23,12 @@ import com.project.zcustom.service.plat.IPlatApiRecordService;
 import com.project.zcustom.service.post.IPlatPostStationService;
 import com.project.zcustom.service.post.IPlatPostStationService;
 import com.project.zcustom.service.property.IPlatPropertyService;
 import com.project.zcustom.service.property.IPlatPropertyService;
 import com.project.zcustom.service.smart.IPlatGreenSmartOtherService;
 import com.project.zcustom.service.smart.IPlatGreenSmartOtherService;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.time.LocalDate;
+import java.util.*;
 
 
 
 
 /**
 /**
@@ -38,6 +39,9 @@ import java.util.Objects;
  */
  */
 @Service
 @Service
 public class DataTools {
 public class DataTools {
+    @Autowired
+    private PlatBuildingMapper platBuildingMapper;
+
     @Resource
     @Resource
     IPlatEmployeeTypeService platEmployeeTypeService;
     IPlatEmployeeTypeService platEmployeeTypeService;
     @Resource
     @Resource
@@ -113,6 +117,45 @@ public class DataTools {
         }
         }
     }
     }
 
 
+
+
+    public void getBuildingData(){
+        LargeBuilding largeBuilding = new LargeBuilding();
+        largeBuilding.setJsonFrequency(repeat(ApiUrlConfig.getBuildCarbonEmissionStatistics(), null));
+        largeBuilding.setJsonPatrol(repeat(ApiUrlConfig.getBuildEnergyForYear(), null));
+        largeBuilding.setJsonPatrolPoint(repeat(ApiUrlConfig.getBuildEnergyStatistics(), null));
+        largeBuilding.setJsonPowerWaterMonth((repeat(ApiUrlConfig.getBuildPowerForYear(), String.valueOf(LocalDate.now().getMonthValue()))));
+        largeBuilding.setJsonAir(repeat(ApiUrlConfig.getBuildElectricityStatistics(), null));
+        largeBuilding.setJsonTarget(repeat(ApiUrlConfig.getBuildWaterForYear(), null));
+        largeBuilding.setJsonUseElectricity(repeat(ApiUrlConfig.getBuildWaterStatistics(), null));
+        largeBuilding.setJsonGreenElectricity(repeat(ApiUrlConfig.getBuildNonHeatingEnergyForYear(), null));
+        largeBuilding.setJsonCarbon(repeat(ApiUrlConfig.getBuildUsePowerStatistics(), null));
+        largeBuilding.setJsonEnergyYear(repeat(ApiUrlConfig.getBuildPowerForMonth(), null));
+        largeBuilding.setJsonPowerYear(repeat(ApiUrlConfig.getBuildUseHeatGas(), null));
+        largeBuilding.setJsonWaterYear(repeat(ApiUrlConfig.getBuildUseWater(), null));
+        if (platBuildingMapper.getCount() > 0){
+            platBuildingMapper.updateBuilding(largeBuilding);
+        }
+        else {
+            platBuildingMapper.insertBuilding(largeBuilding);
+        }
+    }
+
+    public String repeat(String url, String params){
+        String result = null;
+        if (!StringUtils.isEmpty(params)){
+            result = HttpUtils.sendGet(url, params);
+        }
+        else {
+            result = HttpUtils.sendGet(url);
+        }
+        return result;
+    }
+
+
+
+
+
     /**
     /**
      * 碳排放量月度变化趋势图接口
      * 碳排放量月度变化趋势图接口
      */
      */

+ 120 - 0
project-zcustom/src/main/resources/mapper/zcustom/unit/PlatBuildingMapper.xml

@@ -4,6 +4,10 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.project.zcustom.mapper.unit.PlatBuildingMapper">
 <mapper namespace="com.project.zcustom.mapper.unit.PlatBuildingMapper">
 
 
+    <select id="getCount" resultType="int">
+        select count(*) from large_building
+    </select>
+
     <select id="getPowerAndWaterMonth" resultType="String">
     <select id="getPowerAndWaterMonth" resultType="String">
         select json_power_water_month from large_building
         select json_power_water_month from large_building
     </select>
     </select>
@@ -51,4 +55,120 @@
     <select id="patrolPoint" resultType="String">
     <select id="patrolPoint" resultType="String">
         select json_patrol_point from large_building
         select json_patrol_point from large_building
     </select>
     </select>
+
+
+
+
+    <update id="updatePowerAndWaterMonth" parameterType="String">
+        update large_building
+        set json_power_water_month = #{res}
+    </update>
+
+    <update id="updateAirCondition" parameterType="String">
+        update large_building
+        set json_air = #{res}
+    </update>
+
+    <update id="updateTarget" parameterType="String">
+        update large_building
+        set json_target = #{res}
+    </update>
+
+    <update id="updateUseElectricity" parameterType="String">
+        update large_building
+        set json_use_electricity = #{res}
+    </update>
+
+    <update id="updateGreenElectricity" parameterType="String">
+        update large_building
+        set json_green_electricity = #{res}
+    </update>
+
+    <update id="updateCarbon" parameterType="String">
+        update large_building
+        set json_carbon = #{res}
+    </update>
+
+    <update id="updateEnergyYear" parameterType="String">
+        update large_building
+        set json_energy_year = #{res}
+    </update>
+
+    <update id="updatePowerYear" parameterType="String">
+        update large_building
+        set json_power_year = #{res}
+    </update>
+
+    <update id="updateWaterYear" parameterType="String">
+        update large_building
+        set json_water_year = #{res}
+    </update>
+
+    <update id="updateFrequency" parameterType="String">
+        update large_building
+        set json_frequency = #{res}
+    </update>
+
+    <update id="updatePatrol" parameterType="String">
+        update large_building
+        set json_patrol = #{res}
+    </update>
+
+    <update id="updatePatrolPoint" parameterType="String">
+        update large_building
+        set json_patrol_point = #{res}
+    </update>
+
+    <update id="updateBuilding" parameterType="LargeBuilding">
+        update large_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_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>
 </mapper>
 </mapper>