xiaowang 10 meses atrás
commit
45253c4f53

+ 33 - 0
.gitignore

@@ -0,0 +1,33 @@
+HELP.md
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/

+ 159 - 0
pom.xml

@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>2.2.1.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+    <groupId>com.example</groupId>
+    <artifactId>mdd</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+    <name>mdd</name>
+    <description>mdd</description>
+    <properties>
+        <java.version>1.8</java.version>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+        <spring-boot.version>2.6.13</spring-boot.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>druid</artifactId>
+            <version>1.1.14</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>3.12.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.5.0</version>
+        </dependency>
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>8.0.25</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-net</groupId>
+            <artifactId>commons-net</artifactId>
+            <version>3.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.taosdata.jdbc</groupId>
+            <artifactId>taos-jdbcdriver</artifactId>
+            <version>3.2.5</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.ant</groupId>
+            <artifactId>ant</artifactId>
+            <version>1.8.1</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.junrar</groupId>
+            <artifactId>junrar</artifactId>
+            <version>0.7</version>
+        </dependency>
+        <dependency>
+            <groupId>com.jcraft</groupId>
+            <artifactId>jsch</artifactId> <!-- 解决 sftp 连接 -->
+            <version>0.1.55</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-compress</artifactId>
+            <version>1.21</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <resources>
+            <!-- 配置文件复制到target目录下,不然开发调试的时候会报错 -->
+            <resource>
+                <!-- 资源文件的路径,不配置的话默认位于src/main/resources/目录下,  -->
+                <directory>src/main/resources</directory>
+                <!-- 是否对资源文件进行过滤 -->
+                <filtering>true</filtering>
+                <!-- 这里没有配置targetPath,默认复制到outputDirectory目录下  -->
+            </resource>
+            <!-- 配置文件放在target/config目录下 -->
+            <resource>
+                <directory>src/main/resources</directory>
+                <targetPath>${project.build.directory}/config</targetPath>
+            </resource>
+        </resources>
+
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>
+                            <groupId>org.projectlombok</groupId>
+                            <artifactId>lombok</artifactId>
+                        </exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <version>2.2.1.RELEASE</version>
+                <configuration>
+                    <mainClass>com.example.mdd.MddApplication</mainClass>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+            <!-- 打包过程忽略Junit测试 -->
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>2.17</version>
+                <configuration>
+                    <skip>true</skip>
+                </configuration>
+            </plugin>
+        </plugins>
+
+    </build>
+
+
+</project>

+ 13 - 0
src/main/java/com/example/mdd/MddApplication.java

@@ -0,0 +1,13 @@
+package com.example.mdd;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class MddApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(MddApplication.class, args);
+    }
+
+}

+ 30 - 0
src/main/java/com/example/mdd/entity/CaiYun.java

@@ -0,0 +1,30 @@
+package com.example.mdd.entity;
+
+import lombok.Data;
+
+@Data
+public class CaiYun {
+    String id;
+    //场站编号
+    String stationCode;
+    //经度
+    String longitude;
+    //纬度
+    String latitude;
+    //时间
+    String datetime;
+    //地表 2 米气温
+    String temperature;
+    //地面气压
+    String pressure;
+    //地表 2 米相对湿度(%)
+    String humidity;
+    //地表 10 米风向
+    String direction;
+    //地表 10 米风速
+    String speed;
+    //向下短波辐射通量(W/M2)
+    String dswrf;
+    //地表水平能见度
+    String visibility;
+}

+ 38 - 0
src/main/java/com/example/mdd/entity/HeFeng.java

@@ -0,0 +1,38 @@
+package com.example.mdd.entity;
+
+import lombok.Data;
+
+@Data
+public class HeFeng {
+    String id;
+    //场站编号
+    String stationCode;
+    //经度
+    String longitude;
+    //纬度
+    String latitude;
+    //预报时间
+    String fxTime;
+    //温度,默认单位:摄氏度
+    String temp;
+    //天气状况的文字描述,包括阴晴雨雪等天气状态的描述
+    String text;
+    //风向
+    String windDir;
+    //风向360角度
+    String wind360;
+    //风速,公里/小时
+    String windSpeed;
+    //风力等级
+    String windScale;
+    //相对湿度
+    String humidity;
+    //云量,百分比数值。可能为空
+    String cloud;
+    //当前小时累计降水量,默认单位:毫米
+    String precip;
+    //露点温度。可能为空
+    String dew;
+
+
+}

+ 184 - 0
src/main/java/com/example/mdd/entity/PowerStation.java

@@ -0,0 +1,184 @@
+package com.example.mdd.entity;
+
+
+import lombok.Data;
+
+/**
+ * itil场站信息
+ **/
+@Data
+public class PowerStation {
+    ////@Schema(description = "ID")
+    private String stationId;
+
+    //@Schema(description = "场站编号")
+    private String stationCode;
+
+    ////@Schema(description = "省份")
+    private String areaCode;
+
+    ////@Schema(description = "集团公司")
+    private String groupCompany;
+
+    ////@Schema(description = "业主")
+    private String stationOwner;
+
+    ////@Schema(description = "运维方")
+    private String stationOperator;
+
+    //@Schema(description = "调度名称")
+
+    private String stationName;
+
+    //@Schema(description = "项目名称")
+
+    private String stationAlias;
+
+    //@Schema(description = "场站类型")
+
+    private String stationType;
+
+    //@Schema(description = "报备装机容量")
+    private String installedCapacity;
+
+    //@Schema(description = "实际装机容量")
+    private String installedCapacityActual;
+
+    //@Schema(description = "实际并网容量")
+    private String installedCapacityLastest;
+
+    //@Schema(description = "经度")
+    private String longitude;
+
+    //@Schema(description = "纬度")
+    private String latitude;
+
+    //@Schema(description = "地形")
+    private String terrainType;
+
+    //    //@Schema(description = "地貌")
+    //    private String landformType;
+
+    //@Schema(description = "场站地址")
+    private String stationAddress;
+
+    //@Schema(description = "状态")
+    private String stationState;
+
+    //@Schema(description = "项目编号")
+    private String projectCode;
+
+    //@Schema(description = "外部场站编号")
+    private String stationCodeExternal;
+
+    //@Schema(description = "项目执行状态")
+    private String projectProgress;
+
+    //@Schema(description = "转运维时间")
+    private String projectAcceptanceTime;
+
+    //@Schema(description = "第一次并网时间")
+    private String firstOnGridTime;
+
+    //@Schema(description = "全并网时间")
+    private String fullOnGridTime;
+
+    //@Schema(description = "最近一次并网时间")
+    private String lastExpandTime;
+
+    //@Schema(description = "参与考核时间")
+    private String joinGradingTime;
+
+    //@Schema(description = "产品目录")
+    private String productCatalog;
+
+    //@Schema(description = "功率预测平台")
+    private String ipfcstEdition;
+
+    //@Schema(description = "系统版本号")
+    private String softwareVersion;
+
+    //@Schema(description = "核心版本号")
+    private String coreVersion;
+
+    //@Schema(description = "C平台版本号")
+    private String cpVersion;
+
+    //@Schema(description = "外网服务器下载软件版本")
+    private String ftpToolVersion;
+
+    //@Schema(description = "FTP账号(电科院提供)")
+    private String epriFtpUser;
+
+    //@Schema(description = "FTP密码(电科院提供)")
+    private String epriFtpPwd;
+
+    //@Schema(description = "FTP账号(云平台使用)")
+    private String cloudFtpUser;
+
+    //@Schema(description = "FTP密码(云平台使用)")
+    private String cloudFtpPwd;
+
+    //@Schema(description = "下载方式")
+    private String downloadMode;
+
+    //@Schema(description = "是否可切换云平台")
+    private String switchable;
+
+    //@Schema(description = "是否支持二维码扫描")
+    private String qrcodeEnable;
+
+    //@Schema(description = "短期模型系数")
+    private String stRatio;
+
+    //@Schema(description = "预测天数")
+    private String forecastDays;
+
+    //@Schema(description = "文件生成时间")
+    private String fileCreationTime;
+
+    //@Schema(description = "预测数据来源")
+    private String forecastType;
+
+    //@Schema(description = "预测数据点号")
+    private String forecastModel;
+
+    //@Schema(description = "NWP数据来源")
+    private String nwpType;
+
+    //@Schema(description = "NWP数据点号")
+    private String nwpPoint;
+
+    //@Schema(description = "电科院路径")
+    private String epriFilepath;
+
+    //@Schema(description = "象心力路径")
+    private String xxlFilepath;
+
+    //@Schema(description = "西班牙路径")
+    private String xbyFilepath;
+
+    //@Schema(description = "项目负责人")
+    private String projectDirector;
+
+    //@Schema(description = "主备机标识")
+    private String multiTag;
+
+    //@Schema(description = "附件数量")
+    private Integer numberOfAttachments;
+
+    //@Schema(description = "备注")
+    private String remark;
+
+    //@Schema(description = "删除标识")
+    private String activeFlag;
+    //@Schema(description = "调度标识")
+    private String provinceDispatch;
+
+    //@ApiModelProperty(value = "运维负责人")
+    private String maintenance;
+
+    //@ApiModelProperty(value = "客服负责人")
+    private String customerService;
+}
+

+ 34 - 0
src/main/java/com/example/mdd/entity/XinZhi.java

@@ -0,0 +1,34 @@
+package com.example.mdd.entity;
+
+import lombok.Data;
+
+@Data
+public class XinZhi {
+    String id;
+    //场站编号
+    String stationCode;
+    //经度
+    String longitude;
+    //纬度
+    String latitude;
+    //时间
+    String date;
+    //地表 2 米相对湿度(%)
+    String humidity;
+    //地表 10 米风向
+    String direction;
+    //风向角度,范围0~360
+    String directionDegree;
+    //地表 10 米风速
+    String speed;
+    //风力等级
+    String scale;
+    //最高温度
+    String high;
+    //最低温度
+    String low;
+    //降水量,单位mm
+    String rainfall;
+    //数据插入日期
+    String insertDate;
+}

+ 23 - 0
src/main/java/com/example/mdd/job/Download.java

@@ -0,0 +1,23 @@
+package com.example.mdd.job;
+
+import com.example.mdd.service.MeteorologicalDataDownload;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+
+@Slf4j
+@Service
+@EnableScheduling
+public class Download {
+    @Resource
+    MeteorologicalDataDownload md;
+
+    @Scheduled(cron = "0 0 10 * * ?")
+    public void download() {
+        md.download();
+    }
+}

+ 90 - 0
src/main/java/com/example/mdd/service/CaiYunDownload.java

@@ -0,0 +1,90 @@
+package com.example.mdd.service;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.mdd.entity.CaiYun;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@Slf4j
+public class CaiYunDownload {
+    public void download(Connection conn, String stationCode, String longitude, String latitude) {
+        //彩云天气api接口
+        String url = "https://api.caiyunapp.com/v2.6/SRQIFijX5MGtdmhe/" + longitude + "," + latitude + "/hourly?hourlysteps=24 ";
+        String body = HttpUtil.createGet(url).execute().charset("utf-8").body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        JSONObject result = JSONUtil.parseObj(jsonObject.get("result"));
+        JSONObject hourly = JSONUtil.parseObj(result.get("hourly"));
+        JSONArray visibility = JSONUtil.parseArray(hourly.get("visibility"));
+        JSONArray temperature = JSONUtil.parseArray(hourly.get("temperature"));
+        JSONArray pressure = JSONUtil.parseArray(hourly.get("pressure"));
+        JSONArray humidity = JSONUtil.parseArray(hourly.get("humidity"));
+        JSONArray dswrf = JSONUtil.parseArray(hourly.get("dswrf"));
+        JSONArray wind = JSONUtil.parseArray(hourly.get("wind"));
+        List<CaiYun> list = new ArrayList<>();
+        if (!visibility.isEmpty()) {
+            for (int i = 0; i < 24; i++) {
+                CaiYun caiYun = new CaiYun();
+                Map vis = (Map) visibility.get(i);
+                Map temp = (Map) temperature.get(i);
+                Map pre = (Map) pressure.get(i);
+                Map hum = (Map) humidity.get(i);
+                Map ds = (Map) dswrf.get(i);
+                Map w = (Map) wind.get(i);
+                caiYun.setVisibility(vis.get("value").toString());
+                caiYun.setDatetime(vis.get("datetime").toString());
+                caiYun.setTemperature(temp.get("value").toString());
+                caiYun.setPressure(pre.get("value").toString());
+                caiYun.setHumidity(hum.get("value").toString());
+                caiYun.setDswrf(ds.get("value").toString());
+                caiYun.setDirection(w.get("direction").toString());
+                caiYun.setSpeed(new BigDecimal(String.valueOf(w.get("speed"))).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).toString());
+                list.add(caiYun);
+            }
+        }
+        if (!list.isEmpty()) {
+            String tableSql = "INSERT ignore INTO `caiyun` ( `stationCode`, `longitude`, `latitude`, `datetime`, `temperature`, `pressure`, `humidity`, `direction`, `speed`, `dswrf`, `visibility`) " +
+                    "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
+            try {
+                PreparedStatement pstmt = conn.prepareStatement(tableSql);
+                conn.setAutoCommit(false);
+                log.info("彩云天气:共{}条记录", list.size());
+                list.forEach(item -> {
+                    try {
+                        pstmt.setString(1, stationCode);
+                        pstmt.setString(2, longitude);
+                        pstmt.setString(3, latitude);
+                        pstmt.setString(4, item.getDatetime());
+                        pstmt.setString(5, item.getTemperature());
+                        pstmt.setString(6, item.getPressure());
+                        pstmt.setString(7, item.getHumidity());
+                        pstmt.setString(8, item.getDirection());
+                        pstmt.setString(9, item.getSpeed());
+                        pstmt.setString(10, item.getDswrf());
+                        pstmt.setString(11, item.getVisibility());
+                        pstmt.addBatch();
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+                pstmt.executeBatch();
+                conn.commit();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        log.info("场站编号:{} 彩云天气数据下载完成", stationCode);
+    }
+}

+ 63 - 0
src/main/java/com/example/mdd/service/HeFengDownload.java

@@ -0,0 +1,63 @@
+package com.example.mdd.service;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+@Service
+@Slf4j
+public class HeFengDownload {
+    public void download(Connection conn, String stationCode, String longitude, String latitude) {
+        //和风天气api接口
+        String url = "https://devapi.qweather.com/v7/grid-weather/24h?location=" + longitude + "," + latitude + "&key=54d9633382814e148836ce6be2d003fb";
+        String body = HttpUtil.createGet(url).execute().charset("utf-8").body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        JSONArray list = JSONUtil.parseArray(jsonObject.get("hourly"));
+        if (!list.isEmpty()) {
+            String tableSql = "INSERT ignore INTO `hefeng` ( `stationCode`,`longitude`,`latitude`,`fxTime`, `temp`, `text`, `windDir`, `wind360`, `windSpeed`, `windScale`, `humidity`, `cloud`, `precip`, `dew`)" +
+                    " VALUES ( ?,?,?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
+            try {
+                PreparedStatement pstmt = conn.prepareStatement(tableSql);
+                conn.setAutoCommit(false);
+                log.info("和风天气:共{}条记录", list.size());
+                list.forEach(item -> {
+                    JSONObject jsonObject1 = JSONUtil.parseObj(item);
+                    try {
+                        pstmt.setString(1, stationCode);
+                        pstmt.setString(2, longitude);
+                        pstmt.setString(3, latitude);
+                        pstmt.setString(4, jsonObject1.getStr("fxTime"));
+                        pstmt.setString(5, jsonObject1.getStr("temp"));
+                        pstmt.setString(6, jsonObject1.getStr("text"));
+                        pstmt.setString(7, jsonObject1.getStr("windDir"));
+                        pstmt.setString(8, jsonObject1.getStr("wind360"));
+                        //公里/小时换算成m/s需要除3.6
+                        pstmt.setString(9, new BigDecimal(jsonObject1.getStr("windSpeed")).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).toString());
+                        pstmt.setString(10, jsonObject1.getStr("windScale"));
+                        pstmt.setString(11, jsonObject1.getStr("humidity"));
+                        pstmt.setString(12, jsonObject1.getStr("cloud"));
+                        pstmt.setString(13, jsonObject1.getStr("precip"));
+                        pstmt.setString(14, jsonObject1.getStr("dew"));
+                        pstmt.addBatch();
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+                pstmt.executeBatch();
+                conn.commit();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        log.info("场站编号:{} 和风天气数据下载完成", stationCode);
+    }
+}

+ 53 - 0
src/main/java/com/example/mdd/service/MeteorologicalDataDownload.java

@@ -0,0 +1,53 @@
+package com.example.mdd.service;
+
+import cn.hutool.db.DbUtil;
+import cn.hutool.db.ds.simple.SimpleDataSource;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.mdd.entity.PowerStation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.List;
+
+@Service
+@Slf4j
+public class MeteorologicalDataDownload {
+    @Resource
+    private HeFengDownload heFengDownload;
+    @Resource
+    private CaiYunDownload caiYunDownload;
+    @Resource
+    private XinZhiDownload xinZhiDownload;
+
+    public void download() {
+        String body = HttpUtil.get("http://itil.jiayuepowertech.com:9958/itil/api/power-station", 10000);
+        JSONObject json = JSONUtil.parseObj(body);
+        String code = json.get("code").toString();
+        String data = json.get("data").toString();
+        if (code.equals("0") && !data.isEmpty()) {
+            JSONArray array = JSONUtil.parseArray(data);
+            //itil所有的场站数据  根据场站数据的经纬度通过气象平台的api接口查询数据
+            List<PowerStation> list = array.toList(PowerStation.class);
+            try {
+                DataSource ds = new SimpleDataSource("jdbc:mysql://192.168.12.10:23306/mdd"
+                        , "root", "la!yibei82nianxueB");
+                Connection conn = DbUtil.use(ds).getConnection();
+                for (PowerStation powerStation : list) {
+                    heFengDownload.download(conn, powerStation.getStationCode(), powerStation.getLongitude(), powerStation.getLatitude());
+                    caiYunDownload.download(conn, powerStation.getStationCode(), powerStation.getLongitude(), powerStation.getLatitude());
+                    xinZhiDownload.download(conn, powerStation.getStationCode(), powerStation.getLongitude(), powerStation.getLatitude());
+                }
+            } catch (SQLException e) {
+                throw new RuntimeException(e);
+            }
+
+        }
+    }
+}

+ 92 - 0
src/main/java/com/example/mdd/service/XinZhiDownload.java

@@ -0,0 +1,92 @@
+package com.example.mdd.service;
+
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.example.mdd.entity.XinZhi;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Service
+@Slf4j
+public class XinZhiDownload {
+
+    public void download(Connection conn, String stationCode, String longitude, String latitude) {
+        //逐日天气预报 三天
+        String url = "https://api.seniverse.com/v3/weather/daily.json?key=Sw6CStXIxKnEw1uSV&location=" + latitude + ":" + longitude + "&language=zh-Hans&unit=c&start=-1&days=5";
+        //天气实况 免费用户只有个气温 没用
+        //String url = "https://api.seniverse.com/v3/weather/now.json?key=Sw6CStXIxKnEw1uSV&location=47.0519:131.7097&language=zh-Hans&unit=c";
+        String body = HttpUtil.createGet(url).execute().charset("utf-8").body();
+        JSONObject jsonObject = JSONUtil.parseObj(body);
+        JSONArray result = JSONUtil.parseArray(jsonObject.get("results"));
+        JSONObject all = (JSONObject) result.get(0);
+        JSONArray daily = JSONUtil.parseArray(all.get("daily"));
+        List<XinZhi> list = new ArrayList<>();
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
+        if (!daily.isEmpty()) {
+            for (int i = 0; i < daily.size(); i++) {
+                JSONObject jsonObject1 = (JSONObject) daily.get(i);
+                XinZhi xinZhi = new XinZhi();
+                xinZhi.setStationCode(stationCode);
+                xinZhi.setLongitude(longitude);
+                xinZhi.setLatitude(latitude);
+                xinZhi.setDate((String) jsonObject1.get("date"));
+                xinZhi.setDirection((String) jsonObject1.get("wind_direction"));
+                xinZhi.setDirectionDegree((String) jsonObject1.get("wind_direction_degree"));
+                xinZhi.setHumidity((String) jsonObject1.get("humidity"));
+                xinZhi.setHigh((String) jsonObject1.get("high"));
+                xinZhi.setLow((String) jsonObject1.get("low"));
+                xinZhi.setScale((String) jsonObject1.get("wind_scale"));
+                xinZhi.setSpeed((String) jsonObject1.get("wind_speed"));
+                xinZhi.setRainfall((String) jsonObject1.get("rainfall"));
+                list.add(xinZhi);
+            }
+
+        }
+        if (!list.isEmpty()) {
+            String tableSql = "INSERT ignore INTO `xinzhi` ( `stationCode`, `longitude`, `latitude`, `date`, `direction`, `direction_degree`, `speed`, `scale`, `humidity`, `high`, `low`, `rainfall`,`insert_date`) VALUES" +
+                    " (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?);";
+            try {
+                PreparedStatement pstmt = conn.prepareStatement(tableSql);
+                conn.setAutoCommit(false);
+                log.info("心知天气:共{}天记录", list.size());
+                list.forEach(item -> {
+                    try {
+                        pstmt.setString(1, item.getStationCode());
+                        pstmt.setString(2, item.getLongitude());
+                        pstmt.setString(3, item.getLatitude());
+                        pstmt.setString(4, item.getDate());
+                        pstmt.setString(5, item.getDirection());
+                        pstmt.setString(6, item.getDirectionDegree());
+                        pstmt.setString(7, new BigDecimal(item.getSpeed()).divide(new BigDecimal("3.6"), 2, RoundingMode.HALF_UP).toString());
+                        pstmt.setString(8, item.getScale());
+                        pstmt.setString(9, item.getHumidity());
+                        pstmt.setString(10, item.getHigh());
+                        pstmt.setString(11, item.getLow());
+                        pstmt.setString(12, item.getRainfall());
+                        pstmt.setString(13, df.format(new Date()));
+                        pstmt.addBatch();
+                    } catch (SQLException e) {
+                        throw new RuntimeException(e);
+                    }
+                });
+                pstmt.executeBatch();
+                conn.commit();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            log.info("场站编号:{} 心知天气数据下载完成", stationCode);
+        }
+    }
+}

+ 2 - 0
src/main/resources/application.yml

@@ -0,0 +1,2 @@
+server:
+  port: 19527

+ 40 - 0
src/main/resources/db.setting

@@ -0,0 +1,40 @@
+## db.setting文件
+url = jdbc:mysql://192.168.12.10:23306/mdd
+user = root
+pass = la!yibei82nianxueB
+## 可选配置
+# 是否在日志中显示执行的SQL
+showSql = true
+# 是否格式化显示的SQL
+formatSql = false
+# 是否显示SQL参数
+showParams = true
+
+#----------------------------------------------------------------------------------------------------------------
+## 连接池配置项
+
+## ---------------------------------------------------- Druid
+# 初始化时建立物理连接的个数。初始化发生在显示调用init方法,或者第一次getConnection时
+initialSize = 1
+# 最大连接池数量
+maxActive = 8
+# 最小连接池数量
+minIdle = 0
+# 获取连接时最大等待时间,单位毫秒。配置了maxWait之后, 缺省启用公平锁,并发效率会有所下降, 如果需要可以通过配置useUnfairLock属性为true使用非公平锁。
+maxWait = 0
+# 是否缓存preparedStatement,也就是PSCache。 PSCache对支持游标的数据库性能提升巨大,比如说oracle。 在mysql5.5以下的版本中没有PSCache功能,建议关闭掉。作者在5.5版本中使用PSCache,通过监控界面发现PSCache有缓存命中率记录, 该应该是支持PSCache。
+poolPreparedStatements = false
+# 要启用PSCache,必须配置大于0,当大于0时, poolPreparedStatements自动触发修改为true。 在Druid中,不会存在Oracle下PSCache占用内存过多的问题, 可以把这个数值配置大一些,比如说100
+maxOpenPreparedStatements = -1
+# 用来检测连接是否有效的sql,要求是一个查询语句。 如果validationQuery为null,testOnBorrow、testOnReturn、 testWhileIdle都不会其作用。
+validationQuery = SELECT 1
+# 申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
+testOnBorrow = true
+# 归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
+testOnReturn = false
+# 建议配置为true,不影响性能,并且保证安全性。 申请连接的时候检测,如果空闲时间大于 timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
+testWhileIdle = false
+# 有两个含义: 1) Destroy线程会检测连接的间隔时间 2) testWhileIdle的判断依据,详细看testWhileIdle属性的说明
+timeBetweenEvictionRunsMillis = 60000
+# 物理连接初始化的时候执行的sql
+connectionInitSqls = SELECT 1

+ 64 - 0
src/main/resources/logback.xml

@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 这个是根配置文件,一定要有的
+    scan:
+        是当配置文件被修改后会被重新加载
+    scanPeriod:
+        设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,
+        默认单位是毫秒。当scan为true时,此属性生效。默认的时间间隔为1分钟。
+    debug:
+        当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态。
+        默认值为false。
+     -->
+<configuration>
+    <!-- 日志存放路径
+        下面的标签可以自己定义
+        name:相当于Map的key
+        value:就是map的value
+        ${catalina.base}是tomcat的当前路径
+        /logs:就是tomcat下的日志路径,
+        /ehrlog:如果没有目录会默认创建
+    -->
+    <property name="LOG_HOME" value="./logs/"/>
+    <!-- appender:
+        name相当于一个名称
+        class:确定要加载哪个类
+        encoder:一定要加 encoder,
+        默认配置为PatternLayoutEncoder
+        patter:必填
+        ConsoleAppender:输出在控制台上
+    -->
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+        <encoder>
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度,%msg:日志消息,%n是换行符-->
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{50}) - %highlight(%msg%n)
+            </pattern>
+            <charset>UTF-8</charset>
+        </encoder>
+    </appender>
+    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+        <!-- 当前日志文件 -->
+        <file>${LOG_HOME}mdd.log</file>
+        <!-- 编码 -->
+        <!--<Encoding>UTF-8</Encoding>-->
+        <!-- 按照时间来 -->
+        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
+            <!--日志文件输出的文件名-->
+            <FileNamePattern>${LOG_HOME}mdd.%d{yyyy-MM-dd}.%i.log.gz</FileNamePattern>
+            <!--日志文件保留天数-->
+            <MaxHistory>180</MaxHistory>
+            <maxFileSize>10MB</maxFileSize>
+            <totalSizeCap>1024MB</totalSizeCap>
+            <cleanHistoryOnStart>true</cleanHistoryOnStart>
+        </rollingPolicy>
+        <!-- 布局 -->
+        <encoder>
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度,%msg:日志消息,%n是换行符-->
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
+        </encoder>
+        <append>false</append>
+    </appender>
+    <root level="info">
+        <appender-ref ref="STDOUT"/>
+        <appender-ref ref="FILE"/>
+    </root>
+</configuration>

+ 13 - 0
src/test/java/com/example/mdd/MddApplicationTests.java

@@ -0,0 +1,13 @@
+package com.example.mdd;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class MddApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}