修整代码
This commit is contained in:
parent
20d78cb487
commit
59978b6be5
@ -3,8 +3,7 @@ package com.ycwl.basic.config;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.ycwl.basic.interceptor.AuthInterceptor;
|
||||
import com.ycwl.basic.xss.XssJacksonDeserializer;
|
||||
import com.ycwl.basic.xss.XssJacksonSerializer;
|
||||
import com.ycwl.basic.stats.interceptor.StatsInterceptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@ -29,13 +28,17 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private AuthInterceptor authInterceptor;
|
||||
@Autowired
|
||||
private StatsInterceptor statsInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(authInterceptor)
|
||||
// 拦截除指定接口外的所有请求,通过判断 注解 来决定是否需要做登录验证
|
||||
.addPathPatterns("/**")
|
||||
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/api-docs", "/doc.html/**", "/error", "/csrf", "/");
|
||||
.excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/api-docs", "/doc.html/**", "/error", "/");
|
||||
registry.addInterceptor(statsInterceptor)
|
||||
.addPathPatterns("/api/mobile/**");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,25 +81,6 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer createConvert() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
|
||||
ObjectMapper mapper = builder.build();
|
||||
/*注入自定义的序列化工具,将RequestBody的参数进行转译后传输*/
|
||||
SimpleModule simpleModule = new SimpleModule();
|
||||
// XSS序列化
|
||||
simpleModule.addSerializer(String.class, new XssJacksonSerializer());
|
||||
simpleModule.addDeserializer(String.class, new XssJacksonDeserializer());
|
||||
mapper.registerModule(simpleModule);
|
||||
converters.add(new MappingJackson2HttpMessageConverter(mapper));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
private StringHttpMessageConverter stringHttpMessageConverter;
|
||||
@Autowired
|
||||
|
@ -17,8 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@IgnoreToken
|
||||
@RestController
|
||||
@Api(tags = "渲染端对接接口")
|
||||
|
@ -1,25 +1,18 @@
|
||||
package com.ycwl.basic.controller.vpt;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.annotation.IgnoreLogReq;
|
||||
import com.ycwl.basic.annotation.IgnoreToken;
|
||||
import com.ycwl.basic.constant.StorageConstant;
|
||||
import com.ycwl.basic.device.entity.common.FileObject;
|
||||
import com.ycwl.basic.device.operator.VptPassiveStorageOperator;
|
||||
import com.ycwl.basic.device.operator.VptPassiveStorageOperator;
|
||||
import com.ycwl.basic.facebody.adapter.IFaceBodyAdapter;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.wvp.WvpSyncReqVo;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -29,7 +22,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@IgnoreToken
|
||||
|
@ -1,24 +1,19 @@
|
||||
package com.ycwl.basic.controller.wvp;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.ycwl.basic.annotation.IgnoreLogReq;
|
||||
import com.ycwl.basic.annotation.IgnoreToken;
|
||||
import com.ycwl.basic.constant.StorageConstant;
|
||||
import com.ycwl.basic.device.entity.common.FileObject;
|
||||
import com.ycwl.basic.device.operator.WvpPassiveStorageOperator;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicConfigEntity;
|
||||
import com.ycwl.basic.model.wvp.WvpSyncReqVo;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.service.pc.DeviceService;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.storage.enums.StorageAcl;
|
||||
import com.ycwl.basic.storage.utils.StorageUtil;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@ -28,7 +23,6 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@IgnoreToken
|
||||
|
@ -1,20 +0,0 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* 是否同意用户协议枚举
|
||||
*
|
||||
* @author songmingsong
|
||||
*/
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public enum AgreementEnum {
|
||||
AGREE(1, "同意"),
|
||||
NOT_AGREE(0, "未同意");
|
||||
private int type;
|
||||
private String remark;
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
package com.ycwl.basic.enums;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/6 16:46
|
||||
*/
|
||||
public enum GoodsTypeEnum {
|
||||
VIDEO(1,"成片"),
|
||||
SOURCE(2,"源素材")
|
||||
;
|
||||
|
||||
|
||||
public Integer code;
|
||||
|
||||
private String value;
|
||||
public static final Map<Integer, GoodsTypeEnum> cacheMap;
|
||||
|
||||
static {
|
||||
cacheMap = new HashMap<>(GoodsTypeEnum.values().length);
|
||||
for (GoodsTypeEnum value : GoodsTypeEnum.values()) {
|
||||
cacheMap.put(value.code, value);
|
||||
}
|
||||
}
|
||||
public static final java.util.Map<String, GoodsTypeEnum> valueMap;
|
||||
|
||||
static {
|
||||
valueMap = new HashMap<>(GoodsTypeEnum.values().length);
|
||||
for (GoodsTypeEnum value : GoodsTypeEnum.values()) {
|
||||
valueMap.put(value.value, value);
|
||||
}
|
||||
}
|
||||
|
||||
GoodsTypeEnum(Integer code, String value) {
|
||||
this.code = code;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取value值
|
||||
*/
|
||||
public static String getValue(Integer noticeMethod) {
|
||||
if (noticeMethod == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GoodsTypeEnum GoodsTypeEnum = cacheMap.get(noticeMethod);
|
||||
if (GoodsTypeEnum == null) {
|
||||
return null;
|
||||
}
|
||||
return GoodsTypeEnum.value;
|
||||
}
|
||||
/**
|
||||
* 获取code值
|
||||
*/
|
||||
public static Integer getCode(String noticeMethod) {
|
||||
if (noticeMethod == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
GoodsTypeEnum GoodsTypeEnum = valueMap.get(noticeMethod);
|
||||
if (GoodsTypeEnum == null) {
|
||||
return -1;
|
||||
}
|
||||
return GoodsTypeEnum.code;
|
||||
}
|
||||
}
|
@ -7,8 +7,6 @@ import com.ycwl.basic.constant.PermissionConstant;
|
||||
import com.ycwl.basic.constant.RequestConstant;
|
||||
import com.ycwl.basic.exception.CheckTokenException;
|
||||
import com.ycwl.basic.exception.MissTokenException;
|
||||
import com.ycwl.basic.exception.PermissionException;
|
||||
import com.ycwl.basic.exception.TokenExpireException;
|
||||
import com.ycwl.basic.model.jwt.JwtInfo;
|
||||
import com.ycwl.basic.utils.JwtTokenUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -24,17 +22,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class AuthInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Autowired
|
||||
JwtTokenUtil jwtTokenUtil;
|
||||
|
||||
@Autowired
|
||||
RedisTemplate redisTemplate;
|
||||
|
||||
|
@ -7,7 +7,6 @@ import com.ycwl.basic.config.WechatConfig;
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.constant.NumberConstant;
|
||||
import com.ycwl.basic.constant.WeiXinConstant;
|
||||
import com.ycwl.basic.enums.AgreementEnum;
|
||||
import com.ycwl.basic.enums.BizCodeEnum;
|
||||
import com.ycwl.basic.enums.WechatErrorCodeEnum;
|
||||
import com.ycwl.basic.exception.AppException;
|
||||
@ -137,7 +136,7 @@ public class AppMemberServiceImpl implements AppMemberService {
|
||||
public ApiResponse<?> agreement() {
|
||||
MemberEntity memberEntity = new MemberEntity();
|
||||
memberEntity.setId(Long.parseLong(BaseContextHandler.getUserId()));
|
||||
memberEntity.setAgreement(AgreementEnum.AGREE.getType());
|
||||
memberEntity.setAgreement(1);
|
||||
return ApiResponse.success(memberMapper.update(memberEntity));
|
||||
}
|
||||
|
||||
|
@ -1,202 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* @date 2022年06月02日 13:40
|
||||
* 自定义的BigDecimal计算工具类
|
||||
*/
|
||||
public class CustomBigDecimalUtils {
|
||||
|
||||
public static final BigDecimal HUNDRED_BIG_DECIMAL = new BigDecimal("100");
|
||||
|
||||
/**
|
||||
* 除法
|
||||
*
|
||||
* @param divisor 除数
|
||||
* @param dividend 被除数
|
||||
* @param scale 保留的小数位数
|
||||
* @param roundingMode 舍入模式:比如四舍五入
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:43
|
||||
*/
|
||||
public static BigDecimal divide(BigDecimal divisor,
|
||||
BigDecimal dividend,
|
||||
int scale,
|
||||
RoundingMode roundingMode) {
|
||||
if (divisor == null || dividend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
if (Double.compare(divisor.doubleValue(), BigDecimal.ZERO.doubleValue()) == 0 ||
|
||||
Double.compare(dividend.doubleValue(), BigDecimal.ZERO.doubleValue()) == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return divisor.divide(dividend, scale, roundingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 除法
|
||||
*
|
||||
* @param divisor 除数
|
||||
* @param dividend 被除数
|
||||
* @param scale 保留的小数位数
|
||||
* @param roundingMode 舍入模式:比如四舍五入
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:43
|
||||
*/
|
||||
public static BigDecimal divide(Integer divisor,
|
||||
Integer dividend,
|
||||
int scale,
|
||||
RoundingMode roundingMode) {
|
||||
if (divisor == null || dividend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
if (divisor == 0 || dividend == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return new BigDecimal(divisor).divide(new BigDecimal(dividend), scale, roundingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 除法
|
||||
*
|
||||
* @param divisor 除数
|
||||
* @param dividend 被除数
|
||||
* @param scale 保留的小数位数
|
||||
* @param roundingMode 舍入模式:比如四舍五入
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:43
|
||||
*/
|
||||
public static BigDecimal divide(Double divisor,
|
||||
Double dividend,
|
||||
int scale,
|
||||
RoundingMode roundingMode) {
|
||||
if (divisor == null || dividend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
if (Double.compare(divisor, BigDecimal.ZERO.doubleValue()) == 0 ||
|
||||
Double.compare(dividend, BigDecimal.ZERO.doubleValue()) == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return new BigDecimal(String.valueOf(divisor)).divide(new BigDecimal(String.valueOf(dividend)),
|
||||
scale, roundingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 除法
|
||||
*
|
||||
* @param divisor 除数
|
||||
* @param dividend 被除数
|
||||
* @param scale 保留的小数位数
|
||||
* @param roundingMode 舍入模式:比如四舍五入
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:43
|
||||
*/
|
||||
public static BigDecimal divide(Double divisor,
|
||||
Integer dividend,
|
||||
int scale,
|
||||
RoundingMode roundingMode) {
|
||||
if (divisor == null || dividend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
if (Double.compare(divisor, BigDecimal.ZERO.doubleValue()) == 0 ||
|
||||
Double.compare(dividend, BigDecimal.ZERO.doubleValue()) == 0) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return new BigDecimal(String.valueOf(divisor)).divide(new BigDecimal(String.valueOf(dividend)),
|
||||
scale, roundingMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减法
|
||||
*
|
||||
* @param subtraction 减数
|
||||
* @param minuend 被减数
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:53
|
||||
*/
|
||||
public static BigDecimal subtract(BigDecimal subtraction,
|
||||
BigDecimal minuend) {
|
||||
if (subtraction == null || minuend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
return subtraction.subtract(minuend);
|
||||
}
|
||||
|
||||
/**
|
||||
* 减法
|
||||
*
|
||||
* @param subtraction 减数
|
||||
* @param minuend 被减数
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:53
|
||||
*/
|
||||
public static BigDecimal subtract(Double subtraction,
|
||||
Double minuend) {
|
||||
if (subtraction == null || minuend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
return new BigDecimal(String.valueOf(subtraction)).subtract(new BigDecimal(String.valueOf(minuend)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 减法
|
||||
*
|
||||
* @param subtraction 减数
|
||||
* @param minuend 被减数
|
||||
* @return java.math.BigDecimal
|
||||
* @date 2022/6/2 13:53
|
||||
*/
|
||||
public static BigDecimal subtract(BigDecimal subtraction,
|
||||
Double minuend) {
|
||||
if (subtraction == null || minuend == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
return subtraction.subtract(new BigDecimal(minuend));
|
||||
}
|
||||
|
||||
/**
|
||||
* 加法
|
||||
* @date 2022/6/7 17:31
|
||||
* @param addend 加数
|
||||
* @param summand 被加数
|
||||
* @return java.lang.Double
|
||||
*/
|
||||
public static Double add(Double addend,
|
||||
Double summand) {
|
||||
if (addend == null || summand == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
return new BigDecimal(addend.toString()).add(new BigDecimal(summand.toString())).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加法
|
||||
* @date 2022/6/7 17:31
|
||||
* @param addend 加数
|
||||
* @param summand 被加数
|
||||
* @return java.lang.Double
|
||||
*/
|
||||
public static Double add(BigDecimal addend,
|
||||
BigDecimal summand) {
|
||||
if (addend == null || summand == null) {
|
||||
throw new NullPointerException("传入的数据不能为空");
|
||||
}
|
||||
|
||||
return addend.add(summand).doubleValue();
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import org.apache.http.StatusLine;
|
||||
|
||||
/**
|
||||
* Http服务工具类
|
||||
* @author songmingsong
|
||||
*/
|
||||
public class HttpServiceUtil {
|
||||
/**
|
||||
* 请求OK代码
|
||||
*/
|
||||
public static final int REQUEST_OK_CODE=200;
|
||||
/**
|
||||
* 无响应内容
|
||||
*/
|
||||
public static final String REQUEST_NO_RESULT="No_Result";
|
||||
|
||||
|
||||
/**
|
||||
* 是否响应成功
|
||||
* @param status 响应状态
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean success(StatusLine status) {
|
||||
return status.getStatusCode() == REQUEST_OK_CODE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,180 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @date 2022年07月14日 14:12
|
||||
* 数据格式转换工具类
|
||||
*/
|
||||
public class ObjectConvertUtils {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ObjectConvertUtils.class);
|
||||
|
||||
/**
|
||||
* 浅克隆
|
||||
*
|
||||
* @param source 原对象
|
||||
* @param clazz 目标对象
|
||||
* @return T
|
||||
* @date 2022/4/6 13:45
|
||||
*/
|
||||
public static <T> T clone(Object source, Class<T> clazz) {
|
||||
return clone(source, clazz, true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @date 2022/7/18 16:36
|
||||
* @param source 原对象
|
||||
* @param clazz 目标对象
|
||||
* @param whetherAssignNull 是否赋值空值:true是 false否
|
||||
* @return T
|
||||
*/
|
||||
public static <T> T clone(Object source, Class<T> clazz, Boolean whetherAssignNull) {
|
||||
T target;
|
||||
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
target = clazz.newInstance();
|
||||
if (whetherAssignNull) {
|
||||
BeanUtils.copyProperties(source, target);
|
||||
} else {
|
||||
BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
|
||||
}
|
||||
return target;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("数据转换异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象与对象之间的数据转换
|
||||
*
|
||||
* @param source 转换的数据对象
|
||||
* @param target 需要转换数据的对象
|
||||
* @date 2022/7/14 17:24
|
||||
*/
|
||||
public static void clone(Object source, Object target) {
|
||||
clone(source, target, true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @date 2022/7/18 16:39
|
||||
* @param source 转换的数据对象
|
||||
* @param target 需要转换数据的对象
|
||||
* @param whetherAssignNull 是否赋值空值:true是 false否
|
||||
*/
|
||||
public static void clone(Object source, Object target, Boolean whetherAssignNull) {
|
||||
if (source == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
if (whetherAssignNull) {
|
||||
BeanUtils.copyProperties(source, target, getNullPropertyNames(source));
|
||||
} else {
|
||||
BeanUtils.copyProperties(source, target);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("数据转换异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象与对象之间的数据转换
|
||||
*
|
||||
* @param source 转换的数据对象
|
||||
* @param target 需要转换数据的对象
|
||||
* @date 2022/7/15 9:11
|
||||
*/
|
||||
public static void cglibBeanCopierCloneObject(Object source, Object target) {
|
||||
BeanCopierUtils.copyProperties(source, target);
|
||||
}
|
||||
/**
|
||||
* 对象与对象之间的数据转换
|
||||
*
|
||||
* @param source 转换的数据对象
|
||||
* @param target 需要转换数据的对象
|
||||
* @date 2022/7/15 9:11
|
||||
*/
|
||||
public static <T> T cglibBeanCopierCloneObject(Object source, Class<T> target) {
|
||||
T t;
|
||||
try {
|
||||
t = target.newInstance();
|
||||
BeanCopierUtils.copyProperties(source, t);
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将list集合转换为传入的对象的数据集合
|
||||
*
|
||||
* @param sourceList 原数据集合
|
||||
* @param clazz 需要转换的集合数据对象
|
||||
* @return java.util.List<T>
|
||||
* @date 2022/4/6 13:49
|
||||
*/
|
||||
public static <T> List<T> cloneList(List<?> sourceList, Class<T> clazz) {
|
||||
return cloneList(sourceList, clazz, true);
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @date 2022/7/18 16:41
|
||||
* @param sourceList 原数据集合
|
||||
* @param clazz 需要转换的集合数据对象
|
||||
* @param whetherAssignNull 是否赋值空值:true是 false否
|
||||
* @return java.util.List<T>
|
||||
*/
|
||||
public static <T> List<T> cloneList(List<?> sourceList, Class<T> clazz, Boolean whetherAssignNull) {
|
||||
try {
|
||||
List<T> targetList = new ArrayList<>(sourceList.size());
|
||||
for (Object source : sourceList) {
|
||||
if (whetherAssignNull) {
|
||||
targetList.add(clone(source, clazz));
|
||||
} else {
|
||||
targetList.add(clone(source, clazz, false));
|
||||
}
|
||||
}
|
||||
|
||||
return targetList;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("数据转换异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取需要忽略的属性
|
||||
*/
|
||||
public static String[] getNullPropertyNames(Object source) {
|
||||
final BeanWrapper src = new BeanWrapperImpl(source);
|
||||
PropertyDescriptor[] pds = src.getPropertyDescriptors();
|
||||
|
||||
Set<String> emptyNames = new HashSet<>();
|
||||
for (PropertyDescriptor pd : pds) {
|
||||
Object srcValue = src.getPropertyValue(pd.getName());
|
||||
// 此处判断可根据需求修改
|
||||
if (srcValue == null) {
|
||||
emptyNames.add(pd.getName());
|
||||
}
|
||||
}
|
||||
String[] result = new String[emptyNames.size()];
|
||||
return emptyNames.toArray(result);
|
||||
}
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @date 2022年08月08日 16:06
|
||||
* redis缓存操作行为工具类
|
||||
*/
|
||||
@Component
|
||||
public class RedisCacheOperationUtils {
|
||||
|
||||
/**
|
||||
* string类型的redis操作类
|
||||
*/
|
||||
private static StringRedisTemplate stringRedisTemplate;
|
||||
/**
|
||||
* 通用的redis操作类
|
||||
*/
|
||||
private static RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 创建string类型的操作对象
|
||||
*/
|
||||
public static BoundValueOperations<String, String> createValueOperations(String cacheKey) {
|
||||
return stringRedisTemplate.boundValueOps(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 创建list类型的操作对象
|
||||
*/
|
||||
public static BoundListOperations<String, List<String>> createListOperations(String cacheKey) {
|
||||
return redisTemplate.boundListOps(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 创建hash类型的操作对象
|
||||
*/
|
||||
public static BoundHashOperations createHashOperations(String cacheKey) {
|
||||
return redisTemplate.boundHashOps(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 创建set类型的操作对象
|
||||
*/
|
||||
public static BoundSetOperations createSetOperations(String cacheKey) {
|
||||
return redisTemplate.boundSetOps(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 创建zset类型的操作对象
|
||||
*/
|
||||
public static BoundZSetOperations createZSetOperations(String cacheKey) {
|
||||
return redisTemplate.boundZSetOps(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 判断缓存key值是否存在
|
||||
*/
|
||||
public static Boolean hasKey(String cacheKey) {
|
||||
return redisTemplate.hasKey(cacheKey);
|
||||
}
|
||||
/**
|
||||
* 删除缓存的redis缓存key
|
||||
*/
|
||||
public static Boolean delete(String cacheKey) {
|
||||
return redisTemplate.delete(cacheKey);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setStringRedisTemplate(StringRedisTemplate stringRedisTemplate) {
|
||||
RedisCacheOperationUtils.stringRedisTemplate = stringRedisTemplate;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setRedisTemplate(RedisTemplate redisTemplate) {
|
||||
RedisCacheOperationUtils.redisTemplate = redisTemplate;
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
package com.ycwl.basic.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.config.Registry;
|
||||
import org.apache.http.config.RegistryBuilder;
|
||||
import org.apache.http.conn.socket.ConnectionSocketFactory;
|
||||
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
||||
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
/**
|
||||
* SSL工具类
|
||||
*
|
||||
* @author songmingsong
|
||||
*/
|
||||
@Slf4j
|
||||
public class SslUtil {
|
||||
/**
|
||||
* 获取HtttpClient对象
|
||||
*
|
||||
* @return CloseableHttpClient
|
||||
*/
|
||||
public static CloseableHttpClient sslHttpClientBuild() {
|
||||
Registry<ConnectionSocketFactory> socketFactoryRegistry =
|
||||
RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE)
|
||||
.register("https", trustAllHttpsCertificates()).build();
|
||||
// 创建ConnectionManager,添加Connection配置信息
|
||||
PoolingHttpClientConnectionManager connectionManager =
|
||||
new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
||||
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build();
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* 信任所有Http证书
|
||||
*
|
||||
* @return SSLConnectionSocketFactory
|
||||
*/
|
||||
private static SSLConnectionSocketFactory trustAllHttpsCertificates() {
|
||||
SSLConnectionSocketFactory socketFactory = null;
|
||||
TrustManager[] trustAllCerts = new TrustManager[1];
|
||||
TrustManager tm = new X509TrustManager() {
|
||||
|
||||
@Override
|
||||
// 返回受信任的X509证书数组。
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
// 该方法检查服务器的证书,若不信任该证书同样抛出异常。通过自己实现该方法,可以使之信任我们指定的任何证书。
|
||||
// 在实现该方法时,也可以简单的不做任何处理,即一个空的函数体,由于不会抛出异常,它就会信任任何证书。
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
try {
|
||||
if (chain!=null&&chain.length>0) {
|
||||
chain[0].checkValidity();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("checkServerTrusted",e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
// 该方法检查客户端的证书,若不信任该证书则抛出异常。由于我们不需要对客户端进行认证,
|
||||
// 因此我们只需要执行默认的信任管理器的这个方法。JSSE中,默认的信任管理器类为TrustManager。
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
|
||||
try {
|
||||
if (chain!=null&&chain.length>0) {
|
||||
chain[0].checkValidity();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("checkClientTrusted",e);
|
||||
}
|
||||
}
|
||||
};
|
||||
trustAllCerts[0] = tm;
|
||||
SSLContext sc = null;
|
||||
try {
|
||||
sc = SSLContext.getInstance("TLSv1.2");
|
||||
sc.init(null, trustAllCerts, null);
|
||||
socketFactory = new SSLConnectionSocketFactory(sc, NoopHostnameVerifier.INSTANCE);
|
||||
// HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
} catch (Exception e) {
|
||||
log.error("trustAllHttpsCertificates", e);
|
||||
}
|
||||
return socketFactory;
|
||||
}
|
||||
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.ycwl.basic.xss;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
public class XssJacksonDeserializer extends JsonDeserializer<String> {
|
||||
@Override
|
||||
public String deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
|
||||
return StringEscapeUtils.escapeHtml4(jp.getText());
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.ycwl.basic.xss;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import java.io.IOException;
|
||||
|
||||
public class XssJacksonSerializer extends JsonSerializer<String>{
|
||||
@Override
|
||||
public void serialize(String value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
|
||||
jgen.writeString(StringEscapeUtils.escapeHtml4(value));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user