Browse Source

天气数据集成

learshaw 2 months ago
parent
commit
e91b0ef2b0
33 changed files with 971 additions and 165 deletions
  1. 1 1
      common-cloud/ruoyi-auth/src/main/resources/bootstrap.yml
  2. 1 1
      common-cloud/ruoyi-gateway/src/main/resources/application-local.yml
  3. 1 1
      common-cloud/ruoyi-gateway/src/main/resources/bootstrap.yml
  4. 1 1
      common-cloud/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml
  5. 3 10
      common-cloud/tool-modules/general-data/Dockerfile
  6. 9 6
      common-cloud/tool-modules/general-data/pom.xml
  7. 2 0
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/GeneralDataApplication.java
  8. 94 0
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/config/RedisConfig.java
  9. 2 1
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/controller/WeatherController.java
  10. 3 1
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/DateServiceImpl.java
  11. 1 1
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/WeatherColAmapServiceImpl.java
  12. 4 3
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/WeatherServiceImpl.java
  13. 0 125
      common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/util/HttpUtils.java
  14. 10 2
      common-cloud/tool-modules/general-data/src/main/resources/application-locale.yml
  15. 44 0
      common-cloud/tool-modules/general-data/src/main/resources/application-prod-139.yml
  16. 1 1
      common-cloud/tool-modules/general-data/src/main/resources/application.yml
  17. 2 9
      ems/ems-cloud/docker/Dockerfile
  18. 1 1
      ems/ems-cloud/ems-dev-adapter/src/main/resources/bootstrap.yml
  19. 2 0
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/EmsApplication.java
  20. 83 0
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/WeatherController.java
  21. 72 0
      ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/service/TaskService.java
  22. 11 0
      ems/ems-cloud/ems-server/src/main/resources/application-local.yml
  23. 11 0
      ems/ems-cloud/ems-server/src/main/resources/application-prod-ct.yml
  24. 1 1
      ems/ems-cloud/ems-server/src/main/resources/bootstrap.yml
  25. 49 0
      ems/ems-core/src/main/java/com/ruoyi/ems/mapper/AdmWeatherForecastMapper.java
  26. 53 0
      ems/ems-core/src/main/java/com/ruoyi/ems/mapper/AdmWeatherRtMapper.java
  27. 67 0
      ems/ems-core/src/main/java/com/ruoyi/ems/service/IWeatherService.java
  28. 130 0
      ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/WeatherServiceImpl.java
  29. 41 0
      ems/ems-core/src/main/resources/mapper/ems/AdmWeatherForecastMapper.xml
  30. 47 0
      ems/ems-core/src/main/resources/mapper/ems/AdmWeatherRtMapper.xml
  31. 6 0
      prod-common/pom.xml
  32. 36 0
      prod-common/src/main/java/com/huashe/common/utils/CloseUtils.java
  33. 182 0
      prod-common/src/main/java/com/huashe/common/utils/HttpUtils.java

+ 1 - 1
common-cloud/ruoyi-auth/src/main/resources/bootstrap.yml

@@ -9,7 +9,7 @@ spring:
     name: ruoyi-auth
     name: ruoyi-auth
   profiles:
   profiles:
     # 环境配置
     # 环境配置
-    active: prod
+    active: local
   cloud:
   cloud:
     nacos:
     nacos:
       discovery:
       discovery:

+ 1 - 1
common-cloud/ruoyi-gateway/src/main/resources/application-local.yml

@@ -36,7 +36,7 @@ spring:
             - StripPrefix=0
             - StripPrefix=0
         # 能源-设备适配器
         # 能源-设备适配器
         - id: ems-dev-adapter
         - id: ems-dev-adapter
-          uri: lb://ems-dev-adapter
+          uri: http://127.0.0.1:9203
           predicates:
           predicates:
             - Path=/ems-dev-adapter/**
             - Path=/ems-dev-adapter/**
           filters:
           filters:

+ 1 - 1
common-cloud/ruoyi-gateway/src/main/resources/bootstrap.yml

@@ -9,7 +9,7 @@ spring:
     name: ruoyi-gateway
     name: ruoyi-gateway
   profiles:
   profiles:
     # 环境配置
     # 环境配置
-    active: prod
+    active: local
   cloud:
   cloud:
     nacos:
     nacos:
       discovery:
       discovery:

+ 1 - 1
common-cloud/ruoyi-modules/ruoyi-system/src/main/resources/bootstrap.yml

@@ -9,7 +9,7 @@ spring:
     name: ruoyi-system
     name: ruoyi-system
   profiles:
   profiles:
     # 环境配置
     # 环境配置
-    active: prod
+    active: local
   cloud:
   cloud:
     nacos:
     nacos:
       discovery:
       discovery:

+ 3 - 10
common-cloud/tool-modules/general-data/Dockerfile

@@ -2,7 +2,7 @@
 #   docker build -t general-data:1.0 .
 #   docker build -t general-data:1.0 .
 ########################################################
 ########################################################
 
 
-FROM centos-base:7.6.1810
+FROM openjdk:8
 
 
 MAINTAINER learshaw@gmail.com
 MAINTAINER learshaw@gmail.com
 
 
@@ -11,17 +11,10 @@ RUN mkdir -p /usr/local/java && \
     mkdir -p /opt/tool/general-data
     mkdir -p /opt/tool/general-data
 WORKDIR /opt/tool
 WORKDIR /opt/tool
 
 
-# 添加JDK
-ADD jdk-8u333-linux-x64.tar.gz /usr/local/java/
+# 添加
 COPY general-data-1.0.0-SNAPSHOT.jar /opt/tool/general-data/
 COPY general-data-1.0.0-SNAPSHOT.jar /opt/tool/general-data/
 
 
 # 端口
 # 端口
-EXPOSE 9300
-
-# 设置环境变量
-ENV JAVA_HOME /usr/local/java/jdk1.8.0_333
-ENV JRE_HOME /usr/local/java/jdk1.8.0_333/jre
-ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
-ENV PATH $JAVA_HOME/bin:$PATH
+EXPOSE 9000
 
 
 CMD ["java", "-Duser.timezone=Asia/Shanghai", "-jar", "/opt/tool/general-data/general-data-1.0.0-SNAPSHOT.jar"]
 CMD ["java", "-Duser.timezone=Asia/Shanghai", "-jar", "/opt/tool/general-data/general-data-1.0.0-SNAPSHOT.jar"]

+ 9 - 6
common-cloud/tool-modules/general-data/pom.xml

@@ -43,6 +43,15 @@
             <artifactId>spring-boot-configuration-processor</artifactId>
             <artifactId>spring-boot-configuration-processor</artifactId>
             <optional>true</optional>
             <optional>true</optional>
         </dependency>
         </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <!-- JSON序列化支持 -->
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+        </dependency>
         <!-- mysql驱动 -->
         <!-- mysql驱动 -->
         <dependency>
         <dependency>
             <groupId>com.mysql</groupId>
             <groupId>com.mysql</groupId>
@@ -91,12 +100,6 @@
             <artifactId>commons-io</artifactId>
             <artifactId>commons-io</artifactId>
             <version>2.6</version>
             <version>2.6</version>
         </dependency>
         </dependency>
-        <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
-            <version>4.5.12</version>
-        </dependency>
 
 
         <dependency>
         <dependency>
             <groupId>junit</groupId>
             <groupId>junit</groupId>

+ 2 - 0
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/GeneralDataApplication.java

@@ -9,6 +9,7 @@ package com.huashe.common.data;
 
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableAsync;
 
 
 /**
 /**
@@ -20,6 +21,7 @@ import org.springframework.scheduling.annotation.EnableAsync;
  * @see [相关类/方法]
  * @see [相关类/方法]
  * @since [产品/模块版本]
  * @since [产品/模块版本]
  */
  */
+@EnableCaching
 @EnableAsync
 @EnableAsync
 @SpringBootApplication
 @SpringBootApplication
 public class GeneralDataApplication {
 public class GeneralDataApplication {

+ 94 - 0
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/config/RedisConfig.java

@@ -0,0 +1,94 @@
+/*
+ * 文 件 名:  RedisConfig
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/5/20
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.huashe.common.data.config;
+
+import com.fasterxml.jackson.annotation.JsonTypeInfo;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.redis.cache.RedisCacheConfiguration;
+import org.springframework.data.redis.cache.RedisCacheManager;
+import org.springframework.data.redis.connection.RedisConnectionFactory;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
+import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
+import org.springframework.data.redis.serializer.StringRedisSerializer;
+
+import java.time.Duration;
+import java.util.TimeZone;
+
+/**
+ * Redis配置类
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/5/20]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Configuration
+public class RedisConfig {
+    @Autowired
+    private RedisConnectionFactory redisConnectionFactory;
+
+    @Bean
+    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory factory) {
+        RedisTemplate<String, Object> template = new RedisTemplate<>();
+        template.setConnectionFactory(factory);
+
+        // 创建带类型信息的JSON序列化器
+        Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
+
+        ObjectMapper objectMapper = new ObjectMapper();
+        // 启用类型信息(关键配置)
+        objectMapper.activateDefaultTyping(
+            objectMapper.getPolymorphicTypeValidator(),
+            ObjectMapper.DefaultTyping.NON_FINAL,
+            JsonTypeInfo.As.PROPERTY
+        );
+        objectMapper.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+        serializer.setObjectMapper(objectMapper);
+
+        // 配置序列化器
+        template.setKeySerializer(new StringRedisSerializer());
+        template.setValueSerializer(serializer);
+        template.setHashKeySerializer(new StringRedisSerializer());
+        template.setHashValueSerializer(serializer);
+
+        template.afterPropertiesSet();
+        return template;
+    }
+
+    @Bean
+    public RedisCacheManager cacheManager(RedisConnectionFactory factory) {
+        // 创建带类型信息的JSON序列化器
+        Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<>(Object.class);
+
+        ObjectMapper objectMapper = new ObjectMapper();
+        objectMapper.activateDefaultTyping(
+            objectMapper.getPolymorphicTypeValidator(),
+            ObjectMapper.DefaultTyping.NON_FINAL,
+            JsonTypeInfo.As.PROPERTY
+        );
+        objectMapper.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
+        serializer.setObjectMapper(objectMapper);
+
+        // 配置缓存
+        RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig()
+            .entryTtl(Duration.ofMillis(1800 * 1000L))
+            .serializeValuesWith(SerializationPair.fromSerializer(serializer));
+
+        return RedisCacheManager.builder(factory)
+            .cacheDefaults(config)
+            .build();
+    }
+}

+ 2 - 1
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/controller/WeatherController.java

@@ -10,6 +10,7 @@
  */
  */
 package com.huashe.common.data.controller;
 package com.huashe.common.data.controller;
 
 
+import com.alibaba.fastjson2.JSON;
 import com.huashe.common.data.config.ApiAuth;
 import com.huashe.common.data.config.ApiAuth;
 import com.huashe.common.data.model.CallResponse;
 import com.huashe.common.data.model.CallResponse;
 import com.huashe.common.data.service.TaskService;
 import com.huashe.common.data.service.TaskService;
@@ -89,7 +90,7 @@ public class WeatherController {
     @ApiResponses({ @ApiResponse(code = 200, message = "success"),
     @ApiResponses({ @ApiResponse(code = 200, message = "success"),
         @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
         @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
     })
     })
-    public CallResponse<List<WeatherRt>> getWeather(@RequestParam(value = "adcode") String adcode,
+    public CallResponse<List<WeatherRt>> getWeatherHis(@RequestParam(value = "adcode") String adcode,
         @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
         @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
         CallResponse<List<WeatherRt>> callResponse = new CallResponse<>();
         CallResponse<List<WeatherRt>> callResponse = new CallResponse<>();
 
 

+ 3 - 1
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/DateServiceImpl.java

@@ -16,16 +16,17 @@ import com.alibaba.fastjson.JSONObject;
 import com.huashe.common.data.config.CollectConfig;
 import com.huashe.common.data.config.CollectConfig;
 import com.huashe.common.data.mapper.AdmHolidayMapper;
 import com.huashe.common.data.mapper.AdmHolidayMapper;
 import com.huashe.common.data.service.DateService;
 import com.huashe.common.data.service.DateService;
-import com.huashe.common.data.util.HttpUtils;
 import com.huashe.common.domain.model.DateAttr;
 import com.huashe.common.domain.model.DateAttr;
 import com.huashe.common.domain.model.Holiday;
 import com.huashe.common.domain.model.Holiday;
 import com.huashe.common.exception.Assert;
 import com.huashe.common.exception.Assert;
 import com.huashe.common.exception.BusinessException;
 import com.huashe.common.exception.BusinessException;
 import com.huashe.common.utils.DateUtils;
 import com.huashe.common.utils.DateUtils;
+import com.huashe.common.utils.HttpUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -80,6 +81,7 @@ public class DateServiceImpl implements DateService {
         }
         }
     }
     }
 
 
+    @Cacheable(value = "dateAttr", key = "#dateStr")
     @Override
     @Override
     public DateAttr getDateAttr(String dateStr) {
     public DateAttr getDateAttr(String dateStr) {
         Date date = DateUtils.stringToDate(dateStr, "yyyy-MM-dd");
         Date date = DateUtils.stringToDate(dateStr, "yyyy-MM-dd");

+ 1 - 1
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/WeatherColAmapServiceImpl.java

@@ -20,7 +20,7 @@ import com.huashe.common.data.config.AmapWeatherConfig;
 import com.huashe.common.data.mapper.AdmWeatherForecastMapper;
 import com.huashe.common.data.mapper.AdmWeatherForecastMapper;
 import com.huashe.common.data.mapper.AdmWeatherRtMapper;
 import com.huashe.common.data.mapper.AdmWeatherRtMapper;
 import com.huashe.common.data.service.WeatherColService;
 import com.huashe.common.data.service.WeatherColService;
-import com.huashe.common.data.util.HttpUtils;
+import com.huashe.common.utils.HttpUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;

+ 4 - 3
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/WeatherServiceimpl.java → common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/service/impl/WeatherServiceImpl.java

@@ -23,6 +23,7 @@ import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import javax.annotation.Resource;
 import javax.annotation.Resource;
@@ -39,9 +40,7 @@ import java.util.List;
  * @since [产品/模块版本]
  * @since [产品/模块版本]
  */
  */
 @Service
 @Service
-public class WeatherServiceimpl implements WeatherService {
-    private static final Logger log = LoggerFactory.getLogger(WeatherServiceimpl.class);
-
+public class WeatherServiceImpl implements WeatherService {
     @Resource
     @Resource
     private DimGaWeatherMapper weatherTypeMapper;
     private DimGaWeatherMapper weatherTypeMapper;
 
 
@@ -51,6 +50,7 @@ public class WeatherServiceimpl implements WeatherService {
     @Resource
     @Resource
     private AdmWeatherForecastMapper weatherForecastMapper;
     private AdmWeatherForecastMapper weatherForecastMapper;
 
 
+    @Cacheable(value = "weatherRt", key = "#adcode")
     @Override
     @Override
     public WeatherRt getWeatherRt(String adcode) {
     public WeatherRt getWeatherRt(String adcode) {
         return weatherRtMapper.getNewByAdcode(adcode);
         return weatherRtMapper.getNewByAdcode(adcode);
@@ -61,6 +61,7 @@ public class WeatherServiceimpl implements WeatherService {
         return weatherRtMapper.getByTime(adcode, startTime, endTime);
         return weatherRtMapper.getByTime(adcode, startTime, endTime);
     }
     }
 
 
+    @Cacheable(value = "weatherForecast", key = "#adcode")
     @Override
     @Override
     public List<WeatherForecast> getWeatherForecast(String adcode) {
     public List<WeatherForecast> getWeatherForecast(String adcode) {
         return weatherForecastMapper.getByAdcode(adcode);
         return weatherForecastMapper.getByAdcode(adcode);

+ 0 - 125
common-cloud/tool-modules/general-data/src/main/java/com/huashe/common/data/util/HttpUtils.java

@@ -1,125 +0,0 @@
-/*
- * 文 件 名:  HttpUtils
- * 版    权:
- * 描    述:  <描述>
- * 修 改 人:  learshaw
- * 修改时间:  2021/9/17
- * 跟踪单号:  <跟踪单号>
- * 修改单号:  <修改单号>
- * 修改内容:  <修改内容>
- */
-package com.huashe.common.data.util;
-
-import com.huashe.common.exception.Assert;
-import com.huashe.common.exception.BusinessException;
-import com.huashe.common.utils.CloseUtils;
-import org.apache.http.HttpEntity;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * HttpUtils
- * <功能详细描述>
- *
- * @author learshaw
- * @version [版本号, 2021/9/17]
- * @see [相关类/方法]
- * @since [产品/模块版本]
- */
-public class HttpUtils {
-    private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
-
-    private static final int CONNECT_TIMEOUT = 60000;
-
-    private static final int REQUEST_TIMEOUT = 30000;
-
-    private static final int SOCKET_TIMEOUT = 30000;
-
-    /**
-     * 发送Get请求
-     * @param url 地址
-     * @return 响应
-     */
-    public static String doGet(String url) {
-        CloseableHttpClient httpClient = null;
-        CloseableHttpResponse response = null;
-        String result = null;
-
-        try {
-            Assert.notEmpty(url, -1, "url 地址不合法!");
-            httpClient = HttpClients.createDefault();
-            HttpGet httpGet = new HttpGet(url);
-            httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
-            httpGet.setConfig(buildRequestConfig());
-            response = httpClient.execute(httpGet);
-            HttpEntity entity = response.getEntity();
-            result = EntityUtils.toString(entity);
-        }
-        catch (BusinessException var11) {
-            log.error("doGet fail! {}", var11.getMessage());
-            throw var11;
-        }
-        catch (Exception var12) {
-            log.error("doGet fail!", var12);
-            throw new BusinessException(-1, var12.getMessage(), var12);
-        }
-        finally {
-            CloseUtils.close(response);
-            CloseUtils.close(httpClient);
-        }
-
-        return result;
-    }
-
-    /**
-     * 发送post请求
-     * @param url 地址
-     * @param payload 请求参数
-     * @return
-     */
-    public String doPost(String url, String payload) {
-        CloseableHttpClient httpClient = null;
-        CloseableHttpResponse httpResponse = null;
-        String result = null;
-
-        try {
-            Assert.notEmpty(url, -1, "url 地址不合法!");
-            httpClient = HttpClients.createDefault();
-            HttpPost httpPost = new HttpPost(url);
-            httpPost.setConfig(buildRequestConfig());
-            httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
-            httpPost.setEntity(new StringEntity(payload));
-
-            httpResponse = httpClient.execute(httpPost);
-            HttpEntity entity = httpResponse.getEntity();
-            result = EntityUtils.toString(entity);
-        }
-        catch (BusinessException var11) {
-            log.error("doPost fail! {}", var11.getMessage());
-            throw var11;
-        }
-        catch (Exception var12) {
-            log.error("doPost fail!", var12);
-            throw new BusinessException(-1, var12.getMessage(), var12);
-        }
-        finally {
-            CloseUtils.close(httpResponse);
-            CloseUtils.close(httpClient);
-        }
-
-        return result;
-    }
-
-    private static RequestConfig buildRequestConfig() {
-        return RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT).setConnectionRequestTimeout(REQUEST_TIMEOUT)
-            .setSocketTimeout(SOCKET_TIMEOUT).build();
-    }
-}

+ 10 - 2
common-cloud/tool-modules/general-data/src/main/resources/application-locale.yml

@@ -3,7 +3,14 @@ spring:
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
     url: jdbc:mysql://172.192.13.95:3306/common_data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
     url: jdbc:mysql://172.192.13.95:3306/common_data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
     username: root
     username: root
-    password: abc123
+    password: root
+  redis:
+    host: 172.192.10.105
+    port: 30013
+    password:
+  jackson:
+    time-zone: Asia/Shanghai
+    date-format: yyyy-MM-dd HH:mm:ss
 
 
 mybatis:
 mybatis:
   mapper-locations: classpath:mapper/*.xml
   mapper-locations: classpath:mapper/*.xml
@@ -33,4 +40,5 @@ weather:
       - '2100:雨'
       - '2100:雨'
       - '4100:雾'
       - '4100:雾'
       - '4200:霾'
       - '4200:霾'
-      - '4300:沙'
+      - '4300:沙'
+      - '4300:尘'

+ 44 - 0
common-cloud/tool-modules/general-data/src/main/resources/application-prod-139.yml

@@ -0,0 +1,44 @@
+spring:
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://172.25.90.14:3310/common_data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+    username: common_data
+    password: zzT6c43XR6ewT2Bz
+  redis:
+    host: 172.25.90.14
+    port: 6379
+    password: redis_eDKDdX
+  jackson:
+    time-zone: Asia/Shanghai
+    date-format: yyyy-MM-dd HH:mm:ss
+
+mybatis:
+  mapper-locations: classpath:mapper/*.xml
+  type-aliases-package: com.huashe.common.domain.model,com.huashe.common.weather.model
+
+holiday:
+  cron: 0 0 8 1 * ?
+  url: https://unpkg.com/holiday-calendar@1.1.6/data/CN/#year#.json
+
+weather:
+  rt-cron: 0 15 0,6,12,18 * * ?
+  forecast-cron: 0 15 8 * * ?
+  # 服务提供商
+  service-provider: amap
+  region:
+    # 数据来源 db、conf
+    source: db
+    conf-adcodes:
+  amap:
+    url: https://restapi.amap.com/v3/weather/weatherInfo?key=${weather.amap.key}&city=#{adcode}&extensions=#{extensions}&output=JSON
+    key: 9a5a4852c8698e783989e7f376d77816
+    weatherList:
+      - '1101:晴'
+      - '1103:多云'
+      - '1106:阴'
+      - '2200:雪'
+      - '2100:雨'
+      - '4100:雾'
+      - '4200:霾'
+      - '4300:沙'
+      - '4300:尘'

+ 1 - 1
common-cloud/tool-modules/general-data/src/main/resources/application.yml

@@ -2,7 +2,7 @@ spring:
   application:
   application:
     name: collect-weather
     name: collect-weather
   profiles:
   profiles:
-    active: locale
+    active: prod-139
 
 
 server:
 server:
   port: 9000
   port: 9000

+ 2 - 9
ems/ems-cloud/docker/Dockerfile

@@ -2,7 +2,7 @@
 #   docker build -t ems-server:1.0 .
 #   docker build -t ems-server:1.0 .
 ########################################################
 ########################################################
 
 
-FROM centos-base:7.6.1810
+FROM openjdk:8
 
 
 MAINTAINER learshaw@gmail.com
 MAINTAINER learshaw@gmail.com
 
 
@@ -11,8 +11,7 @@ RUN mkdir -p /usr/local/java && \
     mkdir -p /opt/ems/{ruoyi-gateway,ruoyi-auth,ruoyi-system,ems-server,ems-dev-adapter}
     mkdir -p /opt/ems/{ruoyi-gateway,ruoyi-auth,ruoyi-system,ems-server,ems-dev-adapter}
 WORKDIR /opt/ems
 WORKDIR /opt/ems
 
 
-# 添加JDK
-ADD jdk-8u333-linux-x64.tar.gz /usr/local/java/
+# 添加
 COPY ruoyi-gateway.jar /opt/ems/ruoyi-gateway/
 COPY ruoyi-gateway.jar /opt/ems/ruoyi-gateway/
 COPY ruoyi-auth.jar /opt/ems/ruoyi-auth/
 COPY ruoyi-auth.jar /opt/ems/ruoyi-auth/
 COPY ruoyi-system.jar /opt/ems/ruoyi-system/
 COPY ruoyi-system.jar /opt/ems/ruoyi-system/
@@ -28,10 +27,4 @@ EXPOSE 9201
 EXPOSE 9202
 EXPOSE 9202
 EXPOSE 9203
 EXPOSE 9203
 
 
-# 设置环境变量
-ENV JAVA_HOME /usr/local/java/jdk1.8.0_333
-ENV JRE_HOME /usr/local/java/jdk1.8.0_333/jre
-ENV CLASSPATH .:${JAVA_HOME}/lib:${JRE_HOME}/lib
-ENV PATH $JAVA_HOME/bin:$PATH
-
 CMD ["sh", "/opt/ems/start-all.sh"]
 CMD ["sh", "/opt/ems/start-all.sh"]

+ 1 - 1
ems/ems-cloud/ems-dev-adapter/src/main/resources/bootstrap.yml

@@ -10,7 +10,7 @@ spring:
     name: ems-dev-adapter
     name: ems-dev-adapter
   profiles:
   profiles:
     # 环境配置
     # 环境配置
-    active: prod
+    active: local
   cloud:
   cloud:
     nacos:
     nacos:
       discovery:
       discovery:

+ 2 - 0
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/EmsApplication.java

@@ -5,12 +5,14 @@ import com.ruoyi.common.security.annotation.EnableRyFeignClients;
 import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 import com.ruoyi.common.swagger.annotation.EnableCustomSwagger2;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.scheduling.annotation.EnableAsync;
 
 
 /**
 /**
  * 能源管理模块
  * 能源管理模块
  *
  *
  * @author ruoyi
  * @author ruoyi
  */
  */
+@EnableAsync
 @EnableCustomConfig
 @EnableCustomConfig
 @EnableCustomSwagger2
 @EnableCustomSwagger2
 @EnableRyFeignClients
 @EnableRyFeignClients

+ 83 - 0
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/controller/WeatherController.java

@@ -0,0 +1,83 @@
+/*
+ * 文 件 名:  WeatherController
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/5/8
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.controller;
+
+import com.huashe.common.domain.AjaxResult;
+import com.ruoyi.common.core.web.controller.BaseController;
+import com.ruoyi.ems.service.IWeatherService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiResponse;
+import io.swagger.annotations.ApiResponses;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * 天气相关API
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/5/8]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+
+@RestController
+@RequestMapping("/weather")
+@Api(value = "WeatherController", description = "天气数据接口")
+public class WeatherController extends BaseController {
+    private static final Logger log = LoggerFactory.getLogger(WeatherController.class);
+
+    @Autowired
+    private IWeatherService weatherService;
+
+    /**
+     * 实时天气获取
+     */
+    @RequestMapping(value = "/getWeather", method = RequestMethod.GET)
+    @ApiOperation(value = "/getWeather", notes = "获取实时天气")
+    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
+        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
+    })
+    public AjaxResult getWeather(@RequestParam(value = "adcode") String adcode) {
+        return success(weatherService.getWeatherRt(adcode));
+    }
+
+    /**
+     * 获取历史天气数据
+     */
+    @RequestMapping(value = "/getWeatherHis", method = RequestMethod.GET)
+    @ApiOperation(value = "/getWeatherHis", notes = "获取天气历史")
+    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
+        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
+    })
+    public AjaxResult getWeatherHis(@RequestParam(value = "adcode") String adcode,
+        @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime) {
+        return success(weatherService.getWeatherHis(adcode, startTime, endTime));
+    }
+
+    /**
+     * 获取历史天气数据
+     */
+    @RequestMapping(value = "/getWeatherForecast", method = RequestMethod.GET)
+    @ApiOperation(value = "/getWeatherForecast", notes = "获取天气预报")
+    @ApiResponses({ @ApiResponse(code = 200, message = "success"),
+        @ApiResponse(code = 400, message = "{code:****,message:'fail'}")
+    })
+    public AjaxResult getWeatherForecast(@RequestParam(value = "adcode") String adcode) {
+        return success(weatherService.getWeatherForecast(adcode));
+    }
+}

+ 72 - 0
ems/ems-cloud/ems-server/src/main/java/com/ruoyi/ems/service/TaskService.java

@@ -0,0 +1,72 @@
+/*
+ * 文 件 名:  TaskService
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/5/22
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.service;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.huashe.common.domain.model.WeatherForecast;
+import com.huashe.common.domain.model.WeatherRt;
+import com.huashe.common.exception.Assert;
+import com.huashe.common.utils.HttpUtils;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 调度任务
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/5/22]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Configuration
+@EnableScheduling
+public class TaskService {
+    private static final Logger log = LoggerFactory.getLogger(TaskService.class);
+
+    @Value("${weather.adcode}")
+    private String weatherAdcode;
+
+    @Resource
+    private IWeatherService weatherService;
+
+    /**
+     * 天气实况采集
+     */
+    @Async
+    @Scheduled(cron = "${weather.rt.cron}")
+    public void collectRt() {
+        log.debug("start collect weather rt.");
+        weatherService.collectRt(weatherAdcode);
+    }
+
+    /**
+     * 天气预报采集
+     */
+    @Async
+    @Scheduled(cron = "${weather.forecast.cron}")
+    public void collectForecast() {
+        log.debug("start collect weather forecast.");
+        weatherService.collectForecast(weatherAdcode);
+    }
+}

+ 11 - 0
ems/ems-cloud/ems-server/src/main/resources/application-local.yml

@@ -43,6 +43,17 @@ spring:
           # url:
           # url:
           # driver-class-name:
           # driver-class-name:
 
 
+weather:
+  adcode: 321200
+  api-key: 4988803c28e1461b999054255a0b311fga37G3RPI1Bc2uR1
+  server: 139.224.116.141:9000
+  rt:
+    cron: 0 0 0/1 * * ?
+    api-addr: http://${weather.server}/general-data/weather/getWeather
+  forecast:
+    cron: 0 15 8 * * ?
+    api-addr: http://${weather.server}//general-data/weather/getWeatherForecast
+
 # mybatis配置
 # mybatis配置
 mybatis:
 mybatis:
   # 搜索指定包别名
   # 搜索指定包别名

+ 11 - 0
ems/ems-cloud/ems-server/src/main/resources/application-prod-ct.yml

@@ -43,6 +43,17 @@ spring:
           username: ems_ct
           username: ems_ct
           password: SBBsnTccaQaJ3ceW
           password: SBBsnTccaQaJ3ceW
 
 
+weather:
+  adcode: 321200
+  api-key: 4988803c28e1461b999054255a0b311fga37G3RPI1Bc2uR1
+  server: 139.224.116.141:9000
+  rt:
+    cron: 0 0 0/1 * * ?
+    api-addr: http://${weather.server}/general-data/weather/getWeather
+  forecast:
+    cron: 0 15 8 * * ?
+    api-addr: http://${weather.server}//general-data/weather/getWeatherForecast
+
 # mybatis配置
 # mybatis配置
 mybatis:
 mybatis:
   # 搜索指定包别名
   # 搜索指定包别名

+ 1 - 1
ems/ems-cloud/ems-server/src/main/resources/bootstrap.yml

@@ -10,7 +10,7 @@ spring:
     name: ems-server
     name: ems-server
   profiles:
   profiles:
     # 环境配置
     # 环境配置
-    active: prod
+    active: local
   cloud:
   cloud:
     nacos:
     nacos:
       discovery:
       discovery:

+ 49 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/AdmWeatherForecastMapper.java

@@ -0,0 +1,49 @@
+/*
+ * 文 件 名:  DwdWeatherHourRtMapper
+ * 版    权:
+ * 描    述:  <描述>
+ * 修 改 人:  learshaw
+ * 修改时间:  2021/9/22
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.mapper;
+
+import com.huashe.common.domain.model.WeatherForecast;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 小时天气时空保存
+ * <功能详细描述>
+ *
+ * @author learshaw
+ * @version [版本号, 2021/9/22]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Mapper
+public interface AdmWeatherForecastMapper {
+    /**
+     * 根据adcode和date查询
+     * @param adcode 行政区划代码
+
+     * @return List<WeatherRt>
+     */
+    List<WeatherForecast> getByAdcode(@Param("adcode") String adcode);
+
+    /**
+     * 天气预报入库
+     *
+     * @param list 对象
+     */
+    void insertBatch(List<WeatherForecast> list);
+
+    /**
+     * 根据区划代码删除
+     */
+    void deleteByAdcode(@Param("adcode") String adcode);
+}

+ 53 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/mapper/AdmWeatherRtMapper.java

@@ -0,0 +1,53 @@
+/*
+ * 文 件 名:  DwdWeatherHourRtMapper
+ * 版    权:
+ * 描    述:  <描述>
+ * 修 改 人:  learshaw
+ * 修改时间:  2021/9/22
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.mapper;
+
+import com.huashe.common.domain.model.WeatherRt;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * 天气实况保存
+ * <功能详细描述>
+ *
+ * @author learshaw
+ * @version [版本号, 2021/9/22]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Mapper
+public interface AdmWeatherRtMapper {
+    /**
+     * 小时天气实况入库
+     *
+     * @param poItem 对象
+     */
+    void merge(WeatherRt poItem);
+
+    /**
+     * 获取最新数据
+     * @param adcode 行政区划代码
+     * @return WeatherRt
+     */
+    WeatherRt getNewByAdcode(@Param("adcode") String adcode);
+
+    /**
+     * 根据adcode和date查询
+     * @param adcode 行政区划代码
+     * @param startTime 开始时间
+     * @param endTime 结束时间
+     * @return List<WeatherRt>
+     */
+    List<WeatherRt> getByTime(@Param("adcode") String adcode, @Param("startTime") String startTime,
+        @Param("endTime") String endTime);
+}

+ 67 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/IWeatherService.java

@@ -0,0 +1,67 @@
+/*
+ * 文 件 名:  WeatherService
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/5/8
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.service;
+
+import com.huashe.common.domain.model.WeatherForecast;
+import com.huashe.common.domain.model.WeatherRt;
+
+import java.util.List;
+
+/**
+ * 天气数据服务
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/5/8]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public interface IWeatherService {
+    /**
+     * 获取实时天气
+     *
+     * @param adcode 行政区划代码
+     * @return 实时天气数据
+     */
+    WeatherRt getWeatherRt(String adcode);
+
+    /**
+     * 获取历史天气数据
+     *
+     * @param adcode    行政区划代码
+     * @param startTime 开始时间
+     * @param endTime   结束时间
+     * @return 历史天气数据列表
+     */
+    List<WeatherRt> getWeatherHis(String adcode, String startTime, String endTime);
+
+    /**
+     * 获取未来天气预报
+     *
+     * @param adcode 行政区划代码
+     * @return 未来天气预报数据
+     */
+    List<WeatherForecast> getWeatherForecast(String adcode);
+
+    /**
+     * 按小时采集
+     *
+     * @return 小时实时天气
+     */
+    void collectRt(String adcode);
+
+    /**
+     * 按小时采集
+     *
+     * @return 小时实时天气
+     */
+    void collectForecast(String adcode);
+}

+ 130 - 0
ems/ems-core/src/main/java/com/ruoyi/ems/service/impl/WeatherServiceImpl.java

@@ -0,0 +1,130 @@
+/*
+ * 文 件 名:  WeatherServiceImpl
+ * 版    权:  华设设计集团股份有限公司
+ * 描    述:  <描述>
+ * 修 改 人:  lvwenbin
+ * 修改时间:  2025/5/22
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.ruoyi.ems.service.impl;
+
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
+import com.huashe.common.domain.model.WeatherForecast;
+import com.huashe.common.domain.model.WeatherRt;
+import com.huashe.common.exception.Assert;
+import com.huashe.common.utils.HttpUtils;
+import com.ruoyi.ems.mapper.AdmWeatherForecastMapper;
+import com.ruoyi.ems.mapper.AdmWeatherRtMapper;
+import com.ruoyi.ems.service.IWeatherService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.utils.URIBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.List;
+
+/**
+ * 天气服务
+ * <功能详细描述>
+ *
+ * @author lvwenbin
+ * @version [版本号, 2025/5/22]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+@Service
+public class WeatherServiceImpl implements IWeatherService {
+    private static final Logger log = LoggerFactory.getLogger(WeatherServiceImpl.class);
+
+    @Resource
+    private AdmWeatherRtMapper weatherRtMapper;
+
+    @Resource
+    private AdmWeatherForecastMapper weatherForecastMapper;
+
+    @Value("${weather.api-key}")
+    private String apiKey;
+
+    @Value("${weather.rt.api-addr}")
+    private String weatherRtAddr;
+
+    @Value("${weather.forecast.api-addr}")
+    private String weatherForecastAddr;
+
+    @Override
+    public WeatherRt getWeatherRt(String adcode) {
+        return weatherRtMapper.getNewByAdcode(adcode);
+    }
+
+    @Override
+    public List<WeatherRt> getWeatherHis(String adcode, String startTime, String endTime) {
+        return weatherRtMapper.getByTime(adcode, startTime, endTime);
+    }
+
+    @Override
+    public List<WeatherForecast> getWeatherForecast(String adcode) {
+        return weatherForecastMapper.getByAdcode(adcode);
+    }
+
+    @Override
+    public void collectRt(String adcode) {
+        try {
+            URIBuilder uriBuilder = new URIBuilder(weatherRtAddr);
+            uriBuilder.addParameter("adcode", adcode).addParameter("apiKey", apiKey);
+            String res = HttpUtils.doGet(uriBuilder);
+            log.debug("get res:\r\n{}", res);
+
+            JSONObject jsonObject = JSON.parseObject(res);
+
+            String code = jsonObject.getString("code");
+            Assert.isTrue(StringUtils.equals(code, "0"), -1, jsonObject.getString("message"));
+
+            String data = jsonObject.getString("data");
+            Assert.notNull(data, -1, "weather list is null.");
+
+            WeatherRt weatherRt = JSONObject.parseObject(data, WeatherRt.class);
+            weatherRtMapper.merge(weatherRt);
+        }
+        catch (Exception e) {
+            log.error("collectRt fail!", e);
+        }
+    }
+
+    @Override
+    public void collectForecast(String adcode) {
+        try {
+            URIBuilder uriBuilder = new URIBuilder(weatherForecastAddr);
+            uriBuilder.addParameter("adcode", adcode).addParameter("apiKey", apiKey);
+            String res = HttpUtils.doGet(uriBuilder);
+            log.debug("get res:\r\n{}", res);
+
+            JSONObject jsonObject = JSON.parseObject(res);
+
+            String code = jsonObject.getString("code");
+            Assert.isTrue(StringUtils.equals(code, "0"), -1, jsonObject.getString("message"));
+
+            JSONArray data = jsonObject.getJSONArray("data");
+            Assert.notNull(data, -1, "weather list is null.");
+
+            if (!data.isEmpty()) {
+                List<WeatherForecast> forecastList = JSON.parseArray(data.toString(), WeatherForecast.class);
+
+                if (CollectionUtils.isNotEmpty(forecastList)) {
+                    weatherForecastMapper.deleteByAdcode(adcode);
+                    weatherForecastMapper.insertBatch(forecastList);
+                }
+            }
+        }
+        catch (Exception e) {
+            log.error("collectForecast fail!", e);
+        }
+    }
+}

+ 41 - 0
ems/ems-core/src/main/resources/mapper/ems/AdmWeatherForecastMapper.xml

@@ -0,0 +1,41 @@
+<?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.ruoyi.ems.mapper.AdmWeatherForecastMapper">
+    <resultMap id="BaseResultMap" type="com.huashe.common.domain.model.WeatherForecast">
+        <result column="adcode" property="adcode" jdbcType="VARCHAR"/>
+        <result column="area_name" property="areaName" jdbcType="VARCHAR"/>
+        <result column="date" property="date" jdbcType="DATE"/>
+        <result column="day_weather_type" property="dayWeatherType" jdbcType="VARCHAR"/>
+        <result column="day_weather_cn" property="dayWeatherCn" jdbcType="VARCHAR"/>
+        <result column="night_weather_type" property="nightWeatherType" jdbcType="VARCHAR"/>
+        <result column="night_weather_cn" property="nightWeatherCn" jdbcType="VARCHAR"/>
+        <result column="day_temp" property="dayTemp" jdbcType="DOUBLE"/>
+        <result column="night_temp" property="nightTemp" jdbcType="DOUBLE"/>
+        <result column="day_wind_power" property="dayWindPower" jdbcType="VARCHAR"/>
+        <result column="night_wind_power" property="nightWindPower" jdbcType="VARCHAR"/>
+        <result column="day_wind_dir" property="dayWindDir" jdbcType="VARCHAR"/>
+        <result column="night_wind_dir" property="nightWindDir" jdbcType="VARCHAR"/>
+        <result column="report_time" property="reportTime" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <select id="getByAdcode" parameterType="java.lang.String" resultMap="BaseResultMap" >
+        SELECT
+            `adcode`, `area_name`, `date`, `day_weather_type`, `day_weather_cn`, `night_weather_type`, `night_weather_cn`, `day_temp`, `night_temp`, `day_wind_power`, `night_wind_power`, `day_wind_dir`, `night_wind_dir`, `report_time`
+        FROM `adm_area_weather_forecast`
+        WHERE `adcode` = #{adcode}
+    </select>
+
+    <update id="insertBatch" parameterType="java.util.List">
+        INSERT INTO `adm_area_weather_forecast`
+            (`adcode`, `area_name`, `date`, `day_weather_type`, `day_weather_cn`, `night_weather_type`, `night_weather_cn`, `day_temp`, `night_temp`, `day_wind_power`, `night_wind_power`, `day_wind_dir`, `night_wind_dir`, `report_time`)
+        VALUES
+        <foreach collection="list" item="item" index="index" separator=",">
+            (#{item.adcode}, #{item.areaName}, #{item.date}, #{item.dayWeatherType}, #{item.dayWeatherCn}, #{item.nightWeatherType}, #{item.nightWeatherCn},
+             #{item.dayTemp}, #{item.nightTemp}, #{item.dayWindPower}, #{item.nightWindPower}, #{item.dayWindDir}, #{item.nightWindDir}, #{item.reportTime})
+        </foreach>
+    </update>
+
+    <delete id="deleteByAdcode" parameterType="java.lang.String">
+        delete from `adm_area_weather_forecast` where adcode = #{adcode}
+    </delete>
+</mapper>

+ 47 - 0
ems/ems-core/src/main/resources/mapper/ems/AdmWeatherRtMapper.xml

@@ -0,0 +1,47 @@
+<?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.ruoyi.ems.mapper.AdmWeatherRtMapper">
+    <resultMap id="BaseResultMap" type="com.huashe.common.domain.model.WeatherRt">
+        <result column="adcode" property="adcode" jdbcType="VARCHAR"/>
+        <result column="area_name" property="areaName" jdbcType="VARCHAR"/>
+        <result column="date" property="date" jdbcType="DATE"/>
+        <result column="weather_type" property="weatherType" jdbcType="VARCHAR"/>
+        <result column="weather_cn" property="weatherCn" jdbcType="VARCHAR"/>
+        <result column="temperature" property="temperature" jdbcType="DOUBLE"/>
+        <result column="humidity" property="humidity" jdbcType="INTEGER"/>
+        <result column="wind_power" property="windPower" jdbcType="VARCHAR"/>
+        <result column="wind_direction" property="windDirection" jdbcType="VARCHAR"/>
+        <result column="report_time" property="reportTime" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <update id="merge" parameterType="com.huashe.common.domain.model.WeatherRt">
+        REPLACE INTO `adm_area_weather_rt`
+        (
+            `adcode`,
+            `area_name`,
+            `date`,
+            `weather_type`,
+            `weather_cn`,
+            `temperature`,
+            `humidity`,
+            `wind_power`,
+            `wind_direction`,
+            `report_time`
+        )
+        VALUES (#{adcode}, #{areaName}, #{date}, #{weatherType}, #{weatherCn}, #{temperature}, #{humidity}, #{windPower}, #{windDirection}, #{reportTime})
+    </update>
+
+    <select id="getNewByAdcode" resultMap="BaseResultMap">
+        select
+            `adcode`,`area_name`,`date`,`weather_type`,`weather_cn`,`temperature`,`humidity`,`wind_power`,`wind_direction`,`report_time`
+        from `adm_area_weather_rt`
+        where `adcode` = #{adcode} order by `date` desc limit 1
+    </select>
+
+    <select id="getByTime" resultMap="BaseResultMap">
+        select
+            `adcode`,`area_name`,`date`,`weather_type`,`weather_cn`,`temperature`,`humidity`,`wind_power`,`wind_direction`,`report_time`
+        from `adm_area_weather_rt`
+        where `adcode` = #{adcode} and `date` &gt;= STR_TO_DATE(#{startTime},'%Y-%m-%d') and date &lt;= STR_TO_DATE(#{endTime},'%Y-%m-%d')
+    </select>
+</mapper>

+ 6 - 0
prod-common/pom.xml

@@ -46,6 +46,12 @@
             <version>${commons-lang3.version}</version>
             <version>${commons-lang3.version}</version>
         </dependency>
         </dependency>
 
 
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.12</version>
+        </dependency>
+
         <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
         <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
         <dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
             <groupId>org.slf4j</groupId>

+ 36 - 0
prod-common/src/main/java/com/huashe/common/utils/CloseUtils.java

@@ -10,6 +10,8 @@
  */
  */
 package com.huashe.common.utils;
 package com.huashe.common.utils;
 
 
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.impl.client.CloseableHttpClient;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
 
 
@@ -156,6 +158,40 @@ public abstract class CloseUtils {
     }
     }
 
 
     /**
     /**
+     * $关闭连接
+     *
+     * @param httpResponse http响应
+     * @see [类、类#方法、类#成员]
+     */
+    public static void close(CloseableHttpResponse httpResponse) {
+        if (httpResponse != null) {
+            try {
+                httpResponse.close();
+            }
+            catch (IOException e) {
+                log.error("close httpResponse failed.", e);
+            }
+        }
+    }
+
+    /**
+     * $关闭连接
+     *
+     * @param httpClient http连接
+     * @see [类、类#方法、类#成员]
+     */
+    public static void close(CloseableHttpClient httpClient) {
+        if (httpClient != null) {
+            try {
+                httpClient.close();
+            }
+            catch (IOException e) {
+                log.error("close httpClient failed.", e);
+            }
+        }
+    }
+
+    /**
      * $万能关闭方法 <br>
      * $万能关闭方法 <br>
      * $关闭带close方法的对象
      * $关闭带close方法的对象
      *
      *

+ 182 - 0
prod-common/src/main/java/com/huashe/common/utils/HttpUtils.java

@@ -0,0 +1,182 @@
+/*
+ * 文 件 名:  HttpUtils
+ * 版    权:
+ * 描    述:  <描述>
+ * 修 改 人:  learshaw
+ * 修改时间:  2021/9/17
+ * 跟踪单号:  <跟踪单号>
+ * 修改单号:  <修改单号>
+ * 修改内容:  <修改内容>
+ */
+package com.huashe.common.utils;
+
+import com.huashe.common.exception.Assert;
+import com.huashe.common.exception.BusinessException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.utils.URIBuilder;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * HttpUtils
+ * <功能详细描述>
+ *
+ * @author learshaw
+ * @version [版本号, 2021/9/17]
+ * @see [相关类/方法]
+ * @since [产品/模块版本]
+ */
+public class HttpUtils {
+    private static final Logger log = LoggerFactory.getLogger(HttpUtils.class);
+
+    private static final int CONNECT_TIMEOUT = 10000;
+
+    private static final int REQUEST_TIMEOUT = 15000;
+
+    private static final int SOCKET_TIMEOUT = 5000;
+
+    /**
+     * 发送Get请求
+     *
+     * @param url 地址
+     * @return 响应
+     */
+    public static String doGet(String url) {
+        String result = null;
+
+        try {
+            // 创建HttpGet对象,并执行请求
+            Assert.notEmpty(url, -1, "url 地址不合法!");
+            URIBuilder uriBuilder = new URIBuilder(url);
+            HttpGet httpGet = new HttpGet(uriBuilder.build());
+            httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
+            result = execute(httpGet);
+        }
+        catch (Exception e) {
+            log.error("doGet fail!", e);
+            throw new BusinessException(-1, e.getMessage(), e);
+        }
+
+
+        return result;
+    }
+
+    /**
+     * 发送Get请求
+     *
+     * @param uriBuilder 地址
+     * @return 响应
+     */
+    public static String doGet(URIBuilder uriBuilder) {
+        String result = null;
+
+        try {
+            HttpGet httpGet = new HttpGet(uriBuilder.build());
+            httpGet.setHeader("Content-Type", "application/json;charset=UTF-8");
+            result = execute(httpGet);
+        }
+        catch (Exception e) {
+            log.error("doGet fail!", e);
+            throw new BusinessException(-1, e.getMessage(), e);
+        }
+
+        return result;
+    }
+
+    /**
+     * 发送post请求
+     *
+     * @param url     地址
+     * @param payload 请求参数
+     * @return
+     */
+    public String doPost(String url, String payload) {
+        String result = null;
+
+        try {
+            Assert.notEmpty(url, -1, "url 地址不合法!");
+            URIBuilder uriBuilder = new URIBuilder(url);
+            HttpPost httpPost = new HttpPost(uriBuilder.build());
+            httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.setEntity(new StringEntity(payload));
+            result =  execute(httpPost);
+        }
+        catch (Exception e) {
+            log.error("doPost fail!", e);
+            throw new BusinessException(-1, e.getMessage(), e);
+        }
+
+        return result;
+    }
+
+    /**
+     * 发送post请求
+     *
+     * @param uriBuilder 地址
+     * @param payload 请求参数
+     * @return
+     */
+    public String doPost(URIBuilder uriBuilder, String payload) {
+        String result = null;
+
+        try {
+            HttpPost httpPost = new HttpPost(uriBuilder.build());
+            httpPost.addHeader("Content-Type", "application/json;charset=UTF-8");
+            httpPost.setEntity(new StringEntity(payload));
+            result =  execute(httpPost);
+        }
+        catch (Exception e) {
+            log.error("doPost fail!", e);
+            throw new BusinessException(-1, e.getMessage(), e);
+        }
+
+        return result;
+    }
+
+    /**
+     * 发送Get请求
+     *
+     * @param request 请求对象
+     * @return 响应
+     */
+    public static String execute(HttpUriRequest request) {
+        CloseableHttpResponse response = null;
+        CloseableHttpClient httpClient = null;
+        String result = null;
+
+        try {
+            // 创建RequestConfig对象,并设置超时时间
+            RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT) // 设置等待数据超时时间(单位毫秒)
+                .setConnectTimeout(CONNECT_TIMEOUT) // 设置连接超时时间(单位毫秒)
+                .setConnectionRequestTimeout(REQUEST_TIMEOUT)// 设置从连接池获取连接的超时时间(单位毫秒)
+                .build();
+
+            // 创建HttpClient对象,并设置请求配置
+            httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
+            response = httpClient.execute(request);
+            HttpEntity entity = response.getEntity();
+            result = EntityUtils.toString(entity);
+        }
+        catch (Exception e) {
+            log.error("execute fail!", e);
+            throw new BusinessException(-1, e.getMessage(), e);
+        }
+        finally {
+            CloseUtils.close(response);
+            CloseUtils.close(httpClient);
+        }
+
+        return result;
+    }
+}