优化用户查询接口:先校验是否登录,然后才能查询用户数据
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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,28 +114,33 @@ 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();
|
||||||
String userType = "";
|
Long userId = this.getUserId(request);
|
||||||
if (ue.getId().equals(ue.getTenantId())) {
|
if(userId!=null) {
|
||||||
userType = "租户";
|
list = userMapperEx.selectByConditionUser(userName, loginName, offset, rows);
|
||||||
} else if(ue.getTenantId() == null){
|
for (UserEx ue : list) {
|
||||||
userType = "超管";
|
String userType = "";
|
||||||
} else {
|
if (ue.getId().equals(ue.getTenantId())) {
|
||||||
userType = "普通";
|
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);
|
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user