diff --git a/jpahefengweather/pom.xml b/jpahefengweather/pom.xml index 1824715..385a3e2 100644 --- a/jpahefengweather/pom.xml +++ b/jpahefengweather/pom.xml @@ -49,18 +49,6 @@ 1.18.20 true - - - org.apache.logging.log4j - log4j-api - 2.17.1 - - - - org.apache.logging.log4j - log4j-core - 2.17.1 - org.apache.poi @@ -92,36 +80,6 @@ annotations 19.0.0 - - com.liuhuiyu - util - 2022.1.0 - - - com.liuhuiyu - spring-util - 2021.1.0 - - - com.liuhuiyu - web - 2022.1.0 - - - com.liuhuiyu - jpa - 2021.1.0 - - - com.liuhuiyu - okhttp3util - 2021.2.2 - - - com.liuhuiyu - test - 2021.1.0 - javax.validation validation-api @@ -155,21 +113,31 @@ eddsa 0.3.0 - - - - - - - - - - - - - + + commons-beanutils + commons-beanutils + 1.9.4 + + + commons-collections + commons-collections + + + - + + + + repository + http://47.242.184.139:8081/repository/maven-public/ + + true + + + true + + + ${project.artifactId} @@ -179,5 +147,4 @@ - \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/JpahefengweatherApplication.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/JpahefengweatherApplication.java index 3e368b3..7e68684 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/JpahefengweatherApplication.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/JpahefengweatherApplication.java @@ -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; + } } \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WeatherController.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/HefengWeatherController.java similarity index 52% rename from jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WeatherController.java rename to jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/HefengWeatherController.java index 05bc63a..de2f281 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WeatherController.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/HefengWeatherController.java @@ -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> getNowWeatherEntity(@Validated @RequestBody BaseWeatherFindDto dto){ - List weathers = this.weatherService.findNowWeatherByLocationIdAndDate(dto.getLocationId(),dto.getWeatherDate()); + List 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> getNowWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){ - List weathers = this.weatherService.findHistoryWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate()); + List 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 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> getForecastWeatherDto(@Validated @RequestBody BaseWeatherFindDto dto){ - List weathers = this.weatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),dto.getWeatherDate()); + List 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 +} \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/TyphoonController.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WztfwStormController.java similarity index 55% rename from jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/TyphoonController.java rename to jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WztfwStormController.java index db7c689..13a35ba 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/TyphoonController.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/WztfwStormController.java @@ -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> 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 getTyphoonInfoByTfid(@Validated @RequestBody TyphoonTfidDto dto){ - return Result.of(this.zjsltStormService.findTyphoonInfoByTfid(dto.getTfid())); - } //endregion //region 根据年份获取台风列表 @PostMapping("/getWztfStormListByYear") diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/ZjsltStormController.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/ZjsltStormController.java new file mode 100644 index 0000000..0c29ba0 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/controller/ZjsltStormController.java @@ -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 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 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); + } +} \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/BaseDataCenterView.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/BaseDataCenterView.java deleted file mode 100644 index a07b445..0000000 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/BaseDataCenterView.java +++ /dev/null @@ -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 分页查询的条件 - * @return java.lang.Long - * @author LiuHuiYu - * Created DateTime 2022-02-21 16:24 - */ - protected Long count(T t, String sql, String baseWhere, FullWhere fullWhere) { - StringBuilder sqlBuilder = new StringBuilder(sql); - sqlBuilder.append(baseWhere); - Map 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 返回分页的数据类型 - * @param 分页查询的条件 - * @return java.util.List - */ - protected List pageList(DaoOperator b, T t, String sql, String baseWhere, String order, FullWhere fullWhere) { - StringBuilder sqlBuilder = new StringBuilder(sql); - sqlBuilder.append(baseWhere); - Map 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 PageImpl page(DaoOperator b, T t, String sql, FullWhere 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 返回分页的数据类型 - * @param 分页查询的条件 - * @return java.util.List - */ - protected List list(DaoOperator b, T t, String sql, String baseWhere, String order, FullWhere fullWhere) { - StringBuilder sqlBuilder = new StringBuilder(sql); - sqlBuilder.append(baseWhere); - Map 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 parameterMap) 实现 - * @param 返回分页的数据类型 - * @param 分页查询的条件 - * @return org.springframework.data.domain.PageImpl - * @author LiuHuiYu - * Created DateTime 2022-04-09 11:41 - */ - protected PageImpl page(DaoOperator b, T t, String sql, String baseWhere, String order, FullWhere fullWhere) { - Long total = this.count(t, sql, baseWhere, fullWhere); - final List 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); - } - -} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/FullWhere.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/FullWhere.java deleted file mode 100644 index f61ed4c..0000000 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/FullWhere.java +++ /dev/null @@ -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 { - /** - * 功能描述 - * - * @param find 查询条件 - * @param sqlBuilder sql - * @param parameterMap 参数列表 - * @author LiuHuiYu - * Created DateTime 2022-02-21 16:19 - */ - void fullWhere(T find, StringBuilder sqlBuilder, Map parameterMap); -} \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/NowWeatherRepository.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/NowWeatherRepository.java index 061f3b4..e3dc972 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/NowWeatherRepository.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/NowWeatherRepository.java @@ -16,11 +16,9 @@ import java.util.List; public interface NowWeatherRepository extends JpaRepository { //方法名称必须要遵循驼峰式命名规则,findBy(关键字)+属性名称(首字母大写)+查询条件(首字母大写) //List 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 findByLocationIdAndWeatherDate(String locationId, String weatherDate); List 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 findByLocationIdAndWeatherDateOrderByIdAsc(String locationId, String weatherDate); NowWeather findFirstByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate); NowWeather findTopByLocationIdAndWeatherDateOrderByIdDesc(String locationId, String weatherDate); + //NowWeather findByLocationIdO(String locationId, String weatherDate); } diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/ZjsltStormRepository.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/ZjsltStormRepository.java index e10f215..e89e63d 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/ZjsltStormRepository.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dao/ZjsltStormRepository.java @@ -20,4 +20,6 @@ public interface ZjsltStormRepository extends JpaRepository { ZjsltStorm findByTfid(String tfid); List findByYear(String year); + + List findByYearAndIsactiveOrderByCreateDateDesc(String year,String isactive); } diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseDto.java index aefaa4a..71f31e5 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseFindDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseFindDto.java index 72762cb..bd0c459 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseFindDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseFindDto.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseWeatherFindDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseWeatherFindDto.java index cbdbe71..7515c57 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseWeatherFindDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/BaseWeatherFindDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastDto.java index a860b3d..c41badc 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastDto.java @@ -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("预报日期") diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastWeatherDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastWeatherDto.java index cf904df..e78406e 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastWeatherDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/ForecastWeatherDto.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/HefengWeatherResultDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/HefengWeatherResultDto.java new file mode 100644 index 0000000..ead0147 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/HefengWeatherResultDto.java @@ -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 daily; +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcBaseDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcBaseDto.java index bbfd4bd..42d82b2 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcBaseDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcBaseDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcForecastWeatherDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcForecastWeatherDto.java index 9cc82af..9132363 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcForecastWeatherDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcForecastWeatherDto.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcNowWeatherDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcNowWeatherDto.java index f4023b7..b3ae7de 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcNowWeatherDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NmcNowWeatherDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowDto.java index 380cb01..904c162 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowWeatherDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowWeatherDto.java index b2b7b63..9d3c9df 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowWeatherDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/NowWeatherDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/StormDataDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/StormDataDto.java index 252ce65..a03eea1 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/StormDataDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/StormDataDto.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyhoonActivityDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyhoonActivityDto.java index 621caa9..0be475b 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyhoonActivityDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyhoonActivityDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonBaseDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonBaseDto.java index 94e489d..2851f8c 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonBaseDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonBaseDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonTfidDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonTfidDto.java index 6e7d1ac..80a6a46 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonTfidDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/TyphoonTfidDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/WztfStormInfoDto.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/WztfStormInfoDto.java index 7476170..a2834a6 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/WztfStormInfoDto.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/dto/WztfStormInfoDto.java @@ -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; /** diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ForecastWeather.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ForecastWeather.java index 3a90b91..082dd8d 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ForecastWeather.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ForecastWeather.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengFutureWeather.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengFutureWeather.java index 93c8bf0..9c63aff 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengFutureWeather.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengFutureWeather.java @@ -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")}) diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengRealtimeWeather.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengRealtimeWeather.java index 99cb4b0..fb8df04 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengRealtimeWeather.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/HefengRealtimeWeather.java @@ -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")}) diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcCity.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcCity.java index 319a110..58cce05 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcCity.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcCity.java @@ -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{ diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcNowWeather.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcNowWeather.java index 949538c..ed4beb8 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcNowWeather.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcNowWeather.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcProvince.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcProvince.java index 72dd131..5db4f73 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcProvince.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcProvince.java @@ -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{ diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcStorm.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcStorm.java index 3e2001e..6636c47 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcStorm.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NmcStorm.java @@ -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 { diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NowWeather.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NowWeather.java index f066c1b..808b5a0 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NowWeather.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/NowWeather.java @@ -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; diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/TyphoonInfo.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/TyphoonInfo.java index f5f0dfb..531af0c 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/TyphoonInfo.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/TyphoonInfo.java @@ -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) diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStorm.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStorm.java index ae69008..22ea832 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStorm.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStorm.java @@ -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 { diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStormInfo.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStormInfo.java index d24c3b0..56a0651 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStormInfo.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/WztfStormInfo.java @@ -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) diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ZjsltStorm.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ZjsltStorm.java index f389b45..159ed23 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ZjsltStorm.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/entity/ZjsltStorm.java @@ -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 { diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/WeatherService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/HefengWeatherService.java similarity index 84% rename from jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/WeatherService.java rename to jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/HefengWeatherService.java index 9cc0c01..6aa2965 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/WeatherService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/HefengWeatherService.java @@ -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 */ List findForecastWeatherByLocationIdAndDateDto(String locationId, String date); + /** + * 和风天气,根据位置id和日期查询实时天气和天气预报后,整合数据到一个dto提供给api调用 + * @return List + */ + HefengWeatherResultDto getHefengWeatherResultDtoByLocationIdAndDateDto(String locationId, String date); } diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/WeatherServiceImpl.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/HefengWeatherServiceImpl.java similarity index 85% rename from jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/WeatherServiceImpl.java rename to jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/HefengWeatherServiceImpl.java index 3650e23..09407e1 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/WeatherServiceImpl.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/HefengWeatherServiceImpl.java @@ -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 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 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 findForecastWeatherByLocationIdAndDateDto(String locationId, String date) { - List weathers = this.findForecastWeatherByLocationIdAndDate(locationId,date); + List weathers = this.findForecastWeatherByLocationIdAndDateOrderByCreateDateDesc(locationId,date); if(weathers!=null&&weathers.size()>0){ List 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 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; + } +} \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/ZjsltStormServiceImpl.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/ZjsltStormServiceImpl.java index 6574b70..999bd62 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/ZjsltStormServiceImpl.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/Impl/ZjsltStormServiceImpl.java @@ -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 getTyhoonActivity() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy"); + List 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); diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledHefengWeatherService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledHefengWeatherService.java index d9dacdb..71c43f8 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledHefengWeatherService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledHefengWeatherService.java @@ -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 * * * * *")//每天0,8,16点各执行一次,一天总共执行三次 + //@Scheduled(cron = "0 15 * * * *")//每天0,8,16点各执行一次,一天总共执行三次 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 forecastWeatherDtoList=this.hefengWeatherService.findForecastWeatherByLocationIdAndDateDto(dto.getLocationId(),currentDate); + log.info(new Gson().toJson(forecastWeatherDtoList)); + } } \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledNmcWeatherService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledNmcWeatherService.java index 2978536..582e26e 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledNmcWeatherService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledNmcWeatherService.java @@ -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(); diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledWztfwStormService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledWztfwStormService.java index 37790e8..c810b9c 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledWztfwStormService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledWztfwStormService.java @@ -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()); diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledZjsltStormService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledZjsltStormService.java index ce9b2e2..d635999 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledZjsltStormService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ScheduledZjsltStormService.java @@ -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>() { }.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 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 list = this.zjsltStormService.findByYear(currentYear); + log.info(String.valueOf(list.size())); + log.info(new Gson().toJson(list)); + } } diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ZjsltStormService.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ZjsltStormService.java index f795eae..a9301bc 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ZjsltStormService.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/service/ZjsltStormService.java @@ -11,6 +11,8 @@ public interface ZjsltStormService { ZjsltStorm findByTfid(String tfid); //根据年份查询台风列表 List findByYear(String year); + //根据年份查询台风列表 + List getTyhoonActivity(); /** * 保存台风数据 */ diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyAssert.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyAssert.java new file mode 100644 index 0000000..fa9e4e2 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyAssert.java @@ -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 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 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); + } +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyException.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyException.java new file mode 100644 index 0000000..f29819e --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/LhyException.java @@ -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; + } +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapToT.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapToT.java new file mode 100644 index 0000000..554e4ac --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapToT.java @@ -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 { + /** + * Object 转换成 类型 T + * @param map Map + * @return T + */ + T mapToT(Map map); +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapUtil.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapUtil.java new file mode 100644 index 0000000..2061048 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/MapUtil.java @@ -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 静态方法 + + /** + * Map对象转换成Map对象 + * + * @param obj Map对象 + * @return Map对象 + */ + public static Map mapObjectToStringKeyMap(Object obj) { + if (obj == null) { + return null; + } + else if (obj instanceof Map) { + Map map = (Map) obj; + Map 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 map, String key) { + return getMapObjectValue(map, key, null); + } + + private Object getMapObjectValue(Map map, String key, Object defValue) { + return map.getOrDefault(key, defValue); + } + + public static String getMapStringValue(Map map, String key) { + return getMapStringValue(map, key, ""); + } + + /** + * 获取字符串(如果key 不存在返回 “”) + * + * @param map map + * @param key key + * @return 字符串 + */ + public static String getMapStringValue(Map 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 map, String key) { + return getMapIntegerValue(map, key, 0); + } + + public static Integer getMapIntegerValue(Map 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 map, String key) { + return getMapFloatValue(map, key, 0F); + } + + public static Float getMapFloatValue(Map 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 map, String key) { + return getMapLongValue(map, key, 0L); + } + + public static Long getMapLongValue(Map 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 map, String key) { + return getMapBooleanValue(map, key, false); + } + + public static Boolean getMapBooleanValue(Map 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 mapNumberToInt(Map resultMap) { + Map 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 listNumberToInt(List list) { + List 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 mapToObject(Map 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 mapOfJsonString(String jsonString) { + try { + Map resultMap = new Gson().fromJson(jsonString, new TypeToken>() { + }.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 得到的类 + * @return T + * @author LiuHuiYu + * Created DateTime 2022-01-22 16:42 + */ + public static T fromMap(Map map, Class classOfT) { + String json = new Gson().toJson(map); + return new Gson().fromJson(json, classOfT); + } + + /** + * 将Map序列化成指定类 + * + * @param map map + * @param classOfT T.class + * @param 得到的类 + * @return T + * @author LiuHuiYu + * Created DateTime 2022-01-22 16:42 + */ + public static T fromMap(Map map, Class 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 mapDoubleToInt(Map resultMap) { + Map 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 listDoubleToInt(List list) { + List 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 map = mapOfJsonString(jsonString); + return new MapUtil(map); + } + + private final Map map; + + public MapUtil(Map 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 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 getValue(String key, Function function) { + return function.apply(map.getOrDefault(key, null)); + } + + public List getListValue(String key, Function function) { + Function> 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 + * @author LiuHuiYu + * Created DateTime 2021-08-06 9:50 + */ + public > R getCollectionValue(String key, Function function, Supplier initializeCollection) { + Function> 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 + * @author LiuHuiYu + * Created DateTime 2021-08-06 9:50 + */ + public > R getCollectionValueAllowJudgment(String key, Function> function, Supplier 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 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 getMap(String key) { + return getMap(key, new HashMap<>(0)); + } + + public Map getMap(String key, Map defValue) { + Object obj = map.get(key); + if (obj == null) { + return defValue; + } + else { + try { + return mapObjectToStringKeyMap(obj); + } + catch (Exception ignored) { + return defValue; + } + } + } + + public PageImpl getPageImpl(String key, MapToT mapToT) { + PageImpl def = new PageImpl<>(new ArrayList<>(0)); + return getPageImpl(key, mapToT, def); + } + + public PageImpl getPageImpl(String key, MapToT mapToT, PageImpl defValue) { + Object obj = map.get(key); + if (obj == null) { + return defValue; + } + else { + try { + Map map = mapObjectToStringKeyMap(obj); + return mapToPageImpl(map, mapToT); + } + catch (Exception ignored) { + return defValue; + } + } + } + + /** + * 获取ResultMap模型中的分页数据 + * + * @param map 原始map数据 + * @param mapToT 转换函数 + * @param 泛型 + * @return org.springframework.data.domain.PageImpl + * @author LiuHuiYu + * Created DateTime 2021-11-29 17:18 + */ + public static @NotNull PageImpl mapToPageImpl(Map map, MapToT 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 list = mapUtil.getListValue("content", obj -> mapToT.mapToT(MapUtil.mapObjectToStringKeyMap(obj))); + return new PageImpl<>(list, pageable, totalElements); + } + + public static class ResInfo { + Boolean res; + T resData; + + public ResInfo(Boolean res, T resData) { + this.res = res; + this.resData = resData; + } + } + + public static T cloneObj(T a, Class classOfT) { + String json = new Gson().toJson(a); + return new Gson().fromJson(json, classOfT); + } +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ObjectToT.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ObjectToT.java new file mode 100644 index 0000000..1301e07 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ObjectToT.java @@ -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 { + /** + * Object 转换成 类型 T + * @param o Object + * @return T + */ + T objectToT(Object o); +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpConfig.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpConfig.java index bd366c7..15295bf 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpConfig.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpConfig.java @@ -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); diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpUtil.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpUtil.java index 389c240..0c370c1 100644 --- a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpUtil.java +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/OkHttpUtil.java @@ -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 diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/Result.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/Result.java new file mode 100644 index 0000000..7cb7fc4 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/Result.java @@ -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 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 @NotNull Result of(T data) { + return new Result<>(data); + } + + @Contract(value = "_, _ -> new", pure = true) + public static @NotNull Result of(T data, Integer flag) { + return new Result<>(data, flag); + } + + @Contract(value = "_, _, _ -> new", pure = true) + public static @NotNull Result of(T data, Integer flag, String msg) { + return new Result<>(data, flag, msg); + } + + @Contract(value = "_ -> new", pure = true) + public static @NotNull Result error(String msg) { + return new Result<>(null, ERROR, msg); + } + + @Contract(value = "_, _-> new", pure = true) + public static @NotNull Result error(String msg, int errorCode) { + return new Result<>(null, errorCode, msg); + } + + @Contract(value = " -> new", pure = true) + public static @NotNull Result 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 @NotNull Result ofMap(Map map, Class clazz) { + Result 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 map) { + return getValueOfResultMap(map, o -> o); + } + + /** + * 获取ResultMap模型中的数据 + * + * @param map 传入数据 + * @param mapToT 转换函数 + * @param 转换类型 + * @return java.util.List 返回转换后的数组(过滤null数据) + * @author LiuHuiYu + * Created DateTime 2021-11-25 17:05 + */ + public static List getResultToList(Map map, MapToT 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 list = new ArrayList<>(arrayList.size()); + for (Object obj : arrayList) { + Map itemMap = MapUtil.mapObjectToStringKeyMap(obj); + final T t = mapToT.mapToT(itemMap); + if (t != null) { + list.add(t); + } + } + return list; + } + + /** + * 获取ResultMap模型中的数据 + * + * @param map 传入数据 + * @param mapToT 转换函数 + * @param 转换类型 + * @return T 返回转换后的结果 + * @author LiuHuiYu + * Created DateTime 2021-11-25 17:10 + */ + public static T getResultData(Map map, MapToT mapToT) { + LhyAssert.assertNotNull(mapToT, new ResultException("不能传入null解析方法mapToT。")); + Object obj = getValueOfResultMap(map, o -> o); + Map itemMap = MapUtil.mapObjectToStringKeyMap(obj); + return mapToT.mapToT(itemMap); + } + + /** + * 将map转换成Result + * + * @param map Result的map结构 + * @return Result 返回Result结构 + * @author LiuHuiYu + * Created DateTime 2021-11-25 17:08 + */ + public static Result getResult(Map map) { + LhyAssert.assertNotNull(map, new ResultException("传入null值,无法进行解析map。")); + Result 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 转换后的类型 + * @return T 转换后的结果 + * @author LiuHuiYu + * Created DateTime 2021-11-25 16:52 + */ + public static T getValueOfResultMap(Map map, ObjectToT objectToT) { + LhyAssert.assertNotNull(objectToT, new ResultException("不能传入null解析方法mapToT。")); + LhyAssert.assertNotNull(map, new ResultException("传入null值,无法进行解析map。")); + Result result = getResult(map); + LhyAssert.assertTrue(result.isSuccess(), result.getMsg()); + return objectToT.objectToT(result.getData()); + } + + /** + * 获取ResultMap模型中的分页数据 + * + * @param map 原始map数据 + * @param mapToT 转换函数 + * @param 泛型 + * @return org.springframework.data.domain.PageImpl + * @author LiuHuiYu + * Created DateTime 2021-11-29 17:18 + */ + @Contract("_, _ -> new") + public static @NotNull PageImpl getResultToPageImpl(Map map, MapToT mapToT) { + LhyAssert.assertNotNull(mapToT, new ResultException("不能传入null解析方法mapToT。")); + Result 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 list = mapUtil.getListValue("content", obj -> mapToT.mapToT(MapUtil.mapObjectToStringKeyMap(obj))); + return new PageImpl<>(list, pageable, totalElements); + } + else { + throw new RuntimeException(result.getMsg()); + } + } +} \ No newline at end of file diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultEnum.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultEnum.java new file mode 100644 index 0000000..34dbce5 --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultEnum.java @@ -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; + } +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultException.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultException.java new file mode 100644 index 0000000..18bcdfd --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/ResultException.java @@ -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); + } +} diff --git a/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/RetryUtil.java b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/RetryUtil.java new file mode 100644 index 0000000..7c1483d --- /dev/null +++ b/jpahefengweather/src/main/java/com/rehome/jpahefengweather/utils/RetryUtil.java @@ -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 retry(int num, Callable callFunctions) { + return retry(num, false, callFunctions); + } + + /** + * 多次重试 + * + * @param num 执行次数(失败后重试) + * @param callFunctions 重试调用函数 + * @param failedCall 调用函数失败后执行 + * @author LiuHuiYu + * Created DateTime 2021-07-05 16:58 + */ + public static R retry(int num, Callable 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 retry(Callable 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 retry(int num, Callable 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 retry(int num, boolean loop, Callable 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); + } + } +} diff --git a/jpahefengweather/src/main/java/org/hibernate/cfg/PropertyContainer.java b/jpahefengweather/src/main/java/org/hibernate/cfg/PropertyContainer.java new file mode 100644 index 0000000..57afcef --- /dev/null +++ b/jpahefengweather/src/main/java/org/hibernate/cfg/PropertyContainer.java @@ -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 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 fields = this.xClass.getDeclaredProperties(AccessType.FIELD.getType()); + List getters = this.xClass.getDeclaredProperties(AccessType.PROPERTY.getType()); + this.preFilter(fields, getters); + Map persistentAttributesFromGetters = new HashMap(); + LinkedHashMap 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 fields, List 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 persistentAttributeMap, Map persistentAttributesFromGetters, List fields, List 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 persistentAttributeMap, Map persistentAttributesFromGetters, List fields, List 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 getProperties() { + return Collections.unmodifiableCollection(this.persistentAttributes); + } + + public Iterable propertyIterator() { + return this.persistentAttributes; + } + + private static List verifyAndInitializePersistentAttributes(XClass xClass, Map localAttributeMap) { + ArrayList 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()); + } +} \ No newline at end of file diff --git a/jpahefengweather/src/main/resources/application.yml b/jpahefengweather/src/main/resources/application.yml index e4ea79c..ac957ca 100644 --- a/jpahefengweather/src/main/resources/application.yml +++ b/jpahefengweather/src/main/resources/application.yml @@ -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 \ No newline at end of file + resources-path: /Users/admin/storage # 外部资源文件存储路径 格式:/Users/edao/storage \ No newline at end of file diff --git a/jpahefengweather/src/test/java/com/rehome/jpahefengweather/controller/WeatherControllerTest.java b/jpahefengweather/src/test/java/com/rehome/jpahefengweather/controller/WeatherControllerTest.java deleted file mode 100644 index 7e9a0c2..0000000 --- a/jpahefengweather/src/test/java/com/rehome/jpahefengweather/controller/WeatherControllerTest.java +++ /dev/null @@ -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> result = this.weatherController.getCityList(); - List citys = result.getData(); - //LOG.info("{}",new Gson().toJson(citys)); - System.out.println(citys.size()); - }catch (Exception e){ - e.printStackTrace(); - } - } - -}