和风天气全部改用jpa,移除所有sql编码查询
parent
924942f065
commit
972426019c
@ -1,52 +1,26 @@
|
|||||||
package com.rehome.jpahefengweather.controller;
|
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.TyphoonBaseDto;
|
||||||
import com.rehome.jpahefengweather.dto.TyphoonTfidDto;
|
|
||||||
import com.rehome.jpahefengweather.dto.WztfStormInfoDto;
|
import com.rehome.jpahefengweather.dto.WztfStormInfoDto;
|
||||||
import com.rehome.jpahefengweather.entity.*;
|
import com.rehome.jpahefengweather.entity.*;
|
||||||
import com.rehome.jpahefengweather.service.WeatherService;
|
|
||||||
import com.rehome.jpahefengweather.service.WztfStormService;
|
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.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/typhoon")
|
@RequestMapping("/typhoon")
|
||||||
public class TyphoonController {
|
public class WztfwStormController {
|
||||||
@Resource
|
|
||||||
private ZjsltStormService zjsltStormService;
|
|
||||||
@Resource
|
@Resource
|
||||||
private WztfStormService wztfStormService;
|
private WztfStormService wztfStormService;
|
||||||
|
|
||||||
|
|
||||||
//region 根据年份获取台风列表
|
|
||||||
@PostMapping("/getStormListByYear")
|
|
||||||
@ApiOperation(value = "获取台风列表", notes = "获取台风列表")
|
|
||||||
@ApiImplicitParams(value = {
|
|
||||||
@ApiImplicitParam(name = "dto", value = "获取台风列表", dataTypeClass = TyphoonBaseDto.class, paramType = "body", required = true),
|
|
||||||
})
|
|
||||||
public Result<List<ZjsltStorm>> getStormListByYear(@Validated @RequestBody TyphoonBaseDto dto){
|
|
||||||
return Result.of(this.zjsltStormService.findByYear(dto.getYear()));
|
|
||||||
}
|
|
||||||
//endregion
|
|
||||||
|
|
||||||
//region 根据台风id获取单条台风数据
|
|
||||||
@PostMapping("/getTyphoonInfoByTfid")
|
|
||||||
@ApiOperation(value = "根据台风id获取单条台风数据", notes = "根据台风id获取单条台风数据")
|
|
||||||
@ApiImplicitParams(value = {
|
|
||||||
@ApiImplicitParam(name = "dto", value = "根据台风id获取单条台风数据", dataTypeClass = TyphoonTfidDto.class, paramType = "body", required = true),
|
|
||||||
})
|
|
||||||
public Result<TyphoonInfo> getTyphoonInfoByTfid(@Validated @RequestBody TyphoonTfidDto dto){
|
|
||||||
return Result.of(this.zjsltStormService.findTyphoonInfoByTfid(dto.getTfid()));
|
|
||||||
}
|
|
||||||
//endregion
|
//endregion
|
||||||
//region 根据年份获取台风列表
|
//region 根据年份获取台风列表
|
||||||
@PostMapping("/getWztfStormListByYear")
|
@PostMapping("/getWztfStormListByYear")
|
||||||
@ -1,22 +0,0 @@
|
|||||||
package com.rehome.jpahefengweather.dao;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author LiuHuiYu
|
|
||||||
* @version v1.0.0.0
|
|
||||||
* Created DateTime 2022-02-21 16:17
|
|
||||||
*/
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface FullWhere<T> {
|
|
||||||
/**
|
|
||||||
* 功能描述
|
|
||||||
*
|
|
||||||
* @param find 查询条件
|
|
||||||
* @param sqlBuilder sql
|
|
||||||
* @param parameterMap 参数列表
|
|
||||||
* @author LiuHuiYu
|
|
||||||
* Created DateTime 2022-02-21 16:19
|
|
||||||
*/
|
|
||||||
void fullWhere(T find, StringBuilder sqlBuilder, Map<String, Object> parameterMap);
|
|
||||||
}
|
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
package com.rehome.jpahefengweather.dto;
|
||||||
|
|
||||||
|
import com.rehome.jpahefengweather.entity.HefengFutureWeather;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
@Data
|
||||||
|
public class HefengWeatherResultDto extends HefengRealtimeWeatherDto{
|
||||||
|
//每日天气预报
|
||||||
|
private List<HefengFutureWeather> daily;
|
||||||
|
}
|
||||||
@ -0,0 +1,142 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2020-09-10 8:41
|
||||||
|
*/
|
||||||
|
public class LhyAssert {
|
||||||
|
static Function<String, RuntimeException> exceptionProxy;
|
||||||
|
|
||||||
|
private static RuntimeException throwEx(String message) {
|
||||||
|
if (exceptionProxy == null) {
|
||||||
|
return new RuntimeException(message);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return exceptionProxy.apply(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接受到异常信息后的异常抛出处理
|
||||||
|
*
|
||||||
|
* @param proxy 接受到异常信息后的代理。
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2021-12-10 14:43
|
||||||
|
*/
|
||||||
|
public static void exceptionProxy(Function<String, RuntimeException> proxy) {
|
||||||
|
exceptionProxy = proxy;
|
||||||
|
}
|
||||||
|
//region assertTrue
|
||||||
|
|
||||||
|
public static void assertTrue(boolean value, RuntimeException exception) {
|
||||||
|
if (!value) {
|
||||||
|
throw exception;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertTrue(boolean value, String message) {
|
||||||
|
assertTrue(value, throwEx(message));
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region assertFalse
|
||||||
|
|
||||||
|
public static void assertFalse(boolean value, String message) {
|
||||||
|
assertTrue(!value, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertFalse(boolean value, RuntimeException exception) {
|
||||||
|
assertTrue(!value, exception);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region assertNotNull
|
||||||
|
public static void assertNotNull(Object object, RuntimeException exception) {
|
||||||
|
assertTrue(object != null, exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param object 对象
|
||||||
|
*/
|
||||||
|
public static void assertNotNull(Object object, String message) {
|
||||||
|
assertTrue(object != null, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region assertNull
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象不为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param object 对象
|
||||||
|
*/
|
||||||
|
public static void assertNull(Object object, RuntimeException exception) {
|
||||||
|
assertTrue(object == null, exception);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象不为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param object 对象
|
||||||
|
*/
|
||||||
|
public static void assertNull(Object object, String message) {
|
||||||
|
assertTrue(object == null, message);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
//region 枚举模式拦截
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象不为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param value 对象
|
||||||
|
* @param resultEnum 错误枚举
|
||||||
|
*/
|
||||||
|
public static void assertTrue(boolean value, ResultEnum resultEnum) {
|
||||||
|
if (!value) {
|
||||||
|
throw new LhyException(resultEnum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param object 对象
|
||||||
|
* @param resultEnum 错误枚举
|
||||||
|
*/
|
||||||
|
public static void assertNotNull(Object object, ResultEnum resultEnum) {
|
||||||
|
assertTrue(object != null, resultEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对象不为空则抛出异常
|
||||||
|
*
|
||||||
|
* @param object 对象
|
||||||
|
* @param resultEnum 错误枚举
|
||||||
|
*/
|
||||||
|
public static void assertNull(Object object, ResultEnum resultEnum) {
|
||||||
|
assertTrue(object == null, resultEnum);
|
||||||
|
}
|
||||||
|
//endregion
|
||||||
|
|
||||||
|
|
||||||
|
public static void assertLen(String value, int min, int max, String message) {
|
||||||
|
assertNotNull(value, message + "未设定");
|
||||||
|
assertTrue(
|
||||||
|
(min <= 0 || value.length() >= min) &&
|
||||||
|
(max < 0 || value.length() <= max), message + "(长度范围[" + min + "-" + max + "])");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void assertLen(String value, int min, int max, RuntimeException exception) {
|
||||||
|
assertNotNull(value, exception);
|
||||||
|
assertTrue(value.length() >= min && value.length() <= max, exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,53 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自定义报错类
|
||||||
|
*
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2020-06-23 13:27
|
||||||
|
*/
|
||||||
|
public class LhyException extends RuntimeException {
|
||||||
|
private Integer errId;
|
||||||
|
/*
|
||||||
|
public ArchivesManagementException(Integer code, String message) {
|
||||||
|
super(message);
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
public LhyException(@NotNull ResultEnum resultEnum) {
|
||||||
|
super(resultEnum.getMessage());
|
||||||
|
this.errId = resultEnum.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LhyException(@NotNull ResultEnum resultEnum, String message) {
|
||||||
|
super(resultEnum.getMessage() + ":" + message);
|
||||||
|
this.errId = resultEnum.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LhyException(String message, @NotNull ResultEnum resultEnum) {
|
||||||
|
super(message + resultEnum.getMessage());
|
||||||
|
this.errId = resultEnum.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LhyException(String message, @NotNull ResultEnum resultEnum, String message1) {
|
||||||
|
super(message + resultEnum.getMessage() + message1);
|
||||||
|
this.errId = resultEnum.getCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
public LhyException(String message) {
|
||||||
|
super(message);
|
||||||
|
this.errId = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getErrId() {
|
||||||
|
return errId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrId(Integer errId) {
|
||||||
|
this.errId = errId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2021-03-23 16:49
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface MapToT<T> {
|
||||||
|
/**
|
||||||
|
* Object 转换成 类型 T
|
||||||
|
* @param map Map<String,Object>
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
T mapToT(Map<String,Object> map);
|
||||||
|
}
|
||||||
@ -0,0 +1,637 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import org.apache.commons.beanutils.BeanUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2021-01-20 14:53
|
||||||
|
*/
|
||||||
|
public class MapUtil {
|
||||||
|
|
||||||
|
boolean throwException = false;
|
||||||
|
|
||||||
|
public boolean isThrowException() {
|
||||||
|
return throwException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrowException(boolean throwException) {
|
||||||
|
this.throwException = throwException;
|
||||||
|
}
|
||||||
|
|
||||||
|
//region 静态方法
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map对象转换成Map<String, Object>对象
|
||||||
|
*
|
||||||
|
* @param obj Map对象
|
||||||
|
* @return Map<String, Object>对象
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> mapObjectToStringKeyMap(Object obj) {
|
||||||
|
if (obj == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Map<?, ?>) {
|
||||||
|
Map<?, ?> map = (Map<?, ?>) obj;
|
||||||
|
Map<String, Object> resMap = new HashMap<>(map.size());
|
||||||
|
map.forEach((k, v) -> resMap.put(k.toString(), v));
|
||||||
|
return resMap;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new HashMap<>(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getMapObjectValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapObjectValue(map, key, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getMapObjectValue(Map<String, Object> map, String key, Object defValue) {
|
||||||
|
return map.getOrDefault(key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMapStringValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapStringValue(map, key, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取字符串(如果key 不存在返回 “”)
|
||||||
|
*
|
||||||
|
* @param map map
|
||||||
|
* @param key key
|
||||||
|
* @return 字符串
|
||||||
|
*/
|
||||||
|
public static String getMapStringValue(Map<String, Object> map, String key, String defValue) {
|
||||||
|
if (map.containsKey(key)) {
|
||||||
|
Object obj = map.get(key);
|
||||||
|
return obj == null ? defValue : obj.toString();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getMapIntegerValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapIntegerValue(map, key, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer getMapIntegerValue(Map<String, Object> map, String key, Integer defValue) {
|
||||||
|
Object obj = map.getOrDefault(key, defValue);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Number) {
|
||||||
|
return ((Number) obj).intValue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String value = obj.toString();
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(value);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Float getMapFloatValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapFloatValue(map, key, 0F);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Float getMapFloatValue(Map<String, Object> map, String key, Float defValue) {
|
||||||
|
Object obj = map.getOrDefault(key, defValue);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Number) {
|
||||||
|
return ((Number) obj).floatValue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String value = obj.toString();
|
||||||
|
try {
|
||||||
|
return Float.parseFloat(value);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getMapLongValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapLongValue(map, key, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Long getMapLongValue(Map<String, Object> map, String key, Long defValue) {
|
||||||
|
Object obj = map.getOrDefault(key, defValue);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Number) {
|
||||||
|
return ((Number) obj).longValue();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String value = obj.toString();
|
||||||
|
try {
|
||||||
|
return Long.parseLong(value);
|
||||||
|
}
|
||||||
|
catch (NumberFormatException ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getMapBooleanValue(Map<String, Object> map, String key) {
|
||||||
|
return getMapBooleanValue(map, key, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Boolean getMapBooleanValue(Map<String, Object> map, String key, boolean defValue) {
|
||||||
|
Object obj = map.getOrDefault(key, defValue);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Boolean) {
|
||||||
|
return (Boolean) obj;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Boolean.parseBoolean(obj.toString());
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 map 中的 可转化为 int 的数字转化为 int
|
||||||
|
*
|
||||||
|
* @param resultMap map
|
||||||
|
* @return 修正后的map
|
||||||
|
*/
|
||||||
|
public static Map<String, Object> mapNumberToInt(Map<?, ?> resultMap) {
|
||||||
|
Map<String, Object> res = new HashMap<>(resultMap.size());
|
||||||
|
for (Object keyObj : resultMap.keySet()) {
|
||||||
|
String key = keyObj.toString();
|
||||||
|
if (resultMap.get(key) instanceof Double) {
|
||||||
|
Double value = (Double) resultMap.get(key);
|
||||||
|
if (value.intValue() == value) {
|
||||||
|
res.put(key, ((Double) resultMap.get(key)).intValue());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.put(key, resultMap.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (resultMap.get(key) instanceof List<?>) {
|
||||||
|
res.put(key, listNumberToInt((List<?>) resultMap.get(key)));
|
||||||
|
}
|
||||||
|
else if (resultMap.get(key) instanceof Map<?, ?>) {
|
||||||
|
res.put(key, mapNumberToInt((Map<?, ?>) resultMap.get(key)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.put(key, resultMap.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 list 中的 可转化为 int 的数字转化为 int
|
||||||
|
*
|
||||||
|
* @param list list
|
||||||
|
* @return 修正后的list
|
||||||
|
*/
|
||||||
|
public static List<Object> listNumberToInt(List<?> list) {
|
||||||
|
List<Object> res = new ArrayList<>(list.size());
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof Number) {
|
||||||
|
Double value = (Double) o;
|
||||||
|
if (value.intValue() == value) {
|
||||||
|
Object v = value.intValue();
|
||||||
|
res.add(v);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (o instanceof Map<?, ?>) {
|
||||||
|
res.add(mapNumberToInt((Map<?, ?>) o));
|
||||||
|
}
|
||||||
|
else if (o instanceof List<?>) {
|
||||||
|
res.add(listNumberToInt((List<?>) o));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.add(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
public static <T> T mapToObject(Map<String, Object> map, T t) {
|
||||||
|
if (map == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
BeanUtils.populate(t, map);
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//endregion
|
||||||
|
public static Map<String, Object> mapOfJsonString(String jsonString) {
|
||||||
|
try {
|
||||||
|
Map<String, Object> resultMap = new Gson().fromJson(jsonString, new TypeToken<Map<String, Object>>() {
|
||||||
|
}.getType());
|
||||||
|
return mapDoubleToInt(resultMap);
|
||||||
|
}
|
||||||
|
catch (JsonSyntaxException e) {
|
||||||
|
throw new RuntimeException("无法解析成Map格式数据");
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Map序列化成指定类
|
||||||
|
*
|
||||||
|
* @param map map
|
||||||
|
* @param classOfT T.class
|
||||||
|
* @param <T> 得到的类
|
||||||
|
* @return T
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2022-01-22 16:42
|
||||||
|
*/
|
||||||
|
public static <T> T fromMap(Map<String, Object> map, Class<T> classOfT) {
|
||||||
|
String json = new Gson().toJson(map);
|
||||||
|
return new Gson().fromJson(json, classOfT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将Map序列化成指定类
|
||||||
|
*
|
||||||
|
* @param map map
|
||||||
|
* @param classOfT T.class
|
||||||
|
* @param <T> 得到的类
|
||||||
|
* @return T
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2022-01-22 16:42
|
||||||
|
*/
|
||||||
|
public static <T> T fromMap(Map<String, Object> map, Class<T> classOfT, GsonAdapter[] typeAdapter) {
|
||||||
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
|
for (GsonAdapter gsonAdapter : typeAdapter) {
|
||||||
|
gsonBuilder.registerTypeAdapter(gsonAdapter.type, gsonAdapter.typeAdapter);
|
||||||
|
}
|
||||||
|
Gson gson = gsonBuilder.create();
|
||||||
|
String json = gson.toJson(map);
|
||||||
|
return new Gson().fromJson(json, classOfT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class GsonAdapter {
|
||||||
|
Type type;
|
||||||
|
Object typeAdapter;
|
||||||
|
|
||||||
|
public GsonAdapter(Type type, Object typeAdapter) {
|
||||||
|
this.type = type;
|
||||||
|
this.typeAdapter = typeAdapter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Object> mapDoubleToInt(Map<?, ?> resultMap) {
|
||||||
|
Map<String, Object> res = new HashMap<>(resultMap.size());
|
||||||
|
for (Object keyObj : resultMap.keySet()) {
|
||||||
|
String key = keyObj.toString();
|
||||||
|
if (resultMap.get(key) instanceof Double) {
|
||||||
|
Double value = (Double) resultMap.get(key);
|
||||||
|
if (value.intValue() == value) {
|
||||||
|
res.put(key, ((Double) resultMap.get(key)).intValue());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.put(key, resultMap.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (resultMap.get(key) instanceof List<?>) {
|
||||||
|
res.put(key, listDoubleToInt((List<?>) resultMap.get(key)));
|
||||||
|
}
|
||||||
|
else if (resultMap.get(key) instanceof Map<?, ?>) {
|
||||||
|
res.put(key, mapDoubleToInt((Map<?, ?>) resultMap.get(key)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.put(key, resultMap.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Object> listDoubleToInt(List<?> list) {
|
||||||
|
List<Object> res = new ArrayList<>(list.size());
|
||||||
|
for (Object o : list) {
|
||||||
|
if (o instanceof Number) {
|
||||||
|
Double value = (Double) o;
|
||||||
|
if (value.intValue() == value) {
|
||||||
|
Object v = value.intValue();
|
||||||
|
res.add(v);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (o instanceof Map<?, ?>) {
|
||||||
|
res.add(mapDoubleToInt((Map<?, ?>) o));
|
||||||
|
}
|
||||||
|
else if (o instanceof List<?>) {
|
||||||
|
res.add(listDoubleToInt((List<?>) o));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
res.add(o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MapUtil ofJsonString(String jsonString) {
|
||||||
|
Map<String, Object> map = mapOfJsonString(jsonString);
|
||||||
|
return new MapUtil(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Map<String, Object> map;
|
||||||
|
|
||||||
|
public MapUtil(Map<String, Object> map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringValue(String key) {
|
||||||
|
return getMapStringValue(this.map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringValue(String key, String defValue) {
|
||||||
|
return getMapStringValue(this.map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIntegerValue(String key) {
|
||||||
|
return getMapIntegerValue(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getIntegerValue(String key, Integer defValue) {
|
||||||
|
return getMapIntegerValue(map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getFloatValue(String key) {
|
||||||
|
return getMapFloatValue(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getFloatValue(String key, Float defValue) {
|
||||||
|
return getMapFloatValue(map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLongValue(String key) {
|
||||||
|
return getMapLongValue(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getLongValue(String key, Long defValue) {
|
||||||
|
return getMapLongValue(map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObjectValue(String key) {
|
||||||
|
return getMapObjectValue(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getObjectValue(String key, Object defValue) {
|
||||||
|
return getMapObjectValue(map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getValue(String key, T defValue) {
|
||||||
|
Object obj = map.getOrDefault(key, defValue);
|
||||||
|
if (obj.getClass().equals(defValue.getClass())) {
|
||||||
|
return (T) obj;
|
||||||
|
}
|
||||||
|
else if (throwException) {
|
||||||
|
throw new RuntimeException("类型转换失败。");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getBooleanValue(String key) {
|
||||||
|
return getMapBooleanValue(map, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Boolean getBooleanValue(String key, boolean defValue) {
|
||||||
|
return getMapBooleanValue(map, key, defValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTimestampValue(String key) {
|
||||||
|
return getTimestampValue(key, Timestamp.valueOf(LocalDateTime.now()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Timestamp getTimestampValue(String key, Timestamp defValue) {
|
||||||
|
Object obj = map.get(key);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Timestamp) {
|
||||||
|
return (Timestamp) obj;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Number) {
|
||||||
|
return new Timestamp(((Number) obj).longValue());
|
||||||
|
}
|
||||||
|
else if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
return Timestamp.valueOf((String) obj);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBigDecimal(String key) {
|
||||||
|
return getBigDecimal(key, BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getBigDecimal(String key, BigDecimal defValue) {
|
||||||
|
Object obj = map.get(key);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else if (obj instanceof Double) {
|
||||||
|
return BigDecimal.valueOf((Double) obj);
|
||||||
|
}
|
||||||
|
else if (obj instanceof Long) {
|
||||||
|
return BigDecimal.valueOf((Long) obj);
|
||||||
|
}
|
||||||
|
else if (obj instanceof Number) {
|
||||||
|
return BigDecimal.valueOf(((Number) obj).doubleValue());
|
||||||
|
}
|
||||||
|
else if (obj instanceof String) {
|
||||||
|
try {
|
||||||
|
return new BigDecimal((String) obj);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T getValue(String key, Function<Object, T> function) {
|
||||||
|
return function.apply(map.getOrDefault(key, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> List<T> getListValue(String key, Function<Object, T> function) {
|
||||||
|
Function<Object, ResInfo<T>> function2 = (obj) -> new ResInfo<>(true, function.apply(obj));
|
||||||
|
return getCollectionValueAllowJudgment(key, function2, () -> new ArrayList<>(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection获取(List;Set)
|
||||||
|
*
|
||||||
|
* @param key 键值
|
||||||
|
* @param function 转换
|
||||||
|
* @param initializeCollection 初始化 Collection
|
||||||
|
* @return java.util.Collection<T>
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2021-08-06 9:50
|
||||||
|
*/
|
||||||
|
public <T, R extends Collection<T>> R getCollectionValue(String key, Function<Object, T> function, Supplier<R> initializeCollection) {
|
||||||
|
Function<Object, ResInfo<T>> function2 = (obj) -> new ResInfo<>(true, function.apply(obj));
|
||||||
|
return getCollectionValueAllowJudgment(key, function2, initializeCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection获取(List;Set)
|
||||||
|
*
|
||||||
|
* @param key 键值
|
||||||
|
* @param function 转换
|
||||||
|
* @param initializeCollection 初始化 Collection
|
||||||
|
* @return java.util.Collection<T>
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2021-08-06 9:50
|
||||||
|
*/
|
||||||
|
public <T, R extends Collection<T>> R getCollectionValueAllowJudgment(String key, Function<Object, ResInfo<T>> function, Supplier<R> initializeCollection) {
|
||||||
|
R resList = initializeCollection.get();
|
||||||
|
if (this.map.containsKey(key)) {
|
||||||
|
Object obj = this.map.get(key);
|
||||||
|
if (obj instanceof Collection<?>) {
|
||||||
|
Collection<?> list = (Collection<?>) obj;
|
||||||
|
list.forEach(item -> {
|
||||||
|
ResInfo<T> resInfo = function.apply(item);
|
||||||
|
if (resInfo.res) {
|
||||||
|
resList.add(resInfo.resData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return resList;
|
||||||
|
}
|
||||||
|
else if (this.throwException) {
|
||||||
|
throw new RuntimeException("无法解析非List数据");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return resList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (this.throwException) {
|
||||||
|
throw new RuntimeException("不存在的键值。");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return resList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getMap(String key) {
|
||||||
|
return getMap(key, new HashMap<>(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getMap(String key, Map<String, Object> defValue) {
|
||||||
|
Object obj = map.get(key);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
return mapObjectToStringKeyMap(obj);
|
||||||
|
}
|
||||||
|
catch (Exception ignored) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> PageImpl<T> getPageImpl(String key, MapToT<T> mapToT) {
|
||||||
|
PageImpl<T> def = new PageImpl<>(new ArrayList<>(0));
|
||||||
|
return getPageImpl(key, mapToT, def);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> PageImpl<T> getPageImpl(String key, MapToT<T> mapToT, PageImpl<T> defValue) {
|
||||||
|
Object obj = map.get(key);
|
||||||
|
if (obj == null) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
try {
|
||||||
|
Map<String, Object> map = mapObjectToStringKeyMap(obj);
|
||||||
|
return mapToPageImpl(map, mapToT);
|
||||||
|
}
|
||||||
|
catch (Exception ignored) {
|
||||||
|
return defValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取ResultMap模型中的分页数据
|
||||||
|
*
|
||||||
|
* @param map 原始map数据
|
||||||
|
* @param mapToT 转换函数
|
||||||
|
* @param <T> 泛型
|
||||||
|
* @return org.springframework.data.domain.PageImpl<T>
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* Created DateTime 2021-11-29 17:18
|
||||||
|
*/
|
||||||
|
public static <T> @NotNull PageImpl<T> mapToPageImpl(Map<String, Object> map, MapToT<T> mapToT) {
|
||||||
|
MapUtil mapUtil = new MapUtil(map);
|
||||||
|
int number = mapUtil.getIntegerValue("number", 0);
|
||||||
|
int size = mapUtil.getIntegerValue("size", 0);
|
||||||
|
PageRequest pageable = PageRequest.of(number, size);
|
||||||
|
long totalElements = mapUtil.getLongValue("totalElements", 0L);
|
||||||
|
List<T> list = mapUtil.getListValue("content", obj -> mapToT.mapToT(MapUtil.mapObjectToStringKeyMap(obj)));
|
||||||
|
return new PageImpl<>(list, pageable, totalElements);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ResInfo<T> {
|
||||||
|
Boolean res;
|
||||||
|
T resData;
|
||||||
|
|
||||||
|
public ResInfo(Boolean res, T resData) {
|
||||||
|
this.res = res;
|
||||||
|
this.resData = resData;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T cloneObj(T a, Class<T> classOfT) {
|
||||||
|
String json = new Gson().toJson(a);
|
||||||
|
return new Gson().fromJson(json, classOfT);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2021-03-23 16:48
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface ObjectToT<T> {
|
||||||
|
/**
|
||||||
|
* Object 转换成 类型 T
|
||||||
|
* @param o Object
|
||||||
|
* @return T
|
||||||
|
*/
|
||||||
|
T objectToT(Object o);
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回信息集合
|
||||||
|
*
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2020-07-08 11:45
|
||||||
|
*/
|
||||||
|
public enum ResultEnum {
|
||||||
|
/**
|
||||||
|
* 成功
|
||||||
|
*/
|
||||||
|
SUCCESS(0, "成功"),
|
||||||
|
CUSTOM_ERROR(-1,"自定义错误"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
ResultEnum(Integer code, String message) {
|
||||||
|
this.code = code;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Result解析报错
|
||||||
|
* @author LiuHuiYu
|
||||||
|
* @version v1.0.0.0
|
||||||
|
* Created DateTime 2021-12-10 16:25
|
||||||
|
*/
|
||||||
|
public class ResultException extends LhyException{
|
||||||
|
|
||||||
|
public ResultException(String message) {
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,240 @@
|
|||||||
|
package org.hibernate.cfg;
|
||||||
|
|
||||||
|
|
||||||
|
import org.hibernate.AnnotationException;
|
||||||
|
import org.hibernate.annotations.Any;
|
||||||
|
import org.hibernate.annotations.ManyToAny;
|
||||||
|
import org.hibernate.annotations.Target;
|
||||||
|
import org.hibernate.annotations.Type;
|
||||||
|
import org.hibernate.annotations.common.reflection.XClass;
|
||||||
|
import org.hibernate.annotations.common.reflection.XProperty;
|
||||||
|
import org.hibernate.boot.MappingException;
|
||||||
|
import org.hibernate.boot.jaxb.Origin;
|
||||||
|
import org.hibernate.boot.jaxb.SourceType;
|
||||||
|
import org.hibernate.cfg.annotations.HCANNHelper;
|
||||||
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解决SpringDataJpa实体类中属性顺序与数据库中生成字段顺序不一致的问题
|
||||||
|
* */
|
||||||
|
|
||||||
|
class PropertyContainer {
|
||||||
|
private static final CoreMessageLogger LOG = (CoreMessageLogger)Logger.getMessageLogger(CoreMessageLogger.class, PropertyContainer.class.getName());
|
||||||
|
private final XClass xClass;
|
||||||
|
private final XClass entityAtStake;
|
||||||
|
private final AccessType classLevelAccessType;
|
||||||
|
private final List<XProperty> persistentAttributes;
|
||||||
|
|
||||||
|
PropertyContainer(XClass clazz, XClass entityAtStake, AccessType defaultClassLevelAccessType) {
|
||||||
|
this.xClass = clazz;
|
||||||
|
this.entityAtStake = entityAtStake;
|
||||||
|
if (defaultClassLevelAccessType == AccessType.DEFAULT) {
|
||||||
|
defaultClassLevelAccessType = AccessType.PROPERTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
AccessType localClassLevelAccessType = this.determineLocalClassDefinedAccessStrategy();
|
||||||
|
|
||||||
|
assert localClassLevelAccessType != null;
|
||||||
|
|
||||||
|
this.classLevelAccessType = localClassLevelAccessType != AccessType.DEFAULT ? localClassLevelAccessType : defaultClassLevelAccessType;
|
||||||
|
|
||||||
|
assert this.classLevelAccessType == AccessType.FIELD || this.classLevelAccessType == AccessType.PROPERTY;
|
||||||
|
|
||||||
|
List<XProperty> fields = this.xClass.getDeclaredProperties(AccessType.FIELD.getType());
|
||||||
|
List<XProperty> getters = this.xClass.getDeclaredProperties(AccessType.PROPERTY.getType());
|
||||||
|
this.preFilter(fields, getters);
|
||||||
|
Map<String, XProperty> persistentAttributesFromGetters = new HashMap();
|
||||||
|
LinkedHashMap<String, XProperty> localAttributeMap = new LinkedHashMap();
|
||||||
|
collectPersistentAttributesUsingLocalAccessType(this.xClass, localAttributeMap, persistentAttributesFromGetters, fields, getters);
|
||||||
|
collectPersistentAttributesUsingClassLevelAccessType(this.xClass, this.classLevelAccessType, localAttributeMap, persistentAttributesFromGetters, fields, getters);
|
||||||
|
this.persistentAttributes = verifyAndInitializePersistentAttributes(this.xClass, localAttributeMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void preFilter(List<XProperty> fields, List<XProperty> getters) {
|
||||||
|
Iterator propertyIterator = fields.iterator();
|
||||||
|
|
||||||
|
XProperty property;
|
||||||
|
while(propertyIterator.hasNext()) {
|
||||||
|
property = (XProperty)propertyIterator.next();
|
||||||
|
if (mustBeSkipped(property)) {
|
||||||
|
propertyIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyIterator = getters.iterator();
|
||||||
|
|
||||||
|
while(propertyIterator.hasNext()) {
|
||||||
|
property = (XProperty)propertyIterator.next();
|
||||||
|
if (mustBeSkipped(property)) {
|
||||||
|
propertyIterator.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void collectPersistentAttributesUsingLocalAccessType(XClass xClass, LinkedHashMap<String, XProperty> persistentAttributeMap, Map<String, XProperty> persistentAttributesFromGetters, List<XProperty> fields, List<XProperty> getters) {
|
||||||
|
Iterator propertyIterator = fields.iterator();
|
||||||
|
|
||||||
|
XProperty xProperty;
|
||||||
|
Access localAccessAnnotation;
|
||||||
|
while(propertyIterator.hasNext()) {
|
||||||
|
xProperty = (XProperty)propertyIterator.next();
|
||||||
|
localAccessAnnotation = (Access)xProperty.getAnnotation(Access.class);
|
||||||
|
if (localAccessAnnotation != null && localAccessAnnotation.value() == javax.persistence.AccessType.FIELD) {
|
||||||
|
propertyIterator.remove();
|
||||||
|
persistentAttributeMap.put(xProperty.getName(), xProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
propertyIterator = getters.iterator();
|
||||||
|
|
||||||
|
while(propertyIterator.hasNext()) {
|
||||||
|
xProperty = (XProperty)propertyIterator.next();
|
||||||
|
localAccessAnnotation = (Access)xProperty.getAnnotation(Access.class);
|
||||||
|
if (localAccessAnnotation != null && localAccessAnnotation.value() == javax.persistence.AccessType.PROPERTY) {
|
||||||
|
propertyIterator.remove();
|
||||||
|
String name = xProperty.getName();
|
||||||
|
XProperty previous = (XProperty)persistentAttributesFromGetters.get(name);
|
||||||
|
if (previous != null) {
|
||||||
|
throw new MappingException(LOG.ambiguousPropertyMethods(xClass.getName(), HCANNHelper.annotatedElementSignature(previous), HCANNHelper.annotatedElementSignature(xProperty)), new Origin(SourceType.ANNOTATION, xClass.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
persistentAttributeMap.put(name, xProperty);
|
||||||
|
persistentAttributesFromGetters.put(name, xProperty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void collectPersistentAttributesUsingClassLevelAccessType(XClass xClass, AccessType classLevelAccessType, LinkedHashMap<String, XProperty> persistentAttributeMap, Map<String, XProperty> persistentAttributesFromGetters, List<XProperty> fields, List<XProperty> getters) {
|
||||||
|
Iterator var6;
|
||||||
|
XProperty getter;
|
||||||
|
if (classLevelAccessType == AccessType.FIELD) {
|
||||||
|
var6 = fields.iterator();
|
||||||
|
|
||||||
|
while(var6.hasNext()) {
|
||||||
|
getter = (XProperty)var6.next();
|
||||||
|
if (!persistentAttributeMap.containsKey(getter.getName())) {
|
||||||
|
persistentAttributeMap.put(getter.getName(), getter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
var6 = getters.iterator();
|
||||||
|
|
||||||
|
while(var6.hasNext()) {
|
||||||
|
getter = (XProperty)var6.next();
|
||||||
|
String name = getter.getName();
|
||||||
|
XProperty previous = (XProperty)persistentAttributesFromGetters.get(name);
|
||||||
|
if (previous != null) {
|
||||||
|
throw new MappingException(LOG.ambiguousPropertyMethods(xClass.getName(), HCANNHelper.annotatedElementSignature(previous), HCANNHelper.annotatedElementSignature(getter)), new Origin(SourceType.ANNOTATION, xClass.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!persistentAttributeMap.containsKey(name)) {
|
||||||
|
persistentAttributeMap.put(getter.getName(), getter);
|
||||||
|
persistentAttributesFromGetters.put(name, getter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public XClass getEntityAtStake() {
|
||||||
|
return this.entityAtStake;
|
||||||
|
}
|
||||||
|
|
||||||
|
public XClass getDeclaringClass() {
|
||||||
|
return this.xClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AccessType getClassLevelAccessType() {
|
||||||
|
return this.classLevelAccessType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
|
@Deprecated
|
||||||
|
public Collection<XProperty> getProperties() {
|
||||||
|
return Collections.unmodifiableCollection(this.persistentAttributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Iterable<XProperty> propertyIterator() {
|
||||||
|
return this.persistentAttributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<XProperty> verifyAndInitializePersistentAttributes(XClass xClass, Map<String, XProperty> localAttributeMap) {
|
||||||
|
ArrayList<XProperty> output = new ArrayList(localAttributeMap.size());
|
||||||
|
Iterator var3 = localAttributeMap.values().iterator();
|
||||||
|
|
||||||
|
while(var3.hasNext()) {
|
||||||
|
XProperty xProperty = (XProperty)var3.next();
|
||||||
|
if (!xProperty.isTypeResolved() && !discoverTypeWithoutReflection(xProperty)) {
|
||||||
|
String msg = "Property " + StringHelper.qualify(xClass.getName(), xProperty.getName()) + " has an unbound type and no explicit target entity. Resolve this Generic usage issue or set an explicit target attribute (eg @OneToMany(target=) or use an explicit @Type";
|
||||||
|
throw new AnnotationException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.add(xProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CollectionHelper.toSmallList(output);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AccessType determineLocalClassDefinedAccessStrategy() {
|
||||||
|
AccessType hibernateDefinedAccessType = AccessType.DEFAULT;
|
||||||
|
AccessType jpaDefinedAccessType = AccessType.DEFAULT;
|
||||||
|
org.hibernate.annotations.AccessType accessType = (org.hibernate.annotations.AccessType)this.xClass.getAnnotation(org.hibernate.annotations.AccessType.class);
|
||||||
|
if (accessType != null) {
|
||||||
|
hibernateDefinedAccessType = AccessType.getAccessStrategy(accessType.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
Access access = (Access)this.xClass.getAnnotation(Access.class);
|
||||||
|
if (access != null) {
|
||||||
|
jpaDefinedAccessType = AccessType.getAccessStrategy(access.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hibernateDefinedAccessType != AccessType.DEFAULT && jpaDefinedAccessType != AccessType.DEFAULT && hibernateDefinedAccessType != jpaDefinedAccessType) {
|
||||||
|
throw new org.hibernate.MappingException("@AccessType and @Access specified with contradicting values. Use of @Access only is recommended. ");
|
||||||
|
} else {
|
||||||
|
AccessType classDefinedAccessType;
|
||||||
|
if (hibernateDefinedAccessType != AccessType.DEFAULT) {
|
||||||
|
classDefinedAccessType = hibernateDefinedAccessType;
|
||||||
|
} else {
|
||||||
|
classDefinedAccessType = jpaDefinedAccessType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return classDefinedAccessType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean discoverTypeWithoutReflection(XProperty p) {
|
||||||
|
if (p.isAnnotationPresent(OneToOne.class) && !((OneToOne)p.getAnnotation(OneToOne.class)).targetEntity().equals(Void.TYPE)) {
|
||||||
|
return true;
|
||||||
|
} else if (p.isAnnotationPresent(OneToMany.class) && !((OneToMany)p.getAnnotation(OneToMany.class)).targetEntity().equals(Void.TYPE)) {
|
||||||
|
return true;
|
||||||
|
} else if (p.isAnnotationPresent(ManyToOne.class) && !((ManyToOne)p.getAnnotation(ManyToOne.class)).targetEntity().equals(Void.TYPE)) {
|
||||||
|
return true;
|
||||||
|
} else if (p.isAnnotationPresent(ManyToMany.class) && !((ManyToMany)p.getAnnotation(ManyToMany.class)).targetEntity().equals(Void.TYPE)) {
|
||||||
|
return true;
|
||||||
|
} else if (p.isAnnotationPresent(Any.class)) {
|
||||||
|
return true;
|
||||||
|
} else if (p.isAnnotationPresent(ManyToAny.class)) {
|
||||||
|
if (!p.isCollection() && !p.isArray()) {
|
||||||
|
throw new AnnotationException("@ManyToAny used on a non collection non array property: " + p.getName());
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (p.isAnnotationPresent(Type.class)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return p.isAnnotationPresent(Target.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean mustBeSkipped(XProperty property) {
|
||||||
|
return property.isAnnotationPresent(Transient.class) || "net.sf.cglib.transform.impl.InterceptFieldCallback".equals(property.getType().getName()) || "org.hibernate.bytecode.internal.javassist.FieldHandler".equals(property.getType().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,65 +0,0 @@
|
|||||||
package com.rehome.jpahefengweather.controller;
|
|
||||||
|
|
||||||
import com.liuhuiyu.test.BaseServiceTest;
|
|
||||||
import com.liuhuiyu.util.model.Result;
|
|
||||||
import com.rehome.jpahefengweather.entity.HefengCity;
|
|
||||||
import com.rehome.jpahefengweather.service.CityService;
|
|
||||||
import com.rehome.jpahefengweather.utils.TimestampUtil;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author HuangWenFei
|
|
||||||
* @version v1.0.0.0
|
|
||||||
* Created DateTime 2022-05-01 15:45
|
|
||||||
*/
|
|
||||||
public class WeatherControllerTest extends BaseServiceTest {
|
|
||||||
|
|
||||||
private static final Logger LOG= LogManager.getLogger(WeatherControllerTest.class);
|
|
||||||
private CityService cityService;
|
|
||||||
private WeatherController weatherController;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setCityService(CityService cityService) {
|
|
||||||
this.cityService = cityService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setWeatherController(WeatherController weatherController) {
|
|
||||||
this.weatherController = weatherController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAllCitys() {
|
|
||||||
try {
|
|
||||||
SimpleDateFormat sdFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
||||||
String now = sdFormat.format(new Date());
|
|
||||||
Timestamp beginTime = TimestampUtil.beginTime(now);
|
|
||||||
Calendar calendar=Calendar.getInstance();
|
|
||||||
calendar.add(Calendar.DATE,10);
|
|
||||||
|
|
||||||
Date date=sdFormat.parse(sdFormat.format(calendar.getTime()));
|
|
||||||
Calendar calendarOne=Calendar.getInstance();
|
|
||||||
calendarOne.setTime(date);
|
|
||||||
String end = sdFormat.format(calendarOne.getTime());
|
|
||||||
Timestamp endTime = TimestampUtil.beginTime(end);
|
|
||||||
|
|
||||||
|
|
||||||
Result<List<HefengCity>> result = this.weatherController.getCityList();
|
|
||||||
List<HefengCity> citys = result.getData();
|
|
||||||
//LOG.info("{}",new Gson().toJson(citys));
|
|
||||||
System.out.println(citys.size());
|
|
||||||
}catch (Exception e){
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue