和风天气全部改用jpa,移除所有sql编码查询

master
wenfei 6 months ago
parent 924942f065
commit 972426019c

@ -49,18 +49,6 @@
<version>1.18.20</version>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
<!-- 引入poi解析excel -->
<dependency>
<groupId>org.apache.poi</groupId>
@ -92,36 +80,6 @@
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>util</artifactId>
<version>2022.1.0</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>spring-util</artifactId>
<version>2021.1.0</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>web</artifactId>
<version>2022.1.0</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>jpa</artifactId>
<version>2021.1.0</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>okhttp3util</artifactId>
<version>2021.2.2</version>
</dependency>
<dependency>
<groupId>com.liuhuiyu</groupId>
<artifactId>test</artifactId>
<version>2021.1.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
@ -155,21 +113,31 @@
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.dameng</groupId>-->
<!-- <artifactId>DmJdbcDriver18</artifactId>-->
<!-- <version>8.1.2.141</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.dameng</groupId>-->
<!-- <artifactId>DmDialect-for-hibernate5.3</artifactId>-->
<!-- <version>8.1.2.141</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>
</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>
@ -179,5 +147,4 @@
</plugin>
</plugins>
</build>
</project>

@ -1,10 +1,13 @@
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.cache.annotation.EnableCaching;
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;
@ -14,7 +17,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableJpaAuditing
@EnableScheduling
@SpringBootApplication
public class JpahefengweatherApplication extends SpringBootServletInitializer {
public class JpahefengweatherApplication extends SpringBootServletInitializer implements ApplicationContextAware {
public static ApplicationContext context;
public static void main(String[] args) {
SpringApplication.run(JpahefengweatherApplication.class, args);
@ -30,4 +35,9 @@ public class JpahefengweatherApplication extends SpringBootServletInitializer {
SpringApplicationBuilder builder) {
return builder.sources(JpahefengweatherApplication.class);
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
context = applicationContext;
}
}

@ -1,32 +1,30 @@
package com.rehome.jpahefengweather.controller;
import com.liuhuiyu.util.model.Result;
import com.rehome.jpahefengweather.dto.BaseFindDto;
import com.rehome.jpahefengweather.dto.BaseWeatherFindDto;
import com.rehome.jpahefengweather.dto.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto;
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.WeatherService;
import com.rehome.jpahefengweather.service.HefengWeatherService;
import com.rehome.jpahefengweather.utils.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/weather")
public class WeatherController {
@RequestMapping("/hefengWeather/service")
public class HefengWeatherController {
@Resource
private CityService cityService;
@Resource
private WeatherService weatherService;
private HefengWeatherService hefengWeatherService;
/**
* @date 2022-05-01 14:42
@ -45,7 +43,7 @@ public class WeatherController {
@ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
})
public Result<List<NowWeather>> getNowWeatherEntity(@Validated @RequestBody BaseWeatherFindDto dto){
List<NowWeather> weathers = this.weatherService.findNowWeatherByLocationIdAndDate(dto.getLocationId(),dto.getWeatherDate());
List<NowWeather> weathers = this.hefengWeatherService.findNowWeatherByLocationIdAndDate(dto.getLocationId(),dto.getWeatherDate());
return Result.of(weathers);
}
//endregion
@ -56,7 +54,7 @@ public class WeatherController {
@ApiImplicitParam(name = "dto", value = "获取历史天气处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
})
public Result<List<NowWeatherDto>> getNowWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
List<NowWeatherDto> weathers = this.weatherService.findHistoryWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
List<NowWeatherDto> weathers = this.hefengWeatherService.findHistoryWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
return Result.of(weathers);
}
//endregion
@ -67,7 +65,7 @@ public class WeatherController {
@ApiImplicitParam(name = "dto", value = "实时天气数据处理", dataTypeClass = BaseFindDto.class, paramType = "body", required = true),
})
public Result<NowWeatherDto> getNowWeatherDtoOne(@Validated @RequestBody BaseFindDto dto){
NowWeatherDto nowWeatherDto=this.weatherService.findNowWeatherByLocationIdAndDateDto(dto.getLocationId());
NowWeatherDto nowWeatherDto=this.hefengWeatherService.findNowWeatherByLocationIdAndDateDto(dto.getLocationId());
return Result.of(nowWeatherDto);
}
//endregion
@ -78,9 +76,31 @@ public class WeatherController {
@ApiImplicitParam(name = "dto", value = "天气预报处理", dataTypeClass = BaseWeatherFindDto.class, paramType = "body", required = true),
})
public Result<List<ForecastWeatherDto>> getForecastWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){
List<ForecastWeatherDto> weathers = this.weatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate());
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
}

@ -1,52 +1,26 @@
package com.rehome.jpahefengweather.controller;
import com.liuhuiyu.util.model.Result;
import com.rehome.jpahefengweather.dto.BaseWeatherFindDto;
import com.rehome.jpahefengweather.dto.TyphoonBaseDto;
import com.rehome.jpahefengweather.dto.TyphoonTfidDto;
import com.rehome.jpahefengweather.dto.WztfStormInfoDto;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.WeatherService;
import com.rehome.jpahefengweather.service.WztfStormService;
import com.rehome.jpahefengweather.service.ZjsltStormService;
import com.rehome.jpahefengweather.utils.Result;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping("/typhoon")
public class TyphoonController {
@Resource
private ZjsltStormService zjsltStormService;
public class WztfwStormController {
@Resource
private WztfStormService wztfStormService;
//region 根据年份获取台风列表
@PostMapping("/getStormListByYear")
@ApiOperation(value = "获取台风列表", notes = "获取台风列表")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "dto", value = "获取台风列表", dataTypeClass = TyphoonBaseDto.class, paramType = "body", required = true),
})
public Result<List<ZjsltStorm>> getStormListByYear(@Validated @RequestBody TyphoonBaseDto dto){
return Result.of(this.zjsltStormService.findByYear(dto.getYear()));
}
//endregion
//region 根据台风id获取单条台风数据
@PostMapping("/getTyphoonInfoByTfid")
@ApiOperation(value = "根据台风id获取单条台风数据", notes = "根据台风id获取单条台风数据")
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "dto", value = "根据台风id获取单条台风数据", dataTypeClass = TyphoonTfidDto.class, paramType = "body", required = true),
})
public Result<TyphoonInfo> getTyphoonInfoByTfid(@Validated @RequestBody TyphoonTfidDto dto){
return Result.of(this.zjsltStormService.findTyphoonInfoByTfid(dto.getTfid()));
}
//endregion
//region 根据年份获取台风列表
@PostMapping("/getWztfStormListByYear")

@ -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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
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);
}
}

@ -1,129 +0,0 @@
package com.rehome.jpahefengweather.dao;
import com.liuhuiyu.jpa.BaseView;
import com.liuhuiyu.jpa.DaoOperator;
import com.rehome.jpahefengweather.utils.DaoUtil;
import com.rehome.jpahefengweather.utils.IPaging;
import org.springframework.data.domain.PageImpl;
import javax.sql.DataSource;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-02-21 16:16
*/
public abstract class BaseDataCenterView extends BaseView {
public BaseDataCenterView(DataSource dataSource) {
super(dataSource);
}
/**
*
*
* @param t
* @param sql
* @param fullWhere
* @param <T>
* @return java.lang.Long
* @author LiuHuiYu
* Created DateTime 2022-02-21 16:24
*/
protected <T> Long count(T t, String sql, String baseWhere, FullWhere<T> fullWhere) {
StringBuilder sqlBuilder = new StringBuilder(sql);
sqlBuilder.append(baseWhere);
Map<String, Object> parameterMap = new HashMap<>(0);
fullWhere.fullWhere(t, sqlBuilder, parameterMap);
DaoUtil.countOracleSql(sqlBuilder);
return super.selectCount(sqlBuilder.toString(), parameterMap);
}
/**
*
* @author LiuHuiYu
* Created DateTime 2022-04-25 10:29
* @param b
* @param t
* @param sql
* @param baseWhere
* @param order
* @param fullWhere
* @param <R>
* @param <T>
* @return java.util.List<R>
*/
protected <T extends IPaging, R> List<R> pageList(DaoOperator<R> b, T t, String sql, String baseWhere, String order, FullWhere<T> fullWhere) {
StringBuilder sqlBuilder = new StringBuilder(sql);
sqlBuilder.append(baseWhere);
Map<String, Object> parameterMap = new HashMap<>(0);
fullWhere.fullWhere(t, sqlBuilder, parameterMap);
sqlBuilder.append(" ").append(order);
DaoUtil.paginationOracleSql(sqlBuilder, t.getPaging());
return super.getResultList(b, sqlBuilder.toString(), parameterMap);
}
protected <T extends IPaging, R> PageImpl<R> page(DaoOperator<R> b, T t, String sql, FullWhere<T> fullWhere, String order) {
return page(b, t, sql, " WHERE(1=1) ", order, fullWhere);
}
/**
*
* @author LiuHuiYu
* Created DateTime 2022-04-25 10:29
* @param b
* @param t
* @param sql
* @param baseWhere
* @param order
* @param fullWhere
* @param <R>
* @param <T>
* @return java.util.List<R>
*/
protected <T extends IPaging, R> List<R> list(DaoOperator<R> b, T t, String sql, String baseWhere, String order, FullWhere<T> fullWhere) {
StringBuilder sqlBuilder = new StringBuilder(sql);
sqlBuilder.append(baseWhere);
Map<String, Object> parameterMap = new HashMap<>(0);
fullWhere.fullWhere(t, sqlBuilder, parameterMap);
sqlBuilder.append(" ").append(order);
return super.getResultList(b, sqlBuilder.toString(), parameterMap);
}
/**
*
*
* @param b
* @param t
* @param sql
* @param baseWhere where
* @param order ( order by)
* @param fullWhere void fullWhere(T find, StringBuilder sqlBuilder, Map<String, Object> parameterMap)
* @param <R>
* @param <T>
* @return org.springframework.data.domain.PageImpl<R>
* @author LiuHuiYu
* Created DateTime 2022-04-09 11:41
*/
protected <T extends IPaging, R> PageImpl<R> page(DaoOperator<R> b, T t, String sql, String baseWhere, String order, FullWhere<T> fullWhere) {
Long total = this.count(t, sql, baseWhere, fullWhere);
final List<R> gatekeeperCarLogDtoList;
if (total == 0) {
gatekeeperCarLogDtoList = Collections.emptyList();
}
else if (t.getPaging().isAllInOne()) {
gatekeeperCarLogDtoList = this.list(b, t, sql, baseWhere, order, fullWhere);
}
else if (t.getPaging().getPageSize() == 0) {
gatekeeperCarLogDtoList = Collections.emptyList();
}
else {
//记录查询
gatekeeperCarLogDtoList = pageList(b, t, sql, baseWhere, order, fullWhere);
}
return new PageImpl<>(gatekeeperCarLogDtoList, t.getPaging().getPageRequest(), total);
}
}

@ -1,22 +0,0 @@
package com.rehome.jpahefengweather.dao;
import java.util.Map;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2022-02-21 16:17
*/
@FunctionalInterface
public interface FullWhere<T> {
/**
*
*
* @param find
* @param sqlBuilder sql
* @param parameterMap
* @author LiuHuiYu
* Created DateTime 2022-02-21 16:19
*/
void fullWhere(T find, StringBuilder sqlBuilder, Map<String, Object> parameterMap);
}

@ -16,11 +16,9 @@ import java.util.List;
public interface NowWeatherRepository extends JpaRepository<NowWeather,Long> {
//方法名称必须要遵循驼峰式命名规则findBy关键字+属性名称(首字母大写)+查询条件(首字母大写)
//List<NowWeather> findByLocationIdAndWeatherDate(String locationId, String weatherDate);
@Query(value="select * from now_weather where location_id=?1 and weather_date=?2 order by id desc", nativeQuery = true)
List<NowWeather> findByLocationIdAndWeatherDate(String locationId, String weatherDate);
List<NowWeather> findByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate);
@Query(value="select * from (select * from now_weather where location_id=?1 and weather_date=?2 order by id desc) where rownum = 1", nativeQuery = true)
NowWeather findByLocationIdOne(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);
}

@ -20,4 +20,6 @@ public interface ZjsltStormRepository extends JpaRepository<ZjsltStorm,String> {
ZjsltStorm findByTfid(String tfid);
List<ZjsltStorm> findByYear(String year);
List<ZjsltStorm> findByYearAndIsactiveOrderByCreateDateDesc(String year,String isactive);
}

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,6 +1,7 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,10 +1,10 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**
@ -12,7 +12,7 @@ import java.util.Map;
* @version v1.0.0.0
* Created DateTime 2022-05-01 16:22
*/
@ApiModel(value = "ForecastDto", description = "实时天气数据")
@ApiModel(value = "ForecastDto", description = "天气预报数据")
public class ForecastDto {
@ApiModelProperty("预报日期")

@ -1,10 +1,10 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import java.util.Map;

@ -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;
}

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,6 +1,7 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;

@ -1,10 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.dto.bean.NmcNowData;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,10 +1,10 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
import java.util.Map;

@ -1,9 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,10 +1,10 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,10 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -1,10 +1,9 @@
package com.rehome.jpahefengweather.dto;
import com.liuhuiyu.util.map.MapUtil;
import com.rehome.jpahefengweather.utils.MapUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.Map;
/**

@ -8,8 +8,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
//@Table(name="t_users")
@ -26,9 +25,8 @@ public class ForecastWeather implements Serializable {
private String locationNameZh;
// 存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
//存放长文本
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;

@ -6,8 +6,7 @@ import lombok.Data;
import org.hibernate.annotations.Proxy;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
@Table(indexes = {@Index(name = "idx_location_id_future", columnList = "locationId")})

@ -6,8 +6,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@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")})

@ -7,8 +7,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class NmcCity implements Serializable{

@ -7,8 +7,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class NmcNowWeather implements Serializable{
@ -17,8 +16,7 @@ public class NmcNowWeather implements Serializable{
private Long id;
//存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;

@ -7,8 +7,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class NmcProvince implements Serializable{

@ -8,8 +8,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class NmcStorm implements Serializable {

@ -11,8 +11,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
//@Table(name="t_users")
@ -30,8 +29,7 @@ public class NowWeather implements Serializable {
private String locationNameZh;
//存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
@Column(columnDefinition = "TEXT")
private String weather;
private String weatherDate;

@ -9,8 +9,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class TyphoonInfo implements Serializable {
@ -18,8 +17,7 @@ public class TyphoonInfo implements Serializable {
private String tfid;
//存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
@Column(columnDefinition = "TEXT")
private String stormData;
@Temporal(TemporalType.TIMESTAMP)

@ -9,8 +9,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class WztfStorm implements Serializable {

@ -9,8 +9,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class WztfStormInfo implements Serializable {
@ -18,8 +17,7 @@ public class WztfStormInfo implements Serializable {
private String tfbh;
//存放长文本
@Lob
@Basic(fetch=FetchType.LAZY)
@Column(columnDefinition = "TEXT")
private String stormData;
@Temporal(TemporalType.TIMESTAMP)

@ -9,8 +9,7 @@ import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data
@Entity
public class ZjsltStorm implements Serializable {

@ -1,13 +1,14 @@
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 WeatherService {
public interface HefengWeatherService {
/**
* 3000+
* @return NowWeather
@ -59,4 +60,9 @@ public interface WeatherService {
* @return List<ForecastWeather>
*/
List<ForecastWeatherDto> findForecastWeatherByLocationIdAndDateDto(String locationId, String date);
/**
* iddtoapi
* @return List<ForecastWeather>
*/
HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(String locationId, String date);
}

@ -1,30 +1,27 @@
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.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.HefengFutureWeatherDto;
import com.rehome.jpahefengweather.dto.HefengRealtimeWeatherDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto;
import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.service.WeatherService;
import com.rehome.jpahefengweather.service.HefengWeatherService;
import com.rehome.jpahefengweather.utils.OkHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class WeatherServiceImpl implements WeatherService {
public class HefengWeatherServiceImpl implements HefengWeatherService {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
@ -42,7 +39,7 @@ public class WeatherServiceImpl implements WeatherService {
@Override
public List<NowWeather> findNowWeatherByLocationIdAndDate(String locationId, String date) {
return this.nowWeatherRepository.findByLocationIdAndWeatherDate(locationId,date);
return this.nowWeatherRepository.findByLocationIdAndWeatherDateOrderByIdDesc(locationId,date);
}
@Override
@ -181,6 +178,7 @@ public class WeatherServiceImpl implements WeatherService {
daily.setCity(city.getAdm2NameZh());
daily.setLocationNameZh(city.getLocationNameZh());
daily.setCreateTime(dailyDB.getCreateTime());
daily.setUpdateTime(now);
daily.setFxLink(hefengFutureWeatherDto.getFxLink());
hefengFutureWeatherRepository.save(daily);
@ -216,8 +214,9 @@ public class WeatherServiceImpl implements WeatherService {
public NowWeatherDto findNowWeatherByLocationIdAndDateDto(String locationId) {
SimpleDateFormat sdFormat=new SimpleDateFormat("yyyy-MM-dd");
String now = sdFormat.format(new Date());
NowWeather nowWeather = this.nowWeatherRepository.findByLocationIdOne(locationId,now);
if(nowWeather!=null){
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;
@ -242,7 +241,7 @@ public class WeatherServiceImpl implements WeatherService {
@Override
public List<ForecastWeatherDto> findForecastWeatherByLocationIdAndDateDto(String locationId, String date) {
List<ForecastWeather> weathers = this.findForecastWeatherByLocationIdAndDate(locationId,date);
List<ForecastWeather> weathers = this.findForecastWeatherByLocationIdAndDateOrderByCreateDateDesc(locationId,date);
if(weathers!=null&&weathers.size()>0){
List<ForecastWeatherDto> dtos = new ArrayList<>();
for (ForecastWeather weather:weathers) {
@ -254,4 +253,30 @@ public class WeatherServiceImpl implements WeatherService {
}
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;
}
}

@ -1,14 +1,16 @@
package com.rehome.jpahefengweather.service.Impl;
import com.rehome.jpahefengweather.dao.NmcStormRepository;
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 org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
@ -29,6 +31,16 @@ public class ZjsltStormServiceImpl implements ZjsltStormService {
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);

@ -3,8 +3,7 @@ package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.liuhuiyu.spring_util.SpringUtil;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.dto.*;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.excel.*;
import com.rehome.jpahefengweather.utils.JwtUtils;
@ -15,6 +14,7 @@ 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 javax.annotation.Resource;
@ -41,8 +41,9 @@ public class ScheduledHefengWeatherService {
@Resource
private CityService cityService;
@Resource
private WeatherService weatherService;
private HefengWeatherService hefengWeatherService;
/**
@ -53,7 +54,7 @@ public class ScheduledHefengWeatherService {
* //天气图标用法: https://icons.qweather.com/usage/
* @Param: null
*/
//@Scheduled(cron = "0 34 * * * *")//每个小时执行一次
//@Scheduled(cron = "0 30 * * * *")//每个小时执行一次
public void scheduled() {
log.info("scheduled");
log.info("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
@ -116,12 +117,7 @@ public class ScheduledHefengWeatherService {
}
}
}
//@Scheduled(cron = "0/5 * * * * *")//每个小时执行一次
public void scheduledGetJwt() {
String jwt = JwtUtils.getJwt();
log.info(jwt);
}
/**
* @date 2022-03-16 09:41
@ -137,7 +133,7 @@ public class ScheduledHefengWeatherService {
//广东省惠州市惠阳
String locationNameEn_Huiyang = "Huiyang";
this.weatherService.saveHefengWeatherByLocationNameEn(locationNameEn_Huiyang);
this.hefengWeatherService.saveHefengWeatherByLocationNameEn(locationNameEn_Huiyang);
}
/**
@ -146,14 +142,14 @@ public class ScheduledHefengWeatherService {
* @Param: null
*/
//@Scheduled(cron = "0 0 9 * * *")//每天9点执行一次
@Scheduled(cron = "0 16 * * * *")//每个小时执行一次
@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.weatherService.saveHefengFutureWeatherByLocationNameEn(locationNameEn_Huiyang);
this.hefengWeatherService.saveHefengFutureWeatherByLocationNameEn(locationNameEn_Huiyang);
}
/**
@ -334,7 +330,7 @@ public class ScheduledHefengWeatherService {
* @description: ,
* @Param: null
*/
//@Scheduled(cron = "*/10 * * * * *")//每天0816点各执行一次一天总共执行三次
//@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()));
@ -370,4 +366,39 @@ public class ScheduledHefengWeatherService {
}
});
}
/**
* @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));
}
}

@ -2,22 +2,15 @@ package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.liuhuiyu.spring_util.SpringUtil;
import com.rehome.jpahefengweather.JpahefengweatherApplication;
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 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 javax.annotation.Resource;
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;
@ -36,8 +29,6 @@ public class ScheduledNmcWeatherService {
@Resource
private CityService cityService;
@Resource
private WeatherService weatherService;
@Resource
private NmcCityService nmcCityService;
@Resource
private NmcWeatherService nmcWeatherService;
@ -207,9 +198,8 @@ public class ScheduledNmcWeatherService {
nowWeather.setLastUpdateDate(now);
nowWeather.setCreateDate(now);
NmcWeatherService nmcWeatherServiceTemp = SpringUtil.getBean(NmcWeatherService.class);
NmcWeatherService nmcWeatherServiceTemp = JpahefengweatherApplication.context.getBean(NmcWeatherService.class);
nmcWeatherServiceTemp.saveNowWeather(nowWeather);
}
} catch (Exception e) {
e.printStackTrace();

@ -2,7 +2,6 @@ package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.liuhuiyu.spring_util.SpringUtil;
import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.excel.*;
@ -28,7 +27,7 @@ import java.util.concurrent.TimeUnit;
* Created DateTime 2021-04-26 14:35
* @description:
*/
//@Component
@Component
public class ScheduledWztfwStormService {
@Resource
@ -39,9 +38,9 @@ public class ScheduledWztfwStormService {
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 30 * * * *")
@Scheduled(cron = "0 39 15 * * *")
public void getWztfHistoryStormList() {
for(int i=1945;i<2025;i++){
for(int i=1945;i<2026;i++){
getWztfStormList(String.valueOf(i));
}
//getWztfStormList(String.valueOf(1944));
@ -62,7 +61,7 @@ public class ScheduledWztfwStormService {
.build();
try {
Thread.sleep(3000);
Thread.sleep(1000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());

@ -2,13 +2,14 @@ package com.rehome.jpahefengweather.service;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.liuhuiyu.spring_util.SpringUtil;
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 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;
@ -28,8 +29,9 @@ import java.util.concurrent.TimeUnit;
* Created DateTime 2021-04-26 14:35
* @description:
*/
//@Component
@Component
public class ScheduledZjsltStormService {
private Logger log = LoggerFactory.getLogger(this.getClass());
@Resource
private ZjsltStormService zjsltStormService;
@ -40,9 +42,9 @@ public class ScheduledZjsltStormService {
* @description:
* @Param: null
*/
// @Scheduled(cron = "0 48 * * * *")
// @Scheduled(cron = "0 24 * * * *")
// public void getZjsltHistoryStormList() {
// for(int i=1940;i<2025;i++){
// for(int i=1944;i<2026;i++){
// getZjsltStormList(String.valueOf(i));
// }
// }
@ -51,9 +53,9 @@ public class ScheduledZjsltStormService {
* @description:
* @Param: null
*/
//@Scheduled(cron = "0 30 * * * *")
//@Scheduled(cron = "0 23 * * * *")
public void getZjsltStormList() {
System.out.println("getZjsltStormList");
log.info("getZjsltStormList");
String strNow = String.valueOf(System.currentTimeMillis());
// 初始化 OkHttpClient
@ -63,7 +65,7 @@ public class ScheduledZjsltStormService {
.readTimeout(30, TimeUnit.SECONDS)
.build();
try {
Thread.sleep(5000);
Thread.sleep(2000);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
String nowDate = sdf.format(new Date());
@ -74,7 +76,7 @@ public class ScheduledZjsltStormService {
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());
System.out.println(url);
log.info(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
@ -83,16 +85,16 @@ public class ScheduledZjsltStormService {
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//System.out.println(body);
//log.info(body);
if (StringUtils.hasText(body)) {
if (body.length() > 0) {
Gson gson = new Gson();
int startIndex = body.indexOf("[");
int endIndex = body.lastIndexOf("]");
// System.out.println(body.indexOf("["));
// System.out.println(body.lastIndexOf("]"));
// log.info(body.indexOf("["));
// log.info(body.lastIndexOf("]"));
String stormStr = body.substring(startIndex, endIndex + 1);
//System.out.println(stormStr);
//log.info(stormStr);
if (stormStr != null && stormStr.length() > 2) {
Type type = new TypeToken<ArrayList<ZjsltStorm>>() {
}.getType();
@ -101,7 +103,7 @@ public class ScheduledZjsltStormService {
for (ZjsltStorm storm : stormList) {
storm.setYear(nowYear);
storm.setCreateDate(new Date());
System.out.println(gson.toJson(storm));
log.info(gson.toJson(storm));
ZjsltStorm stormDB = this.zjsltStormService.findByTfid(storm.getTfid());
if (stormDB == null) {
//数据库无数据,第一次插入,同时从第三方平台拉取台风路径数据入库
@ -147,7 +149,7 @@ public class ScheduledZjsltStormService {
* @Param: null
*/
public void saveOrUpdateTyphoonInfo(ZjsltStorm storm) {
System.out.println("saveOrUpdateTyphoonInfo");
log.info("saveOrUpdateTyphoonInfo");
String strNow = String.valueOf(System.currentTimeMillis());
// 初始化 OkHttpClient
@ -167,7 +169,7 @@ public class ScheduledZjsltStormService {
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());
System.out.println(url);
log.info(url);
// 初始化请求体
Request request = new Request.Builder()
.get()
@ -176,23 +178,23 @@ public class ScheduledZjsltStormService {
// 得到返回Response
Response response = client.newCall(request).execute();
String body = response.body().string();
//System.out.println(body);
//log.info(body);
if (StringUtils.hasText(body)) {
if (body.length() > 0) {
Gson gson = new Gson();
int startIndex = body.indexOf("[");
int endIndex = body.lastIndexOf("]");
// System.out.println(body.indexOf("["));
// System.out.println(body.lastIndexOf("]"));
// log.info(body.indexOf("["));
// log.info(body.lastIndexOf("]"));
String typhoonInfoArryStr = body.substring(startIndex, endIndex + 1);
//System.out.println(typhoonInfoArryStr);
//log.info(typhoonInfoArryStr);
if (typhoonInfoArryStr != null && typhoonInfoArryStr.length() > 2) {
int startIndex0 = typhoonInfoArryStr.indexOf("{");
int endIndex0 = typhoonInfoArryStr.lastIndexOf("}");
// System.out.println(startIndex0);
// System.out.println(endIndex0);
// log.info(startIndex0);
// log.info(endIndex0);
String typhoonInfoStr = typhoonInfoArryStr.substring(startIndex0, endIndex0 + 1);
//System.out.println(typhoonInfoStr);
//log.info(typhoonInfoStr);
TyphoonInfo typhoonInfoDB = this.zjsltStormService.findTyphoonInfoByTfid(storm.getTfid());
TyphoonInfo typhoonInfo = new TyphoonInfo();
@ -216,4 +218,35 @@ public class ScheduledZjsltStormService {
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));
}
}

@ -11,6 +11,8 @@ public interface ZjsltStormService {
ZjsltStorm findByTfid(String tfid);
//根据年份查询台风列表
List<ZjsltStorm> findByYear(String year);
//根据年份查询台风列表
List<ZjsltStorm> getTyhoonActivity();
/**
*
*/

@ -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;
}
}

@ -0,0 +1,18 @@
package com.rehome.jpahefengweather.utils;
import java.util.Map;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2021-03-23 16:49
*/
@FunctionalInterface
public interface MapToT<T> {
/**
* Object T
* @param map Map<String,Object>
* @return T
*/
T mapToT(Map<String,Object> map);
}

@ -0,0 +1,637 @@
package com.rehome.jpahefengweather.utils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import org.apache.commons.beanutils.BeanUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2021-01-20 14:53
*/
public class MapUtil {
boolean throwException = false;
public boolean isThrowException() {
return throwException;
}
public void setThrowException(boolean throwException) {
this.throwException = throwException;
}
//region 静态方法
/**
* MapMap<String, Object>
*
* @param obj Map
* @return Map<String, Object>
*/
public static Map<String, Object> mapObjectToStringKeyMap(Object obj) {
if (obj == null) {
return null;
}
else if (obj instanceof Map<?, ?>) {
Map<?, ?> map = (Map<?, ?>) obj;
Map<String, Object> resMap = new HashMap<>(map.size());
map.forEach((k, v) -> resMap.put(k.toString(), v));
return resMap;
}
else {
return new HashMap<>(0);
}
}
private Object getMapObjectValue(Map<String, Object> map, String key) {
return getMapObjectValue(map, key, null);
}
private Object getMapObjectValue(Map<String, Object> map, String key, Object defValue) {
return map.getOrDefault(key, defValue);
}
public static String getMapStringValue(Map<String, Object> map, String key) {
return getMapStringValue(map, key, "");
}
/**
* (key )
*
* @param map map
* @param key key
* @return
*/
public static String getMapStringValue(Map<String, Object> map, String key, String defValue) {
if (map.containsKey(key)) {
Object obj = map.get(key);
return obj == null ? defValue : obj.toString();
}
else {
return defValue;
}
}
public static Integer getMapIntegerValue(Map<String, Object> map, String key) {
return getMapIntegerValue(map, key, 0);
}
public static Integer getMapIntegerValue(Map<String, Object> map, String key, Integer defValue) {
Object obj = map.getOrDefault(key, defValue);
if (obj == null) {
return defValue;
}
else if (obj instanceof Number) {
return ((Number) obj).intValue();
}
else {
String value = obj.toString();
try {
return Integer.parseInt(value);
}
catch (NumberFormatException ex) {
return defValue;
}
}
}
public static Float getMapFloatValue(Map<String, Object> map, String key) {
return getMapFloatValue(map, key, 0F);
}
public static Float getMapFloatValue(Map<String, Object> map, String key, Float defValue) {
Object obj = map.getOrDefault(key, defValue);
if (obj == null) {
return defValue;
}
else if (obj instanceof Number) {
return ((Number) obj).floatValue();
}
else {
String value = obj.toString();
try {
return Float.parseFloat(value);
}
catch (NumberFormatException ex) {
return defValue;
}
}
}
public static Long getMapLongValue(Map<String, Object> map, String key) {
return getMapLongValue(map, key, 0L);
}
public static Long getMapLongValue(Map<String, Object> map, String key, Long defValue) {
Object obj = map.getOrDefault(key, defValue);
if (obj == null) {
return defValue;
}
else if (obj instanceof Number) {
return ((Number) obj).longValue();
}
else {
String value = obj.toString();
try {
return Long.parseLong(value);
}
catch (NumberFormatException ex) {
return defValue;
}
}
}
public static Boolean getMapBooleanValue(Map<String, Object> map, String key) {
return getMapBooleanValue(map, key, false);
}
public static Boolean getMapBooleanValue(Map<String, Object> map, String key, boolean defValue) {
Object obj = map.getOrDefault(key, defValue);
if (obj == null) {
return defValue;
}
else if (obj instanceof Boolean) {
return (Boolean) obj;
}
try {
return Boolean.parseBoolean(obj.toString());
}
catch (Exception ex) {
return defValue;
}
}
/**
* map int int
*
* @param resultMap map
* @return map
*/
public static Map<String, Object> mapNumberToInt(Map<?, ?> resultMap) {
Map<String, Object> res = new HashMap<>(resultMap.size());
for (Object keyObj : resultMap.keySet()) {
String key = keyObj.toString();
if (resultMap.get(key) instanceof Double) {
Double value = (Double) resultMap.get(key);
if (value.intValue() == value) {
res.put(key, ((Double) resultMap.get(key)).intValue());
}
else {
res.put(key, resultMap.get(key));
}
}
else if (resultMap.get(key) instanceof List<?>) {
res.put(key, listNumberToInt((List<?>) resultMap.get(key)));
}
else if (resultMap.get(key) instanceof Map<?, ?>) {
res.put(key, mapNumberToInt((Map<?, ?>) resultMap.get(key)));
}
else {
res.put(key, resultMap.get(key));
}
}
return res;
}
/**
* list int int
*
* @param list list
* @return list
*/
public static List<Object> listNumberToInt(List<?> list) {
List<Object> res = new ArrayList<>(list.size());
for (Object o : list) {
if (o instanceof Number) {
Double value = (Double) o;
if (value.intValue() == value) {
Object v = value.intValue();
res.add(v);
}
else {
res.add(value);
}
}
else if (o instanceof Map<?, ?>) {
res.add(mapNumberToInt((Map<?, ?>) o));
}
else if (o instanceof List<?>) {
res.add(listNumberToInt((List<?>) o));
}
else {
res.add(o);
}
}
return res;
}
@Deprecated
public static <T> T mapToObject(Map<String, Object> map, T t) {
if (map == null) {
return null;
}
try {
BeanUtils.populate(t, map);
}
catch (Exception e) {
throw new RuntimeException(e);
}
return t;
}
//endregion
public static Map<String, Object> mapOfJsonString(String jsonString) {
try {
Map<String, Object> resultMap = new Gson().fromJson(jsonString, new TypeToken<Map<String, Object>>() {
}.getType());
return mapDoubleToInt(resultMap);
}
catch (JsonSyntaxException e) {
throw new RuntimeException("无法解析成Map格式数据");
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Map
*
* @param map map
* @param classOfT T.class
* @param <T>
* @return T
* @author LiuHuiYu
* Created DateTime 2022-01-22 16:42
*/
public static <T> T fromMap(Map<String, Object> map, Class<T> classOfT) {
String json = new Gson().toJson(map);
return new Gson().fromJson(json, classOfT);
}
/**
* Map
*
* @param map map
* @param classOfT T.class
* @param <T>
* @return T
* @author LiuHuiYu
* Created DateTime 2022-01-22 16:42
*/
public static <T> T fromMap(Map<String, Object> map, Class<T> classOfT, GsonAdapter[] typeAdapter) {
GsonBuilder gsonBuilder = new GsonBuilder();
for (GsonAdapter gsonAdapter : typeAdapter) {
gsonBuilder.registerTypeAdapter(gsonAdapter.type, gsonAdapter.typeAdapter);
}
Gson gson = gsonBuilder.create();
String json = gson.toJson(map);
return new Gson().fromJson(json, classOfT);
}
public static class GsonAdapter {
Type type;
Object typeAdapter;
public GsonAdapter(Type type, Object typeAdapter) {
this.type = type;
this.typeAdapter = typeAdapter;
}
}
public static Map<String, Object> mapDoubleToInt(Map<?, ?> resultMap) {
Map<String, Object> res = new HashMap<>(resultMap.size());
for (Object keyObj : resultMap.keySet()) {
String key = keyObj.toString();
if (resultMap.get(key) instanceof Double) {
Double value = (Double) resultMap.get(key);
if (value.intValue() == value) {
res.put(key, ((Double) resultMap.get(key)).intValue());
}
else {
res.put(key, resultMap.get(key));
}
}
else if (resultMap.get(key) instanceof List<?>) {
res.put(key, listDoubleToInt((List<?>) resultMap.get(key)));
}
else if (resultMap.get(key) instanceof Map<?, ?>) {
res.put(key, mapDoubleToInt((Map<?, ?>) resultMap.get(key)));
}
else {
res.put(key, resultMap.get(key));
}
}
return res;
}
public static List<Object> listDoubleToInt(List<?> list) {
List<Object> res = new ArrayList<>(list.size());
for (Object o : list) {
if (o instanceof Number) {
Double value = (Double) o;
if (value.intValue() == value) {
Object v = value.intValue();
res.add(v);
}
else {
res.add(value);
}
}
else if (o instanceof Map<?, ?>) {
res.add(mapDoubleToInt((Map<?, ?>) o));
}
else if (o instanceof List<?>) {
res.add(listDoubleToInt((List<?>) o));
}
else {
res.add(o);
}
}
return res;
}
public static MapUtil ofJsonString(String jsonString) {
Map<String, Object> map = mapOfJsonString(jsonString);
return new MapUtil(map);
}
private final Map<String, Object> map;
public MapUtil(Map<String, Object> map) {
this.map = map;
}
public String getStringValue(String key) {
return getMapStringValue(this.map, key);
}
public String getStringValue(String key, String defValue) {
return getMapStringValue(this.map, key, defValue);
}
public Integer getIntegerValue(String key) {
return getMapIntegerValue(map, key);
}
public Integer getIntegerValue(String key, Integer defValue) {
return getMapIntegerValue(map, key, defValue);
}
public Float getFloatValue(String key) {
return getMapFloatValue(map, key);
}
public Float getFloatValue(String key, Float defValue) {
return getMapFloatValue(map, key, defValue);
}
public Long getLongValue(String key) {
return getMapLongValue(map, key);
}
public Long getLongValue(String key, Long defValue) {
return getMapLongValue(map, key, defValue);
}
public Object getObjectValue(String key) {
return getMapObjectValue(map, key);
}
public Object getObjectValue(String key, Object defValue) {
return getMapObjectValue(map, key, defValue);
}
public <T> T getValue(String key, T defValue) {
Object obj = map.getOrDefault(key, defValue);
if (obj.getClass().equals(defValue.getClass())) {
return (T) obj;
}
else if (throwException) {
throw new RuntimeException("类型转换失败。");
}
else {
return defValue;
}
}
public Boolean getBooleanValue(String key) {
return getMapBooleanValue(map, key);
}
public Boolean getBooleanValue(String key, boolean defValue) {
return getMapBooleanValue(map, key, defValue);
}
public Timestamp getTimestampValue(String key) {
return getTimestampValue(key, Timestamp.valueOf(LocalDateTime.now()));
}
public Timestamp getTimestampValue(String key, Timestamp defValue) {
Object obj = map.get(key);
if (obj == null) {
return defValue;
}
else if (obj instanceof Timestamp) {
return (Timestamp) obj;
}
else if (obj instanceof Number) {
return new Timestamp(((Number) obj).longValue());
}
else if (obj instanceof String) {
try {
return Timestamp.valueOf((String) obj);
}
catch (Exception ex) {
return defValue;
}
}
else {
return defValue;
}
}
public BigDecimal getBigDecimal(String key) {
return getBigDecimal(key, BigDecimal.ZERO);
}
public BigDecimal getBigDecimal(String key, BigDecimal defValue) {
Object obj = map.get(key);
if (obj == null) {
return defValue;
}
else if (obj instanceof Double) {
return BigDecimal.valueOf((Double) obj);
}
else if (obj instanceof Long) {
return BigDecimal.valueOf((Long) obj);
}
else if (obj instanceof Number) {
return BigDecimal.valueOf(((Number) obj).doubleValue());
}
else if (obj instanceof String) {
try {
return new BigDecimal((String) obj);
}
catch (Exception ex) {
return defValue;
}
}
else {
return defValue;
}
}
public <T> T getValue(String key, Function<Object, T> function) {
return function.apply(map.getOrDefault(key, null));
}
public <T> List<T> getListValue(String key, Function<Object, T> function) {
Function<Object, ResInfo<T>> function2 = (obj) -> new ResInfo<>(true, function.apply(obj));
return getCollectionValueAllowJudgment(key, function2, () -> new ArrayList<>(0));
}
/**
* Collection(List;Set)
*
* @param key
* @param function
* @param initializeCollection Collection
* @return java.util.Collection<T>
* @author LiuHuiYu
* Created DateTime 2021-08-06 9:50
*/
public <T, R extends Collection<T>> R getCollectionValue(String key, Function<Object, T> function, Supplier<R> initializeCollection) {
Function<Object, ResInfo<T>> function2 = (obj) -> new ResInfo<>(true, function.apply(obj));
return getCollectionValueAllowJudgment(key, function2, initializeCollection);
}
/**
* Collection(List;Set)
*
* @param key
* @param function
* @param initializeCollection Collection
* @return java.util.Collection<T>
* @author LiuHuiYu
* Created DateTime 2021-08-06 9:50
*/
public <T, R extends Collection<T>> R getCollectionValueAllowJudgment(String key, Function<Object, ResInfo<T>> function, Supplier<R> initializeCollection) {
R resList = initializeCollection.get();
if (this.map.containsKey(key)) {
Object obj = this.map.get(key);
if (obj instanceof Collection<?>) {
Collection<?> list = (Collection<?>) obj;
list.forEach(item -> {
ResInfo<T> resInfo = function.apply(item);
if (resInfo.res) {
resList.add(resInfo.resData);
}
});
return resList;
}
else if (this.throwException) {
throw new RuntimeException("无法解析非List数据");
}
else {
return resList;
}
}
else if (this.throwException) {
throw new RuntimeException("不存在的键值。");
}
else {
return resList;
}
}
public Map<String, Object> getMap(String key) {
return getMap(key, new HashMap<>(0));
}
public Map<String, Object> getMap(String key, Map<String, Object> defValue) {
Object obj = map.get(key);
if (obj == null) {
return defValue;
}
else {
try {
return mapObjectToStringKeyMap(obj);
}
catch (Exception ignored) {
return defValue;
}
}
}
public <T> PageImpl<T> getPageImpl(String key, MapToT<T> mapToT) {
PageImpl<T> def = new PageImpl<>(new ArrayList<>(0));
return getPageImpl(key, mapToT, def);
}
public <T> PageImpl<T> getPageImpl(String key, MapToT<T> mapToT, PageImpl<T> defValue) {
Object obj = map.get(key);
if (obj == null) {
return defValue;
}
else {
try {
Map<String, Object> map = mapObjectToStringKeyMap(obj);
return mapToPageImpl(map, mapToT);
}
catch (Exception ignored) {
return defValue;
}
}
}
/**
* ResultMap
*
* @param map map
* @param mapToT
* @param <T>
* @return org.springframework.data.domain.PageImpl<T>
* @author LiuHuiYu
* Created DateTime 2021-11-29 17:18
*/
public static <T> @NotNull PageImpl<T> mapToPageImpl(Map<String, Object> map, MapToT<T> mapToT) {
MapUtil mapUtil = new MapUtil(map);
int number = mapUtil.getIntegerValue("number", 0);
int size = mapUtil.getIntegerValue("size", 0);
PageRequest pageable = PageRequest.of(number, size);
long totalElements = mapUtil.getLongValue("totalElements", 0L);
List<T> list = mapUtil.getListValue("content", obj -> mapToT.mapToT(MapUtil.mapObjectToStringKeyMap(obj)));
return new PageImpl<>(list, pageable, totalElements);
}
public static class ResInfo<T> {
Boolean res;
T resData;
public ResInfo(Boolean res, T resData) {
this.res = res;
this.resData = resData;
}
}
public static <T> T cloneObj(T a, Class<T> classOfT) {
String json = new Gson().toJson(a);
return new Gson().fromJson(json, classOfT);
}
}

@ -0,0 +1,16 @@
package com.rehome.jpahefengweather.utils;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2021-03-23 16:48
*/
@FunctionalInterface
public interface ObjectToT<T> {
/**
* Object T
* @param o Object
* @return T
*/
T objectToT(Object o);
}

@ -1,5 +1,13 @@
package com.rehome.jpahefengweather.utils;
import okhttp3.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@ -7,28 +15,22 @@ import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import com.liuhuiyu.spring_util.SpringUtil;
import okhttp3.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
/**
* Created by qhong on 2018/7/3 16:52
**/
@Configuration
public class OkHttpConfig {
private static OkHttpConfig okHttpConfig=null;
public static OkHttpConfig getInstance() {
return SpringUtil.getBean(OkHttpConfig.class);
if(okHttpConfig==null){
okHttpConfig = new OkHttpConfig();
}
return okHttpConfig;
}
public OkHttpConfig() {}
public OkHttpClient okHttpClient;
private OkHttpClient okHttpClient=null;
public OkHttpClient getOkHttpClient(){
if(okHttpClient==null){
okHttpClient=OkHttpConfig.getInstance().okHttpClient();
@ -37,7 +39,7 @@ public class OkHttpConfig {
}
@Bean
//@Bean
public X509TrustManager x509TrustManager() {
return new X509TrustManager() {
@Override
@ -52,7 +54,7 @@ public class OkHttpConfig {
}
};
}
@Bean
//@Bean
public SSLSocketFactory sslSocketFactory() {
try {
//信任任何链接
@ -70,11 +72,11 @@ public class OkHttpConfig {
* Create a new connection pool with tuning parameters appropriate for a single-user application.
* The tuning parameters in this pool are subject to change in future OkHttp releases. Currently
*/
@Bean
//@Bean
public ConnectionPool pool() {
return new ConnectionPool(200, 5, TimeUnit.MINUTES);
}
@Bean
//@Bean
public OkHttpClient okHttpClient() {
return new OkHttpClient.Builder()
.addNetworkInterceptor(new TokenHeaderInterceptor())
@ -92,8 +94,6 @@ public class OkHttpConfig {
Request originalRequest = chain.request();
String token = JwtUtils.getJwt();
if(token!=null){
System.out.println("token:");
System.out.println(token);
String credential = "Bearer " + token;
Request updateRequest = originalRequest.newBuilder().header("Authorization", credential).build();
return chain.proceed(updateRequest);

@ -1,12 +1,8 @@
package com.rehome.jpahefengweather.utils;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;
import com.liuhuiyu.spring_util.SpringUtil;
import okhttp3.*;
import org.springframework.lang.NonNull;
/**
* Created by qhong on 2018/7/3 16:55

@ -0,0 +1,277 @@
package com.rehome.jpahefengweather.utils;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2020-07-08 11:44
*/
public class Result<T> implements Serializable {
public static final int OK = 0;
public static final int ERROR = -1;
/**
*
*/
private Integer flag;
/**
*
*/
private String msg;
/**
*
*/
private T data;
public Result() {
this.flag = OK;
this.msg = "操作成功";
this.data = null;
}
private Result(T data) {
this();
this.data = data;
}
private Result(T data, Integer flag) {
this();
this.data = data;
this.flag = flag;
}
private Result(T data, Integer flag, String msg) {
this();
this.data = data;
this.flag = flag;
this.msg = msg;
}
public Integer getFlag() {
return flag;
}
public void setFlag(Integer flag) {
this.flag = flag;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
public boolean isSuccess() {
return this.flag.equals(OK);
}
/**
*
*/
@Contract(value = "_ -> new", pure = true)
public static <T> @NotNull Result<T> of(T data) {
return new Result<>(data);
}
@Contract(value = "_, _ -> new", pure = true)
public static <T> @NotNull Result<T> of(T data, Integer flag) {
return new Result<>(data, flag);
}
@Contract(value = "_, _, _ -> new", pure = true)
public static <T> @NotNull Result<T> of(T data, Integer flag, String msg) {
return new Result<>(data, flag, msg);
}
@Contract(value = "_ -> new", pure = true)
public static <T> @NotNull Result<T> error(String msg) {
return new Result<>(null, ERROR, msg);
}
@Contract(value = "_, _-> new", pure = true)
public static <T> @NotNull Result<T> error(String msg, int errorCode) {
return new Result<>(null, errorCode, msg);
}
@Contract(value = " -> new", pure = true)
public static <T> @NotNull Result<T> success() {
return new Result<>(null, OK, "");
}
private static final String FLAG_KEY = "flag";
private static final String MSG_KEY = "msg";
private static final String DATA_KEY = "data";
@Deprecated
public static <T> @NotNull Result<T> ofMap(Map<String, Object> map, Class<T> clazz) {
Result<T> result = new Result<>();
if (map.containsKey(FLAG_KEY)) {
result.flag = ((Number) map.get(FLAG_KEY)).intValue();
}
else {
throw new RuntimeException("缺少关键字" + FLAG_KEY);
}
if (map.containsKey(MSG_KEY)) {
result.msg = map.get(MSG_KEY).toString();
}
else {
throw new RuntimeException("缺少关键字" + MSG_KEY);
}
if (map.containsKey(DATA_KEY)) {
if (clazz.isInstance(map.get(DATA_KEY))) {
result.data = clazz.cast(map.get(DATA_KEY));
}
else {
throw new RuntimeException("Map 关键字‘" + DATA_KEY + "’无法转换为当前类型。");
}
}
else {
throw new RuntimeException("缺少关键字" + DATA_KEY);
}
return result;
}
/**
* ResultMap
*
* @param map
* @return java.lang.Object
* @author LiuHuiYu
* Created DateTime 2021-11-25 17:11
*/
public static Object getResultObj(Map<String, Object> map) {
return getValueOfResultMap(map, o -> o);
}
/**
* ResultMap
*
* @param map
* @param mapToT
* @param <T>
* @return java.util.List<T> null
* @author LiuHuiYu
* Created DateTime 2021-11-25 17:05
*/
public static <T> List<T> getResultToList(Map<String, Object> map, MapToT<T> mapToT) {
LhyAssert.assertNotNull(mapToT, new ResultException("不能传入null解析方法mapToT。"));
LhyAssert.assertNotNull(map, new ResultException("传入null值,无法进行解析map。"));
ArrayList<?> arrayList = getValueOfResultMap(map, o -> {
LhyAssert.assertTrue(o instanceof ArrayList, new ResultException("对象无法解析成列表"));
return (ArrayList<?>) o;
});
List<T> list = new ArrayList<>(arrayList.size());
for (Object obj : arrayList) {
Map<String, Object> itemMap = MapUtil.mapObjectToStringKeyMap(obj);
final T t = mapToT.mapToT(itemMap);
if (t != null) {
list.add(t);
}
}
return list;
}
/**
* ResultMap
*
* @param map
* @param mapToT
* @param <T>
* @return T
* @author LiuHuiYu
* Created DateTime 2021-11-25 17:10
*/
public static <T> T getResultData(Map<String, Object> map, MapToT<T> mapToT) {
LhyAssert.assertNotNull(mapToT, new ResultException("不能传入null解析方法mapToT。"));
Object obj = getValueOfResultMap(map, o -> o);
Map<String, Object> itemMap = MapUtil.mapObjectToStringKeyMap(obj);
return mapToT.mapToT(itemMap);
}
/**
* mapResult
*
* @param map Resultmap
* @return Result<java.lang.Object> Result
* @author LiuHuiYu
* Created DateTime 2021-11-25 17:08
*/
public static Result<Object> getResult(Map<String, Object> map) {
LhyAssert.assertNotNull(map, new ResultException("传入null值,无法进行解析map。"));
Result<Object> result = new Result<>();
LhyAssert.assertTrue(map.containsKey(FLAG_KEY), new ResultException("flag信息有效判定字段不存在。"));
result.setFlag((int) map.get(FLAG_KEY));
if (map.containsKey(MSG_KEY)) {
result.setMsg((String)map.get(MSG_KEY));
}
if (map.containsKey(DATA_KEY)) {
result.setData(map.get(DATA_KEY));
}
return result;
}
/**
* ResultMap
*
* @param map Result Map
* @param objectToT
* @param <T>
* @return T
* @author LiuHuiYu
* Created DateTime 2021-11-25 16:52
*/
public static <T> T getValueOfResultMap(Map<String, Object> map, ObjectToT<T> objectToT) {
LhyAssert.assertNotNull(objectToT, new ResultException("不能传入null解析方法mapToT。"));
LhyAssert.assertNotNull(map, new ResultException("传入null值,无法进行解析map。"));
Result<Object> result = getResult(map);
LhyAssert.assertTrue(result.isSuccess(), result.getMsg());
return objectToT.objectToT(result.getData());
}
/**
* ResultMap
*
* @param map map
* @param mapToT
* @param <T>
* @return org.springframework.data.domain.PageImpl<T>
* @author LiuHuiYu
* Created DateTime 2021-11-29 17:18
*/
@Contract("_, _ -> new")
public static <T> @NotNull PageImpl<T> getResultToPageImpl(Map<String, Object> map, MapToT<T> mapToT) {
LhyAssert.assertNotNull(mapToT, new ResultException("不能传入null解析方法mapToT。"));
Result<Object> result = getResult(map);
if (result.isSuccess()) {
MapUtil mapUtil = new MapUtil(MapUtil.mapObjectToStringKeyMap(result.getData()));
int number = mapUtil.getIntegerValue("number", 0);
int size = mapUtil.getIntegerValue("size", 0);
PageRequest pageable = PageRequest.of(number, size);
long totalElements = mapUtil.getLongValue("totalElements", 0L);
List<T> list = mapUtil.getListValue("content", obj -> mapToT.mapToT(MapUtil.mapObjectToStringKeyMap(obj)));
return new PageImpl<>(list, pageable, totalElements);
}
else {
throw new RuntimeException(result.getMsg());
}
}
}

@ -0,0 +1,33 @@
package com.rehome.jpahefengweather.utils;
/**
*
*
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2020-07-08 11:45
*/
public enum ResultEnum {
/**
*
*/
SUCCESS(0, "成功"),
CUSTOM_ERROR(-1,"自定义错误"),
;
private Integer code;
private String message;
ResultEnum(Integer code, String message) {
this.code = code;
this.message = message;
}
public Integer getCode() {
return code;
}
public String getMessage() {
return message;
}
}

@ -0,0 +1,14 @@
package com.rehome.jpahefengweather.utils;
/**
* Result
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2021-12-10 16:25
*/
public class ResultException extends LhyException{
public ResultException(String message) {
super(message);
}
}

@ -0,0 +1,101 @@
package com.rehome.jpahefengweather.utils;
import java.util.concurrent.Callable;
/**
*
*
* @author LiuHuiYu
* @version v1.0.0.0
* Created DateTime 2021-07-05 15:44
*/
public class RetryUtil {
/**
*
*
* @param num
* @param callFunctions
* @author LiuHuiYu
* Created DateTime 2021-07-05 16:58
*/
public static <R> R retry(int num, Callable<R> callFunctions) {
return retry(num, false, callFunctions);
}
/**
*
*
* @param num ()
* @param callFunctions
* @param failedCall
* @author LiuHuiYu
* Created DateTime 2021-07-05 16:58
*/
public static <R> R retry(int num, Callable<R> callFunctions, Runnable failedCall) {
return retry(num, true, callFunctions, failedCall);
}
/**
*
*
* @param callFunctions
* @param failedCall
* @author LiuHuiYu
* Created DateTime 2021-07-05 16:58
*/
public static <R> R retry(Callable<R> callFunctions, Runnable failedCall) {
return retry(2, true, callFunctions, failedCall);
}
/**
*
*
* @param num
* @param callFunctions [0]>0 1 1
* @author LiuHuiYu
* Created DateTime 2021-07-05 17:13
*/
public static <R> R retry(int num, Callable<R> callable, Runnable... callFunctions) {
return retry(num, true, callable, callFunctions);
}
/**
*
*
* @param num
* @param loop
* @param callable
* @param callFunctions [0]>0 1 1
* @author LiuHuiYu
* Created DateTime 2021-07-05 17:13
*/
public static <R> R retry(int num, boolean loop, Callable<R> callable, Runnable... callFunctions) {
int pointer = -1;
try {
for (int i = 0; i < num - 1; i++) {
try {
return callable.call();
}
catch (Exception e) {
if (pointer >= callFunctions.length - 1) {
if (loop) {
pointer = 0;
}
else {
continue;
}
}
else {
pointer++;
}
callFunctions[pointer].run();
}
}
return callable.call();
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}

@ -0,0 +1,240 @@
package org.hibernate.cfg;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.Any;
import org.hibernate.annotations.ManyToAny;
import org.hibernate.annotations.Target;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.common.reflection.XClass;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.boot.MappingException;
import org.hibernate.boot.jaxb.Origin;
import org.hibernate.boot.jaxb.SourceType;
import org.hibernate.cfg.annotations.HCANNHelper;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.jboss.logging.Logger;
import javax.persistence.*;
import java.util.*;
/**
* SpringDataJpa
* */
class PropertyContainer {
private static final CoreMessageLogger LOG = (CoreMessageLogger)Logger.getMessageLogger(CoreMessageLogger.class, PropertyContainer.class.getName());
private final XClass xClass;
private final XClass entityAtStake;
private final AccessType classLevelAccessType;
private final List<XProperty> persistentAttributes;
PropertyContainer(XClass clazz, XClass entityAtStake, AccessType defaultClassLevelAccessType) {
this.xClass = clazz;
this.entityAtStake = entityAtStake;
if (defaultClassLevelAccessType == AccessType.DEFAULT) {
defaultClassLevelAccessType = AccessType.PROPERTY;
}
AccessType localClassLevelAccessType = this.determineLocalClassDefinedAccessStrategy();
assert localClassLevelAccessType != null;
this.classLevelAccessType = localClassLevelAccessType != AccessType.DEFAULT ? localClassLevelAccessType : defaultClassLevelAccessType;
assert this.classLevelAccessType == AccessType.FIELD || this.classLevelAccessType == AccessType.PROPERTY;
List<XProperty> fields = this.xClass.getDeclaredProperties(AccessType.FIELD.getType());
List<XProperty> getters = this.xClass.getDeclaredProperties(AccessType.PROPERTY.getType());
this.preFilter(fields, getters);
Map<String, XProperty> persistentAttributesFromGetters = new HashMap();
LinkedHashMap<String, XProperty> localAttributeMap = new LinkedHashMap();
collectPersistentAttributesUsingLocalAccessType(this.xClass, localAttributeMap, persistentAttributesFromGetters, fields, getters);
collectPersistentAttributesUsingClassLevelAccessType(this.xClass, this.classLevelAccessType, localAttributeMap, persistentAttributesFromGetters, fields, getters);
this.persistentAttributes = verifyAndInitializePersistentAttributes(this.xClass, localAttributeMap);
}
private void preFilter(List<XProperty> fields, List<XProperty> getters) {
Iterator propertyIterator = fields.iterator();
XProperty property;
while(propertyIterator.hasNext()) {
property = (XProperty)propertyIterator.next();
if (mustBeSkipped(property)) {
propertyIterator.remove();
}
}
propertyIterator = getters.iterator();
while(propertyIterator.hasNext()) {
property = (XProperty)propertyIterator.next();
if (mustBeSkipped(property)) {
propertyIterator.remove();
}
}
}
private static void collectPersistentAttributesUsingLocalAccessType(XClass xClass, LinkedHashMap<String, XProperty> persistentAttributeMap, Map<String, XProperty> persistentAttributesFromGetters, List<XProperty> fields, List<XProperty> getters) {
Iterator propertyIterator = fields.iterator();
XProperty xProperty;
Access localAccessAnnotation;
while(propertyIterator.hasNext()) {
xProperty = (XProperty)propertyIterator.next();
localAccessAnnotation = (Access)xProperty.getAnnotation(Access.class);
if (localAccessAnnotation != null && localAccessAnnotation.value() == javax.persistence.AccessType.FIELD) {
propertyIterator.remove();
persistentAttributeMap.put(xProperty.getName(), xProperty);
}
}
propertyIterator = getters.iterator();
while(propertyIterator.hasNext()) {
xProperty = (XProperty)propertyIterator.next();
localAccessAnnotation = (Access)xProperty.getAnnotation(Access.class);
if (localAccessAnnotation != null && localAccessAnnotation.value() == javax.persistence.AccessType.PROPERTY) {
propertyIterator.remove();
String name = xProperty.getName();
XProperty previous = (XProperty)persistentAttributesFromGetters.get(name);
if (previous != null) {
throw new MappingException(LOG.ambiguousPropertyMethods(xClass.getName(), HCANNHelper.annotatedElementSignature(previous), HCANNHelper.annotatedElementSignature(xProperty)), new Origin(SourceType.ANNOTATION, xClass.getName()));
}
persistentAttributeMap.put(name, xProperty);
persistentAttributesFromGetters.put(name, xProperty);
}
}
}
private static void collectPersistentAttributesUsingClassLevelAccessType(XClass xClass, AccessType classLevelAccessType, LinkedHashMap<String, XProperty> persistentAttributeMap, Map<String, XProperty> persistentAttributesFromGetters, List<XProperty> fields, List<XProperty> getters) {
Iterator var6;
XProperty getter;
if (classLevelAccessType == AccessType.FIELD) {
var6 = fields.iterator();
while(var6.hasNext()) {
getter = (XProperty)var6.next();
if (!persistentAttributeMap.containsKey(getter.getName())) {
persistentAttributeMap.put(getter.getName(), getter);
}
}
} else {
var6 = getters.iterator();
while(var6.hasNext()) {
getter = (XProperty)var6.next();
String name = getter.getName();
XProperty previous = (XProperty)persistentAttributesFromGetters.get(name);
if (previous != null) {
throw new MappingException(LOG.ambiguousPropertyMethods(xClass.getName(), HCANNHelper.annotatedElementSignature(previous), HCANNHelper.annotatedElementSignature(getter)), new Origin(SourceType.ANNOTATION, xClass.getName()));
}
if (!persistentAttributeMap.containsKey(name)) {
persistentAttributeMap.put(getter.getName(), getter);
persistentAttributesFromGetters.put(name, getter);
}
}
}
}
public XClass getEntityAtStake() {
return this.entityAtStake;
}
public XClass getDeclaringClass() {
return this.xClass;
}
public AccessType getClassLevelAccessType() {
return this.classLevelAccessType;
}
/** @deprecated */
@Deprecated
public Collection<XProperty> getProperties() {
return Collections.unmodifiableCollection(this.persistentAttributes);
}
public Iterable<XProperty> propertyIterator() {
return this.persistentAttributes;
}
private static List<XProperty> verifyAndInitializePersistentAttributes(XClass xClass, Map<String, XProperty> localAttributeMap) {
ArrayList<XProperty> output = new ArrayList(localAttributeMap.size());
Iterator var3 = localAttributeMap.values().iterator();
while(var3.hasNext()) {
XProperty xProperty = (XProperty)var3.next();
if (!xProperty.isTypeResolved() && !discoverTypeWithoutReflection(xProperty)) {
String msg = "Property " + StringHelper.qualify(xClass.getName(), xProperty.getName()) + " has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type";
throw new AnnotationException(msg);
}
output.add(xProperty);
}
return CollectionHelper.toSmallList(output);
}
private AccessType determineLocalClassDefinedAccessStrategy() {
AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
AccessType jpaDefinedAccessType = AccessType.DEFAULT;
org.hibernate.annotations.AccessType accessType = (org.hibernate.annotations.AccessType)this.xClass.getAnnotation(org.hibernate.annotations.AccessType.class);
if (accessType != null) {
hibernateDefinedAccessType = AccessType.getAccessStrategy(accessType.value());
}
Access access = (Access)this.xClass.getAnnotation(Access.class);
if (access != null) {
jpaDefinedAccessType = AccessType.getAccessStrategy(access.value());
}
if (hibernateDefinedAccessType != AccessType.DEFAULT && jpaDefinedAccessType != AccessType.DEFAULT && hibernateDefinedAccessType != jpaDefinedAccessType) {
throw new org.hibernate.MappingException("@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. ");
} else {
AccessType classDefinedAccessType;
if (hibernateDefinedAccessType != AccessType.DEFAULT) {
classDefinedAccessType = hibernateDefinedAccessType;
} else {
classDefinedAccessType = jpaDefinedAccessType;
}
return classDefinedAccessType;
}
}
private static boolean discoverTypeWithoutReflection(XProperty p) {
if (p.isAnnotationPresent(OneToOne.class) && !((OneToOne)p.getAnnotation(OneToOne.class)).targetEntity().equals(Void.TYPE)) {
return true;
} else if (p.isAnnotationPresent(OneToMany.class) && !((OneToMany)p.getAnnotation(OneToMany.class)).targetEntity().equals(Void.TYPE)) {
return true;
} else if (p.isAnnotationPresent(ManyToOne.class) && !((ManyToOne)p.getAnnotation(ManyToOne.class)).targetEntity().equals(Void.TYPE)) {
return true;
} else if (p.isAnnotationPresent(ManyToMany.class) && !((ManyToMany)p.getAnnotation(ManyToMany.class)).targetEntity().equals(Void.TYPE)) {
return true;
} else if (p.isAnnotationPresent(Any.class)) {
return true;
} else if (p.isAnnotationPresent(ManyToAny.class)) {
if (!p.isCollection() && !p.isArray()) {
throw new AnnotationException("@ManyToAny used on a non collection non array property: " + p.getName());
} else {
return true;
}
} else if (p.isAnnotationPresent(Type.class)) {
return true;
} else {
return p.isAnnotationPresent(Target.class);
}
}
private static boolean mustBeSkipped(XProperty property) {
return property.isAnnotationPresent(Transient.class) || "net.sf.cglib.transform.impl.InterceptFieldCallback".equals(property.getType().getName()) || "org.hibernate.bytecode.internal.javassist.FieldHandler".equals(property.getType().getName());
}
}

@ -1,6 +1,6 @@
#1.项目启动的端口
server:
port: 48080
port: 8604
spring:
datasource:
@ -73,4 +73,4 @@ spring:
hibernate:
ddl-auto: update # 第一次建表create 后面用update要不然每次重启都会新建表
rehome:
resources-path: /Users/edao/storage # 外部资源文件存储路径 格式:/Users/edao/storage
resources-path: /Users/admin/storage # 外部资源文件存储路径 格式:/Users/edao/storage

@ -1,65 +0,0 @@
package com.rehome.jpahefengweather.controller;
import com.liuhuiyu.test.BaseServiceTest;
import com.liuhuiyu.util.model.Result;
import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.utils.TimestampUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @author HuangWenFei
* @version v1.0.0.0
* Created DateTime 2022-05-01 15:45
*/
public class WeatherControllerTest extends BaseServiceTest {
private static final Logger LOG= LogManager.getLogger(WeatherControllerTest.class);
private CityService cityService;
private WeatherController weatherController;
@Autowired
public void setCityService(CityService cityService) {
this.cityService = cityService;
}
@Autowired
public void setWeatherController(WeatherController weatherController) {
this.weatherController = weatherController;
}
@Test
public void findAllCitys() {
try {
SimpleDateFormat sdFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
String now = sdFormat.format(new Date());
Timestamp beginTime = TimestampUtil.beginTime(now);
Calendar calendar=Calendar.getInstance();
calendar.add(Calendar.DATE,10);
Date date=sdFormat.parse(sdFormat.format(calendar.getTime()));
Calendar calendarOne=Calendar.getInstance();
calendarOne.setTime(date);
String end = sdFormat.format(calendarOne.getTime());
Timestamp endTime = TimestampUtil.beginTime(end);
Result<List<HefengCity>> result = this.weatherController.getCityList();
List<HefengCity> citys = result.getData();
//LOG.info("{}",new Gson().toJson(citys));
System.out.println(citys.size());
}catch (Exception e){
e.printStackTrace();
}
}
}
Loading…
Cancel
Save