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

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{
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){ }catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
@@ -110,13 +114,17 @@ 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 {
list=userMapperEx.selectByConditionUser(userName, loginName, offset, rows); //先校验是否登录,然后才能查询用户数据
for(UserEx ue: list){ 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 = ""; String userType = "";
if (ue.getId().equals(ue.getTenantId())) { if (ue.getId().equals(ue.getTenantId())) {
userType = "租户"; userType = "租户";
} else if(ue.getTenantId() == null){ } else if (ue.getTenantId() == null) {
userType = "超管"; userType = "超管";
} else { } else {
userType = "普通"; userType = "普通";
@@ -124,14 +132,15 @@ public class UserService {
ue.setUserType(userType); ue.setUserType(userType);
//是否经理 //是否经理
String leaderFlagStr = ""; String leaderFlagStr = "";
if("1".equals(ue.getLeaderFlag())) { if ("1".equals(ue.getLeaderFlag())) {
leaderFlagStr = ""; leaderFlagStr = "";
} else { } else {
leaderFlagStr = ""; leaderFlagStr = "";
} }
ue.setLeaderFlagStr(leaderFlagStr); ue.setLeaderFlagStr(leaderFlagStr);
} }
}catch(Exception e){ }
} catch(Exception e){
JshException.readFail(logger, e); JshException.readFail(logger, e);
} }
return list; return list;
@@ -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) {