first
This commit is contained in:
@ -10,6 +10,7 @@ import com.greenorange.promotion.model.dto.user.UserUpdateRequest;
|
||||
import com.greenorange.promotion.model.entity.User;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.greenorange.promotion.model.vo.user.UserVO;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -63,6 +64,8 @@ public interface UserService extends IService<User> {
|
||||
boolean delBatchUser(CommonBatchRequest commonBatchRequest);
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 校验用户是否登录
|
||||
*/
|
||||
User getLoginUser(HttpServletRequest request);
|
||||
}
|
||||
|
@ -15,17 +15,22 @@ import com.greenorange.promotion.model.dto.user.UserAddRequest;
|
||||
import com.greenorange.promotion.model.dto.user.UserQueryRequest;
|
||||
import com.greenorange.promotion.model.dto.user.UserUpdateRequest;
|
||||
import com.greenorange.promotion.model.entity.User;
|
||||
import com.greenorange.promotion.model.enums.UserRoleEnum;
|
||||
import com.greenorange.promotion.model.vo.user.UserVO;
|
||||
import com.greenorange.promotion.service.common.CommonService;
|
||||
import com.greenorange.promotion.service.user.UserService;
|
||||
import com.greenorange.promotion.mapper.UserMapper;
|
||||
import com.greenorange.promotion.utils.SqlUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.greenorange.promotion.constant.UserConstant.USER_LOGIN_STATE;
|
||||
|
||||
/**
|
||||
* @author 35880
|
||||
* @description 针对表【user(用户表)】的数据库操作Service实现
|
||||
@ -149,6 +154,32 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
||||
ThrowUtils.throwIf(!result, ErrorCode.OPERATION_ERROR, "用户批量删除失败");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前登录用户
|
||||
*/
|
||||
@Override
|
||||
public User getLoginUser(HttpServletRequest request) {
|
||||
HttpSession session = request.getSession();
|
||||
Object userObj = session.getAttribute(USER_LOGIN_STATE);
|
||||
User currentUser = (User) userObj;
|
||||
if (currentUser == null || currentUser.getId() == null) {
|
||||
throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
|
||||
}
|
||||
//根据id进行查询
|
||||
Long userId = currentUser.getId();
|
||||
currentUser = this.getById(userId);
|
||||
if (currentUser == null) {
|
||||
throw new BusinessException(ErrorCode.NOT_LOGIN_ERROR);
|
||||
}
|
||||
//被封号
|
||||
if (UserRoleEnum.BAN.getValue().equals(currentUser.getUserRole())) {
|
||||
throw new BusinessException(ErrorCode.FORBIDDEN_ERROR);
|
||||
}
|
||||
return currentUser;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user