改造租户注册
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package com.gxwebsoft.common.core.constants;
|
||||
|
||||
public class DomainConstants {
|
||||
public static final String ROOT_DOMAIN = "websoft.top"; // 根域名
|
||||
public static final String PREFIX = "https://"; // 域名前缀
|
||||
public static final String ADMIN_SUFFIX = ".".concat(ROOT_DOMAIN); // 后台管理域名拼接
|
||||
public static final String WEB_SUFFIX = ".wsdns.cn"; // 应用域名拼接
|
||||
public static final String DOMAIN = PREFIX.concat(ROOT_DOMAIN); // 完整域名
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.gxwebsoft.common.core.utils;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.DomainConstants.*;
|
||||
|
||||
public class DomainUtil {
|
||||
|
||||
/**
|
||||
* 根域名
|
||||
* @return domain.com
|
||||
*/
|
||||
public static String getRootDomain() {
|
||||
return ROOT_DOMAIN;
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理后台地址
|
||||
* @return https://{tenantId}.websoft.top
|
||||
*/
|
||||
public static String getAdminUrl(String tenantId) {
|
||||
return PREFIX.concat(tenantId).concat(ADMIN_SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* 应用网址
|
||||
* @param tenantId
|
||||
* @return https://{tenantId}.wsdns.cn
|
||||
*/
|
||||
public static String getSiteUrl(String tenantId){
|
||||
return PREFIX.concat(tenantId).concat(WEB_SUFFIX);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -132,8 +132,9 @@ public class CompanyController extends BaseController {
|
||||
company.setTid(tenant.getTenantId());
|
||||
company.setAuthoritative(true);
|
||||
// 添加租户并初始化
|
||||
if (tenantService.initialization(company)) {
|
||||
return success("添加成功");
|
||||
final Company result = tenantService.initialization(company);
|
||||
if (result != null) {
|
||||
return success("添加成功",result);
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@@ -494,7 +494,7 @@ public class MainController extends BaseController {
|
||||
@PostMapping("/register")
|
||||
public ApiResult<?> register(@RequestBody User user) {
|
||||
// 验证签名
|
||||
String tenantName = user.getCompanyName(); // 租户名称
|
||||
String tenantName = user.getCompanyName(); // 应用名称
|
||||
String phone = user.getPhone(); // 手机号码
|
||||
String password = user.getPassword(); // 密码
|
||||
String code = user.getCode(); // 短信验证码
|
||||
@@ -519,8 +519,8 @@ public class MainController extends BaseController {
|
||||
company.setCompanyName(tenantName);
|
||||
company.setShortName(tenantName);
|
||||
company.setTenantId(tenant.getTenantId());
|
||||
tenantService.initialization(company);
|
||||
return success("注册成功", tenant.getTenantId());
|
||||
final Company result = tenantService.initialization(company);
|
||||
return success("注册成功", result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ public interface TenantService extends IService<Tenant> {
|
||||
*/
|
||||
Tenant getByIdRel(Integer tenantId);
|
||||
|
||||
boolean initialization(Company company);
|
||||
Company initialization(Company company);
|
||||
|
||||
boolean destructionAll(Integer tenantId);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.DomainUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.system.entity.*;
|
||||
import com.gxwebsoft.common.system.mapper.TenantMapper;
|
||||
@@ -69,7 +70,7 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean initialization(Company company) {
|
||||
public Company initialization(Company company) {
|
||||
// 添加默认字典
|
||||
Dict dict = new Dict();
|
||||
dict.setDictName("性别");
|
||||
@@ -124,10 +125,9 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
company.setServerUrl("https://server.gxwebsoft.com");
|
||||
company.setModulesUrl("https://modules.gxwebsoft.com");
|
||||
company.setSocketUrl("wss://server.gxwebsoft.com");
|
||||
company.setAdminUrl("http://".concat(company.getTid().toString()).concat(".adm.wsdns.cn"));
|
||||
company.setMerchantUrl("http://".concat(company.getTid().toString()).concat(".m.wsdns.cn"));
|
||||
company.setWebsiteUrl("http://".concat(company.getTid().toString()).concat(".wsdns.cn"));
|
||||
company.setH5Code("http://".concat(company.getTid().toString()).concat(".h5.wsdns.cn"));
|
||||
company.setAdminUrl(DomainUtil.getAdminUrl(company.getTid().toString()));
|
||||
company.setWebsiteUrl(DomainUtil.getSiteUrl(company.getTid().toString()));
|
||||
// company.setH5Code("https://".concat("websoft.top"));
|
||||
// company.setAndroidUrl("http://".concat(company.getTid().toString()).concat(".android.wsdns.cn"));
|
||||
// company.setIosUrl("http://".concat(company.getTid().toString()).concat(".ios.wsdns.cn"));
|
||||
company.setVersion(10);
|
||||
@@ -589,12 +589,16 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
||||
}
|
||||
}
|
||||
// 发送邮件通知
|
||||
String title = "恭喜!您的账号已注册成功";
|
||||
String content = "租户ID:".concat(company.getTid().toString()).concat("\r\n名称:" + company.getShortName()).concat("\r\n账号:" + company.getPhone()).concat("\r\n密码:" + company.getPassword());
|
||||
String adminUrl = "\r\n后台管理:".concat("http://").concat(company.getTid().toString()).concat(".websoft.top");
|
||||
String title = "恭喜!您的应用已创建成功";
|
||||
String appUrl = "\r\n应用地址:" + DomainUtil.getSiteUrl(company.getTid().toString());
|
||||
String appName = "\r\n应用名称:" + company.getShortName();
|
||||
String adminUrl = "\r\n后台管理:" + DomainUtil.getAdminUrl(company.getTid().toString());
|
||||
String account = "\r\n账号:admin";
|
||||
String password = "\r\n密码:" + company.getPassword();
|
||||
String content = title + appUrl + appName + adminUrl + account + password;
|
||||
// 发送邮件通知
|
||||
emailRecordService.sendEmail(title, content.concat(adminUrl), company.getEmail());
|
||||
return true;
|
||||
emailRecordService.sendEmail(title, content, company.getEmail());
|
||||
return company;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
package com.gxwebsoft;
|
||||
|
||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||
import com.gxwebsoft.common.core.utils.DomainUtil;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.DomainConstants.DOMAIN;
|
||||
|
||||
/**
|
||||
* Created by WebSoft on 2020-03-23 23:37
|
||||
*/
|
||||
@@ -16,6 +21,14 @@ public class TestMain {
|
||||
@Test
|
||||
public void testGenJwtKey() {
|
||||
System.out.println(JwtUtil.encodeKey(JwtUtil.randomKey()));
|
||||
|
||||
final String adminUrl = DomainUtil.getAdminUrl("10150");
|
||||
final String rootDomain = DomainUtil.getRootDomain();
|
||||
final String siteUrl = DomainUtil.getSiteUrl("10150");
|
||||
System.out.println("DOMAIN = " + DOMAIN);
|
||||
System.out.println("adminUrl = " + adminUrl);
|
||||
System.out.println("rootDomain = " + rootDomain);
|
||||
System.out.println("siteUrl = " + siteUrl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user