alibaba代码规约扫描。

pull/183/head
1332987 3 years ago
parent c392e8fb16
commit 1157caddfd

@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart; import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.domain.SysFile; import com.ruoyi.system.api.domain.SysFile;
import com.ruoyi.system.api.factory.RemoteFileFallbackFactory; import com.ruoyi.system.api.factory.RemoteFileFallbackFactory;
@ -25,5 +25,5 @@ public interface RemoteFileService
* @return * @return
*/ */
@PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public R<SysFile> upload(@RequestPart(value = "file") MultipartFile file); public Rust<SysFile> upload(@RequestPart(value = "file") MultipartFile file);
} }

@ -6,7 +6,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.domain.SysLogininfor; import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog; import com.ruoyi.system.api.domain.SysOperLog;
import com.ruoyi.system.api.factory.RemoteLogFallbackFactory; import com.ruoyi.system.api.factory.RemoteLogFallbackFactory;
@ -27,7 +27,7 @@ public interface RemoteLogService
* @return * @return
*/ */
@PostMapping("/operlog") @PostMapping("/operlog")
public R<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public Rust<Boolean> saveLog(@RequestBody SysOperLog sysOperLog, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** /**
* 访 * 访
@ -37,5 +37,5 @@ public interface RemoteLogService
* @return * @return
*/ */
@PostMapping("/logininfor") @PostMapping("/logininfor")
public R<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public Rust<Boolean> saveLogininfor(@RequestBody SysLogininfor sysLogininfor, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
} }

@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestHeader;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.factory.RemoteUserFallbackFactory; import com.ruoyi.system.api.factory.RemoteUserFallbackFactory;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
@ -29,7 +29,7 @@ public interface RemoteUserService
* @return * @return
*/ */
@GetMapping("/user/info/{username}") @GetMapping("/user/info/{username}")
public R<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public Rust<LoginUser> getUserInfo(@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
/** /**
* *
@ -39,5 +39,5 @@ public interface RemoteUserService
* @return * @return
*/ */
@PostMapping("/user/register") @PostMapping("/user/register")
public R<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); public Rust<Boolean> registerUserInfo(@RequestBody SysUser sysUser, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
} }

@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.RemoteFileService; import com.ruoyi.system.api.RemoteFileService;
import com.ruoyi.system.api.domain.SysFile; import com.ruoyi.system.api.domain.SysFile;
@ -26,9 +26,9 @@ public class RemoteFileFallbackFactory implements FallbackFactory<RemoteFileServ
return new RemoteFileService() return new RemoteFileService()
{ {
@Override @Override
public R<SysFile> upload(MultipartFile file) public Rust<SysFile> upload(MultipartFile file)
{ {
return R.fail("上传文件失败:" + throwable.getMessage()); return Rust.fail("上传文件失败:" + throwable.getMessage());
} }
}; };
} }

@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.RemoteLogService; import com.ruoyi.system.api.RemoteLogService;
import com.ruoyi.system.api.domain.SysLogininfor; import com.ruoyi.system.api.domain.SysLogininfor;
import com.ruoyi.system.api.domain.SysOperLog; import com.ruoyi.system.api.domain.SysOperLog;
@ -26,13 +26,13 @@ public class RemoteLogFallbackFactory implements FallbackFactory<RemoteLogServic
return new RemoteLogService() return new RemoteLogService()
{ {
@Override @Override
public R<Boolean> saveLog(SysOperLog sysOperLog, String source) public Rust<Boolean> saveLog(SysOperLog sysOperLog, String source)
{ {
return null; return null;
} }
@Override @Override
public R<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source) public Rust<Boolean> saveLogininfor(SysLogininfor sysLogininfor, String source)
{ {
return null; return null;
} }

@ -4,7 +4,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory; import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.system.api.RemoteUserService; import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
@ -26,15 +26,15 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
return new RemoteUserService() return new RemoteUserService()
{ {
@Override @Override
public R<LoginUser> getUserInfo(String username, String source) public Rust<LoginUser> getUserInfo(String username, String source)
{ {
return R.fail("获取用户失败:" + throwable.getMessage()); return Rust.fail("获取用户失败:" + throwable.getMessage());
} }
@Override @Override
public R<Boolean> registerUserInfo(SysUser sysUser, String source) public Rust<Boolean> registerUserInfo(SysUser sysUser, String source)
{ {
return R.fail("注册用户失败:" + throwable.getMessage()); return Rust.fail("注册用户失败:" + throwable.getMessage());
} }
}; };
} }

@ -9,7 +9,7 @@ import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.auth.form.LoginBody; import com.ruoyi.auth.form.LoginBody;
import com.ruoyi.auth.form.RegisterBody; import com.ruoyi.auth.form.RegisterBody;
import com.ruoyi.auth.service.SysLoginService; import com.ruoyi.auth.service.SysLoginService;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.utils.JwtUtils; import com.ruoyi.common.core.utils.JwtUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.security.auth.AuthUtil; import com.ruoyi.common.security.auth.AuthUtil;
@ -32,16 +32,16 @@ public class TokenController
private SysLoginService sysLoginService; private SysLoginService sysLoginService;
@PostMapping("login") @PostMapping("login")
public R<?> login(@RequestBody LoginBody form) public Rust<?> login(@RequestBody LoginBody form)
{ {
// 用户登录 // 用户登录
LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword());
// 获取登录token // 获取登录token
return R.ok(tokenService.createToken(userInfo)); return Rust.ok(tokenService.createToken(userInfo));
} }
@DeleteMapping("logout") @DeleteMapping("logout")
public R<?> logout(HttpServletRequest request) public Rust<?> logout(HttpServletRequest request)
{ {
String token = SecurityUtils.getToken(request); String token = SecurityUtils.getToken(request);
if (StringUtils.isNotEmpty(token)) if (StringUtils.isNotEmpty(token))
@ -52,27 +52,27 @@ public class TokenController
// 记录用户退出日志 // 记录用户退出日志
sysLoginService.logout(username); sysLoginService.logout(username);
} }
return R.ok(); return Rust.ok();
} }
@PostMapping("refresh") @PostMapping("refresh")
public R<?> refresh(HttpServletRequest request) public Rust<?> refresh(HttpServletRequest request)
{ {
LoginUser loginUser = tokenService.getLoginUser(request); LoginUser loginUser = tokenService.getLoginUser(request);
if (StringUtils.isNotNull(loginUser)) if (StringUtils.isNotNull(loginUser))
{ {
// 刷新令牌有效期 // 刷新令牌有效期
tokenService.refreshToken(loginUser); tokenService.refreshToken(loginUser);
return R.ok(); return Rust.ok();
} }
return R.ok(); return Rust.ok();
} }
@PostMapping("register") @PostMapping("register")
public R<?> register(@RequestBody RegisterBody registerBody) public Rust<?> register(@RequestBody RegisterBody registerBody)
{ {
// 用户注册 // 用户注册
sysLoginService.register(registerBody.getUsername(), registerBody.getPassword()); sysLoginService.register(registerBody.getUsername(), registerBody.getPassword());
return R.ok(); return Rust.ok();
} }
} }

@ -5,7 +5,7 @@ import org.springframework.stereotype.Component;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.enums.UserStatus; import com.ruoyi.common.core.enums.UserStatus;
import com.ruoyi.common.core.exception.ServiceException; import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.ServletUtils; import com.ruoyi.common.core.utils.ServletUtils;
@ -58,9 +58,9 @@ public class SysLoginService
throw new ServiceException("用户名不在指定范围"); throw new ServiceException("用户名不在指定范围");
} }
// 查询用户信息 // 查询用户信息
R<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER); Rust<LoginUser> userResult = remoteUserService.getUserInfo(username, SecurityConstants.INNER);
if (R.FAIL == userResult.getCode()) if (Rust.FAIL == userResult.getCode())
{ {
throw new ServiceException(userResult.getMsg()); throw new ServiceException(userResult.getMsg());
} }
@ -122,9 +122,9 @@ public class SysLoginService
sysUser.setUserName(username); sysUser.setUserName(username);
sysUser.setNickName(username); sysUser.setNickName(username);
sysUser.setPassword(SecurityUtils.encryptPassword(password)); sysUser.setPassword(SecurityUtils.encryptPassword(password));
R<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER); Rust<?> registerResult = remoteUserService.registerUserInfo(sysUser, SecurityConstants.INNER);
if (R.FAIL == registerResult.getCode()) if (Rust.FAIL == registerResult.getCode())
{ {
throw new ServiceException(registerResult.getMsg()); throw new ServiceException(registerResult.getMsg());
} }

@ -40,7 +40,7 @@ public class SecurityContextHolder
Map<String, Object> map = THREAD_LOCAL.get(); Map<String, Object> map = THREAD_LOCAL.get();
if (map == null) if (map == null)
{ {
map = new ConcurrentHashMap<String, Object>(); map = new ConcurrentHashMap<String, Object>(2);
THREAD_LOCAL.set(map); THREAD_LOCAL.set(map);
} }
return map; return map;

@ -1,14 +1,15 @@
package com.ruoyi.common.core.domain; package com.ruoyi.common.core.domain;
import java.io.Serializable;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import java.io.Serializable;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public class R<T> implements Serializable public class Rust<T> implements Serializable
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -24,49 +25,49 @@ public class R<T> implements Serializable
private T data; private T data;
public static <T> R<T> ok() public static <T> Rust<T> ok()
{ {
return restResult(null, SUCCESS, null); return restResult(null, SUCCESS, null);
} }
public static <T> R<T> ok(T data) public static <T> Rust<T> ok(T data)
{ {
return restResult(data, SUCCESS, null); return restResult(data, SUCCESS, null);
} }
public static <T> R<T> ok(T data, String msg) public static <T> Rust<T> ok(T data, String msg)
{ {
return restResult(data, SUCCESS, msg); return restResult(data, SUCCESS, msg);
} }
public static <T> R<T> fail() public static <T> Rust<T> fail()
{ {
return restResult(null, FAIL, null); return restResult(null, FAIL, null);
} }
public static <T> R<T> fail(String msg) public static <T> Rust<T> fail(String msg)
{ {
return restResult(null, FAIL, msg); return restResult(null, FAIL, msg);
} }
public static <T> R<T> fail(T data) public static <T> Rust<T> fail(T data)
{ {
return restResult(data, FAIL, null); return restResult(data, FAIL, null);
} }
public static <T> R<T> fail(T data, String msg) public static <T> Rust<T> fail(T data, String msg)
{ {
return restResult(data, FAIL, msg); return restResult(data, FAIL, msg);
} }
public static <T> R<T> fail(int code, String msg) public static <T> Rust<T> fail(int code, String msg)
{ {
return restResult(null, code, msg); return restResult(null, code, msg);
} }
private static <T> R<T> restResult(T data, int code, String msg) private static <T> Rust<T> restResult(T data, int code, String msg)
{ {
R<T> apiResult = new R<>(); Rust<T> apiResult = new Rust<>();
apiResult.setCode(code); apiResult.setCode(code);
apiResult.setData(data); apiResult.setData(data);
apiResult.setMsg(msg); apiResult.setMsg(msg);

@ -1,12 +1,13 @@
package com.ruoyi.common.core.text; package com.ruoyi.common.core.text;
import com.ruoyi.common.core.utils.StringUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.Set; import java.util.Set;
import com.ruoyi.common.core.utils.StringUtils;
/** /**
* *
@ -907,7 +908,7 @@ public class Convert
*/ */
public static String tosbc(String input, Set<Character> notConvertSet) public static String tosbc(String input, Set<Character> notConvertSet)
{ {
char c[] = input.toCharArray(); char[] c = input.toCharArray();
for (int i = 0; i < c.length; i++) for (int i = 0; i < c.length; i++)
{ {
if (null != notConvertSet && notConvertSet.contains(c[i])) if (null != notConvertSet && notConvertSet.contains(c[i]))
@ -949,7 +950,7 @@ public class Convert
*/ */
public static String todbc(String text, Set<Character> notConvertSet) public static String todbc(String text, Set<Character> notConvertSet)
{ {
char c[] = text.toCharArray(); char[] c = text.toCharArray();
for (int i = 0; i < c.length; i++) for (int i = 0; i < c.length; i++)
{ {
if (null != notConvertSet && notConvertSet.contains(c[i])) if (null != notConvertSet && notConvertSet.contains(c[i]))

@ -1,5 +1,7 @@
package com.ruoyi.common.core.utils; package com.ruoyi.common.core.utils;
import com.ruoyi.common.core.text.Convert;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@ -7,11 +9,10 @@ import java.util.Set;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import com.ruoyi.common.core.text.Convert; /**
import com.ruoyi.common.core.utils.StringUtils; * @author pan
*/
public class ReUtil public class ReUtil {
{
public final static Pattern GROUP_VAR = Pattern.compile("\\$(\\d+)"); public final static Pattern GROUP_VAR = Pattern.compile("\\$(\\d+)");
/** /**

@ -20,7 +20,7 @@ import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.request.ServletRequestAttributes;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
@ -251,7 +251,7 @@ public class ServletUtils
*/ */
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value) public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value)
{ {
return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL); return webFluxResponseWriter(response, HttpStatus.OK, value, Rust.FAIL);
} }
/** /**
@ -295,7 +295,7 @@ public class ServletUtils
{ {
response.setStatusCode(status); response.setStatusCode(status);
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType); response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
R<?> result = R.fail(code, value.toString()); Rust<?> result = Rust.fail(code, value.toString());
DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes()); DataBuffer dataBuffer = response.bufferFactory().wrap(JSONObject.toJSONString(result).getBytes());
return response.writeWith(Mono.just(dataBuffer)); return response.writeWith(Mono.just(dataBuffer));
} }

@ -1,11 +1,12 @@
package com.ruoyi.common.core.utils; package com.ruoyi.common.core.utils;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.text.StrFormatter;
import org.springframework.util.AntPathMatcher;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.springframework.util.AntPathMatcher;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.text.StrFormatter;
/** /**
* *
@ -332,9 +333,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase) if (preCharIsUpperCase && curreCharIsUpperCase && !nexteCharIsUpperCase)
{ {
sb.append(SEPARATOR); sb.append(SEPARATOR);
} } else if (i != 0 && !preCharIsUpperCase && curreCharIsUpperCase) {
else if ((i != 0 && !preCharIsUpperCase) && curreCharIsUpperCase)
{
sb.append(SEPARATOR); sb.append(SEPARATOR);
} }
sb.append(Character.toLowerCase(c)); sb.append(Character.toLowerCase(c));

@ -1,8 +1,9 @@
package com.ruoyi.common.core.utils.file; package com.ruoyi.common.core.utils.file;
import java.io.File;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.io.File;
/** /**
* *
* *
@ -54,11 +55,11 @@ public class FileTypeUtils
public static String getFileExtendName(byte[] photoByte) public static String getFileExtendName(byte[] photoByte)
{ {
String strFileExtendName = "JPG"; String strFileExtendName = "JPG";
if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) if ((photoByte[0] == 71) && (photoByte[1] == 73) && (photoByte[2] == 70) && (photoByte[3] == 56) && (photoByte[5] == 97)) {
&& ((photoByte[4] == 55) || (photoByte[4] == 57)) && (photoByte[5] == 97)) if ((photoByte[4] == 55) || (photoByte[4] == 57)) {
{
strFileExtendName = "GIF"; strFileExtendName = "GIF";
} }
}
else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70)) else if ((photoByte[6] == 74) && (photoByte[7] == 70) && (photoByte[8] == 73) && (photoByte[9] == 70))
{ {
strFileExtendName = "JPG"; strFileExtendName = "JPG";

@ -58,7 +58,7 @@ public class EscapeUtil
*/ */
public static String clean(String content) public static String clean(String content)
{ {
return new HTMLFilter().filter(content); return new HtmlFilter().filter(content);
} }
/** /**

@ -1,10 +1,6 @@
package com.ruoyi.common.core.utils.html; package com.ruoyi.common.core.utils.html;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -15,8 +11,7 @@ import java.util.regex.Pattern;
* *
* @author ruoyi * @author ruoyi
*/ */
public final class HTMLFilter public final class HtmlFilter {
{
/** /**
* regex flag union representing /si modifiers in php * regex flag union representing /si modifiers in php
**/ **/
@ -45,7 +40,9 @@ public final class HTMLFilter
private static final Pattern P_RIGHT_ARROW = Pattern.compile(">"); private static final Pattern P_RIGHT_ARROW = Pattern.compile(">");
private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>"); private static final Pattern P_BOTH_ARROWS = Pattern.compile("<>");
// @xxx could grow large... maybe use sesat's ReferenceMap /**
* @xxx could grow large... maybe use sesat's ReferenceMap
*/
private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, Pattern> P_REMOVE_PAIR_BLANKS = new ConcurrentHashMap<>();
private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>(); private static final ConcurrentMap<String, Pattern> P_REMOVE_SELF_BLANKS = new ConcurrentHashMap<>();
@ -100,8 +97,7 @@ public final class HTMLFilter
/** /**
* Default constructor. * Default constructor.
*/ */
public HTMLFilter() public HtmlFilter() {
{
vAllowed = new HashMap<>(); vAllowed = new HashMap<>();
final ArrayList<String> aAtos = new ArrayList<>(); final ArrayList<String> aAtos = new ArrayList<>();
@ -122,13 +118,13 @@ public final class HTMLFilter
vAllowed.put("i", noAtts); vAllowed.put("i", noAtts);
vAllowed.put("em", noAtts); vAllowed.put("em", noAtts);
vSelfClosingTags = new String[] { "img" }; vSelfClosingTags = new String[]{"img"};
vNeedClosingTags = new String[] { "a", "b", "strong", "i", "em" }; vNeedClosingTags = new String[]{"a", "b", "strong", "i", "em"};
vDisallowed = new String[] {}; vDisallowed = new String[]{};
vAllowedProtocols = new String[] { "http", "mailto", "https" }; // no ftp. vAllowedProtocols = new String[]{"http", "mailto", "https"}; // no ftp.
vProtocolAtts = new String[] { "src", "href" }; vProtocolAtts = new String[]{"src", "href"};
vRemoveBlanks = new String[] { "a", "b", "strong", "i", "em" }; vRemoveBlanks = new String[]{"a", "b", "strong", "i", "em"};
vAllowedEntities = new String[] { "amp", "gt", "lt", "quot" }; vAllowedEntities = new String[]{"amp", "gt", "lt", "quot"};
stripComment = true; stripComment = true;
encodeQuotes = true; encodeQuotes = true;
alwaysMakeTags = false; alwaysMakeTags = false;
@ -140,8 +136,7 @@ public final class HTMLFilter
* @param conf map containing configuration. keys match field names. * @param conf map containing configuration. keys match field names.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public HTMLFilter(final Map<String, Object> conf) public HtmlFilter(final Map<String, Object> conf) {
{
assert conf.containsKey("vAllowed") : "configuration requires vAllowed"; assert conf.containsKey("vAllowed") : "configuration requires vAllowed";
assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags"; assert conf.containsKey("vSelfClosingTags") : "configuration requires vSelfClosingTags";
@ -165,20 +160,22 @@ public final class HTMLFilter
alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true; alwaysMakeTags = conf.containsKey("alwaysMakeTags") ? (Boolean) conf.get("alwaysMakeTags") : true;
} }
private void reset() private void reset() {
{
vTagCounts.clear(); vTagCounts.clear();
} }
// --------------------------------------------------------------- // ---------------------------------------------------------------
// my versions of some PHP library functions
public static String chr(final int decimal) /**
{ * my versions of some PHP library functions
* @param decimal /
* @return /
*/
public static String chr(final int decimal) {
return String.valueOf((char) decimal); return String.valueOf((char) decimal);
} }
public static String htmlSpecialChars(final String s) public static String htmlSpecialChars(final String s) {
{
String result = s; String result = s;
result = regexReplace(P_AMP, "&amp;", result); result = regexReplace(P_AMP, "&amp;", result);
result = regexReplace(P_QUOTE, "&quot;", result); result = regexReplace(P_QUOTE, "&quot;", result);
@ -195,8 +192,7 @@ public final class HTMLFilter
* @param input text (i.e. submitted by a user) than may contain html * @param input text (i.e. submitted by a user) than may contain html
* @return "clean" version of input, with only valid, whitelisted html elements allowed * @return "clean" version of input, with only valid, whitelisted html elements allowed
*/ */
public String filter(final String input) public String filter(final String input) {
{
reset(); reset();
String s = input; String s = input;
@ -213,22 +209,18 @@ public final class HTMLFilter
return s; return s;
} }
public boolean isAlwaysMakeTags() public boolean isAlwaysMakeTags() {
{
return alwaysMakeTags; return alwaysMakeTags;
} }
public boolean isStripComments() public boolean isStripComments() {
{
return stripComment; return stripComment;
} }
private String escapeComments(final String s) private String escapeComments(final String s) {
{
final Matcher m = P_COMMENTS.matcher(s); final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer(); final StringBuffer buf = new StringBuffer();
if (m.find()) if (m.find()) {
{
final String match = m.group(1); // (.*?) final String match = m.group(1); // (.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->")); m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
} }
@ -237,10 +229,8 @@ public final class HTMLFilter
return buf.toString(); return buf.toString();
} }
private String balancehtml(String s) private String balancehtml(String s) {
{ if (alwaysMakeTags) {
if (alwaysMakeTags)
{
// //
// try and form html // try and form html
// //
@ -249,9 +239,7 @@ public final class HTMLFilter
s = regexReplace(P_BODY_TO_END, "<$1>", s); s = regexReplace(P_BODY_TO_END, "<$1>", s);
s = regexReplace(P_XML_CONTENT, "$1<$2", s); s = regexReplace(P_XML_CONTENT, "$1<$2", s);
} } else {
else
{
// //
// escape stray brackets // escape stray brackets
// //
@ -269,13 +257,11 @@ public final class HTMLFilter
return s; return s;
} }
private String checkTags(String s) private String checkTags(String s) {
{
Matcher m = P_TAGS.matcher(s); Matcher m = P_TAGS.matcher(s);
final StringBuffer buf = new StringBuffer(); final StringBuffer buf = new StringBuffer();
while (m.find()) while (m.find()) {
{
String replaceStr = m.group(1); String replaceStr = m.group(1);
replaceStr = processTag(replaceStr); replaceStr = processTag(replaceStr);
m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr)); m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
@ -285,10 +271,8 @@ public final class HTMLFilter
// these get tallied in processTag // these get tallied in processTag
// (remember to reset before subsequent calls to filter method) // (remember to reset before subsequent calls to filter method)
final StringBuilder sBuilder = new StringBuilder(buf.toString()); final StringBuilder sBuilder = new StringBuilder(buf.toString());
for (String key : vTagCounts.keySet()) for (String key : vTagCounts.keySet()) {
{ for (int ii = 0; ii < vTagCounts.get(key); ii++) {
for (int ii = 0; ii < vTagCounts.get(key); ii++)
{
sBuilder.append("</").append(key).append(">"); sBuilder.append("</").append(key).append(">");
} }
} }
@ -297,18 +281,14 @@ public final class HTMLFilter
return s; return s;
} }
private String processRemoveBlanks(final String s) private String processRemoveBlanks(final String s) {
{
String result = s; String result = s;
for (String tag : vRemoveBlanks) for (String tag : vRemoveBlanks) {
{ if (!P_REMOVE_PAIR_BLANKS.containsKey(tag)) {
if (!P_REMOVE_PAIR_BLANKS.containsKey(tag))
{
P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">")); P_REMOVE_PAIR_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?></" + tag + ">"));
} }
result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result); result = regexReplace(P_REMOVE_PAIR_BLANKS.get(tag), "", result);
if (!P_REMOVE_SELF_BLANKS.containsKey(tag)) if (!P_REMOVE_SELF_BLANKS.containsKey(tag)) {
{
P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>")); P_REMOVE_SELF_BLANKS.putIfAbsent(tag, Pattern.compile("<" + tag + "(\\s[^>]*)?/>"));
} }
result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result); result = regexReplace(P_REMOVE_SELF_BLANKS.get(tag), "", result);
@ -317,136 +297,93 @@ public final class HTMLFilter
return result; return result;
} }
private static String regexReplace(final Pattern regexPattern, final String replacement, final String s) private static String regexReplace(final Pattern regexPattern, final String replacement, final String s) {
{
Matcher m = regexPattern.matcher(s); Matcher m = regexPattern.matcher(s);
return m.replaceAll(replacement); return m.replaceAll(replacement);
} }
private String processTag(final String s) private String processTag(final String s) {
{
// ending tags
Matcher m = P_END_TAG.matcher(s); Matcher m = P_END_TAG.matcher(s);
if (m.find()) if (m.find()) {
{
final String name = m.group(1).toLowerCase(); final String name = m.group(1).toLowerCase();
if (allowed(name)) if (allowed(name)) {
{ if (false == inArray(name, vSelfClosingTags)) {
if (false == inArray(name, vSelfClosingTags)) if (vTagCounts.containsKey(name)) {
{
if (vTagCounts.containsKey(name))
{
vTagCounts.put(name, vTagCounts.get(name) - 1); vTagCounts.put(name, vTagCounts.get(name) - 1);
return "</" + name + ">"; return "</" + name + ">";
} }
} }
} }
} }
// starting tags // starting tags
m = P_START_TAG.matcher(s); m = P_START_TAG.matcher(s);
if (m.find()) if (m.find()) {
{
final String name = m.group(1).toLowerCase(); final String name = m.group(1).toLowerCase();
final String body = m.group(2); final String body = m.group(2);
String ending = m.group(3); String ending = m.group(3);
// debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" ); // debug( "in a starting tag, name='" + name + "'; body='" + body + "'; ending='" + ending + "'" );
if (allowed(name)) if (allowed(name)) {
{
final StringBuilder params = new StringBuilder(); final StringBuilder params = new StringBuilder();
final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body); final Matcher m2 = P_QUOTED_ATTRIBUTES.matcher(body);
final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body); final Matcher m3 = P_UNQUOTED_ATTRIBUTES.matcher(body);
final List<String> paramNames = new ArrayList<>(); final List<String> paramNames = new ArrayList<>();
final List<String> paramValues = new ArrayList<>(); final List<String> paramValues = new ArrayList<>();
while (m2.find()) while (m2.find()) {
{
paramNames.add(m2.group(1)); // ([a-z0-9]+) paramNames.add(m2.group(1)); // ([a-z0-9]+)
paramValues.add(m2.group(3)); // (.*?) paramValues.add(m2.group(3)); // (.*?)
} }
while (m3.find()) while (m3.find()) {
{
paramNames.add(m3.group(1)); // ([a-z0-9]+) paramNames.add(m3.group(1)); // ([a-z0-9]+)
paramValues.add(m3.group(3)); // ([^\"\\s']+) paramValues.add(m3.group(3)); // ([^\"\\s']+)
} }
String paramName, paramValue; String paramName, paramValue;
for (int ii = 0; ii < paramNames.size(); ii++) for (int ii = 0; ii < paramNames.size(); ii++) {
{
paramName = paramNames.get(ii).toLowerCase(); paramName = paramNames.get(ii).toLowerCase();
paramValue = paramValues.get(ii); paramValue = paramValues.get(ii);
if (allowedAttribute(name, paramName)) {
// debug( "paramName='" + paramName + "'" ); if (inArray(paramName, vProtocolAtts)) {
// debug( "paramValue='" + paramValue + "'" );
// debug( "allowed? " + vAllowed.get( name ).contains( paramName ) );
if (allowedAttribute(name, paramName))
{
if (inArray(paramName, vProtocolAtts))
{
paramValue = processParamProtocol(paramValue); paramValue = processParamProtocol(paramValue);
} }
params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\""); params.append(' ').append(paramName).append("=\\\"").append(paramValue).append("\"");
} }
} }
if (inArray(name, vSelfClosingTags)) {
if (inArray(name, vSelfClosingTags))
{
ending = " /"; ending = " /";
} }
if (inArray(name, vNeedClosingTags)) {
if (inArray(name, vNeedClosingTags))
{
ending = ""; ending = "";
} }
if (ending == null || ending.length() < 1) {
if (ending == null || ending.length() < 1) if (vTagCounts.containsKey(name)) {
{
if (vTagCounts.containsKey(name))
{
vTagCounts.put(name, vTagCounts.get(name) + 1); vTagCounts.put(name, vTagCounts.get(name) + 1);
} } else {
else
{
vTagCounts.put(name, 1); vTagCounts.put(name, 1);
} }
} } else {
else
{
ending = " /"; ending = " /";
} }
return "<" + name + params + ending + ">"; return "<" + name + params + ending + ">";
} } else {
else
{
return ""; return "";
} }
} }
// comments // comments
m = P_COMMENT.matcher(s); m = P_COMMENT.matcher(s);
if (!stripComment && m.find()) if (!stripComment && m.find()) {
{
return "<" + m.group() + ">"; return "<" + m.group() + ">";
} }
return ""; return "";
} }
private String processParamProtocol(String s) private String processParamProtocol(String s) {
{
s = decodeEntities(s); s = decodeEntities(s);
final Matcher m = P_PROTOCOL.matcher(s); final Matcher m = P_PROTOCOL.matcher(s);
if (m.find()) if (m.find()) {
{
final String protocol = m.group(1); final String protocol = m.group(1);
if (!inArray(protocol, vAllowedProtocols)) if (!inArray(protocol, vAllowedProtocols)) {
{
// bad protocol, turn into local anchor link instead // bad protocol, turn into local anchor link instead
s = "#" + s.substring(protocol.length() + 1); s = "#" + s.substring(protocol.length() + 1);
if (s.startsWith("#//")) if (s.startsWith("#//")) {
{
s = "#" + s.substring(3); s = "#" + s.substring(3);
} }
} }
@ -455,13 +392,11 @@ public final class HTMLFilter
return s; return s;
} }
private String decodeEntities(String s) private String decodeEntities(String s) {
{
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
Matcher m = P_ENTITY.matcher(s); Matcher m = P_ENTITY.matcher(s);
while (m.find()) while (m.find()) {
{
final String match = m.group(1); final String match = m.group(1);
final int decimal = Integer.decode(match).intValue(); final int decimal = Integer.decode(match).intValue();
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
@ -471,8 +406,7 @@ public final class HTMLFilter
buf = new StringBuffer(); buf = new StringBuffer();
m = P_ENTITY_UNICODE.matcher(s); m = P_ENTITY_UNICODE.matcher(s);
while (m.find()) while (m.find()) {
{
final String match = m.group(1); final String match = m.group(1);
final int decimal = Integer.valueOf(match, 16).intValue(); final int decimal = Integer.valueOf(match, 16).intValue();
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
@ -482,8 +416,7 @@ public final class HTMLFilter
buf = new StringBuffer(); buf = new StringBuffer();
m = P_ENCODE.matcher(s); m = P_ENCODE.matcher(s);
while (m.find()) while (m.find()) {
{
final String match = m.group(1); final String match = m.group(1);
final int decimal = Integer.valueOf(match, 16).intValue(); final int decimal = Integer.valueOf(match, 16).intValue();
m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal))); m.appendReplacement(buf, Matcher.quoteReplacement(chr(decimal)));
@ -495,14 +428,12 @@ public final class HTMLFilter
return s; return s;
} }
private String validateEntities(final String s) private String validateEntities(final String s) {
{
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
// validate entities throughout the string // validate entities throughout the string
Matcher m = P_VALID_ENTITIES.matcher(s); Matcher m = P_VALID_ENTITIES.matcher(s);
while (m.find()) while (m.find()) {
{
final String one = m.group(1); // ([^&;]*) final String one = m.group(1); // ([^&;]*)
final String two = m.group(2); // (?=(;|&|$)) final String two = m.group(2); // (?=(;|&|$))
m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two))); m.appendReplacement(buf, Matcher.quoteReplacement(checkEntity(one, two)));
@ -512,14 +443,11 @@ public final class HTMLFilter
return encodeQuotes(buf.toString()); return encodeQuotes(buf.toString());
} }
private String encodeQuotes(final String s) private String encodeQuotes(final String s) {
{ if (encodeQuotes) {
if (encodeQuotes)
{
StringBuffer buf = new StringBuffer(); StringBuffer buf = new StringBuffer();
Matcher m = P_VALID_QUOTES.matcher(s); Matcher m = P_VALID_QUOTES.matcher(s);
while (m.find()) while (m.find()) {
{
final String one = m.group(1); // (>|^) final String one = m.group(1); // (>|^)
final String two = m.group(2); // ([^<]+?) final String two = m.group(2); // ([^<]+?)
final String three = m.group(3); // (<|$) final String three = m.group(3); // (<|$)
@ -528,43 +456,34 @@ public final class HTMLFilter
} }
m.appendTail(buf); m.appendTail(buf);
return buf.toString(); return buf.toString();
} } else {
else
{
return s; return s;
} }
} }
private String checkEntity(final String preamble, final String term) private String checkEntity(final String preamble, final String term) {
{
return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&amp;" + preamble; return ";".equals(term) && isValidEntity(preamble) ? '&' + preamble : "&amp;" + preamble;
} }
private boolean isValidEntity(final String entity) private boolean isValidEntity(final String entity) {
{
return inArray(entity, vAllowedEntities); return inArray(entity, vAllowedEntities);
} }
private static boolean inArray(final String s, final String[] array) private static boolean inArray(final String s, final String[] array) {
{ for (String item : array) {
for (String item : array) if (item != null && item.equals(s)) {
{
if (item != null && item.equals(s))
{
return true; return true;
} }
} }
return false; return false;
} }
private boolean allowed(final String name) private boolean allowed(final String name) {
{
return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed); return (vAllowed.isEmpty() || vAllowed.containsKey(name)) && !inArray(name, vDisallowed);
} }
private boolean allowedAttribute(final String name, final String paramName) private boolean allowedAttribute(final String name, final String paramName) {
{
return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName)); return allowed(name) && (vAllowed.isEmpty() || vAllowed.get(name).contains(paramName));
} }
} }

@ -68,24 +68,24 @@ public class IpUtils {
final byte b0 = addr[0]; final byte b0 = addr[0];
final byte b1 = addr[1]; final byte b1 = addr[1];
// 10.x.x.x/8 // 10.x.x.x/8
final byte SECTION1 = 0x0A; final byte section1 = 0x0A;
// 172.16.x.x/12 // 172.16.x.x/12
final byte SECTION2 = (byte) 0xAC; final byte section2 = (byte) 0xAC;
final byte SECTION3 = (byte) 0x10; final byte section3 = (byte) 0x10;
final byte SECTION4 = (byte) 0x1F; final byte section4 = (byte) 0x1F;
// 192.168.x.x/16 // 192.168.x.x/16
final byte SECTION5 = (byte) 0xC0; final byte section5 = (byte) 0xC0;
final byte SECTION6 = (byte) 0xA8; final byte section6 = (byte) 0xA8;
switch (b0) { switch (b0) {
case SECTION1: case section1:
return true; return true;
case SECTION2: case section2:
if (b1 >= SECTION3 && b1 <= SECTION4) { if (b1 >= section3 && b1 <= section4) {
return true; return true;
} }
case SECTION5: case section5:
switch (b1) { switch (b1) {
case SECTION6: { case section6: {
return true; return true;
} }
default:{ default:{

@ -1,19 +1,15 @@
package com.ruoyi.common.core.utils.reflect; package com.ruoyi.common.core.utils.reflect;
import java.lang.reflect.Field; import com.ruoyi.common.core.text.Convert;
import java.lang.reflect.InvocationTargetException; import com.ruoyi.common.core.utils.DateUtils;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.utils.DateUtils; import java.lang.reflect.*;
import java.util.Date;
/** /**
* . getter/setter, 访, , Class, AOP. * . getter/setter, 访, , Class, AOP.
@ -102,7 +98,6 @@ public class ReflectUtils
Field field = getAccessibleField(obj, fieldName); Field field = getAccessibleField(obj, fieldName);
if (field == null) if (field == null)
{ {
// throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
return; return;
} }
@ -312,24 +307,25 @@ public class ReflectUtils
*/ */
public static void makeAccessible(Method method) public static void makeAccessible(Method method)
{ {
if ((!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) if (!method.isAccessible()) {
&& !method.isAccessible()) if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers())) {
{
method.setAccessible(true); method.setAccessible(true);
} }
} }
}
/** /**
* private/protectedpublicJDKSecurityManager * private/protectedpublicJDKSecurityManager
*/ */
public static void makeAccessible(Field field) public static void makeAccessible(Field field)
{ {
if ((!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers()) if (!field.isAccessible()) {
|| Modifier.isFinal(field.getModifiers())) && !field.isAccessible()) if (!Modifier.isPublic(field.getModifiers()) || !Modifier.isPublic(field.getDeclaringClass().getModifiers())
{ || Modifier.isFinal(field.getModifiers())) {
field.setAccessible(true); field.setAccessible(true);
} }
} }
}
/** /**
* , Class, * , Class,

@ -5,8 +5,7 @@ package com.ruoyi.common.core.utils.sign;
* *
* @author ruoyi * @author ruoyi
*/ */
public final class Base64 public final class Base64 {
{
static private final int BASELENGTH = 128; static private final int BASELENGTH = 128;
static private final int LOOKUPLENGTH = 64; static private final int LOOKUPLENGTH = 64;
static private final int TWENTYFOURBITGROUP = 24; static private final int TWENTYFOURBITGROUP = 24;
@ -18,59 +17,48 @@ public final class Base64
static final private byte[] BASE_64_ALPHABET = new byte[BASELENGTH]; static final private byte[] BASE_64_ALPHABET = new byte[BASELENGTH];
static final private char[] LOOK_UP_BASE_64_ALPHABET = new char[LOOKUPLENGTH]; static final private char[] LOOK_UP_BASE_64_ALPHABET = new char[LOOKUPLENGTH];
static static {
{ for (int i = 0; i < BASELENGTH; ++i) {
for (int i = 0; i < BASELENGTH; ++i)
{
BASE_64_ALPHABET[i] = -1; BASE_64_ALPHABET[i] = -1;
} }
for (int i = 'Z'; i >= 'A'; i--) for (int i = 'Z'; i >= 'A'; i--) {
{
BASE_64_ALPHABET[i] = (byte) (i - 'A'); BASE_64_ALPHABET[i] = (byte) (i - 'A');
} }
for (int i = 'z'; i >= 'a'; i--) for (int i = 'z'; i >= 'a'; i--) {
{
BASE_64_ALPHABET[i] = (byte) (i - 'a' + 26); BASE_64_ALPHABET[i] = (byte) (i - 'a' + 26);
} }
for (int i = '9'; i >= '0'; i--) for (int i = '9'; i >= '0'; i--) {
{
BASE_64_ALPHABET[i] = (byte) (i - '0' + 52); BASE_64_ALPHABET[i] = (byte) (i - '0' + 52);
} }
BASE_64_ALPHABET['+'] = 62; BASE_64_ALPHABET['+'] = 62;
BASE_64_ALPHABET['/'] = 63; BASE_64_ALPHABET['/'] = 63;
for (int i = 0; i <= 25; i++) for (int i = 0; i <= 25; i++) {
{
LOOK_UP_BASE_64_ALPHABET[i] = (char) ('A' + i); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('A' + i);
} }
for (int i = 26, j = 0; i <= 51; i++, j++) for (int i = 26, j = 0; i <= 51; i++, j++) {
{
LOOK_UP_BASE_64_ALPHABET[i] = (char) ('a' + j); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('a' + j);
} }
for (int i = 52, j = 0; i <= 61; i++, j++) for (int i = 52, j = 0; i <= 61; i++, j++) {
{
LOOK_UP_BASE_64_ALPHABET[i] = (char) ('0' + j); LOOK_UP_BASE_64_ALPHABET[i] = (char) ('0' + j);
} }
LOOK_UP_BASE_64_ALPHABET[62] = (char) '+'; LOOK_UP_BASE_64_ALPHABET[62] = (char) '+';
LOOK_UP_BASE_64_ALPHABET[63] = (char) '/'; LOOK_UP_BASE_64_ALPHABET[63] = (char) '/';
} }
private static boolean isWhiteSpace(char octect) private static boolean isWhiteSpace(char octect) {
{
return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9);
} }
private static boolean isPad(char octect) private static boolean isPad(char octect) {
{
return (octect == PAD); return (octect == PAD);
} }
private static boolean isData(char octect) private static boolean isData(char octect) {
{
return (octect < BASELENGTH && BASE_64_ALPHABET[octect] != -1); return (octect < BASELENGTH && BASE_64_ALPHABET[octect] != -1);
} }
@ -80,23 +68,20 @@ public final class Base64
* @param binaryData Array containing binaryData * @param binaryData Array containing binaryData
* @return Encoded Base64 array * @return Encoded Base64 array
*/ */
public static String encode(byte[] binaryData) public static String encode(byte[] binaryData) {
{ if (binaryData == null) {
if (binaryData == null)
{
return null; return null;
} }
int lengthDataBits = binaryData.length * EIGHTBIT; int lengthDataBits = binaryData.length * EIGHTBIT;
if (lengthDataBits == 0) if (lengthDataBits == 0) {
{
return ""; return "";
} }
int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP; int fewerThan24bits = lengthDataBits % TWENTYFOURBITGROUP;
int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP; int numberTriplets = lengthDataBits / TWENTYFOURBITGROUP;
int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets; int numberQuartet = fewerThan24bits != 0 ? numberTriplets + 1 : numberTriplets;
char encodedData[] = null; char[] encodedData = null;
encodedData = new char[numberQuartet * 4]; encodedData = new char[numberQuartet * 4];
@ -105,8 +90,7 @@ public final class Base64
int encodedIndex = 0; int encodedIndex = 0;
int dataIndex = 0; int dataIndex = 0;
for (int i = 0; i < numberTriplets; i++) for (int i = 0; i < numberTriplets; i++) {
{
b1 = binaryData[dataIndex++]; b1 = binaryData[dataIndex++];
b2 = binaryData[dataIndex++]; b2 = binaryData[dataIndex++];
b3 = binaryData[dataIndex++]; b3 = binaryData[dataIndex++];
@ -125,8 +109,7 @@ public final class Base64
} }
// form integral number of 6-bit groups // form integral number of 6-bit groups
if (fewerThan24bits == EIGHTBIT) if (fewerThan24bits == EIGHTBIT) {
{
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
k = (byte) (b1 & 0x03); k = (byte) (b1 & 0x03);
byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0); byte val1 = ((b1 & SIGN) == 0) ? (byte) (b1 >> 2) : (byte) ((b1) >> 2 ^ 0xc0);
@ -134,9 +117,7 @@ public final class Base64
encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[k << 4]; encodedData[encodedIndex++] = LOOK_UP_BASE_64_ALPHABET[k << 4];
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
encodedData[encodedIndex++] = PAD; encodedData[encodedIndex++] = PAD;
} } else if (fewerThan24bits == SIXTEENBIT) {
else if (fewerThan24bits == SIXTEENBIT)
{
b1 = binaryData[dataIndex]; b1 = binaryData[dataIndex];
b2 = binaryData[dataIndex + 1]; b2 = binaryData[dataIndex + 1];
l = (byte) (b2 & 0x0f); l = (byte) (b2 & 0x0f);
@ -159,71 +140,48 @@ public final class Base64
* @param encoded string containing Base64 data * @param encoded string containing Base64 data
* @return Array containind decoded data. * @return Array containind decoded data.
*/ */
public static byte[] decode(String encoded) public static byte[] decode(String encoded) {
{ if (encoded == null) {
if (encoded == null)
{
return null; return null;
} }
char[] base64Data = encoded.toCharArray(); char[] base64Data = encoded.toCharArray();
// remove white spaces int len = removeWhiteSpace(base64Data);// 删除空格
int len = removeWhiteSpace(base64Data); if (len % FOURBYTE != 0) {
return null;// sho应该能被四整除
if (len % FOURBYTE != 0)
{
return null;// should be divisible by four
} }
int numberQuadruple = (len / FOURBYTE); int numberQuadruple = (len / FOURBYTE);
if (numberQuadruple == 0) {
if (numberQuadruple == 0)
{
return new byte[0]; return new byte[0];
} }
byte[] decodedData = null;
byte decodedData[] = null;
byte b1 = 0, b2 = 0, b3 = 0, b4 = 0; byte b1 = 0, b2 = 0, b3 = 0, b4 = 0;
char d1 = 0, d2 = 0, d3 = 0, d4 = 0; char d1 = 0, d2 = 0, d3 = 0, d4 = 0;
int i = 0; int i = 0;
int encodedIndex = 0; int encodedIndex = 0;
int dataIndex = 0; int dataIndex = 0;
decodedData = new byte[(numberQuadruple) * 3]; decodedData = new byte[(numberQuadruple) * 3];
for (; i < numberQuadruple - 1; i++) {
for (; i < numberQuadruple - 1; i++)
{
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])) if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))
|| !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) || !isData((d3 = base64Data[dataIndex++])) || !isData((d4 = base64Data[dataIndex++]))) {
{
return null; return null;
} // if found "no data" just return null } // if found "no data" just return null
b1 = BASE_64_ALPHABET[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = BASE_64_ALPHABET[d2]; b2 = BASE_64_ALPHABET[d2];
b3 = BASE_64_ALPHABET[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = BASE_64_ALPHABET[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
} }
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++]))) {
if (!isData((d1 = base64Data[dataIndex++])) || !isData((d2 = base64Data[dataIndex++])))
{
return null;// if found "no data" just return null return null;// if found "no data" just return null
} }
b1 = BASE_64_ALPHABET[d1]; b1 = BASE_64_ALPHABET[d1];
b2 = BASE_64_ALPHABET[d2]; b2 = BASE_64_ALPHABET[d2];
d3 = base64Data[dataIndex++]; d3 = base64Data[dataIndex++];
d4 = base64Data[dataIndex++]; d4 = base64Data[dataIndex++];
if (!isData((d3)) || !isData((d4))) if (!isData((d3)) || !isData((d4))) {// Check if they are PAD characters
{// Check if they are PAD characters if (isPad(d3) && isPad(d4)) {
if (isPad(d3) && isPad(d4))
{
if ((b2 & 0xf) != 0)// last 4 bits should be zero if ((b2 & 0xf) != 0)// last 4 bits should be zero
{ {
return null; return null;
@ -232,9 +190,7 @@ public final class Base64
System.arraycopy(decodedData, 0, tmp, 0, i * 3); System.arraycopy(decodedData, 0, tmp, 0, i * 3);
tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4); tmp[encodedIndex] = (byte) (b1 << 2 | b2 >> 4);
return tmp; return tmp;
} } else if (!isPad(d3) && isPad(d4)) {
else if (!isPad(d3) && isPad(d4))
{
b3 = BASE_64_ALPHABET[d3]; b3 = BASE_64_ALPHABET[d3];
if ((b3 & 0x3) != 0)// last 2 bits should be zero if ((b3 & 0x3) != 0)// last 2 bits should be zero
{ {
@ -245,20 +201,15 @@ public final class Base64
tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); tmp[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); tmp[encodedIndex] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
return tmp; return tmp;
} } else {
else
{
return null; return null;
} }
} } else { // No PAD e.g 3cQl
else
{ // No PAD e.g 3cQl
b3 = BASE_64_ALPHABET[d3]; b3 = BASE_64_ALPHABET[d3];
b4 = BASE_64_ALPHABET[d4]; b4 = BASE_64_ALPHABET[d4];
decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4); decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf)); decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
decodedData[encodedIndex++] = (byte) (b3 << 6 | b4); decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);
} }
return decodedData; return decodedData;
} }
@ -269,20 +220,16 @@ public final class Base64
* @param data the byte array of base64 data (with WS) * @param data the byte array of base64 data (with WS)
* @return the new length * @return the new length
*/ */
private static int removeWhiteSpace(char[] data) private static int removeWhiteSpace(char[] data) {
{ if (data == null) {
if (data == null)
{
return 0; return 0;
} }
// count characters that's not whitespace // count characters that's not whitespace
int newSize = 0; int newSize = 0;
int len = data.length; int len = data.length;
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++) {
{ if (!isWhiteSpace(data[i])) {
if (!isWhiteSpace(data[i]))
{
data[newSize++] = data[i]; data[newSize++] = data[i];
} }
} }

@ -12,9 +12,9 @@ public class IdUtils
* *
* @return UUID * @return UUID
*/ */
public static String randomUUID() public static String randomuuid()
{ {
return UUID.randomUUID().toString(); return UUID.randomuuid().toString();
} }
/** /**
@ -22,9 +22,9 @@ public class IdUtils
* *
* @return UUID线 * @return UUID线
*/ */
public static String simpleUUID() public static String simpleuuid()
{ {
return UUID.randomUUID().toString(true); return UUID.randomuuid().toString(true);
} }
/** /**
@ -32,9 +32,9 @@ public class IdUtils
* *
* @return UUID * @return UUID
*/ */
public static String fastUUID() public static String fastuuid()
{ {
return UUID.fastUUID().toString(); return UUID.fastuuid().toString();
} }
/** /**
@ -42,8 +42,8 @@ public class IdUtils
* *
* @return UUID线 * @return UUID线
*/ */
public static String fastSimpleUUID() public static String fastsimpleuuid()
{ {
return UUID.fastUUID().toString(true); return UUID.fastuuid().toString(true);
} }
} }

@ -9,19 +9,29 @@ import com.ruoyi.common.core.utils.StringUtils;
*/ */
public class Seq public class Seq
{ {
// 通用序列类型 /**
*
*/
public static final String COMM_SEQ_TYPE = "COMMON"; public static final String COMM_SEQ_TYPE = "COMMON";
// 上传序列类型 /**
*
*/
public static final String UPLOAD_SEQ_TYPE = "UPLOAD"; public static final String UPLOAD_SEQ_TYPE = "UPLOAD";
// 通用接口序列数 /**
*
*/
private static AtomicInteger commSeq = new AtomicInteger(1); private static AtomicInteger commSeq = new AtomicInteger(1);
// 上传接口序列数 /**
*
*/
private static AtomicInteger uploadSeq = new AtomicInteger(1); private static AtomicInteger uploadSeq = new AtomicInteger(1);
// 机器标识 /**
*
*/
private static String machineCode = "A"; private static String machineCode = "A";
/** /**

@ -1,11 +1,12 @@
package com.ruoyi.common.core.utils.uuid; package com.ruoyi.common.core.utils.uuid;
import com.ruoyi.common.core.exception.UtilException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.util.Random; import java.util.Random;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import com.ruoyi.common.core.exception.UtilException;
/** /**
* universally unique identifierUUID * universally unique identifierUUID
@ -70,9 +71,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* *
* @return {@code UUID} * @return {@code UUID}
*/ */
public static UUID fastUUID() public static UUID fastuuid()
{ {
return randomUUID(false); return randomuuid(false);
} }
/** /**
@ -80,9 +81,9 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* *
* @return {@code UUID} * @return {@code UUID}
*/ */
public static UUID randomUUID() public static UUID randomuuid()
{ {
return randomUUID(true); return randomuuid(true);
} }
/** /**
@ -91,7 +92,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* @param isSecure 使{@link SecureRandom} * @param isSecure 使{@link SecureRandom}
* @return {@code UUID} * @return {@code UUID}
*/ */
public static UUID randomUUID(boolean isSecure) public static UUID randomuuid(boolean isSecure)
{ {
final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom(); final Random ng = isSecure ? Holder.NUMBER_GENERATOR : getRandom();
@ -111,7 +112,7 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
* *
* @return {@code UUID} * @return {@code UUID}
*/ */
public static UUID nameUUIDFromBytes(byte[] name) public static UUID nameUuidFromBytes(byte[] name)
{ {
MessageDigest md; MessageDigest md;
try try
@ -147,7 +148,10 @@ public final class UUID implements java.io.Serializable, Comparable<UUID>
} }
for (int i = 0; i < 5; i++) for (int i = 0; i < 5; i++)
{ {
components[i] = "0x" + components[i]; StringBuilder sb = new StringBuilder();
sb.append(sb);
sb.append(components[i]);
components[i] = sb.toString();
} }
long mostSigBits = Long.decode(components[0]).longValue(); long mostSigBits = Long.decode(components[0]).longValue();

@ -1,10 +1,11 @@
package com.ruoyi.common.core.web.domain; package com.ruoyi.common.core.web.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.annotation.JsonFormat;
/** /**
* Entity * Entity
@ -102,7 +103,7 @@ public class BaseEntity implements Serializable
{ {
if (params == null) if (params == null)
{ {
params = new HashMap<>(); params = new HashMap<>(2);
} }
return params; return params;
} }

@ -1,18 +1,17 @@
package com.ruoyi.common.security.annotation; package com.ruoyi.common.security.annotation;
import java.lang.annotation.Documented; import com.ruoyi.common.security.config.ApplicationConfig;
import java.lang.annotation.ElementType; import com.ruoyi.common.security.feign.FeignAutoConfiguration;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.mybatis.spring.annotation.MapperScan; import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.annotation.EnableAsync;
import com.ruoyi.common.security.config.ApplicationConfig;
import com.ruoyi.common.security.feign.FeignAutoConfiguration;
import java.lang.annotation.*;
/**
* @author pan
*/
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented

@ -33,10 +33,11 @@ public class InnerAuthAspect implements Ordered
String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID); String userid = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USER_ID);
String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME); String username = ServletUtils.getRequest().getHeader(SecurityConstants.DETAILS_USERNAME);
// 用户信息验证 // 用户信息验证
if (innerAuth.isUser() && (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username))) if (innerAuth.isUser()) {
{ if (StringUtils.isEmpty(userid) || StringUtils.isEmpty(username)) {
throw new InnerAuthException("没有设置用户信息,不允许访问 "); throw new InnerAuthException("没有设置用户信息,不允许访问 ");
} }
}
return point.proceed(); return point.proceed();
} }

@ -1,11 +1,5 @@
package com.ruoyi.common.security.service; package com.ruoyi.common.security.service;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.common.core.constant.CacheConstants; import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.utils.JwtUtils; import com.ruoyi.common.core.utils.JwtUtils;
@ -16,6 +10,13 @@ import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/** /**
* token * token
@ -43,7 +44,7 @@ public class TokenService
*/ */
public Map<String, Object> createToken(LoginUser loginUser) public Map<String, Object> createToken(LoginUser loginUser)
{ {
String token = IdUtils.fastUUID(); String token = IdUtils.fastuuid();
Long userId = loginUser.getSysUser().getUserId(); Long userId = loginUser.getSysUser().getUserId();
String userName = loginUser.getSysUser().getUserName(); String userName = loginUser.getSysUser().getUserName();
loginUser.setToken(token); loginUser.setToken(token);
@ -53,13 +54,13 @@ public class TokenService
refreshToken(loginUser); refreshToken(loginUser);
// Jwt存储信息 // Jwt存储信息
Map<String, Object> claimsMap = new HashMap<String, Object>(); Map<String, Object> claimsMap = new HashMap<String, Object>(2);
claimsMap.put(SecurityConstants.USER_KEY, token); claimsMap.put(SecurityConstants.USER_KEY, token);
claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId);
claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName);
// 接口返回信息 // 接口返回信息
Map<String, Object> rspMap = new HashMap<String, Object>(); Map<String, Object> rspMap = new HashMap<String, Object>(2);
rspMap.put("access_token", JwtUtils.createToken(claimsMap)); rspMap.put("access_token", JwtUtils.createToken(claimsMap));
rspMap.put("expires_in", EXPIRE_TIME); rspMap.put("expires_in", EXPIRE_TIME);
return rspMap; return rspMap;

@ -1,14 +1,13 @@
package com.ruoyi.common.swagger.annotation; package com.ruoyi.common.swagger.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.Import;
import com.ruoyi.common.swagger.config.SwaggerAutoConfiguration; import com.ruoyi.common.swagger.config.SwaggerAutoConfiguration;
import org.springframework.context.annotation.Import;
import java.lang.annotation.*;
/**
* @author pan
*/
@Target({ ElementType.TYPE }) @Target({ ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented

@ -1,9 +1,5 @@
package com.ruoyi.common.swagger.config; package com.ruoyi.common.swagger.config;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ -12,24 +8,26 @@ import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.*;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.AuthorizationScope;
import springfox.documentation.service.Contact;
import springfox.documentation.service.SecurityReference;
import springfox.documentation.service.SecurityScheme;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spi.service.contexts.SecurityContext; import springfox.documentation.spi.service.contexts.SecurityContext;
import springfox.documentation.spring.web.plugins.ApiSelectorBuilder; import springfox.documentation.spring.web.plugins.ApiSelectorBuilder;
import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2; import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
/**
* @author pan
*/
@Configuration @Configuration
@EnableSwagger2 @EnableSwagger2
@EnableAutoConfiguration @EnableAutoConfiguration
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true) @ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
public class SwaggerAutoConfiguration public class SwaggerAutoConfiguration{
{
/** /**
* Spring Boot * Spring Boot
*/ */

@ -1,10 +1,14 @@
package com.ruoyi.common.swagger.config; package com.ruoyi.common.swagger.config;
import java.util.ArrayList;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @author pan
*/
@Component @Component
@ConfigurationProperties("swagger") @ConfigurationProperties("swagger")
public class SwaggerProperties public class SwaggerProperties

@ -1,8 +1,9 @@
package com.ruoyi.gateway.config; package com.ruoyi.gateway.config;
import java.util.Random;
import com.google.code.kaptcha.text.impl.DefaultTextCreator; import com.google.code.kaptcha.text.impl.DefaultTextCreator;
import java.util.Random;
/** /**
* *
* *
@ -30,7 +31,7 @@ public class KaptchaTextCreator extends DefaultTextCreator
} }
else if (randomoperands == 1) else if (randomoperands == 1)
{ {
if (!(x == 0) && y % x == 0) if ((x != 0) && y % x == 0)
{ {
result = y / x; result = y / x;
suChinese.append(CNUMBERS[y]); suChinese.append(CNUMBERS[y]);

@ -31,7 +31,9 @@ public class AuthFilter implements GlobalFilter, Ordered
{ {
private static final Logger log = LoggerFactory.getLogger(AuthFilter.class); private static final Logger log = LoggerFactory.getLogger(AuthFilter.class);
// 排除过滤的 uri 地址nacos自行添加 /**
* uri nacos
*/
@Autowired @Autowired
private IgnoreWhiteProperties ignoreWhite; private IgnoreWhiteProperties ignoreWhite;

@ -1,16 +1,15 @@
package com.ruoyi.gateway.filter; package com.ruoyi.gateway.filter;
import java.nio.charset.StandardCharsets; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.html.EscapeUtil;
import com.ruoyi.gateway.config.properties.XssProperties;
import io.netty.buffer.ByteBufAllocator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.gateway.filter.GatewayFilterChain; import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter; import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.*;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
import org.springframework.core.io.buffer.NettyDataBufferFactory;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -18,13 +17,11 @@ import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.http.server.reactive.ServerHttpRequestDecorator;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.ServerWebExchange;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.html.EscapeUtil;
import com.ruoyi.gateway.config.properties.XssProperties;
import io.netty.buffer.ByteBufAllocator;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import java.nio.charset.StandardCharsets;
/** /**
* *
* *
@ -34,7 +31,9 @@ import reactor.core.publisher.Mono;
@ConditionalOnProperty(value = "security.xss.enabled", havingValue = "true") @ConditionalOnProperty(value = "security.xss.enabled", havingValue = "true")
public class XssFilter implements GlobalFilter, Ordered public class XssFilter implements GlobalFilter, Ordered
{ {
// 跨站脚本的 xss 配置nacos自行添加 /**
* xss nacos
*/
@Autowired @Autowired
private XssProperties xss; private XssProperties xss;

@ -1,6 +1,5 @@
package com.ruoyi.gateway.handler; package com.ruoyi.gateway.handler;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -8,16 +7,16 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono; import reactor.core.publisher.Mono;
import springfox.documentation.swagger.web.SecurityConfiguration; import springfox.documentation.swagger.web.*;
import springfox.documentation.swagger.web.SecurityConfigurationBuilder;
import springfox.documentation.swagger.web.SwaggerResourcesProvider; import java.util.Optional;
import springfox.documentation.swagger.web.UiConfiguration;
import springfox.documentation.swagger.web.UiConfigurationBuilder;
/**
* @author pan
*/
@RestController @RestController
@RequestMapping("/swagger-resources") @RequestMapping("/swagger-resources")
public class SwaggerHandler public class SwaggerHandler {
{
@Autowired(required = false) @Autowired(required = false)
private SecurityConfiguration securityConfiguration; private SecurityConfiguration securityConfiguration;

@ -54,7 +54,7 @@ public class ValidateCodeServiceImpl implements ValidateCodeService
} }
// 保存验证码信息 // 保存验证码信息
String uuid = IdUtils.simpleUUID(); String uuid = IdUtils.simpleuuid();
String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid; String verifyKey = Constants.CAPTCHA_CODE_KEY + uuid;
String capStr = null, code = null; String capStr = null, code = null;

@ -6,7 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.utils.file.FileUtils; import com.ruoyi.common.core.utils.file.FileUtils;
import com.ruoyi.file.service.ISysFileService; import com.ruoyi.file.service.ISysFileService;
import com.ruoyi.system.api.domain.SysFile; import com.ruoyi.system.api.domain.SysFile;
@ -28,7 +28,7 @@ public class SysFileController
* *
*/ */
@PostMapping("upload") @PostMapping("upload")
public R<SysFile> upload(MultipartFile file) public Rust<SysFile> upload(MultipartFile file)
{ {
try try
{ {
@ -37,12 +37,12 @@ public class SysFileController
SysFile sysFile = new SysFile(); SysFile sysFile = new SysFile();
sysFile.setName(FileUtils.getName(url)); sysFile.setName(FileUtils.getName(url));
sysFile.setUrl(url); sysFile.setUrl(url);
return R.ok(sysFile); return Rust.ok(sysFile);
} }
catch (Exception e) catch (Exception e)
{ {
log.error("上传文件失败", e); log.error("上传文件失败", e);
return R.fail(e.getMessage()); return Rust.fail(e.getMessage());
} }
} }
} }

@ -1,21 +1,5 @@
package com.ruoyi.gen.controller; package com.ruoyi.gen.controller;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
@ -27,6 +11,16 @@ import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import com.ruoyi.gen.service.IGenTableColumnService; import com.ruoyi.gen.service.IGenTableColumnService;
import com.ruoyi.gen.service.IGenTableService; import com.ruoyi.gen.service.IGenTableService;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* *
@ -65,7 +59,7 @@ public class GenController extends BaseController
GenTable table = genTableService.selectGenTableById(tableId); GenTable table = genTableService.selectGenTableById(tableId);
List<GenTable> tables = genTableService.selectGenTableAll(); List<GenTable> tables = genTableService.selectGenTableAll();
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
Map<String, Object> map = new HashMap<String, Object>(); Map<String, Object> map = new HashMap<String, Object>(2);
map.put("info", table); map.put("info", table);
map.put("rows", list); map.put("rows", list);
map.put("tables", tables); map.put("tables", tables);

@ -1,26 +1,5 @@
package com.ruoyi.gen.service; package com.ruoyi.gen.service;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
@ -36,6 +15,28 @@ import com.ruoyi.gen.mapper.GenTableMapper;
import com.ruoyi.gen.util.GenUtils; import com.ruoyi.gen.util.GenUtils;
import com.ruoyi.gen.util.VelocityInitializer; import com.ruoyi.gen.util.VelocityInitializer;
import com.ruoyi.gen.util.VelocityUtils; import com.ruoyi.gen.util.VelocityUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* *
@ -308,14 +309,15 @@ public class GenTableServiceImpl implements IGenTableService
column.setDictType(prevColumn.getDictType()); column.setDictType(prevColumn.getDictType());
column.setQueryType(prevColumn.getQueryType()); column.setQueryType(prevColumn.getQueryType());
} }
if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk()) {
&& (column.isInsert() || column.isEdit()) if (column.isInsert() || column.isEdit()) {
&& ((column.isUsableColumn()) || (!column.isSuperColumn()))) if (column.isUsableColumn() || (!column.isSuperColumn())) {
{
// 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项 // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
column.setIsRequired(prevColumn.getIsRequired()); column.setIsRequired(prevColumn.getIsRequired());
column.setHtmlType(prevColumn.getHtmlType()); column.setHtmlType(prevColumn.getHtmlType());
} }
}
}
genTableColumnMapper.updateGenTableColumn(column); genTableColumnMapper.updateGenTableColumn(column);
} }
else else

@ -1,25 +1,24 @@
package com.ruoyi.gen.util; package com.ruoyi.gen.util;
import java.util.Arrays;
import org.apache.commons.lang3.RegExUtils;
import com.ruoyi.common.core.constant.GenConstants; import com.ruoyi.common.core.constant.GenConstants;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.gen.config.GenConfig; import com.ruoyi.gen.config.GenConfig;
import com.ruoyi.gen.domain.GenTable; import com.ruoyi.gen.domain.GenTable;
import com.ruoyi.gen.domain.GenTableColumn; import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.commons.lang3.RegExUtils;
import java.util.Arrays;
/** /**
* *
* *
* @author ruoyi * @author ruoyi
*/ */
public class GenUtils public class GenUtils {
{
/** /**
* *
*/ */
public static void initTable(GenTable genTable, String operName) public static void initTable(GenTable genTable, String operName) {
{
genTable.setClassName(convertClassName(genTable.getTableName())); genTable.setClassName(convertClassName(genTable.getTableName()));
genTable.setPackageName(GenConfig.getPackageName()); genTable.setPackageName(GenConfig.getPackageName());
genTable.setModuleName(getModuleName(GenConfig.getPackageName())); genTable.setModuleName(getModuleName(GenConfig.getPackageName()));
@ -32,8 +31,7 @@ public class GenUtils
/** /**
* *
*/ */
public static void initColumnField(GenTableColumn column, GenTable table) public static void initColumnField(GenTableColumn column, GenTable table) {
{
String dataType = getDbType(column.getColumnType()); String dataType = getDbType(column.getColumnType());
String columnName = column.getColumnName(); String columnName = column.getColumnName();
column.setTableId(table.getTableId()); column.setTableId(table.getTableId());
@ -43,89 +41,55 @@ public class GenUtils
// 设置默认类型 // 设置默认类型
column.setJavaType(GenConstants.TYPE_STRING); column.setJavaType(GenConstants.TYPE_STRING);
column.setQueryType(GenConstants.QUERY_EQ); column.setQueryType(GenConstants.QUERY_EQ);
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType)) {
if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType) || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType))
{
// 字符串长度超过500设置为文本域 // 字符串长度超过500设置为文本域
Integer columnLength = getColumnLength(column.getColumnType()); Integer columnLength = getColumnLength(column.getColumnType());
String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; String htmlType = columnLength >= 500 || arraysContains(GenConstants.COLUMNTYPE_TEXT, dataType) ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT;
column.setHtmlType(htmlType); column.setHtmlType(htmlType);
} } else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) {
else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType))
{
column.setJavaType(GenConstants.TYPE_DATE); column.setJavaType(GenConstants.TYPE_DATE);
column.setHtmlType(GenConstants.HTML_DATETIME); column.setHtmlType(GenConstants.HTML_DATETIME);
} } else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) {
else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType))
{
column.setHtmlType(GenConstants.HTML_INPUT); column.setHtmlType(GenConstants.HTML_INPUT);
// 如果是浮点型 统一用BigDecimal // 如果是浮点型 统一用BigDecimal
String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ",");
if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) {
{
column.setJavaType(GenConstants.TYPE_BIGDECIMAL); column.setJavaType(GenConstants.TYPE_BIGDECIMAL);
} } else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) {
// 如果是整形
else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10)
{
column.setJavaType(GenConstants.TYPE_INTEGER); column.setJavaType(GenConstants.TYPE_INTEGER);
} } else {
// 长整形
else
{
column.setJavaType(GenConstants.TYPE_LONG); column.setJavaType(GenConstants.TYPE_LONG);
} }
} }
// 插入字段(默认所有字段都需要插入) // 插入字段(默认所有字段都需要插入)
column.setIsInsert(GenConstants.REQUIRE); column.setIsInsert(GenConstants.REQUIRE);
// 编辑字段 // 编辑字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) {
{
column.setIsEdit(GenConstants.REQUIRE); column.setIsEdit(GenConstants.REQUIRE);
} }
// 列表字段 // 列表字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) {
{
column.setIsList(GenConstants.REQUIRE); column.setIsList(GenConstants.REQUIRE);
} }
// 查询字段 // 查询字段
if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) {
{
column.setIsQuery(GenConstants.REQUIRE); column.setIsQuery(GenConstants.REQUIRE);
} }
// 查询字段类型 // 查询字段类型
if (StringUtils.endsWithIgnoreCase(columnName, "name")) if (StringUtils.endsWithIgnoreCase(columnName, "name")) {
{
column.setQueryType(GenConstants.QUERY_LIKE); column.setQueryType(GenConstants.QUERY_LIKE);
} }
// 状态字段设置单选框 // 状态字段设置单选框
if (StringUtils.endsWithIgnoreCase(columnName, "status")) if (StringUtils.endsWithIgnoreCase(columnName, "status")) {
{
column.setHtmlType(GenConstants.HTML_RADIO); column.setHtmlType(GenConstants.HTML_RADIO);
} } else if (StringUtils.endsWithIgnoreCase(columnName, "type")
// 类型&性别字段设置下拉框 || StringUtils.endsWithIgnoreCase(columnName, "sex")) {
else if (StringUtils.endsWithIgnoreCase(columnName, "type")
|| StringUtils.endsWithIgnoreCase(columnName, "sex"))
{
column.setHtmlType(GenConstants.HTML_SELECT); column.setHtmlType(GenConstants.HTML_SELECT);
} } else if (StringUtils.endsWithIgnoreCase(columnName, "image")) {
// 图片字段设置图片上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "image"))
{
column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD); column.setHtmlType(GenConstants.HTML_IMAGE_UPLOAD);
} } else if (StringUtils.endsWithIgnoreCase(columnName, "file")) {
// 文件字段设置文件上传控件
else if (StringUtils.endsWithIgnoreCase(columnName, "file"))
{
column.setHtmlType(GenConstants.HTML_FILE_UPLOAD); column.setHtmlType(GenConstants.HTML_FILE_UPLOAD);
} } else if (StringUtils.endsWithIgnoreCase(columnName, "content")) {
// 内容字段设置富文本控件
else if (StringUtils.endsWithIgnoreCase(columnName, "content"))
{
column.setHtmlType(GenConstants.HTML_EDITOR); column.setHtmlType(GenConstants.HTML_EDITOR);
} }
} }
@ -137,8 +101,7 @@ public class GenUtils
* @param targetValue * @param targetValue
* @return * @return
*/ */
public static boolean arraysContains(String[] arr, String targetValue) public static boolean arraysContains(String[] arr, String targetValue) {
{
return Arrays.asList(arr).contains(targetValue); return Arrays.asList(arr).contains(targetValue);
} }
@ -148,8 +111,7 @@ public class GenUtils
* @param packageName * @param packageName
* @return * @return
*/ */
public static String getModuleName(String packageName) public static String getModuleName(String packageName) {
{
int lastIndex = packageName.lastIndexOf("."); int lastIndex = packageName.lastIndexOf(".");
int nameLength = packageName.length(); int nameLength = packageName.length();
return StringUtils.substring(packageName, lastIndex + 1, nameLength); return StringUtils.substring(packageName, lastIndex + 1, nameLength);
@ -161,8 +123,7 @@ public class GenUtils
* @param tableName * @param tableName
* @return * @return
*/ */
public static String getBusinessName(String tableName) public static String getBusinessName(String tableName) {
{
int lastIndex = tableName.lastIndexOf("_"); int lastIndex = tableName.lastIndexOf("_");
int nameLength = tableName.length(); int nameLength = tableName.length();
return StringUtils.substring(tableName, lastIndex + 1, nameLength); return StringUtils.substring(tableName, lastIndex + 1, nameLength);
@ -174,12 +135,10 @@ public class GenUtils
* @param tableName * @param tableName
* @return * @return
*/ */
public static String convertClassName(String tableName) public static String convertClassName(String tableName) {
{
boolean autoRemovePre = GenConfig.getAutoRemovePre(); boolean autoRemovePre = GenConfig.getAutoRemovePre();
String tablePrefix = GenConfig.getTablePrefix(); String tablePrefix = GenConfig.getTablePrefix();
if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) {
{
String[] searchList = StringUtils.split(tablePrefix, ","); String[] searchList = StringUtils.split(tablePrefix, ",");
tableName = replaceFirst(tableName, searchList); tableName = replaceFirst(tableName, searchList);
} }
@ -193,13 +152,10 @@ public class GenUtils
* @param searchList * @param searchList
* @return * @return
*/ */
public static String replaceFirst(String replacementm, String[] searchList) public static String replaceFirst(String replacementm, String[] searchList) {
{
String text = replacementm; String text = replacementm;
for (String searchString : searchList) for (String searchString : searchList) {
{ if (replacementm.startsWith(searchString)) {
if (replacementm.startsWith(searchString))
{
text = replacementm.replaceFirst(searchString, ""); text = replacementm.replaceFirst(searchString, "");
break; break;
} }
@ -213,8 +169,7 @@ public class GenUtils
* @param text * @param text
* @return * @return
*/ */
public static String replaceText(String text) public static String replaceText(String text) {
{
return RegExUtils.replaceAll(text, "(?:表|若依)", ""); return RegExUtils.replaceAll(text, "(?:表|若依)", "");
} }
@ -224,14 +179,10 @@ public class GenUtils
* @param columnType * @param columnType
* @return * @return
*/ */
public static String getDbType(String columnType) public static String getDbType(String columnType) {
{ if (StringUtils.indexOf(columnType, "(") > 0) {
if (StringUtils.indexOf(columnType, "(") > 0)
{
return StringUtils.substringBefore(columnType, "("); return StringUtils.substringBefore(columnType, "(");
} } else {
else
{
return columnType; return columnType;
} }
} }
@ -242,15 +193,11 @@ public class GenUtils
* @param columnType * @param columnType
* @return * @return
*/ */
public static Integer getColumnLength(String columnType) public static Integer getColumnLength(String columnType) {
{ if (StringUtils.indexOf(columnType, "(") > 0) {
if (StringUtils.indexOf(columnType, "(") > 0)
{
String length = StringUtils.substringBetween(columnType, "(", ")"); String length = StringUtils.substringBetween(columnType, "(", ")");
return Integer.valueOf(length); return Integer.valueOf(length);
} } else {
else
{
return 0; return 0;
} }
} }

@ -37,7 +37,6 @@ public class ScheduleConfig
prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true"); prop.put("org.quartz.jobStore.txIsolationLevelSerializable", "true");
// sqlserver 启用 // sqlserver 启用
// prop.put("org.quartz.jobStore.selectWithLockSQL", "SELECT * FROM {0}LOCKS UPDLOCK WHERE LOCK_NAME = ?");
prop.put("org.quartz.jobStore.misfireThreshold", "12000"); prop.put("org.quartz.jobStore.misfireThreshold", "12000");
prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_"); prop.put("org.quartz.jobStore.tablePrefix", "QRTZ_");
factory.setQuartzProperties(prop); factory.setQuartzProperties(prop);

@ -1,9 +1,10 @@
package com.ruoyi.job.service; package com.ruoyi.job.service;
import java.util.List;
import org.quartz.SchedulerException;
import com.ruoyi.common.core.exception.job.TaskException; import com.ruoyi.common.core.exception.job.TaskException;
import com.ruoyi.job.domain.SysJob; import com.ruoyi.job.domain.SysJob;
import org.quartz.SchedulerException;
import java.util.List;
/** /**
* *
@ -30,9 +31,9 @@ public interface ISysJobService
/** /**
* *
*
* @param job * @param job
* @return * @return
* @throws SchedulerException
*/ */
public int pauseJob(SysJob job) throws SchedulerException; public int pauseJob(SysJob job) throws SchedulerException;
@ -41,6 +42,7 @@ public interface ISysJobService
* *
* @param job * @param job
* @return * @return
* @throws SchedulerException
*/ */
public int resumeJob(SysJob job) throws SchedulerException; public int resumeJob(SysJob job) throws SchedulerException;
@ -49,6 +51,7 @@ public interface ISysJobService
* *
* @param job * @param job
* @return * @return
* @throws SchedulerException
*/ */
public int deleteJob(SysJob job) throws SchedulerException; public int deleteJob(SysJob job) throws SchedulerException;

@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.domain.AjaxResult;
@ -131,7 +131,7 @@ public class SysProfileController extends BaseController
if (!file.isEmpty()) if (!file.isEmpty())
{ {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
R<SysFile> fileResult = remoteFileService.upload(file); Rust<SysFile> fileResult = remoteFileService.upload(file);
if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData())) if (StringUtils.isNull(fileResult) || StringUtils.isNull(fileResult.getData()))
{ {
return AjaxResult.error("文件服务异常,请联系管理员"); return AjaxResult.error("文件服务异常,请联系管理员");

@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.constant.UserConstants; import com.ruoyi.common.core.constant.UserConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.Rust;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil; import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.controller.BaseController;
@ -108,12 +108,12 @@ public class SysUserController extends BaseController
*/ */
@InnerAuth @InnerAuth
@GetMapping("/info/{username}") @GetMapping("/info/{username}")
public R<LoginUser> info(@PathVariable("username") String username) public Rust<LoginUser> info(@PathVariable("username") String username)
{ {
SysUser sysUser = userService.selectUserByUserName(username); SysUser sysUser = userService.selectUserByUserName(username);
if (StringUtils.isNull(sysUser)) if (StringUtils.isNull(sysUser))
{ {
return R.fail("用户名或密码错误"); return Rust.fail("用户名或密码错误");
} }
// 角色集合 // 角色集合
Set<String> roles = permissionService.getRolePermission(sysUser.getUserId()); Set<String> roles = permissionService.getRolePermission(sysUser.getUserId());
@ -123,7 +123,7 @@ public class SysUserController extends BaseController
sysUserVo.setSysUser(sysUser); sysUserVo.setSysUser(sysUser);
sysUserVo.setRoles(roles); sysUserVo.setRoles(roles);
sysUserVo.setPermissions(permissions); sysUserVo.setPermissions(permissions);
return R.ok(sysUserVo); return Rust.ok(sysUserVo);
} }
/** /**
@ -131,18 +131,18 @@ public class SysUserController extends BaseController
*/ */
@InnerAuth @InnerAuth
@PostMapping("/register") @PostMapping("/register")
public R<Boolean> register(@RequestBody SysUser sysUser) public Rust<Boolean> register(@RequestBody SysUser sysUser)
{ {
String username = sysUser.getUserName(); String username = sysUser.getUserName();
if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser")))) if (!("true".equals(configService.selectConfigByKey("sys.account.registerUser"))))
{ {
return R.fail("当前系统没有开启注册功能!"); return Rust.fail("当前系统没有开启注册功能!");
} }
if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username))) if (UserConstants.NOT_UNIQUE.equals(userService.checkUserNameUnique(username)))
{ {
return R.fail("保存用户'" + username + "'失败,注册账号已存在"); return Rust.fail("保存用户'" + username + "'失败,注册账号已存在");
} }
return R.ok(userService.registerUser(sysUser)); return Rust.ok(userService.registerUser(sysUser));
} }
/** /**

@ -1,8 +1,9 @@
package com.ruoyi.system.mapper; package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.api.domain.SysLogininfor; import com.ruoyi.system.api.domain.SysLogininfor;
import java.util.List;
/** /**
* 访 * 访
* *
@ -14,6 +15,7 @@ public interface SysLogininforMapper
* *
* *
* @param logininfor 访 * @param logininfor 访
* @return int
*/ */
public int insertLogininfor(SysLogininfor logininfor); public int insertLogininfor(SysLogininfor logininfor);

@ -1,8 +1,9 @@
package com.ruoyi.system.mapper; package com.ruoyi.system.mapper;
import java.util.List;
import com.ruoyi.system.api.domain.SysOperLog; import com.ruoyi.system.api.domain.SysOperLog;
import java.util.List;
/** /**
* *
* *
@ -14,6 +15,7 @@ public interface SysOperLogMapper
* *
* *
* @param operLog * @param operLog
* @return int
*/ */
public int insertOperlog(SysOperLog operLog); public int insertOperlog(SysOperLog operLog);

@ -1,8 +1,9 @@
package com.ruoyi.system.service; package com.ruoyi.system.service;
import java.util.List;
import com.ruoyi.system.api.domain.SysLogininfor; import com.ruoyi.system.api.domain.SysLogininfor;
import java.util.List;
/** /**
* 访 * 访
* *
@ -14,6 +15,7 @@ public interface ISysLogininforService
* *
* *
* @param logininfor 访 * @param logininfor 访
* @return int
*/ */
public int insertLogininfor(SysLogininfor logininfor); public int insertLogininfor(SysLogininfor logininfor);

@ -2,6 +2,9 @@ package com.ruoyi.system.service;
import java.util.Set; import java.util.Set;
/**
* @author pan
*/
public interface ISysPermissionService public interface ISysPermissionService
{ {
/** /**

@ -1,14 +1,18 @@
package com.ruoyi.system.service.impl; package com.ruoyi.system.service.impl;
import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.api.domain.SysUser; import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.service.ISysMenuService; import com.ruoyi.system.service.ISysMenuService;
import com.ruoyi.system.service.ISysPermissionService; import com.ruoyi.system.service.ISysPermissionService;
import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.Set;
/**
* @author pan
*/
@Service @Service
public class SysPermissionServiceImpl implements ISysPermissionService public class SysPermissionServiceImpl implements ISysPermissionService
{ {

Loading…
Cancel
Save