增加多租户的功能

This commit is contained in:
季圣华
2019-06-27 18:01:08 +08:00
parent a6223e57db
commit 97111a9c82
16 changed files with 1632 additions and 45 deletions

View File

@@ -7,10 +7,12 @@ import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Tenant;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.entities.UserEx;
import com.jsh.erp.datasource.vo.TreeNodeEx;
import com.jsh.erp.exception.BusinessParamCheckingException;
import com.jsh.erp.service.tenant.TenantService;
import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
@@ -52,6 +54,9 @@ public class UserController {
@Resource
private UserService userService;
@Resource
private TenantService tenantService;
private static String message = "成功";
private static final String HTTP = "http://";
private static final String CODE_OK = "200";
@@ -107,19 +112,15 @@ public class UserController {
msgTip = "user can login";
request.getSession().setAttribute("user",user);
if(("open").equals(mybatisPlusStatus)) {
String url = HTTP + manageIp + ":" + managePort + "/tenant/getTenant?tenantId=" + user.getTenantId();
JSONObject obj = HttpClient.httpGet(url);
if(obj!=null && obj.getString("code").equals(CODE_OK)) {
JSONObject dataObj = obj.getJSONObject("data");
if(dataObj!=null) {
String tenantId = dataObj.getString("tenantId");
String userNumLimit = dataObj.getString("userNumLimit");
String billsNumLimit = dataObj.getString("billsNumLimit");
if(tenantId!=null) {
request.getSession().setAttribute("tenantId",tenantId); //租户tenantId
request.getSession().setAttribute("userNumLimit",userNumLimit); //用户限制数
request.getSession().setAttribute("billsNumLimit",billsNumLimit); //单据限制数
}
Tenant tenant = tenantService.getTenantByTenantId(user.getTenantId());
if(tenant!=null) {
Long tenantId = tenant.getTenantId();
Integer userNumLimit = tenant.getUserNumLimit();
Integer billsNumLimit = tenant.getBillsNumLimit();
if(tenantId!=null) {
request.getSession().setAttribute("tenantId",tenantId); //租户tenantId
request.getSession().setAttribute("userNumLimit",userNumLimit); //用户限制数
request.getSession().setAttribute("billsNumLimit",billsNumLimit); //单据限制数
}
}
}
@@ -351,33 +352,7 @@ public class UserController {
ue.setLoginame(loginame);
ue.setPassword(password);
userService.checkUserNameAndLoginName(ue); //检查用户名和登录名
ue = userService.registerUser(ue,manageRoleId);
/**
* create by: qiankunpingtai
* create time: 2019/4/9 17:17
* websitehttps://qiankunpingtai.cn
* description:
* 这里涉及到多个项目,需要用分布式事务去处理
* 为了不使问题复杂化,暂时另外开启一个线程去处理其它项目的数据操作
*/
final UserEx ueFinal=ue;
final ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.execute(() -> {
try{
//调第三方接口创建租户管理信息
String url = HTTP + manageIp + ":" + managePort + "/tenant/add";
JSONObject tenantObj = new JSONObject();
tenantObj.put("tenantId", ueFinal.getId());
tenantObj.put("loginName",ueFinal.getLoginame());
String param = URLEncoder.encode(tenantObj.toString());
HttpClient.httpPost(url + "?info=" + param, param);
logger.info("===============创建租户信息完成===============");
}catch(Exception e){
//记录一下第三方接口创建租户管理信息创建失败
logger.debug("调用第三方接口创建租户管理信息失败tenantId[{}],loginName:[{}]",ueFinal.getId(),ueFinal.getLoginame());
}
});
ue = userService.registerUser(ue,manageRoleId,request);
return result;
}
/**