BUGFIX: format;

This commit is contained in:
shahaibo
2023-10-20 14:47:18 +08:00
parent f18c27fe02
commit 9fa605f83e
134 changed files with 1345 additions and 1203 deletions

View File

@@ -20,25 +20,26 @@ public class FileProperties {
private String linuxDomain;
public ElPath getSys(){
public ElPath getSys() {
String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")) {
if (os.toLowerCase().startsWith("win")) {
return windows;
} else if(os.toLowerCase().startsWith("mac")){
} else if (os.toLowerCase().startsWith("mac")) {
return mac;
}
return linux;
}
public String getLinuxDomain(){
public String getLinuxDomain() {
String os = System.getProperty("os.name");
if((!os.toLowerCase().startsWith("win") )&& (!os.toLowerCase().startsWith("mac"))) {
if ((!os.toLowerCase().startsWith("win")) && (!os.toLowerCase().startsWith("mac"))) {
return linuxDomain;
}
return null;
}
@Data
public static class ElPath{
public static class ElPath {
private String path;
}
}

View File

@@ -18,10 +18,11 @@ public class MinIoClientConfig {
/**
* 注入minio 客户端
*
* @return
*/
@Bean
public MinioClient minioClient(){
public MinioClient minioClient() {
return MinioClient.builder()
.endpoint(endpoint)

View File

@@ -14,7 +14,7 @@ public class BusinessException extends RuntimeException {
private Integer code;
private String msg;
public BusinessException(ResultEnum resultEnum){
public BusinessException(ResultEnum resultEnum) {
super(resultEnum.getMsg());
this.code = resultEnum.getCode();
this.msg = resultEnum.getMsg();

View File

@@ -51,11 +51,12 @@ public class ExceptionCatch {
return Response.error(resultEnum.getCode(), resultEnum.getMsg());
}
}
return Response.error(ResultEnum.ERROR.getCode(), e.getMessage()==null?ResultEnum.ERROR.getMsg():e.getMessage());
return Response.error(ResultEnum.ERROR.getCode(), e.getMessage() == null ? ResultEnum.ERROR.getMsg() : e.getMessage());
}
/**
* 处理参数校验异常
*
* @param e
* @return ResponseData
*/
@@ -68,6 +69,7 @@ public class ExceptionCatch {
/**
* 处理参数校验异常
*
* @param e
* @return ResponseData
*/

View File

@@ -22,7 +22,7 @@ import java.util.function.Function;
**/
@Data
@Slf4j
public abstract class QueryCriteria<T,E> {
public abstract class QueryCriteria<T, E> {
private long page = 1;
private long limit = 10;
@@ -36,12 +36,12 @@ public abstract class QueryCriteria<T,E> {
this.mapper = mapper;
}
public QueryWrapper<T> buildWrapper(){
public QueryWrapper<T> buildWrapper() {
QueryWrapper<T> wrapper = new QueryWrapper<>();
Field[] fields = this.getClass().getDeclaredFields();
for (Field field : fields) {
Condition condition = field.getAnnotation(Condition.class);
if(condition != null){
if (condition != null) {
field.setAccessible(true);
Object value = null;
try {
@@ -49,27 +49,27 @@ public abstract class QueryCriteria<T,E> {
} catch (IllegalAccessException e) {
log.warn("reflection anomaly!");
}
if(!StrUtil.isEmptyIfStr(value)){
switch (condition.type()){
if (!StrUtil.isEmptyIfStr(value)) {
switch (condition.type()) {
case EQ:
wrapper.eq(ConvertUtil.humpToLine2(field.getName()), value);
break;
case LIKE:
wrapper.like(ConvertUtil.humpToLine2(field.getName()), value);
case BETWEEN:
if(value instanceof Collection && ((List) value).size() >= 2){
wrapper.between(ConvertUtil.humpToLine2(field.getName()), ((List)value).get(0), ((List)value).get(1));
if (value instanceof Collection && ((List) value).size() >= 2) {
wrapper.between(ConvertUtil.humpToLine2(field.getName()), ((List) value).get(0), ((List) value).get(1));
}
default:
}
}else if(condition.isNull()){
} else if (condition.isNull()) {
wrapper.isNull(ConvertUtil.humpToLine2(field.getName()));
}
}
Order order = field.getAnnotation(Order.class);
if(order != null){
if(!StrUtil.isEmptyIfStr(order.order())){
switch (order.order()){
if (order != null) {
if (!StrUtil.isEmptyIfStr(order.order())) {
switch (order.order()) {
case DESC:
wrapper.orderByDesc(ConvertUtil.humpToLine2(field.getName()));
break;

View File

@@ -16,9 +16,9 @@ public class AidaConfiguration {
@Bean(value = "IntelligentCurtainApis")
public Docket gxyd5aThemeApis() {
Contact contact = new Contact("Mr.Y","","136");
Contact contact = new Contact("Mr.Y", "", "136");
Docket docket=new Docket(DocumentationType.SWAGGER_2)
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.description("aida接口文档")
.contact(contact)

View File

@@ -3,11 +3,12 @@ package com.ai.da.common.context;
import com.ai.da.model.vo.AuthPrincipalVo;
public class UserContext {
private static ThreadLocal<AuthPrincipalVo> userHolder= new ThreadLocal<AuthPrincipalVo>();
private static ThreadLocal<AuthPrincipalVo> userHolder = new ThreadLocal<AuthPrincipalVo>();
public static AuthPrincipalVo getUserHolder() {
return userHolder.get();
}
public static void delete() {
userHolder.remove();
}

View File

@@ -39,8 +39,8 @@ public enum CollectionLevel1TypeEnum {
return realName;
}
public static CollectionLevel1TypeEnum uploadOf(String realName){
public static CollectionLevel1TypeEnum uploadOf(String realName) {
return Stream.of(CollectionLevel1TypeEnum.values())
.filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
.filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -6,5 +6,5 @@ package com.ai.da.common.enums;
* @create: 2020-01-14 17:33
**/
public enum ConditionType {
EQ,LIKE,BETWEEN;
EQ, LIKE, BETWEEN;
}

View File

@@ -16,19 +16,19 @@ public enum CurrentDesignPictureTypeEnum {
/**
* PIN
*/
PIN(1,"PIN"),
PIN(1, "PIN"),
/**
* USER_LIBRARY
*/
USER_LIBRARY(2,"userLibrary"),
USER_LIBRARY(2, "userLibrary"),
/**
* SYS_FILE
*/
SYS_FILE(3,"sysFile"),
SYS_FILE(3, "sysFile"),
/**
* noPIN
*/
NO_PIN(4,"noPIN");
NO_PIN(4, "noPIN");
private Integer code;
private String desc;
@@ -38,10 +38,11 @@ public enum CurrentDesignPictureTypeEnum {
this.desc = desc;
}
public static CurrentDesignPictureTypeEnum of(String name){
return Stream.of(CurrentDesignPictureTypeEnum.values()).filter(v ->v.name().equals(name)).findFirst().orElse(null);
public static CurrentDesignPictureTypeEnum of(String name) {
return Stream.of(CurrentDesignPictureTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);
}
public static List<CurrentDesignPictureTypeEnum> ofList(List<Integer> codes){
return Stream.of(CurrentDesignPictureTypeEnum.values()).filter(v ->codes.contains(v.code)).collect(Collectors.toList());
public static List<CurrentDesignPictureTypeEnum> ofList(List<Integer> codes) {
return Stream.of(CurrentDesignPictureTypeEnum.values()).filter(v -> codes.contains(v.code)).collect(Collectors.toList());
}
}

View File

@@ -16,15 +16,15 @@ public enum CurrentDesignPrintPictureTypeEnum {
/**
* 空白
*/
NO(1,"空白"),
NO(1, "空白"),
/**
* PIN
*/
PIN(2,"PIN"),
PIN(2, "PIN"),
/**
* noPIN
*/
NO_PIN(3,"noPIN");
NO_PIN(3, "noPIN");
private Integer code;
private String desc;
@@ -33,7 +33,8 @@ public enum CurrentDesignPrintPictureTypeEnum {
this.code = code;
this.desc = desc;
}
public static List<CurrentDesignPrintPictureTypeEnum> ofList(List<Integer> codes){
return Stream.of(CurrentDesignPrintPictureTypeEnum.values()).filter(v ->codes.contains(v.code)).collect(Collectors.toList());
public static List<CurrentDesignPrintPictureTypeEnum> ofList(List<Integer> codes) {
return Stream.of(CurrentDesignPrintPictureTypeEnum.values()).filter(v -> codes.contains(v.code)).collect(Collectors.toList());
}
}

View File

@@ -8,17 +8,17 @@ public enum GenerateModeEnum {
/**
* 通过文本生成
*/
TEXT(1,"text"),
TEXT(1, "text"),
/**
* 通过图片生成
*/
IMAGE(2,"image"),
IMAGE(2, "image"),
/**
* 通过文本和图片生成
*/
TEXT_IMAGE(2,"text-image");
TEXT_IMAGE(2, "text-image");
private Integer code;
private String value;

View File

@@ -39,8 +39,8 @@ public enum LibraryLevel1TypeEnum {
return realName;
}
public static LibraryLevel1TypeEnum uploadOf(String realName){
public static LibraryLevel1TypeEnum uploadOf(String realName) {
return Stream.of(LibraryLevel1TypeEnum.values())
.filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
.filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -30,9 +30,10 @@ public enum LibraryTopTypeEnum {
public String getRealName() {
return realName;
}
public static LibraryTopTypeEnum uploadOf(String realName){
public static LibraryTopTypeEnum uploadOf(String realName) {
return Stream.of(LibraryTopTypeEnum.values())
.filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
.filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -17,7 +17,7 @@ public enum LoginTypeEnum {
*/
PASSWORD;
public static LoginTypeEnum of(String name){
return Stream.of(LoginTypeEnum.values()).filter(v ->v.name().equals(name)).findFirst().orElse(null);
public static LoginTypeEnum of(String name) {
return Stream.of(LoginTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);
}
}

View File

@@ -8,14 +8,14 @@ public enum ModelNameEnum {
/**
* 使用模型0
*/
MODEL_0("0","model_0");
MODEL_0("0", "model_0");
private String code;
private String modelName;
ModelNameEnum(String code,String modelName) {
ModelNameEnum(String code, String modelName) {
this.code = code;
this.modelName = modelName;
}

View File

@@ -9,7 +9,7 @@ import java.util.stream.Stream;
**/
public enum OperationTypeEnum {
/**
*登入
* 登入
*/
LOGIN,
/**
@@ -25,7 +25,7 @@ public enum OperationTypeEnum {
*/
FORGET_PWD;
public static OperationTypeEnum of(String name){
return Stream.of(OperationTypeEnum.values()).filter(v ->v.name().equals(name)).findFirst().orElse(null);
public static OperationTypeEnum of(String name) {
return Stream.of(OperationTypeEnum.values()).filter(v -> v.name().equals(name)).findFirst().orElse(null);
}
}

View File

@@ -6,5 +6,5 @@ package com.ai.da.common.enums;
* @create: 2020-01-14 17:33
**/
public enum OrderType {
DESC,ASC;
DESC, ASC;
}

View File

@@ -36,7 +36,7 @@ public enum PythonToJavaApiOperationTypeEnum {
return realName;
}
public static PythonToJavaApiOperationTypeEnum uploadOf(String realName){
return Stream.of(PythonToJavaApiOperationTypeEnum.values()).filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
public static PythonToJavaApiOperationTypeEnum uploadOf(String realName) {
return Stream.of(PythonToJavaApiOperationTypeEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -27,7 +27,7 @@ public enum SingleOverallEnum {
return realName;
}
public static SingleOverallEnum of(String realName){
return Stream.of(SingleOverallEnum.values()).filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
public static SingleOverallEnum of(String realName) {
return Stream.of(SingleOverallEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -40,7 +40,7 @@ public enum SwitchCategoryEnum {
return realName;
}
public static SwitchCategoryEnum of(String realName){
return Stream.of(SwitchCategoryEnum.values()).filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
public static SwitchCategoryEnum of(String realName) {
return Stream.of(SwitchCategoryEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
}

View File

@@ -9,11 +9,11 @@ import java.util.stream.Stream;
**/
public enum SysFileLevel1TypeEnum {
IMAGES("Images","images"),
IMAGES("Images", "images"),
ICON_C("Iconc","iconc"),
ICON_C("Iconc", "iconc"),
ACCESSORIES("Accessories","accessories");
ACCESSORIES("Accessories", "accessories");
private String realName;
/**
@@ -34,7 +34,7 @@ public enum SysFileLevel1TypeEnum {
return uploadPathName;
}
public static SysFileLevel1TypeEnum uploadOf(String uploadPathName){
return Stream.of(SysFileLevel1TypeEnum.values()).filter(v ->v.getUploadPathName().equals(uploadPathName)).findFirst().orElse(null);
public static SysFileLevel1TypeEnum uploadOf(String uploadPathName) {
return Stream.of(SysFileLevel1TypeEnum.values()).filter(v -> v.getUploadPathName().equals(uploadPathName)).findFirst().orElse(null);
}
}

View File

@@ -14,27 +14,27 @@ public enum SysFileLevel2TypeEnum {
/**
* ICON
*/
ICON("Icon","icon"),
ICON("Icon", "icon"),
BAG("Bag","bag"),
BAG("Bag", "bag"),
EARRINGS("Earring","earring"),
EARRINGS("Earring", "earring"),
HAIRSTYLE("Hairstyle","hairstyle"),
HAIRSTYLE("Hairstyle", "hairstyle"),
SHOES("Shoes","shoes"),
SHOES("Shoes", "shoes"),
BODY("Body","body"),
BODY("Body", "body"),
BLOUSE("Blouse","blouse"),
BLOUSE("Blouse", "blouse"),
DRESS("Dress","dress"),
DRESS("Dress", "dress"),
OUTWEAR("Outwear","outwear"),
OUTWEAR("Outwear", "outwear"),
SKIRT("Skirt","skirt"),
SKIRT("Skirt", "skirt"),
TROUSERS("Trousers","trousers");
TROUSERS("Trousers", "trousers");
private String realName;
/**
@@ -55,21 +55,24 @@ public enum SysFileLevel2TypeEnum {
return uploadPathName;
}
public static SysFileLevel2TypeEnum uploadOf(String uploadPathName){
return Stream.of(SysFileLevel2TypeEnum.values()).filter(v ->v.getUploadPathName().equals(uploadPathName)).findFirst().orElse(null);
}
public static SysFileLevel2TypeEnum realNameOf(String realName){
return Stream.of(SysFileLevel2TypeEnum.values()).filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
public static SysFileLevel2TypeEnum uploadOf(String uploadPathName) {
return Stream.of(SysFileLevel2TypeEnum.values()).filter(v -> v.getUploadPathName().equals(uploadPathName)).findFirst().orElse(null);
}
public static SysFileLevel2TypeEnum realNameOfPython(String realName){
return Stream.of(BLOUSE,DRESS,OUTWEAR,SKIRT,TROUSERS).filter(v ->v.getRealName().equals(realName)).findFirst().orElse(null);
public static SysFileLevel2TypeEnum realNameOf(String realName) {
return Stream.of(SysFileLevel2TypeEnum.values()).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
public static List<String> ofPython(){
return Stream.of(BLOUSE,DRESS,OUTWEAR,SKIRT,TROUSERS).map(SysFileLevel2TypeEnum::getRealName).collect(Collectors.toList());
public static SysFileLevel2TypeEnum realNameOfPython(String realName) {
return Stream.of(BLOUSE, DRESS, OUTWEAR, SKIRT, TROUSERS).filter(v -> v.getRealName().equals(realName)).findFirst().orElse(null);
}
public static List<String> ofPythonPath(){
return Stream.of(BLOUSE,DRESS,OUTWEAR,SKIRT,TROUSERS).map(SysFileLevel2TypeEnum::getUploadPathName).collect(Collectors.toList());
public static List<String> ofPython() {
return Stream.of(BLOUSE, DRESS, OUTWEAR, SKIRT, TROUSERS).map(SysFileLevel2TypeEnum::getRealName).collect(Collectors.toList());
}
public static List<String> ofPythonPath() {
return Stream.of(BLOUSE, DRESS, OUTWEAR, SKIRT, TROUSERS).map(SysFileLevel2TypeEnum::getUploadPathName).collect(Collectors.toList());
}
public static final List<String> ACCESSORIES_LIST = Arrays.asList(

View File

@@ -16,23 +16,24 @@ public class TokenQuery {
private static final String GENERATE_USER_DOMAIN = "https://www.szsige.com";
public static JSONObject getToken(String session) {
String url = GET_TOKEN_DOMAIN + TokenApis.GET_TOKEN.getUrl()+ session;
String url = GET_TOKEN_DOMAIN + TokenApis.GET_TOKEN.getUrl() + session;
log.info("获取用户token接口请求url:" + url);
HttpResponse httpResponse = HttpUtil.createPost(url).execute();
log.info("获取用户token接口响应" + httpResponse);
if(httpResponse.isOk() && StrUtil.isNotEmpty(httpResponse.body())){
if (httpResponse.isOk() && StrUtil.isNotEmpty(httpResponse.body())) {
return JSONObject.parseObject(httpResponse.body());
}
return null;
}
public static JSONObject generateUser(Map<String, Object> param,String token) {
public static JSONObject generateUser(Map<String, Object> param, String token) {
HttpResponse httpResponse = HttpUtil.createPost(GENERATE_USER_DOMAIN + TokenApis.GENERATE_USER.getUrl())
.body(JSONObject.toJSONString(param!=null?param:new HashMap<>()))
.header("Authorization", "Bearer "+token)
.body(JSONObject.toJSONString(param != null ? param : new HashMap<>()))
.header("Authorization", "Bearer " + token)
.header("X-Promiss", "9672233956")
.execute();
log.info("生成用户信息接口响应:" + httpResponse);
if(httpResponse.isOk() && StrUtil.isNotEmpty(httpResponse.body())){
if (httpResponse.isOk() && StrUtil.isNotEmpty(httpResponse.body())) {
return JSONObject.parseObject(httpResponse.body());
}
return null;

View File

@@ -17,7 +17,7 @@ import java.util.List;
@Data
@NoArgsConstructor
@ApiModel("分页响应结果")
public class PageBaseResponse<T>{
public class PageBaseResponse<T> {
@ApiModelProperty("页码")
private long page;
@ApiModelProperty("每页数量")
@@ -30,7 +30,6 @@ public class PageBaseResponse<T>{
private List<T> content;
public PageBaseResponse(List<T> list, long page, long size, long total, long pages) {
this.page = page;
this.size = size;
@@ -39,7 +38,7 @@ public class PageBaseResponse<T>{
this.content = list;
}
public static <T> PageBaseResponse<T> success(IPage<T> page){
return new PageBaseResponse<>(page.getRecords() , page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
public static <T> PageBaseResponse<T> success(IPage<T> page) {
return new PageBaseResponse<>(page.getRecords(), page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
}
}

View File

@@ -31,9 +31,8 @@ public class PageResponse<T> extends Response<List<T>> {
private List<T> content;
public PageResponse(Response<List<T>> response, long page, long size, long total, long pages) {
if(response != null) {
if (response != null) {
this.setData(response.getData());
this.setErrCode(response.getErrCode());
this.setErrMsg(response.getErrMsg());
@@ -45,8 +44,8 @@ public class PageResponse<T> extends Response<List<T>> {
this.content = response.getData();
}
public static <T> PageResponse<T> success(IPage<T> page){
public static <T> PageResponse<T> success(IPage<T> page) {
Response<List<T>> response = success(page.getRecords());
return new PageResponse<>(response , page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
return new PageResponse<>(response, page.getCurrent(), page.getSize(), page.getTotal(), page.getPages());
}
}

View File

@@ -27,28 +27,27 @@ public class Response<T> implements Serializable {
@ApiModelProperty("数据结果")
private T data;
public static <T> Response<T> success(){
public static <T> Response<T> success() {
return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), null);
}
public static <T> Response<T> success(String msg){
public static <T> Response<T> success(String msg) {
return success(ResultEnum.SUCCESS.getCode(), msg, null);
}
public static <T> Response<T> success(T data){
public static <T> Response<T> success(T data) {
return success(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMsg(), data);
}
public static <T> Response<T> success(int code, T data){
public static <T> Response<T> success(int code, T data) {
return success(code, ResultEnum.SUCCESS.getMsg(), data);
}
public static <T> Response<T> success(int code, String msg, T data){
public static <T> Response<T> success(int code, String msg, T data) {
return getResponse(code, msg, data);
}
public static <T> Response<T> fail(String msg) {
return fail(ResultEnum.FAIL.getCode(), msg);
}
@@ -85,7 +84,7 @@ public class Response<T> implements Serializable {
return getResponse(code, msg, data);
}
private static <T> Response<T> getResponse(int code, String msg, T data){
private static <T> Response<T> getResponse(int code, String msg, T data) {
return new Response<>(code, msg, data);
}

View File

@@ -13,17 +13,16 @@ public enum ResultEnum {
ERROR(false, -1, "system error!"),
PARAMETER_ERROR(false, -2, "parameter error!"),
NO_LOGIN(false,-100,"User not logged in"),
NO_PERMISSION(false,-200,"No access"),
ACCOUNT_LOCK(false,-300,"Account frozen");
NO_LOGIN(false, -100, "User not logged in"),
NO_PERMISSION(false, -200, "No access"),
ACCOUNT_LOCK(false, -300, "Account frozen");
private int code;
private String msg;
private boolean isOK;
ResultEnum(boolean isOK, int code, String msg){
ResultEnum(boolean isOK, int code, String msg) {
this.isOK = isOK;
this.code = code;
this.msg = msg;

View File

@@ -43,6 +43,6 @@ public class UserLoginFailureHandler implements AuthenticationFailureHandler {
log.error("登录失败:", e);
response = Response.fail("登录失败!");
}
JSONResponseUtils.build(httpServletResponse,response);
JSONResponseUtils.build(httpServletResponse, response);
}
}

View File

@@ -41,10 +41,10 @@ public class AuthenticationFilter extends OncePerRequestFilter {
private SecurityProperties properties;
private static final List<String> FILTER_URL =
Arrays.asList("/favicon.ico","/doc.html","api/account/login","api/account/preLogin","api/account/sendEmail",
"/webjars/","/swagger-resources","/v2/api-docs","api/account/resetPwd",
Arrays.asList("/favicon.ico", "/doc.html", "api/account/login", "api/account/preLogin", "api/account/sendEmail",
"/webjars/", "/swagger-resources", "/v2/api-docs", "api/account/resetPwd",
"/api/python/saveGeneratePicture", "/api/python/getLibraryByUserId",
"/api/third/party/addUser","/api/third/party/editUser","/api/element/initDefaultSysFile",
"/api/third/party/addUser", "/api/third/party/editUser", "/api/element/initDefaultSysFile",
"/api/python/chatStream",
"/api/python/flush"
);
@@ -53,16 +53,16 @@ public class AuthenticationFilter extends OncePerRequestFilter {
protected void doFilterInternal(HttpServletRequest httpServletRequest, @NonNull HttpServletResponse httpServletResponse, @NonNull FilterChain filterChain) throws ServletException, IOException {
String requestURI = httpServletRequest.getRequestURI();
if(calculateUrl(requestURI)){
if (calculateUrl(requestURI)) {
StopWatch stopWatch = new StopWatch();
HttpServletRequest wrappedRequest = httpServletRequest;
HttpServletResponse wrappedResponse = httpServletResponse;
try{
try {
stopWatch.start();
if ((httpServletRequest.getContentType() == null && httpServletRequest.getContentLength() > 0) || (httpServletRequest.getContentType() != null && !httpServletRequest.getContentType().contains("application/json"))) {
extracted(wrappedRequest);
filterChain.doFilter(wrappedRequest, wrappedResponse);
}else {
} else {
wrappedRequest = new MultiReadHttpServletRequest(httpServletRequest);
wrappedResponse = new MultiReadHttpServletResponse(httpServletResponse);
extracted(wrappedRequest);
@@ -74,14 +74,16 @@ public class AuthenticationFilter extends OncePerRequestFilter {
} finally {
stopWatch.stop();
}
}else {
} else {
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
}
private Boolean calculateUrl(String requestURI ){
String filterUrl = FILTER_URL.stream().filter(url ->requestURI.contains(url)).findFirst().orElse(null);
return null == filterUrl ? Boolean.TRUE :Boolean.FALSE;
private Boolean calculateUrl(String requestURI) {
String filterUrl = FILTER_URL.stream().filter(url -> requestURI.contains(url)).findFirst().orElse(null);
return null == filterUrl ? Boolean.TRUE : Boolean.FALSE;
}
private void extracted(HttpServletRequest request) throws AuthenticationException {
String jwtToken = request.getHeader(properties.getJwtTokenHeader());
log.debug("后台检查令牌:{}", jwtToken);
@@ -91,7 +93,7 @@ public class AuthenticationFilter extends OncePerRequestFilter {
}
// 检查token
boolean validate = jwtTokenHelper.validateToken(jwtToken);
if(validate){
if (validate) {
AuthPrincipalVo principal = jwtTokenHelper.parserToUser(jwtToken);
if (principal == null) {
throw new RuntimeException("TOKEN已过期请重新登录");

View File

@@ -31,7 +31,7 @@ public class JWTTokenHelper {
private static final String ISSUER = "DWJ";
private static final String AUTHORITIES = "authorities";
public String createToken(AuthPrincipalVo principal){
public String createToken(AuthPrincipalVo principal) {
String token = Jwts.builder()
.setId(String.valueOf(principal.getId()))
.setSubject(JSONObject.toJSONString(principal))
@@ -45,24 +45,24 @@ public class JWTTokenHelper {
return token;
}
public boolean validateToken(String token){
public boolean validateToken(String token) {
Claims claims = parser(token);
if (MapUtil.isEmpty(claims)){
if (MapUtil.isEmpty(claims)) {
return false;
}
return true;
}
public AuthPrincipalVo parserToUser(String token){
public AuthPrincipalVo parserToUser(String token) {
String subject = parser(token).getSubject();
if(StrUtil.isNotEmpty(subject)){
if (StrUtil.isNotEmpty(subject)) {
return JSONObject.parseObject(subject, AuthPrincipalVo.class);
}
return null;
}
public Claims parser(String token) {
token = token.replaceAll(securityProperties.getJwtTokenPrefix(),"");
token = token.replaceAll(securityProperties.getJwtTokenPrefix(), "");
return Jwts.parser().setSigningKey(securityProperties.getJwtSecret()).parseClaimsJws(token).getBody();
}
}

View File

@@ -23,16 +23,17 @@ public class AccessLimitUtils {
* @param interfaceName
* @return
*/
public static void validate(String interfaceName,Integer count) {
Integer useCount= LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
if(useCount >count){
public static void validate(String interfaceName, Integer count) {
Integer useCount = LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
if (useCount > count) {
//系统繁忙
throw new BusinessException("system busy !");
}else{
useCount ++;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName,useCount);
} else {
useCount++;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName, useCount);
}
}
/**
* 校验过后 接口完毕 去掉限流
*
@@ -40,9 +41,9 @@ public class AccessLimitUtils {
* @return
*/
public static void validateOut(String interfaceName) {
Integer useCount= LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
useCount --;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName,useCount);
Integer useCount = LocalCacheUtils.getAidaInterfaceCurrentLimitingCache(interfaceName);
useCount--;
LocalCacheUtils.setAidaInterfaceCurrentLimitingCache(interfaceName, useCount);
}
}

View File

@@ -54,11 +54,11 @@ public class ConvertUtil {
return sb.toString();
}
public static String lowerCaseFirstLetter(String str){
if(StrUtil.isNotBlank(str)){
public static String lowerCaseFirstLetter(String str) {
if (StrUtil.isNotBlank(str)) {
str = str.trim();
String result = str.substring(0, 1).toLowerCase();
if(str.length() > 1){
if (str.length() > 1) {
result += str.substring(1);
}
return result;

View File

@@ -12,11 +12,13 @@ import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@Slf4j
public class DateUtil {
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
public static final String YYYYMM = "yyyyMM";
public static final String YYYY_MM_DD = "yyyyMMdd";
/**
* LocalDate -> Date
*/
@@ -25,13 +27,15 @@ public class DateUtil {
}
/**
* LocalDateTime -> Date
* LocalDateTime -> Date
*/
public static Date asDate(LocalDateTime localDateTime) {
return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}
/**
* date 装 String
*
* @param date
* @param formatter
* @return
@@ -43,21 +47,23 @@ public class DateUtil {
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zoneId);
return dateTimeFormatter.format(localDateTime);
}
/**
* 根据时区获取时间
*
* @param timeZone "Asia/Tokyo"
* @return
*/
public static Date getByTimeZone(String timeZone) {
String dateStr = dateToStr(new Date(),YYYY_MM_DD_HH_MM_SS);
String dateStr = dateToStr(new Date(), YYYY_MM_DD_HH_MM_SS);
SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
// 设置时区
sdf.setTimeZone(TimeZone.getTimeZone(timeZone));
Date date = null;
try{
Date date = null;
try {
date = sdf.parse(dateStr);
}catch (ParseException parseException){
log.error("时间转换异常!",parseException);
} catch (ParseException parseException) {
log.error("时间转换异常!", parseException);
}
return date;
}

View File

@@ -129,53 +129,56 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
/**
* 获取文件尺寸
*/
public static FileVO getFileSize(MultipartFile file) {
public static FileVO getFileSize(MultipartFile file) {
int width = 0;
int height = 0;
try{
try {
// 图片对象
BufferedImage bufferedImage = ImageIO.read(file.getInputStream());
// 宽度
width = bufferedImage.getWidth();
width = bufferedImage.getWidth();
// 高度
height = bufferedImage.getHeight();
}catch (IOException ioException){
height = bufferedImage.getHeight();
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}", ExceptionUtil.stacktraceToString(ioException));
}
return new FileVO(height,width);
return new FileVO(height, width);
}
/**
* 获取文件尺寸
*/
public static FileVO getFileSize(InputStream inputStream) {
public static FileVO getFileSize(InputStream inputStream) {
int width = 0;
int height = 0;
try{
try {
// 图片对象
BufferedImage bufferedImage = ImageIO.read(inputStream);
// 宽度
width = bufferedImage.getWidth();
// 高度
height = bufferedImage.getHeight();
}catch (IOException ioException){
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}", ExceptionUtil.stacktraceToString(ioException));
}
return new FileVO(height,width);
return new FileVO(height, width);
}
/**
* 获取远程文件流
*/
public static InputStream getOriginFile(String path) {
public static InputStream getOriginFile(String path) {
try{
try {
//远程
URL url = new URL(path);
return url.openStream();
}catch (IOException ioException){
log.error("获取文件尺寸异常###{}###path##{}", ExceptionUtil.stacktraceToString(ioException),path);
} catch (IOException ioException) {
log.error("获取文件尺寸异常###{}###path##{}", ExceptionUtil.stacktraceToString(ioException), path);
throw new BusinessException("get file is failed!");
}
}
/**
* 将文件名解析成文件的上传路径
*/
@@ -183,7 +186,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
String suffix = getExtensionName(file.getOriginalFilename());
String nowStr = format.format(date)+"-" ;
String nowStr = format.format(date) + "-";
try {
String fileName = file.getOriginalFilename();
String fileSuffix = fileName.substring(fileName.lastIndexOf("."));
@@ -204,6 +207,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
return null;
}
/**
* 将文件名解析成文件的上传路径
*/
@@ -211,7 +215,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
Date date = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddhhmmssS");
String suffix = getExtensionName(file.getOriginalFilename());
String nowStr = format.format(date)+"-" ;
String nowStr = format.format(date) + "-";
try {
String fileName = file.getOriginalFilename();
String path = filePath + fileName;
@@ -242,6 +246,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
}
return false;
}
/**
* 获取指定文件夹下所有文件,不含文件夹里的文件
*
@@ -249,7 +254,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
* @return
*/
public static List<File> getAllFile(String dirFilePath) {
if (StrUtil.isBlank(dirFilePath)){
if (StrUtil.isBlank(dirFilePath)) {
return null;
}
return getAllFile(new File(dirFilePath));
@@ -263,11 +268,11 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
*/
public static List<File> getAllFile(File dirFile) {
// 如果文件夹不存在或着不是文件夹,则返回 null
if (Objects.isNull(dirFile) || !dirFile.exists() || dirFile.isFile()){
if (Objects.isNull(dirFile) || !dirFile.exists() || dirFile.isFile()) {
return null;
}
File[] childrenFiles = dirFile.listFiles();
if (Objects.isNull(childrenFiles) || childrenFiles.length == 0){
if (Objects.isNull(childrenFiles) || childrenFiles.length == 0) {
return null;
}
List<File> files = new ArrayList<>();
@@ -280,7 +285,7 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
else {
// 如果是文件夹,则将其内部文件添加进结果集合
List<File> cFiles = getAllFile(childFile);
if (Objects.isNull(cFiles) || cFiles.isEmpty()){
if (Objects.isNull(cFiles) || cFiles.isEmpty()) {
continue;
}
files.addAll(cFiles);

View File

@@ -14,10 +14,11 @@ import java.io.IOException;
@Slf4j
public class ImageUtil {
static BufferedImage bufferedImage;
static int r,g,b; // 分别用来存放获取的RGB值
static int heigth,width;
static int r, g, b; // 分别用来存放获取的RGB值
static int heigth, width;
static int id = 0;
public static void find(){
public static void find() {
// 读取要操作的图片,这里的图片路径请改成自己要处理的图片
try {
bufferedImage = ImageIO.read(new File("D:\\programManager\\private\\curtain\\curtain\\WechatIMG170.png"));
@@ -27,16 +28,16 @@ public class ImageUtil {
// 获取图片的宽和高;
heigth = bufferedImage.getHeight();
width = bufferedImage.getHeight();
System.out.println("heigth = "+heigth +", width ="+width);
System.out.println("heigth = " + heigth + ", width =" + width);
// 采用行优先遍历,先遍历宽
for (int y = 0; y < heigth; y++) {
for (int x = 0; x < width; x++) {
id++;
Color color = new Color(bufferedImage.getRGB(x,y));
Color color = new Color(bufferedImage.getRGB(x, y));
r = color.getRed();
g = color.getGreen();
b = color.getBlue();
System.out.println("此时的id为 "+ id+ " R = "+ r + ", G = "+g+", B ="+b);
System.out.println("此时的id为 " + id + " R = " + r + ", G = " + g + ", B =" + b);
}
}
}

View File

@@ -25,25 +25,26 @@ public final class LocalCacheUtils {
* token
*/
private static LoadingCache<String, String> tokenCache = loadTokenCache();
/**
*
*缓存接口这里是LoadingCacheLoadingCache在缓存项不存在时可以自动加载缓存
* 缓存接口这里是LoadingCacheLoadingCache在缓存项不存在时可以自动加载缓存
*/
private static LoadingCache<String, String> loadTokenCache(){
LoadingCache<String, String> tokenCache = CacheBuilder.newBuilder()
private static LoadingCache<String, String> loadTokenCache() {
LoadingCache<String, String> tokenCache = CacheBuilder.newBuilder()
.concurrencyLevel(10)
.expireAfterWrite(24*100, TimeUnit.HOURS)
.expireAfterWrite(24 * 100, TimeUnit.HOURS)
.initialCapacity(100)
.maximumSize(10000)
.recordStats()
.build(new CacheLoader<String, String>() {
@Override
public String load(String key) throws Exception {
return "null";
}
@Override
public String load(String key) throws Exception {
return "null";
}
});
return tokenCache;
}
/**
* 邮箱,短信验证码
*/
@@ -51,7 +52,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后10分钟过期,防止跨洲发送慢失效问题
.expireAfterWrite(60*30, TimeUnit.SECONDS)
.expireAfterWrite(60 * 30, TimeUnit.SECONDS)
//刷新机制 每隔一定时间刷新缓存loader 只有调用get具体的操作才生效(懒加载) 不设置则不刷新
// .refreshAfterWrite(60, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
@@ -75,7 +76,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(100)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -96,7 +97,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(100)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -118,7 +119,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后一天过期
.expireAfterWrite(60*60*24, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24, TimeUnit.SECONDS)
//设置缓存容器的初始容量为15000
.initialCapacity(15000)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -133,27 +134,27 @@ public final class LocalCacheUtils {
}
});
/**
/**
* design文件进度统计
*/
private static LoadingCache<Long, List<String>> designProcessCache = CacheBuilder.newBuilder()
//设置并发级别为10并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后5分钟过期
.expireAfterWrite(60*5, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
.maximumSize(100)
//设置要统计缓存的命中率
.recordStats()
//build方法中可以指定CacheLoader在缓存不存在时通过CacheLoader的实现自动加载缓存
.build(new CacheLoader<Long, List<String>>() {
@Override
public List<String> load(Long key) throws Exception {
return Collections.EMPTY_LIST;
}
});
//设置并发级别为10并发级别是指可以同时写缓存的线程数
.concurrencyLevel(10)
//设置写缓存后5分钟过期
.expireAfterWrite(60 * 5, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
.maximumSize(100)
//设置要统计缓存的命中率
.recordStats()
//build方法中可以指定CacheLoader在缓存不存在时通过CacheLoader的实现自动加载缓存
.build(new CacheLoader<Long, List<String>>() {
@Override
public List<String> load(Long key) throws Exception {
return Collections.EMPTY_LIST;
}
});
/**
* aida 接口限流(先粗暴做)
@@ -162,7 +163,7 @@ public final class LocalCacheUtils {
//设置并发级别为5并发级别是指可以同时写缓存的线程数
.concurrencyLevel(20)
//设置写缓存后30天过期
.expireAfterWrite(60*60*24*30, TimeUnit.SECONDS)
.expireAfterWrite(60 * 60 * 24 * 30, TimeUnit.SECONDS)
//设置缓存容器的初始容量为100
.initialCapacity(5)
//设置缓存最大容量50000超过50000之后就会按照LRU最近虽少使用算法来移除缓存项
@@ -176,8 +177,10 @@ public final class LocalCacheUtils {
return 0;
}
});
/**
* 添加token本地缓存
*
* @param key
* @param value
*/
@@ -187,6 +190,7 @@ public final class LocalCacheUtils {
/**
* 获取token本地缓存
*
* @param key
* @return
*/
@@ -202,8 +206,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 删除token本地缓存(登出)
*
* @param key
* @return
*/
@@ -214,8 +220,10 @@ public final class LocalCacheUtils {
log.error("delTokenCache方法错误", e);
}
}
/**
* 添加验证码本地缓存
*
* @param key
* @param value
*/
@@ -225,6 +233,7 @@ public final class LocalCacheUtils {
/**
* 获取验证码本地缓存
*
* @param key
* @return
*/
@@ -240,8 +249,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 添加系统文本地缓存
*
* @param key
* @param sysFile
*/
@@ -251,6 +262,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件本地缓存
*
* @param key
* @return
*/
@@ -263,8 +275,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件本地缓存
*
* @return
*/
public static void clearAllSysFileCache() {
@@ -274,8 +288,10 @@ public final class LocalCacheUtils {
log.error("clearAllSysFileCache方法错误", e);
}
}
/**
* 添加系统文本地缓存,通过类型
*
* @param level1Type
* @param sysFileList
*/
@@ -285,6 +301,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件本地缓存
*
* @param level2Type
* @return
*/
@@ -296,8 +313,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件本地缓存
*
* @return
*/
public static void clearAllSysFileCacheByLevel2Type() {
@@ -307,8 +326,10 @@ public final class LocalCacheUtils {
log.error("clearAllSysFileCacheByLevel2Type方法错误", e);
}
}
/**
* 添加系统文件范围最大最小值本地缓存
*
* @param key
* @param value
*/
@@ -318,6 +339,7 @@ public final class LocalCacheUtils {
/**
* 获取系统文件范围最大最小值本地缓存
*
* @param key
* @return
*/
@@ -333,8 +355,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 清除所有系统文件范围最大最小值本地缓存
*
* @return
*/
public static void clearAllMaxMinValueCache() {
@@ -344,8 +368,10 @@ public final class LocalCacheUtils {
log.error("clearAllMaxMinValueCache方法错误", e);
}
}
/**
* 添加系design文件进度统计
*
* @param key
* @param value
*/
@@ -355,6 +381,7 @@ public final class LocalCacheUtils {
/**
* 获取design文件进度统计
*
* @param key
* @return
*/
@@ -367,8 +394,10 @@ public final class LocalCacheUtils {
}
return null;
}
/**
* 进度统计完后 删除进度
*
* @param key
* @return
*/
@@ -382,6 +411,7 @@ public final class LocalCacheUtils {
/**
* 设置本次接口流量数
*
* @param key
* @param value
*/
@@ -391,6 +421,7 @@ public final class LocalCacheUtils {
/**
* 获取本次接口流量数
*
* @param key
* @return
*/

View File

@@ -58,6 +58,7 @@ public class MD5Utils {
}
return md5;
}
/**
* MD5加密文件
*

View File

@@ -37,6 +37,7 @@ import java.util.stream.Collectors;
public class MinioUtil {
@Autowired
private MinioClient minioClient;
/**
* description: 判断bucket是否存在不存在则创建
*
@@ -55,6 +56,7 @@ public class MinioUtil {
/**
* 创建存储bucket
*
* @param bucketName 存储bucket名称
* @return Boolean
*/
@@ -72,6 +74,7 @@ public class MinioUtil {
/**
* 删除存储bucket
*
* @param bucketName 存储bucket名称
* @return Boolean
*/
@@ -86,6 +89,7 @@ public class MinioUtil {
}
return true;
}
/**
* description: 上传文件
*
@@ -93,7 +97,6 @@ public class MinioUtil {
* @param path
* @param multipartFile
* @return: java.lang.String
*/
public List<String> uploadBatch(String bucketName, String path, MultipartFile[] multipartFile) {
List<String> names = new ArrayList<>(multipartFile.length);
@@ -138,7 +141,6 @@ public class MinioUtil {
* @param path
* @param file
* @return: java.lang.String
*/
public String upload(String bucketName, String path, MultipartFile file) {
String fileName = file.getOriginalFilename();
@@ -292,6 +294,7 @@ public class MinioUtil {
/**
* 查看文件对象
*
* @param bucketName 存储bucket名称
* @return 存储bucket内文件对象信息
*/
@@ -316,8 +319,9 @@ public class MinioUtil {
/**
* 批量删除文件对象
*
* @param bucketName 存储bucket名称
* @param objects 对象名称集合
* @param objects 对象名称集合
*/
public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) {
List<DeleteObject> dos = objects.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList());
@@ -372,7 +376,7 @@ public class MinioUtil {
public String getPresignedUrl(String path, int expiry) {
if (LocalCacheUtils.getPresignedUrlCache(path) != null) {
return LocalCacheUtils.getPresignedUrlCache(path);
}else {
} else {
if (!path.contains("/")) {
throw new BusinessException("The path is error!");
}
@@ -387,21 +391,22 @@ public class MinioUtil {
/**
* 将桶名、文件名从url中分离出来
* @param url 带桶名、文件名的url
*
* @param url 带桶名、文件名的url
* @param expiry 图片过期时间
* @return 可以直接访问的minio图片地址
*/
public String splitThenGetPreviewUrl(String url,int expiry){
public String splitThenGetPreviewUrl(String url, int expiry) {
String[] parts = url.split("/");
String bucketName = parts[0];
StringBuilder fileName = new StringBuilder();
for (int i = 1; i < parts.length; i++){
for (int i = 1; i < parts.length; i++) {
fileName.append(parts[i]);
if (i != parts.length -1){
if (i != parts.length - 1) {
fileName.append("/");
}
}
return getPresignedUrl(bucketName, String.valueOf(fileName),expiry);
return getPresignedUrl(bucketName, String.valueOf(fileName), expiry);
}
public boolean doesObjectExist(String bucketName, String objectName) {

View File

@@ -45,24 +45,20 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
finally {
} finally {
if (inputStream != null) {
try {
inputStream.close();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
if (reader != null) {
try {
reader.close();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
@@ -72,6 +68,7 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
/**
* 复制输入流
*
* @param inputStream 请求输入流
* @return 复制出来的输入流
*/
@@ -84,8 +81,7 @@ public class MultiReadHttpServletRequest extends HttpServletRequestWrapper {
byteArrayOutputStream.write(buffer, 0, len);
}
byteArrayOutputStream.flush();
}
catch (IOException e) {
} catch (IOException e) {
e.printStackTrace();
}
return new ByteArrayInputStream(byteArrayOutputStream.toByteArray());

View File

@@ -1,4 +1,5 @@
package com.ai.da.common.utils;
import java.util.*;
import java.lang.reflect.Field;

View File

@@ -5,10 +5,10 @@ public class PantoneUtils {
public static int[] rgbToHsv(int[] rgb) {
//切割rgb数组
int red = rgb[0];
int green= rgb[1];
int green = rgb[1];
int blue = rgb[2];
float r = (float) red / 255;
float r = (float) red / 255;
float g = (float) green / 255;
float b = (float) blue / 255;
@@ -21,7 +21,7 @@ public class PantoneUtils {
hsv[0] = 60 * (
(hsv[2] == min) ? Float.NaN :
(hsv[2] == r) ? (g - b) / (hsv[2] - min) + ((g < b) ? 6 : 0) :
(hsv[2] == g) ? (b - r) / (hsv[2] - min) + 2:
(hsv[2] == g) ? (b - r) / (hsv[2] - min) + 2 :
(r - g) / (hsv[2] - min) + 4
);

View File

@@ -35,16 +35,17 @@ public class RandomsUtil {
* @param randomEnd
*/
public static String generateVerifyCode(Long randomStart, Long randomEnd) {
return String.valueOf(RandomUtil.randomLong(randomStart,randomEnd));
return String.valueOf(RandomUtil.randomLong(randomStart, randomEnd));
}
/**
* 生成随机系统图片
*
* @param randomStart 可以等于
* @param randomEnd 小于最大值
* @param randomEnd 小于最大值
*/
public static Long randomSysFile(Long randomStart, Long randomEnd) {
return RandomUtil.randomLong(randomStart,randomEnd);
return RandomUtil.randomLong(randomStart, randomEnd);
}

View File

@@ -13,36 +13,36 @@ import java.util.concurrent.TimeUnit;
**/
public final class RedisCacheUtils {
private static RedisTemplate<String, Object> getRedisTemplate(){
private static RedisTemplate<String, Object> getRedisTemplate() {
return SpringUtils.getBean("redisTemplate");
}
private static <T> RedisTemplate<String, T> getRedisTemplate(Class<T> clazz){
private static <T> RedisTemplate<String, T> getRedisTemplate(Class<T> clazz) {
return SpringUtils.getBean("redisTemplate");
}
private static <T> RedisTemplate<String, List<T>> getListRedisTemplate(Class<T> clazz){
private static <T> RedisTemplate<String, List<T>> getListRedisTemplate(Class<T> clazz) {
return SpringUtils.getBean("redisTemplate");
}
public static <T> T get(String key, Class<T> clazz){
public static <T> T get(String key, Class<T> clazz) {
return getRedisTemplate(clazz).opsForValue().get(key);
}
public static <T> List<T> getList(String key, Class<T> clazz){
public static <T> List<T> getList(String key, Class<T> clazz) {
return getListRedisTemplate(clazz).opsForValue().get(key);
}
public static void set(String key, Object value){
public static void set(String key, Object value) {
getRedisTemplate().opsForValue().set(key, value);
}
public static void set(String key, Object value, long time, TimeUnit unit){
public static void set(String key, Object value, long time, TimeUnit unit) {
getRedisTemplate().opsForValue().set(key, value, time, unit);
}
public static boolean delete(String key){
if(StrUtil.isNotEmpty(key)){
public static boolean delete(String key) {
if (StrUtil.isNotEmpty(key)) {
return Boolean.TRUE.equals(getRedisTemplate().delete(key));
}
return false;

View File

@@ -10,17 +10,16 @@ public class RequestInfoUtil {
* @param request
* @return java.lang.String
* @version 1.0
*
*
* <p>
* <p>
* 使用了ng等代理服务器要在ng加以下配置
* location / {
* proxy_pass http://127.0.0.1:10678;
* proxy_set_header Host $host;
* proxy_set_header X-Real-IP $remote_addr;
* proxy_set_header REMOTE-HOST $remote_addr;
* proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
* }
* proxy_pass http://127.0.0.1:10678;
* proxy_set_header Host $host;
* proxy_set_header X-Real-IP $remote_addr;
* proxy_set_header REMOTE-HOST $remote_addr;
* proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
* }
*/
public static String getIpAddress(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");

View File

@@ -59,6 +59,7 @@ public class RsaDecryptUtils {
/**
* 解密
*
* @param args
* @throws NoSuchAlgorithmException
*/

View File

@@ -8,15 +8,15 @@ public class SecurityContextUtils {
public static AuthPrincipalVo getCurrentUser() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null && authentication.getPrincipal() != null){
return (AuthPrincipalVo) authentication.getPrincipal();
if (authentication != null && authentication.getPrincipal() != null) {
return (AuthPrincipalVo) authentication.getPrincipal();
}
return null;
}
public static Long getCurrentUserId() {
AuthPrincipalVo currentUser = getCurrentUser();
if(currentUser != null){
if (currentUser != null) {
return currentUser.getId();
}
return null;
@@ -24,7 +24,7 @@ public class SecurityContextUtils {
public static String getCurrentUsername() {
AuthPrincipalVo currentUser = getCurrentUser();
if(currentUser != null){
if (currentUser != null) {
return currentUser.getUsername();
}
return null;

View File

@@ -65,8 +65,8 @@ public class SendEmailUtil {
public static Long BIND_MAILBOX_TEMPLATE_ID = 45619L;
public static Boolean send(String receiverAddress,String ip,Long templateId,String verifyCode) {
try{
public static Boolean send(String receiverAddress, String ip, Long templateId, String verifyCode) {
try {
// 实例化一个认证对象入参需要传入腾讯云账户secretIdsecretKey,此处还需注意密钥对的保密
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
Credential cred = new Credential(SECRET_ID, SECRET_KEy);
@@ -85,30 +85,31 @@ public class SendEmailUtil {
req.setDestination(new String[]{receiverAddress});
String subject = templateId == LOGIN_TEMPLATE_ID ? LOGIN_SUBJECT :
templateId == UPDATE_PWD_TEMPLATE_ID ? FORGET_PWD_SUBJECT :
templateId == EXCEPTION_ID_TEMPLATE_ID ? EXCEPTION_ID_SUBJECT :BIND_MAILBOX_SUBJECT;
templateId == EXCEPTION_ID_TEMPLATE_ID ? EXCEPTION_ID_SUBJECT : BIND_MAILBOX_SUBJECT;
req.setSubject(subject);
req.setTemplate(contractTemplate(templateId, verifyCode,ip));
req.setTemplate(contractTemplate(templateId, verifyCode, ip));
// 返回的resp是一个SendEmailResponse的实例与请求对象对应
SendEmailResponse resp = client.SendEmail(req);
// 输出json格式的字符串回包
log.info("短信发送结果res###{}",SendEmailResponse.toJsonString(resp));
return Boolean.TRUE;
log.info("短信发送结果res###{}", SendEmailResponse.toJsonString(resp));
return Boolean.TRUE;
} catch (TencentCloudSDKException e) {
log.info("邮件发送失败###{}",e.toString());
log.info("邮件发送失败###{}", e.toString());
throw new BusinessException(e.getMessage());
}
}
private static Template contractTemplate(Long templateId,String verifyCode,String ip){
private static Template contractTemplate(Long templateId, String verifyCode, String ip) {
Template template = new Template();
template.setTemplateID(templateId);
JSONObject jsonObject = new JSONObject();
if(templateId == EXCEPTION_ID_TEMPLATE_ID ){
jsonObject.put("exceptionIp",ip);
jsonObject.put("loginTime",DateUtil.dateToStr(new Date(),DateUtil.YYYY_MM_DD_HH_MM_SS));
}else{
jsonObject.put("code",verifyCode);
if (templateId == EXCEPTION_ID_TEMPLATE_ID) {
jsonObject.put("exceptionIp", ip);
jsonObject.put("loginTime", DateUtil.dateToStr(new Date(), DateUtil.YYYY_MM_DD_HH_MM_SS));
} else {
jsonObject.put("code", verifyCode);
}
template.setTemplateData(jsonObject.toJSONString());
return template;

View File

@@ -27,18 +27,18 @@ public class SpringUtils implements ApplicationContextAware {
}
public static <T> T getBean(String beanName) {
if(applicationContext.containsBean(beanName)){
if (applicationContext.containsBean(beanName)) {
return (T) applicationContext.getBean(beanName);
}else{
} else {
return null;
}
}
public static <T> Map<String, T> getBeansOfType(Class<T> baseType){
public static <T> Map<String, T> getBeansOfType(Class<T> baseType) {
return applicationContext.getBeansOfType(baseType);
}
public static ApplicationContext getApplicationContext(){
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}