优化租户管理的编辑功能
This commit is contained in:
@@ -75,6 +75,8 @@ public class TenantConfig {
|
||||
// 过滤自定义查询此时无租户信息约束出现
|
||||
if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) {
|
||||
return true;
|
||||
} else if ("com.jsh.erp.datasource.mappers.UserMapperEx.disableUserByLimit".equals(ms.getId())) {
|
||||
return true;
|
||||
} else if ("com.jsh.erp.datasource.mappers.RoleMapperEx.getRoleWithoutTenant".equals(ms.getId())) {
|
||||
return true;
|
||||
} else if ("com.jsh.erp.datasource.mappers.LogMapperEx.insertLogWithUserId".equals(ms.getId())) {
|
||||
|
||||
@@ -34,12 +34,6 @@ public class ExceptionConstants {
|
||||
**/
|
||||
public static final int SERVICE_SYSTEM_ERROR_CODE = 500;
|
||||
public static final String SERVICE_SYSTEM_ERROR_MSG = "未知异常";
|
||||
|
||||
/**
|
||||
* 删除操作被拒绝,请联系管理员
|
||||
**/
|
||||
public static final int DELETE_REFUSED_CODE = 600;
|
||||
public static final String DELETE_REFUSED_MSG = "删除操作被拒绝,请联系管理员";
|
||||
/**
|
||||
* 检测到存在依赖数据,是否强制删除?
|
||||
**/
|
||||
@@ -66,16 +60,13 @@ public class ExceptionConstants {
|
||||
public static final String USER_LOGIN_NAME_ALREADY_EXISTS_MSG = "登录名在本系统已存在";
|
||||
//用户录入数量超出限制
|
||||
public static final int USER_OVER_LIMIT_FAILED_CODE = 500004;
|
||||
public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系管理员";
|
||||
public static final String USER_OVER_LIMIT_FAILED_MSG = "用户录入数量超出限制,请联系平台管理员";
|
||||
//此用户名限制使用
|
||||
public static final int USER_NAME_LIMIT_USE_CODE = 500005;
|
||||
public static final String USER_NAME_LIMIT_USE_MSG = "此用户名限制使用";
|
||||
//演示用户不允许删除
|
||||
public static final int USER_LIMIT_DELETE_CODE = 500006;
|
||||
public static final String USER_LIMIT_DELETE_MSG = "抱歉,演示模式下的演示用户不允许删除";
|
||||
//演示用户不允许修改
|
||||
public static final int USER_LIMIT_UPDATE_CODE = 500007;
|
||||
public static final String USER_LIMIT_UPDATE_MSG = "抱歉,演示模式下的演示用户不允许修改";
|
||||
//启用的用户数量超出限制
|
||||
public static final int USER_ENABLE_OVER_LIMIT_FAILED_CODE = 500006;
|
||||
public static final String USER_ENABLE_OVER_LIMIT_FAILED_MSG = "启用的用户数量超出限制,请联系平台管理员";
|
||||
//租户不能被删除
|
||||
public static final int USER_LIMIT_TENANT_DELETE_CODE = 500008;
|
||||
public static final String USER_LIMIT_TENANT_DELETE_MSG = "抱歉,租户不能被删除";
|
||||
@@ -519,11 +510,4 @@ public class ExceptionConstants {
|
||||
success.put(GLOBAL_RETURNS_MESSAGE, SERVICE_SUCCESS_MSG);
|
||||
return success;
|
||||
}
|
||||
|
||||
public static JSONObject standardErrorUserOver () {
|
||||
JSONObject success = new JSONObject();
|
||||
success.put(GLOBAL_RETURNS_CODE, USER_OVER_LIMIT_FAILED_CODE);
|
||||
success.put(GLOBAL_RETURNS_MESSAGE, USER_OVER_LIMIT_FAILED_MSG);
|
||||
return success;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -444,7 +444,7 @@ public class UserController {
|
||||
Byte status = jsonObject.getByte("status");
|
||||
String ids = jsonObject.getString("ids");
|
||||
Map<String, Object> objectMap = new HashMap<>();
|
||||
int res = userService.batchSetStatus(status, ids);
|
||||
int res = userService.batchSetStatus(status, ids, request);
|
||||
if(res > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else {
|
||||
@@ -466,7 +466,7 @@ public class UserController {
|
||||
Long userId = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userId").toString());
|
||||
User user = userService.getUser(userId);
|
||||
//获取当前用户数
|
||||
Long userCurrentNum = userService.countUser(null, null);
|
||||
int userCurrentNum = userService.getUser().size();
|
||||
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
|
||||
data.put("type", tenant.getType()); //租户类型,0免费租户,1付费租户
|
||||
data.put("expireTime", Tools.parseDateToStr(tenant.getExpireTime()));
|
||||
|
||||
@@ -6,6 +6,8 @@ public class TenantEx extends Tenant{
|
||||
|
||||
private String expireTimeStr;
|
||||
|
||||
private Integer userCount;
|
||||
|
||||
public String getCreateTimeStr() {
|
||||
return createTimeStr;
|
||||
}
|
||||
@@ -21,4 +23,12 @@ public class TenantEx extends Tenant{
|
||||
public void setExpireTimeStr(String expireTimeStr) {
|
||||
this.expireTimeStr = expireTimeStr;
|
||||
}
|
||||
|
||||
public Integer getUserCount() {
|
||||
return userCount;
|
||||
}
|
||||
|
||||
public void setUserCount(Integer userCount) {
|
||||
this.userCount = userCount;
|
||||
}
|
||||
}
|
||||
@@ -30,4 +30,6 @@ public interface UserMapperEx {
|
||||
|
||||
List<TreeNodeEx> getNodeTree();
|
||||
List<TreeNodeEx> getNextNodeTree(Map<String, Object> parameterMap);
|
||||
|
||||
void disableUserByLimit(@Param("tenantId") Long tenantId);
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.datasource.mappers.TenantMapper;
|
||||
import com.jsh.erp.datasource.mappers.TenantMapperEx;
|
||||
import com.jsh.erp.datasource.mappers.UserMapperEx;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.exception.JshException;
|
||||
import com.jsh.erp.service.log.LogService;
|
||||
@@ -33,6 +34,9 @@ public class TenantService {
|
||||
@Resource
|
||||
private TenantMapperEx tenantMapperEx;
|
||||
|
||||
@Resource
|
||||
private UserMapperEx userMapperEx;
|
||||
|
||||
@Resource
|
||||
private LogService logService;
|
||||
|
||||
@@ -113,6 +117,8 @@ public class TenantService {
|
||||
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
|
||||
int result=0;
|
||||
try{
|
||||
//如果租户下的用户限制数量为1,则将该租户之外的用户全部禁用
|
||||
userMapperEx.disableUserByLimit(tenant.getTenantId());
|
||||
result=tenantMapper.updateByPrimaryKeySelective(tenant);
|
||||
}catch(Exception e){
|
||||
JshException.writeFail(logger, e);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jsh.erp.service.user;
|
||||
|
||||
import com.jsh.erp.datasource.entities.*;
|
||||
import com.jsh.erp.exception.BusinessParamCheckingException;
|
||||
import com.jsh.erp.service.functions.FunctionService;
|
||||
import com.jsh.erp.service.redis.RedisService;
|
||||
import com.jsh.erp.service.role.RoleService;
|
||||
@@ -778,12 +779,27 @@ public class UserService {
|
||||
}
|
||||
|
||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
||||
public int batchSetStatus(Byte status, String ids)throws Exception {
|
||||
public int batchSetStatus(Byte status, String ids, HttpServletRequest request)throws Exception {
|
||||
int result=0;
|
||||
StringBuilder userStr = new StringBuilder();
|
||||
List<User> list = getUserListByIds(ids);
|
||||
//选中的用户的数量
|
||||
int selectUserSize = list.size();
|
||||
//查询启用状态的用户的数量
|
||||
int enableUserSize = getUser().size();
|
||||
long userNumLimit = Long.parseLong(redisService.getObjectFromSessionByKey(request,"userNumLimit").toString());
|
||||
if(selectUserSize + enableUserSize > userNumLimit && status == 0) {
|
||||
throw new BusinessParamCheckingException(ExceptionConstants.USER_ENABLE_OVER_LIMIT_FAILED_CODE,
|
||||
ExceptionConstants.USER_ENABLE_OVER_LIMIT_FAILED_MSG);
|
||||
}
|
||||
StringBuilder userStr = new StringBuilder();
|
||||
List<Long> idList = new ArrayList<>();
|
||||
for(User user: list) {
|
||||
userStr.append(user.getLoginName()).append(" ");
|
||||
if(user.getId().equals(user.getTenantId())) {
|
||||
//租户不能进行禁用
|
||||
} else {
|
||||
idList.add(user.getId());
|
||||
userStr.append(user.getLoginName()).append(" ");
|
||||
}
|
||||
}
|
||||
String statusStr ="";
|
||||
if(status == 0) {
|
||||
@@ -791,15 +807,18 @@ public class UserService {
|
||||
} else if(status == 2) {
|
||||
statusStr ="批量禁用";
|
||||
}
|
||||
logService.insertLog("用户",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userStr).append("-").append(statusStr).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
List<Long> idList = StringUtil.strToLongList(ids);
|
||||
User user = new User();
|
||||
user.setStatus(status);
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andIdIn(idList);
|
||||
result = userMapper.updateByExampleSelective(user, example);
|
||||
if(idList.size()>0) {
|
||||
User user = new User();
|
||||
user.setStatus(status);
|
||||
UserExample example = new UserExample();
|
||||
example.createCriteria().andIdIn(idList);
|
||||
result = userMapper.updateByExampleSelective(user, example);
|
||||
logService.insertLog("用户",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userStr).append("-").append(statusStr).toString(),
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||
} else {
|
||||
result = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user