用户禁用 拉黑

This commit is contained in:
wangw 2025-05-24 11:21:26 +08:00
parent 1f766cc8df
commit d3462828ed
6 changed files with 121 additions and 30 deletions

View File

@ -2,10 +2,16 @@ package com.sqx.common.aspect;
import cn.hutool.core.thread.ThreadUtil;
import com.google.gson.Gson;
import com.sqx.common.exception.CzgException;
import com.sqx.common.exception.LimitException;
import com.sqx.common.exception.UserException;
import com.sqx.common.utils.HttpContextUtils;
import com.sqx.common.utils.IPUtils;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.app.utils.JwtUtils;
import com.sqx.modules.common.service.CommonInfoService;
import io.jsonwebtoken.Claims;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
@ -13,14 +19,11 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
/**
* 方法调用统一切面处理
*/
@ -32,14 +35,37 @@ public class AppApiMethodAspect {
@Autowired
private CommonInfoService commonInfoService;
@Autowired
private UserService userService;
@Autowired
private JwtUtils jwtUtils;
@Pointcut("!execution(public * (com.sqx.modules.sys.controller.SysLoginController).*(..)) " +
"&& execution(public * (com.sqx.modules.*.controller..*).*(..)))")
public void pkg() {
}
@Around("pkg()")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String token = request.getHeader("token");
if (StringUtils.isBlank(token)) {
Claims claims = jwtUtils.getClaimByToken(token);
if (claims != null && !jwtUtils.isTokenExpired(claims.getExpiration())) {
Long userId = Long.parseLong(claims.getSubject());
UserEntity userInfo = userService.selectUserById(userId);
if (userInfo == null) {
throw new CzgException("用户不存在");
} else if (userInfo.getStatus() == 0) {
throw new UserException("用户被拉黑", 701);
} else if (userInfo.getStatus() == 2) {
throw new UserException("用户被禁用", 702);
}
}
}
long start = System.currentTimeMillis();
//避免回填
Object[] args = pjp.getArgs();
@ -50,8 +76,6 @@ public class AppApiMethodAspect {
args[i] = null;
}
}
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String requestIp = IPUtils.getIpAddr(request);
// Integer maxAccessCount = Integer.parseInt(commonInfoService.findOne(935).getValue());

View File

@ -37,6 +37,15 @@ public class SqxExceptionHandler {
return r;
}
@ExceptionHandler(UserException.class)
public Result handleUserException(UserException e) {
Result r = new Result();
r.put("code", e.getCode());
r.put("msg", e.getMessage());
return r;
}
@ExceptionHandler(NoHandlerFoundException.class)
public Result handlerNoFoundException(Exception e, WebRequest webRequest) {
logErrorInfo(webRequest);

View File

@ -0,0 +1,52 @@
package com.sqx.common.exception;
/**
* 自定义异常
*
*/
public class UserException extends RuntimeException {
private static final long serialVersionUID = 1L;
private String msg;
private int code = 701;
public UserException(String msg) {
super(msg);
this.msg = msg;
}
public UserException(String msg, Throwable e) {
super(msg, e);
this.msg = msg;
}
public UserException(String msg, int code) {
super(msg);
this.msg = msg;
this.code = code;
}
public UserException(String msg, int code, Throwable e) {
super(msg, e);
this.msg = msg;
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
}

View File

@ -196,14 +196,23 @@ public class UserController {
@RequestMapping(value = "/updateUserStatusByUserId", method = RequestMethod.GET)
@ApiOperation("禁用或启用用户")
@ResponseBody
public Result updateUserByUserId(Long userId) {
public Result updateUserByUserId(Long userId, Integer status) {
UserEntity byId = userService.getById(userId);
if (byId.getStatus().equals(1)) {
byId.setStatus(2);
} else {
byId.setStatus(1);
if (byId == null) {
return Result.error("用户不存在");
}
if (status.equals(1)) {
byId.setStatus(1);
userService.upUserBlack(byId, 1);
} else if (status.equals(2)) {
byId.setStatus(2);
userService.updateById(byId);
} else if (status.equals(0)) {
userService.upUserBlack(byId, 0);
} else {
return Result.error("状态不正确");
}
userService.updateById(byId);
return Result.success();
}
@ -444,12 +453,5 @@ public class UserController {
return userService.updateUserInviteAmount(userInviteDTO);
}
@ApiOperation("更新用户邀请奖励金额")
@RequestMapping(value = "/removeUserBlack", method = RequestMethod.GET)
@ResponseBody
public Result removeUserBlack(Long userId, Integer status) {
return userService.removeUserBlack(userId, status);
}
}

View File

@ -235,7 +235,7 @@ public interface UserService extends IService<UserEntity> {
Result updateUserInviteAmount(UserInviteDTO userInviteDTO);
Result removeUserBlack(Long userId, Integer status);
Result upUserBlack(UserEntity userEntity, Integer status);
Map<String, Object> queryPayAndExtractInfo();

View File

@ -899,10 +899,14 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
return Result.error("账号或密码不正确!");
}
if (!userInfo.getStatus().equals(1)) {
if (userInfo.getStatus().equals(0)) {
return Result.error("账号已被禁用,请联系客服处理!");
}
// if (!userInfo.getStatus().equals(1)) {
// return Result.error("账号已被禁用,请联系客服处理!");
// }
// 实名认证信息
UserInfo idCardAuth = userInfoService.getByUserId(userInfo.getUserId());
if (idCardAuth != null && StrUtil.isNotBlank(idCardAuth.getCertNo())) {
@ -1349,8 +1353,10 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
CommonInfo three = commonInfoService.findOne(238);
CommonInfo four = commonInfoService.findOne(239);
CommonInfo name = commonInfoService.findOne(81);
String testUsername = three.getValue(); //在短信宝注册的用户名
String testPassword = four.getValue(); //在短信宝注册的密码
//在短信宝注册的用户名
String testUsername = three.getValue();
//在短信宝注册的密码
String testPassword = four.getValue();
String value = "";
switch (state) {
case "register":
@ -1584,7 +1590,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
GTNotification notification = new GTNotification();
pushDTO.setPushMessage(pushMessage);
// 配置通知栏图标
notification.setLogo(commonInfoService.findOne(19).getValue() + "/logo.png"); //配置通知栏图标需要在客户端开发时嵌入默认为push.png
//配置通知栏图标需要在客户端开发时嵌入默认为push.png
notification.setLogo(commonInfoService.findOne(19).getValue() + "/logo.png");
// 配置通知栏网络图标
notification.setLogoUrl(commonInfoService.findOne(19).getValue() + "/logo.png");
notification.setTitle(title);
@ -1670,8 +1677,9 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
});
}
// counts 降序
userInfoList = userInfoList.stream()
.sorted((u1, u2) -> Integer.compare(u2.getCounts(), u1.getCounts())) // counts 降序
.sorted((u1, u2) -> Integer.compare(u2.getCounts(), u1.getCounts()))
.collect(Collectors.toList());
return Result.success().put("data", PageUtils.page(new PageInfo<>(userInfoList), true));
}
@ -1783,12 +1791,8 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
}
@Override
public Result removeUserBlack(Long userId, Integer status) {
UserEntity userEntity = getById(userId);
if (userEntity == null) {
return Result.error("用户不存在");
}
public Result upUserBlack(UserEntity userEntity, Integer status) {
Long userId = userEntity.getUserId();
if (status == 0) {
userEntity.setStatus(0);
update(userEntity, new LambdaUpdateWrapper<UserEntity>().eq(UserEntity::getUserId, userId));