mirror of
https://github.com/mfish-qf/mfish-nocode.git
synced 2026-08-30 17:12:14 +08:00
refactor: 代码重构
This commit is contained in:
@@ -2,33 +2,29 @@
|
||||
=====================================
|
||||
当前最新版本: 1.0.0
|
||||
|
||||
[](https://github.com/mfish-qf/mfish-nocode/blob/main/LICENSE)
|
||||
[](http://www.mfish.com.cn)
|
||||
[](http://www.mfish.com.cn)
|
||||
[](https://github.com/mfish-qf/mfish-nocode/releases/tag/v1.0.0)
|
||||
[](http://www.mfish.com.cn)
|
||||
[](http://www.mfish.com.cn)
|
||||
[](https://github.com/mfish-qf/mfish-nocode/releases/tag/v1.0.0)
|
||||
[](https://github.com/mfish-qf/mfish-nocode/blob/main/LICENSE)
|
||||
|
||||
[](https://github.com/mfish-qf/mfish-nocode)
|
||||
[](https://github.com/mfish-qf/mfish-nocode)
|
||||
[](https://github.com/mfish-qf/mfish-nocode)
|
||||
## 项目介绍
|
||||
|
||||
摸鱼低代码平台希望打造一个基于低代码的无代码平台。即能给程序员使用,也能满足非专业人士的需求。
|
||||
|
||||
* 后端基于Spring Cloud Alibaba
|
||||
* 注册中心、配置中心采用nacos
|
||||
* 当前版本完成oauth2统一认证接入
|
||||
* 持续进行功能完善
|
||||
|
||||
## 前端源码地址
|
||||
|
||||
* *[前端----github地址](https://github.com/mfish-qf/mfish-nocode-view)*
|
||||
* *[前端----gitee地址](https://gitee.com/qiufeng9862/mfish-nocode-view)*
|
||||
[](https://github.com/mfish-qf/mfish-nocode-view)
|
||||
[](https://gitee.com/qiufeng9862/mfish-nocode-view)
|
||||
|
||||
## 演示环境
|
||||
|
||||
* *[demo地址](http://app.mfish.com.cn:11119)*
|
||||
|
||||
## 功能模块(开发中...)
|
||||
|
||||
> vue3版本已经实现了系统管理、系统监控、各种组件、权限、GUI代码生成、完全可以用于生产环境。
|
||||
|
||||
## 功能模块
|
||||
```
|
||||
├─驾驶舱
|
||||
│ ├─工作台
|
||||
|
||||
+5
-5
@@ -1,7 +1,7 @@
|
||||
package cn.com.mfish.common.oauth.api.remote;
|
||||
|
||||
import cn.com.mfish.common.core.constants.Constants;
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.constants.ServiceConstants;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.common.oauth.api.entity.UserInfo;
|
||||
@@ -31,10 +31,10 @@ public interface RemoteUserService {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/user/info")
|
||||
Result<UserInfo> getUserInfo(@RequestHeader(CredentialConstants.REQ_ORIGIN) String origin, @RequestHeader(Constants.AUTHENTICATION) String token);
|
||||
Result<UserInfo> getUserInfo(@RequestHeader(RPCConstants.REQ_ORIGIN) String origin, @RequestHeader(Constants.AUTHENTICATION) String token);
|
||||
|
||||
@GetMapping("/user/{id}")
|
||||
Result<UserInfo> getUserById(@RequestHeader(CredentialConstants.REQ_ORIGIN) String origin, @PathVariable("id") String id);
|
||||
Result<UserInfo> getUserById(@RequestHeader(RPCConstants.REQ_ORIGIN) String origin, @PathVariable("id") String id);
|
||||
|
||||
/**
|
||||
* 获取用户角色
|
||||
@@ -45,7 +45,7 @@ public interface RemoteUserService {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/user/roles")
|
||||
Result<List<UserRole>> getRoles(@RequestHeader(CredentialConstants.REQ_ORIGIN) String origin, @RequestParam("userId") String userId, @RequestParam("clientId") String clientId);
|
||||
Result<List<UserRole>> getRoles(@RequestHeader(RPCConstants.REQ_ORIGIN) String origin, @RequestParam("userId") String userId, @RequestParam("clientId") String clientId);
|
||||
|
||||
/**
|
||||
* 获取用户权限
|
||||
@@ -56,5 +56,5 @@ public interface RemoteUserService {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/user/permissions")
|
||||
Result<Set<String>> getPermissions(@RequestHeader(CredentialConstants.REQ_ORIGIN) String origin, @RequestParam("userId") String userId, @RequestParam("clientId") String clientId);
|
||||
Result<Set<String>> getPermissions(@RequestHeader(RPCConstants.REQ_ORIGIN) String origin, @RequestParam("userId") String userId, @RequestParam("clientId") String clientId);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.sys.api.remote;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.constants.ServiceConstants;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.sys.api.entity.SysLog;
|
||||
@@ -18,5 +18,5 @@ import org.springframework.web.bind.annotation.RequestHeader;
|
||||
@FeignClient(contextId = "remoteLogService", value = ServiceConstants.SYS_SERVICE, fallbackFactory = RemoteLogFallback.class)
|
||||
public interface RemoteLogService {
|
||||
@PostMapping("/sysLog")
|
||||
Result<SysLog> addLog(@RequestHeader(CredentialConstants.REQ_ORIGIN) String origin, @RequestBody SysLog sysLog);
|
||||
Result<SysLog> addLog(@RequestHeader(RPCConstants.REQ_ORIGIN) String origin, @RequestBody SysLog sysLog);
|
||||
}
|
||||
|
||||
+4
-27
@@ -1,5 +1,7 @@
|
||||
package cn.com.mfish.common.core.constants;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* 通用常量信息
|
||||
*
|
||||
@@ -7,16 +9,6 @@ package cn.com.mfish.common.core.constants;
|
||||
* @date: 2021/8/12 11:27
|
||||
*/
|
||||
public class Constants {
|
||||
/**
|
||||
* UTF-8 字符集
|
||||
*/
|
||||
public static final String UTF8 = "UTF-8";
|
||||
|
||||
/**
|
||||
* contentType类型
|
||||
*/
|
||||
public static final String CONTENT_TYPE_JSON = "application/json";
|
||||
|
||||
/**
|
||||
* head令牌自定义标识
|
||||
*/
|
||||
@@ -42,21 +34,6 @@ public class Constants {
|
||||
*/
|
||||
public static final String OAUTH_HEADER_NAME = "Bearer ";
|
||||
|
||||
/**
|
||||
* 令牌密钥
|
||||
*/
|
||||
public final static String SECRET = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
/**
|
||||
* 令牌缓存有效期,默认720(分钟)
|
||||
*/
|
||||
public final static long EXPIRES_IN = 720;
|
||||
|
||||
/**
|
||||
* 令牌缓存刷新时间,默认120(分钟)
|
||||
*/
|
||||
public final static long REFRESH_TIME = 120;
|
||||
|
||||
/**
|
||||
* http请求
|
||||
*/
|
||||
@@ -70,12 +47,12 @@ public class Constants {
|
||||
/**
|
||||
* 成功标记
|
||||
*/
|
||||
public static final Integer SUCCESS = HttpStatus.SUCCESS;
|
||||
public static final Integer SUCCESS = HttpStatus.OK.value();
|
||||
|
||||
/**
|
||||
* 失败标记
|
||||
*/
|
||||
public static final Integer FAIL = HttpStatus.ERROR;
|
||||
public static final Integer FAIL = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
||||
|
||||
/**
|
||||
* 验证码redisKey标签
|
||||
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
package cn.com.mfish.common.core.constants;
|
||||
|
||||
/**
|
||||
* 请求状态码
|
||||
*
|
||||
* @author: mfish
|
||||
* @date: 2021/8/12 11:37
|
||||
*/
|
||||
public class HttpStatus {
|
||||
/**
|
||||
* 操作成功
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* 对象创建成功
|
||||
*/
|
||||
public static final int CREATED = 201;
|
||||
|
||||
/**
|
||||
* 请求已经被接受
|
||||
*/
|
||||
public static final int ACCEPTED = 202;
|
||||
|
||||
/**
|
||||
* 操作已经执行成功,但是没有返回数据
|
||||
*/
|
||||
public static final int NO_CONTENT = 204;
|
||||
|
||||
/**
|
||||
* 资源已被移除
|
||||
*/
|
||||
public static final int MOVED_PERM = 301;
|
||||
|
||||
/**
|
||||
* 重定向
|
||||
*/
|
||||
public static final int SEE_OTHER = 303;
|
||||
|
||||
/**
|
||||
* 资源没有被修改
|
||||
*/
|
||||
public static final int NOT_MODIFIED = 304;
|
||||
|
||||
/**
|
||||
* 参数列表错误(缺少,格式不匹配)
|
||||
*/
|
||||
public static final int BAD_REQUEST = 400;
|
||||
|
||||
/**
|
||||
* 未授权
|
||||
*/
|
||||
public static final int UNAUTHORIZED = 401;
|
||||
|
||||
/**
|
||||
* 访问受限,授权过期
|
||||
*/
|
||||
public static final int FORBIDDEN = 403;
|
||||
|
||||
/**
|
||||
* 资源,服务未找到
|
||||
*/
|
||||
public static final int NOT_FOUND = 404;
|
||||
|
||||
/**
|
||||
* 不允许的http方法
|
||||
*/
|
||||
public static final int BAD_METHOD = 405;
|
||||
|
||||
/**
|
||||
* 资源冲突,或者资源被锁
|
||||
*/
|
||||
public static final int CONFLICT = 409;
|
||||
|
||||
/**
|
||||
* 不支持的数据,媒体类型
|
||||
*/
|
||||
public static final int UNSUPPORTED_TYPE = 415;
|
||||
|
||||
/**
|
||||
* 系统内部错误
|
||||
*/
|
||||
public static final int ERROR = 500;
|
||||
|
||||
/**
|
||||
* 接口未实现
|
||||
*/
|
||||
public static final int NOT_IMPLEMENTED = 501;
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ package cn.com.mfish.common.core.constants;
|
||||
* @description: 凭证常量
|
||||
* @date: 2021/11/18 18:16
|
||||
*/
|
||||
public class CredentialConstants {
|
||||
public class RPCConstants {
|
||||
/**
|
||||
* 请求来源
|
||||
*/
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
package cn.com.mfish.common.core.utils;
|
||||
|
||||
import cn.com.mfish.common.core.constants.Constants;
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.utils.html.WebRequest;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.utils.http.WebRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AuthInfoUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getCurrentUserId() {
|
||||
String userId = ServletUtils.getRequest().getHeader(CredentialConstants.REQ_USER_ID);
|
||||
String userId = ServletUtils.getRequest().getHeader(RPCConstants.REQ_USER_ID);
|
||||
return StringUtils.isEmpty(userId) ? null : userId;
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class AuthInfoUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getCurrentAccount() {
|
||||
String account = ServletUtils.getRequest().getHeader(CredentialConstants.REQ_ACCOUNT);
|
||||
String account = ServletUtils.getRequest().getHeader(RPCConstants.REQ_ACCOUNT);
|
||||
return StringUtils.isEmpty(account) ? null : account;
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class AuthInfoUtils {
|
||||
* @return
|
||||
*/
|
||||
public static String getCurrentClientId() {
|
||||
String clientId = ServletUtils.getRequest().getHeader(CredentialConstants.REQ_CLIENT_ID);
|
||||
String clientId = ServletUtils.getRequest().getHeader(RPCConstants.REQ_CLIENT_ID);
|
||||
return StringUtils.isEmpty(clientId) ? null : clientId;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,254 +0,0 @@
|
||||
package cn.com.mfish.common.core.utils;
|
||||
|
||||
/**
|
||||
* Base64工具类
|
||||
*
|
||||
* @author: mfish
|
||||
* @date: 2021/8/12 15:38
|
||||
*/
|
||||
public class Base64 {
|
||||
static private final int BASELENGTH = 128;
|
||||
static private final int LOOKUPLENGTH = 64;
|
||||
static private final int TWENTYFOURBITGROUP = 24;
|
||||
static private final int EIGHTBIT = 8;
|
||||
static private final int SIXTEENBIT = 16;
|
||||
static private final int FOURBYTE = 4;
|
||||
static private final int SIGN = -128;
|
||||
static private final char PAD = '=';
|
||||
static final private byte[] base64Alphabet = new byte[BASELENGTH];
|
||||
static final private char[] lookUpBase64Alphabet = new char[LOOKUPLENGTH];
|
||||
|
||||
static {
|
||||
for (int i = 0; i < BASELENGTH; ++i) {
|
||||
base64Alphabet[i] = -1;
|
||||
}
|
||||
for (int i = 'Z'; i >= 'A'; i--) {
|
||||
base64Alphabet[i] = (byte) (i - 'A');
|
||||
}
|
||||
for (int i = 'z'; i >= 'a'; i--) {
|
||||
base64Alphabet[i] = (byte) (i - 'a' + 26);
|
||||
}
|
||||
|
||||
for (int i = '9'; i >= '0'; i--) {
|
||||
base64Alphabet[i] = (byte) (i - '0' + 52);
|
||||
}
|
||||
|
||||
base64Alphabet['+'] = 62;
|
||||
base64Alphabet['/'] = 63;
|
||||
|
||||
for (int i = 0; i <= 25; i++) {
|
||||
lookUpBase64Alphabet[i] = (char) ('A' + i);
|
||||
}
|
||||
|
||||
for (int i = 26, j = 0; i <= 51; i++, j++) {
|
||||
lookUpBase64Alphabet[i] = (char) ('a' + j);
|
||||
}
|
||||
|
||||
for (int i = 52, j = 0; i <= 61; i++, j++) {
|
||||
lookUpBase64Alphabet[i] = (char) ('0' + j);
|
||||
}
|
||||
lookUpBase64Alphabet[62] = (char) '+';
|
||||
lookUpBase64Alphabet[63] = (char) '/';
|
||||
}
|
||||
|
||||
private static boolean isWhiteSpace(char octect) {
|
||||
return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
|
||||
}
|
||||
|
||||
private static boolean isPad(char octect) {
|
||||
return (octect == PAD);
|
||||
}
|
||||
|
||||
private static boolean isData(char octect) {
|
||||
return (octect < BASELENGTH && base64Alphabet[octect] != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes hex octects into Base64
|
||||
*
|
||||
* @param binaryData Array containing binaryData
|
||||
* @return Encoded Base64 array
|
||||
*/
|
||||
public static String encode(byte[] binaryData) {
|
||||
if (binaryData == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int lengthDataBits = binaryData.length * EIGHTBIT;
|
||||
if (lengthDataBits == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
|
||||
int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
|
||||
int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets;
|
||||
char encodedData[] = null;
|
||||
|
||||
encodedData = new char[numberQuartet * 4];
|
||||
|
||||
byte k = 0, l = 0, b1 = 0, b2 = 0, b3 = 0;
|
||||
|
||||
int encodedIndex = 0;
|
||||
int dataIndex = 0;
|
||||
|
||||
for (int i = 0; i < numberTriplets; i++) {
|
||||
b1 = binaryData[dataIndex++];
|
||||
b2 = binaryData[dataIndex++];
|
||||
b3 = binaryData[dataIndex++];
|
||||
|
||||
l = (byte) (b2 & 0x0f);
|
||||
k = (byte) (b1 & 0x03);
|
||||
|
||||
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
|
||||
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
|
||||
byte val3 = ((b3 & SIGN) == 0) ? (byte) (b3 >> 6) : (byte) ((b3) >> 6 ^ 0xfc);
|
||||
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[(l << 2) | val3];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[b3 & 0x3f];
|
||||
}
|
||||
|
||||
// form integral number of 6-bit groups
|
||||
if (fewerThan24bits == EIGHTBIT) {
|
||||
b1 = binaryData[dataIndex];
|
||||
k = (byte) (b1 & 0x03);
|
||||
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[k << 4];
|
||||
encodedData[encodedIndex++] = PAD;
|
||||
encodedData[encodedIndex++] = PAD;
|
||||
} else if (fewerThan24bits == SIXTEENBIT) {
|
||||
b1 = binaryData[dataIndex];
|
||||
b2 = binaryData[dataIndex + 1];
|
||||
l = (byte) (b2 & 0x0f);
|
||||
k = (byte) (b1 & 0x03);
|
||||
|
||||
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
|
||||
byte val2 = ((b2 & SIGN) == 0) ? (byte) (b2 >> 4) : (byte) ((b2) >> 4 ^ 0xf0);
|
||||
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[val1];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[val2 | (k << 4)];
|
||||
encodedData[encodedIndex++] = lookUpBase64Alphabet[l << 2];
|
||||
encodedData[encodedIndex++] = PAD;
|
||||
}
|
||||
return new String(encodedData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes Base64 data into octects
|
||||
*
|
||||
* @param encoded string containing Base64 data
|
||||
* @return Array containind decoded data.
|
||||
*/
|
||||
public static byte[] decode(String encoded) {
|
||||
if (encoded == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
char[] base64Data = encoded.toCharArray();
|
||||
// remove white spaces
|
||||
int len = removeWhiteSpace(base64Data);
|
||||
|
||||
if (len % FOURBYTE != 0) {
|
||||
return null;// should be divisible by four
|
||||
}
|
||||
|
||||
int numberQuadruple = (len / FOURBYTE);
|
||||
|
||||
if (numberQuadruple == 0) {
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
byte decodedData[] = null;
|
||||
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
|
||||
char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
|
||||
|
||||
int i = 0;
|
||||
int encodedIndex = 0;
|
||||
int dataIndex = 0;
|
||||
decodedData = new byte[(numberQuadruple) * 3];
|
||||
|
||||
for (; i < numberQuadruple - 1; i++) {
|
||||
|
||||
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))
|
||||
|| !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) {
|
||||
return null;
|
||||
} // if found "no data" just return null
|
||||
|
||||
b1 = base64Alphabet[d1];
|
||||
b2 = base64Alphabet[d2];
|
||||
b3 = base64Alphabet[d3];
|
||||
b4 = base64Alphabet[d4];
|
||||
|
||||
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
|
||||
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
|
||||
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
|
||||
}
|
||||
|
||||
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) {
|
||||
return null;// if found "no data" just return null
|
||||
}
|
||||
|
||||
b1 = base64Alphabet[d1];
|
||||
b2 = base64Alphabet[d2];
|
||||
|
||||
d3 = base64Data[dataIndex++];
|
||||
d4 = base64Data[dataIndex++];
|
||||
if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters
|
||||
if (isPad(d3) && isPad(d4)) {
|
||||
if ((b2 & 0xf) != 0)// last 4 bits should be zero
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] tmp = new byte[i * 3 + 1];
|
||||
System.arraycopy(decodedData, 0, tmp, 0, i * 3);
|
||||
tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
|
||||
return tmp;
|
||||
} else if (!isPad(d3) && isPad(d4)) {
|
||||
b3 = base64Alphabet[d3];
|
||||
if ((b3 & 0x3) != 0)// last 2 bits should be zero
|
||||
{
|
||||
return null;
|
||||
}
|
||||
byte[] tmp = new byte[i * 3 + 2];
|
||||
System.arraycopy(decodedData, 0, tmp, 0, i * 3);
|
||||
tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
|
||||
tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
|
||||
return tmp;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else { // No PAD e.g 3cQl
|
||||
b3 = base64Alphabet[d3];
|
||||
b4 = base64Alphabet[d4];
|
||||
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
|
||||
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
|
||||
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
|
||||
|
||||
}
|
||||
return decodedData;
|
||||
}
|
||||
|
||||
/**
|
||||
* remove WhiteSpace from MIME containing encoded Base64 data.
|
||||
*
|
||||
* @param data the byte array of base64 data (with WS)
|
||||
* @return the new length
|
||||
*/
|
||||
private static int removeWhiteSpace(char[] data) {
|
||||
if (data == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// count characters that's not whitespace
|
||||
int newSize = 0;
|
||||
int len = data.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!isWhiteSpace(data[i])) {
|
||||
data[newSize++] = data[i];
|
||||
}
|
||||
}
|
||||
return newSize;
|
||||
}
|
||||
}
|
||||
-8
@@ -1,7 +1,6 @@
|
||||
package cn.com.mfish.common.core.utils;
|
||||
|
||||
import cn.com.mfish.common.core.constants.Constants;
|
||||
import cn.com.mfish.common.core.utils.text.Convert;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
@@ -34,13 +33,6 @@ public class ServletUtils {
|
||||
return getRequest().getParameter(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取String参数
|
||||
*/
|
||||
public static String getParameter(String name, String defaultValue) {
|
||||
return Convert.toStr(getRequest().getParameter(name), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取request
|
||||
*/
|
||||
|
||||
+1
-12
@@ -37,18 +37,7 @@ public final class SpringBeanFactory implements BeanFactoryPostProcessor {
|
||||
* @return
|
||||
*/
|
||||
public static <T> T getBean(Class<T> clz) {
|
||||
T result = (T) beanFactory.getBean(clz);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否包含某个名称的bean
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public static boolean containsBean(String name) {
|
||||
return beanFactory.containsBean(name);
|
||||
return beanFactory.getBean(clz);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-131
@@ -3,10 +3,8 @@ package cn.com.mfish.common.core.utils;
|
||||
import cn.com.mfish.common.core.constants.Constants;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -22,116 +20,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
*/
|
||||
private static final char SEPARATOR = '_';
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否为空, 包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Collection<?> coll) {
|
||||
return isNull(coll) || coll.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Collection是否非空,包含List,Set,Queue
|
||||
*
|
||||
* @param coll 要判断的Collection
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Collection<?> coll) {
|
||||
return !isEmpty(coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否为空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* * @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Object[] objects) {
|
||||
return isNull(objects) || (objects.length == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象数组是否非空
|
||||
*
|
||||
* @param objects 要判断的对象数组
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Object[] objects) {
|
||||
return !isEmpty(objects);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(Map<?, ?> map) {
|
||||
return isNull(map) || map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个Map是否为空
|
||||
*
|
||||
* @param map 要判断的Map
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotEmpty(Map<?, ?> map) {
|
||||
return !isEmpty(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isEmpty(String str) {
|
||||
return isNull(str) || "".equals(str.trim());
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个字符串是否为非空串
|
||||
*
|
||||
* @param str String
|
||||
* @return true:非空串 false:空串
|
||||
*/
|
||||
public static boolean isNotEmpty(String str) {
|
||||
return !isEmpty(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否为空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:为空 false:非空
|
||||
*/
|
||||
public static boolean isNull(Object object) {
|
||||
return object == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否非空
|
||||
*
|
||||
* @param object Object
|
||||
* @return true:非空 false:空
|
||||
*/
|
||||
public static boolean isNotNull(Object object) {
|
||||
return !isNull(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* * 判断一个对象是否是数组类型(Java基本型别的数组)
|
||||
*
|
||||
* @param object 对象
|
||||
* @return true:是数组 false:不是数组
|
||||
*/
|
||||
public static boolean isArray(Object object) {
|
||||
return isNotNull(object) && object.getClass().isArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 去空格
|
||||
*/
|
||||
@@ -184,24 +72,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否包含字符串
|
||||
*
|
||||
* @param str 验证字符串
|
||||
* @param strs 字符串组
|
||||
* @return 包含返回true
|
||||
*/
|
||||
public static boolean inStringIgnoreCase(String str, String... strs) {
|
||||
if (str != null && strs != null) {
|
||||
for (String s : strs) {
|
||||
if (str.equalsIgnoreCase(trim(s))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 驼峰式命名法 例如:user_name->userName
|
||||
*
|
||||
@@ -291,7 +161,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||
* @return 是否匹配
|
||||
*/
|
||||
public static boolean matches(String str, List<String> strs) {
|
||||
if (isEmpty(str) || isEmpty(strs)) {
|
||||
if (isEmpty(str) || strs == null || strs.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
for (String pattern : strs) {
|
||||
|
||||
+1
-3
@@ -1,4 +1,4 @@
|
||||
package cn.com.mfish.common.core.utils.html;
|
||||
package cn.com.mfish.common.core.utils.http;
|
||||
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
|
||||
@@ -7,8 +7,6 @@ import cn.com.mfish.common.core.utils.StringUtils;
|
||||
* @date: 2021/8/12 10:48
|
||||
*/
|
||||
public class EscapeUtil {
|
||||
public static final String RE_HTML_MARK = "(<[^<]*?>)|(<[\\s]*?/[^<]*?>)|(<[^<]*?/[\\s]*?>)";
|
||||
|
||||
private static final char[][] TEXT = new char[64][];
|
||||
|
||||
static {
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.com.mfish.common.core.utils.html;
|
||||
package cn.com.mfish.common.core.utils.http;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package cn.com.mfish.common.core.utils.html;
|
||||
package cn.com.mfish.common.core.utils.http;
|
||||
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.web.context.request.NativeWebRequest;
|
||||
-92
@@ -1,92 +0,0 @@
|
||||
package cn.com.mfish.common.core.utils.text;
|
||||
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
/**
|
||||
* 字符集编码转换相关工具类
|
||||
*
|
||||
* @author: mfish
|
||||
* @date: 2021/8/12 10:37
|
||||
*/
|
||||
public class CharsetKit {
|
||||
/**
|
||||
* ISO-8859-1
|
||||
*/
|
||||
public static final String ISO_8859_1 = "ISO-8859-1";
|
||||
/**
|
||||
* UTF-8
|
||||
*/
|
||||
public static final String UTF_8 = "UTF-8";
|
||||
/**
|
||||
* GBK
|
||||
*/
|
||||
public static final String GBK = "GBK";
|
||||
|
||||
/**
|
||||
* ISO-8859-1
|
||||
*/
|
||||
public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1);
|
||||
/**
|
||||
* UTF-8
|
||||
*/
|
||||
public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8);
|
||||
/**
|
||||
* GBK
|
||||
*/
|
||||
public static final Charset CHARSET_GBK = Charset.forName(GBK);
|
||||
|
||||
/**
|
||||
* 转换为Charset对象
|
||||
*
|
||||
* @param charset 字符集,为空则返回默认字符集
|
||||
* @return Charset
|
||||
*/
|
||||
public static Charset charset(String charset) {
|
||||
return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换字符串的字符集编码
|
||||
*
|
||||
* @param source 字符串
|
||||
* @param srcCharset 源字符集,默认ISO-8859-1
|
||||
* @param destCharset 目标字符集,默认UTF-8
|
||||
* @return 转换后的字符集
|
||||
*/
|
||||
public static String convert(String source, String srcCharset, String destCharset) {
|
||||
return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换字符串的字符集编码
|
||||
*
|
||||
* @param source 字符串
|
||||
* @param srcCharset 源字符集,默认ISO-8859-1
|
||||
* @param destCharset 目标字符集,默认UTF-8
|
||||
* @return 转换后的字符集
|
||||
*/
|
||||
public static String convert(String source, Charset srcCharset, Charset destCharset) {
|
||||
if (null == srcCharset) {
|
||||
srcCharset = StandardCharsets.ISO_8859_1;
|
||||
}
|
||||
|
||||
if (null == destCharset) {
|
||||
destCharset = StandardCharsets.UTF_8;
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) {
|
||||
return source;
|
||||
}
|
||||
return new String(source.getBytes(srcCharset), destCharset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 系统字符集编码
|
||||
*/
|
||||
public static String systemCharset() {
|
||||
return Charset.defaultCharset().name();
|
||||
}
|
||||
}
|
||||
-849
@@ -1,849 +0,0 @@
|
||||
package cn.com.mfish.common.core.utils.text;
|
||||
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 类型转换工具类
|
||||
*
|
||||
* @author: mfish
|
||||
* @date: 2021/8/12 10:36
|
||||
*/
|
||||
public class Convert {
|
||||
/**
|
||||
* 转换为字符串
|
||||
* 如果给定的值为null,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String toStr(Object value, String defaultValue) {
|
||||
if (null == value) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return (String) value;
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符串
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String toStr(Object value) {
|
||||
return toStr(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符
|
||||
* 如果给定的值为null,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Character toChar(Object value, Character defaultValue) {
|
||||
if (null == value) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Character) {
|
||||
return (Character) value;
|
||||
}
|
||||
|
||||
final String valueStr = toStr(value, null);
|
||||
return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为字符
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Character toChar(Object value) {
|
||||
return toChar(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为byte
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Byte toByte(Object value, Byte defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Byte) {
|
||||
return (Byte) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).byteValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Byte.parseByte(valueStr);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为byte
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Byte toByte(Object value) {
|
||||
return toByte(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Short
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Short toShort(Object value, Short defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Short) {
|
||||
return (Short) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).shortValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Short.parseShort(valueStr.trim());
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Short
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Short toShort(Object value) {
|
||||
return toShort(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Number
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Number toNumber(Object value, Number defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return (Number) value;
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return NumberFormat.getInstance().parse(valueStr);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Number
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Number toNumber(Object value) {
|
||||
return toNumber(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为int
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer toInt(Object value, Integer defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
return (Integer) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).intValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(valueStr.trim());
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为int
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer toInt(Object value) {
|
||||
return toInt(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String str) {
|
||||
return toIntArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Long数组
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String str) {
|
||||
return toLongArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Integer数组
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Integer[] toIntArray(String split, String str) {
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
return new Integer[]{};
|
||||
}
|
||||
String[] arr = str.split(split);
|
||||
final Integer[] ints = new Integer[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
final Integer v = toInt(arr[i], 0);
|
||||
ints[i] = v;
|
||||
}
|
||||
return ints;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Long数组
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long[] toLongArray(String split, String str) {
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
return new Long[]{};
|
||||
}
|
||||
String[] arr = str.split(split);
|
||||
final Long[] longs = new Long[arr.length];
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
final Long v = toLong(arr[i], null);
|
||||
longs[i] = v;
|
||||
}
|
||||
return longs;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组
|
||||
*
|
||||
* @param str 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String str) {
|
||||
return toStrArray(",", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为String数组
|
||||
*
|
||||
* @param split 分隔符
|
||||
* @param split 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static String[] toStrArray(String split, String str) {
|
||||
return str.split(split);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为long
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long toLong(Object value, Long defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Long) {
|
||||
return (Long) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).longValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
// 支持科学计数法
|
||||
return new BigDecimal(valueStr.trim()).longValue();
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为long
|
||||
* 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Long toLong(Object value) {
|
||||
return toLong(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为double
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Double toDouble(Object value, Double defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Double) {
|
||||
return (Double) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).doubleValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
// 支持科学计数法
|
||||
return new BigDecimal(valueStr.trim()).doubleValue();
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为double
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Double toDouble(Object value) {
|
||||
return toDouble(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Float
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Float toFloat(Object value, Float defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Float) {
|
||||
return (Float) value;
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return ((Number) value).floatValue();
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Float.parseFloat(valueStr.trim());
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Float
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Float toFloat(Object value) {
|
||||
return toFloat(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为boolean
|
||||
* String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Boolean toBool(Object value, Boolean defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof Boolean) {
|
||||
return (Boolean) value;
|
||||
}
|
||||
String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
valueStr = valueStr.trim().toLowerCase();
|
||||
switch (valueStr) {
|
||||
case "true":
|
||||
case "yes":
|
||||
case "ok":
|
||||
case "1":
|
||||
return true;
|
||||
case "false":
|
||||
case "no":
|
||||
case "0":
|
||||
return false;
|
||||
default:
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为boolean
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static Boolean toBool(Object value) {
|
||||
return toBool(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Enum对象
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
*
|
||||
* @param clazz Enum的Class
|
||||
* @param value 值
|
||||
* @param defaultValue 默认值
|
||||
* @return Enum
|
||||
*/
|
||||
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (clazz.isAssignableFrom(value.getClass())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
E myE = (E) value;
|
||||
return myE;
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return Enum.valueOf(clazz, valueStr);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Enum对象
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
*
|
||||
* @param clazz Enum的Class
|
||||
* @param value 值
|
||||
* @return Enum
|
||||
*/
|
||||
public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) {
|
||||
return toEnum(clazz, value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigInteger
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigInteger toBigInteger(Object value, BigInteger defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof BigInteger) {
|
||||
return (BigInteger) value;
|
||||
}
|
||||
if (value instanceof Long) {
|
||||
return BigInteger.valueOf((Long) value);
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return new BigInteger(valueStr);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigInteger
|
||||
* 如果给定的值为空,或者转换失败,返回默认值<code>null</code>
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigInteger toBigInteger(Object value) {
|
||||
return toBigInteger(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigDecimal
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @param defaultValue 转换错误时的默认值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) {
|
||||
if (value == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
if (value instanceof BigDecimal) {
|
||||
return (BigDecimal) value;
|
||||
}
|
||||
if (value instanceof Long) {
|
||||
return new BigDecimal((Long) value);
|
||||
}
|
||||
if (value instanceof Double) {
|
||||
return new BigDecimal((Double) value);
|
||||
}
|
||||
if (value instanceof Integer) {
|
||||
return new BigDecimal((Integer) value);
|
||||
}
|
||||
final String valueStr = toStr(value, null);
|
||||
if (StringUtils.isEmpty(valueStr)) {
|
||||
return defaultValue;
|
||||
}
|
||||
try {
|
||||
return new BigDecimal(valueStr);
|
||||
} catch (Exception e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为BigDecimal
|
||||
* 如果给定的值为空,或者转换失败,返回默认值
|
||||
* 转换失败不会报错
|
||||
*
|
||||
* @param value 被转换的值
|
||||
* @return 结果
|
||||
*/
|
||||
public static BigDecimal toBigDecimal(Object value) {
|
||||
return toBigDecimal(value, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String utf8Str(Object obj) {
|
||||
return str(obj, CharsetKit.CHARSET_UTF_8);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param charsetName 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(Object obj, String charsetName) {
|
||||
return str(obj, Charset.forName(charsetName));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为字符串
|
||||
* 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param charset 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(Object obj, Charset charset) {
|
||||
if (null == obj) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (obj instanceof String) {
|
||||
return (String) obj;
|
||||
}
|
||||
if (obj instanceof byte[] || obj instanceof Byte[]) {
|
||||
if (obj instanceof byte[]) {
|
||||
return str((byte[]) obj, charset);
|
||||
}
|
||||
Byte[] bytes = (Byte[]) obj;
|
||||
int length = bytes.length;
|
||||
byte[] dest = new byte[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
dest[i] = bytes[i];
|
||||
}
|
||||
return str(dest, charset);
|
||||
}
|
||||
if (obj instanceof ByteBuffer) {
|
||||
return str((ByteBuffer) obj, charset);
|
||||
}
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将byte数组转为字符串
|
||||
*
|
||||
* @param bytes byte数组
|
||||
* @param charset 字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(byte[] bytes, String charset) {
|
||||
return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 解码字节码
|
||||
*
|
||||
* @param data 字符串
|
||||
* @param charset 字符集,如果此字段为空,则解码的结果取决于平台
|
||||
* @return 解码后的字符串
|
||||
*/
|
||||
public static String str(byte[] data, Charset charset) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (null == charset) {
|
||||
return new String(data);
|
||||
}
|
||||
return new String(data, charset);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将编码的byteBuffer数据转换为字符串
|
||||
*
|
||||
* @param data 数据
|
||||
* @param charset 字符集,如果为空使用当前系统字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(ByteBuffer data, String charset) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return str(data, Charset.forName(charset));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将编码的byteBuffer数据转换为字符串
|
||||
*
|
||||
* @param data 数据
|
||||
* @param charset 字符集,如果为空使用当前系统字符集
|
||||
* @return 字符串
|
||||
*/
|
||||
public static String str(ByteBuffer data, Charset charset) {
|
||||
if (null == charset) {
|
||||
charset = Charset.defaultCharset();
|
||||
}
|
||||
return charset.decode(data).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 半角转全角
|
||||
*
|
||||
* @param input String.
|
||||
* @return 全角字符串.
|
||||
*/
|
||||
public static String toSBC(String input) {
|
||||
return toSBC(input, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 半角转全角
|
||||
*
|
||||
* @param input String
|
||||
* @param notConvertSet 不替换的字符集合
|
||||
* @return 全角字符串.
|
||||
*/
|
||||
public static String toSBC(String input, Set<Character> notConvertSet) {
|
||||
char c[] = input.toCharArray();
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (null != notConvertSet && notConvertSet.contains(c[i])) {
|
||||
// 跳过不替换的字符
|
||||
continue;
|
||||
}
|
||||
if (c[i] == ' ') {
|
||||
c[i] = '\u3000';
|
||||
} else if (c[i] < '\177') {
|
||||
c[i] = (char) (c[i] + 65248);
|
||||
}
|
||||
}
|
||||
return new String(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全角转半角
|
||||
*
|
||||
* @param input String.
|
||||
* @return 半角字符串
|
||||
*/
|
||||
public static String toDBC(String input) {
|
||||
return toDBC(input, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 替换全角为半角
|
||||
*
|
||||
* @param text 文本
|
||||
* @param notConvertSet 不替换的字符集合
|
||||
* @return 替换后的字符
|
||||
*/
|
||||
public static String toDBC(String text, Set<Character> notConvertSet) {
|
||||
char c[] = text.toCharArray();
|
||||
for (int i = 0; i < c.length; i++) {
|
||||
if (null != notConvertSet && notConvertSet.contains(c[i])) {
|
||||
// 跳过不替换的字符
|
||||
continue;
|
||||
}
|
||||
if (c[i] == '\u3000') {
|
||||
c[i] = ' ';
|
||||
} else if (c[i] > '\uFF00' && c[i] < '\uFF5F') {
|
||||
c[i] = (char) (c[i] - 65248);
|
||||
}
|
||||
}
|
||||
return new String(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 数字金额大写转换 先写个完整的然后将如零拾替换成零
|
||||
*
|
||||
* @param n 数字
|
||||
* @return 中文大写数字
|
||||
*/
|
||||
public static String digitUppercase(double n) {
|
||||
String[] fraction = {"角", "分"};
|
||||
String[] digit = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"};
|
||||
String[][] unit = {{"元", "万", "亿"}, {"", "拾", "佰", "仟"}};
|
||||
String head = n < 0 ? "负" : "";
|
||||
n = Math.abs(n);
|
||||
|
||||
String s = "";
|
||||
for (int i = 0; i < fraction.length; i++) {
|
||||
s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", "");
|
||||
}
|
||||
if (s.length() < 1) {
|
||||
s = "整";
|
||||
}
|
||||
int integerPart = (int) Math.floor(n);
|
||||
|
||||
for (int i = 0; i < unit[0].length && integerPart > 0; i++) {
|
||||
String p = "";
|
||||
for (int j = 0; j < unit[1].length && n > 0; j++) {
|
||||
p = digit[integerPart % 10] + unit[1][j] + p;
|
||||
integerPart = integerPart / 10;
|
||||
}
|
||||
s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s;
|
||||
}
|
||||
return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整");
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
package cn.com.mfish.common.core.utils.text;
|
||||
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 字符串格式化
|
||||
*
|
||||
* @author: mfish
|
||||
* @date: 2021/8/12 10:36
|
||||
*/
|
||||
public class StrFormatter {
|
||||
public static final String EMPTY_JSON = "{}";
|
||||
public static final char C_BACKSLASH = '\\';
|
||||
public static final char C_DELIM_START = '{';
|
||||
public static final char C_DELIM_END = '}';
|
||||
|
||||
/**
|
||||
* 格式化字符串
|
||||
* 此方法只是简单将占位符 {} 按照顺序替换为参数
|
||||
* 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可
|
||||
* 例:
|
||||
* 通常使用:format("this is {} for {}", "a", "b") -> this is a for b
|
||||
* 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a
|
||||
* 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b
|
||||
*
|
||||
* @param strPattern 字符串模板
|
||||
* @param argArray 参数列表
|
||||
* @return 结果
|
||||
*/
|
||||
public static String format(final String strPattern, final Object... argArray) {
|
||||
if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) {
|
||||
return strPattern;
|
||||
}
|
||||
final int strPatternLength = strPattern.length();
|
||||
// 初始化定义好的长度以获得更好的性能
|
||||
StringBuilder sbuf = new StringBuilder(strPatternLength + 50);
|
||||
int handledPosition = 0;
|
||||
int delimIndex;// 占位符所在位置
|
||||
for (int argIndex = 0; argIndex < argArray.length; argIndex++) {
|
||||
delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition);
|
||||
if (delimIndex == -1) {
|
||||
if (handledPosition == 0) {
|
||||
return strPattern;
|
||||
}
|
||||
// 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果
|
||||
sbuf.append(strPattern, handledPosition, strPatternLength);
|
||||
return sbuf.toString();
|
||||
}
|
||||
if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) {
|
||||
if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) {
|
||||
// 转义符之前还有一个转义符,占位符依旧有效
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(Convert.utf8Str(argArray[argIndex]));
|
||||
handledPosition = delimIndex + 2;
|
||||
} else {
|
||||
// 占位符被转义
|
||||
argIndex--;
|
||||
sbuf.append(strPattern, handledPosition, delimIndex - 1);
|
||||
sbuf.append(C_DELIM_START);
|
||||
handledPosition = delimIndex + 1;
|
||||
}
|
||||
} else {
|
||||
// 正常占位符
|
||||
sbuf.append(strPattern, handledPosition, delimIndex);
|
||||
sbuf.append(Convert.utf8Str(argArray[argIndex]));
|
||||
handledPosition = delimIndex + 2;
|
||||
}
|
||||
}
|
||||
// 加入最后一个占位符后所有的字符
|
||||
sbuf.append(strPattern, handledPosition, strPattern.length());
|
||||
return sbuf.toString();
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class LogAspect {
|
||||
String params = "";
|
||||
if (paramsArray != null && paramsArray.length > 0) {
|
||||
for (Object obj : paramsArray) {
|
||||
if (StringUtils.isNull(obj)) {
|
||||
if (null == obj) {
|
||||
continue;
|
||||
}
|
||||
if (obj instanceof String) {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.common.log.service;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.sys.api.entity.SysLog;
|
||||
import cn.com.mfish.sys.api.remote.RemoteLogService;
|
||||
@@ -25,7 +25,7 @@ public class AsyncSaveLog {
|
||||
|
||||
@Async
|
||||
public void saveLog(SysLog sysLog) {
|
||||
Result result = remoteLogService.addLog(CredentialConstants.INNER, sysLog);
|
||||
Result result = remoteLogService.addLog(RPCConstants.INNER, sysLog);
|
||||
if (result.isSuccess()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.common.oauth.cache;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.common.oauth.api.remote.RemoteUserService;
|
||||
import cn.com.mfish.common.redis.common.RedisPrefix;
|
||||
@@ -40,7 +40,7 @@ public class UserPermissionCache extends BaseTempCache<Set<String>> {
|
||||
*/
|
||||
@Override
|
||||
protected Set<String> getFromDB(String... key) {
|
||||
Result<Set<String>> result = remoteUserService.getPermissions(CredentialConstants.INNER, key[0], key[1]);
|
||||
Result<Set<String>> result = remoteUserService.getPermissions(RPCConstants.INNER, key[0], key[1]);
|
||||
if (result == null || !result.isSuccess()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.common.oauth.cache;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.common.oauth.api.remote.RemoteUserService;
|
||||
import cn.com.mfish.common.redis.common.RedisPrefix;
|
||||
@@ -41,7 +41,7 @@ public class UserRoleCache extends BaseTempCache<List<UserRole>> {
|
||||
*/
|
||||
@Override
|
||||
protected List<UserRole> getFromDB(String... key) {
|
||||
Result<List<UserRole>> result = remoteUserService.getRoles(CredentialConstants.INNER, key[0], key[1]);
|
||||
Result<List<UserRole>> result = remoteUserService.getRoles(RPCConstants.INNER, key[0], key[1]);
|
||||
if (result == null || !result.isSuccess()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package cn.com.mfish.common.web.aspect;
|
||||
|
||||
import cn.com.mfish.common.core.annotation.GlobalException;
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.exception.OAuthValidateException;
|
||||
import cn.com.mfish.common.core.utils.ServletUtils;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
@@ -31,9 +31,9 @@ public class InnerUserAspect {
|
||||
@Around("@annotation(innerUser)")
|
||||
public Object innerAround(ProceedingJoinPoint point, InnerUser innerUser) throws Throwable {
|
||||
HttpServletRequest request = ServletUtils.getRequest();
|
||||
String source = request.getHeader(CredentialConstants.REQ_ORIGIN);
|
||||
String source = request.getHeader(RPCConstants.REQ_ORIGIN);
|
||||
// 内部请求验证
|
||||
if (CredentialConstants.INNER.equals(source) && !innerUser.validateUser()) {
|
||||
if (RPCConstants.INNER.equals(source) && !innerUser.validateUser()) {
|
||||
return point.proceed();
|
||||
}
|
||||
Result result = tokenValidator.validator(request);
|
||||
|
||||
@@ -19,29 +19,34 @@ public class MathCaptchaCreate extends DefaultTextCreator {
|
||||
int y = random.nextInt(10);
|
||||
StringBuilder sb;
|
||||
int seed = (int) Math.round(Math.random() * 2);
|
||||
Integer result = 0;
|
||||
if (seed == 0) {
|
||||
sb = createFormula(NUMBERS[x], "*", NUMBERS[y]);
|
||||
result = x * y;
|
||||
} else if (seed == 1) {
|
||||
if (!(x == 0) && y % x == 0) {
|
||||
sb = createFormula(NUMBERS[y], "/", NUMBERS[x]);
|
||||
result = y / x;
|
||||
} else {
|
||||
Integer result;
|
||||
switch (seed) {
|
||||
case 0:
|
||||
sb = createFormula(NUMBERS[x], "*", NUMBERS[y]);
|
||||
result = x * y;
|
||||
break;
|
||||
case 1:
|
||||
if (!(x == 0) && y % x == 0) {
|
||||
sb = createFormula(NUMBERS[y], "/", NUMBERS[x]);
|
||||
result = y / x;
|
||||
} else {
|
||||
sb = createFormula(NUMBERS[x], "+", NUMBERS[y]);
|
||||
result = x + y;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (x >= y) {
|
||||
sb = createFormula(NUMBERS[x], "-", NUMBERS[y]);
|
||||
result = x - y;
|
||||
} else {
|
||||
sb = createFormula(NUMBERS[y], "-", NUMBERS[x]);
|
||||
result = y - x;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
sb = createFormula(NUMBERS[x], "+", NUMBERS[y]);
|
||||
result = x + y;
|
||||
}
|
||||
} else if (seed == 2) {
|
||||
if (x >= y) {
|
||||
sb = createFormula(NUMBERS[x], "-", NUMBERS[y]);
|
||||
result = x - y;
|
||||
} else {
|
||||
sb = createFormula(NUMBERS[y], "-", NUMBERS[x]);
|
||||
result = y - x;
|
||||
}
|
||||
} else {
|
||||
sb = createFormula(NUMBERS[x], "+", NUMBERS[y]);
|
||||
result = x + y;
|
||||
break;
|
||||
}
|
||||
sb.append("=?#" + result);
|
||||
return sb.toString();
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.util.List;
|
||||
* @date: 2021/11/11 10:37
|
||||
*/
|
||||
@Component
|
||||
public class SwaggerProvider implements WebFluxConfigurer,SwaggerResourcesProvider {
|
||||
public class SwaggerProvider implements WebFluxConfigurer, SwaggerResourcesProvider {
|
||||
/**
|
||||
* swagger2默认的url后缀
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ public class SwaggerProvider implements WebFluxConfigurer,SwaggerResourcesProvid
|
||||
.forEach(routeDefinition -> routeDefinition.getPredicates().stream()
|
||||
.forEach(predicateDefinition ->
|
||||
resources.add(swaggerResource(routeDefinition.getId()
|
||||
, predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX+"0")
|
||||
, predicateDefinition.getArgs().get(NameUtils.GENERATED_NAME_PREFIX + "0")
|
||||
.replace("/**", SWAGGER2URL)))));
|
||||
return resources;
|
||||
}
|
||||
@@ -58,6 +58,7 @@ public class SwaggerProvider implements WebFluxConfigurer,SwaggerResourcesProvid
|
||||
|
||||
/**
|
||||
* swagger-ui 地址
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package cn.com.mfish.gateway.filter;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.HttpStatus;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.utils.AuthInfoUtils;
|
||||
import cn.com.mfish.common.core.utils.ServletUtils;
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
@@ -15,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
|
||||
import org.springframework.cloud.gateway.filter.GlobalFilter;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.server.reactive.ServerHttpRequest;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
@@ -32,7 +32,7 @@ import javax.annotation.Resource;
|
||||
public class AuthFilter implements GlobalFilter, Ordered {
|
||||
|
||||
@Resource
|
||||
private IgnoreWhiteProperties ignoreWhite;
|
||||
private IgnoreWhiteProperties ignoreWhiteProperties;
|
||||
@Resource
|
||||
private TokenValidator tokenValidator;
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||
ServerHttpRequest request = exchange.getRequest();
|
||||
String url = request.getURI().getPath();
|
||||
// 跳过不需要验证的路径
|
||||
if (StringUtils.matches(url, ignoreWhite.getWhites())) {
|
||||
if (StringUtils.matches(url, ignoreWhiteProperties.getWhites())) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
String accessToken = AuthInfoUtils.getAccessToken(request);
|
||||
@@ -50,7 +50,7 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||
}
|
||||
ServerHttpRequest.Builder mutate = request.mutate();
|
||||
// 内部请求来源参数清除
|
||||
GatewayUtils.removeHeader(mutate, CredentialConstants.REQ_ORIGIN);
|
||||
GatewayUtils.removeHeader(mutate, RPCConstants.REQ_ORIGIN);
|
||||
Result result = tokenValidator.validator(request);
|
||||
if (!result.isSuccess()) {
|
||||
return unauthorizedResponse(exchange, result.getMsg());
|
||||
@@ -71,9 +71,9 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||
* @return
|
||||
*/
|
||||
private void defaultTokenDeal(RedisAccessToken accessToken, ServerHttpRequest.Builder mutate) {
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_CLIENT_ID, accessToken.getClientId());
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_USER_ID, accessToken.getUserId());
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_ACCOUNT, accessToken.getAccount());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_CLIENT_ID, accessToken.getClientId());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_USER_ID, accessToken.getUserId());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_ACCOUNT, accessToken.getAccount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,14 +85,14 @@ public class AuthFilter implements GlobalFilter, Ordered {
|
||||
*/
|
||||
private void weChatTokenDeal(WeChatToken weChatToken, ServerHttpRequest.Builder mutate) {
|
||||
//todo 微信客户端暂时写死system,默认认为是系统客户端
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_CLIENT_ID, "system");
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_USER_ID, weChatToken.getUserId());
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_ACCOUNT, weChatToken.getAccount());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_CLIENT_ID, "system");
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_USER_ID, weChatToken.getUserId());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_ACCOUNT, weChatToken.getAccount());
|
||||
}
|
||||
|
||||
private Mono<Void> unauthorizedResponse(ServerWebExchange exchange, String msg) {
|
||||
log.error("[鉴权异常处理]请求路径:{}", exchange.getRequest().getPath());
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED);
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), msg, HttpStatus.UNAUTHORIZED.value());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CacheFilter extends AbstractGatewayFilterFactory<CacheFilter.Config
|
||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||
// GET DELETE 不过滤
|
||||
HttpMethod method = exchange.getRequest().getMethod();
|
||||
if (method == null || method.matches("GET") || method.matches("DELETE")) {
|
||||
if (method == null || method == HttpMethod.GET || method == HttpMethod.DELETE) {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
return DataBufferUtils.join(exchange.getRequest().getBody()).map(dataBuffer -> {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.gateway.filter;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.exception.CaptchaException;
|
||||
import cn.com.mfish.common.core.utils.ServletUtils;
|
||||
import cn.com.mfish.gateway.common.GatewayUtils;
|
||||
@@ -57,7 +57,7 @@ public class CheckCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
||||
return chain.filter(exchange);
|
||||
}
|
||||
ServerHttpRequest.Builder mutate = request.mutate();
|
||||
GatewayUtils.removeHeader(mutate, CredentialConstants.REQ_CHECK_CAPTCHA_EXCEPTION);
|
||||
GatewayUtils.removeHeader(mutate, RPCConstants.REQ_CHECK_CAPTCHA_EXCEPTION);
|
||||
try {
|
||||
String rspStr = resolveBodyFromRequest(request);
|
||||
Map<String, String> map = getParamMap(rspStr);
|
||||
@@ -72,7 +72,7 @@ public class CheckCodeFilter extends AbstractGatewayFilterFactory<Object> {
|
||||
} catch (CaptchaException e) {
|
||||
//如果需要自身校验,不直接返回校验结果,由网关转发到自身服务处理
|
||||
if (selfCheck != CheckStatus.无需校验) {
|
||||
GatewayUtils.addHeader(mutate, CredentialConstants.REQ_CHECK_CAPTCHA_EXCEPTION, e.getMessage());
|
||||
GatewayUtils.addHeader(mutate, RPCConstants.REQ_CHECK_CAPTCHA_EXCEPTION, e.getMessage());
|
||||
} else {
|
||||
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage());
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.com.mfish.gateway.filter;
|
||||
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
import cn.com.mfish.common.core.utils.html.EscapeUtil;
|
||||
import cn.com.mfish.common.core.utils.http.EscapeUtil;
|
||||
import cn.com.mfish.gateway.config.properties.XssProperties;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
+2
-2
@@ -2,7 +2,6 @@ package cn.com.mfish.gateway.service.impl;
|
||||
|
||||
import cn.com.mfish.common.core.constants.Constants;
|
||||
import cn.com.mfish.common.core.exception.CaptchaException;
|
||||
import cn.com.mfish.common.core.utils.Base64;
|
||||
import cn.com.mfish.common.core.utils.StringUtils;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.gateway.config.properties.CaptchaProperties;
|
||||
@@ -16,6 +15,7 @@ import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
@@ -70,7 +70,7 @@ public class CheckCodeServiceImpl implements CheckCodeService {
|
||||
return Result.fail(e.getMessage());
|
||||
}
|
||||
ajax.getData().put("captchaKey", uuid);
|
||||
ajax.getData().put("img", Base64.encode(os.toByteArray()));
|
||||
ajax.getData().put("img", Base64.getEncoder().encodeToString(os.toByteArray()));
|
||||
return ajax;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cn.com.mfish.oauth.service.impl;
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.exception.CaptchaException;
|
||||
import cn.com.mfish.common.core.web.Result;
|
||||
import cn.com.mfish.common.redis.common.RedisPrefix;
|
||||
@@ -53,7 +53,7 @@ public class LoginServiceImpl implements LoginService {
|
||||
|
||||
@Override
|
||||
public boolean postLogin(Model model, HttpServletRequest request) {
|
||||
String captchaEx = request.getHeader(CredentialConstants.REQ_CHECK_CAPTCHA_EXCEPTION);
|
||||
String captchaEx = request.getHeader(RPCConstants.REQ_CHECK_CAPTCHA_EXCEPTION);
|
||||
if (!StringUtils.isEmpty(captchaEx)) {
|
||||
model.addAttribute(SerConstant.ERROR_MSG, CaptchaException.Info.getExceptionInfo(captchaEx).toString());
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.com.mfish.test.controller;
|
||||
|
||||
|
||||
import cn.com.mfish.common.core.constants.CredentialConstants;
|
||||
import cn.com.mfish.common.core.constants.RPCConstants;
|
||||
import cn.com.mfish.common.core.enums.OperateType;
|
||||
import cn.com.mfish.common.core.enums.ReqSource;
|
||||
import cn.com.mfish.common.core.utils.AuthInfoUtils;
|
||||
@@ -33,12 +33,12 @@ public class TestController {
|
||||
@GetMapping("/user")
|
||||
public Result<UserInfo> getUserInfo(HttpServletRequest request) {
|
||||
String token = AuthInfoUtils.getAccessToken(request);
|
||||
return remoteUserService.getUserInfo(CredentialConstants.INNER, token);
|
||||
return remoteUserService.getUserInfo(RPCConstants.INNER, token);
|
||||
}
|
||||
|
||||
@GetMapping("/curUser")
|
||||
public Result<UserInfo> getCurUserInfo() {
|
||||
return remoteUserService.getUserById(CredentialConstants.INNER, "1");
|
||||
return remoteUserService.getUserById(RPCConstants.INNER, "1");
|
||||
}
|
||||
|
||||
@Log(title = "测试参数", operateType = OperateType.QUERY, reqSource = ReqSource.MANAGER)
|
||||
|
||||
Reference in New Issue
Block a user