master
修改密码漏洞修复完成 6 months ago
parent 64b5e5e567
commit 8679be33df

@ -150,6 +150,11 @@
<artifactId>mssql-jdbc</artifactId> <artifactId>mssql-jdbc</artifactId>
<version>11.2.0.jre8</version> <version>11.2.0.jre8</version>
</dependency> </dependency>
<dependency>
<groupId>net.i2p.crypto</groupId>
<artifactId>eddsa</artifactId>
<version>0.3.0</version>
</dependency>
<!-- <dependency>--> <!-- <dependency>-->

@ -2,13 +2,11 @@ package com.rehome.jpahefengweather.controller;
import com.liuhuiyu.util.model.Result; import com.liuhuiyu.util.model.Result;
import com.liuhuiyu.util.web.AddressRoutingUtil;
import com.liuhuiyu.util.web.HttpUtil;
import com.rehome.jpahefengweather.dto.BaseFindDto; import com.rehome.jpahefengweather.dto.BaseFindDto;
import com.rehome.jpahefengweather.dto.BaseWeatherFindDto; import com.rehome.jpahefengweather.dto.BaseWeatherFindDto;
import com.rehome.jpahefengweather.dto.ForecastWeatherDto; import com.rehome.jpahefengweather.dto.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto; import com.rehome.jpahefengweather.dto.NowWeatherDto;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.NowWeather; import com.rehome.jpahefengweather.entity.NowWeather;
import com.rehome.jpahefengweather.service.CityService; import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.service.WeatherService; import com.rehome.jpahefengweather.service.WeatherService;
@ -36,8 +34,8 @@ public class WeatherController {
* @Param: * @Param:
*/ */
@GetMapping("/getCityList") @GetMapping("/getCityList")
public Result<List<CityList>> getCityList(){ public Result<List<HefengCity>> getCityList(){
return Result.of(this.cityService.findAllCitys()); return Result.of(this.cityService.findAllCity());
} }
//region 获取历史天气 //region 获取历史天气

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

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

@ -20,6 +20,12 @@ public class ForecastWeather implements Serializable {
private String locationId; private String locationId;
private String province;
private String city ;
private String locationNameZh;
// 存放长文本 // 存放长文本
@Lob @Lob
@Basic(fetch=FetchType.LAZY) @Basic(fetch=FetchType.LAZY)

@ -1,22 +1,15 @@
package com.rehome.jpahefengweather.entity; package com.rehome.jpahefengweather.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import org.hibernate.annotations.Proxy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@EntityListeners(AuditingEntityListener.class)
@Proxy(lazy = false)
@Data @Data
@Entity @Entity
//@Table(name="t_users") public class HefengCity implements Serializable {
public class CityList implements Serializable {
@Id @Id
private String locationId; private String locationId;
@ -47,12 +40,10 @@ public class CityList implements Serializable {
private String adcode; private String adcode;
// @CreatedDate // @CreatedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date createDate; private Date createDate;
// @LastModifiedDate // @LastModifiedDate
// @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate; private Date lastUpdateDate;
} }

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

@ -23,6 +23,12 @@ public class NowWeather implements Serializable {
private String locationId; private String locationId;
private String province;
private String city ;
private String locationNameZh;
//存放长文本 //存放长文本
@Lob @Lob
@Basic(fetch=FetchType.LAZY) @Basic(fetch=FetchType.LAZY)

@ -1,15 +1,34 @@
package com.rehome.jpahefengweather.service; package com.rehome.jpahefengweather.service;
import com.liuhuiyu.util.model.Result; import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengProvince;
import java.util.List; import java.util.List;
public interface CityService { public interface CityService {
void saveCitys(List<CityList> cityLists); /**
*
* @param provinceList
*/
void saveProvinceList(List<HefengProvince> provinceList);
/**
*
* @param cityList
*/
void saveCityList(List<HefengCity> cityList);
/**
* 3000+
* @return List
*/
List<HefengCity> findAllCity();
/**
* 3000+
* @return List
*/
List<HefengCity> findCityByProvinceCode(String provinceCode);
/** /**
* 3000+ * 3000+
* @return List * @return List
*/ */
List<CityList> findAllCitys(); List<HefengProvince> findAllProvince();
} }

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

@ -1,21 +1,16 @@
package com.rehome.jpahefengweather.service.Impl; package com.rehome.jpahefengweather.service.Impl;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.rehome.jpahefengweather.dao.CityRepository;
import com.rehome.jpahefengweather.dao.ForecastWeatherRepository; import com.rehome.jpahefengweather.dao.ForecastWeatherRepository;
import com.rehome.jpahefengweather.dao.NowWeatherRepository; import com.rehome.jpahefengweather.dao.NowWeatherRepository;
import com.rehome.jpahefengweather.dto.ForecastWeatherDto; import com.rehome.jpahefengweather.dto.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto; import com.rehome.jpahefengweather.dto.NowWeatherDto;
import com.rehome.jpahefengweather.entity.CityList;
import com.rehome.jpahefengweather.entity.ForecastWeather; import com.rehome.jpahefengweather.entity.ForecastWeather;
import com.rehome.jpahefengweather.entity.NowWeather; import com.rehome.jpahefengweather.entity.NowWeather;
import com.rehome.jpahefengweather.service.WeatherService; import com.rehome.jpahefengweather.service.WeatherService;
import org.hibernate.query.Query;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;

@ -1,19 +1,13 @@
package com.rehome.jpahefengweather.service; package com.rehome.jpahefengweather.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.liuhuiyu.spring_util.SpringUtil; import com.liuhuiyu.spring_util.SpringUtil;
import com.liuhuiyu.util.string.StringUtil;
import com.rehome.jpahefengweather.dto.NmcBaseDto; import com.rehome.jpahefengweather.dto.NmcBaseDto;
import com.rehome.jpahefengweather.dto.NmcNowWeatherDto;
import com.rehome.jpahefengweather.dto.StormDataDto;
import com.rehome.jpahefengweather.entity.*; import com.rehome.jpahefengweather.entity.*;
import com.rehome.jpahefengweather.service.Impl.NmcWeatherServiceImpl;
import com.rehome.jpahefengweather.service.excel.*; import com.rehome.jpahefengweather.service.excel.*;
import com.rehome.jpahefengweather.utils.JwtUtils;
import com.rehome.jpahefengweather.utils.OkHttpUtil; import com.rehome.jpahefengweather.utils.OkHttpUtil;
import okhttp3.*; import okhttp3.*;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
@ -25,13 +19,9 @@ import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigInteger;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
/** /**
* @author huangwenfei * @author huangwenfei
@ -69,7 +59,7 @@ public class ScheduledService {
* @description: * @description:
* @Param: null * @Param: null
*/ */
//@Scheduled(cron = "0 30 * * * *")//每个小时执行一次 //@Scheduled(cron = "0 32 * * * *")//每个小时执行一次
public void scheduled() { public void scheduled() {
System.out.println("scheduled"); System.out.println("scheduled");
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
@ -95,9 +85,35 @@ public class ScheduledService {
ReadCityExcelXlsx readCityExcelXlsx = new ReadCityExcelXlsx(this.resourcesPath, "China-City-List-latest.xlsx"); ReadCityExcelXlsx readCityExcelXlsx = new ReadCityExcelXlsx(this.resourcesPath, "China-City-List-latest.xlsx");
//readCityExcelXlsx.testReadExcel(); //readCityExcelXlsx.testReadExcel();
List<CityList> excelReadCityExcelXlsx = readCityExcelXlsx.getCityLists(); List<HefengCity> excelReadCityExcelXlsx = readCityExcelXlsx.getCityLists();
this.cityService.saveCitys(excelReadCityExcelXlsx); if(excelReadCityExcelXlsx!=null&&excelReadCityExcelXlsx.size()>0){
this.cityService.saveCityList(excelReadCityExcelXlsx);
Map<String,String> provinceCodeMap = new HashMap<>();
for (HefengCity hefengCity :excelReadCityExcelXlsx) {
provinceCodeMap.put(hefengCity.getAdm1NameEn(),hefengCity.getAdm1NameZh());
}
System.out.println(new Gson().toJson(provinceCodeMap));
System.out.println(String.valueOf(provinceCodeMap.size()));
List<HefengProvince> provinceList = new ArrayList<>();
for (String key : provinceCodeMap.keySet()) {
String provinceName = provinceCodeMap.get(key);
HefengProvince province = new HefengProvince();
province.setCode(key);
province.setName(provinceName);
Date now = new Date();
province.setCreateDate(now);
province.setLastUpdateDate(now);
provinceList.add(province);
}
if(provinceList.size()>0){
this.cityService.saveProvinceList(provinceList);
}
List<HefengCity> listCityByProvince = this.cityService.findCityByProvinceCode("Guangdong");
System.out.println("----------");
System.out.println(new Gson().toJson(listCityByProvince));
System.out.println("广东省城市总数:"+String.valueOf(listCityByProvince.size()));
System.out.println("和风天气省份和城市数据同步成功");
}
} else { } else {
System.out.println("文件不存在"); System.out.println("文件不存在");
} }
@ -107,6 +123,11 @@ public class ScheduledService {
} }
} }
//@Scheduled(cron = "0/5 * * * * *")//每个小时执行一次
public void scheduledGetJwt() {
String jwt = JwtUtils.getJwt();
System.out.println(jwt);
}
/** /**
* @date 2022-03-16 09:41 * @date 2022-03-16 09:41
* @description: , OkHttpClient * @description: , OkHttpClient
@ -114,23 +135,24 @@ public class ScheduledService {
*/ */
//@Scheduled(cron = "0 0 10,14,18,20,22 * * *")//每天1014182022点各执行一次一天总共执行五次 //@Scheduled(cron = "0 0 10,14,18,20,22 * * *")//每天1014182022点各执行一次一天总共执行五次
//@Scheduled(cron = "0 0 0,8,12,16 * * *")//每天081216点各执行一次一天总共执行四次 //@Scheduled(cron = "0 0 0,8,12,16 * * *")//每天081216点各执行一次一天总共执行四次
@Scheduled(cron = "0 15 * * * *")//每个小时执行一次
public void scheduledGetWeather() { public void scheduledGetWeather() {
System.out.println("scheduledGetWeather"); System.out.println("scheduledGetWeather");
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
List<CityList> citys = this.cityService.findAllCitys(); List<HefengCity> cityList = this.cityService.findCityByProvinceCode("Guangdong");
if (citys != null && citys.size() > 0) { if (cityList != null && cityList.size() > 0) {
Date now = new Date(); Date now = new Date();
System.out.println(citys.size()); System.out.println(cityList.size());
for (int i = 0; i < citys.size(); i++) { for (int i = 0; i < cityList.size(); i++) {
CityList city = citys.get(i); HefengCity city = cityList.get(i);
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
//我的帐号: c67db396fcdb416c959933d29e30db3d //我的帐号: c67db396fcdb416c959933d29e30db3d
//克金帐号: 3522d7d5736947d7a63e8d7d95316406 //克金帐号: 3522d7d5736947d7a63e8d7d95316406
params.put("key", "c67db396fcdb416c959933d29e30db3d"); params.put("key", "c67db396fcdb416c959933d29e30db3d");
params.put("location", city.getLocationId()); params.put("location", city.getLocationId());
String weatherData = OkHttpUtil.get("https://devapi.qweather.com/v7/weather/now", params); String weatherData = OkHttpUtil.get("https://m573jftdb9.re.qweatherapi.com/v7/weather/now", params);
//System.out.println(weatherData); System.out.println(weatherData);
try { try {
Thread.sleep(200); Thread.sleep(200);
} catch (Exception e) { } catch (Exception e) {
@ -148,6 +170,10 @@ public class ScheduledService {
nowWeather.setWeather(weatherData); nowWeather.setWeather(weatherData);
nowWeather.setCreateDate(now); nowWeather.setCreateDate(now);
nowWeather.setLastUpdateDate(now); nowWeather.setLastUpdateDate(now);
nowWeather.setProvince(city.getAdm1NameZh());
nowWeather.setCity(city.getAdm2NameZh());
nowWeather.setLocationNameZh(city.getLocationNameZh());
this.weatherService.saveNowWeather(nowWeather); this.weatherService.saveNowWeather(nowWeather);
// } // }
} else { } else {
@ -163,21 +189,22 @@ public class ScheduledService {
* @Param: null * @Param: null
*/ */
//@Scheduled(cron = "0 0 9 * * *")//每天9点执行一次 //@Scheduled(cron = "0 0 9 * * *")//每天9点执行一次
@Scheduled(cron = "0 16 * * * *")//每个小时执行一次
public void scheduledGetForecastWeather() { public void scheduledGetForecastWeather() {
System.out.println("scheduledGetForecastWeather"); System.out.println("scheduledGetForecastWeather");
System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); System.out.println("=====>>>>>使用cron:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
List<CityList> citys = this.cityService.findAllCitys(); List<HefengCity> citys = this.cityService.findAllCity();
if (citys != null && citys.size() > 0) { if (citys != null && citys.size() > 0) {
Date now = new Date(); Date now = new Date();
System.out.println(citys.size()); System.out.println(citys.size());
for (int i = 0; i < citys.size(); i++) { for (int i = 0; i < citys.size(); i++) {
CityList city = citys.get(i); HefengCity city = citys.get(i);
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
//c67db396fcdb416c959933d29e30db3d //c67db396fcdb416c959933d29e30db3d
params.put("key", "c67db396fcdb416c959933d29e30db3d"); params.put("key", "c67db396fcdb416c959933d29e30db3d");
params.put("location", city.getLocationId()); params.put("location", city.getLocationId());
String weatherData = OkHttpUtil.get("https://devapi.qweather.com/v7/weather/7d", params); String weatherData = OkHttpUtil.get("https://m573jftdb9.re.qweatherapi.com/v7/weather/7d", params);
//System.out.println(weatherData); //System.out.println(weatherData);
try { try {
Thread.sleep(500); Thread.sleep(500);
@ -196,6 +223,10 @@ public class ScheduledService {
forecastWeather.setWeather(weatherData); forecastWeather.setWeather(weatherData);
forecastWeather.setLastUpdateDate(now); forecastWeather.setLastUpdateDate(now);
forecastWeather.setCreateDate(now); forecastWeather.setCreateDate(now);
forecastWeather.setProvince(city.getAdm1NameZh());
forecastWeather.setCity(city.getAdm2NameZh());
forecastWeather.setLocationNameZh(city.getLocationNameZh());
this.weatherService.saveForecastWeather(forecastWeather); this.weatherService.saveForecastWeather(forecastWeather);
//} //}
} else { } else {
@ -778,7 +809,7 @@ public class ScheduledService {
* @description: * @description:
* @Param: null * @Param: null
*/ */
@Scheduled(cron = "0 30 * * * *") //@Scheduled(cron = "0 30 * * * *")
public void getWztfHistoryStormList() { public void getWztfHistoryStormList() {
for(int i=1945;i<2025;i++){ for(int i=1945;i<2025;i++){
getWztfStormList(String.valueOf(i)); getWztfStormList(String.valueOf(i));

@ -2,7 +2,6 @@ package com.rehome.jpahefengweather.service;
import com.rehome.jpahefengweather.dto.ForecastWeatherDto; import com.rehome.jpahefengweather.dto.ForecastWeatherDto;
import com.rehome.jpahefengweather.dto.NowWeatherDto; import com.rehome.jpahefengweather.dto.NowWeatherDto;
import com.rehome.jpahefengweather.entity.CityList;
import com.rehome.jpahefengweather.entity.ForecastWeather; import com.rehome.jpahefengweather.entity.ForecastWeather;
import com.rehome.jpahefengweather.entity.NowWeather; import com.rehome.jpahefengweather.entity.NowWeather;

@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@ -34,14 +34,14 @@ public class ReadCityExcelXls {
System.out.println("excel文件不存在"); System.out.println("excel文件不存在");
return; return;
} }
List<CityList> excelList = this.readExcel(file); List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来"); System.out.println("list中的数据打印出来");
if(excelList!=null&&excelList.size()>0){ if(excelList!=null&&excelList.size()>0){
System.out.println(String.valueOf(excelList.size())); System.out.println(String.valueOf(excelList.size()));
} }
if(excelList!=null){ if(excelList!=null){
for (int i = 0; i < excelList.size(); i++) { for (int i = 0; i < excelList.size(); i++) {
CityList city = excelList.get(i); HefengCity city = excelList.get(i);
Gson gson = new Gson(); Gson gson = new Gson();
System.out.print(gson.toJson(city)); System.out.print(gson.toJson(city));
System.out.println(); System.out.println();
@ -49,19 +49,19 @@ public class ReadCityExcelXls {
} }
} }
public List<CityList> getCityLists() { public List<HefengCity> getCityLists() {
// 要读取的Excel文件路径 // 要读取的Excel文件路径
File file = new File(this.filePath); File file = new File(this.filePath);
if (!file.exists()) { if (!file.exists()) {
System.out.println("excel文件不存在"); System.out.println("excel文件不存在");
return null; return null;
} }
List<CityList> excelList = this.readExcel(file); List<HefengCity> excelList = this.readExcel(file);
return excelList; return excelList;
} }
// 去读Excel的方法readExcel该方法的入口参数为一个File对象 // 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List<CityList> readExcel(File file) { public List<HefengCity> readExcel(File file) {
try { try {
//用流的方式先读取到你想要的excel的文件 //用流的方式先读取到你想要的excel的文件
FileInputStream fis=new FileInputStream(file); FileInputStream fis=new FileInputStream(file);
@ -72,7 +72,7 @@ public class ReadCityExcelXls {
// Excel的页签数量 // Excel的页签数量
int sheet_size = hb.getNumberOfSheets(); int sheet_size = hb.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) { for (int index = 0; index < sheet_size; index++) {
List<CityList> outerList = new ArrayList<CityList>(); List<HefengCity> outerList = new ArrayList<HefengCity>();
// 每个页签创建一个Sheet对象 // 每个页签创建一个Sheet对象
HSSFSheet sheet=hb.getSheetAt(index); HSSFSheet sheet=hb.getSheetAt(index);
//获取第一行 //获取第一行
@ -84,7 +84,7 @@ public class ReadCityExcelXls {
if(i==0){ if(i==0){
continue; continue;
} }
CityList city = new CityList(); HefengCity city = new HefengCity();
//获取哪一行i //获取哪一行i
Row row=sheet.getRow(i); Row row=sheet.getRow(i);
if (row!=null) { if (row!=null) {

@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
@ -34,14 +34,14 @@ public class ReadCityExcelXlsx {
System.out.println("excel文件不存在"); System.out.println("excel文件不存在");
return; return;
} }
List<CityList> excelList = this.readExcel(file); List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来"); System.out.println("list中的数据打印出来");
if (excelList != null && excelList.size() > 0) { if (excelList != null && excelList.size() > 0) {
System.out.println(String.valueOf(excelList.size())); System.out.println(String.valueOf(excelList.size()));
} }
if(excelList!=null){ if(excelList!=null){
for (int i = 0; i < excelList.size(); i++) { for (int i = 0; i < excelList.size(); i++) {
CityList city = excelList.get(i); HefengCity city = excelList.get(i);
Gson gson = new Gson(); Gson gson = new Gson();
System.out.print(gson.toJson(city)); System.out.print(gson.toJson(city));
System.out.println(); System.out.println();
@ -49,19 +49,19 @@ public class ReadCityExcelXlsx {
} }
} }
public List<CityList> getCityLists() { public List<HefengCity> getCityLists() {
// 要读取的Excel文件路径 // 要读取的Excel文件路径
File file = new File(this.filePath); File file = new File(this.filePath);
if (!file.exists()) { if (!file.exists()) {
System.out.println("excel文件不存在"); System.out.println("excel文件不存在");
return null; return null;
} }
List<CityList> excelList = this.readExcel(file); List<HefengCity> excelList = this.readExcel(file);
return excelList; return excelList;
} }
// 去读Excel的方法readExcel该方法的入口参数为一个File对象 // 去读Excel的方法readExcel该方法的入口参数为一个File对象
public List<CityList> readExcel(File file) { public List<HefengCity> readExcel(File file) {
try { try {
//用流的方式先读取到你想要的excel的文件 //用流的方式先读取到你想要的excel的文件
FileInputStream fis = new FileInputStream(file); FileInputStream fis = new FileInputStream(file);
@ -70,7 +70,7 @@ public class ReadCityExcelXlsx {
// Excel的页签数量 // Excel的页签数量
int sheet_size = workbook.getNumberOfSheets(); int sheet_size = workbook.getNumberOfSheets();
for (int index = 0; index < sheet_size; index++) { for (int index = 0; index < sheet_size; index++) {
List<CityList> outerList = new ArrayList<CityList>(); List<HefengCity> outerList = new ArrayList<HefengCity>();
// 每个页签创建一个Sheet对象 // 每个页签创建一个Sheet对象
XSSFSheet sheet = workbook.getSheetAt(index); XSSFSheet sheet = workbook.getSheetAt(index);
//获取第一行 //获取第一行
@ -82,7 +82,7 @@ public class ReadCityExcelXlsx {
if(i==0){ if(i==0){
continue; continue;
} }
CityList city = new CityList(); HefengCity city = new HefengCity();
//获取哪一行i //获取哪一行i
Row row = sheet.getRow(i); Row row = sheet.getRow(i);
if (row != null) { if (row != null) {

@ -7,7 +7,7 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengCity;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem;
@ -32,7 +32,7 @@ public class ReadExcelXls {
System.out.println("excel文件不存在"); System.out.println("excel文件不存在");
return; return;
} }
List<CityList> excelList = this.readExcel(file); List<HefengCity> excelList = this.readExcel(file);
System.out.println("list中的数据打印出来"); System.out.println("list中的数据打印出来");
if(excelList!=null&&excelList.size()>0){ if(excelList!=null&&excelList.size()>0){
System.out.println(String.valueOf(excelList.size())); System.out.println(String.valueOf(excelList.size()));

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

@ -1,5 +1,6 @@
package com.rehome.jpahefengweather.utils; package com.rehome.jpahefengweather.utils;
import java.io.IOException;
import java.security.KeyManagementException; import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
@ -12,10 +13,10 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager; import javax.net.ssl.X509TrustManager;
import com.liuhuiyu.spring_util.SpringUtil; import com.liuhuiyu.spring_util.SpringUtil;
import okhttp3.ConnectionPool; import okhttp3.*;
import okhttp3.OkHttpClient;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
/** /**
* Created by qhong on 2018/7/3 16:52 * Created by qhong on 2018/7/3 16:52
@ -76,6 +77,7 @@ public class OkHttpConfig {
@Bean @Bean
public OkHttpClient okHttpClient() { public OkHttpClient okHttpClient() {
return new OkHttpClient.Builder() return new OkHttpClient.Builder()
.addNetworkInterceptor(new TokenHeaderInterceptor())
.sslSocketFactory(sslSocketFactory(), x509TrustManager()) .sslSocketFactory(sslSocketFactory(), x509TrustManager())
.retryOnConnectionFailure(true)//是否开启缓存 .retryOnConnectionFailure(true)//是否开启缓存
.connectionPool(pool())//连接池 .connectionPool(pool())//连接池
@ -83,4 +85,20 @@ public class OkHttpConfig {
.readTimeout(30L, TimeUnit.SECONDS) .readTimeout(30L, TimeUnit.SECONDS)
.build(); .build();
} }
public static class TokenHeaderInterceptor implements Interceptor {
@NonNull
@Override
public Response intercept(@NonNull Chain chain) throws IOException {
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);
}
return chain.proceed(originalRequest);
}
}
} }

@ -1,15 +1,12 @@
package com.rehome.jpahefengweather.utils; package com.rehome.jpahefengweather.utils;
import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import com.liuhuiyu.spring_util.SpringUtil; import com.liuhuiyu.spring_util.SpringUtil;
import okhttp3.FormBody; import okhttp3.*;
import okhttp3.MediaType; import org.springframework.lang.NonNull;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/** /**
* Created by qhong on 2018/7/3 16:55 * Created by qhong on 2018/7/3 16:55
@ -130,4 +127,6 @@ public class OkHttpUtil{
.build(); .build();
return execNewCall(request); return execNewCall(request);
} }
} }

@ -14,7 +14,7 @@ spring:
#url: jdbc:mysql://192.168.1.28:3340/hefengweather?useUnicode=true&characterEncoding=utf-8&useSSL=false #url: jdbc:mysql://192.168.1.28:3340/hefengweather?useUnicode=true&characterEncoding=utf-8&useSSL=false
# url: jdbc:mysql://192.168.1.71:2881/hefengweather?useUnicode=true&characterEncoding=utf-8&useSSL=false # url: jdbc:mysql://192.168.1.71:2881/hefengweather?useUnicode=true&characterEncoding=utf-8&useSSL=false
driverClassName: com.mysql.cj.jdbc.Driver #com.mysql.cj.jdbc.Driver com.mysql.jdbc.Driver driverClassName: com.mysql.cj.jdbc.Driver #com.mysql.cj.jdbc.Driver com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.2.18:3306/nmcweather?useUnicode=true&characterEncoding=utf-8&useSSL=false url: jdbc:mysql://127.0.0.1:3306/hefengweather?useUnicode=true&characterEncoding=utf-8&useSSL=false
username: root username: root
password: Skyinno251, password: Skyinno251,
# driverClassName: oracle.jdbc.driver.OracleDriver # driverClassName: oracle.jdbc.driver.OracleDriver
@ -73,4 +73,4 @@ spring:
hibernate: hibernate:
ddl-auto: update # 第一次建表create 后面用update要不然每次重启都会新建表 ddl-auto: update # 第一次建表create 后面用update要不然每次重启都会新建表
rehome: rehome:
resources-path: /Users/wenfeihuang/storage # 外部资源文件存储路径 格式:/Users/edao/storage resources-path: /Users/edao/storage # 外部资源文件存储路径 格式:/Users/edao/storage

@ -1,9 +1,8 @@
package com.rehome.jpahefengweather.controller; package com.rehome.jpahefengweather.controller;
import com.google.gson.Gson;
import com.liuhuiyu.test.BaseServiceTest; import com.liuhuiyu.test.BaseServiceTest;
import com.liuhuiyu.util.model.Result; import com.liuhuiyu.util.model.Result;
import com.rehome.jpahefengweather.entity.CityList; import com.rehome.jpahefengweather.entity.HefengCity;
import com.rehome.jpahefengweather.service.CityService; import com.rehome.jpahefengweather.service.CityService;
import com.rehome.jpahefengweather.utils.TimestampUtil; import com.rehome.jpahefengweather.utils.TimestampUtil;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -54,8 +53,8 @@ public class WeatherControllerTest extends BaseServiceTest {
Timestamp endTime = TimestampUtil.beginTime(end); Timestamp endTime = TimestampUtil.beginTime(end);
Result<List<CityList>> result = this.weatherController.getCityList(); Result<List<HefengCity>> result = this.weatherController.getCityList();
List<CityList> citys = result.getData(); List<HefengCity> citys = result.getData();
//LOG.info("{}",new Gson().toJson(citys)); //LOG.info("{}",new Gson().toJson(citys));
System.out.println(citys.size()); System.out.println(citys.size());
}catch (Exception e){ }catch (Exception e){

Loading…
Cancel
Save