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

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

View File

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