|
|
|
@ -1,17 +1,15 @@
|
|
|
|
package com.rehome.weather.service.impl;
|
|
|
|
package com.rehome.weather.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.rehome.weather.config.dao.JuheWeatherProperties;
|
|
|
|
import com.rehome.weather.dao.*;
|
|
|
|
import com.rehome.weather.dao.StormDao;
|
|
|
|
|
|
|
|
import com.rehome.weather.dto.BaseStormDto;
|
|
|
|
import com.rehome.weather.dto.BaseStormDto;
|
|
|
|
import com.rehome.weather.dto.StormDto;
|
|
|
|
import com.rehome.weather.dto.StormDto;
|
|
|
|
import com.rehome.weather.entity.*;
|
|
|
|
import com.rehome.weather.entity.*;
|
|
|
|
import com.rehome.weather.service.StormService;
|
|
|
|
import com.rehome.weather.service.StormService;
|
|
|
|
import com.rehome.weather.utils.WeatherUtil;
|
|
|
|
import com.rehome.weather.utils.WeatherUtil;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
|
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
|
|
import org.springframework.cache.annotation.CacheConfig;
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
@ -31,17 +29,44 @@ import java.util.*;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@EnableConfigurationProperties(JuheWeatherProperties.class)
|
|
|
|
|
|
|
|
@CacheConfig(cacheNames = "com.rehome.weather.service.impl.StormServiceImpl")
|
|
|
|
@CacheConfig(cacheNames = "com.rehome.weather.service.impl.StormServiceImpl")
|
|
|
|
public class StormServiceImpl implements StormService {
|
|
|
|
public class StormServiceImpl implements StormService {
|
|
|
|
private Logger log = LoggerFactory.getLogger(this.getClass());
|
|
|
|
private Logger log = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
|
|
|
|
|
|
//台风dao
|
|
|
|
//台风dao
|
|
|
|
|
|
|
|
// @Resource
|
|
|
|
|
|
|
|
// private StormDao stormDao ;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private StormDao stormDao ;
|
|
|
|
private StormDataRepository stormDataRepository;
|
|
|
|
//聚合数据 配置文件相关参数
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
JuheWeatherProperties juheWeatherProperties;
|
|
|
|
private StormForecastRepository stormForecastRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private StormTrackJpaRepository stormTrackJpaRepository;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//聚合数据 配置文件相关参数
|
|
|
|
|
|
|
|
// @Resource
|
|
|
|
|
|
|
|
// JuheWeatherProperties juheWeatherProperties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${weather.stormListUrl}")
|
|
|
|
|
|
|
|
private String stormListUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${weather.heFengStormKey}")
|
|
|
|
|
|
|
|
private String heFengStormKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${weather.stormForecastUrl}")
|
|
|
|
|
|
|
|
private String stormForecastUrl;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${weather.stormTrackUrl}")
|
|
|
|
|
|
|
|
private String stormTrackUrl;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 功能描述 从和风天气开发平台查询台风列表数据并入库
|
|
|
|
* 功能描述 从和风天气开发平台查询台风列表数据并入库
|
|
|
|
@ -51,8 +76,7 @@ public class StormServiceImpl implements StormService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@CacheEvict(cacheNames = "com.rehome.weather.service.impl.StormServiceImpl",allEntries = true)
|
|
|
|
@CacheEvict(cacheNames = "com.rehome.weather.service.impl.StormServiceImpl",allEntries = true)
|
|
|
|
public Map getStormListByScheduled(String year) {
|
|
|
|
public Map getStormListByScheduled(String year) {
|
|
|
|
String stormListUrl = juheWeatherProperties.getStormListUrl();
|
|
|
|
|
|
|
|
String heFengStormKey=juheWeatherProperties.getHeFengStormKey();
|
|
|
|
|
|
|
|
String url=stormListUrl+"?key="+heFengStormKey+"&basin=NP&year="+year;
|
|
|
|
String url=stormListUrl+"?key="+heFengStormKey+"&basin=NP&year="+year;
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
log.info(url);
|
|
|
|
log.info(url);
|
|
|
|
@ -62,33 +86,35 @@ public class StormServiceImpl implements StormService {
|
|
|
|
if(stormDto!=null&&stormDto.getCode().equals("200")){
|
|
|
|
if(stormDto!=null&&stormDto.getCode().equals("200")){
|
|
|
|
List<StormData> storm=stormDto.getStorm();
|
|
|
|
List<StormData> storm=stormDto.getStorm();
|
|
|
|
if(storm.size()>0){
|
|
|
|
if(storm.size()>0){
|
|
|
|
for (StormData stormEntity : storm) {
|
|
|
|
for (StormData stormData : storm) {
|
|
|
|
stormEntity.setPlatform("hefeng");
|
|
|
|
stormData.setPlatform("hefeng");
|
|
|
|
stormEntity.setPlatformdesc("和风天气开发平台");
|
|
|
|
stormData.setPlatformdesc("和风天气开发平台");
|
|
|
|
StormData stormEntityDb=stormDao.getStormById(stormEntity.getId());
|
|
|
|
Optional<StormData> stormEntityDb=stormDataRepository.findById(stormData.getId());
|
|
|
|
if(stormEntityDb==null){
|
|
|
|
if(!stormEntityDb.isPresent()){
|
|
|
|
//数据库不存在这条台风数据 插入这条台风数据,
|
|
|
|
//数据库不存在这条台风数据 插入这条台风数据,
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风实况和路径接口数据并入库,
|
|
|
|
//同时调用台风实况和路径接口数据并入库,
|
|
|
|
log.info("数据库不存在这条台风数据 插入这条台风数据,");
|
|
|
|
log.info("数据库不存在这条台风数据 插入这条台风数据,");
|
|
|
|
int resultId=stormDao.insertStorm(stormEntity);
|
|
|
|
StormData resultStorm=stormDataRepository.save(stormData);
|
|
|
|
log.info("插入台风数据成功,id:"+String.valueOf(resultId));
|
|
|
|
if(resultStorm!=null){
|
|
|
|
this.getStormForecastByScheduled(stormEntity.getId());
|
|
|
|
log.info("插入台风数据成功,id:"+String.valueOf(resultStorm.getId()));
|
|
|
|
this.getStormTrackByScheduled(stormEntity.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getStormForecastByScheduled(stormData.getId());
|
|
|
|
|
|
|
|
this.getStormTrackByScheduled(stormData.getId());
|
|
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
//数据库存在这条台风数据
|
|
|
|
//数据库存在这条台风数据
|
|
|
|
if(stormEntity.getIsActive().equals("1")){
|
|
|
|
if(stormData.getIsActive().equals("1")){
|
|
|
|
//台风处于活跃状态
|
|
|
|
//台风处于活跃状态
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风实况和路径接口数据并入库
|
|
|
|
//同时调用台风实况和路径接口数据并入库
|
|
|
|
log.info("台风处于活跃状态");
|
|
|
|
log.info("台风处于活跃状态");
|
|
|
|
this.getStormForecastByScheduled(stormEntity.getId());
|
|
|
|
this.getStormForecastByScheduled(stormData.getId());
|
|
|
|
this.getStormTrackByScheduled(stormEntity.getId());
|
|
|
|
this.getStormTrackByScheduled(stormData.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(stormEntity.getIsActive().equals("0")){
|
|
|
|
if(stormData.getIsActive().equals("0")){
|
|
|
|
//台风已停止状态
|
|
|
|
//台风已停止状态
|
|
|
|
if(stormEntityDb.getIsActive().equals("1")){
|
|
|
|
if(stormEntityDb.get().getIsActive().equals("1")){
|
|
|
|
//数据库里台风还处于活跃状态,更新台风状态
|
|
|
|
//数据库里台风还处于活跃状态,更新台风状态
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风预报接口数据并入库,
|
|
|
|
//同时调用台风实况和路径接口数据并入库
|
|
|
|
//同时调用台风实况和路径接口数据并入库
|
|
|
|
@ -99,11 +125,13 @@ public class StormServiceImpl implements StormService {
|
|
|
|
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
|
|
|
String nowTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
|
|
|
|
//把时间转换
|
|
|
|
//把时间转换
|
|
|
|
Timestamp updatetime =Timestamp.valueOf(nowTime);
|
|
|
|
Timestamp updatetime =Timestamp.valueOf(nowTime);
|
|
|
|
stormEntity.setUpdatetime(updatetime);
|
|
|
|
stormData.setUpdatetime(updatetime);
|
|
|
|
int resultId=stormDao.updateStorm(stormEntity);
|
|
|
|
StormData resultStorm=stormDataRepository.save(stormData);
|
|
|
|
log.info("更新台风数据成功,id:"+String.valueOf(resultId));
|
|
|
|
if(resultStorm!=null){
|
|
|
|
this.getStormForecastByScheduled(stormEntity.getId());
|
|
|
|
log.info("更新台风数据成功,id:"+String.valueOf(resultStorm.getId()));
|
|
|
|
this.getStormTrackByScheduled(stormEntity.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getStormForecastByScheduled(stormData.getId());
|
|
|
|
|
|
|
|
this.getStormTrackByScheduled(stormData.getId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -130,8 +158,7 @@ public class StormServiceImpl implements StormService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getStormForecastByScheduled(String stormid) {
|
|
|
|
public String getStormForecastByScheduled(String stormid) {
|
|
|
|
String stormForecastUrl = juheWeatherProperties.getStormForecastUrl();
|
|
|
|
|
|
|
|
String heFengStormKey=juheWeatherProperties.getHeFengStormKey();
|
|
|
|
|
|
|
|
String url=stormForecastUrl+"?key="+heFengStormKey+"&stormid="+stormid;
|
|
|
|
String url=stormForecastUrl+"?key="+heFengStormKey+"&stormid="+stormid;
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
log.info(url);
|
|
|
|
log.info(url);
|
|
|
|
@ -141,8 +168,10 @@ public class StormServiceImpl implements StormService {
|
|
|
|
StormForecast stormForecast = new StormForecast();
|
|
|
|
StormForecast stormForecast = new StormForecast();
|
|
|
|
stormForecast.setStormid(stormid);
|
|
|
|
stormForecast.setStormid(stormid);
|
|
|
|
stormForecast.setForecast(stormJson);
|
|
|
|
stormForecast.setForecast(stormJson);
|
|
|
|
int resultId=stormDao.insertStormForecast(stormForecast);
|
|
|
|
StormForecast resultStormForecast=stormForecastRepository.save(stormForecast);
|
|
|
|
log.info("插入台风预报数据成功,id:"+String.valueOf(resultId));
|
|
|
|
if(resultStormForecast!=null){
|
|
|
|
|
|
|
|
log.info("插入台风预报数据成功,id:"+String.valueOf(resultStormForecast.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stormJson;
|
|
|
|
return stormJson;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -154,8 +183,7 @@ public class StormServiceImpl implements StormService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getStormTrackByScheduled(String stormid) {
|
|
|
|
public String getStormTrackByScheduled(String stormid) {
|
|
|
|
String stormTrackUrl = juheWeatherProperties.getStormTrackUrl();
|
|
|
|
|
|
|
|
String heFengStormKey=juheWeatherProperties.getHeFengStormKey();
|
|
|
|
|
|
|
|
String url=stormTrackUrl+"?key="+heFengStormKey+"&stormid="+stormid;
|
|
|
|
String url=stormTrackUrl+"?key="+heFengStormKey+"&stormid="+stormid;
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
String stormJson = WeatherUtil.analysisUrlGzip(url);
|
|
|
|
log.info(url);
|
|
|
|
log.info(url);
|
|
|
|
@ -165,8 +193,10 @@ public class StormServiceImpl implements StormService {
|
|
|
|
StormTrack stormTrack = new StormTrack();
|
|
|
|
StormTrack stormTrack = new StormTrack();
|
|
|
|
stormTrack.setStormid(stormid);
|
|
|
|
stormTrack.setStormid(stormid);
|
|
|
|
stormTrack.setTrack(stormJson);
|
|
|
|
stormTrack.setTrack(stormJson);
|
|
|
|
int resultId=stormDao.insertStormTrack(stormTrack);
|
|
|
|
StormTrack resultStormTrack=stormTrackJpaRepository.save(stormTrack);
|
|
|
|
log.info("插入台风实况和路径数据成功,id:"+String.valueOf(resultId));
|
|
|
|
if(resultStormTrack!=null){
|
|
|
|
|
|
|
|
log.info("插入台风实况和路径数据成功,id:"+String.valueOf(resultStormTrack.getId()));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stormJson;
|
|
|
|
return stormJson;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -180,9 +210,9 @@ public class StormServiceImpl implements StormService {
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#year+'-getLocalStormList'")
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#year+'-getLocalStormList'")
|
|
|
|
public Map getLocalStormList(String year) {
|
|
|
|
public Map getLocalStormList(String year) {
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
List<StormData> storm=stormDao.getLocalStorms(year);
|
|
|
|
Optional<List<StormData>> storm=stormDataRepository.findByYear(year);
|
|
|
|
List stormEmpty=new ArrayList<StormData>();
|
|
|
|
List stormEmpty=new ArrayList<StormData>();
|
|
|
|
if(storm==null){
|
|
|
|
if(!storm.isPresent()){
|
|
|
|
map.put("storm",stormEmpty);
|
|
|
|
map.put("storm",stormEmpty);
|
|
|
|
}else{
|
|
|
|
}else{
|
|
|
|
map.put("storm",storm);
|
|
|
|
map.put("storm",storm);
|
|
|
|
@ -199,9 +229,9 @@ public class StormServiceImpl implements StormService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#stormid+'-getLocalStormForecastByStormId'")
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#stormid+'-getLocalStormForecastByStormId'")
|
|
|
|
public String getLocalStormForecastByStormId(String stormid) {
|
|
|
|
public String getLocalStormForecastByStormId(String stormid) {
|
|
|
|
StormForecast stormForecast = stormDao.getStormForecastById(stormid);
|
|
|
|
Optional<StormForecast> stormForecast = stormForecastRepository.findByIdOne(stormid);
|
|
|
|
if(stormForecast!=null){
|
|
|
|
if(stormForecast.isPresent()){
|
|
|
|
return stormForecast.getForecast();
|
|
|
|
return stormForecast.get().getForecast();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
map.put("code","10000");
|
|
|
|
map.put("code","10000");
|
|
|
|
@ -218,9 +248,9 @@ public class StormServiceImpl implements StormService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#stormid+'-getLocalStormTrackByStormId'")
|
|
|
|
@Cacheable(cacheNames="com.rehome.weather.service.impl.StormServiceImpl",key="#stormid+'-getLocalStormTrackByStormId'")
|
|
|
|
public String getLocalStormTrackByStormId(String stormid) {
|
|
|
|
public String getLocalStormTrackByStormId(String stormid) {
|
|
|
|
StormTrack stormTrack = stormDao.getStormTrackById(stormid);
|
|
|
|
Optional<StormTrack> stormTrack = stormTrackJpaRepository.findByIdOne(stormid);
|
|
|
|
if (stormTrack!=null){
|
|
|
|
if (stormTrack.isPresent()){
|
|
|
|
return stormTrack.getTrack();
|
|
|
|
return stormTrack.get().getTrack();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
Map map = new HashMap<String,Object>();
|
|
|
|
map.put("code","10000");
|
|
|
|
map.put("code","10000");
|
|
|
|
|