优化租户管理的编辑功能
This commit is contained in:
@@ -75,6 +75,8 @@ public class TenantConfig {
|
|||||||
// 过滤自定义查询此时无租户信息约束出现
|
// 过滤自定义查询此时无租户信息约束出现
|
||||||
if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) {
|
if ("com.jsh.erp.datasource.mappers.UserMapperEx.getUserListByUserNameOrLoginName".equals(ms.getId())) {
|
||||||
return true;
|
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())) {
|
} else if ("com.jsh.erp.datasource.mappers.RoleMapperEx.getRoleWithoutTenant".equals(ms.getId())) {
|
||||||
return true;
|
return true;
|
||||||
} else if ("com.jsh.erp.datasource.mappers.LogMapperEx.insertLogWithUserId".equals(ms.getId())) {
|
} 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 int SERVICE_SYSTEM_ERROR_CODE = 500;
|
||||||
public static final String SERVICE_SYSTEM_ERROR_MSG = "未知异常";
|
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 String USER_LOGIN_NAME_ALREADY_EXISTS_MSG = "登录名在本系统已存在";
|
||||||
//用户录入数量超出限制
|
//用户录入数量超出限制
|
||||||
public static final int USER_OVER_LIMIT_FAILED_CODE = 500004;
|
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 int USER_NAME_LIMIT_USE_CODE = 500005;
|
||||||
public static final String USER_NAME_LIMIT_USE_MSG = "此用户名限制使用";
|
public static final String USER_NAME_LIMIT_USE_MSG = "此用户名限制使用";
|
||||||
//演示用户不允许删除
|
//启用的用户数量超出限制
|
||||||
public static final int USER_LIMIT_DELETE_CODE = 500006;
|
public static final int USER_ENABLE_OVER_LIMIT_FAILED_CODE = 500006;
|
||||||
public static final String USER_LIMIT_DELETE_MSG = "抱歉,演示模式下的演示用户不允许删除";
|
public static final String USER_ENABLE_OVER_LIMIT_FAILED_MSG = "启用的用户数量超出限制,请联系平台管理员";
|
||||||
//演示用户不允许修改
|
|
||||||
public static final int USER_LIMIT_UPDATE_CODE = 500007;
|
|
||||||
public static final String USER_LIMIT_UPDATE_MSG = "抱歉,演示模式下的演示用户不允许修改";
|
|
||||||
//租户不能被删除
|
//租户不能被删除
|
||||||
public static final int USER_LIMIT_TENANT_DELETE_CODE = 500008;
|
public static final int USER_LIMIT_TENANT_DELETE_CODE = 500008;
|
||||||
public static final String USER_LIMIT_TENANT_DELETE_MSG = "抱歉,租户不能被删除";
|
public static final String USER_LIMIT_TENANT_DELETE_MSG = "抱歉,租户不能被删除";
|
||||||
@@ -519,11 +510,4 @@ public class ExceptionConstants {
|
|||||||
success.put(GLOBAL_RETURNS_MESSAGE, SERVICE_SUCCESS_MSG);
|
success.put(GLOBAL_RETURNS_MESSAGE, SERVICE_SUCCESS_MSG);
|
||||||
return success;
|
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");
|
Byte status = jsonObject.getByte("status");
|
||||||
String ids = jsonObject.getString("ids");
|
String ids = jsonObject.getString("ids");
|
||||||
Map<String, Object> objectMap = new HashMap<>();
|
Map<String, Object> objectMap = new HashMap<>();
|
||||||
int res = userService.batchSetStatus(status, ids);
|
int res = userService.batchSetStatus(status, ids, request);
|
||||||
if(res > 0) {
|
if(res > 0) {
|
||||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||||
} else {
|
} else {
|
||||||
@@ -466,7 +466,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);
|
||||||
//获取当前用户数
|
//获取当前用户数
|
||||||
Long userCurrentNum = userService.countUser(null, null);
|
int userCurrentNum = userService.getUser().size();
|
||||||
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
|
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
|
||||||
data.put("type", tenant.getType()); //租户类型,0免费租户,1付费租户
|
data.put("type", tenant.getType()); //租户类型,0免费租户,1付费租户
|
||||||
data.put("expireTime", Tools.parseDateToStr(tenant.getExpireTime()));
|
data.put("expireTime", Tools.parseDateToStr(tenant.getExpireTime()));
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ public class TenantEx extends Tenant{
|
|||||||
|
|
||||||
private String expireTimeStr;
|
private String expireTimeStr;
|
||||||
|
|
||||||
|
private Integer userCount;
|
||||||
|
|
||||||
public String getCreateTimeStr() {
|
public String getCreateTimeStr() {
|
||||||
return createTimeStr;
|
return createTimeStr;
|
||||||
}
|
}
|
||||||
@@ -21,4 +23,12 @@ public class TenantEx extends Tenant{
|
|||||||
public void setExpireTimeStr(String expireTimeStr) {
|
public void setExpireTimeStr(String expireTimeStr) {
|
||||||
this.expireTimeStr = 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> getNodeTree();
|
||||||
List<TreeNodeEx> getNextNodeTree(Map<String, Object> parameterMap);
|
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.entities.*;
|
||||||
import com.jsh.erp.datasource.mappers.TenantMapper;
|
import com.jsh.erp.datasource.mappers.TenantMapper;
|
||||||
import com.jsh.erp.datasource.mappers.TenantMapperEx;
|
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.BusinessRunTimeException;
|
||||||
import com.jsh.erp.exception.JshException;
|
import com.jsh.erp.exception.JshException;
|
||||||
import com.jsh.erp.service.log.LogService;
|
import com.jsh.erp.service.log.LogService;
|
||||||
@@ -33,6 +34,9 @@ public class TenantService {
|
|||||||
@Resource
|
@Resource
|
||||||
private TenantMapperEx tenantMapperEx;
|
private TenantMapperEx tenantMapperEx;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserMapperEx userMapperEx;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private LogService logService;
|
private LogService logService;
|
||||||
|
|
||||||
@@ -113,6 +117,8 @@ public class TenantService {
|
|||||||
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
|
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
|
||||||
int result=0;
|
int result=0;
|
||||||
try{
|
try{
|
||||||
|
//如果租户下的用户限制数量为1,则将该租户之外的用户全部禁用
|
||||||
|
userMapperEx.disableUserByLimit(tenant.getTenantId());
|
||||||
result=tenantMapper.updateByPrimaryKeySelective(tenant);
|
result=tenantMapper.updateByPrimaryKeySelective(tenant);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
JshException.writeFail(logger, e);
|
JshException.writeFail(logger, e);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.jsh.erp.service.user;
|
package com.jsh.erp.service.user;
|
||||||
|
|
||||||
import com.jsh.erp.datasource.entities.*;
|
import com.jsh.erp.datasource.entities.*;
|
||||||
|
import com.jsh.erp.exception.BusinessParamCheckingException;
|
||||||
import com.jsh.erp.service.functions.FunctionService;
|
import com.jsh.erp.service.functions.FunctionService;
|
||||||
import com.jsh.erp.service.redis.RedisService;
|
import com.jsh.erp.service.redis.RedisService;
|
||||||
import com.jsh.erp.service.role.RoleService;
|
import com.jsh.erp.service.role.RoleService;
|
||||||
@@ -778,12 +779,27 @@ public class UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
|
@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;
|
int result=0;
|
||||||
StringBuilder userStr = new StringBuilder();
|
|
||||||
List<User> list = getUserListByIds(ids);
|
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) {
|
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 ="";
|
String statusStr ="";
|
||||||
if(status == 0) {
|
if(status == 0) {
|
||||||
@@ -791,15 +807,18 @@ public class UserService {
|
|||||||
} else if(status == 2) {
|
} else if(status == 2) {
|
||||||
statusStr ="批量禁用";
|
statusStr ="批量禁用";
|
||||||
}
|
}
|
||||||
logService.insertLog("用户",
|
if(idList.size()>0) {
|
||||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userStr).append("-").append(statusStr).toString(),
|
User user = new User();
|
||||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
user.setStatus(status);
|
||||||
List<Long> idList = StringUtil.strToLongList(ids);
|
UserExample example = new UserExample();
|
||||||
User user = new User();
|
example.createCriteria().andIdIn(idList);
|
||||||
user.setStatus(status);
|
result = userMapper.updateByExampleSelective(user, example);
|
||||||
UserExample example = new UserExample();
|
logService.insertLog("用户",
|
||||||
example.createCriteria().andIdIn(idList);
|
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userStr).append("-").append(statusStr).toString(),
|
||||||
result = userMapper.updateByExampleSelective(user, example);
|
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
|
||||||
|
} else {
|
||||||
|
result = 1;
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,12 @@
|
|||||||
<mapper namespace="com.jsh.erp.datasource.mappers.TenantMapperEx">
|
<mapper namespace="com.jsh.erp.datasource.mappers.TenantMapperEx">
|
||||||
|
|
||||||
<resultMap extends="com.jsh.erp.datasource.mappers.LogMapper.BaseResultMap" id="ResultMapEx" type="com.jsh.erp.datasource.entities.TenantEx">
|
<resultMap extends="com.jsh.erp.datasource.mappers.LogMapper.BaseResultMap" id="ResultMapEx" type="com.jsh.erp.datasource.entities.TenantEx">
|
||||||
|
<result column="userCount" jdbcType="VARCHAR" property="userCount" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<select id="selectByConditionTenant" parameterType="com.jsh.erp.datasource.entities.TenantExample" resultMap="ResultMapEx">
|
<select id="selectByConditionTenant" parameterType="com.jsh.erp.datasource.entities.TenantExample" resultMap="ResultMapEx">
|
||||||
select *
|
select jsh_tenant.*,
|
||||||
|
(select count(jsh_user.id) from jsh_user where jsh_user.Status='0' and jsh_user.tenant_id=jsh_tenant.tenant_id) userCount
|
||||||
FROM jsh_tenant
|
FROM jsh_tenant
|
||||||
where 1=1
|
where 1=1
|
||||||
<if test="loginName != null">
|
<if test="loginName != null">
|
||||||
|
|||||||
@@ -77,6 +77,7 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<resultMap id="BaseTreeResultMap" type="com.jsh.erp.datasource.vo.TreeNodeEx">
|
<resultMap id="BaseTreeResultMap" type="com.jsh.erp.datasource.vo.TreeNodeEx">
|
||||||
<result column="id" property="id"/>
|
<result column="id" property="id"/>
|
||||||
<result column="text" property="text"/>
|
<result column="text" property="text"/>
|
||||||
@@ -129,4 +130,9 @@
|
|||||||
and ifnull(org_stcd,'0') !='5'
|
and ifnull(org_stcd,'0') !='5'
|
||||||
order by sort asc
|
order by sort asc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<update id="disableUserByLimit">
|
||||||
|
update jsh_user set Status='2'
|
||||||
|
where tenant_id=#{tenantId} and id!=#{tenantId} and Status!='1'
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user