mirror of https://gitee.com/stylefeng/roses
Merge branch 'dev-7.1.6'
commit
b745ec3229
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
*
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.rule.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 用来标记在控制器类或方法上,进行判断是否需要对接口进行日志记录
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/1/12 20:48
|
||||
*/
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface BusinessLog {
|
||||
|
||||
/**
|
||||
* 是否进行日志记录,默认是开启
|
||||
*/
|
||||
boolean openLog() default true;
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@
|
|||
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||
*/
|
||||
package cn.stylefeng.roses.kernel.scanner.api.annotation.field;
|
||||
package cn.stylefeng.roses.kernel.rule.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
|
@ -80,7 +80,7 @@ public interface RuleConstants {
|
|||
/**
|
||||
* 中文的多语言类型编码
|
||||
*/
|
||||
String CHINES_TRAN_LANGUAGE_CODE = "chinese";
|
||||
String CHINESE_TRAN_LANGUAGE_CODE = "chinese";
|
||||
|
||||
/**
|
||||
* 租户数据源标识前缀
|
||||
|
|
|
@ -44,10 +44,11 @@ public interface SymbolConstant {
|
|||
|
||||
String AND = "&";
|
||||
|
||||
String POINT = ".";
|
||||
String DOT = ".";
|
||||
|
||||
String SLASH = "/";
|
||||
|
||||
String BACK_SLASH = "\\";
|
||||
|
||||
String SPACE = " ";
|
||||
}
|
||||
|
|
|
@ -65,6 +65,11 @@ public class ServiceException extends RuntimeException {
|
|||
*/
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 异常的具体携带数据
|
||||
*/
|
||||
private Object data;
|
||||
|
||||
/**
|
||||
* 根据模块名,错误码,用户提示直接抛出异常
|
||||
*/
|
||||
|
@ -97,4 +102,15 @@ public class ServiceException extends RuntimeException {
|
|||
this.userTip = exception.getUserTip();
|
||||
}
|
||||
|
||||
/**
|
||||
* 携带数据的异常构造函数
|
||||
*/
|
||||
public ServiceException(String moduleName, String errorCode, String userTip, Object data) {
|
||||
super(userTip);
|
||||
this.errorCode = errorCode;
|
||||
this.moduleName = moduleName;
|
||||
this.userTip = userTip;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.rule.pojo.dict;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
@ -44,16 +45,19 @@ public class SimpleDict {
|
|||
/**
|
||||
* id
|
||||
*/
|
||||
@ChineseDescription("id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@ChineseDescription("名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@ChineseDescription("编码")
|
||||
private String code;
|
||||
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import lombok.EqualsAndHashCode;
|
|||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class ErrorResponseData extends ResponseData {
|
||||
public class ErrorResponseData<T> extends ResponseData<T> {
|
||||
|
||||
/**
|
||||
* 异常的具体类名称
|
||||
|
@ -58,7 +58,7 @@ public class ErrorResponseData extends ResponseData {
|
|||
super(Boolean.FALSE, code, message, null);
|
||||
}
|
||||
|
||||
public ErrorResponseData(String code, String message, Object object) {
|
||||
public ErrorResponseData(String code, String message, T object) {
|
||||
super(Boolean.FALSE, code, message, object);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.rule.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
@ -33,32 +34,36 @@ import lombok.Data;
|
|||
* @date 2020/10/17 17:33
|
||||
*/
|
||||
@Data
|
||||
public class ResponseData {
|
||||
public class ResponseData<T> {
|
||||
|
||||
/**
|
||||
* 请求是否成功
|
||||
*/
|
||||
@ChineseDescription("请求是否成功")
|
||||
private Boolean success;
|
||||
|
||||
/**
|
||||
* 响应状态码
|
||||
*/
|
||||
@ChineseDescription("响应状态码")
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 响应信息
|
||||
*/
|
||||
@ChineseDescription("响应信息")
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 响应对象
|
||||
*/
|
||||
private Object data;
|
||||
@ChineseDescription("响应对象")
|
||||
private T data;
|
||||
|
||||
public ResponseData() {
|
||||
}
|
||||
|
||||
public ResponseData(Boolean success, String code, String message, Object data) {
|
||||
public ResponseData(Boolean success, String code, String message, T data) {
|
||||
this.success = success;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
|
|
|
@ -32,17 +32,17 @@ import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
|||
* @author fengshuonan
|
||||
* @date 2020/10/16 16:23
|
||||
*/
|
||||
public class SuccessResponseData extends ResponseData {
|
||||
public class SuccessResponseData<T> extends ResponseData<T> {
|
||||
|
||||
public SuccessResponseData() {
|
||||
super(Boolean.TRUE, RuleConstants.SUCCESS_CODE, RuleConstants.SUCCESS_MESSAGE, null);
|
||||
}
|
||||
|
||||
public SuccessResponseData(Object object) {
|
||||
public SuccessResponseData(T object) {
|
||||
super(Boolean.TRUE, RuleConstants.SUCCESS_CODE, RuleConstants.SUCCESS_MESSAGE, object);
|
||||
}
|
||||
|
||||
public SuccessResponseData(String code, String message, Object object) {
|
||||
public SuccessResponseData(String code, String message, T object) {
|
||||
super(Boolean.TRUE, code, message, object);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.rule.tree.ztree;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TreeConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.tree.factory.base.AbstractTreeNode;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -48,11 +49,13 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("节点id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 父节点id
|
||||
*/
|
||||
@ChineseDescription("父节点id")
|
||||
private Long pId;
|
||||
|
||||
/**
|
||||
|
@ -60,6 +63,7 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("节点名称")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
|
@ -67,6 +71,7 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("是否打开节点")
|
||||
private Boolean open;
|
||||
|
||||
/**
|
||||
|
@ -74,6 +79,7 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("是否被选中")
|
||||
private Boolean checked;
|
||||
|
||||
/**
|
||||
|
@ -81,6 +87,7 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("节点图标")
|
||||
private String iconSkin;
|
||||
|
||||
/**
|
||||
|
@ -88,6 +95,7 @@ public class ZTreeNode implements AbstractTreeNode<ZTreeNode> {
|
|||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ChineseDescription("子节点集合")
|
||||
private List<ZTreeNode> children;
|
||||
|
||||
/**
|
||||
|
|
|
@ -56,6 +56,11 @@ public class HttpServletUtil {
|
|||
*/
|
||||
private static final String LOCAL_IP = "127.0.0.1";
|
||||
|
||||
/**
|
||||
* Nginx代理自定义的IP名称
|
||||
*/
|
||||
private static final String AGENT_SOURCE_IP = "Agent-Source-Ip";
|
||||
|
||||
/**
|
||||
* 本机ip地址的ipv6地址
|
||||
*/
|
||||
|
@ -73,7 +78,7 @@ public class HttpServletUtil {
|
|||
* @date 2020/10/15 17:48
|
||||
*/
|
||||
public static HttpServletRequest getRequest() {
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes == null) {
|
||||
throw new ServiceException(ServletExceptionEnum.HTTP_CONTEXT_ERROR);
|
||||
} else {
|
||||
|
@ -88,7 +93,7 @@ public class HttpServletUtil {
|
|||
* @date 2020/10/15 17:48
|
||||
*/
|
||||
public static HttpServletResponse getResponse() {
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
|
||||
if (requestAttributes == null) {
|
||||
throw new ServiceException(ServletExceptionEnum.HTTP_CONTEXT_ERROR);
|
||||
} else {
|
||||
|
@ -108,7 +113,7 @@ public class HttpServletUtil {
|
|||
if (ObjectUtil.isEmpty(request)) {
|
||||
return LOCAL_IP;
|
||||
} else {
|
||||
String remoteHost = ServletUtil.getClientIP(request);
|
||||
String remoteHost = ServletUtil.getClientIP(request, AGENT_SOURCE_IP);
|
||||
return LOCAL_REMOTE_HOST.equals(remoteHost) ? LOCAL_IP : remoteHost;
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +156,7 @@ public class HttpServletUtil {
|
|||
HttpRequest http = HttpUtil.createGet(String.format(ipGeoApi, ip));
|
||||
http.header(requestApiHeader, appCodeSymbol + " " + ipGeoAppCode);
|
||||
resultJson = http.timeout(3000).execute().body();
|
||||
resultJson = String.join("", (List<String>) JSONPath.read(resultJson, jsonPath));
|
||||
resultJson = String.join("", (List<String>)JSONPath.read(resultJson, jsonPath));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("根据ip定位异常,具体信息为:{}", e.getMessage());
|
||||
|
@ -192,8 +197,7 @@ public class HttpServletUtil {
|
|||
* @date 2021/2/22 22:37
|
||||
*/
|
||||
public static Boolean getNormalRequestFlag(HttpServletRequest request) {
|
||||
return request.getHeader("Accept") == null
|
||||
|| request.getHeader("Accept").toLowerCase().contains("text/html");
|
||||
return request.getHeader("Accept") == null || request.getHeader("Accept").toLowerCase().contains("text/html");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -206,8 +210,7 @@ public class HttpServletUtil {
|
|||
* @date 2021/2/22 22:37
|
||||
*/
|
||||
public static Boolean getJsonRequestFlag(HttpServletRequest request) {
|
||||
return request.getHeader("Accept") == null
|
||||
|| request.getHeader("Accept").toLowerCase().contains("application/json");
|
||||
return request.getHeader("Accept") == null || request.getHeader("Accept").toLowerCase().contains("application/json");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-auth</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -114,4 +114,11 @@ public interface AuthServiceApi {
|
|||
*/
|
||||
void checkAuth(String token, String requestUrl);
|
||||
|
||||
/**
|
||||
* 取消冻结帐号
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/22 16:37
|
||||
*/
|
||||
void cancelFreeze(LoginRequest loginRequest);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,6 @@ public interface SessionManagerApi {
|
|||
*
|
||||
* @param token 用户登录的token
|
||||
* @param loginUser 登录的用户
|
||||
* @param loginUser 登录的用户
|
||||
* @author fengshuonan
|
||||
* @date 2020/10/19 16:47
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package cn.stylefeng.roses.kernel.auth.api.constants;
|
||||
|
||||
/**
|
||||
* 登录前缀相关的常量
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/22 17:37
|
||||
*/
|
||||
public interface LoginCacheConstants {
|
||||
|
||||
/**
|
||||
* 登录最大次数
|
||||
*/
|
||||
Integer MAX_LOGIN_COUNT = 5;
|
||||
|
||||
/**
|
||||
* 登录冻结缓存前缀
|
||||
*/
|
||||
String LOGIN_CACHE_PREFIX = "login:";
|
||||
|
||||
/**
|
||||
* 冻结时间
|
||||
*/
|
||||
Long LOGIN_CACHE_TIMEOUT_SECONDS = 1800L;
|
||||
}
|
|
@ -121,7 +121,12 @@ public enum AuthExceptionEnum implements AbstractExceptionEnum {
|
|||
/**
|
||||
* 无法访问未经授权的接口
|
||||
*/
|
||||
CANT_REQUEST_UN_OPEN_API(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "17", "无法访问未经授权的接口,未授权url为:{}");
|
||||
CANT_REQUEST_UN_OPEN_API(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "17", "无法访问未经授权的接口,未授权url为:{}"),
|
||||
|
||||
/**
|
||||
* 超过最大登录次数
|
||||
*/
|
||||
EXCEED_MAX_LOGIN_COUNT(RuleConstants.BUSINESS_ERROR_TYPE_CODE + AuthConstants.AUTH_EXCEPTION_STEP_CODE + "18", "超过最大登录次数,帐号被锁定");
|
||||
|
||||
/**
|
||||
* 错误编码
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package cn.stylefeng.roses.kernel.auth.api.expander;
|
||||
|
||||
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
||||
|
||||
/**
|
||||
* 登录相关配置快速获取
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/24 15:47
|
||||
*/
|
||||
public class LoginConfigExpander {
|
||||
|
||||
/**
|
||||
* 获取帐号错误次数校验开关
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/24 15:48
|
||||
*/
|
||||
public static boolean getAccountErrorDetectionFlag() {
|
||||
return ConfigContext.me().getSysConfigValueWithDefault("ACCOUNT_ERROR_DETECTION", Boolean.class, false);
|
||||
}
|
||||
}
|
|
@ -24,8 +24,8 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.auth.api.pojo.auth;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ package cn.stylefeng.roses.kernel.auth.api.pojo.auth;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,8 +30,8 @@ import cn.hutool.core.util.StrUtil;
|
|||
import cn.stylefeng.roses.kernel.auth.api.enums.DataScopeTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleRoleInfo;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.basic.SimpleUserInfo;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
|
@ -160,7 +160,7 @@ public class LoginUser implements Serializable {
|
|||
* 默认语种是中文
|
||||
*/
|
||||
@ChineseDescription("当前用户语种的标识")
|
||||
private String tranLanguageCode = RuleConstants.CHINES_TRAN_LANGUAGE_CODE;
|
||||
private String tranLanguageCode = RuleConstants.CHINESE_TRAN_LANGUAGE_CODE;
|
||||
|
||||
/**
|
||||
* 租户的编码
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-auth</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -126,6 +126,11 @@
|
|||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>system-business-user</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -36,10 +36,12 @@ import cn.hutool.http.HttpResponse;
|
|||
import cn.stylefeng.roses.kernel.auth.api.AuthServiceApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.AuthConstants;
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.LoginCacheConstants;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.auth.api.exception.AuthException;
|
||||
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.auth.api.expander.LoginConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.password.PasswordTransferEncryptApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.SsoProperties;
|
||||
|
@ -47,6 +49,7 @@ import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginRequest;
|
|||
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginResponse;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.auth.LoginWithTokenRequest;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.demo.expander.DemoConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.jwt.JwtTokenOperator;
|
||||
import cn.stylefeng.roses.kernel.jwt.api.context.JwtContext;
|
||||
|
@ -66,6 +69,8 @@ import cn.stylefeng.roses.kernel.system.api.ResourceServiceApi;
|
|||
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
|
||||
import cn.stylefeng.roses.kernel.system.api.enums.UserStatusEnum;
|
||||
import cn.stylefeng.roses.kernel.system.api.pojo.user.UserLoginInfoDTO;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.entity.SysUser;
|
||||
import cn.stylefeng.roses.kernel.system.modular.user.service.SysUserService;
|
||||
import cn.stylefeng.roses.kernel.validator.api.exception.enums.ValidatorExceptionEnum;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
@ -119,6 +124,12 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
@Resource
|
||||
private ResourceServiceApi resourceServiceApi;
|
||||
|
||||
@Resource
|
||||
private SysUserService sysUserService;
|
||||
|
||||
@Resource
|
||||
private CacheOperatorApi<String> loginCacheOperatorApi;
|
||||
|
||||
@Override
|
||||
public LoginResponse login(LoginRequest loginRequest) {
|
||||
return loginAction(loginRequest, true, null);
|
||||
|
@ -254,6 +265,25 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
* @date 2020/10/21 16:59
|
||||
*/
|
||||
private LoginResponse loginAction(LoginRequest loginRequest, Boolean validatePassword, String caToken) {
|
||||
SysUser userByAccount = sysUserService.getUserByAccount(loginRequest.getAccount());
|
||||
// 判断登录错误检测是否开启
|
||||
if (LoginConfigExpander.getAccountErrorDetectionFlag()) {
|
||||
// 判断错误次数,超过最大放入缓存中
|
||||
if (StrUtil.isBlank(loginCacheOperatorApi.get(userByAccount.getUserId().toString()))) {
|
||||
if (userByAccount.getLoginCount() > LoginCacheConstants.MAX_LOGIN_COUNT) {
|
||||
loginCacheOperatorApi.put(userByAccount.getUserId().toString(), "true", 1800L);
|
||||
throw new AuthException(AuthExceptionEnum.EXCEED_MAX_LOGIN_COUNT);
|
||||
}
|
||||
} else {
|
||||
throw new AuthException(AuthExceptionEnum.EXCEED_MAX_LOGIN_COUNT);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 获取用户密码的加密值和用户的状态
|
||||
UserLoginInfoDTO userValidateInfo = userServiceApi.getUserLoginInfo(loginRequest.getAccount());
|
||||
|
||||
// 8. 获取LoginUser,用于用户的缓存
|
||||
LoginUser loginUser = userValidateInfo.getLoginUser();
|
||||
|
||||
// 1.参数为空校验
|
||||
if (validatePassword) {
|
||||
|
@ -275,6 +305,8 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||
}
|
||||
if (!captchaApi.validateCaptcha(verKey, verCode)) {
|
||||
// 登录失败日志
|
||||
loginLogServiceApi.loginFail(loginUser.getUserId(), "验证码错误");
|
||||
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -288,6 +320,8 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
throw new AuthException(ValidatorExceptionEnum.CAPTCHA_EMPTY);
|
||||
}
|
||||
if (!dragCaptchaApi.validateCaptcha(verKey, Convert.toInt(verXLocationValue))) {
|
||||
// 登录失败日志
|
||||
loginLogServiceApi.loginFail(loginUser.getUserId(), "拖拽验证码错误");
|
||||
throw new AuthException(ValidatorExceptionEnum.DRAG_CAPTCHA_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -308,13 +342,15 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
return new LoginResponse(remoteLoginCode);
|
||||
}
|
||||
|
||||
// 5. 获取用户密码的加密值和用户的状态
|
||||
UserLoginInfoDTO userValidateInfo = userServiceApi.getUserLoginInfo(loginRequest.getAccount());
|
||||
|
||||
// 6. 校验用户密码是否正确
|
||||
if (validatePassword) {
|
||||
Boolean checkResult = passwordStoredEncryptApi.checkPassword(loginRequest.getPassword(), userValidateInfo.getUserPasswordHexed());
|
||||
if (!checkResult) {
|
||||
//更新登录次数
|
||||
userByAccount.setLoginCount(userByAccount.getLoginCount() + 1);
|
||||
sysUserService.updateById(userByAccount);
|
||||
// 登录失败日志
|
||||
loginLogServiceApi.loginFail(loginUser.getUserId(), "帐号或密码错误");
|
||||
throw new AuthException(AuthExceptionEnum.USERNAME_PASSWORD_ERROR);
|
||||
}
|
||||
}
|
||||
|
@ -324,9 +360,6 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
throw new AuthException(AuthExceptionEnum.USER_STATUS_ERROR, UserStatusEnum.getCodeMessage(userValidateInfo.getUserStatus()));
|
||||
}
|
||||
|
||||
// 8. 获取LoginUser,用于用户的缓存
|
||||
LoginUser loginUser = userValidateInfo.getLoginUser();
|
||||
|
||||
// 9. 生成用户的token
|
||||
DefaultJwtPayload defaultJwtPayload = new DefaultJwtPayload(loginUser.getUserId(), loginUser.getAccount(), loginRequest.getRememberMe(), caToken);
|
||||
String jwtToken = JwtContext.me().generateTokenDefaultPayload(defaultJwtPayload);
|
||||
|
@ -355,6 +388,10 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
String ip = HttpServletUtil.getRequestClientIp(HttpServletUtil.getRequest());
|
||||
userServiceApi.updateUserLoginInfo(loginUser.getUserId(), new Date(), ip);
|
||||
|
||||
//重置登录次数
|
||||
userByAccount.setLoginCount(1);
|
||||
sysUserService.updateById(userByAccount);
|
||||
|
||||
// 13.登录成功日志
|
||||
loginLogServiceApi.loginSuccess(loginUser.getUserId());
|
||||
}
|
||||
|
@ -403,4 +440,13 @@ public class AuthServiceImpl implements AuthServiceApi {
|
|||
return loginCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelFreeze(LoginRequest loginRequest) {
|
||||
SysUser sysUser = sysUserService.getUserByAccount(loginRequest.getAccount());
|
||||
sysUser.setLoginCount(1);
|
||||
// 修改数据库中的登录次数
|
||||
sysUserService.updateById(sysUser);
|
||||
// 删除缓存中的数据
|
||||
loginCacheOperatorApi.remove(sysUser.getUserId().toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.auth.auth;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.LoginUserApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginUserHolder;
|
||||
|
@ -32,9 +31,6 @@ import cn.stylefeng.roses.kernel.auth.api.exception.AuthException;
|
|||
import cn.stylefeng.roses.kernel.auth.api.exception.enums.AuthExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.auth.api.loginuser.CommonLoginUserUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.dsctn.api.constants.DatasourceContainerConstants;
|
||||
import cn.stylefeng.roses.kernel.dsctn.api.context.CurrentDataSourceContext;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.system.api.UserServiceApi;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -80,19 +76,7 @@ public class LoginUserImpl implements LoginUserApi {
|
|||
throw new AuthException(AuthExceptionEnum.AUTH_EXPIRED_ERROR);
|
||||
}
|
||||
|
||||
// 获取当前上下文的数据源名称
|
||||
String dataSourceName = CurrentDataSourceContext.getDataSourceName();
|
||||
|
||||
// 如果当前用户有租户编码,则需要切下数据源
|
||||
if (ObjectUtil.isNotEmpty(session.getTenantCode()) && !session.getTenantCode().equals(DatasourceContainerConstants.MASTER_DATASOURCE_NAME)) {
|
||||
CurrentDataSourceContext.setDataSourceName(RuleConstants.TENANT_DB_PREFIX + session.getTenantCode());
|
||||
}
|
||||
try {
|
||||
// 从新组装一次loginUser,保证loginUser中数据的时效性
|
||||
return userServiceApi.getEffectiveLoginUser(session);
|
||||
} finally {
|
||||
CurrentDataSourceContext.setDataSourceName(dataSourceName);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
23
kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/cache/LoginMemoryCache.java
vendored
Normal file
23
kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/cache/LoginMemoryCache.java
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.auth.cache;
|
||||
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.LoginCacheConstants;
|
||||
import cn.stylefeng.roses.kernel.cache.memory.AbstractMemoryCacheOperator;
|
||||
|
||||
/**
|
||||
* 用户帐号冻结的缓存
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/22 17:33
|
||||
*/
|
||||
public class LoginMemoryCache extends AbstractMemoryCacheOperator<String> {
|
||||
|
||||
public LoginMemoryCache(TimedCache<String, String> timedCache) {
|
||||
super(timedCache);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return LoginCacheConstants.LOGIN_CACHE_PREFIX;
|
||||
}
|
||||
}
|
23
kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/cache/LoginRedisCache.java
vendored
Normal file
23
kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/cache/LoginRedisCache.java
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
package cn.stylefeng.roses.kernel.auth.cache;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.LoginCacheConstants;
|
||||
import cn.stylefeng.roses.kernel.cache.redis.AbstractRedisCacheOperator;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
/**
|
||||
* 用户帐号冻结的缓存
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/23 23:34
|
||||
*/
|
||||
public class LoginRedisCache extends AbstractRedisCacheOperator<String> {
|
||||
|
||||
public LoginRedisCache(RedisTemplate<String, String> redisTemplate) {
|
||||
super(redisTemplate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCommonKeyPrefix() {
|
||||
return LoginCacheConstants.LOGIN_CACHE_PREFIX;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-auth</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package cn.stylefeng.roses.kernel.auth.starter;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import cn.stylefeng.roses.kernel.auth.api.constants.LoginCacheConstants;
|
||||
import cn.stylefeng.roses.kernel.auth.cache.LoginMemoryCache;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 登录缓存的自动配置
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/22 17:40
|
||||
*/
|
||||
@Configuration
|
||||
public class GunsLoginCacheAutoConfiguration {
|
||||
|
||||
/**
|
||||
* 登录帐号冻结的缓存
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/22 17:45
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(name = "loginCacheOperatorApi")
|
||||
public CacheOperatorApi<String> loginCacheOperatorApi() {
|
||||
TimedCache<String, String> loginTimeCache = CacheUtil.newTimedCache(LoginCacheConstants.LOGIN_CACHE_TIMEOUT_SECONDS * 1000);
|
||||
return new LoginMemoryCache(loginTimeCache);
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.stylefeng.roses.kernel.auth.starter.GunsAuthAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.auth.starter.GunsSsoAutoConfiguration
|
||||
cn.stylefeng.roses.kernel.auth.starter.GunsSsoAutoConfiguration,\
|
||||
cn.stylefeng.roses.kernel.auth.starter.GunsLoginCacheAutoConfiguration
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-cache</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-cache</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-cache</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-cache</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-cache</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-config</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.config.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
@ -18,21 +19,25 @@ public class ConfigInitItem {
|
|||
/**
|
||||
* 配置中文名称
|
||||
*/
|
||||
@ChineseDescription("配置中文名称")
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* 配置编码
|
||||
*/
|
||||
@ChineseDescription("配置编码")
|
||||
private String configCode;
|
||||
|
||||
/**
|
||||
* 配置的初始化值
|
||||
*/
|
||||
@ChineseDescription("配置初始化值")
|
||||
private String configValue;
|
||||
|
||||
/**
|
||||
* 配置的描述
|
||||
*/
|
||||
@ChineseDescription("配置的描述")
|
||||
private String configDescription;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.stylefeng.roses.kernel.config.api.pojo;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -18,6 +19,7 @@ public class ConfigInitRequest {
|
|||
* <p>
|
||||
* key是配置编码,value是配置值
|
||||
*/
|
||||
@ChineseDescription("系统配置集合")
|
||||
private Map<String, String> sysConfigs;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-config</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -24,9 +24,12 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.config.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitRequest;
|
||||
import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig;
|
||||
import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam;
|
||||
import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService;
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
|
@ -37,7 +40,7 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置控制器
|
||||
|
@ -59,9 +62,9 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:11
|
||||
*/
|
||||
@PostResource(name = "添加系统参数配置", path = "/sysConfig/add")
|
||||
public ResponseData add(@RequestBody @Validated(SysConfigParam.add.class) SysConfigParam sysConfigParam) {
|
||||
public ResponseData<?> add(@RequestBody @Validated(SysConfigParam.add.class) SysConfigParam sysConfigParam) {
|
||||
sysConfigService.add(sysConfigParam);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,9 +74,9 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:11
|
||||
*/
|
||||
@PostResource(name = "删除系统参数配置", path = "/sysConfig/delete")
|
||||
public ResponseData delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) {
|
||||
public ResponseData<?> delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) {
|
||||
sysConfigService.del(sysConfigParam);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,9 +86,9 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:11
|
||||
*/
|
||||
@PostResource(name = "编辑系统参数配置", path = "/sysConfig/edit")
|
||||
public ResponseData edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) {
|
||||
public ResponseData<?> edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) {
|
||||
sysConfigService.edit(sysConfigParam);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -95,8 +98,8 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:12
|
||||
*/
|
||||
@GetResource(name = "查看系统参数配置", path = "/sysConfig/detail")
|
||||
public ResponseData detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData(sysConfigService.detail(sysConfigParam));
|
||||
public ResponseData<SysConfig> detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData<>(sysConfigService.detail(sysConfigParam));
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,8 +110,8 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:10
|
||||
*/
|
||||
@GetResource(name = "分页查询配置列表", path = "/sysConfig/page")
|
||||
public ResponseData page(SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData(sysConfigService.findPage(sysConfigParam));
|
||||
public ResponseData<PageResult<SysConfig>> page(SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData<>(sysConfigService.findPage(sysConfigParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -118,8 +121,8 @@ public class SysConfigController {
|
|||
* @date 2020/4/14 11:10
|
||||
*/
|
||||
@GetResource(name = "系统参数配置列表", path = "/sysConfig/list")
|
||||
public ResponseData list(SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData(sysConfigService.findList(sysConfigParam));
|
||||
public ResponseData<List<SysConfig>> list(SysConfigParam sysConfigParam) {
|
||||
return new SuccessResponseData<>(sysConfigService.findList(sysConfigParam));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -129,8 +132,8 @@ public class SysConfigController {
|
|||
* @date 2021/7/8 17:20
|
||||
*/
|
||||
@GetResource(name = "获取系统配置是否初始化的标志", path = "/sysConfig/getInitConfigFlag", requiredPermission = false)
|
||||
public ResponseData getInitConfigFlag() {
|
||||
return new SuccessResponseData(sysConfigService.getInitConfigFlag());
|
||||
public ResponseData<Boolean> getInitConfigFlag() {
|
||||
return new SuccessResponseData<>(sysConfigService.getInitConfigFlag());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,9 +143,9 @@ public class SysConfigController {
|
|||
* @date 2021/7/8 16:36
|
||||
*/
|
||||
@PostResource(name = "初始化系统配置参数,用在系统第一次登录时", path = "/sysConfig/initConfig", requiredPermission = false)
|
||||
public ResponseData initConfig(@RequestBody ConfigInitRequest configInitRequest) {
|
||||
public ResponseData<?> initConfig(@RequestBody ConfigInitRequest configInitRequest) {
|
||||
sysConfigService.initConfig(configInitRequest);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,8 +155,8 @@ public class SysConfigController {
|
|||
* @date 2021/7/8 16:36
|
||||
*/
|
||||
@GetResource(name = "获取需要初始化的配置列表", path = "/sysConfig/getInitConfigList")
|
||||
public ResponseData getInitConfigList() {
|
||||
return new SuccessResponseData(sysConfigService.getInitConfigs());
|
||||
public ResponseData<List<ConfigInitItem>> getInitConfigList() {
|
||||
return new SuccessResponseData<>(sysConfigService.getInitConfigs());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.config.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -46,54 +47,63 @@ public class SysConfig extends BaseEntity {
|
|||
* 主键
|
||||
*/
|
||||
@TableId(value = "config_id", type = IdType.ASSIGN_ID)
|
||||
@ChineseDescription("主键id")
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@TableField("config_name")
|
||||
@ChineseDescription("名称")
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@TableField("config_code")
|
||||
@ChineseDescription("编码")
|
||||
private String configCode;
|
||||
|
||||
/**
|
||||
* 属性值
|
||||
*/
|
||||
@TableField("config_value")
|
||||
@ChineseDescription("属性值")
|
||||
private String configValue;
|
||||
|
||||
/**
|
||||
* 是否是系统参数:Y-是,N-否
|
||||
*/
|
||||
@TableField("sys_flag")
|
||||
@ChineseDescription("是否是系统参数:Y-是,N-否")
|
||||
private String sysFlag;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@TableField("remark")
|
||||
@ChineseDescription("备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态:1-正常,2停用
|
||||
*/
|
||||
@TableField("status_flag")
|
||||
@ChineseDescription("状态:1-正常,2停用")
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 常量所属分类的编码,来自于“常量的分类”字典
|
||||
*/
|
||||
@TableField("group_code")
|
||||
@ChineseDescription("常量所属分类的编码")
|
||||
private String groupCode;
|
||||
|
||||
/**
|
||||
* 是否删除:Y-被删除,N-未删除
|
||||
*/
|
||||
@TableField(value = "del_flag", fill = FieldFill.INSERT)
|
||||
@ChineseDescription("是否删除:Y-被删除,N-未删除")
|
||||
private String delFlag;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.config.modular.param;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.validator.api.validators.flag.FlagValue;
|
||||
import lombok.Data;
|
||||
|
@ -46,24 +47,28 @@ public class SysConfigParam extends BaseRequest {
|
|||
* 主键
|
||||
*/
|
||||
@NotNull(message = "configId不能为空", groups = {edit.class, delete.class, detail.class})
|
||||
@ChineseDescription("主键")
|
||||
private Long configId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
@NotBlank(message = "名称不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("名称")
|
||||
private String configName;
|
||||
|
||||
/**
|
||||
* 编码
|
||||
*/
|
||||
@NotBlank(message = "编码不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("编码")
|
||||
private String configCode;
|
||||
|
||||
/**
|
||||
* 配置值
|
||||
*/
|
||||
@NotBlank(message = "配置值不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("配置值")
|
||||
private String configValue;
|
||||
|
||||
/**
|
||||
|
@ -71,22 +76,26 @@ public class SysConfigParam extends BaseRequest {
|
|||
*/
|
||||
@NotBlank(message = "是否是系统参数不能为空", groups = {add.class, edit.class})
|
||||
@FlagValue(message = "是否是系统参数格式错误,正确格式应该Y或者N", groups = {add.class, edit.class})
|
||||
@ChineseDescription("是否系统参数")
|
||||
private String sysFlag;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@ChineseDescription("备注")
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 状态:1-正常,2停用
|
||||
*/
|
||||
@ChineseDescription("状态")
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 常量所属分类的编码,来自于“常量的分类”字典
|
||||
*/
|
||||
@NotBlank(message = "量所属分类的编码不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("常量所属分类的编码")
|
||||
private String groupCode;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-config</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-config</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-config</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-db</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.db.api.pojo.page;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -43,26 +44,31 @@ public class PageResult<T> implements Serializable {
|
|||
/**
|
||||
* 第几页
|
||||
*/
|
||||
@ChineseDescription("第几页,从1开始")
|
||||
private Integer pageNo = 1;
|
||||
|
||||
/**
|
||||
* 每页条数
|
||||
*/
|
||||
@ChineseDescription("每页条数")
|
||||
private Integer pageSize = 20;
|
||||
|
||||
/**
|
||||
* 总页数
|
||||
*/
|
||||
@ChineseDescription("总页数")
|
||||
private Integer totalPage = 0;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
@ChineseDescription("总记录数")
|
||||
private Integer totalRows = 0;
|
||||
|
||||
/**
|
||||
* 结果集
|
||||
*/
|
||||
@ChineseDescription("结果集")
|
||||
private List<T> rows;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-db</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-db</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-db</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -66,26 +66,26 @@ public class CustomDatabaseIdProvider implements DatabaseIdProvider {
|
|||
|
||||
} catch (Exception e2) {
|
||||
log.warn("CustomDatabaseIdProvider无法判断当前数据源类型,默认选择Mysql类型");
|
||||
return DbTypeEnum.MYSQL.getUrlWords();
|
||||
return DbTypeEnum.MYSQL.getXmlDatabaseId();
|
||||
}
|
||||
}
|
||||
|
||||
// 达梦和oracle使用同一种
|
||||
if (url.contains(DbTypeEnum.ORACLE.getUrlWords())) {
|
||||
return DbTypeEnum.ORACLE.getUrlWords();
|
||||
return DbTypeEnum.ORACLE.getXmlDatabaseId();
|
||||
}
|
||||
if (url.contains(DbTypeEnum.DM.getUrlWords())) {
|
||||
return DbTypeEnum.ORACLE.getUrlWords();
|
||||
return DbTypeEnum.ORACLE.getXmlDatabaseId();
|
||||
}
|
||||
|
||||
if (url.contains(DbTypeEnum.MS_SQL.getUrlWords())) {
|
||||
return DbTypeEnum.MS_SQL.getUrlWords();
|
||||
return DbTypeEnum.MS_SQL.getXmlDatabaseId();
|
||||
}
|
||||
if (url.contains(DbTypeEnum.PG_SQL.getUrlWords())) {
|
||||
return DbTypeEnum.PG_SQL.getUrlWords();
|
||||
return DbTypeEnum.PG_SQL.getXmlDatabaseId();
|
||||
}
|
||||
|
||||
return DbTypeEnum.MYSQL.getUrlWords();
|
||||
return DbTypeEnum.MYSQL.getXmlDatabaseId();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-db</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
|||
<artifactId>db-sdk-flyway</artifactId>
|
||||
<version>${roses.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package cn.stylefeng.roses.kernel.db.starter;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
|
||||
import com.alibaba.druid.util.Utils;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import javax.servlet.*;
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
@AutoConfigureBefore(DataSourceAutoConfiguration.class)
|
||||
public class RemoveDruidAdConfig {
|
||||
|
||||
/**
|
||||
* 除去页面底部的广告
|
||||
*
|
||||
* @author xixiaowei
|
||||
* @date 2022/1/24 15:23
|
||||
*/
|
||||
@Bean
|
||||
public FilterRegistrationBean removeDruidAdFilterRegistrationBean() {
|
||||
// 提取common.js的配置路径
|
||||
String pattern = "/druid/*";
|
||||
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
||||
|
||||
final String filePath = "support/http/resources/js/common.js";
|
||||
|
||||
//创建filter进行过滤
|
||||
Filter filter = new Filter() {
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) throws ServletException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
|
||||
chain.doFilter(request, response);
|
||||
// 重置缓冲区,响应头不会被重置
|
||||
response.resetBuffer();
|
||||
// 获取common.js
|
||||
String text = Utils.readFromResource(filePath);
|
||||
// 正则替换banner, 除去底部的广告信息
|
||||
text = text.replaceAll("<a.*?banner\"></a><br/>", "");
|
||||
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
||||
response.getWriter().write(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
};
|
||||
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
||||
registrationBean.setFilter(filter);
|
||||
registrationBean.addUrlPatterns(commonJsPattern);
|
||||
return registrationBean;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-ds-container</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.dsctn.api.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.validator.api.validators.unique.TableUniqueValue;
|
||||
import lombok.Data;
|
||||
|
@ -48,6 +49,7 @@ public class DatabaseInfoRequest extends BaseRequest {
|
|||
* 主键id
|
||||
*/
|
||||
@NotNull(message = "dbId不能为空", groups = {edit.class, delete.class, detail.class})
|
||||
@ChineseDescription("主键id")
|
||||
private Long dbId;
|
||||
|
||||
/**
|
||||
|
@ -61,45 +63,53 @@ public class DatabaseInfoRequest extends BaseRequest {
|
|||
columnName = "db_name",
|
||||
idFieldName = "db_id",
|
||||
excludeLogicDeleteItems = true)
|
||||
@ChineseDescription("数据库名称(英文名称)")
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* jdbc的驱动类型
|
||||
*/
|
||||
@NotBlank(message = "jdbc的驱动类型为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("jdbc的驱动类型")
|
||||
private String jdbcDriver;
|
||||
|
||||
/**
|
||||
* jdbc的url
|
||||
*/
|
||||
@NotBlank(message = "jdbc的url", groups = {add.class, edit.class})
|
||||
@ChineseDescription("jdbc的url")
|
||||
private String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 数据库连接的账号
|
||||
*/
|
||||
@NotBlank(message = "数据库连接的账号", groups = {add.class, edit.class})
|
||||
@ChineseDescription("数据库连接的账号")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 数据库连接密码
|
||||
*/
|
||||
@NotBlank(message = "数据库连接密码", groups = {add.class, edit.class})
|
||||
@ChineseDescription("数据库连接密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据库schemaName,注意,每种数据库的schema意义不同
|
||||
*/
|
||||
@ChineseDescription("数据库schemaName")
|
||||
private String schemaName;
|
||||
|
||||
/**
|
||||
* 状态标识:1-正常,2-无法连接
|
||||
*/
|
||||
@ChineseDescription("状态标识:1-正常,2-无法连接")
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 备注,摘要
|
||||
*/
|
||||
@ChineseDescription("备注")
|
||||
private String remarks;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-ds-container</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|||
import cn.stylefeng.roses.kernel.dsctn.api.pojo.request.DatabaseInfoRequest;
|
||||
import cn.stylefeng.roses.kernel.dsctn.modular.entity.DatabaseInfo;
|
||||
import cn.stylefeng.roses.kernel.dsctn.modular.service.DatabaseInfoService;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
|
@ -62,9 +63,10 @@ public class DatabaseInfoController {
|
|||
* @date 2020/11/1 22:16
|
||||
*/
|
||||
@PostResource(name = "新增数据源", path = "/databaseInfo/add")
|
||||
public ResponseData add(@RequestBody @Validated(BaseRequest.add.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
@BusinessLog
|
||||
public ResponseData<?> add(@RequestBody @Validated(BaseRequest.add.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
databaseInfoService.add(databaseInfoRequest);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,9 +76,10 @@ public class DatabaseInfoController {
|
|||
* @date 2020/11/1 22:18
|
||||
*/
|
||||
@PostResource(name = "删除数据源", path = "/databaseInfo/delete")
|
||||
public ResponseData del(@RequestBody @Validated(DatabaseInfoRequest.delete.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
@BusinessLog
|
||||
public ResponseData<?> del(@RequestBody @Validated(DatabaseInfoRequest.delete.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
databaseInfoService.del(databaseInfoRequest);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -86,9 +89,10 @@ public class DatabaseInfoController {
|
|||
* @date 2020/11/1 22:16
|
||||
*/
|
||||
@PostResource(name = "编辑数据源", path = "/databaseInfo/edit")
|
||||
public ResponseData edit(@RequestBody @Validated(DatabaseInfoRequest.edit.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
@BusinessLog
|
||||
public ResponseData<?> edit(@RequestBody @Validated(DatabaseInfoRequest.edit.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
databaseInfoService.edit(databaseInfoRequest);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -98,9 +102,9 @@ public class DatabaseInfoController {
|
|||
* @date 2020/11/1 22:18
|
||||
*/
|
||||
@GetResource(name = "查询数据源列表(带分页)", path = "/databaseInfo/page")
|
||||
public ResponseData findPage(DatabaseInfoRequest databaseInfoRequest) {
|
||||
public ResponseData<PageResult<DatabaseInfo>> findPage(DatabaseInfoRequest databaseInfoRequest) {
|
||||
PageResult<DatabaseInfo> pageResult = databaseInfoService.findPage(databaseInfoRequest);
|
||||
return new SuccessResponseData(pageResult);
|
||||
return new SuccessResponseData<>(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,9 +114,9 @@ public class DatabaseInfoController {
|
|||
* @date 2020/11/1 22:18
|
||||
*/
|
||||
@GetResource(name = "查询所有数据源列表", path = "/databaseInfo/list")
|
||||
public ResponseData findList(DatabaseInfoRequest databaseInfoRequest) {
|
||||
public ResponseData<List<DatabaseInfo>> findList(DatabaseInfoRequest databaseInfoRequest) {
|
||||
List<DatabaseInfo> databaseInfos = databaseInfoService.findList(databaseInfoRequest);
|
||||
return new SuccessResponseData(databaseInfos);
|
||||
return new SuccessResponseData<>(databaseInfos);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,9 +126,9 @@ public class DatabaseInfoController {
|
|||
* @date 2021/1/23 20:29
|
||||
*/
|
||||
@GetResource(name = "查询数据源详情", path = "/databaseInfo/detail")
|
||||
public ResponseData detail(@Validated(BaseRequest.detail.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
public ResponseData<DatabaseInfo> detail(@Validated(BaseRequest.detail.class) DatabaseInfoRequest databaseInfoRequest) {
|
||||
DatabaseInfo databaseInfo = databaseInfoService.detail(databaseInfoRequest);
|
||||
return new SuccessResponseData(databaseInfo);
|
||||
return new SuccessResponseData<>(databaseInfo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.dsctn.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -46,60 +47,70 @@ public class DatabaseInfo extends BaseEntity {
|
|||
* 主键id
|
||||
*/
|
||||
@TableId(value = "db_id", type = IdType.ASSIGN_ID)
|
||||
@ChineseDescription("主键id")
|
||||
private Long dbId;
|
||||
|
||||
/**
|
||||
* 数据库名称(英文名称)
|
||||
*/
|
||||
@TableField("db_name")
|
||||
@ChineseDescription("数据库名称(英文名称)")
|
||||
private String dbName;
|
||||
|
||||
/**
|
||||
* jdbc的驱动类型
|
||||
*/
|
||||
@TableField("jdbc_driver")
|
||||
@ChineseDescription("jdbc的驱动类型")
|
||||
private String jdbcDriver;
|
||||
|
||||
/**
|
||||
* jdbc的url
|
||||
*/
|
||||
@TableField("jdbc_url")
|
||||
@ChineseDescription("jdbc的url")
|
||||
private String jdbcUrl;
|
||||
|
||||
/**
|
||||
* 数据库连接的账号
|
||||
*/
|
||||
@TableField("username")
|
||||
@ChineseDescription("数据库连接的账号")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 数据库连接密码
|
||||
*/
|
||||
@TableField("password")
|
||||
@ChineseDescription("数据库连接密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据库的schema名称,每种数据库的schema意义都不同
|
||||
*/
|
||||
@TableField("schema_name")
|
||||
@ChineseDescription("数据库的schema名称")
|
||||
private String schemaName;
|
||||
|
||||
/**
|
||||
* 状态标识:1-正常,2-无法连接
|
||||
*/
|
||||
@TableField("status_flag")
|
||||
@ChineseDescription("状态标识:1-正常,2-无法连接")
|
||||
private Integer statusFlag;
|
||||
|
||||
/**
|
||||
* 无法连接原因
|
||||
*/
|
||||
@TableField("error_description")
|
||||
@ChineseDescription("无法连接原因")
|
||||
private String errorDescription;
|
||||
|
||||
/**
|
||||
* 备注,摘要
|
||||
*/
|
||||
@TableField("remarks")
|
||||
@ChineseDescription("备注")
|
||||
private String remarks;
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-ds-container</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-ds-container</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-email</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-email</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-email</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-email</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -65,4 +65,14 @@ public interface FileInfoApi {
|
|||
*/
|
||||
String getFileAuthUrl(Long fileId, String token);
|
||||
|
||||
/**
|
||||
* 获取文件的下载地址(不带鉴权的),生成外网地址
|
||||
*
|
||||
* @param fileId 文件id
|
||||
* @return 外部系统可以直接访问的url
|
||||
* @author fengshuonan
|
||||
* @date 2020/10/26 10:40
|
||||
*/
|
||||
String getFileUnAuthUrl(Long fileId);
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.file.api;
|
||||
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.BucketAuthEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -188,4 +189,12 @@ public interface FileOperatorApi {
|
|||
*/
|
||||
void deleteFile(String bucketName, String key);
|
||||
|
||||
/**
|
||||
* 获取当前api的文件存储类型
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/1/2 20:50
|
||||
*/
|
||||
FileLocationEnum getFileLocationEnum();
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -53,7 +53,12 @@ public enum FileLocationEnum {
|
|||
/**
|
||||
* 本地
|
||||
*/
|
||||
LOCAL(4);
|
||||
LOCAL(4),
|
||||
|
||||
/**
|
||||
* 数据库中
|
||||
*/
|
||||
DB(5);
|
||||
|
||||
private final Integer code;
|
||||
|
||||
|
|
|
@ -106,14 +106,4 @@ public class FileConfigExpander {
|
|||
return ConfigContext.me().getSysConfigValueWithDefault("SYS_LOCAL_FILE_SAVE_PATH_WINDOWS", String.class, new LocalFileProperties().getLocalFileSavePathWin());
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认的系统头像,base64编码的
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2020/12/29 20:10
|
||||
*/
|
||||
public static String getDefaultAvatarBase64() {
|
||||
return ConfigContext.me().getSysConfigValueWithDefault("SYS_DEFAULT_AVATAR_BASE64", String.class, FileConstants.DEFAULT_BASE_64_AVATAR);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.file.api.pojo.request;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -48,6 +49,7 @@ public class SysFileInfoRequest extends BaseRequest {
|
|||
* 文件ID
|
||||
*/
|
||||
@NotNull(message = "fileId不能为空", groups = {versionBack.class, detail.class})
|
||||
@ChineseDescription("文件id")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +60,7 @@ public class SysFileInfoRequest extends BaseRequest {
|
|||
* 版本号升级的依据,code相同id不同视为同一个文件的不同版本
|
||||
*/
|
||||
@NotNull(message = "fileCode不能为空", groups = {edit.class, delete.class,})
|
||||
@ChineseDescription("文件编码")
|
||||
private Long fileCode;
|
||||
|
||||
/**
|
||||
|
@ -66,48 +69,57 @@ public class SysFileInfoRequest extends BaseRequest {
|
|||
* 机密文件为需要鉴权的文件,非机密文件则不需要任何权限(不登录也可以访问)
|
||||
*/
|
||||
@NotBlank(message = "是否是机密文件不能为空", groups = {add.class, edit.class})
|
||||
@ChineseDescription("是否为机密文件,Y-是机密,N-不是机密")
|
||||
private String secretFlag;
|
||||
|
||||
/**
|
||||
* 文件名称(上传时候的文件全名,例如:开发文档.txt)
|
||||
*/
|
||||
@ChineseDescription("文件名称(上传时候的文件全名,例如:开发文档.txt)")
|
||||
private String fileOriginName;
|
||||
|
||||
/**
|
||||
* 其他文件形式传参
|
||||
*/
|
||||
@ChineseDescription("其他文件形式参数")
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地
|
||||
*/
|
||||
@ChineseDescription("文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地")
|
||||
private Integer fileLocation;
|
||||
|
||||
/**
|
||||
* 文件仓库(文件夹)
|
||||
*/
|
||||
@NotBlank(message = "fileBucket不能为空", groups = {previewByObjectName.class})
|
||||
@ChineseDescription("文件仓库(文件夹)")
|
||||
private String fileBucket;
|
||||
|
||||
/**
|
||||
* 文件后缀
|
||||
*/
|
||||
@ChineseDescription("文件后缀")
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 文件大小kb
|
||||
*/
|
||||
@ChineseDescription("文件大小")
|
||||
private Long fileSizeKb;
|
||||
|
||||
/**
|
||||
* 存储到bucket中的名称,主键id+.后缀
|
||||
*/
|
||||
@NotBlank(message = "fileObjectName不能为空", groups = {previewByObjectName.class})
|
||||
@ChineseDescription("存储到bucket中的名称,主键id+.后缀")
|
||||
private String fileObjectName;
|
||||
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
@ChineseDescription("存储路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.file.api.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -43,6 +44,7 @@ public class SysFileInfoListResponse implements Serializable {
|
|||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@ChineseDescription("主键id")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
|
@ -52,79 +54,99 @@ public class SysFileInfoListResponse implements Serializable {
|
|||
* <p>
|
||||
* 版本号升级的依据,code相同id不同视为同一个文件的不同版本
|
||||
*/
|
||||
@ChineseDescription("文件编码")
|
||||
private Long fileCode;
|
||||
|
||||
|
||||
/**
|
||||
* 文件仓库(文件夹)
|
||||
*/
|
||||
@ChineseDescription("文件仓库(文件夹)")
|
||||
private String fileBucket;
|
||||
|
||||
|
||||
/**
|
||||
* 存储到bucket中的名称,主键id+.后缀
|
||||
*/
|
||||
@ChineseDescription("存储到bucket中的名称,主键id+.后缀")
|
||||
private String fileObjectName;
|
||||
|
||||
/**
|
||||
* 是否为机密文件
|
||||
*/
|
||||
@ChineseDescription("是否为机密文件")
|
||||
private String secretFlag;
|
||||
|
||||
/**
|
||||
* 文件应用Code名称
|
||||
*/
|
||||
@ChineseDescription("文件应用Code名称")
|
||||
private String fileAppCodeName;
|
||||
|
||||
/**
|
||||
* 文件名称(上传时候的文件名)
|
||||
*/
|
||||
@ChineseDescription("文件名称(上传时候的文件名)")
|
||||
private String fileOriginName;
|
||||
|
||||
|
||||
/**
|
||||
* 文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地
|
||||
*/
|
||||
@ChineseDescription("存储位置:1-阿里云,2-腾讯云,3-minio,4-本地")
|
||||
private Integer fileLocation;
|
||||
|
||||
/**
|
||||
* 文件后缀
|
||||
*/
|
||||
@ChineseDescription("文件后缀")
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 文件大小信息,计算后的
|
||||
*/
|
||||
@ChineseDescription("文件大小信息,计算后")
|
||||
private String fileSizeInfo;
|
||||
|
||||
/**
|
||||
* 文件版本
|
||||
*/
|
||||
@ChineseDescription("文件版本")
|
||||
private Integer fileVersion;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@ChineseDescription("创建人")
|
||||
private Long createAccountId;
|
||||
|
||||
/**
|
||||
* 创建人部门id
|
||||
*/
|
||||
@ChineseDescription("创建人部门id")
|
||||
private Long createDeptId;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@ChineseDescription("创建人姓名")
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@ChineseDescription("创建时间")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@ChineseDescription("创建人姓名")
|
||||
private String realName;
|
||||
|
||||
/**
|
||||
* 文件访问的url
|
||||
*/
|
||||
@ChineseDescription("文件访问的url")
|
||||
private String fileUrl;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.file.api.pojo.response;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
@ -38,6 +39,7 @@ public class SysFileInfoResponse {
|
|||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@ChineseDescription("主键id")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
|
@ -47,71 +49,85 @@ public class SysFileInfoResponse {
|
|||
* <p>
|
||||
* 版本号升级的依据,code相同id不同视为同一个文件的不同版本
|
||||
*/
|
||||
@ChineseDescription("文件编码")
|
||||
private Long fileCode;
|
||||
|
||||
/**
|
||||
* 文件版本
|
||||
*/
|
||||
@ChineseDescription("文件版本")
|
||||
private Integer fileVersion;
|
||||
|
||||
/**
|
||||
* 文件状态(0-历史版,1-最新版)
|
||||
*/
|
||||
@ChineseDescription("文件状态")
|
||||
private String fileStatus;
|
||||
|
||||
/**
|
||||
* 文件后缀,例如.txt
|
||||
*/
|
||||
@ChineseDescription("问价后缀")
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 文件大小kb
|
||||
*/
|
||||
@ChineseDescription("文件大小kb")
|
||||
private Long fileSizeKb;
|
||||
|
||||
/**
|
||||
* 文件大小信息,计算后的
|
||||
*/
|
||||
@ChineseDescription("文件大小信息,计算后")
|
||||
private String fileSizeInfo;
|
||||
|
||||
/**
|
||||
* 是否为机密文件
|
||||
*/
|
||||
@ChineseDescription("是否为机密文件")
|
||||
private String secretFlag;
|
||||
|
||||
/**
|
||||
* 文件的字节
|
||||
*/
|
||||
@ChineseDescription("文件的字节")
|
||||
private byte[] fileBytes;
|
||||
|
||||
/**
|
||||
* 存储到bucket中的名称,主键id+.后缀
|
||||
*/
|
||||
@ChineseDescription("存储到bucket中的名称,主键id+.后缀")
|
||||
private String fileObjectName;
|
||||
|
||||
/**
|
||||
* 文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地
|
||||
*/
|
||||
@ChineseDescription("文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地")
|
||||
private Integer fileLocation;
|
||||
|
||||
/**
|
||||
* 文件仓库
|
||||
*/
|
||||
@ChineseDescription("文件仓库")
|
||||
private String fileBucket;
|
||||
|
||||
/**
|
||||
* 文件名称(上传时候的文件名)
|
||||
*/
|
||||
@ChineseDescription("文件名称(上传时候的文件名)")
|
||||
private String fileOriginName;
|
||||
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
@ChineseDescription("存储路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 文件访问的路径,如果是私密文件,则返回带鉴权的url,如果不是私密文件,则返回公网能直接访问的url
|
||||
*/
|
||||
@ChineseDescription("文件访问路径")
|
||||
private String fileUrl;
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -24,10 +24,14 @@
|
|||
*/
|
||||
package cn.stylefeng.roses.kernel.file.modular.controller;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
||||
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
|
||||
import cn.stylefeng.roses.kernel.file.api.pojo.request.SysFileInfoRequest;
|
||||
import cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoListResponse;
|
||||
import cn.stylefeng.roses.kernel.file.api.pojo.response.SysFileInfoResponse;
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileInfo;
|
||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileInfoService;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.BusinessLog;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
||||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
|
@ -72,14 +76,18 @@ public class SysFileInfoController {
|
|||
|
||||
/**
|
||||
* 上传文件
|
||||
* <p>
|
||||
* 支持上传到数据库,参数fileLocation传递5即可
|
||||
* <p>
|
||||
* fileLocation传递其他值或不传值,不能决定文件上传到本地还是阿里云或其他地方
|
||||
*
|
||||
* @author majianguo
|
||||
* @date 2020/12/27 13:17
|
||||
*/
|
||||
@PostResource(name = "上传文件", path = "/sysFileInfo/upload", requiredPermission = false)
|
||||
public ResponseData upload(@RequestPart("file") MultipartFile file, @Validated(SysFileInfoRequest.add.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
public ResponseData<SysFileInfoResponse> upload(@RequestPart("file") MultipartFile file, @Validated(SysFileInfoRequest.add.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
SysFileInfoResponse fileUploadInfoResult = this.sysFileInfoService.uploadFile(file, sysFileInfoRequest);
|
||||
return new SuccessResponseData(fileUploadInfoResult);
|
||||
return new SuccessResponseData<>(fileUploadInfoResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,9 +181,9 @@ public class SysFileInfoController {
|
|||
* @date 2020/12/16 15:34
|
||||
*/
|
||||
@PostResource(name = "替换文件", path = "/sysFileInfo/update", requiredPermission = false)
|
||||
public ResponseData update(@RequestPart("file") MultipartFile file, @Validated(SysFileInfoRequest.edit.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
public ResponseData<SysFileInfoResponse> update(@RequestPart("file") MultipartFile file, @Validated(SysFileInfoRequest.edit.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
SysFileInfoResponse fileUploadInfoResult = this.sysFileInfoService.updateFile(file, sysFileInfoRequest);
|
||||
return new SuccessResponseData(fileUploadInfoResult);
|
||||
return new SuccessResponseData<>(fileUploadInfoResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -184,10 +192,10 @@ public class SysFileInfoController {
|
|||
* @author majianguo
|
||||
* @date 2020/12/16 15:34
|
||||
*/
|
||||
@PostResource(name = "替换文件", path = "/sysFileInfo/versionBack", requiredPermission = false)
|
||||
public ResponseData versionBack(@Validated(SysFileInfoRequest.versionBack.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
@PostResource(name = "版本回退", path = "/sysFileInfo/versionBack", requiredPermission = false)
|
||||
public ResponseData<SysFileInfoResponse> versionBack(@Validated(SysFileInfoRequest.versionBack.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
SysFileInfoResponse fileUploadInfoResult = this.sysFileInfoService.versionBack(sysFileInfoRequest);
|
||||
return new SuccessResponseData(fileUploadInfoResult);
|
||||
return new SuccessResponseData<>(fileUploadInfoResult);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,9 +207,9 @@ public class SysFileInfoController {
|
|||
* @date 2020/12/27 13:17
|
||||
*/
|
||||
@GetResource(name = "根据附件IDS查询附件信息", path = "/sysFileInfo/getFileInfoListByFileIds", requiredPermission = false)
|
||||
public ResponseData getFileInfoListByFileIds(@RequestParam(value = "fileIds") String fileIds) {
|
||||
public ResponseData<List<SysFileInfoResponse>> getFileInfoListByFileIds(@RequestParam(value = "fileIds") String fileIds) {
|
||||
List<SysFileInfoResponse> list = this.sysFileInfoService.getFileInfoListByFileIds(fileIds);
|
||||
return new SuccessResponseData(list);
|
||||
return new SuccessResponseData<>(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -235,9 +243,10 @@ public class SysFileInfoController {
|
|||
* @date 2020/11/29 11:19
|
||||
*/
|
||||
@PostResource(name = "删除文件信息(真删除文件信息)", path = "/sysFileInfo/deleteReally", requiredPermission = false)
|
||||
public ResponseData deleteReally(@RequestBody @Validated(SysFileInfoRequest.delete.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
@BusinessLog
|
||||
public ResponseData<?> deleteReally(@RequestBody @Validated(SysFileInfoRequest.delete.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
this.sysFileInfoService.deleteReally(sysFileInfoRequest);
|
||||
return new SuccessResponseData();
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -247,8 +256,8 @@ public class SysFileInfoController {
|
|||
* @date 2020/11/29 11:29
|
||||
*/
|
||||
@GetResource(name = "分页查询文件信息表", path = "/sysFileInfo/fileInfoListPage", requiredPermission = false)
|
||||
public ResponseData fileInfoListPage(SysFileInfoRequest sysFileInfoRequest) {
|
||||
return new SuccessResponseData(this.sysFileInfoService.fileInfoListPage(sysFileInfoRequest));
|
||||
public ResponseData<PageResult<SysFileInfoListResponse>> fileInfoListPage(SysFileInfoRequest sysFileInfoRequest) {
|
||||
return new SuccessResponseData<>(this.sysFileInfoService.fileInfoListPage(sysFileInfoRequest));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,8 +267,8 @@ public class SysFileInfoController {
|
|||
* @date 2020/11/29 11:29
|
||||
*/
|
||||
@GetResource(name = "查看详情文件信息表", path = "/sysFileInfo/detail", requiredPermission = false)
|
||||
public ResponseData detail(@Validated(SysFileInfoRequest.detail.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
return new SuccessResponseData(sysFileInfoService.detail(sysFileInfoRequest));
|
||||
public ResponseData<SysFileInfo> detail(@Validated(SysFileInfoRequest.detail.class) SysFileInfoRequest sysFileInfoRequest) {
|
||||
return new SuccessResponseData<>(sysFileInfoService.detail(sysFileInfoRequest));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.entity;
|
||||
|
||||
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
@ -46,6 +47,7 @@ public class SysFileInfo extends BaseEntity {
|
|||
* 主键id
|
||||
*/
|
||||
@TableId(value = "file_id", type = IdType.ASSIGN_ID)
|
||||
@ChineseDescription("主键id")
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
|
@ -54,78 +56,91 @@ public class SysFileInfo extends BaseEntity {
|
|||
* 解决一个文件多个版本问题,多次上传文件编码不变
|
||||
*/
|
||||
@TableField("file_code")
|
||||
@ChineseDescription("文件编码")
|
||||
private Long fileCode;
|
||||
|
||||
/**
|
||||
* 文件版本,从1开始
|
||||
*/
|
||||
@TableField("file_version")
|
||||
@ChineseDescription("文件版本")
|
||||
private Integer fileVersion;
|
||||
|
||||
/**
|
||||
* 当前状态:0-历史版,1-最新版
|
||||
*/
|
||||
@TableField("file_status")
|
||||
@ChineseDescription("当前状态:0-历史版,1-最新版")
|
||||
private String fileStatus;
|
||||
|
||||
/**
|
||||
* 文件存储位置:1-阿里云,2-腾讯云,3-minio,4-本地
|
||||
*/
|
||||
@TableField("file_location")
|
||||
@ChineseDescription("文件存储位置")
|
||||
private Integer fileLocation;
|
||||
|
||||
/**
|
||||
* 文件仓库(文件夹)
|
||||
*/
|
||||
@TableField("file_bucket")
|
||||
@ChineseDescription("文件仓库(文件夹)")
|
||||
private String fileBucket;
|
||||
|
||||
/**
|
||||
* 文件名称(上传时候的文件全名)
|
||||
*/
|
||||
@TableField("file_origin_name")
|
||||
@ChineseDescription("文件名称(上传时候的文件全名)")
|
||||
private String fileOriginName;
|
||||
|
||||
/**
|
||||
* 文件后缀,例如.txt
|
||||
*/
|
||||
@TableField("file_suffix")
|
||||
@ChineseDescription("文件后缀")
|
||||
private String fileSuffix;
|
||||
|
||||
/**
|
||||
* 文件大小kb为单位
|
||||
*/
|
||||
@TableField("file_size_kb")
|
||||
@ChineseDescription("文件大小")
|
||||
private Long fileSizeKb;
|
||||
|
||||
/**
|
||||
* 文件大小信息,计算后的
|
||||
*/
|
||||
@TableField("file_size_info")
|
||||
@ChineseDescription("文件大小信息,计算后的")
|
||||
private String fileSizeInfo;
|
||||
|
||||
/**
|
||||
* 存储到bucket中的名称,主键id+.后缀
|
||||
*/
|
||||
@TableField("file_object_name")
|
||||
@ChineseDescription("存储到bucket中的名称,主键id+.后缀")
|
||||
private String fileObjectName;
|
||||
|
||||
/**
|
||||
* 存储路径
|
||||
*/
|
||||
@TableField("file_path")
|
||||
@ChineseDescription("存储路径")
|
||||
private String filePath;
|
||||
|
||||
/**
|
||||
* 是否为机密文件
|
||||
*/
|
||||
@TableField("secret_flag")
|
||||
@ChineseDescription("是否为机密文件")
|
||||
private String secretFlag;
|
||||
|
||||
/**
|
||||
* 是否删除:Y-被删除,N-未删除
|
||||
*/
|
||||
@TableField(value = "del_flag", fill = FieldFill.INSERT)
|
||||
@ChineseDescription("是否删除")
|
||||
private String delFlag;
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* 文件存储信息实例类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/01/08 15:53
|
||||
*/
|
||||
@TableName("sys_file_storage")
|
||||
@Data
|
||||
public class SysFileStorage {
|
||||
|
||||
/**
|
||||
* 文件主键id,关联file_info表的主键
|
||||
*/
|
||||
@TableId(value = "file_id", type = IdType.ASSIGN_ID)
|
||||
private Long fileId;
|
||||
|
||||
/**
|
||||
* 具体文件的字节信息
|
||||
*/
|
||||
@TableField("file_bytes")
|
||||
private byte[] fileBytes;
|
||||
|
||||
}
|
|
@ -38,6 +38,7 @@ import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
|||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.file.api.pojo.request.SysFileInfoRequest;
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileInfo;
|
||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileStorageService;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
@ -63,6 +64,7 @@ public class FileInfoFactory {
|
|||
public static SysFileInfo createSysFileInfo(MultipartFile file, SysFileInfoRequest sysFileInfoRequest) {
|
||||
|
||||
FileOperatorApi fileOperatorApi = SpringUtil.getBean(FileOperatorApi.class);
|
||||
SysFileStorageService fileStorageService = SpringUtil.getBean(SysFileStorageService.class);
|
||||
|
||||
// 生成文件的唯一id
|
||||
Long fileId = IdWorker.getId();
|
||||
|
@ -89,7 +91,12 @@ public class FileInfoFactory {
|
|||
if (StrUtil.isNotEmpty(sysFileInfoRequest.getFileBucket())) {
|
||||
fileBucket = sysFileInfoRequest.getFileBucket();
|
||||
}
|
||||
fileOperatorApi.storageFile(fileBucket, finalFileName, bytes);
|
||||
// 如果是存在数据库库里,单独处理一下
|
||||
if (FileLocationEnum.DB.getCode().equals(sysFileInfoRequest.getFileLocation())) {
|
||||
fileStorageService.saveFile(fileId, bytes);
|
||||
} else {
|
||||
fileOperatorApi.storageFile(fileBucket, finalFileName, bytes);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new FileException(FileExceptionEnum.ERROR_FILE, e.getMessage());
|
||||
}
|
||||
|
@ -103,7 +110,12 @@ public class FileInfoFactory {
|
|||
// 封装存储文件信息(上传替换公共信息)
|
||||
SysFileInfo sysFileInfo = new SysFileInfo();
|
||||
sysFileInfo.setFileId(fileId);
|
||||
sysFileInfo.setFileLocation(FileLocationEnum.LOCAL.getCode());
|
||||
// 如果是存在数据库库里,单独处理一下
|
||||
if (FileLocationEnum.DB.getCode().equals(sysFileInfoRequest.getFileLocation())) {
|
||||
sysFileInfo.setFileLocation(FileLocationEnum.DB.getCode());
|
||||
} else {
|
||||
sysFileInfo.setFileLocation(fileOperatorApi.getFileLocationEnum().getCode());
|
||||
}
|
||||
sysFileInfo.setFileBucket(fileBucket);
|
||||
sysFileInfo.setFileObjectName(finalFileName);
|
||||
sysFileInfo.setFileOriginName(originalFilename);
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.mapper;
|
||||
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileStorage;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* 文件存储信息 Mapper 接口
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/01/08 15:53
|
||||
*/
|
||||
public interface SysFileStorageMapper extends BaseMapper<SysFileStorage> {
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.system.modular.resource.mapper.ApiResourceFieldMapper">
|
||||
<mapper namespace="cn.stylefeng.roses.kernel.file.modular.mapper.SysFileStorageMapper">
|
||||
|
||||
</mapper>
|
|
@ -0,0 +1,40 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.service;
|
||||
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileStorage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 文件存储信息 服务类
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/01/08 15:53
|
||||
*/
|
||||
public interface SysFileStorageService extends IService<SysFileStorage> {
|
||||
|
||||
/**
|
||||
* 将文件存储在库中
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/1/8 16:08
|
||||
*/
|
||||
void saveFile(Long fileId, byte[] bytes);
|
||||
|
||||
/**
|
||||
* 获取文件的访问url
|
||||
*
|
||||
* @param fileId 文件id
|
||||
* @author fengshuonan
|
||||
* @date 2022/1/8 16:12
|
||||
*/
|
||||
String getFileAuthUrl(String fileId);
|
||||
|
||||
/**
|
||||
* 获取文件不带鉴权的访问url
|
||||
*
|
||||
* @param fileId 文件id
|
||||
* @author fengshuonan
|
||||
* @date 2022/1/8 16:12
|
||||
*/
|
||||
String getFileUnAuthUrl(String fileId);
|
||||
|
||||
}
|
|
@ -25,7 +25,6 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
|
@ -38,6 +37,7 @@ import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
|
|||
import cn.stylefeng.roses.kernel.file.api.FileInfoApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileStatusEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.FileException;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
||||
|
@ -49,11 +49,12 @@ import cn.stylefeng.roses.kernel.file.api.util.DownloadUtil;
|
|||
import cn.stylefeng.roses.kernel.file.api.util.PdfFileTypeUtil;
|
||||
import cn.stylefeng.roses.kernel.file.api.util.PicFileTypeUtil;
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileInfo;
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileStorage;
|
||||
import cn.stylefeng.roses.kernel.file.modular.factory.FileInfoFactory;
|
||||
import cn.stylefeng.roses.kernel.file.modular.mapper.SysFileInfoMapper;
|
||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileInfoService;
|
||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileStorageService;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
|
@ -92,6 +93,9 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
@Resource
|
||||
private FileOperatorApi fileOperatorApi;
|
||||
|
||||
@Resource
|
||||
private SysFileStorageService sysFileStorageService;
|
||||
|
||||
@Override
|
||||
public SysFileInfoResponse getFileInfoResult(Long fileId) {
|
||||
|
||||
|
@ -103,7 +107,13 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
// 获取文件字节码
|
||||
byte[] fileBytes;
|
||||
try {
|
||||
fileBytes = fileOperatorApi.getFileBytes(FileConfigExpander.getDefaultBucket(), sysFileInfo.getFileObjectName());
|
||||
// 如果是存储在数据库,从数据库中获取,其他的方式走FileOperatorApi
|
||||
if (FileLocationEnum.DB.getCode().equals(sysFileInfo.getFileLocation())) {
|
||||
SysFileStorage storage = sysFileStorageService.getById(fileId);
|
||||
fileBytes = storage.getFileBytes();
|
||||
} else {
|
||||
fileBytes = fileOperatorApi.getFileBytes(FileConfigExpander.getDefaultBucket(), sysFileInfo.getFileObjectName());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取文件流异常,具体信息为:{}", e.getMessage());
|
||||
throw new FileException(FileExceptionEnum.FILE_STREAM_ERROR, e.getMessage());
|
||||
|
@ -188,8 +198,10 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
SysFileInfoResponse sysFileInfoResponse = this.getFileInfoResult(sysFileInfoRequest.getFileId());
|
||||
|
||||
// 如果文件加密等级不符合,文件不允许被访问
|
||||
if (!sysFileInfoRequest.getSecretFlag().equals(sysFileInfoResponse.getSecretFlag())) {
|
||||
throw new FileException(FileExceptionEnum.FILE_DENIED_ACCESS);
|
||||
if (YesOrNotEnum.Y.getCode().equals(sysFileInfoResponse.getSecretFlag())) {
|
||||
if (YesOrNotEnum.N.getCode().equals(sysFileInfoRequest.getSecretFlag())) {
|
||||
throw new FileException(FileExceptionEnum.FILE_DENIED_ACCESS);
|
||||
}
|
||||
}
|
||||
|
||||
DownloadUtil.download(sysFileInfoResponse.getFileOriginName(), sysFileInfoResponse.getFileBytes(), response);
|
||||
|
@ -201,7 +213,7 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
|
||||
// 查询该Code的所有历史版本
|
||||
LambdaQueryWrapper<SysFileInfo> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(SysFileInfo::getFileCode, sysFileInfoRequest.getFileCode());
|
||||
lqw.eq(SysFileInfo::getFileCode, sysFileInfoRequest.getFileCode()).or().eq(SysFileInfo::getFileId, sysFileInfoRequest.getFileId());
|
||||
List<SysFileInfo> fileInfos = this.list(lqw);
|
||||
|
||||
// 批量删除
|
||||
|
@ -209,7 +221,12 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
|
||||
// 删除具体文件
|
||||
for (SysFileInfo fileInfo : fileInfos) {
|
||||
this.fileOperatorApi.deleteFile(fileInfo.getFileBucket(), fileInfo.getFileObjectName());
|
||||
//如果文件是在数据库存储,则特殊处理
|
||||
if (fileInfo.getFileLocation().equals(FileLocationEnum.DB.getCode())) {
|
||||
this.sysFileStorageService.removeById(fileInfo.getFileId());
|
||||
} else {
|
||||
this.fileOperatorApi.deleteFile(fileInfo.getFileBucket(), fileInfo.getFileObjectName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -219,7 +236,15 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
List<SysFileInfoListResponse> list = this.baseMapper.fileInfoList(page, sysFileInfoRequest);
|
||||
|
||||
// 排除defaultAvatar.png这个图片,这个是默认头像
|
||||
List<SysFileInfoListResponse> newList = list.stream().filter(i -> !i.getFileOriginName().equals("defaultAvatar.png")).collect(Collectors.toList());
|
||||
List<SysFileInfoListResponse> newList = list.stream().filter(i -> !i.getFileOriginName().equals(FileConstants.DEFAULT_AVATAR_FILE_OBJ_NAME)).collect(Collectors.toList());
|
||||
|
||||
// 拼接图片url地址
|
||||
for (SysFileInfoListResponse sysFileInfoListResponse : newList) {
|
||||
// 判断是否是可以预览的文件
|
||||
if (PicFileTypeUtil.getFileImgTypeFlag(sysFileInfoListResponse.getFileSuffix())) {
|
||||
sysFileInfoListResponse.setFileUrl(this.getFileAuthUrl(sysFileInfoListResponse.getFileId()));
|
||||
}
|
||||
}
|
||||
|
||||
return PageResultFactory.createPageResult(page.setRecords(newList));
|
||||
}
|
||||
|
@ -285,18 +310,14 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
@Override
|
||||
public void preview(SysFileInfoRequest sysFileInfoRequest, HttpServletResponse response) {
|
||||
|
||||
// 如果是默认头像
|
||||
if (FileConstants.DEFAULT_AVATAR_FILE_ID.equals(sysFileInfoRequest.getFileId())) {
|
||||
DownloadUtil.renderPreviewFile(response, Base64.decode(FileConfigExpander.getDefaultAvatarBase64()));
|
||||
return;
|
||||
}
|
||||
|
||||
// 根据文件id获取文件信息结果集
|
||||
SysFileInfoResponse sysFileInfoResponse = this.getFileInfoResult(sysFileInfoRequest.getFileId());
|
||||
|
||||
// 如果文件加密等级不符合,文件不允许被访问
|
||||
if (!sysFileInfoRequest.getSecretFlag().equals(sysFileInfoResponse.getSecretFlag())) {
|
||||
throw new FileException(FileExceptionEnum.FILE_DENIED_ACCESS);
|
||||
if (YesOrNotEnum.Y.getCode().equals(sysFileInfoResponse.getSecretFlag())) {
|
||||
if (YesOrNotEnum.N.getCode().equals(sysFileInfoRequest.getSecretFlag())) {
|
||||
throw new FileException(FileExceptionEnum.FILE_DENIED_ACCESS);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取文件后缀
|
||||
|
@ -345,12 +366,6 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
@Override
|
||||
public void previewByBucketAndObjName(SysFileInfoRequest sysFileInfoRequest, HttpServletResponse response) {
|
||||
|
||||
// 如果是默认头像
|
||||
if (FileConstants.DEFAULT_AVATAR_FILE_OBJ_NAME.equals(sysFileInfoRequest.getFileObjectName())) {
|
||||
DownloadUtil.renderPreviewFile(response, Base64.decode(FileConfigExpander.getDefaultAvatarBase64()));
|
||||
return;
|
||||
}
|
||||
|
||||
// 判断文件是否需要鉴权,需要鉴权的需要带token访问
|
||||
LambdaQueryWrapper<SysFileInfo> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysFileInfo::getFileObjectName, sysFileInfoRequest.getFileObjectName());
|
||||
|
@ -415,23 +430,39 @@ public class SysFileInfoServiceImpl extends ServiceImpl<SysFileInfoMapper, SysFi
|
|||
|
||||
@Override
|
||||
public String getFileAuthUrl(Long fileId) {
|
||||
|
||||
// 获取登录用户的token
|
||||
String token = LoginContext.me().getToken();
|
||||
|
||||
// 获取context-path
|
||||
String contextPath = HttpServletUtil.getRequest().getContextPath();
|
||||
|
||||
return FileConfigExpander.getServerDeployHost() + contextPath + FileConstants.FILE_PRIVATE_PREVIEW_URL + "?fileId=" + fileId + "&token=" + token;
|
||||
return this.getFileAuthUrl(fileId, LoginContext.me().getToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileAuthUrl(Long fileId, String token) {
|
||||
// 获取文件的基本信息
|
||||
SysFileInfoRequest sysFileInfoRequest = new SysFileInfoRequest();
|
||||
sysFileInfoRequest.setFileId(fileId);
|
||||
SysFileInfo sysFileInfo = querySysFileInfo(sysFileInfoRequest);
|
||||
|
||||
// 获取context-path
|
||||
String contextPath = HttpServletUtil.getRequest().getContextPath();
|
||||
// 如果是数据库存储,则返回previewUrl
|
||||
if (sysFileInfo.getFileLocation().equals(FileLocationEnum.DB.getCode())) {
|
||||
return this.sysFileStorageService.getFileAuthUrl(String.valueOf(fileId));
|
||||
} else {
|
||||
// 返回第三方存储文件url
|
||||
return fileOperatorApi.getFileAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName(), FileConfigExpander.getDefaultFileTimeoutSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
return FileConfigExpander.getServerDeployHost() + contextPath + FileConstants.FILE_PRIVATE_PREVIEW_URL + "?fileId=" + fileId + "&token=" + token;
|
||||
@Override
|
||||
public String getFileUnAuthUrl(Long fileId) {
|
||||
// 获取文件的基本信息
|
||||
SysFileInfoRequest sysFileInfoRequest = new SysFileInfoRequest();
|
||||
sysFileInfoRequest.setFileId(fileId);
|
||||
SysFileInfo sysFileInfo = querySysFileInfo(sysFileInfoRequest);
|
||||
|
||||
// 如果是数据库存储,则返回previewUrl
|
||||
if (sysFileInfo.getFileLocation().equals(FileLocationEnum.DB.getCode())) {
|
||||
return this.sysFileStorageService.getFileUnAuthUrl(String.valueOf(fileId));
|
||||
} else {
|
||||
// 返回第三方存储文件url
|
||||
return fileOperatorApi.getFileUnAuthUrl(sysFileInfo.getFileBucket(), sysFileInfo.getFileObjectName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package cn.stylefeng.roses.kernel.file.modular.service.impl;
|
||||
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
|
||||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.file.modular.entity.SysFileStorage;
|
||||
import cn.stylefeng.roses.kernel.file.modular.mapper.SysFileStorageMapper;
|
||||
import cn.stylefeng.roses.kernel.file.modular.service.SysFileStorageService;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 文件存储信息业务实现层
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/01/08 15:53
|
||||
*/
|
||||
@Service
|
||||
public class SysFileStorageServiceImpl extends ServiceImpl<SysFileStorageMapper, SysFileStorage> implements SysFileStorageService {
|
||||
|
||||
@Override
|
||||
public void saveFile(Long fileId, byte[] bytes) {
|
||||
SysFileStorage sysFileStorage = new SysFileStorage();
|
||||
sysFileStorage.setFileId(fileId);
|
||||
sysFileStorage.setFileBytes(bytes);
|
||||
this.save(sysFileStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileAuthUrl(String fileId) {
|
||||
// 获取登录用户的token
|
||||
String token = LoginContext.me().getToken();
|
||||
// 获取context-path
|
||||
String contextPath = HttpServletUtil.getRequest().getContextPath();
|
||||
return FileConfigExpander.getServerDeployHost() + contextPath + FileConstants.FILE_PRIVATE_PREVIEW_URL + "?fileId=" + fileId + "&token=" + token;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFileUnAuthUrl(String fileId) {
|
||||
// 获取context-path
|
||||
String contextPath = HttpServletUtil.getRequest().getContextPath();
|
||||
return FileConfigExpander.getServerDeployHost() + contextPath + FileConstants.FILE_PUBLIC_PREVIEW_URL + "?fileId=" + fileId;
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -25,11 +25,12 @@
|
|||
package cn.stylefeng.roses.kernel.file.aliyun;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.BucketAuthEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.FileException;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.file.api.pojo.props.AliyunOssProperties;
|
||||
import com.aliyun.oss.ClientException;
|
||||
import com.aliyun.oss.OSS;
|
||||
|
@ -200,8 +201,7 @@ public class AliyunFileOperator implements FileOperatorApi {
|
|||
|
||||
@Override
|
||||
public String getFileUnAuthUrl(String bucketName, String key) {
|
||||
String template = "https://{}.oss-cn-beijing.aliyuncs.com/{}";
|
||||
return StrUtil.format(template,bucketName,key);
|
||||
return this.getFileAuthUrl(bucketName, key, FileConfigExpander.getDefaultFileTimeoutSeconds() * 1000);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -209,4 +209,9 @@ public class AliyunFileOperator implements FileOperatorApi {
|
|||
ossClient.deleteObject(bucketName, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileLocationEnum getFileLocationEnum() {
|
||||
return FileLocationEnum.ALIYUN;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
|||
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.BucketAuthEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.FileException;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
|
@ -199,4 +200,10 @@ public class LocalFileOperator implements FileOperatorApi {
|
|||
FileUtil.del(file);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileLocationEnum getFileLocationEnum() {
|
||||
return FileLocationEnum.LOCAL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
|||
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.constants.FileConstants;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.BucketAuthEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.FileException;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
|
@ -233,6 +234,11 @@ public class MinIoFileOperator implements FileOperatorApi {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileLocationEnum getFileLocationEnum() {
|
||||
return FileLocationEnum.MINIO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取文件后缀对应的contentType
|
||||
*
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import cn.hutool.core.io.IoUtil;
|
|||
import cn.hutool.core.thread.ExecutorBuilder;
|
||||
import cn.stylefeng.roses.kernel.file.api.FileOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.BucketAuthEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.enums.FileLocationEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.FileException;
|
||||
import cn.stylefeng.roses.kernel.file.api.exception.enums.FileExceptionEnum;
|
||||
import cn.stylefeng.roses.kernel.file.api.expander.FileConfigExpander;
|
||||
|
@ -261,4 +262,9 @@ public class TenFileOperator implements FileOperatorApi {
|
|||
cosClient.deleteObject(bucketName, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileLocationEnum getFileLocationEnum() {
|
||||
return FileLocationEnum.TENCENT;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-file</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>roses-kernel</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-groovy</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<parent>
|
||||
<groupId>cn.stylefeng.roses</groupId>
|
||||
<artifactId>kernel-d-groovy</artifactId>
|
||||
<version>7.1.5</version>
|
||||
<version>7.2.0</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue