bug 修改

This commit is contained in:
jiang 2024-07-31 15:06:34 +08:00
parent b376304c1a
commit d991c59ba7
8 changed files with 111 additions and 160 deletions

View File

@ -176,13 +176,11 @@ public class SysLoginService {
private LoginUser handleMobileLogin(String mobile, long startTime) {
R<LoginUser> userResult = remoteUserService.getUserInfo(mobile, SecurityConstants.INNER);
validateUserResult(mobile, userResult, startTime);
LoginUser userInfo = userResult.getData();
SysUser user = userInfo.getSysUser();
validateApprovalStatus(user.getUserName(), user, startTime);
validateIpBlacklist(user.getUserName(), startTime);
validateUserStatus(user.getUserName(), user, startTime);
recordLogService.saveLogs(user.getUserName(), startTime, "登陆成功", "手机号验证码登录成功", user.getUserId().toString(), "成功");
return userInfo;
}

View File

@ -36,53 +36,46 @@ import reactor.core.publisher.Mono;
*
* @author bonus
*/
public class ServletUtils
{
public class ServletUtils {
/**
* 获取String参数
*/
public static String getParameter(String name)
{
public static String getParameter(String name) {
return getRequest().getParameter(name);
}
/**
* 获取String参数
*/
public static String getParameter(String name, String defaultValue)
{
public static String getParameter(String name, String defaultValue) {
return Convert.toStr(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name)
{
public static Integer getParameterToInt(String name) {
return Convert.toInt(getRequest().getParameter(name));
}
/**
* 获取Integer参数
*/
public static Integer getParameterToInt(String name, Integer defaultValue)
{
public static Integer getParameterToInt(String name, Integer defaultValue) {
return Convert.toInt(getRequest().getParameter(name), defaultValue);
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name)
{
public static Boolean getParameterToBool(String name) {
return Convert.toBool(getRequest().getParameter(name));
}
/**
* 获取Boolean参数
*/
public static Boolean getParameterToBool(String name, Boolean defaultValue)
{
public static Boolean getParameterToBool(String name, Boolean defaultValue) {
return Convert.toBool(getRequest().getParameter(name), defaultValue);
}
@ -92,8 +85,7 @@ public class ServletUtils
* @param request 请求对象{@link ServletRequest}
* @return Map
*/
public static Map<String, String[]> getParams(ServletRequest request)
{
public static Map<String, String[]> getParams(ServletRequest request) {
final Map<String, String[]> map = request.getParameterMap();
return Collections.unmodifiableMap(map);
}
@ -104,11 +96,9 @@ public class ServletUtils
* @param request 请求对象{@link ServletRequest}
* @return Map
*/
public static Map<String, String> getParamMap(ServletRequest request)
{
public static Map<String, String> getParamMap(ServletRequest request) {
Map<String, String> params = new HashMap<>(16);
for (Map.Entry<String, String[]> entry : getParams(request).entrySet())
{
for (Map.Entry<String, String[]> entry : getParams(request).entrySet()) {
params.put(entry.getKey(), StringUtils.join(entry.getValue(), ","));
}
return params;
@ -117,14 +107,10 @@ public class ServletUtils
/**
* 获取request
*/
public static HttpServletRequest getRequest()
{
try
{
public static HttpServletRequest getRequest() {
try {
return getRequestAttributes().getRequest();
}
catch (Exception e)
{
} catch (Exception e) {
return null;
}
}
@ -132,14 +118,10 @@ public class ServletUtils
/**
* 获取response
*/
public static HttpServletResponse getResponse()
{
try
{
public static HttpServletResponse getResponse() {
try {
return getRequestAttributes().getResponse();
}
catch (Exception e)
{
} catch (Exception e) {
return null;
}
}
@ -147,42 +129,32 @@ public class ServletUtils
/**
* 获取session
*/
public static HttpSession getSession()
{
public static HttpSession getSession() {
return getRequest().getSession();
}
public static ServletRequestAttributes getRequestAttributes()
{
try
{
public static ServletRequestAttributes getRequestAttributes() {
try {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
return (ServletRequestAttributes) attributes;
}
catch (Exception e)
{
} catch (Exception e) {
return null;
}
}
public static String getHeader(HttpServletRequest request, String name)
{
public static String getHeader(HttpServletRequest request, String name) {
String value = request.getHeader(name);
if (StringUtils.isEmpty(value))
{
if (StringUtils.isEmpty(value)) {
return StringUtils.EMPTY;
}
return urlDecode(value);
}
public static Map<String, String> getHeaders(HttpServletRequest request)
{
public static Map<String, String> getHeaders(HttpServletRequest request) {
Map<String, String> map = new LinkedCaseInsensitiveMap<>();
Enumeration<String> enumeration = request.getHeaderNames();
if (enumeration != null)
{
while (enumeration.hasMoreElements())
{
if (enumeration != null) {
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
String value = request.getHeader(key);
map.put(key, value);
@ -195,19 +167,15 @@ public class ServletUtils
* 将字符串渲染到客户端
*
* @param response 渲染对象
* @param string 待渲染的字符串
* @param string 待渲染的字符串
*/
public static void renderString(HttpServletResponse response, String string)
{
try
{
public static void renderString(HttpServletResponse response, String string) {
try {
response.setStatus(200);
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
response.getWriter().print(string);
}
catch (IOException e)
{
} catch (IOException e) {
e.printStackTrace();
}
}
@ -217,28 +185,24 @@ public class ServletUtils
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request)
{
public static boolean isAjaxRequest(HttpServletRequest request) {
final String jsonMimeType = "application/json";
final String xhrHeader = "XMLHttpRequest";
final String jsonSuffix = ".json";
final String xmlSuffix = ".xml";
String accept = request.getHeader("accept");
if (accept != null && accept.contains(jsonMimeType))
{
if (accept != null && accept.contains(jsonMimeType)) {
return true;
}
String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.contains(xhrHeader))
{
if (xRequestedWith != null && xRequestedWith.contains(xhrHeader)) {
return true;
}
String uri = request.getRequestURI();
if (StringUtils.inStringIgnoreCase(uri, jsonSuffix, xmlSuffix))
{
if (StringUtils.inStringIgnoreCase(uri, jsonSuffix, xmlSuffix)) {
return true;
}
@ -252,14 +216,10 @@ public class ServletUtils
* @param str 内容
* @return 编码后的内容
*/
public static String urlEncode(String str)
{
try
{
public static String urlEncode(String str) {
try {
return URLEncoder.encode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
} catch (UnsupportedEncodingException e) {
return StringUtils.EMPTY;
}
}
@ -270,14 +230,10 @@ public class ServletUtils
* @param str 内容
* @return 解码后的内容
*/
public static String urlDecode(String str)
{
try
{
public static String urlDecode(String str) {
try {
return URLDecoder.decode(str, Constants.UTF8);
}
catch (UnsupportedEncodingException e)
{
} catch (UnsupportedEncodingException e) {
return StringUtils.EMPTY;
}
}
@ -286,66 +242,53 @@ public class ServletUtils
* 设置webflux模型响应
*
* @param response ServerHttpResponse
* @param value 响应内容
* @param value 响应内容
* @return Mono
*/
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value,boolean jimi)
{
return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL,jimi);
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, boolean jimi) {
return webFluxResponseWriter(response, HttpStatus.OK, value, R.FAIL, jimi);
}
/**
* 设置webflux模型响应
*
* @param response ServerHttpResponse
* @param code 响应状态码
* @param value 响应内容
* @param code 响应状态码
* @param value 响应内容
* @return Mono&lt;Void&gt;
*/
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code,boolean jimi)
{
return webFluxResponseWriter(response, HttpStatus.OK, value, code,jimi);
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, Object value, int code, boolean jimi) {
return webFluxResponseWriter(response, HttpStatus.OK, value, code, jimi);
}
/**
* 设置webflux模型响应
*
* @param response ServerHttpResponse
* @param status http状态码
* @param code 响应状态码
* @param value 响应内容
* @param status http状态码
* @param code 响应状态码
* @param value 响应内容
* @return Mono&lt;Void&gt;
*/
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code,boolean jimi)
{
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, HttpStatus status, Object value, int code, boolean jimi) {
return webFluxResponseWriter(response, MediaType.APPLICATION_JSON_VALUE, status, value, code, jimi);
}
/**
* 设置webflux模型响应
*
* @param response ServerHttpResponse
* @param response ServerHttpResponse
* @param contentType content-type
* @param status http状态码
* @param code 响应状态码
* @param value 响应内容
* @param status http状态码
* @param code 响应状态码
* @param value 响应内容
* @return Mono&lt;Void&gt;
*/
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code,boolean jimi)
{
public static Mono<Void> webFluxResponseWriter(ServerHttpResponse response, String contentType, HttpStatus status, Object value, int code, boolean jimi) {
response.setStatusCode(status);
response.getHeaders().add(HttpHeaders.CONTENT_TYPE, contentType);
R<?> result = R.fail(code, value.toString());
Map maps= Maps.newHashMap();
if(jimi){
String responseData= AesCbcUtils.encrypt( JSON.toJSONString(result));
maps.put("data",responseData);
maps.put(SystemGlobal.KEY_DECRYPT,true);
}else{
maps.put("data",result);
maps.put(SystemGlobal.KEY_DECRYPT,false);
}
DataBuffer dataBuffer = response.bufferFactory().wrap(JSON.toJSONString(maps).getBytes());
DataBuffer dataBuffer = response.bufferFactory().wrap(JSON.toJSONString(result).getBytes());
return response.writeWith(Mono.just(dataBuffer));
}
}

View File

@ -64,7 +64,6 @@ public class TokenService {
loginUser.setUsername(userName);
loginUser.setIpaddr(IpUtils.getIpAddr());
refreshToken(loginUser);
// Jwt存储信息
Map<String, Object> claimsMap = new HashMap<String, Object>(16);
claimsMap.put(SecurityConstants.USER_KEY, token);
@ -79,13 +78,23 @@ public class TokenService {
return rspMap;
}
public boolean isLogin(String userId) {
String existingTokenKey = redisService.getCacheObject(LOGIN_USER_KEY + userId);
return existingTokenKey != null;
}
public boolean isKey(String key) {
return redisService.hasKey(getTokenKey(key));
}
/**
* 删除已有的token
*/
private void delExistingToken(Long userId) {
public void delExistingToken(Long userId) {
String existingTokenKey = redisService.getCacheObject(LOGIN_USER_KEY + userId);
if (existingTokenKey != null) {
redisService.deleteObject(getTokenKey(existingTokenKey));
redisService.deleteObject(LOGIN_USER_KEY + userId);
}
}

View File

@ -73,7 +73,7 @@ public class ValidateCodeFilter extends AbstractGatewayFilterFactory<Object> {
}
} catch (Exception e) {
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), jaData);
return ServletUtils.webFluxResponseWriter(exchange.getResponse(), e.getMessage(), jaData);
}
return chain.filter(exchange);
};

View File

@ -35,8 +35,7 @@ import com.bonus.system.service.ISysPostService;
@RestController
@RequestMapping("/post")
@Slf4j
public class SysPostController extends BaseController
{
public class SysPostController extends BaseController {
@Autowired
private ISysPostService postService;
@ -45,29 +44,29 @@ public class SysPostController extends BaseController
*/
@RequiresPermissions("system:post:list")
@GetMapping("/list")
@SysLog(title = "岗位管理", businessType = OperaType.QUERY,logType = 0,module = "系统管理->岗位管理")
@SysLog(title = "岗位管理", businessType = OperaType.QUERY, logType = 0, module = "系统管理->岗位管理")
public TableDataInfo list(SysPost post) {
try{
startPage();
List<SysPost> list = postService.selectPostList(post);
return getDataTable(list);
}catch (Exception e){
log.error(e.toString(),e);
}
return getDataTableError(new ArrayList<>());
try {
startPage();
List<SysPost> list = postService.selectPostList(post);
return getDataTable(list);
} catch (Exception e) {
log.error(e.toString(), e);
}
return getDataTableError(new ArrayList<>());
}
@RequiresPermissions("system:post:export")
@PostMapping("/export")
@SysLog(title = "岗位管理", businessType = OperaType.EXPORT,logType = 0,module = "系统管理->岗位管理")
@SysLog(title = "岗位管理", businessType = OperaType.EXPORT, logType = 0, module = "系统管理->岗位管理")
public void export(HttpServletResponse response, SysPost post) {
try{
List<SysPost> list = postService.selectPostList(post);
ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
util.exportExcel(response, list, "岗位数据");
}catch (Exception e){
log.error(e.toString(),e);
}
try {
List<SysPost> list = postService.selectPostList(post);
ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);
util.exportExcel(response, list, "岗位数据");
} catch (Exception e) {
log.error(e.toString(), e);
}
}
/**
@ -76,10 +75,10 @@ public class SysPostController extends BaseController
@RequiresPermissions("system:post:query")
@GetMapping(value = "/{postId}")
public AjaxResult getInfo(@PathVariable Long postId) {
try{
try {
return success(postService.selectPostById(postId));
}catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
}
return error("系统异常");
}
@ -89,9 +88,9 @@ public class SysPostController extends BaseController
*/
@RequiresPermissions("system:post:add")
@PostMapping
@SysLog(title = "岗位管理", businessType = OperaType.INSERT,logType = 0,module = "系统管理->岗位管理",details ="新增岗位" )
@SysLog(title = "岗位管理", businessType = OperaType.INSERT, logType = 0, module = "系统管理->岗位管理", details = "新增岗位")
public AjaxResult add(@Validated @RequestBody SysPost post) {
try{
try {
if (!postService.checkPostNameUnique(post)) {
return error("新增岗位'" + post.getPostName() + "'失败,岗位名称已存在");
} else if (!postService.checkPostCodeUnique(post)) {
@ -99,8 +98,8 @@ public class SysPostController extends BaseController
}
post.setCreateBy(SecurityUtils.getUsername());
return toAjax(postService.insertPost(post));
}catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
}
return error("系统异常");
}
@ -110,9 +109,9 @@ public class SysPostController extends BaseController
*/
@RequiresPermissions("system:post:edit")
@PutMapping
@SysLog(title = "岗位管理", businessType = OperaType.UPDATE,logType = 0,module = "系统管理->岗位管理")
@SysLog(title = "岗位管理", businessType = OperaType.UPDATE, logType = 0, module = "系统管理->岗位管理")
public AjaxResult edit(@Validated @RequestBody SysPost post) {
try{
try {
if (!postService.checkPostNameUnique(post)) {
return error("修改岗位'" + post.getPostName() + "'失败,岗位名称已存在");
} else if (!postService.checkPostCodeUnique(post)) {
@ -120,8 +119,8 @@ public class SysPostController extends BaseController
}
post.setUpdateBy(SecurityUtils.getUsername());
return toAjax(postService.updatePost(post));
}catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
}
return error("系统异常");
}
@ -131,14 +130,15 @@ public class SysPostController extends BaseController
*/
@RequiresPermissions("system:post:remove")
@DeleteMapping("/{postIds}")
@SysLog(title = "岗位管理", businessType = OperaType.DELETE,logType = 0,module = "系统管理->岗位管理")
@SysLog(title = "岗位管理", businessType = OperaType.DELETE, logType = 0, module = "系统管理->岗位管理")
public AjaxResult remove(@PathVariable Long[] postIds) {
try{
try {
return toAjax(postService.deletePostByIds(postIds));
}catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
return error(e.getMessage());
}
return error("人力资源已分配,不能删除");
}
/**
@ -146,11 +146,11 @@ public class SysPostController extends BaseController
*/
@GetMapping("/optionselect")
public AjaxResult optionselect() {
try{
try {
List<SysPost> posts = postService.selectPostAll();
return success(posts);
}catch (Exception e){
log.error(e.toString(),e);
} catch (Exception e) {
log.error(e.toString(), e);
}
return error("系统异常");

View File

@ -110,8 +110,9 @@ public class SysUserController extends BaseController {
return success(message);
} catch (Exception e) {
logger.error(e.toString(), e);
return error(e.getMessage());
}
return error("系统异常,请联系管理员");
}
@PostMapping("/importTemplate")

View File

@ -146,7 +146,7 @@ public class SysPostServiceImpl implements ISysPostService
SysPost post = selectPostById(postId);
if (countUserPostById(postId) > 0)
{
throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName()));
throw new ServiceException(String.format("%1$s已分配用户,不能删除", post.getPostName()));
}
}
return postMapper.deletePostByIds(postIds);

View File

@ -368,7 +368,7 @@ public class SysRoleServiceImpl implements ISysRoleService
SysRole role = selectRoleById(roleId);
if (countUserRoleByRoleId(roleId) > 0)
{
throw new ServiceException(String.format("%1$s已分配,不能删除", role.getRoleName()));
throw new ServiceException(String.format("%1$s已分配用户,不能删除", role.getRoleName()));
}
}
// 删除角色与菜单关联