优化用户查询接口:先校验是否登录,然后才能查询用户数据

This commit is contained in:
jishenghua 2024-08-28 22:53:27 +08:00
parent ac33040c23
commit 6ab20c7baa
2 changed files with 36 additions and 27 deletions

View File

@ -219,7 +219,7 @@ public class UserController {
public JSONArray getUserList(HttpServletRequest request)throws Exception {
JSONArray dataArray = new JSONArray();
try {
List<User> dataList = userService.getUser();
List<User> dataList = userService.getUser(request);
if (null != dataList) {
for (User user : dataList) {
JSONObject item = new JSONObject();
@ -476,7 +476,7 @@ public class UserController {
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
User user = userService.getUser(userId);
//获取当前用户数
int userCurrentNum = userService.getUser().size();
int userCurrentNum = userService.getUser(request).size();
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
if(tenant.getExpireTime()!=null && tenant.getExpireTime().getTime()<System.currentTimeMillis()){
//租户已经过期移除token

View File

@ -96,12 +96,16 @@ public class UserService {
return list;
}
public List<User> getUser()throws Exception {
UserExample example = new UserExample();
example.createCriteria().andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
public List<User> getUser(HttpServletRequest request) throws Exception {
List<User> list=null;
try{
list=userMapper.selectByExample(example);
//先校验是否登录然后才能查询用户数据
Long userId = this.getUserId(request);
if(userId!=null) {
UserExample example = new UserExample();
example.createCriteria().andStatusEqualTo(BusinessConstants.USER_STATUS_NORMAL);
list = userMapper.selectByExample(example);
}
}catch(Exception e){
JshException.readFail(logger, e);
}
@ -110,28 +114,33 @@ public class UserService {
public List<UserEx> select(String userName, String loginName, int offset, int rows)throws Exception {
List<UserEx> list=null;
try{
list=userMapperEx.selectByConditionUser(userName, loginName, offset, rows);
for(UserEx ue: list){
String userType = "";
if (ue.getId().equals(ue.getTenantId())) {
userType = "租户";
} else if(ue.getTenantId() == null){
userType = "超管";
} else {
userType = "普通";
try {
//先校验是否登录然后才能查询用户数据
HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();
Long userId = this.getUserId(request);
if(userId!=null) {
list = userMapperEx.selectByConditionUser(userName, loginName, offset, rows);
for (UserEx ue : list) {
String userType = "";
if (ue.getId().equals(ue.getTenantId())) {
userType = "租户";
} else if (ue.getTenantId() == null) {
userType = "超管";
} else {
userType = "普通";
}
ue.setUserType(userType);
//是否经理
String leaderFlagStr = "";
if ("1".equals(ue.getLeaderFlag())) {
leaderFlagStr = "";
} else {
leaderFlagStr = "";
}
ue.setLeaderFlagStr(leaderFlagStr);
}
ue.setUserType(userType);
//是否经理
String leaderFlagStr = "";
if("1".equals(ue.getLeaderFlag())) {
leaderFlagStr = "";
} else {
leaderFlagStr = "";
}
ue.setLeaderFlagStr(leaderFlagStr);
}
}catch(Exception e){
} catch(Exception e){
JshException.readFail(logger, e);
}
return list;
@ -875,7 +884,7 @@ public class UserService {
//选中的用户的数量
int selectUserSize = list.size();
//查询启用状态的用户的数量
int enableUserSize = getUser().size();
int enableUserSize = getUser(request).size();
User userInfo = userService.getCurrentUser();
Tenant tenant = tenantService.getTenantByTenantId(userInfo.getTenantId());
if(tenant!=null) {