first commit

master
修改密码漏洞修复完成 10 months ago
parent 3c207b9b1d
commit 06f7fa23f1

5
.gitignore vendored

@ -1,5 +1,6 @@
# ---> Maven
target/
target/*
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
@ -17,3 +18,7 @@ buildNumber.properties
# JDT-specific (Eclipse Java Development Tools)
.classpath
.idea
.idea/*
/.idea
/.idea/*

316
mvnw vendored

@ -0,0 +1,316 @@
#!/bin/sh
# ----------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# ----------------------------------------------------------------------------
# ----------------------------------------------------------------------------
# Maven Start Up Batch script
#
# Required ENV vars:
# ------------------
# JAVA_HOME - location of a JDK home dir
#
# Optional ENV vars
# -----------------
# M2_HOME - location of maven2's installed home dir
# MAVEN_OPTS - parameters passed to the Java VM when running Maven
# e.g. to debug Maven itself, use
# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
# MAVEN_SKIP_RC - flag to disable loading of mavenrc files
# ----------------------------------------------------------------------------
if [ -z "$MAVEN_SKIP_RC" ] ; then
if [ -f /usr/local/etc/mavenrc ] ; then
. /usr/local/etc/mavenrc
fi
if [ -f /etc/mavenrc ] ; then
. /etc/mavenrc
fi
if [ -f "$HOME/.mavenrc" ] ; then
. "$HOME/.mavenrc"
fi
fi
# OS specific support. $var _must_ be set to either true or false.
cygwin=false;
darwin=false;
mingw=false
case "`uname`" in
CYGWIN*) cygwin=true ;;
MINGW*) mingw=true;;
Darwin*) darwin=true
# Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
# See https://developer.apple.com/library/mac/qa/qa1170/_index.html
if [ -z "$JAVA_HOME" ]; then
if [ -x "/usr/libexec/java_home" ]; then
export JAVA_HOME="`/usr/libexec/java_home`"
else
export JAVA_HOME="/Library/Java/Home"
fi
fi
;;
esac
if [ -z "$JAVA_HOME" ] ; then
if [ -r /etc/gentoo-release ] ; then
JAVA_HOME=`java-config --jre-home`
fi
fi
if [ -z "$M2_HOME" ] ; then
## resolve links - $0 may be a link to maven's home
PRG="$0"
# need this for relative symlinks
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
M2_HOME=`dirname "$PRG"`/..
# make it fully qualified
M2_HOME=`cd "$M2_HOME" && pwd`
cd "$saveddir"
# echo Using m2 at $M2_HOME
fi
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --unix "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
fi
# For Mingw, ensure paths are in UNIX format before anything is touched
if $mingw ; then
[ -n "$M2_HOME" ] &&
M2_HOME="`(cd "$M2_HOME"; pwd)`"
[ -n "$JAVA_HOME" ] &&
JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
fi
if [ -z "$JAVA_HOME" ]; then
javaExecutable="`which javac`"
if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
# readlink(1) is not available as standard on Solaris 10.
readLink=`which readlink`
if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
if $darwin ; then
javaHome="`dirname \"$javaExecutable\"`"
javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
else
javaExecutable="`readlink -f \"$javaExecutable\"`"
fi
javaHome="`dirname \"$javaExecutable\"`"
javaHome=`expr "$javaHome" : '\(.*\)/bin'`
JAVA_HOME="$javaHome"
export JAVA_HOME
fi
fi
fi
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
else
JAVACMD="`\\unset -f command; \\command -v java`"
fi
fi
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly." >&2
echo " We cannot execute $JAVACMD" >&2
exit 1
fi
if [ -z "$JAVA_HOME" ] ; then
echo "Warning: JAVA_HOME environment variable is not set."
fi
CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
# traverses directory structure from process work directory to filesystem root
# first directory with .mvn subdirectory is considered project base directory
find_maven_basedir() {
if [ -z "$1" ]
then
echo "Path not specified to find_maven_basedir"
return 1
fi
basedir="$1"
wdir="$1"
while [ "$wdir" != '/' ] ; do
if [ -d "$wdir"/.mvn ] ; then
basedir=$wdir
break
fi
# workaround for JBEAP-8937 (on Solaris 10/Sparc)
if [ -d "${wdir}" ]; then
wdir=`cd "$wdir/.."; pwd`
fi
# end of workaround
done
echo "${basedir}"
}
# concatenates all lines of a file
concat_lines() {
if [ -f "$1" ]; then
echo "$(tr -s '\n' ' ' < "$1")"
fi
}
BASE_DIR=`find_maven_basedir "$(pwd)"`
if [ -z "$BASE_DIR" ]; then
exit 1;
fi
##########################################################################################
# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
# This allows using the maven wrapper in projects that prohibit checking in binary data.
##########################################################################################
if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found .mvn/wrapper/maven-wrapper.jar"
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
fi
if [ -n "$MVNW_REPOURL" ]; then
jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
else
jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
fi
while IFS="=" read key value; do
case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
esac
done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
if [ "$MVNW_VERBOSE" = true ]; then
echo "Downloading from: $jarUrl"
fi
wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
if $cygwin; then
wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
fi
if command -v wget > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found wget ... using wget"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
else
wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
fi
elif command -v curl > /dev/null; then
if [ "$MVNW_VERBOSE" = true ]; then
echo "Found curl ... using curl"
fi
if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
curl -o "$wrapperJarPath" "$jarUrl" -f
else
curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
fi
else
if [ "$MVNW_VERBOSE" = true ]; then
echo "Falling back to using Java to download"
fi
javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
# For Cygwin, switch paths to Windows format before running javac
if $cygwin; then
javaClass=`cygpath --path --windows "$javaClass"`
fi
if [ -e "$javaClass" ]; then
if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Compiling MavenWrapperDownloader.java ..."
fi
# Compiling the Java class
("$JAVA_HOME/bin/javac" "$javaClass")
fi
if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
# Running the downloader
if [ "$MVNW_VERBOSE" = true ]; then
echo " - Running MavenWrapperDownloader.java ..."
fi
("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
fi
fi
fi
fi
##########################################################################################
# End of extension
##########################################################################################
export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
if [ "$MVNW_VERBOSE" = true ]; then
echo $MAVEN_PROJECTBASEDIR
fi
MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
[ -n "$M2_HOME" ] &&
M2_HOME=`cygpath --path --windows "$M2_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
[ -n "$CLASSPATH" ] &&
CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
[ -n "$MAVEN_PROJECTBASEDIR" ] &&
MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
fi
# Provide a "standardized" way to retrieve the CLI args that will
# work with both Windows and non-Windows executions.
MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
export MAVEN_CMD_LINE_ARGS
WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
exec "$JAVACMD" \
$MAVEN_OPTS \
$MAVEN_DEBUG_OPTS \
-classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
"-Dmaven.home=${M2_HOME}" \
"-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"

188
mvnw.cmd vendored

@ -0,0 +1,188 @@
@REM ----------------------------------------------------------------------------
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements. See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership. The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License. You may obtain a copy of the License at
@REM
@REM https://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,
@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied. See the License for the
@REM specific language governing permissions and limitations
@REM under the License.
@REM ----------------------------------------------------------------------------
@REM ----------------------------------------------------------------------------
@REM Maven Start Up Batch script
@REM
@REM Required ENV vars:
@REM JAVA_HOME - location of a JDK home dir
@REM
@REM Optional ENV vars
@REM M2_HOME - location of maven2's installed home dir
@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending
@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
@REM e.g. to debug Maven itself, use
@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
@REM ----------------------------------------------------------------------------
@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
@echo off
@REM set title of command window
title %0
@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on'
@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
@REM set %HOME% to equivalent of $HOME
if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
@REM Execute a user defined script before this one
if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
@REM check for pre script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %*
if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %*
:skipRcPre
@setlocal
set ERROR_CODE=0
@REM To isolate internal variables from possible post scripts, we use another setlocal
@setlocal
@REM ==== START VALIDATION ====
if not "%JAVA_HOME%" == "" goto OkJHome
echo.
echo Error: JAVA_HOME not found in your environment. >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
:OkJHome
if exist "%JAVA_HOME%\bin\java.exe" goto init
echo.
echo Error: JAVA_HOME is set to an invalid directory. >&2
echo JAVA_HOME = "%JAVA_HOME%" >&2
echo Please set the JAVA_HOME variable in your environment to match the >&2
echo location of your Java installation. >&2
echo.
goto error
@REM ==== END VALIDATION ====
:init
@REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
@REM Fallback to current working directory if not found.
set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
set EXEC_DIR=%CD%
set WDIR=%EXEC_DIR%
:findBaseDir
IF EXIST "%WDIR%"\.mvn goto baseDirFound
cd ..
IF "%WDIR%"=="%CD%" goto baseDirNotFound
set WDIR=%CD%
goto findBaseDir
:baseDirFound
set MAVEN_PROJECTBASEDIR=%WDIR%
cd "%EXEC_DIR%"
goto endDetectBaseDir
:baseDirNotFound
set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
cd "%EXEC_DIR%"
:endDetectBaseDir
IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
@setlocal EnableExtensions EnableDelayedExpansion
for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
:endReadAdditionalConfig
SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO (
IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B
)
@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
@REM This allows using the maven wrapper in projects that prohibit checking in binary data.
if exist %WRAPPER_JAR% (
if "%MVNW_VERBOSE%" == "true" (
echo Found %WRAPPER_JAR%
)
) else (
if not "%MVNW_REPOURL%" == "" (
SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
)
if "%MVNW_VERBOSE%" == "true" (
echo Couldn't find %WRAPPER_JAR%, downloading it ...
echo Downloading from: %DOWNLOAD_URL%
)
powershell -Command "&{"^
"$webclient = new-object System.Net.WebClient;"^
"if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^
"$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^
"}"^
"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^
"}"
if "%MVNW_VERBOSE%" == "true" (
echo Finished downloading %WRAPPER_JAR%
)
)
@REM End of extension
@REM Provide a "standardized" way to retrieve the CLI args that will
@REM work with both Windows and non-Windows executions.
set MAVEN_CMD_LINE_ARGS=%*
%MAVEN_JAVA_EXE% ^
%JVM_CONFIG_MAVEN_PROPS% ^
%MAVEN_OPTS% ^
%MAVEN_DEBUG_OPTS% ^
-classpath %WRAPPER_JAR% ^
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
%WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
if ERRORLEVEL 1 goto error
goto end
:error
set ERROR_CODE=1
:end
@endlocal & set ERROR_CODE=%ERROR_CODE%
if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost
@REM check for post script, once with legacy .bat ending and once with .cmd ending
if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat"
if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
:skipRcPost
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
if "%MAVEN_BATCH_PAUSE%"=="on" pause
if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE%
cmd /C exit /B %ERROR_CODE%

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.6</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.rehome</groupId>
<artifactId>jpahefengweather</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>jpahefengweather</name>
<description>jpahefengweather</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<optional>true</optional>
</dependency>
<!-- 引入poi解析excel -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.14</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<!--sqlserver驱动 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>11.2.0.jre8</version>
</dependency>
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- PostgreSQL Driver -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>6.1.19</version>
</dependency>
</dependencies>
<!--在项目中使用pom.xml进行下载依赖配置的话可以单独使用-->
<repositories>
<repository>
<id>repository</id>
<url>http://47.242.184.139:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,41 @@
package com.rehome.jpahefengweather;
import org.springframework.beans.BeansException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
@EnableJpaAuditing
@EnableScheduling
@SpringBootApplication
public class JpahefengweatherApplication extends SpringBootServletInitializer implements ApplicationContextAware {
public static ApplicationContext context;
public static void main(String[] args) {
SpringApplication.run(JpahefengweatherApplication.class, args);
}
/**
* @date 2022-03-14 15:20
* @description: springbootwar springboot
* @Param: SpringApplicationBuilder
*/
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(JpahefengweatherApplication.class);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
}

@ -0,0 +1,103 @@
package com.rehome.jpahefengweather.controller;
import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.NowWeather;
import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.service.HefengWeatherService;
import com.rehome.jpahefengweather.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/hefengWeather/service")
public class HefengWeatherController {
@Resource
private CityService cityService;
@Resource
private HefengWeatherService hefengWeatherService;
/**
* @date 2022-05-01 14:42
* @description:
* @Param:
*/
@GetMapping("/getCityList")
public Result<List<HefengCity>> getCityList(){
return Result.of(this.cityService.findAllCity());
}
//region 获取历史天气
@PostMapping("/getNowWeatherEntity")
// @ApiOperation(value = "获取历史天气数据", notes = "获取历史天气数据")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
// })
public Result<List<NowWeather>> getNowWeatherEntity(@Validated @RequestBody BaseWeatherFindDto dto){
List<NowWeather> weathers = this.hefengWeatherService.findNowWeatherByLocationIdAndDate(dto.getLocationId(),dto.getWeatherDate());
return Result.of(weathers);
}
//endregion
//region 获取历史天气
@PostMapping("/getNowWeatherDto")
// @ApiOperation(value = "获取历史天气数据", notes = "获取历史天气数据")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
// })
public Result<List<NowWeatherDto>> getNowWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
List<NowWeatherDto> weathers = this.hefengWeatherService.findHistoryWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
return Result.of(weathers);
}
//endregion
//region 获取实时天气
@PostMapping("/getNowWeatherDtoOne")
// @ApiOperation(value = "获取实时天气数据", notes = "获取实时天气数据")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "实时天气数据处理", dataTypeClass = BaseFindDto.class, paramType = "body", required = true),
// })
public Result<NowWeatherDto> getNowWeatherDtoOne(@Validated @RequestBody BaseFindDto dto){
NowWeatherDto nowWeatherDto=this.hefengWeatherService.findNowWeatherByLocationIdAndDateDto(dto.getLocationId());
return Result.of(nowWeatherDto);
}
//endregion
//region 获取历史天气
@PostMapping("/getForecastWeatherDto")
// @ApiOperation(value = "获取天气预报数据", notes = "获取天气预报数据")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
// })
public Result<List<ForecastWeatherDto>> getForecastWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
List<ForecastWeatherDto> weathers = this.hefengWeatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
return Result.of(weathers);
}
//endregion
//region 获取本地保存的和风天气平台,实时天气和天气预报
@PostMapping("/getHefengWeatherResultDtoByLocationIdAndDateDto")
// @ApiOperation(value = "获取本地保存的和风天气平台,实时天气和天气预报", notes = "获取本地保存的和风天气平台,实时天气和天气预报")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
// })
public HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(@Validated @RequestBody BaseWeatherFindDto dto){
HefengWeatherResultDto hefengWeatherResultDto = this.hefengWeatherService.getHefengWeatherResultDtoByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
return hefengWeatherResultDto;
}
//endregion
//region 获取本地保存的和风天气平台,实时天气和天气预报
@PostMapping("/getHefengWeatherResultDtoByLocationId")
// @ApiOperation(value = "获取本地保存的和风天气平台,实时天气和天气预报", notes = "获取本地保存的和风天气平台,实时天气和天气预报")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseFindDto.class, paramType = "body", required = true),
// })
public HefengWeatherResultDto getHefengWeatherResultDtoByLocationId(@Validated @RequestBody BaseFindDto dto){
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
HefengWeatherResultDto hefengWeatherResultDto = this.hefengWeatherService.getHefengWeatherResultDtoByLocationIdAndDateDto(dto.getLocationId(),currentDate);
return hefengWeatherResultDto;
}
//endregion
}

@ -0,0 +1,44 @@
package com.rehome.jpahefengweather.controller;
import com.rehome.jpahefengweather.dto.TyphoonBaseDto;
import com.rehome.jpahefengweather.dto.WztfStormInfoDto;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.WztfStormService;
import com.rehome.jpahefengweather.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/typhoon")
public class WztfwStormController {
@Resource
private WztfStormService wztfStormService;
//endregion
//region 根据年份获取台风列表
@PostMapping("/getWztfStormListByYear")
// @ApiOperation(value = "获取台风列表", notes = "获取台风列表")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "获取台风列表", dataTypeClass = TyphoonBaseDto.class, paramType = "body", required = true),
// })
public Result<List<WztfStorm>> getWztfStormListByYear(@Validated @RequestBody TyphoonBaseDto dto){
return Result.of(this.wztfStormService.findByYear(dto.getYear()));
}
//endregion
//region 根据台风id获取单条台风数据
@PostMapping("/getWztfStormInfoByTfbh")
// @ApiOperation(value = "根据台风id获取单条台风数据", notes = "根据台风id获取单条台风数据")
// @ApiImplicitParams(value = {
// @ApiImplicitParam(name = "dto", value = "根据台风id获取单条台风数据", dataTypeClass = WztfStormInfoDto.class, paramType = "body", required = true),
// })
public Result<WztfStormInfo> getWztfStormInfoByTfbh(@Validated @RequestBody WztfStormInfoDto dto){
return Result.of(this.wztfStormService.findWztfStormInfoByTfbh(dto.getTfbh()));
}
//endregion
}

@ -0,0 +1,62 @@
package com.rehome.jpahefengweather.controller;
import com.rehome.jpahefengweather.entity.TyphoonInfo;
import com.rehome.jpahefengweather.entity.ZjsltStorm;
import com.rehome.jpahefengweather.service.ZjsltStormService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @author huangwenfei
* @version v1.0.0.0
* Created DateTime 2025-06-17 13:48
* @description:
*/
@RestController
@RequestMapping("/storm/service")
public class ZjsltStormController {
//台风服务
@Resource
private ZjsltStormService zjsltStormService;
/**
*
* @author huangwenfei
* Created DateTime 2021-05-08 14:03
*/
@CrossOrigin
@RequestMapping(value = "/getStormListByYear",method = RequestMethod.GET)
public List<ZjsltStorm> getStormListByYear(@RequestParam(value = "year", required = false) String year){
String currentYear = new SimpleDateFormat("yyyy").format(new Date());
String paramYear = year==null?currentYear:year;
return this.zjsltStormService.findByYear(paramYear);
}
/**
*
* @author huangwenfei
* Created DateTime 2025-06-17 14:48
*/
@CrossOrigin
@RequestMapping(value = "/getTyhoonActivityList",method = RequestMethod.GET)
public List<ZjsltStorm> getTyhoonActivityList(){
return this.zjsltStormService.getTyhoonActivity();
}
/**
*
* @author huangwenfei
* Created DateTime 2021-05-10 14:17
*/
@CrossOrigin
@ResponseBody
@RequestMapping(value = "/getTyhoonInfo",method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public TyphoonInfo getTyhoonInfo(@RequestParam("tfid") String tfid) {
return this.zjsltStormService.findTyphoonInfoByTfid(tfid);
}
}

@ -0,0 +1,21 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.HefengCity;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface CityRepository extends JpaRepository<HefengCity,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
HefengCity findByLocationId(String location_ID);
List<HefengCity> findByAdm1NameEn(String provinceCode);
List<HefengCity> findByAdm2NameEn(String cityCode);
List<HefengCity> findByLocationNameEn(String locationNameEn);
}

@ -0,0 +1,19 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.ForecastWeather;
import com.rehome.jpahefengweather.entity.NowWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface ForecastWeatherRepository extends JpaRepository<ForecastWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
List<ForecastWeather> findByLocationIdAndWeatherDate(String locationId, String weatherDate);
List<ForecastWeather> findByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate);
}

@ -0,0 +1,15 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.HefengFutureWeather;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface HefengFutureWeatherRepository extends JpaRepository<HefengFutureWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
HefengFutureWeather findByLocationIdAndFxDate(String location_ID,String fxDate);
}

@ -0,0 +1,14 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.HefengRealtimeWeather;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface HefengRealtimeWeatherRepository extends JpaRepository<HefengRealtimeWeather,Long> {
}

@ -0,0 +1,18 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NmcCity;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface NmcCityRepository extends JpaRepository<NmcCity,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
NmcCity findByCode(String code);
}

@ -0,0 +1,20 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NmcForecastWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface NmcForecastWeatherRepository extends JpaRepository<NmcForecastWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
List<NmcForecastWeather> findByWeatherDateOrderByIdDesc(String weatherDate);
}

@ -0,0 +1,20 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NmcNowWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface NmcNowWeatherRepository extends JpaRepository<NmcNowWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
List<NmcNowWeather> findByCodeAndWeatherDateOrderByIdDesc(String code, String weatherDate);
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NmcProvince;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface NmcProvinceRepository extends JpaRepository<NmcProvince,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
NmcProvince findByCode(String code);
}

@ -0,0 +1,22 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NmcStorm;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface NmcStormRepository extends JpaRepository<NmcStorm,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
NmcStorm findByCode(Long code);
List<NmcStorm> findByYear(String year);
}

@ -0,0 +1,24 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.NowWeather;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface NowWeatherRepository extends JpaRepository<NowWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
//List<NowWeather> findByLocationIdAndWeatherDate(String locationId, String weatherDate);
List<NowWeather> findByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate);
List<NowWeather> findByLocationIdAndWeatherDateOrderByIdAsc(String locationId, String weatherDate);
NowWeather findFirstByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate);
NowWeather findTopByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate);
//NowWeather findByLocationIdO(String locationId, String weatherDate);
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.HefengProvince;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface ProvinceRepository extends JpaRepository<HefengProvince,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
HefengProvince findByCode(String code);
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.TyphoonInfo;
import org.springframework.data.jpa.repository.JpaRepository;
/**
* T :
* ID :OID
*
*/
public interface TyphoonInfoRepository extends JpaRepository<TyphoonInfo,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
TyphoonInfo findByTfid(String tfid);
}

@ -0,0 +1,18 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.WztfStorm;
import com.rehome.jpahefengweather.entity.WztfStormInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface WztfStormInfoRepository extends JpaRepository<WztfStormInfo,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
WztfStormInfo findByTfbh(String tfbh);
}

@ -0,0 +1,20 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.WztfStorm;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface WztfStormRepository extends JpaRepository<WztfStorm,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
WztfStorm findByTfbh(String tfbh);
List<WztfStorm> findByYear(String year);
}

@ -0,0 +1,25 @@
package com.rehome.jpahefengweather.dao;
import com.rehome.jpahefengweather.entity.ZjsltStorm;
import org.springframework.data.jpa.repository.JpaRepository;
import java.util.List;
/**
* T :
* ID :OID
*
*/
public interface ZjsltStormRepository extends JpaRepository<ZjsltStorm,String> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
ZjsltStorm findByTfid(String tfid);
List<ZjsltStorm> findByYear(String year);
List<ZjsltStorm> findByYearAndIsactiveOrderByCreateDateDesc(String year,String isactive);
}

@ -0,0 +1,58 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "BaseDto", description = "接收数据")
public class BaseDto {
//@ApiModelProperty("API状态码具体含义请参考状态码 200请求成功")
private String code;
//@ApiModelProperty("当前API的最近更新时间")
private String updateTime;
//@ApiModelProperty("当前数据的响应式页面,便于嵌入网站或应用")
private String fxLink;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static BaseDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, BaseDto.class);
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getUpdateTime() {
return updateTime;
}
public void setUpdateTime(String updateTime) {
this.updateTime = updateTime;
}
public String getFxLink() {
return fxLink;
}
public void setFxLink(String fxLink) {
this.fxLink = fxLink;
}
}

@ -0,0 +1,36 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "BaseFindDto", description = "接收数据")
public class BaseFindDto{
//@ApiModelProperty("位置id,从城市列表获取")
private String locationId;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return cc.rehome.zhanjiang.data_center_model.domain.security.authorize.maintenance_temporary.in.MaintenanceTemporaryFindDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static BaseFindDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, BaseFindDto.class);
}
public String getLocationId() {
return locationId;
}
public void setLocationId(String locationId) {
this.locationId = locationId;
}
}

@ -0,0 +1,36 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "BaseWeatherFindDto", description = "接收数据")
public class BaseWeatherFindDto extends BaseFindDto{
//@ApiModelProperty("查询天气的日期")
private String weatherDate;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return cc.rehome.zhanjiang.data_center_model.domain.security.authorize.maintenance_temporary.in.MaintenanceTemporaryFindDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static BaseWeatherFindDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, BaseWeatherFindDto.class);
}
public String getWeatherDate() {
return weatherDate;
}
public void setWeatherDate(String weatherDate) {
this.weatherDate = weatherDate;
}
}

@ -0,0 +1,299 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "ForecastDto", description = "天气预报数据")
public class ForecastDto {
//@ApiModelProperty("预报日期")
private String fxDate;
//@ApiModelProperty("日出时间")
private String sunrise;
//@ApiModelProperty("日落时间")
private String sunset;
//@ApiModelProperty("月升时间")
private String moonrise;
//@ApiModelProperty("月落时间")
private String moonset;
//@ApiModelProperty("月相名称")
private String moonPhase;
//@ApiModelProperty("月相图标代码,图标可通过天气状况和图标下载")
private String moonPhaseIcon;
//@ApiModelProperty("预报当天最高温度")
private String tempMax;
//@ApiModelProperty("预报当天最低温度")
private String tempMin;
//@ApiModelProperty("预报白天天气状况的图标代码,图标可通过天气状况和图标下载")
private String iconDay;
//@ApiModelProperty("预报白天天气状况文字描述,包括阴晴雨雪等天气状态的描述")
private String textDay;
//@ApiModelProperty("预报夜间天气状况的图标代码,图标可通过天气状况和图标下载")
private String iconNight;
//@ApiModelProperty("预报晚间天气状况文字描述,包括阴晴雨雪等天气状态的描述")
private String textNight;
//@ApiModelProperty("预报白天风向360角度")
private String wind360Day;
//@ApiModelProperty("预报白天风向")
private String windDirDay;
//@ApiModelProperty("预报白天风力等级")
private String windScaleDay;
//@ApiModelProperty("预报白天风速,公里/小时")
private String windSpeedDay;
//@ApiModelProperty("预报夜间风向360角度")
private String wind360Night;
//@ApiModelProperty("预报夜间当天风向")
private String windDirNight;
//@ApiModelProperty("预报夜间风力等级")
private String windScaleNight;
//@ApiModelProperty("预报夜间风速,公里/小时")
private String windSpeedNight;
//@ApiModelProperty("预报当天总降水量,默认单位:毫米")
private String precip;
//@ApiModelProperty("紫外线强度指数")
private String uvIndex;
//@ApiModelProperty("相对湿度,百分比数值")
private String humidity;
//@ApiModelProperty("大气压强,默认单位:百帕")
private String pressure;
//@ApiModelProperty("能见度,默认单位:公里")
private String vis;
//@ApiModelProperty("云量,百分比数值。可能为空")
private String cloud;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static ForecastDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, ForecastDto.class);
}
public String getFxDate() {
return fxDate;
}
public void setFxDate(String fxDate) {
this.fxDate = fxDate;
}
public String getSunrise() {
return sunrise;
}
public void setSunrise(String sunrise) {
this.sunrise = sunrise;
}
public String getSunset() {
return sunset;
}
public void setSunset(String sunset) {
this.sunset = sunset;
}
public String getMoonrise() {
return moonrise;
}
public void setMoonrise(String moonrise) {
this.moonrise = moonrise;
}
public String getMoonset() {
return moonset;
}
public void setMoonset(String moonset) {
this.moonset = moonset;
}
public String getMoonPhase() {
return moonPhase;
}
public void setMoonPhase(String moonPhase) {
this.moonPhase = moonPhase;
}
public String getMoonPhaseIcon() {
return moonPhaseIcon;
}
public void setMoonPhaseIcon(String moonPhaseIcon) {
this.moonPhaseIcon = moonPhaseIcon;
}
public String getTempMax() {
return tempMax;
}
public void setTempMax(String tempMax) {
this.tempMax = tempMax;
}
public String getTempMin() {
return tempMin;
}
public void setTempMin(String tempMin) {
this.tempMin = tempMin;
}
public String getIconDay() {
return iconDay;
}
public void setIconDay(String iconDay) {
this.iconDay = iconDay;
}
public String getTextDay() {
return textDay;
}
public void setTextDay(String textDay) {
this.textDay = textDay;
}
public String getIconNight() {
return iconNight;
}
public void setIconNight(String iconNight) {
this.iconNight = iconNight;
}
public String getTextNight() {
return textNight;
}
public void setTextNight(String textNight) {
this.textNight = textNight;
}
public String getWind360Day() {
return wind360Day;
}
public void setWind360Day(String wind360Day) {
this.wind360Day = wind360Day;
}
public String getWindDirDay() {
return windDirDay;
}
public void setWindDirDay(String windDirDay) {
this.windDirDay = windDirDay;
}
public String getWindScaleDay() {
return windScaleDay;
}
public void setWindScaleDay(String windScaleDay) {
this.windScaleDay = windScaleDay;
}
public String getWindSpeedDay() {
return windSpeedDay;
}
public void setWindSpeedDay(String windSpeedDay) {
this.windSpeedDay = windSpeedDay;
}
public String getWind360Night() {
return wind360Night;
}
public void setWind360Night(String wind360Night) {
this.wind360Night = wind360Night;
}
public String getWindDirNight() {
return windDirNight;
}
public void setWindDirNight(String windDirNight) {
this.windDirNight = windDirNight;
}
public String getWindScaleNight() {
return windScaleNight;
}
public void setWindScaleNight(String windScaleNight) {
this.windScaleNight = windScaleNight;
}
public String getWindSpeedNight() {
return windSpeedNight;
}
public void setWindSpeedNight(String windSpeedNight) {
this.windSpeedNight = windSpeedNight;
}
public String getPrecip() {
return precip;
}
public void setPrecip(String precip) {
this.precip = precip;
}
public String getUvIndex() {
return uvIndex;
}
public void setUvIndex(String uvIndex) {
this.uvIndex = uvIndex;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getPressure() {
return pressure;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public String getVis() {
return vis;
}
public void setVis(String vis) {
this.vis = vis;
}
public String getCloud() {
return cloud;
}
public void setCloud(String cloud) {
this.cloud = cloud;
}
}

@ -0,0 +1,38 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.List;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "ForecastWeatherDto", description = "接收数据")
public class ForecastWeatherDto extends BaseDto{
//@ApiModelProperty("天气预报数据")
private List<ForecastDto> daily;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static ForecastWeatherDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, ForecastWeatherDto.class);
}
public List<ForecastDto> getDaily() {
return daily;
}
public void setDaily(List<ForecastDto> daily) {
this.daily = daily;
}
}

@ -0,0 +1,21 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.entity.HefengFutureWeather;
import com.rehome.jpahefengweather.entity.HefengRealtimeWeather;
import lombok.Data;
import java.util.List;
@Data
public class HefengFutureWeatherDto {
//状态码
private String code;
//当前API的最近更新时间
private String updateTime;
//当前数据的响应式页面,便于嵌入网站或应用
private String fxLink ;
//每日天气预报
private List<HefengFutureWeather> daily;
//数据来源,可能为空
private HefengWeatherRefer refer;
}

@ -0,0 +1,18 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.entity.HefengRealtimeWeather;
import lombok.Data;
@Data
public class HefengRealtimeWeatherDto {
//状态码
private String code;
//当前API的最近更新时间
private String updateTime;
//当前数据的响应式页面,便于嵌入网站或应用
private String fxLink ;
//实时天气
private HefengRealtimeWeather now;
//数据来源,可能为空
private HefengWeatherRefer refer;
}

@ -0,0 +1,14 @@
package com.rehome.jpahefengweather.dto;
import lombok.Data;
import java.util.List;
@Data
public class HefengWeatherRefer {
//原始数据来源,或数据源说明,可能为空
private List<String> sources;
// 数据许可或版权声明,可能为空
private List<String> license;
}

@ -0,0 +1,11 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.entity.HefengFutureWeather;
import lombok.Data;
import java.util.List;
@Data
public class HefengWeatherResultDto extends HefengRealtimeWeatherDto{
//每日天气预报
private List<HefengFutureWeather> daily;
}

@ -0,0 +1,46 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "NmcBaseDto", description = "接收数据")
public class NmcBaseDto {
//@ApiModelProperty("API状态码具体含义请参考状态码 0请求成功")
private int code;
//@ApiModelProperty("当前API的最近更新时间")
private String msg;
/**
* map NmcBaseDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.NmcBaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static NmcBaseDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, NmcBaseDto.class);
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}

@ -0,0 +1,37 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.List;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "NmcForecastWeatherDto", description = "接收数据")
public class NmcForecastWeatherDto extends NmcBaseDto{
//@ApiModelProperty("实时天气数据")
private List<List<String>> data;
/**
* map NmcNowWeatherDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.NmcNowWeatherDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static NmcForecastWeatherDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, NmcForecastWeatherDto.class);
}
public List<List<String>> getData() {
return data;
}
public void setData(List<List<String>> data) {
this.data = data;
}
}

@ -0,0 +1,36 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.dto.bean.NmcNowData;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "NmcNowWeatherDto", description = "接收数据")
public class NmcNowWeatherDto extends NmcBaseDto{
//@ApiModelProperty("实时天气数据")
private NmcNowData data;
/**
* map NmcNowWeatherDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.NmcNowWeatherDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static NmcNowWeatherDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, NmcNowWeatherDto.class);
}
public NmcNowData getData() {
return data;
}
public void setData(NmcNowData data) {
this.data = data;
}
}

@ -0,0 +1,177 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "NowDto", description = "实时天气数据")
public class NowDto {
//@ApiModelProperty("数据观测时间")
private String obsTime;
//@ApiModelProperty("温度,默认单位:摄氏度")
private String temp;
//@ApiModelProperty("体感温度,默认单位:摄氏度")
private String feelsLike;
//@ApiModelProperty("天气状况和图标的代码,图标可通过天气状况和图标下载")
private String icon;
//@ApiModelProperty("天气状况的文字描述,包括阴晴雨雪等天气状态的描述")
private String text;
//@ApiModelProperty("风向360角度")
private String wind360;
//@ApiModelProperty("风向")
private String windDir;
//@ApiModelProperty("风力等级")
private String windScale;
//@ApiModelProperty("风速,公里/小时")
private String windSpeed;
//@ApiModelProperty("相对湿度,百分比数值")
private String humidity;
//@ApiModelProperty("当前小时累计降水量,默认单位:毫米")
private String precip;
//@ApiModelProperty("大气压强,默认单位:百帕")
private String pressure;
//@ApiModelProperty("能见度,默认单位:公里")
private String vis;
//@ApiModelProperty("云量,百分比数值。可能为空")
private String cloud;
//@ApiModelProperty("露点温度。可能为空")
private String dew;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static NowDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, NowDto.class);
}
public String getObsTime() {
return obsTime;
}
public void setObsTime(String obsTime) {
this.obsTime = obsTime;
}
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getFeelsLike() {
return feelsLike;
}
public void setFeelsLike(String feelsLike) {
this.feelsLike = feelsLike;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getWind360() {
return wind360;
}
public void setWind360(String wind360) {
this.wind360 = wind360;
}
public String getWindDir() {
return windDir;
}
public void setWindDir(String windDir) {
this.windDir = windDir;
}
public String getWindScale() {
return windScale;
}
public void setWindScale(String windScale) {
this.windScale = windScale;
}
public String getWindSpeed() {
return windSpeed;
}
public void setWindSpeed(String windSpeed) {
this.windSpeed = windSpeed;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getPrecip() {
return precip;
}
public void setPrecip(String precip) {
this.precip = precip;
}
public String getPressure() {
return pressure;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public String getVis() {
return vis;
}
public void setVis(String vis) {
this.vis = vis;
}
public String getCloud() {
return cloud;
}
public void setCloud(String cloud) {
this.cloud = cloud;
}
public String getDew() {
return dew;
}
public void setDew(String dew) {
this.dew = dew;
}
}

@ -0,0 +1,36 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "NowWeatherDto", description = "接收数据")
public class NowWeatherDto extends BaseDto{
//@ApiModelProperty("实时天气数据")
private NowDto now;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static NowWeatherDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, NowWeatherDto.class);
}
public NowDto getNow() {
return now;
}
public void setNow(NowDto now) {
this.now = now;
}
}

@ -0,0 +1,39 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import lombok.Data;
import java.util.List;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "StormDataDto", description = "接收数据")
@Data
public class StormDataDto extends BaseDto{
//@ApiModelProperty("获取台风列表数据")
List<List<String>> typhoonList;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static StormDataDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, StormDataDto.class);
}
public List<List<String>> getTyphoonList() {
return typhoonList;
}
public void setTyphoonList(List<List<String>> typhoonList) {
this.typhoonList = typhoonList;
}
}

@ -0,0 +1,188 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-08-23 11:13
*/
//@ApiModel(value = "TyhoonActivityDto", description = "实时活跃台风")
public class TyhoonActivityDto {
//@ApiModelProperty("台风英文名")
private String enname;
//@ApiModelProperty("纬度")
private String lat;
//@ApiModelProperty("经度")
private String lng;
//@ApiModelProperty("台风移动方向")
private String movedirection;
//@ApiModelProperty("台风移动速速")
private String movespeed;
//@ApiModelProperty("台风中文名")
private String name;
//@ApiModelProperty("台风风力等级")
private String power;
//@ApiModelProperty("中心气压,大气压强,默认单位:百帕")
private String pressure;
//@ApiModelProperty("七级风速圈半径")
private String radius7;
//@ApiModelProperty("十级风速圈半径")
private String radius10;
//@ApiModelProperty("十二级风速圈半径")
private String radius12;
//@ApiModelProperty("台风风速")
private String speed;
//@ApiModelProperty("台风等级名称")
private String strong;
//@ApiModelProperty("台风id")
private String tfid;
//@ApiModelProperty("发布时间")
private String time;
//@ApiModelProperty("发布时间格式化")
private String timeformate;
/**
* map TyhoonActivityDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.TyhoonActivityDto
* @author HuangWenFei
* Created DateTime 2022-08-23 11:13
*/
public static TyhoonActivityDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, TyhoonActivityDto.class);
}
public String getEnname() {
return enname;
}
public void setEnname(String enname) {
this.enname = enname;
}
public String getLat() {
return lat;
}
public void setLat(String lat) {
this.lat = lat;
}
public String getLng() {
return lng;
}
public void setLng(String lng) {
this.lng = lng;
}
public String getMovedirection() {
return movedirection;
}
public void setMovedirection(String movedirection) {
this.movedirection = movedirection;
}
public String getMovespeed() {
return movespeed;
}
public void setMovespeed(String movespeed) {
this.movespeed = movespeed;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPower() {
return power;
}
public void setPower(String power) {
this.power = power;
}
public String getPressure() {
return pressure;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public String getRadius7() {
return radius7;
}
public void setRadius7(String radius7) {
this.radius7 = radius7;
}
public String getRadius10() {
return radius10;
}
public void setRadius10(String radius10) {
this.radius10 = radius10;
}
public String getRadius12() {
return radius12;
}
public void setRadius12(String radius12) {
this.radius12 = radius12;
}
public String getSpeed() {
return speed;
}
public void setSpeed(String speed) {
this.speed = speed;
}
public String getStrong() {
return strong;
}
public void setStrong(String strong) {
this.strong = strong;
}
public String getTfid() {
return tfid;
}
public void setTfid(String tfid) {
this.tfid = tfid;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getTimeformate() {
return timeformate;
}
public void setTimeformate(String timeformate) {
this.timeformate = timeformate;
}
}

@ -0,0 +1,38 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "TyphoonBaseDto", description = "实时天气数据")
public class TyphoonBaseDto {
//@ApiModelProperty("数据观测时间")
private String year;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static TyphoonBaseDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, TyphoonBaseDto.class);
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
}

@ -0,0 +1,37 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "TyphoonTfidDto", description = "实时天气数据")
public class TyphoonTfidDto {
//@ApiModelProperty("数据观测时间")
private String tfid;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static TyphoonTfidDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, TyphoonTfidDto.class);
}
public String getTfid() {
return tfid;
}
public void setTfid(String tfid) {
this.tfid = tfid;
}
}

@ -0,0 +1,37 @@
package com.rehome.jpahefengweather.dto;
import com.rehome.jpahefengweather.utils.MapUtil;
import java.util.Map;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
//@ApiModel(value = "WztfStormInfoDto", description = "实时天气数据")
public class WztfStormInfoDto {
//@ApiModelProperty("数据观测时间")
private String tfbh;
/**
* map MaintenanceTemporaryFindDto
*
* @param map map
* @return com.rehome.jpahefengweather.dto.BaseDto
* @author HuangWenFei
* Created DateTime 2022-04-19 10:02
*/
public static WztfStormInfoDto ofSelfMap(Map<String, Object> map) {
return MapUtil.fromMap(map, WztfStormInfoDto.class);
}
public String getTfbh() {
return tfbh;
}
public void setTfbh(String tfbh) {
this.tfbh = tfbh;
}
}

@ -0,0 +1,12 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Air {
private String forecasttime;
private int aqi;
private int aq;
private String text;
private String aqiCode;
}

@ -0,0 +1,4 @@
package com.rehome.jpahefengweather.dto.bean;
public class NmcForecastData {
}

@ -0,0 +1,16 @@
package com.rehome.jpahefengweather.dto.bean;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import lombok.Data;
import java.util.List;
@Data
public class NmcNowData {
//实时天气
Real real;
//空气
Air air;
//温度变化图表曲线图数据
List<Tempchart> tempchart;
}

@ -0,0 +1,12 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Real {
private String publish_time;
private Station station;
private Weather weather;
private Wind wind;
private Warn warn;
}

@ -0,0 +1,11 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Station {
private String code;
private String province;
private String city;
private String url;
}

@ -0,0 +1,14 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Tempchart {
private String time;
private int max_temp;
private int min_temp;
private String day_img;
private String day_text;
private String night_img;
private String night_text;
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Warn {
private String alert;
private String pic;
private String province;
private String city;
private String url;
private String issuecontent;
private String fmeans;
private String signaltype;
private String signallevel;
private String pic2;
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Weather {
private double temperature;
private double temperatureDiff;
private int airpressure;
private int humidity;
private int rain;
private int rcomfort;
private int icomfort;
private String info;
private String img;
private double feelst;
}

@ -0,0 +1,11 @@
package com.rehome.jpahefengweather.dto.bean;
import lombok.Data;
@Data
public class Wind {
private String direct;
private int degree;
private String power;
private double speed;
}

@ -0,0 +1,43 @@
package com.rehome.jpahefengweather.entity;
import jakarta.persistence.*;
import lombok.Data;
import org.hibernate.annotations.Proxy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
//@Table(name="t_users")
public class ForecastWeather implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String locationId;
private String province;
private String city ;
private String locationNameZh;
//存放长文本
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;
// @CreatedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
// @LastModifiedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,53 @@
package com.rehome.jpahefengweather.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class HefengCity implements Serializable {
// 区、县位置id
@Id
private String locationId;
//区、县位置 英文名称
private String locationNameEn;
//区、县位置 中文名称
private String locationNameZh;
//ISO_3166_1 国家编码
private String countryCode;
//国家英文名称
private String countryNameEn ;
//国家中文名称
private String countryNameZh ;
//省份英文名称
private String adm1NameEn;
//省份中文名称
private String adm1NameZh;
//城市英文名称
private String adm2NameEn;
//城市中文名称
private String adm2NameZh ;
//时区
private String timezone ;
//纬度
private String latitude;
//经度
private String longitude;
//区、县位置编码(仅限中国城市))
private String adcode;
// @CreatedDate
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
// @LastModifiedDate
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,150 @@
package com.rehome.jpahefengweather.entity;
import java.util.Date;
import jakarta.persistence.*;
import lombok.Data;
@Data
@Entity
@Table(indexes = {@Index(name = "idx_location_id_future", columnList = "locationId")})
public class HefengFutureWeather {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length=20)
private String locationId;
@Column(length=20)
private String province;
@Column(length=20)
private String city ;
@Column(length=20)
private String locationNameZh;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
@Temporal(TemporalType.TIMESTAMP)
private Date updateTime;
//预报日期
@Column(length=20)
private String fxDate ;
//日出时间,在高纬度地区可能为空
@Column(length=20)
private String sunrise ;
//日落时间,在高纬度地区可能为空
@Column(length=20)
private String sunset ;
@Column(length=20)
//当天月升时间,可能为空
private String moonrise ;
@Column(length=20)
//当天月落时间,可能为空
private String moonset ;
@Column(length=20)
// 月相名称
private String moonPhase ;
@Column(length=20)
//月相图标代码,另请参考天气图标项目
private String moonPhaseIcon ;
@Column(length=20)
//预报当天最高温度
private double tempMax ;
//预报当天最低温度
private double tempMin ;
@Column(length=20)
//预报白天天气状况的图标代码,另请参考天气图标项目
private String iconDay ;
@Column(length=20)
//预报白天天气状况文字描述,包括阴晴雨雪等天气状态的描述
private String textDay ;
@Column(length=20)
//预报夜间天气状况的图标代码,另请参考天气图标项目
private String iconNight ;
@Column(length=20)
//预报晚间天气状况文字描述,包括阴晴雨雪等天气状态的描述
private String textNight ;
@Column(length=20)
//预报白天风向360角度
private String wind360Day ;
@Column(length=20)
//预报白天风向
private String windDirDay ;
@Column(length=20)
//预报白天风力等级
private String windScaleDay ;
@Column(length=20)
//预报白天风速,公里/小时
private String windSpeedDay ;
@Column(length=20)
//预报夜间风向360角度
private String wind360Night ;
@Column(length=20)
//预报夜间当天风向
private String windDirNight ;
@Column(length=20)
//预报夜间风力等级
private String windScaleNight ;
@Column(length=20)
//预报夜间风速,公里/小时
private String windSpeedNight ;
@Column(length=20)
//相对湿度,百分比数值
private double humidity ;
@Column(length=20)
//预报当天总降水量,默认单位:毫米
private String precip ;
@Column(length=20)
//大气压强,默认单位:百帕
private String pressure ;
@Column(length=20)
//能见度,默认单位:公里
private String vis ;
@Column(length=20)
//云量,百分比数值。可能为空
private String cloud ;
//紫外线强度指数
@Column(length=20)
private String uvIndex ;
//当前数据的响应式页面,便于嵌入网站或应用
@Column(length=100)
private String fxLink ;
}
// code 请参考状态码
// updateTime 当前API的最近更新时间
// fxLink 当前数据的响应式页面,便于嵌入网站或应用
// daily.fxDate 预报日期
// daily.sunrise 日出时间,在高纬度地区可能为空
// daily.sunset 日落时间,在高纬度地区可能为空
// daily.moonrise 当天月升时间,可能为空
// daily.moonset 当天月落时间,可能为空
// daily.moonPhase 月相名称
// daily.moonPhaseIcon 月相图标代码,另请参考天气图标项目
// daily.tempMax 预报当天最高温度
// daily.tempMin 预报当天最低温度
// daily.iconDay 预报白天天气状况的图标代码,另请参考天气图标项目
// daily.textDay 预报白天天气状况文字描述,包括阴晴雨雪等天气状态的描述
// daily.iconNight 预报夜间天气状况的图标代码,另请参考天气图标项目
// daily.textNight 预报晚间天气状况文字描述,包括阴晴雨雪等天气状态的描述
// daily.wind360Day 预报白天风向360角度
// daily.windDirDay 预报白天风向
// daily.windScaleDay 预报白天风力等级
// daily.windSpeedDay 预报白天风速,公里/小时
// daily.wind360Night 预报夜间风向360角度
// daily.windDirNight 预报夜间当天风向
// daily.windScaleNight 预报夜间风力等级
// daily.windSpeedNight 预报夜间风速,公里/小时
// daily.precip 预报当天总降水量,默认单位:毫米
// daily.uvIndex 紫外线强度指数
// daily.humidity 相对湿度,百分比数值
// daily.pressure 大气压强,默认单位:百帕
// daily.vis 能见度,默认单位:公里
// daily.cloud 云量,百分比数值。可能为空
// refer.sources 原始数据来源,或数据源说明,可能为空
// refer.license 数据许可或版权声明,可能为空

@ -0,0 +1,27 @@
package com.rehome.jpahefengweather.entity;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class HefengProvince implements Serializable{
//省份编号
@Id
private String code;
//省份中文名称
private String name;
//url
private String url;
//创建时间
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
//最后一次更新时间
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,109 @@
package com.rehome.jpahefengweather.entity;
import jakarta.persistence.*;
import lombok.Data;
import java.util.Date;
@Data
@Entity
@Table(indexes = {@Index(name = "idx_location_id_realtime", columnList = "locationId"),@Index(name = "idx_year", columnList = "year"),@Index(name = "idx_year_month", columnList = "yearAndMonth"),@Index(name = "idx_date", columnList = "date")})
public class HefengRealtimeWeather {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(length=20)
private String locationId;
@Column(length=20)
private String province;
@Column(length=20)
private String city ;
@Column(length=20)
private String locationNameZh;
@Temporal(TemporalType.TIMESTAMP)
private Date createTime;
//数据观测时间、采集时间
@Column(length=30)
private String obsTime ;
//温度,默认单位:摄氏度
@Column(length=20)
private double temp ;
//体感温度,默认单位:摄氏度
@Column(length=20)
private String feelsLike ;
//天气状况的图标代码,另请参考天气图标项目
@Column(length=20)
private String icon ;
//天气状况的文字描述,包括阴晴雨雪等天气状态的描述
@Column(length=20)
private String text ;
//风向360角度
@Column(length=20)
private String wind360 ;
//风向
@Column(length=20)
private String windDir ;
//风力等级
@Column(length=20)
private String windScale ;
//风速,公里/小时
@Column(length=20)
private String windSpeed ;
//相对湿度,百分比数值
@Column(length=20)
private double humidity ;
//过去1小时降水量默认单位毫米
@Column(length=20)
private String precip ;
//大气压强,默认单位:百帕
@Column(length=20)
private String pressure ;
//能见度,默认单位:公里
@Column(length=20)
private String vis ;
@Column(length=20)
//云量,百分比数值。可能为空
private String cloud ;
//露点温度。可能为空
@Column(length=20)
private String dew ;
//当前数据的响应式页面,便于嵌入网站或应用
@Column(length=100)
private String fxLink ;
//当前数据的响应式页面,便于嵌入网站或应用
@Column(length=20)
private String year ;
//当前数据的响应式页面,便于嵌入网站或应用
@Column(length=20)
private String yearAndMonth ;
//当前数据的响应式页面,便于嵌入网站或应用
@Column(length=20)
private String date ;
}
// code 请参考状态码
// updateTime 当前API的最近更新时间
// fxLink 当前数据的响应式页面,便于嵌入网站或应用
// now.obsTime 数据观测时间
// now.temp 温度,默认单位:摄氏度
// now.feelsLike 体感温度,默认单位:摄氏度
// now.icon 天气状况的图标代码,另请参考天气图标项目
// now.text 天气状况的文字描述,包括阴晴雨雪等天气状态的描述
// now.wind360 风向360角度
// now.windDir 风向
// now.windScale 风力等级
// now.windSpeed 风速,公里/小时
// now.humidity 相对湿度,百分比数值
// now.precip 过去1小时降水量默认单位毫米
// now.pressure 大气压强,默认单位:百帕
// now.vis 能见度,默认单位:公里
// now.cloud 云量,百分比数值。可能为空
// now.dew 露点温度。可能为空
// refer.sources 原始数据来源,或数据源说明,可能为空
// refer.license 数据许可或版权声明,可能为空

@ -0,0 +1,26 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class NmcCity implements Serializable{
@Id
private String code;
private String province;
private String city;
private String url;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,33 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import org.hibernate.annotations.Proxy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class NmcForecastWeather implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
private String weather;
private String weatherDate;
private String code;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,29 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class NmcNowWeather implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
//存放长文本
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;
private String code;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,26 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class NmcProvince implements Serializable{
@Id
private String code;
private String name;
private String url;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}
//1655455805800
//1655455830002

@ -0,0 +1,42 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class NmcStorm implements Serializable {
@Id
private Long code;
//台风接入平台
private String ename;
//台风名称
private String name ;
//台风编号
private Long tfNo ;
//台风编号字符串
private String tfNoString ;
//台风描述
private String nameDesc;
//是否为活跃台风 1:活跃台风 0:台风已停止
private Long isActive ;
//台风所处年份
private String year ;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,41 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
//@Table(name="t_users")
public class NowWeather implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String locationId;
private String province;
private String city ;
private String locationNameZh;
//存放长文本
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;
// @CreatedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
// @LastModifiedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,27 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class TyphoonInfo implements Serializable {
@Id
private String tfid;
//存放长文本
@Column(columnDefinition = "TEXT")
private String stormData;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,41 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class WztfStorm implements Serializable {
@Id
private String tfbh;
//台风中文名称
private String name ;
//台风英文名称
private String ename;
//台风结束时间
private String end_time ;
//台风开始时间
private String begin_time ;
//台风标识
private String ident;
//是否为活跃台风 1:活跃台风 0:台风已停止
private int is_current ;
//台风所处年份
private String year ;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
}

@ -0,0 +1,27 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class WztfStormInfo implements Serializable {
@Id
private String tfbh;
//存放长文本
@Column(columnDefinition = "TEXT")
private String stormData;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;
}

@ -0,0 +1,41 @@
package com.rehome.jpahefengweather.entity;
import lombok.Data;
import jakarta.persistence.*;
import java.io.Serializable;
import java.util.Date;
@Data
@Entity
public class ZjsltStorm implements Serializable {
@Id
private String tfid;
//台风英文名称
private String enname;
//台风中文名称
private String name ;
//台风结束时间
private String endtime ;
//台风开始时间
private String starttime ;
//提示等级
private String warnlevel;
//是否为活跃台风 1:活跃台风 0:台风已停止
private String isactive ;
//台风所处年份
private String year ;
@Temporal(TemporalType.TIMESTAMP)
private Date createDate;
}

@ -0,0 +1,44 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.HefengProvince;
import java.util.List;
public interface CityService {
/**
*
* @param provinceList
*/
void saveProvinceList(List<HefengProvince> provinceList);
/**
*
* @param cityList
*/
void saveCityList(List<HefengCity> cityList);
/**
* 3000+
* @return List
*/
List<HefengCity> findAllCity();
/**
*
* @return List
*/
List<HefengCity> findCityByProvinceCode(String provinceCode);
/**
*
* @return List
*/
List<HefengCity> findCityByCityCode(String cityCode);
/**
*
* @return List
*/
List<HefengCity> findByLocationNameEn(String locationNameEn);
/**
* 3000+
* @return List
*/
List<HefengProvince> findAllProvince();
}

@ -0,0 +1,68 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.dto.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.HefengWeatherResultDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto;
import com.rehome.jpahefengweather.entity.ForecastWeather;
import com.rehome.jpahefengweather.entity.NowWeather;
import java.util.List;
public interface HefengWeatherService {
/**
* 3000+
* @return NowWeather
*/
List<NowWeather> findNowWeatherByLocationIdAndDate(String locationId, String date);
/**
* 3000+
* @return NowWeather
*/
List<NowWeather> findNowWeatherByLocationIdAndDateOrderByCreateDateDesc(String locationId, String date);
/**
*
*/
void saveNowWeather(NowWeather nowWeather);
/**
*
*/
void saveHefengWeatherByLocationNameEn(String locationNameEn);
/**
*
*/
void saveHefengFutureWeatherByLocationNameEn(String locationNameEn);
/**
* 3000+
* @return NowWeather
*/
List<ForecastWeather> findForecastWeatherByLocationIdAndDate(String locationId, String date);
/**
* 3000+
* @return NowWeather
*/
List<ForecastWeather> findForecastWeatherByLocationIdAndDateOrderByCreateDateDesc(String locationId, String date);
/**
*
*/
void saveForecastWeather(ForecastWeather nowWeather);
/**
*
* @return NowWeatherDto
*/
NowWeatherDto findNowWeatherByLocationIdAndDateDto(String locationId);
/**
*
* @return List<NowWeatherDto>
*/
List<NowWeatherDto> findHistoryWeatherByLocationIdAndDateDto(String locationId, String date);
/**
*
* @return List<ForecastWeather>
*/
List<ForecastWeatherDto> findForecastWeatherByLocationIdAndDateDto(String locationId, String date);
/**
* iddtoapi
* @return List<ForecastWeather>
*/
HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(String locationId, String date);
}

@ -0,0 +1,92 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.CityRepository;
import com.rehome.jpahefengweather.dao.ProvinceRepository;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.HefengProvince;
import com.rehome.jpahefengweather.service.CityService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class CityServiceImpl implements CityService {
@Resource
private CityRepository cityRepository;
@Resource
private ProvinceRepository provinceRepository;
@Override
public void saveProvinceList(List<HefengProvince> provinceList) {
Date nowTime = new Date();
for (HefengProvince province : provinceList) {
HefengProvince provinceDb = this.provinceRepository.findByCode(province.getCode());
if (provinceDb != null) {
provinceDb.setName(province.getName());
provinceDb.setLastUpdateDate(nowTime);
this.provinceRepository.save(provinceDb);
}else{
province.setLastUpdateDate(nowTime);
province.setCreateDate(nowTime);
this.provinceRepository.save(province);
}
}
}
@Override
public void saveCityList(List<HefengCity> cityList) {
Date now = new Date();
for (HefengCity city : cityList) {
HefengCity cityDB = this.cityRepository.findByLocationId(city.getLocationId());
if (cityDB != null) {
cityDB.setLocationNameEn(city.getLocationNameEn());
cityDB.setLocationNameZh(city.getLocationNameZh());
cityDB.setCountryCode(city.getCountryCode());
cityDB.setCountryNameEn(city.getCountryNameEn());
cityDB.setCountryNameZh(city.getCountryNameZh());
cityDB.setAdm1NameEn(city.getAdm1NameEn());
cityDB.setAdm1NameZh(city.getAdm1NameZh());
cityDB.setAdm2NameEn(city.getAdm2NameEn());
cityDB.setAdm2NameZh(city.getAdm2NameZh());
cityDB.setTimezone(city.getTimezone());
cityDB.setLatitude(city.getLatitude());
cityDB.setLongitude(city.getLongitude());
cityDB.setAdcode(city.getAdcode());
cityDB.setLastUpdateDate(now);
this.cityRepository.save(cityDB);
} else {
city.setLastUpdateDate(now);
city.setCreateDate(now);
this.cityRepository.save(city);
}
}
}
@Override
public List<HefengCity> findAllCity() {
return this.cityRepository.findAll();
}
@Override
public List<HefengCity> findCityByProvinceCode(String provinceCode) {
return this.cityRepository.findByAdm1NameEn(provinceCode);
}
@Override
public List<HefengCity> findCityByCityCode(String cityCode) {
return this.cityRepository.findByAdm2NameEn(cityCode);
}
@Override
public List<HefengCity> findByLocationNameEn(String locationNameEn) {
return this.cityRepository.findByLocationNameEn(locationNameEn);
}
@Override
public List<HefengProvince> findAllProvince() {
return this.provinceRepository.findAll();
}
}

@ -0,0 +1,282 @@
package com.rehome.jpahefengweather.service.Impl;
import com.google.gson.Gson;
import com.rehome.jpahefengweather.dao.ForecastWeatherRepository;
import com.rehome.jpahefengweather.dao.HefengFutureWeatherRepository;
import com.rehome.jpahefengweather.dao.HefengRealtimeWeatherRepository;
import com.rehome.jpahefengweather.dao.NowWeatherRepository;
import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.service.HefengWeatherService;
import com.rehome.jpahefengweather.utils.OkHttpUtil;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class HefengWeatherServiceImpl implements HefengWeatherService {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private NowWeatherRepository nowWeatherRepository;
@Resource
private ForecastWeatherRepository forecastWeatherRepository;
@Resource
private HefengRealtimeWeatherRepository hefengRealtimeWeatherRepository;
@Resource
private HefengFutureWeatherRepository hefengFutureWeatherRepository;
@Resource
private CityService cityService;
@Override
public List<NowWeather> findNowWeatherByLocationIdAndDate(String locationId, String date) {
return this.nowWeatherRepository.findByLocationIdAndWeatherDateOrderByIdDesc(locationId,date);
}
@Override
public List<NowWeather> findNowWeatherByLocationIdAndDateOrderByCreateDateDesc(String locationId, String date) {
return this.nowWeatherRepository.findByLocationIdAndWeatherDateOrderByIdDesc(locationId,date);
}
@Override
public void saveNowWeather(NowWeather nowWeather) {
this.nowWeatherRepository.save(nowWeather);
}
@Override
public void saveHefengWeatherByLocationNameEn(String locationNameEn) {
List<HefengCity> cityList = this.cityService.findByLocationNameEn(locationNameEn);
log.info(new Gson().toJson(cityList));
log.info("查询实时天气总数:"+String.valueOf(cityList.size()));
if (cityList != null && cityList.size() > 0) {
Date now = new Date();
log.info(String.valueOf(cityList.size()));
for (int i = 0; i < cityList.size(); i++) {
HefengCity city = cityList.get(i);
Map<String, String> params = new HashMap<>();
//我的帐号: c67db396fcdb416c959933d29e30db3d
//克金帐号: 3522d7d5736947d7a63e8d7d95316406
//params.put("key", "c67db396fcdb416c959933d29e30db3d");
params.put("location", city.getLocationId());
String realtimeWeatherData = OkHttpUtil.get("https://m573jftdb9.re.qweatherapi.com/v7/weather/now", params);
log.info(realtimeWeatherData);
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
if (realtimeWeatherData!=null&&realtimeWeatherData.trim().length()>0) {
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
SimpleDateFormat sdfYearMonth = new SimpleDateFormat("yyyy-MM");
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
NowWeather nowWeather = new NowWeather();
nowWeather.setWeatherDate(sdfDate.format(now));
nowWeather.setLocationId(city.getLocationId());
nowWeather.setWeather(realtimeWeatherData);
nowWeather.setCreateDate(now);
nowWeather.setLastUpdateDate(now);
nowWeather.setProvince(city.getAdm1NameZh());
nowWeather.setCity(city.getAdm2NameZh());
nowWeather.setLocationNameZh(city.getLocationNameZh());
this.saveNowWeather(nowWeather);
Gson gson = new Gson();
HefengRealtimeWeatherDto hefengRealtimeWeatherDto = gson.fromJson(realtimeWeatherData,HefengRealtimeWeatherDto.class);
if((!ObjectUtils.isEmpty(hefengRealtimeWeatherDto))&&"200".equals(hefengRealtimeWeatherDto.getCode())){
log.info("----------");
log.info(gson.toJson(hefengRealtimeWeatherDto));
HefengRealtimeWeather realtimeWeather = hefengRealtimeWeatherDto.getNow();
if(!ObjectUtils.isEmpty(realtimeWeather)){
realtimeWeather.setLocationId(city.getLocationId());
realtimeWeather.setProvince(city.getAdm1NameZh());
realtimeWeather.setCity(city.getAdm2NameZh());
realtimeWeather.setLocationNameZh(city.getLocationNameZh());
realtimeWeather.setCreateTime(now);
realtimeWeather.setFxLink(hefengRealtimeWeatherDto.getFxLink());
realtimeWeather.setYear(sdfYear.format(now));
realtimeWeather.setYearAndMonth(sdfYearMonth.format(now));
realtimeWeather.setDate(sdfDate.format(now));
hefengRealtimeWeatherRepository.save(realtimeWeather);
}
}
} else {
log.info("-->");
}
}
}
}
@Override
public void saveHefengFutureWeatherByLocationNameEn(String locationNameEn) {
List<HefengCity> cityList = this.cityService.findByLocationNameEn(locationNameEn);
log.info(new Gson().toJson(cityList));
log.info("查询天气预报总数:"+String.valueOf(cityList.size()));
if (cityList != null && cityList.size() > 0) {
Date now = new Date();
log.info(String.valueOf(cityList.size()));
for (int i = 0; i < cityList.size(); i++) {
HefengCity city = cityList.get(i);
Map<String, String> params = new HashMap<>();
//c67db396fcdb416c959933d29e30db3d
//params.put("key", "c67db396fcdb416c959933d29e30db3d");
params.put("location", city.getLocationId());
String futureWeatherData = OkHttpUtil.get("https://m573jftdb9.re.qweatherapi.com/v7/weather/7d", params);
log.info(futureWeatherData);
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
if (futureWeatherData!=null&&futureWeatherData.trim().length()>0) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
ForecastWeather forecastWeather = new ForecastWeather();
forecastWeather.setWeatherDate(sdf.format(now));
forecastWeather.setLocationId(city.getLocationId());
forecastWeather.setWeather(futureWeatherData);
forecastWeather.setLastUpdateDate(now);
forecastWeather.setCreateDate(now);
forecastWeather.setProvince(city.getAdm1NameZh());
forecastWeather.setCity(city.getAdm2NameZh());
forecastWeather.setLocationNameZh(city.getLocationNameZh());
this.saveForecastWeather(forecastWeather);
Gson gson = new Gson();
HefengFutureWeatherDto hefengFutureWeatherDto = gson.fromJson(futureWeatherData, HefengFutureWeatherDto.class);
if((!ObjectUtils.isEmpty(hefengFutureWeatherDto))&&"200".equals(hefengFutureWeatherDto.getCode())){
log.info("----------");
log.info(gson.toJson(hefengFutureWeatherDto));
List<HefengFutureWeather> dailyHefengFutureWeather = hefengFutureWeatherDto.getDaily();
if(!ObjectUtils.isEmpty(dailyHefengFutureWeather)){
for(HefengFutureWeather daily:dailyHefengFutureWeather){
HefengFutureWeather dailyDB = this.hefengFutureWeatherRepository.findByLocationIdAndFxDate(city.getLocationId(),daily.getFxDate());
if(dailyDB==null){
daily.setLocationId(city.getLocationId());
daily.setProvince(city.getAdm1NameZh());
daily.setCity(city.getAdm2NameZh());
daily.setLocationNameZh(city.getLocationNameZh());
daily.setCreateTime(now);
daily.setUpdateTime(now);
daily.setFxLink(hefengFutureWeatherDto.getFxLink());
hefengFutureWeatherRepository.save(daily);
log.info("-----和风天气预报数据保存成功-----");
log.info(gson.toJson(daily));
}else{
daily.setId(dailyDB.getId());
daily.setLocationId(city.getLocationId());
daily.setProvince(city.getAdm1NameZh());
daily.setCity(city.getAdm2NameZh());
daily.setLocationNameZh(city.getLocationNameZh());
daily.setCreateTime(dailyDB.getCreateTime());
daily.setUpdateTime(now);
daily.setFxLink(hefengFutureWeatherDto.getFxLink());
hefengFutureWeatherRepository.save(daily);
log.info("-----和风天气预报数据更新成功-----");
log.info(gson.toJson(daily));
}
}
}
}
} else {
log.info("-->");
}
}
}
}
@Override
public List<ForecastWeather> findForecastWeatherByLocationIdAndDate(String locationId, String date) {
return this.forecastWeatherRepository.findByLocationIdAndWeatherDate(locationId,date);
}
@Override
public List<ForecastWeather> findForecastWeatherByLocationIdAndDateOrderByCreateDateDesc(String locationId, String date) {
return this.forecastWeatherRepository.findByLocationIdAndWeatherDateOrderByIdDesc(locationId,date);
}
@Override
public void saveForecastWeather(ForecastWeather forecastWeather) {
this.forecastWeatherRepository.save(forecastWeather);
}
@Override
public NowWeatherDto findNowWeatherByLocationIdAndDateDto(String locationId) {
SimpleDateFormat sdFormat=new SimpleDateFormat("yyyy-MM-dd");
String now = sdFormat.format(new Date());
List<NowWeather> nowWeatherList = this.nowWeatherRepository.findByLocationIdAndWeatherDateOrderByIdDesc(locationId,now);
if(nowWeatherList!=null&&nowWeatherList.size()>0){
NowWeather nowWeather=nowWeatherList.get(0);
Gson gson = new Gson();
NowWeatherDto nowWeatherDto = gson.fromJson(nowWeather.getWeather(),NowWeatherDto.class);
return nowWeatherDto;
}
return null;
}
@Override
public List<NowWeatherDto> findHistoryWeatherByLocationIdAndDateDto(String locationId, String date) {
List<NowWeather> weathers = this.findNowWeatherByLocationIdAndDateOrderByCreateDateDesc(locationId,date);
if(weathers!=null&&weathers.size()>0){
List<NowWeatherDto> dtos = new ArrayList<>();
for (NowWeather weather:weathers) {
Gson gson = new Gson();
NowWeatherDto nowWeatherDto = gson.fromJson(weather.getWeather(),NowWeatherDto.class);
dtos.add(nowWeatherDto);
}
return dtos;
}
return new ArrayList<>();
}
@Override
public List<ForecastWeatherDto> findForecastWeatherByLocationIdAndDateDto(String locationId, String date) {
List<ForecastWeather> weathers = this.findForecastWeatherByLocationIdAndDateOrderByCreateDateDesc(locationId,date);
if(weathers!=null&&weathers.size()>0){
List<ForecastWeatherDto> dtos = new ArrayList<>();
for (ForecastWeather weather:weathers) {
Gson gson = new Gson();
ForecastWeatherDto forecastWeatherDto = gson.fromJson(weather.getWeather(),ForecastWeatherDto.class);
dtos.add(forecastWeatherDto);
}
return dtos;
}
return new ArrayList<>();
}
@Override
public HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(String locationId, String date) {
NowWeatherDto nowWeatherDto=this.findNowWeatherByLocationIdAndDateDto(locationId);
//System.out.println(new Gson().toJson(nowWeatherDto));
if(nowWeatherDto!=null){
Gson gson = new Gson();
String nowWeatherDtoStr = gson.toJson(nowWeatherDto);
HefengWeatherResultDto hefengWeatherResultDto=gson.fromJson(nowWeatherDtoStr,HefengWeatherResultDto.class);
//System.out.println("-----------hefengWeatherResultDto------------");
//System.out.println(new Gson().toJson(hefengWeatherResultDto));
List<ForecastWeatherDto> forecastWeatherDtoList=this.findForecastWeatherByLocationIdAndDateDto(locationId,date);
//System.out.println(new Gson().toJson(forecastWeatherDtoList));
if(forecastWeatherDtoList!=null&&forecastWeatherDtoList.size()>0){
String futureWeatherData = gson.toJson(forecastWeatherDtoList.get(0));
HefengFutureWeatherDto hefengFutureWeatherDto = gson.fromJson(futureWeatherData, HefengFutureWeatherDto.class);
if(hefengFutureWeatherDto!=null){
hefengWeatherResultDto.setDaily(hefengFutureWeatherDto.getDaily());
return hefengWeatherResultDto;
}
}
}
return null;
}
}

@ -0,0 +1,74 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.NmcCityRepository;
import com.rehome.jpahefengweather.dao.NmcProvinceRepository;
import com.rehome.jpahefengweather.entity.NmcCity;
import com.rehome.jpahefengweather.entity.NmcProvince;
import com.rehome.jpahefengweather.service.NmcCityService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
@Service
public class NmcCityServiceImpl implements NmcCityService {
@Resource
private NmcCityRepository nmcCityRepository;
@Resource
private NmcProvinceRepository nmcProvinceRepository;
@Override
public NmcProvince findProvinceByCode(String code) {
return this.nmcProvinceRepository.findByCode(code);
}
@Override
public NmcCity findCityByCode(String code) {
return this.nmcCityRepository.findByCode(code);
}
@Override
public void saveProvince(NmcProvince province) {
if(province!=null){
Date now = new Date();
NmcProvince provinceDB=this.nmcProvinceRepository.findByCode(province.getCode());
if(provinceDB!=null){
provinceDB.setName(province.getName());
provinceDB.setUrl(province.getUrl());
provinceDB.setLastUpdateDate(now);
this.nmcProvinceRepository.save(provinceDB);
}else{
province.setLastUpdateDate(now);
province.setCreateDate(now);
this.nmcProvinceRepository.save(province);
}
}
}
@Override
public void saveCity(NmcCity city) {
if(city!=null){
Date now = new Date();
NmcCity cityDB=this.nmcCityRepository.findByCode(city.getCode());
if(cityDB!=null){
cityDB.setCity(city.getCity());
cityDB.setProvince(city.getProvince());
cityDB.setUrl(city.getUrl());
cityDB.setLastUpdateDate(now);
this.nmcCityRepository.save(cityDB);
}else{
city.setLastUpdateDate(now);
city.setCreateDate(now);
this.nmcCityRepository.save(city);
}
}
}
@Override
public List<NmcCity> findAllCityList() {
return this.nmcCityRepository.findAll();
}
}

@ -0,0 +1,31 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.NmcNowWeatherRepository;
import com.rehome.jpahefengweather.dao.NmcStormRepository;
import com.rehome.jpahefengweather.entity.NmcStorm;
import com.rehome.jpahefengweather.service.NmcStormService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class NmcStormServiceImpl implements NmcStormService {
@Resource
private NmcStormRepository nmcStormRepository;
@Override
public NmcStorm findById(Long code) {
return this.nmcStormRepository.findByCode(code);
}
@Override
public List<NmcStorm> findListByYear(String year) {
return this.nmcStormRepository.findByYear(year);
}
@Override
public void saveNmcStorm(NmcStorm nmcStorm) {
this.nmcStormRepository.save(nmcStorm);
}
}

@ -0,0 +1,30 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.ForecastWeatherRepository;
import com.rehome.jpahefengweather.dao.NmcForecastWeatherRepository;
import com.rehome.jpahefengweather.dao.NmcNowWeatherRepository;
import com.rehome.jpahefengweather.dao.NowWeatherRepository;
import com.rehome.jpahefengweather.entity.NmcForecastWeather;
import com.rehome.jpahefengweather.entity.NmcNowWeather;
import com.rehome.jpahefengweather.service.NmcWeatherService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@Service
public class NmcWeatherServiceImpl implements NmcWeatherService {
@Resource
private NmcNowWeatherRepository nmcNowWeatherRepository;
@Resource
private NmcForecastWeatherRepository nmcForecastWeatherRepository;
@Override
public void saveNowWeather(NmcNowWeather nowWeather) {
this.nmcNowWeatherRepository.save(nowWeather);
}
@Override
public void saveForecastWeather(NmcForecastWeather forecastWeather) {
this.nmcForecastWeatherRepository.save(forecastWeather);
}
}

@ -0,0 +1,46 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.TyphoonInfoRepository;
import com.rehome.jpahefengweather.dao.WztfStormInfoRepository;
import com.rehome.jpahefengweather.dao.WztfStormRepository;
import com.rehome.jpahefengweather.dao.ZjsltStormRepository;
import com.rehome.jpahefengweather.entity.WztfStorm;
import com.rehome.jpahefengweather.entity.WztfStormInfo;
import com.rehome.jpahefengweather.service.WztfStormService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class WztfStormServiceImpl implements WztfStormService {
@Resource
private WztfStormRepository wztfStormRepository;
@Resource
private WztfStormInfoRepository wztfStormInfoRepository;
@Override
public WztfStorm findByTfbh(String tfbh) {
return this.wztfStormRepository.findByTfbh(tfbh);
}
@Override
public List<WztfStorm> findByYear(String year) {
return this.wztfStormRepository.findByYear(year);
}
@Override
public void saveWztfStorm(WztfStorm wztfStorm) {
this.wztfStormRepository.save(wztfStorm);
}
@Override
public WztfStormInfo findWztfStormInfoByTfbh(String tfbh) {
return this.wztfStormInfoRepository.findByTfbh(tfbh);
}
@Override
public void saveWztfStormInfo(WztfStormInfo wztfStormInfo) {
this.wztfStormInfoRepository.save(wztfStormInfo);
}
}

@ -0,0 +1,58 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.TyphoonInfoRepository;
import com.rehome.jpahefengweather.dao.ZjsltStormRepository;
import com.rehome.jpahefengweather.entity.TyphoonInfo;
import com.rehome.jpahefengweather.entity.ZjsltStorm;
import com.rehome.jpahefengweather.service.ZjsltStormService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class ZjsltStormServiceImpl implements ZjsltStormService {
@Resource
private ZjsltStormRepository zjsltStormRepository;
@Resource
private TyphoonInfoRepository typhoonInfoRepository;
@Override
public ZjsltStorm findByTfid(String tfid) {
return this.zjsltStormRepository.findByTfid(tfid);
}
@Override
public List<ZjsltStorm> findByYear(String year) {
return this.zjsltStormRepository.findByYear(year);
}
@Override
public List<ZjsltStorm> getTyhoonActivity() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
List<ZjsltStorm> list = this.zjsltStormRepository.findByYearAndIsactiveOrderByCreateDateDesc(sdf.format(new Date()),"1");
if(list!=null&&list.size()>0){
return list;
}
return new ArrayList();
}
@Override
public void saveZjsltStorm(ZjsltStorm zjsltStorm) {
this.zjsltStormRepository.save(zjsltStorm);
}
@Override
public TyphoonInfo findTyphoonInfoByTfid(String tfid) {
return this.typhoonInfoRepository.findByTfid(tfid);
}
@Override
public void saveTyphoonInfo(TyphoonInfo typhoonInfo) {
this.typhoonInfoRepository.save(typhoonInfo);
}
}

@ -0,0 +1,20 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.NmcCity;
import com.rehome.jpahefengweather.entity.NmcProvince;
import java.util.List;
public interface NmcCityService {
//code查询所有省份
NmcProvince findProvinceByCode(String code);
//根据code查询城市
NmcCity findCityByCode(String code);
//保存省份
void saveProvince(NmcProvince province);
//保存城市
void saveCity(NmcCity city);
//查询所有城市
List<NmcCity> findAllCityList();
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.NmcNowWeather;
import com.rehome.jpahefengweather.entity.NmcStorm;
import java.util.List;
public interface NmcStormService {
//根据id查询台风
NmcStorm findById(Long id);
//根据年份查询台风列表
List<NmcStorm> findListByYear(String year);
/**
*
*/
void saveNmcStorm(NmcStorm nmcStorm);
}

@ -0,0 +1,17 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.NmcForecastWeather;
import com.rehome.jpahefengweather.entity.NmcNowWeather;
public interface NmcWeatherService {
/**
*
*/
void saveNowWeather(NmcNowWeather nowWeather);
/**
*
*/
void saveForecastWeather(NmcForecastWeather forecastWeather);
}

@ -0,0 +1,403 @@
package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.excel.*;
import com.rehome.jpahefengweather.utils.JwtUtils;
import com.rehome.jpahefengweather.utils.OkHttpUtil;
import jakarta.annotation.Resource;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author huangwenfei
* @version v1.0.0.0
* Created DateTime 2021-04-26 14:35
* @description:
*/
@Component
public class ScheduledHefengWeatherService {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Value("${rehome.resources-path}")
private String resourcesPath;
@Resource
private CityService cityService;
@Resource
private HefengWeatherService hefengWeatherService;
/**
* @date 2022-03-14 15:57
* @description: , -
* https://github.com/qwd/LocationList
* https://dev.qweather.com/docs/start/
* //天气图标用法: https://icons.qweather.com/usage/
* @Param: null
*/
//@Scheduled(cron = "0 30 * * * *")//每个小时执行一次
public void scheduled() {
log.info("scheduled");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
if (this.resourcesPath != null) {
log.info(this.resourcesPath);
try {
File excelFile = new File(this.resourcesPath + File.separator + "China-City-List-latest.xlsx");
if (excelFile.exists()) {
log.info("文件存在");
WriteExcel writeExcel = new WriteExcel(this.resourcesPath, "writeExcel.xlsx");
//writeExcel.testWriteExcel();
ReadExcelXls readExcelXls = new ReadExcelXls(this.resourcesPath, "China-City-List-latest.xls");
//readExcelXls.testReadExcel();
ReadCityExcelXls readCityExcelXls = new ReadCityExcelXls(this.resourcesPath, "China-City-List-latest.xls");
//readCityExcelXls.testReadExcel();
// List<CityList> excelList = readCityExcelXls.getCityLists();
// this.CityService.saveCitys(excelList);
// ReadExcelXlsx readExcelXlsx = new ReadExcelXlsx(this.resourcesPath,"China-City-List-latest.xlsx");
// readExcelXlsx.testReadExcel();
ReadCityExcelXlsx readCityExcelXlsx = new ReadCityExcelXlsx(this.resourcesPath, "China-City-List-latest.xlsx");
//readCityExcelXlsx.testReadExcel();
List<HefengCity> excelReadCityExcelXlsx = readCityExcelXlsx.getCityLists();
if(excelReadCityExcelXlsx!=null&&excelReadCityExcelXlsx.size()>0){
this.cityService.saveCityList(excelReadCityExcelXlsx);
Map<String,String> provinceCodeMap = new HashMap<>();
for (HefengCity hefengCity :excelReadCityExcelXlsx) {
provinceCodeMap.put(hefengCity.getAdm1NameEn(),hefengCity.getAdm1NameZh());
}
log.info(new Gson().toJson(provinceCodeMap));
log.info(String.valueOf(provinceCodeMap.size()));
List<HefengProvince> provinceList = new ArrayList<>();
for (String key : provinceCodeMap.keySet()) {
String provinceName = provinceCodeMap.get(key);
HefengProvince province = new HefengProvince();
province.setCode(key);
province.setName(provinceName);
Date now = new Date();
province.setCreateDate(now);
province.setLastUpdateDate(now);
provinceList.add(province);
}
if(provinceList.size()>0){
this.cityService.saveProvinceList(provinceList);
}
List<HefengCity> listCityByProvince = this.cityService.findCityByProvinceCode("Guangdong");
log.info("----------");
log.info(new Gson().toJson(listCityByProvince));
log.info("广东省城市总数:"+String.valueOf(listCityByProvince.size()));
log.info("和风天气省份和城市数据同步成功");
}
} else {
log.info("文件不存在");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* @date 2022-03-16 09:41
* @description: , api - OkHttpClient
* @Param: null
*/
//@Scheduled(cron = "0 0 10,14,18,20,22 * * *")//每天1014182022点各执行一次一天总共执行五次
//@Scheduled(cron = "0 0 0,8,12,16 * * *")//每天081216点各执行一次一天总共执行四次
@Scheduled(cron = "0 15 * * * *")//每个小时执行一次
public void scheduledGetRealtimeWeather() {
log.info("scheduledGetRealtimeWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//广东省惠州市惠阳
String locationNameEn_Huiyang = "Huiyang";
this.hefengWeatherService.saveHefengWeatherByLocationNameEn(locationNameEn_Huiyang);
}
/**
* @date 2022-03-16 09:41
* @description: , api - 7
* @Param: null
*/
//@Scheduled(cron = "0 0 9 * * *")//每天9点执行一次
@Scheduled(cron = "0 15 * * * *")//每个小时执行一次
public void scheduledGetForecastWeather() {
log.info("scheduledGetForecastWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
//广东省惠州市惠阳
String locationNameEn_Huiyang = "Huiyang";
this.hefengWeatherService.saveHefengFutureWeatherByLocationNameEn(locationNameEn_Huiyang);
}
/**
* @date 2022-03-16 09:41
* @description: ,
* @Param: null
*/
//@Scheduled(cron = "*/5 * * * * *")//每天0816点各执行一次一天总共执行三次
public void getCityList() {
log.info("scheduledGetWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
try {
String url = "http://192.168.1.18:8080/jpahefengweather/weather/getCityList";
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient();
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//log.info(body);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description: , OkHttpClient
* @Param: null
*/
//@Scheduled(cron = "*/10 * * * * *")//每天0816点各执行一次一天总共执行三次
public void getNowWeatherEntity() {
log.info("scheduledGetWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
try {
String url = "http://192.168.1.18:8080/jpahefengweather/weather/getNowWeatherEntity";
// 初始化 OkHttpClient
//OkHttpClient client = new OkHttpClient();
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Map<String, String> param = new HashMap();
String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
param.put("weatherDate", now);
param.put("locationId", "101010100");
Gson gson = new Gson();
MediaType JSON = MediaType.parse("application/json;charset=utf-8");
RequestBody requestBody = RequestBody.create(JSON, gson.toJson(param));
//请求参数体
RequestBody requestBody1 = new FormBody.Builder()
.add("weatherDate", now)
.add("locationId", "101010100")
.build();
// 初始化请求体
Request request = new Request.Builder()
.post(requestBody)
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
log.info(body);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description: , ,OkHttpClient
* @Param: null
*/
//@Scheduled(cron = "*/10 * * * * *")//每天0816点各执行一次一天总共执行三次
public void getNowWeatherDto() {
log.info("scheduledGetWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
String url = "http://192.168.1.18:8080/jpahefengweather/weather/getNowWeatherDto";
// 初始化 OkHttpClient
//OkHttpClient client = new OkHttpClient();
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Map<String, String> param = new HashMap();
String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
param.put("weatherDate", now);
param.put("locationId", "101010100");
Gson gson = new Gson();
MediaType JSON = MediaType.parse("application/json;charset=utf-8");
RequestBody requestBody = RequestBody.create(JSON, gson.toJson(param));
//请求参数体
RequestBody requestBody1 = new FormBody.Builder()
.add("weatherDate", now)
.add("locationId", "101010100")
.build();
// 初始化请求体
Request request = new Request.Builder()
.post(requestBody)
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String body = response.body().string();
log.info(body);
}
});
}
/**
* @date 2022-03-16 09:41
* @description: ,
* @Param: null
*/
//@Scheduled(cron = "*/10 * * * * *")//每天0816点各执行一次一天总共执行三次
public void getNowWeatherDtoOne() {
log.info("scheduledGetWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
String url = "http://192.168.1.18:8080/jpahefengweather/weather/getNowWeatherDtoOne";
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Map<String, String> param = new HashMap();
String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
param.put("weatherDate", now);
param.put("locationId", "101010100");
Gson gson = new Gson();
MediaType JSON = MediaType.parse("application/json;charset=utf-8");
RequestBody requestBody = RequestBody.create(JSON, gson.toJson(param));
//请求参数体
RequestBody requestBody1 = new FormBody.Builder()
.add("weatherDate", now)
.add("locationId", "101010100")
.build();
//post方式提交的数据
FormBody formBody = new FormBody.Builder()
.add("name", "android基础")
.add("price", "50")
.build();
// 初始化请求体
Request request = new Request.Builder()
.post(requestBody)
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String body = response.body().string();
log.info(body);
}
});
}
/**
* @date 2022-03-16 09:41
* @description: ,
* @Param: null
*/
//@Scheduled(cron = "0 15 * * * *")//每天0816点各执行一次一天总共执行三次
public void getForecastWeatherDto() {
log.info("scheduledGetWeather");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
String url = "http://192.168.1.18:8080/jpahefengweather/weather/getForecastWeatherDto";
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
Map<String, String> param = new HashMap();
String now = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
param.put("weatherDate", now);
param.put("locationId", "101010100");
Gson gson = new Gson();
MediaType JSON = MediaType.parse("application/json;charset=utf-8");
RequestBody requestBody = RequestBody.create(JSON, gson.toJson(param));
// 初始化请求体
Request request = new Request.Builder()
.post(requestBody)
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String body = response.body().string();
log.info(body);
}
});
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
@Scheduled(cron = "0 0/1 * * * *")
public void getLocalNowWeatherDto() {
log.info("getLocalNowWeatherDto");
String strNow = String.valueOf(System.currentTimeMillis());
log.info(strNow);
BaseFindDto dto = new BaseFindDto();
dto.setLocationId("101280303");
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
HefengWeatherResultDto hefengWeatherResultDto=this.hefengWeatherService.getHefengWeatherResultDtoByLocationIdAndDateDto(dto.getLocationId(),currentDate);
log.info("-----------和风天气获取实时天气和天气预报完成------------");
log.info(new Gson().toJson(hefengWeatherResultDto));
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
@Scheduled(cron = "0 0/1 * * * *")
public void getLocalForecastWeatherDto() {
log.info("getLocalForecastWeatherDto");
String strNow = String.valueOf(System.currentTimeMillis());
log.info(strNow);
String currentDate = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
BaseFindDto dto = new BaseFindDto();
dto.setLocationId("101280303");
List<ForecastWeatherDto> forecastWeatherDtoList=this.hefengWeatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),currentDate);
log.info(new Gson().toJson(forecastWeatherDtoList));
}
}

@ -0,0 +1,212 @@
package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rehome.jpahefengweather.JpahefengweatherApplication;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.entity.*;
import jakarta.annotation.Resource;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author huangwenfei
* @version v1.0.0.0
* Created DateTime 2021-04-26 14:35
* @description:
*/
//@Component
public class ScheduledNmcWeatherService {
@Value("${rehome.resources-path}")
private String resourcesPath;
@Resource
private CityService cityService;
@Resource
private NmcCityService nmcCityService;
@Resource
private NmcWeatherService nmcWeatherService;
@Resource
private NmcStormService nmcStormService;
@Resource
private ZjsltStormService zjsltStormService;
@Resource
private WztfStormService wztfStormService;
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 29 * * * *")
public void getNmcWeatherProvince() {
System.out.println("scheduledGetWeather");
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
System.out.println(String.valueOf(System.currentTimeMillis()));
String url = "http://www.nmc.cn/rest/province/all?_=" + String.valueOf(System.currentTimeMillis());
System.out.println(url);
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
try {
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
System.out.println(body);
if (StringUtils.hasText(body)) {
Gson gson = new Gson();
List<NmcProvince> provinces = gson.fromJson(body, new TypeToken<List<NmcProvince>>() {
}.getType());
;
for (NmcProvince province : provinces) {
System.out.println(gson.toJson(province));
this.nmcCityService.saveProvince(province);
getNmcWeatherCityByCode(province.getCode());
try {
Thread.sleep(500);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(provinces.size());
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description: code
* @Param: null
*/
public void getNmcWeatherCityByCode(String code) {
String url = "http://www.nmc.cn/rest/province/" + code + "?_=" + String.valueOf(System.currentTimeMillis());
System.out.println(url);
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
try {
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
System.out.println(body);
if (StringUtils.hasText(body)) {
Gson gson = new Gson();
List<NmcCity> citys = gson.fromJson(body, new TypeToken<List<NmcCity>>() {
}.getType());
;
for (NmcCity city : citys) {
System.out.println(gson.toJson(city));
this.nmcCityService.saveCity(city);
}
System.out.println(citys.size());
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 15 * * * *")
public void getNmcNowWeather() {
System.out.println("scheduledGetWeather");
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
System.out.println(String.valueOf(System.currentTimeMillis()));
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
List<NmcCity> citys = this.nmcCityService.findAllCityList();
for (NmcCity city : citys) {
String url = "http://www.nmc.cn/rest/weather?stationid=" + city.getCode() + "&_=" + String.valueOf(System.currentTimeMillis());
System.out.println(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
try {
Thread.sleep(200);
} catch (Exception e) {
e.printStackTrace();
}
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String body = response.body().string();
System.out.println(body);
if (StringUtils.hasText(body)) {
try {
Gson gson = new Gson();
NmcBaseDto nmcBaseDto = gson.fromJson(body, NmcBaseDto.class);
if (nmcBaseDto != null && nmcBaseDto.getCode() == 0) {
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String nowDate = sdf.format(new Date());
NmcNowWeather nowWeather = new NmcNowWeather();
nowWeather.setCode(city.getCode());
nowWeather.setWeather(body);
nowWeather.setWeatherDate(nowDate);
nowWeather.setLastUpdateDate(now);
nowWeather.setCreateDate(now);
NmcWeatherService nmcWeatherServiceTemp = JpahefengweatherApplication.context.getBean(NmcWeatherService.class);
nmcWeatherServiceTemp.saveNowWeather(nowWeather);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
}
}

@ -0,0 +1,194 @@
package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.excel.*;
import com.rehome.jpahefengweather.utils.JwtUtils;
import com.rehome.jpahefengweather.utils.OkHttpUtil;
import jakarta.annotation.Resource;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author huangwenfei
* @version v1.0.0.0
* Created DateTime 2021-04-26 14:35
* @description:
*/
//@Component
public class ScheduledWztfwStormService {
@Resource
private WztfStormService wztfStormService;
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
@Scheduled(cron = "0 39 15 * * *")
public void getWztfHistoryStormList() {
for(int i=1945;i<2026;i++){
getWztfStormList(String.valueOf(i));
}
//getWztfStormList(String.valueOf(1944));
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 15 * * * *")
public void getWztfStormList(String nowYear) {
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
try {
Thread.sleep(1000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());
//String nowYear = sdfYear.format(new Date());
//nowYear = String.valueOf(i);
String url = "http://data.istrongcloud.com/v2/data/complex/" + nowYear + ".json?v=" + String.valueOf(System.currentTimeMillis());
System.out.println(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
System.out.println(body);
if (StringUtils.hasText(body)) {
if (body.length() > 2) {
Gson gson = new Gson();
Type type = new TypeToken<ArrayList<WztfStorm>>() {
}.getType();
List<WztfStorm> stormList = gson.fromJson(body, type);
//打印测试
for (WztfStorm storm : stormList) {
storm.setYear(nowYear);
storm.setCreateDate(new Date());
//System.out.println(gson.toJson(storm));
WztfStorm stormDB = this.wztfStormService.findByTfbh(storm.getTfbh());
if (stormDB == null) {
//数据库无数据,第一次插入,同时从第三方平台拉取台风路径数据入库
this.wztfStormService.saveWztfStorm(storm);
this.saveOrUpdateWztfStormInfo(storm);
} else {
//数据库有数据
if (stormDB.getIs_current() == 1) {
if (storm.getIs_current() == 0) {
//数据库里面台风数据是活跃状态,第三方平台台风数据已变成不活跃状态,更新数据库台风状态,同时更新台风路径
stormDB.setIs_current(storm.getIs_current());
this.wztfStormService.saveWztfStorm(stormDB);
this.saveOrUpdateWztfStormInfo(stormDB);
} else {
//数据库里面台风数据是活跃状态,第三方平台台风数据也是活跃状态
if ((!storm.getEnd_time().equals(stormDB.getEnd_time())) || (!storm.getEname().equals(stormDB.getEname())) || (!storm.getName().equals(stormDB.getName())) || (!storm.getIdent().equals(stormDB.getIdent()))) {
//台风列表数据有变化,更新台风列表数据
stormDB.setEnd_time(storm.getEnd_time());
stormDB.setEname(storm.getEname());
stormDB.setName(storm.getName());
stormDB.setIdent(storm.getIdent());
this.wztfStormService.saveWztfStorm(stormDB);
}
//更新台风路径
this.saveOrUpdateWztfStormInfo(stormDB);
}
} else {
//数据库里面台风数据是不活跃状态,无需做任何事情
//this.saveOrUpdateWztfStormInfo(storm);
}
}
}
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
public void saveOrUpdateWztfStormInfo(WztfStorm storm) {
System.out.println("saveOrUpdateTyphoonInfo");
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());
String nowYear = sdfYear.format(new Date());
String url = "http://data.istrongcloud.com/v2/data/complex/" + storm.getTfbh() + ".json?v=" + String.valueOf(System.currentTimeMillis());
System.out.println(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//System.out.println(body);
if (StringUtils.hasText(body)) {
if (body.length() > 2) {
Gson gson = new Gson();
int startIndex0 = body.indexOf("{");
int endIndex0 = body.lastIndexOf("}");
String typhoonInfoStr = body.substring(startIndex0, endIndex0 + 1);
//System.out.println(typhoonInfoStr);
WztfStormInfo wztfStormInfoDB = this.wztfStormService.findWztfStormInfoByTfbh(storm.getTfbh());
WztfStormInfo wztfStormInfo = new WztfStormInfo();
if (wztfStormInfoDB == null) {
//数据库无数据,保存风路径数据入库
wztfStormInfo.setTfbh(storm.getTfbh());
wztfStormInfo.setStormData(typhoonInfoStr);
wztfStormInfo.setCreateDate(new Date());
wztfStormInfo.setLastUpdateDate(new Date());
this.wztfStormService.saveWztfStormInfo(wztfStormInfo);
} else {
//数据库有数据,更新台风路径数据
wztfStormInfoDB.setStormData(typhoonInfoStr);
wztfStormInfoDB.setLastUpdateDate(new Date());
this.wztfStormService.saveWztfStormInfo(wztfStormInfoDB);
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

@ -0,0 +1,251 @@
package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.excel.*;
import com.rehome.jpahefengweather.utils.JwtUtils;
import com.rehome.jpahefengweather.utils.OkHttpUtil;
import jakarta.annotation.Resource;
import okhttp3.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Type;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* @author huangwenfei
* @version v1.0.0.0
* Created DateTime 2021-04-26 14:35
* @description:
*/
@Component
public class ScheduledZjsltStormService {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private ZjsltStormService zjsltStormService;
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
// @Scheduled(cron = "0 24 * * * *")
// public void getZjsltHistoryStormList() {
// for(int i=1944;i<2026;i++){
// getZjsltStormList(String.valueOf(i));
// }
// }
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 23 * * * *")
public void getZjsltStormList() {
log.info("getZjsltStormList");
String strNow = String.valueOf(System.currentTimeMillis());
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
try {
Thread.sleep(2000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());
String nowYear = sdfYear.format(new Date());
Random random = new Random();//以系统自身时间为种子数
int iRandom = random.nextInt();
Long nowLong = 13728353350362976L;
Long nowLongTemp = nowLong + iRandom;
String url = "https://typhoon.slt.zj.gov.cn/Api/TyphoonList/" + nowYear + "?callback=jQuery" + "1830" + String.valueOf(nowLongTemp) + "_" + strNow + "&_=" + String.valueOf(System.currentTimeMillis());
log.info(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//log.info(body);
if (StringUtils.hasText(body)) {
if (body.length() > 0) {
Gson gson = new Gson();
int startIndex = body.indexOf("[");
int endIndex = body.lastIndexOf("]");
// log.info(body.indexOf("["));
// log.info(body.lastIndexOf("]"));
String stormStr = body.substring(startIndex, endIndex + 1);
//log.info(stormStr);
if (stormStr != null && stormStr.length() > 2) {
Type type = new TypeToken<ArrayList<ZjsltStorm>>() {
}.getType();
List<ZjsltStorm> stormList = gson.fromJson(stormStr, type);
//打印测试
for (ZjsltStorm storm : stormList) {
storm.setYear(nowYear);
storm.setCreateDate(new Date());
log.info(gson.toJson(storm));
ZjsltStorm stormDB = this.zjsltStormService.findByTfid(storm.getTfid());
if (stormDB == null) {
//数据库无数据,第一次插入,同时从第三方平台拉取台风路径数据入库
this.zjsltStormService.saveZjsltStorm(storm);
this.saveOrUpdateTyphoonInfo(storm);
} else {
//数据库有数据
if (stormDB.getIsactive().equals("1")) {
if (storm.getIsactive().equals("0")) {
//数据库里面台风数据是活跃状态,第三方平台台风数据已变成不活跃状态,更新数据库台风状态,同时更新台风路径
stormDB.setIsactive(storm.getIsactive());
this.zjsltStormService.saveZjsltStorm(stormDB);
this.saveOrUpdateTyphoonInfo(stormDB);
} else {
//数据库里面台风数据是活跃状态,第三方平台台风数据也是活跃状态
if ((!storm.getEndtime().equals(stormDB.getEndtime())) || (!storm.getEnname().equals(stormDB.getEnname())) || (!storm.getName().equals(stormDB.getName()))) {
//台风列表数据有变化,更新台风列表数据
stormDB.setEndtime(storm.getEndtime());
stormDB.setEnname(storm.getEnname());
stormDB.setName(storm.getName());
this.zjsltStormService.saveZjsltStorm(stormDB);
}
//更新台风路径
this.saveOrUpdateTyphoonInfo(stormDB);
}
} else {
//数据库里面台风数据是不活跃状态,无需做任何事情
//this.saveOrUpdateTyphoonInfo(storm);
}
}
}
}
}
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
public void saveOrUpdateTyphoonInfo(ZjsltStorm storm) {
log.info("saveOrUpdateTyphoonInfo");
String strNow = String.valueOf(System.currentTimeMillis());
// 初始化 OkHttpClient
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.build();
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());
String nowYear = sdfYear.format(new Date());
Random random = new Random();//以系统自身时间为种子数
int iRandom = random.nextInt();
Long nowLong = 25528353350362976L;
Long nowLongTemp = nowLong + iRandom;
String url = "https://typhoon.slt.zj.gov.cn/Api/TyphoonInfo/" + storm.getTfid() + "?callback=jQuery" + "1830" + String.valueOf(nowLongTemp) + "_" + strNow + "&_=" + String.valueOf(System.currentTimeMillis());
log.info(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
.url(url)
.build();
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//log.info(body);
if (StringUtils.hasText(body)) {
if (body.length() > 0) {
Gson gson = new Gson();
int startIndex = body.indexOf("[");
int endIndex = body.lastIndexOf("]");
// log.info(body.indexOf("["));
// log.info(body.lastIndexOf("]"));
String typhoonInfoArryStr = body.substring(startIndex, endIndex + 1);
//log.info(typhoonInfoArryStr);
if (typhoonInfoArryStr != null && typhoonInfoArryStr.length() > 2) {
int startIndex0 = typhoonInfoArryStr.indexOf("{");
int endIndex0 = typhoonInfoArryStr.lastIndexOf("}");
// log.info(startIndex0);
// log.info(endIndex0);
String typhoonInfoStr = typhoonInfoArryStr.substring(startIndex0, endIndex0 + 1);
//log.info(typhoonInfoStr);
TyphoonInfo typhoonInfoDB = this.zjsltStormService.findTyphoonInfoByTfid(storm.getTfid());
TyphoonInfo typhoonInfo = new TyphoonInfo();
if (typhoonInfoDB == null) {
//数据库无数据,保存风路径数据入库
typhoonInfo.setTfid(storm.getTfid());
typhoonInfo.setStormData(typhoonInfoStr);
typhoonInfo.setCreateDate(new Date());
typhoonInfo.setLastUpdateDate(new Date());
this.zjsltStormService.saveTyphoonInfo(typhoonInfo);
} else {
//数据库有数据,更新台风路径数据
typhoonInfoDB.setStormData(typhoonInfoStr);
typhoonInfoDB.setLastUpdateDate(new Date());
this.zjsltStormService.saveTyphoonInfo(typhoonInfoDB);
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
@Scheduled(cron = "0 0/1 * * * *")
public void getTyhoonActivity() {
log.info("getTyhoonActivity");
String strNow = String.valueOf(System.currentTimeMillis());
log.info(strNow);
List<ZjsltStorm> list = this.zjsltStormService.getTyhoonActivity();
log.info(String.valueOf(list.size()));
log.info(new Gson().toJson(list));
}
/**
* @date 2022-03-16 09:41
* @description:
* @Param: null
*/
@Scheduled(cron = "0 0/1 * * * *")
public void getZjsltStormByYear() {
log.info("getZjsltStormByYear");
String strNow = String.valueOf(System.currentTimeMillis());
log.info(strNow);
String currentYear = new SimpleDateFormat("yyyy").format(new Date());
List<ZjsltStorm> list = this.zjsltStormService.findByYear(currentYear);
log.info(String.valueOf(list.size()));
log.info(new Gson().toJson(list));
}
}

@ -0,0 +1,24 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.WztfStorm;
import com.rehome.jpahefengweather.entity.WztfStormInfo;
import java.util.List;
public interface WztfStormService {
//根据id查询台风
WztfStorm findByTfbh(String tfbh);
//根据年份查询台风列表
List<WztfStorm> findByYear(String year);
/**
*
*/
void saveWztfStorm(WztfStorm wztfStorm);
WztfStormInfo findWztfStormInfoByTfbh(String tfbh);
/**
*
*/
void saveWztfStormInfo(WztfStormInfo wztfStormInfo);
}

@ -0,0 +1,27 @@
package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.entity.TyphoonInfo;
import com.rehome.jpahefengweather.entity.ZjsltStorm;
import java.util.List;
public interface ZjsltStormService {
//根据id查询台风
ZjsltStorm findByTfid(String tfid);
//根据年份查询台风列表
List<ZjsltStorm> findByYear(String year);
//根据年份查询台风列表
List<ZjsltStorm> getTyhoonActivity();
/**
*
*/
void saveZjsltStorm(ZjsltStorm zjsltStorm);
TyphoonInfo findTyphoonInfoByTfid(String tfid);
/**
*
*/
void saveTyphoonInfo(TyphoonInfo typhoonInfo);
}

@ -0,0 +1,118 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class CellStyle {
public static void main(String[] args)throws Exception
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet("cellstyle");
XSSFRow row = spreadsheet.createRow((short) 1);
row.setHeight((short) 800);
XSSFCell cell = (XSSFCell) row.createCell((short) 1);
cell.setCellValue("test of merging");
//MEARGING CELLS
//this statement for merging cells
spreadsheet.addMergedRegion(new CellRangeAddress(
1, //first row (0-based)
1, //last row (0-based)
1, //first column (0-based)
4 //last column (0-based)
));
//CELL Alignment
row = spreadsheet.createRow(5);
cell = (XSSFCell) row.createCell(0);
row.setHeight((short) 800);
// Top Left alignment
XSSFCellStyle style1 = workbook.createCellStyle();
spreadsheet.setColumnWidth(0, 8000);
style1.setAlignment(XSSFCellStyle.ALIGN_LEFT);
style1.setVerticalAlignment(XSSFCellStyle.VERTICAL_TOP);
cell.setCellValue("Top Left");
cell.setCellStyle(style1);
row = spreadsheet.createRow(6);
cell = (XSSFCell) row.createCell(1);
row.setHeight((short) 800);
// Center Align Cell Contents
XSSFCellStyle style2 = workbook.createCellStyle();
style2.setAlignment(XSSFCellStyle.ALIGN_CENTER);
style2.setVerticalAlignment(
XSSFCellStyle.VERTICAL_CENTER);
cell.setCellValue("Center Aligned");
cell.setCellStyle(style2);
row = spreadsheet.createRow(7);
cell = (XSSFCell) row.createCell(2);
row.setHeight((short) 800);
// Bottom Right alignment
XSSFCellStyle style3 = workbook.createCellStyle();
style3.setAlignment(XSSFCellStyle.ALIGN_RIGHT);
style3.setVerticalAlignment(
XSSFCellStyle.VERTICAL_BOTTOM);
cell.setCellValue("Bottom Right");
cell.setCellStyle(style3);
row = spreadsheet.createRow(8);
cell = (XSSFCell) row.createCell(3);
// Justified Alignment
XSSFCellStyle style4 = workbook.createCellStyle();
style4.setAlignment(XSSFCellStyle.ALIGN_JUSTIFY);
style4.setVerticalAlignment(
XSSFCellStyle.VERTICAL_JUSTIFY);
cell.setCellValue("Contents are Justified in Alignment");
cell.setCellStyle(style4);
//CELL BORDER
row = spreadsheet.createRow((short) 10);
row.setHeight((short) 800);
cell = (XSSFCell) row.createCell((short) 1);
cell.setCellValue("BORDER");
XSSFCellStyle style5 = workbook.createCellStyle();
style5.setBorderBottom(XSSFCellStyle.BORDER_THICK);
style5.setBottomBorderColor(
IndexedColors.BLUE.getIndex());
style5.setBorderLeft(XSSFCellStyle.BORDER_DOUBLE);
style5.setLeftBorderColor(
IndexedColors.GREEN.getIndex());
style5.setBorderRight(XSSFCellStyle.BORDER_HAIR);
style5.setRightBorderColor(
IndexedColors.RED.getIndex());
style5.setBorderTop(XSSFCellStyle.BIG_SPOTS);
style5.setTopBorderColor(
IndexedColors.CORAL.getIndex());
cell.setCellStyle(style5);
//Fill Colors
//background color
row = spreadsheet.createRow((short) 10 );
cell = (XSSFCell) row.createCell((short) 1);
XSSFCellStyle style6 = workbook.createCellStyle();
style6.setFillBackgroundColor(
HSSFColor.LEMON_CHIFFON.index );
style6.setFillPattern(XSSFCellStyle.LESS_DOTS);
style6.setAlignment(XSSFCellStyle.ALIGN_FILL);
spreadsheet.setColumnWidth(1,8000);
cell.setCellValue("FILL BACKGROUNG/FILL PATTERN");
cell.setCellStyle(style6);
//Foreground color
row = spreadsheet.createRow((short) 12);
cell = (XSSFCell) row.createCell((short) 1);
XSSFCellStyle style7=workbook.createCellStyle();
style7.setFillForegroundColor(HSSFColor.BLUE.index);
style7.setFillPattern( XSSFCellStyle.LESS_DOTS);
style7.setAlignment(XSSFCellStyle.ALIGN_FILL);
cell.setCellValue("FILL FOREGROUND/FILL PATTERN");
cell.setCellStyle(style7);
FileOutputStream out = new FileOutputStream(
new File("D:\\cellstyle.xlsx"));
workbook.write(out);
out.close();
System.out.println("cellstyle.xlsx written successfully");
}
}

@ -0,0 +1,64 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelDatabase
{
public static void main(String[] args) throws Exception
{
Class.forName("com.mysql.jdbc.Driver");
Connection connect = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/test" ,
"root" ,
"root"
);
Statement statement = connect.createStatement();
ResultSet resultSet = statement
.executeQuery("select * from emp_tbl");
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook
.createSheet("employe db");
XSSFRow row=spreadsheet.createRow(1);
XSSFCell cell;
cell=row.createCell(1);
cell.setCellValue("EMP ID");
cell=row.createCell(2);
cell.setCellValue("EMP NAME");
cell=row.createCell(3);
cell.setCellValue("DEG");
cell=row.createCell(4);
cell.setCellValue("SALARY");
cell=row.createCell(5);
cell.setCellValue("DEPT");
int i=2;
while(resultSet.next())
{
row=spreadsheet.createRow(i);
cell=row.createCell(1);
cell.setCellValue(resultSet.getInt("eid"));
cell=row.createCell(2);
cell.setCellValue(resultSet.getString("ename"));
cell=row.createCell(3);
cell.setCellValue(resultSet.getString("deg"));
cell=row.createCell(4);
cell.setCellValue(resultSet.getString("salary"));
cell=row.createCell(5);
cell.setCellValue(resultSet.getString("dept"));
i++;
}
FileOutputStream out = new FileOutputStream(
new File("exceldatabase.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"exceldatabase.xlsx written successfully");
}
}

@ -0,0 +1,38 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class FontStyle {
public static void main(String[] args)throws Exception
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet("Fontstyle");
XSSFRow row = spreadsheet.createRow(2);
//Create a new font and alter it.
XSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short) 30);
font.setFontName("IMPACT");
font.setItalic(true);
font.setColor(HSSFColor.BRIGHT_GREEN.index);
//Set font into style
XSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
// Create a cell with a value and set style to it.
XSSFCell cell = row.createCell(1);
cell.setCellValue("Font Style");
cell.setCellStyle(style);
FileOutputStream out = new FileOutputStream(
new File("D:\\fontstyle.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"fontstyle.xlsx written successfully");
}
}

@ -0,0 +1,160 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class ReadCityExcelXls {
private String filePath = null;
//ReadCityExcelXls
public ReadCityExcelXls(String dir, String fileName){
if(dir!=null&&fileName!=null){
this.filePath = dir+File.separator+fileName;
}
}
public void testReadExcel() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return;
}
List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来");
if(excelList!=null&&excelList.size()>0){
System.out.println(String.valueOf(excelList.size()));
}
if(excelList!=null){
for (int i = 0; i < excelList.size(); i++) {
HefengCity city = excelList.get(i);
Gson gson = new Gson();
System.out.print(gson.toJson(city));
System.out.println();
}
}
}
public List<HefengCity> getCityLists() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return null;
}
List<HefengCity> excelList = this.readExcel(file);
return excelList;
}
// 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List<HefengCity> readExcel(File file) {
try {
//用流的方式先读取到你想要的excel的文件
FileInputStream fis=new FileInputStream(file);
//解析excel
POIFSFileSystem pSystem=new POIFSFileSystem(fis);
//获取整个excel
HSSFWorkbook hb=new HSSFWorkbook(pSystem);
// Excel的页签数量
int sheet_size = hb.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) {
List<HefengCity> outerList = new ArrayList<HefengCity>();
// 每个页签创建一个Sheet对象
HSSFSheet sheet=hb.getSheetAt(index);
//获取第一行
int firstrow= sheet.getFirstRowNum();
//获取最后一行
int lastrow= sheet.getLastRowNum();
//循环行数依次获取列数
for (int i = firstrow; i < lastrow+1; i++) {
if(i==0){
continue;
}
HefengCity city = new HefengCity();
//获取哪一行i
Row row=sheet.getRow(i);
if (row!=null) {
//获取这一行的第一列
int firstcell=row.getFirstCellNum();
//获取这一行的最后一列
int lastcell=row.getLastCellNum();
for (int j = firstcell; j <lastcell; j++) {
//获取第j列
Cell cell=row.getCell(j);
cell.setCellType(Cell.CELL_TYPE_STRING);
if (cell!=null) {
switch (j){
case 0:
city.setLocationId(cell.getStringCellValue());
break;
case 1:
city.setLocationNameEn(cell.getStringCellValue());
break;
case 2:
city.setLocationNameZh(cell.getStringCellValue());
case 3:
city.setCountryCode(cell.getStringCellValue());
break;
case 4:
city.setCountryNameEn(cell.getStringCellValue());
break;
case 5:
city.setCountryNameZh(cell.getStringCellValue());
break;
case 6:
city.setAdm1NameEn(cell.getStringCellValue());
break;
case 7:
city.setAdm1NameZh(cell.getStringCellValue());
break;
case 8:
city.setAdm2NameEn(cell.getStringCellValue());
break;
case 9:
city.setAdm2NameZh(cell.getStringCellValue());
break;
case 10:
city.setTimezone(cell.getStringCellValue());
break;
case 11:
city.setLatitude(cell.getStringCellValue());
break;
case 12:
city.setLongitude(cell.getStringCellValue());
break;
case 13:
city.setAdcode(cell.getStringCellValue());
break;
default:
break;
}
}
}
outerList.add(city);
}
}
fis.close();
return outerList;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,158 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadCityExcelXlsx {
private String filePath = null;
//ReadCityExcelXls
public ReadCityExcelXlsx(String dir, String fileName) {
if (dir != null && fileName != null) {
this.filePath = dir + File.separator + fileName;
}
}
public void testReadExcel() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return;
}
List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来");
if (excelList != null && excelList.size() > 0) {
System.out.println(String.valueOf(excelList.size()));
}
if(excelList!=null){
for (int i = 0; i < excelList.size(); i++) {
HefengCity city = excelList.get(i);
Gson gson = new Gson();
System.out.print(gson.toJson(city));
System.out.println();
}
}
}
public List<HefengCity> getCityLists() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return null;
}
List<HefengCity> excelList = this.readExcel(file);
return excelList;
}
// 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List<HefengCity> readExcel(File file) {
try {
//用流的方式先读取到你想要的excel的文件
FileInputStream fis = new FileInputStream(file);
//Get the workbook instance for XLSX file
XSSFWorkbook workbook = new XSSFWorkbook(fis);
// Excel的页签数量
int sheet_size = workbook.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) {
List<HefengCity> outerList = new ArrayList<HefengCity>();
// 每个页签创建一个Sheet对象
XSSFSheet sheet = workbook.getSheetAt(index);
//获取第一行
int firstrow = sheet.getFirstRowNum();
//获取最后一行
int lastrow = sheet.getLastRowNum();
//循环行数依次获取列数
for (int i = firstrow; i < lastrow + 1; i++) {
if(i==0){
continue;
}
HefengCity city = new HefengCity();
//获取哪一行i
Row row = sheet.getRow(i);
if (row != null) {
//获取这一行的第一列
int firstcell = row.getFirstCellNum();
//获取这一行的最后一列
int lastcell = row.getLastCellNum();
for (int j = firstcell; j < lastcell; j++) {
//获取第j列
Cell cell = row.getCell(j);
cell.setCellType(Cell.CELL_TYPE_STRING);
if (cell!=null) {
switch (j){
case 0:
city.setLocationId(cell.getStringCellValue());
break;
case 1:
city.setLocationNameEn(cell.getStringCellValue());
break;
case 2:
city.setLocationNameZh(cell.getStringCellValue());
case 3:
city.setCountryCode(cell.getStringCellValue());
break;
case 4:
city.setCountryNameEn(cell.getStringCellValue());
break;
case 5:
city.setCountryNameZh(cell.getStringCellValue());
break;
case 6:
city.setAdm1NameEn(cell.getStringCellValue());
break;
case 7:
city.setAdm1NameZh(cell.getStringCellValue());
break;
case 8:
city.setAdm2NameEn(cell.getStringCellValue());
break;
case 9:
city.setAdm2NameZh(cell.getStringCellValue());
break;
case 10:
city.setTimezone(cell.getStringCellValue());
break;
case 11:
city.setLatitude(cell.getStringCellValue());
break;
case 12:
city.setLongitude(cell.getStringCellValue());
break;
case 13:
city.setAdcode(cell.getStringCellValue());
break;
default:
break;
}
}
}
outerList.add(city);
}
}
fis.close();
return outerList;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,109 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class ReadExcelXls {
private String filePath = null;
//ReadCityExcelXls
public ReadExcelXls(String dir, String fileName){
if(dir!=null&&fileName!=null){
this.filePath = dir+File.separator+fileName;
}
}
public void testReadExcel() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return;
}
List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来");
if(excelList!=null&&excelList.size()>0){
System.out.println(String.valueOf(excelList.size()));
}
for (int i = 0; i < excelList.size(); i++) {
List list = (List) excelList.get(i);
for (int j = 0; j < list.size(); j++) {
System.out.print(list.get(j));
}
System.out.println();
}
}
// 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List readExcel(File file) {
try {
//用流的方式先读取到你想要的excel的文件
FileInputStream fis=new FileInputStream(file);
//解析excel
POIFSFileSystem pSystem=new POIFSFileSystem(fis);
//获取整个excel
HSSFWorkbook hb=new HSSFWorkbook(pSystem);
// Excel的页签数量
int sheet_size = hb.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) {
List<List> outerList = new ArrayList<List>();
// 每个页签创建一个Sheet对象
HSSFSheet sheet=hb.getSheetAt(index);
//获取第一行
int firstrow=sheet.getFirstRowNum();
//获取最后一行
int lastrow=sheet.getLastRowNum();
//循环行数依次获取列数
for (int i = firstrow; i < lastrow+1; i++) {
//获取哪一行i
Row row=sheet.getRow(i);
if (row!=null) {
//获取这一行的第一列
int firstcell= row.getFirstCellNum();
//获取这一行的最后一列
int lastcell= row.getLastCellNum();
//创建一个集合,用处将每一行的每一列数据都存入集合中
List<String> list=new ArrayList<>();
for (int j = firstcell; j <lastcell; j++) {
//获取第j列
Cell cell=row.getCell(j);
if (cell!=null) {
list.add(cell.toString());
}
}
outerList.add(list);
// User user=new User();
// if (list.size()>0) {
// user.setUsername(list.get(1));
// user.setPassword(list.get(2));
// }
// BaseDAO dao=new BaseDAO();
// dao.save(user);
// System.out.println();
}
}
fis.close();
return outerList;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,100 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcelXlsx {
private String filePath = null;
//ReadCityExcelXls
public ReadExcelXlsx(String dir, String fileName) {
if (dir != null && fileName != null) {
this.filePath = dir + File.separator + fileName;
}
}
public void testReadExcel() {
// 要读取的Excel文件路径
File file = new File(this.filePath);
if (!file.exists()) {
System.out.println("excel文件不存在");
return;
}
List excelList = this.readExcel(file);
System.out.println("list中的数据打印出来");
if (excelList != null && excelList.size() > 0) {
System.out.println(String.valueOf(excelList.size()));
}
for (int i = 0; i < excelList.size(); i++) {
List list = (List) excelList.get(i);
for (int j = 0; j < list.size(); j++) {
System.out.print(list.get(j));
}
System.out.println();
}
}
// 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List readExcel(File file) {
try {
//用流的方式先读取到你想要的excel的文件
FileInputStream fis = new FileInputStream(file);
//Get the workbook instance for XLSX file
XSSFWorkbook workbook = new XSSFWorkbook(fis);
// Excel的页签数量
int sheet_size = workbook.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) {
List<List> outerList = new ArrayList<List>();
// 每个页签创建一个Sheet对象
XSSFSheet sheet = workbook.getSheetAt(index);
//获取第一行
int firstrow = sheet.getFirstRowNum();
//获取最后一行
int lastrow = sheet.getLastRowNum();
//循环行数依次获取列数
for (int i = firstrow; i < lastrow + 1; i++) {
//获取哪一行i
Row row = sheet.getRow(i);
if (row != null) {
//获取这一行的第一列
int firstcell = row.getFirstCellNum();
//获取这一行的最后一列
int lastcell = row.getLastCellNum();
//创建一个集合,用处将每一行的每一列数据都存入集合中
List<String> list = new ArrayList<>();
for (int j = firstcell; j < lastcell; j++) {
//获取第j列
Cell cell = row.getCell(j);
if (cell != null) {
list.add(cell.toString());
}
}
outerList.add(list);
}
}
fis.close();
return outerList;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,60 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TextDirection
{
public static void main(String[] args)throws Exception
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet(
"Text direction");
XSSFRow row = spreadsheet.createRow(2);
XSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short) 0);
XSSFCell cell = row.createCell(1);
cell.setCellValue("0D angle");
cell.setCellStyle(myStyle);
//30 degrees
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 30);
cell = row.createCell(3);
cell.setCellValue("30D angle");
cell.setCellStyle(myStyle);
//90 degrees
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 90);
cell = row.createCell(5);
cell.setCellValue("90D angle");
cell.setCellStyle(myStyle);
//120 degrees
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 120);
cell = row.createCell(7);
cell.setCellValue("120D angle");
cell.setCellStyle(myStyle);
//270 degrees
myStyle = workbook.createCellStyle();
myStyle.setRotation((short) 270);
cell = row.createCell(9);
cell.setCellValue("270D angle");
cell.setCellStyle(myStyle);
//360 degrees
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 360);
cell = row.createCell(12);
cell.setCellValue("360D angle");
cell.setCellStyle(myStyle);
FileOutputStream out = new FileOutputStream(
new File("textdirection.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"textdirection.xlsx written successfully");
}
}

@ -0,0 +1,176 @@
package com.rehome.jpahefengweather.service.excel;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class WriteExcel {
private static final String EXCEL_XLS = "xls";
private static final String EXCEL_XLSX = "xlsx";
private String filePath = null;
public void testWriteExcel(){
Map<String, String> dataMap=new HashMap<String, String>();
dataMap.put("BankName", "中国农业银行");
dataMap.put("Addr", "凤凰北路28号");
dataMap.put("Phone", "07568329823");
List<Map> list=new ArrayList<Map>();
list.add(dataMap);
Map<String, String> dataMap1=new HashMap<String, String>();
dataMap1.put("BankName", "中国工商银行");
dataMap1.put("Addr", "凤凰北路38号");
dataMap1.put("Phone", "07568329833");
list.add(dataMap1);
writeExcel(list, 3, this.filePath);
//writeExcel();
}
public WriteExcel(String dir,String fileName){
if(dir!=null&&fileName!=null){
this.filePath = dir+File.separator+fileName;
}
}
public void writeExcel(){
try {
// Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook();
// Get first/desired sheet from the workbook
XSSFSheet sheet = createSheet(workbook, "Sheet 1", false);
// XSSFSheet sheet = workbook.getSheetAt(1);//Don't use this line
// because you get Sheet index (1) is out of range (no sheets)
//Write some information in the cells or do what you want
XSSFRow row1 = sheet.createRow(0);
XSSFCell r1c2 = row1.createCell(0);
r1c2.setCellValue("NAME");
XSSFCell r1c3 = row1.createCell(1);
r1c3.setCellValue("AGE");
//Save excel to HDD Drive
File pathToFile = new File(this.filePath);
if (!pathToFile.exists()) {
pathToFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(pathToFile);
workbook.write(fos);
fos.close();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
public static void writeExcel(List<Map> dataList, int cloumnCount,String finalXlsxPath){
try {
// 获取总列数
int columnNumCount = cloumnCount;
// Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook();
// Get first/desired sheet from the workbook
XSSFSheet sheet = createSheet(workbook, "Sheet 1", false);
/**
*
*/
int rowNumber = sheet.getLastRowNum(); // 第一行从0开始算
System.out.println("原始数据总行数,除属性列:" + rowNumber);
for (int i = 1; i <= rowNumber; i++) {
Row row = sheet.getRow(i);
sheet.removeRow(row);
}
/**
* Excel
*/
for (int j = 0; j < dataList.size(); j++) {
if(j==0){
// 创建一行:从第二行开始,跳过属性列
Row row0 = sheet.createRow(j );
for (int k = 0; k <= columnNumCount; k++) {
// 在一行内循环
Cell first = row0.createCell(0);
first.setCellValue("银行名称");
Cell second = row0.createCell(1);
second.setCellValue("地址");
Cell third = row0.createCell(2);
third.setCellValue("电话");
}
}
// 创建一行:从第二行开始,跳过属性列
Row row = sheet.createRow(j + 1);
// 得到要插入的每一条记录
Map dataMap = dataList.get(j);
String name = dataMap.get("BankName").toString();
String address = dataMap.get("Addr").toString();
String phone = dataMap.get("Phone").toString();
for (int k = 0; k <= columnNumCount; k++) {
// 在一行内循环
Cell first = row.createCell(0);
first.setCellValue(name);
Cell second = row.createCell(1);
second.setCellValue(address);
Cell third = row.createCell(2);
third.setCellValue(phone);
}
}
//Save excel to HDD Drive
File pathToFile = new File(finalXlsxPath);
if (!pathToFile.exists()) {
pathToFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(pathToFile);
workbook.write(fos);
fos.close();
System.out.println("Done");
} catch (Exception e) {
e.printStackTrace();
}
}
private static XSSFSheet createSheet(XSSFWorkbook wb, String prefix, boolean isHidden) {
XSSFSheet sheet = null;
int count = 0;
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
String sName = wb.getSheetName(i);
if (sName.startsWith(prefix))
count++;
}
if (count > 0) {
sheet = wb.createSheet(prefix + count);
} else
sheet = wb.createSheet(prefix);
if (isHidden)
wb.setSheetHidden(wb.getNumberOfSheets() - 1, XSSFWorkbook.SHEET_STATE_VERY_HIDDEN);
return sheet;
}
}

@ -0,0 +1,88 @@
package com.rehome.jpahefengweather.utils;
import java.util.Arrays;
import java.util.Locale;
/**
* dao
*
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-01-12 9:38
*/
public class DaoUtil {
/**
* oracle
*
* @param sqlBuilder sql
* @param paging
* @author LiuHuiYu
* Created DateTime 2022-01-12 9:39
*/
public static void paginationOracleSql(StringBuilder sqlBuilder, Paging paging) {
String rowNumName;
for(int i=0;;i++){
rowNumName = "rowno_" + i;
if(!sqlBuilder.toString().toLowerCase(Locale.ROOT).contains(rowNumName)){
break;
}
}
sqlBuilder.insert(0, "SELECT * FROM (SELECT t_pagination.*, ROWNUM AS " + rowNumName + " FROM(");
sqlBuilder.append(") t_pagination WHERE ROWNUM <= ")
.append(paging.endRowNo())
.append(") table_alias WHERE table_alias.")
.append(rowNumName)
.append(" >= ")
.append(paging.beginRowNo());
}
/**
* sql
*
* @param sqlBuilder sql StringBuilder
* @author LiuHuiYu
* Created DateTime 2022-01-12 9:57
*/
public static void countOracleSql(StringBuilder sqlBuilder) {
int index = sqlBuilder.toString().toLowerCase().indexOf(" from ");
sqlBuilder.replace(0, index, "select count(1)");
}
/**
* sql
*
* @param sqlBuilder sql StringBuilder
* @author LiuHuiYu
* @deprecated
* Created DateTime 2022-01-12 9:57
*/
@Deprecated
public static void countOracleSql2(StringBuilder sqlBuilder) {
String fromString = " from ";
int f = 0;
int level = 0;
for (int i = 0; i < sqlBuilder.length(); i++) {
//字符串检测
if (Arrays.asList('\'', '\"').contains(sqlBuilder.charAt(i))) {
throw new RuntimeException("当前解析无法解析包含字符串的sql语句");
}
//包含检测
if (sqlBuilder.charAt(i) == '(') {
level++;
}
else if (sqlBuilder.charAt(i) == ')') {
level--;
}
if (level < 0) {
throw new RuntimeException("输入的sql语句异常");
}
// if (f == fromString.length() && level == 0) {
// ;
// }
}
int index = sqlBuilder.toString().toLowerCase().indexOf(" from ");
sqlBuilder.replace(0, index, "select count(1)");
}
}

@ -0,0 +1,100 @@
package com.rehome.jpahefengweather.utils;
import org.apache.poi.hssf.usermodel.*;
import java.util.List;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-03-24 15:19
*/
public class ExcelUtil {
/**
* Excel
*
* @param sheetName sheet
* @param title
* @param values
* @param wb HSSFWorkbook
* @return HSSFWorkbook
*/
public static HSSFWorkbook getWorkbook(String sheetName, String[] title, String[][] values, HSSFWorkbook wb) {
// 第一步创建一个HSSFWorkbook对应一个Excel文件
if (wb == null) {
wb = new HSSFWorkbook();
}
// 第二步在workbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet(sheetName);
// 第三步在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
HSSFRow row = sheet.createRow(0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
// 创建一个居中格式
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//声明列对象
HSSFCell cell;
//创建标题
for (int i = 0; i < title.length; i++) {
cell = row.createCell(i);
cell.setCellValue(title[i]);
cell.setCellStyle(style);
}
//创建内容
for (int i = 0; i < values.length; i++) {
row = sheet.createRow(i + 1);
for (int j = 0; j < values[i].length; j++) {
//将内容按顺序赋给对应的列对象
row.createCell(j).setCellValue(values[i][j]);
}
}
return wb;
}
public static HSSFWorkbook getWorkbook(String sheetName, String[] title, List<String[]> values, HSSFWorkbook wb) {
// 第一步创建一个HSSFWorkbook对应一个Excel文件
if (wb == null) {
wb = new HSSFWorkbook();
}
// 第二步在workbook中添加一个sheet,对应Excel文件中的sheet
HSSFSheet sheet = wb.createSheet(sheetName);
// 第三步在sheet中添加表头第0行,注意老版本poi对Excel的行数列数有限制
HSSFRow row = sheet.createRow(0);
// 第四步,创建单元格,并设置值表头 设置表头居中
HSSFCellStyle style = wb.createCellStyle();
// 创建一个居中格式
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//声明列对象
HSSFCell cell;
//创建标题
for (int i = 0; i < title.length; i++) {
cell = row.createCell(i);
cell.setCellValue(title[i]);
cell.setCellStyle(style);
}
//创建内容
for (int i = 0; i < values.size(); i++) {
row = sheet.createRow(i + 1);
for (int j = 0; j < values.get(i).length; j++) {
//将内容按顺序赋给对应的列对象
row.createCell(j).setCellValue(values.get(i)[j]);
}
}
return wb;
}
}

@ -0,0 +1,38 @@
package com.rehome.jpahefengweather.utils;
/**
*
* <pre>
* &#x40;ApiModelProperty("分页信息")
* private Paging paging = new Paging();
*
* &#x40;Override
* public Paging getPaging() {
* return paging;
* }
*
* &#x40;Override
* public void setPaging(Paging paging) {
* this.paging = paging;
* }
* </pre>
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-01-12 10:22
*/
public interface IPaging {
/**
*
* @author LiuHuiYu
* Created DateTime 2022-01-20 15:29
* @return cc.rehome.zhanjiang.data_center_model.domain.Paging
*/
Paging getPaging();
/**
*
* @author LiuHuiYu
* Created DateTime 2022-01-20 15:29
* @param paging
*/
void setPaging(Paging paging);
}

@ -0,0 +1,18 @@
package com.rehome.jpahefengweather.utils;
import java.io.Serializable;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-01-08 9:45
*/
public interface ISerializationJson extends Serializable {
/**
* json
* @author LiuHuiYu
* Created DateTime 2022-01-20 15:30
* @return java.lang.String
*/
String toJson();
}

@ -0,0 +1,66 @@
package com.rehome.jpahefengweather.utils;
import net.i2p.crypto.eddsa.EdDSAEngine;
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.springframework.lang.NonNull;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Base64;
public class JwtUtils {
public static String getJwt(){
try {
// Private key
String privateKeyString = "MC4CAQAwBQYDK2VwBCIEIOtI2Yuhkyor4Zfny9OUMbzMmZCEJ7hqIpuoDhk0zYcy";
privateKeyString = privateKeyString.trim().replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyString);
PKCS8EncodedKeySpec encoded = new PKCS8EncodedKeySpec(privateKeyBytes);
PrivateKey privateKey = new EdDSAPrivateKey(encoded);
// Header
String headerJson = "{\"alg\": \"EdDSA\", \"kid\": \"C4B98RHV2D\"}";
// Payload
long iat = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() - 30;
long exp = iat + 900;
String payloadJson = "{\"sub\": \"278AVHGU9W\", \"iat\": " + iat + ", \"exp\": " + exp + "}";
// Base64url header+payload
String headerEncoded = Base64.getUrlEncoder().encodeToString(headerJson.getBytes(StandardCharsets.UTF_8));
String payloadEncoded = Base64.getUrlEncoder().encodeToString(payloadJson.getBytes(StandardCharsets.UTF_8));
String data = headerEncoded + "." + payloadEncoded;
EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
// Sign
final Signature s = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
s.initSign(privateKey);
s.update(data.getBytes(StandardCharsets.UTF_8));
byte[] signature = s.sign();
String signatureString = Base64.getUrlEncoder().encodeToString(signature);
System.out.println("Signature: \n" + signatureString);
// Print Token
String jwt = data + "." + signatureString;
System.out.println("JWT: \n" + jwt);
return jwt;
}catch (Exception e){
e.printStackTrace();
}
return null;
}
}

@ -0,0 +1,142 @@
package com.rehome.jpahefengweather.utils;
import java.util.function.Function;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2020-09-10 8:41
*/
public class LhyAssert {
static Function<String, RuntimeException> exceptionProxy;
private static RuntimeException throwEx(String message) {
if (exceptionProxy == null) {
return new RuntimeException(message);
}
else {
return exceptionProxy.apply(message);
}
}
/**
*
*
* @param proxy
* @author LiuHuiYu
* Created DateTime 2021-12-10 14:43
*/
public static void exceptionProxy(Function<String, RuntimeException> proxy) {
exceptionProxy = proxy;
}
//region assertTrue
public static void assertTrue(boolean value, RuntimeException exception) {
if (!value) {
throw exception;
}
}
public static void assertTrue(boolean value, String message) {
assertTrue(value, throwEx(message));
}
//endregion
//region assertFalse
public static void assertFalse(boolean value, String message) {
assertTrue(!value, message);
}
public static void assertFalse(boolean value, RuntimeException exception) {
assertTrue(!value, exception);
}
//endregion
//region assertNotNull
public static void assertNotNull(Object object, RuntimeException exception) {
assertTrue(object != null, exception);
}
/**
*
*
* @param object
*/
public static void assertNotNull(Object object, String message) {
assertTrue(object != null, message);
}
//endregion
//region assertNull
/**
*
*
* @param object
*/
public static void assertNull(Object object, RuntimeException exception) {
assertTrue(object == null, exception);
}
/**
*
*
* @param object
*/
public static void assertNull(Object object, String message) {
assertTrue(object == null, message);
}
//endregion
//region 枚举模式拦截
/**
*
*
* @param value
* @param resultEnum
*/
public static void assertTrue(boolean value, ResultEnum resultEnum) {
if (!value) {
throw new LhyException(resultEnum);
}
}
/**
*
*
* @param object
* @param resultEnum
*/
public static void assertNotNull(Object object, ResultEnum resultEnum) {
assertTrue(object != null, resultEnum);
}
/**
*
*
* @param object
* @param resultEnum
*/
public static void assertNull(Object object, ResultEnum resultEnum) {
assertTrue(object == null, resultEnum);
}
//endregion
public static void assertLen(String value, int min, int max, String message) {
assertNotNull(value, message + "未设定");
assertTrue(
(min <= 0 || value.length() >= min) &&
(max < 0 || value.length() <= max), message + "(长度范围[" + min + "-" + max + "])");
}
public static void assertLen(String value, int min, int max, RuntimeException exception) {
assertNotNull(value, exception);
assertTrue(value.length() >= min && value.length() <= max, exception);
}
}

@ -0,0 +1,53 @@
package com.rehome.jpahefengweather.utils;
import org.jetbrains.annotations.NotNull;
/**
*
*
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2020-06-23 13:27
*/
public class LhyException extends RuntimeException {
private Integer errId;
/*
public ArchivesManagementException(Integer code, String message) {
super(message);
this.code = code;
}
*/
public LhyException(@NotNull ResultEnum resultEnum) {
super(resultEnum.getMessage());
this.errId = resultEnum.getCode();
}
public LhyException(@NotNull ResultEnum resultEnum, String message) {
super(resultEnum.getMessage() + ":" + message);
this.errId = resultEnum.getCode();
}
public LhyException(String message, @NotNull ResultEnum resultEnum) {
super(message + resultEnum.getMessage());
this.errId = resultEnum.getCode();
}
public LhyException(String message, @NotNull ResultEnum resultEnum, String message1) {
super(message + resultEnum.getMessage() + message1);
this.errId = resultEnum.getCode();
}
public LhyException(String message) {
super(message);
this.errId = 0;
}
public Integer getErrId() {
return errId;
}
public void setErrId(Integer errId) {
this.errId = errId;
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save