解决超管从后台创建租户报错的bug

This commit is contained in:
jishenghua 2024-06-20 22:52:28 +08:00
parent f8ea188267
commit aa58b36145
2 changed files with 28 additions and 20 deletions

View File

@ -44,11 +44,8 @@ public class TenantService {
@Resource
private LogService logService;
@Value("${tenant.userNumLimit}")
private Integer userNumLimit;
@Value("${tenant.tryDayLimit}")
private Integer tryDayLimit;
@Value("${manage.roleId}")
private Integer manageRoleId;
public Tenant getTenant(long id)throws Exception {
Tenant result=null;
@ -103,18 +100,14 @@ public class TenantService {
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertTenant(JSONObject obj, HttpServletRequest request)throws Exception {
Tenant tenant = JSONObject.parseObject(obj.toJSONString(), Tenant.class);
int result=0;
UserEx ue = JSONObject.parseObject(obj.toJSONString(), UserEx.class);
int result = 0;
try{
tenant.setCreateTime(new Date());
if(tenant.getUserNumLimit()==null) {
tenant.setUserNumLimit(userNumLimit); //默认用户限制数量
}
if(tenant.getExpireTime()==null) {
tenant.setExpireTime(Tools.addDays(new Date(), tryDayLimit)); //租户允许试用的天数
}
result = tenantMapper.insertSelective(tenant);
}catch(Exception e){
ue.setUsername(ue.getLoginName());
userService.checkLoginName(ue); //检查登录名
userService.registerUser(ue,manageRoleId,request);
result = 1;
} catch(Exception e){
JshException.writeFail(logger, e);
}
return result;

View File

@ -1,6 +1,7 @@
package com.jsh.erp.service.user;
import com.jsh.erp.datasource.entities.*;
import com.jsh.erp.datasource.mappers.TenantMapper;
import com.jsh.erp.exception.BusinessParamCheckingException;
import com.jsh.erp.service.functions.FunctionService;
import com.jsh.erp.service.platformConfig.PlatformConfigService;
@ -43,7 +44,8 @@ public class UserService {
@Resource
private UserMapper userMapper;
@Resource
private TenantMapper tenantMapper;
@Resource
private UserMapperEx userMapperEx;
@Resource
@ -65,6 +67,12 @@ public class UserService {
@Resource
private RedisService redisService;
@Value("${tenant.userNumLimit}")
private Integer userNumLimit;
@Value("${tenant.tryDayLimit}")
private Integer tryDayLimit;
public User getUser(long id)throws Exception {
User result=null;
try{
@ -585,9 +593,8 @@ public class UserService {
ue.setIsmanager(BusinessConstants.USER_NOT_MANAGER);
}
ue.setStatus(BusinessConstants.USER_STATUS_NORMAL);
int result=0;
try{
result= userMapper.insertSelective(ue);
userMapper.insertSelective(ue);
Long userId = getIdByLoginName(ue.getLoginName());
ue.setId(userId);
}catch(Exception e){
@ -614,7 +621,15 @@ public class UserService {
tenantObj.put("userNumLimit", ue.getUserNumLimit());
tenantObj.put("expireTime", ue.getExpireTime());
tenantObj.put("remark", ue.getRemark());
tenantService.insertTenant(tenantObj, request);
Tenant tenant = JSONObject.parseObject(tenantObj.toJSONString(), Tenant.class);
tenant.setCreateTime(new Date());
if(tenant.getUserNumLimit()==null) {
tenant.setUserNumLimit(userNumLimit); //默认用户限制数量
}
if(tenant.getExpireTime()==null) {
tenant.setExpireTime(Tools.addDays(new Date(), tryDayLimit)); //租户允许试用的天数
}
tenantMapper.insertSelective(tenant);
logger.info("===============创建租户信息完成===============");
}
}