Compare commits
4 Commits
147288799a
...
cd71fcbcda
Author | SHA1 | Date |
---|---|---|
smallchill | cd71fcbcda | |
smallchill | 945efc8fbf | |
卢春梦 | 823bdca0b4 | |
卢春梦 | 6af2daad18 |
|
@ -25,6 +25,7 @@ import org.springblade.core.secure.BladeUser;
|
|||
import org.springblade.core.secure.utils.SecureUtil;
|
||||
import org.springblade.core.tool.constant.BladeConstant;
|
||||
import org.springblade.core.tool.utils.DateUtil;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
@ -86,6 +87,7 @@ public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> exte
|
|||
BladeUser user = SecureUtil.getUser();
|
||||
if (user != null) {
|
||||
entity.setCreateUser(user.getUserId());
|
||||
entity.setCreateDept(Func.firstLong(user.getDeptId()));
|
||||
entity.setUpdateUser(user.getUserId());
|
||||
}
|
||||
Date now = DateUtil.now();
|
||||
|
|
|
@ -119,6 +119,16 @@ public class SecureUtil {
|
|||
return (BladeUser) bladeUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param auth auth
|
||||
* @return BladeUser
|
||||
*/
|
||||
public static BladeUser getUser(String auth) {
|
||||
return getUser(getClaims(auth));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
|
@ -126,7 +136,16 @@ public class SecureUtil {
|
|||
* @return BladeUser
|
||||
*/
|
||||
public static BladeUser getUser(HttpServletRequest request) {
|
||||
Claims claims = getClaims(request);
|
||||
return getUser(getClaims(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
* @param claims Claims
|
||||
* @return BladeUser
|
||||
*/
|
||||
public static BladeUser getUser(Claims claims) {
|
||||
if (claims == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -293,10 +312,20 @@ public class SecureUtil {
|
|||
*/
|
||||
public static Claims getClaims(HttpServletRequest request) {
|
||||
String auth = request.getHeader(SecureUtil.HEADER);
|
||||
String token = getToken(
|
||||
StringUtil.isNotBlank(auth) ? auth : request.getParameter(SecureUtil.HEADER)
|
||||
);
|
||||
return SecureUtil.parseJWT(token);
|
||||
if (StringUtil.isBlank(auth)) {
|
||||
auth = request.getParameter(SecureUtil.HEADER);
|
||||
}
|
||||
return getClaims(auth);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Claims
|
||||
*
|
||||
* @param auth auth
|
||||
* @return Claims
|
||||
*/
|
||||
public static Claims getClaims(String auth) {
|
||||
return SecureUtil.parseJWT(getToken(auth));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,6 +130,16 @@ public class R<T> implements Serializable {
|
|||
return new R<>(code, data, data == null ? BladeConstant.DEFAULT_NULL_MESSAGE : msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功
|
||||
*
|
||||
* @param <T> 泛型标记
|
||||
* @return Result
|
||||
*/
|
||||
public static <T> R<T> success() {
|
||||
return new R<>(ResultCode.SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回R
|
||||
*
|
||||
|
@ -222,4 +232,16 @@ public class R<T> implements Serializable {
|
|||
return flag ? success(BladeConstant.DEFAULT_SUCCESS_MESSAGE) : fail(BladeConstant.DEFAULT_FAILURE_MESSAGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据状态返回成功或者失败
|
||||
*
|
||||
* @param status 状态
|
||||
* @param msg 异常msg
|
||||
* @param <T> 泛型标记
|
||||
* @return Result
|
||||
*/
|
||||
public static <T> R<T> status(boolean status, String msg) {
|
||||
return status ? R.success() : R.fail(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -726,6 +726,32 @@ public class Func {
|
|||
return Arrays.asList(toLongArray(split, str));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一位Long数值
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long firstLong(String str) {
|
||||
return firstLong(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取第一位Long数值
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long firstLong(String split, String str) {
|
||||
List<Long> longs = toLongList(split, str);
|
||||
if (isEmpty(longs)) {
|
||||
return null;
|
||||
} else {
|
||||
return longs.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组<br>
|
||||
*
|
||||
|
|
|
@ -53,4 +53,25 @@ public class TemplateUtil {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析模版
|
||||
*
|
||||
* @param template 模版
|
||||
* @param params 参数
|
||||
* @return 解析后的字符串
|
||||
*/
|
||||
public static String safeProcess(String template, Kv params) {
|
||||
Matcher matcher = pattern.matcher(template);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
while (matcher.find()) {
|
||||
String key = matcher.group(1) != null ? matcher.group(1) : matcher.group(2);
|
||||
String replacement = params.getStr(key);
|
||||
if (replacement != null) {
|
||||
matcher.appendReplacement(sb, replacement);
|
||||
}
|
||||
}
|
||||
matcher.appendTail(sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue