优化租户管理的编辑功能

This commit is contained in:
季圣华 2022-10-23 00:24:34 +08:00
parent d7c0012885
commit b6d1e01233
9 changed files with 66 additions and 35 deletions

View File

@ -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())) {

View File

@ -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;
}
}

View File

@ -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()));

View File

@ -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;
}
}

View File

@ -30,4 +30,6 @@ public interface UserMapperEx {
List<TreeNodeEx> getNodeTree();
List<TreeNodeEx> getNextNodeTree(Map<String, Object> parameterMap);
void disableUserByLimit(@Param("tenantId") Long tenantId);
}

View File

@ -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);

View File

@ -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;
}
}

View File

@ -3,10 +3,12 @@
<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">
<result column="userCount" jdbcType="VARCHAR" property="userCount" />
</resultMap>
<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
where 1=1
<if test="loginName != null">

View File

@ -77,6 +77,7 @@
</foreach>
)
</update>
<resultMap id="BaseTreeResultMap" type="com.jsh.erp.datasource.vo.TreeNodeEx">
<result column="id" property="id"/>
<result column="text" property="text"/>
@ -129,4 +130,9 @@
and ifnull(org_stcd,'0') !='5'
order by sort asc
</select>
<update id="disableUserByLimit">
update jsh_user set Status='2'
where tenant_id=#{tenantId} and id!=#{tenantId} and Status!='1'
</update>
</mapper>