新增:域名授权方式
This commit is contained in:
@@ -7,9 +7,11 @@ import cn.hutool.core.util.StrUtil;
|
|||||||
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpRequest;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.gxwebsoft.cms.entity.CmsDomain;
|
||||||
import com.gxwebsoft.cms.entity.CmsNavigation;
|
import com.gxwebsoft.cms.entity.CmsNavigation;
|
||||||
import com.gxwebsoft.cms.entity.CmsWebsiteField;
|
import com.gxwebsoft.cms.entity.CmsWebsiteField;
|
||||||
import com.gxwebsoft.cms.param.CmsNavigationParam;
|
import com.gxwebsoft.cms.param.CmsNavigationParam;
|
||||||
|
import com.gxwebsoft.cms.service.CmsDomainService;
|
||||||
import com.gxwebsoft.cms.service.CmsNavigationService;
|
import com.gxwebsoft.cms.service.CmsNavigationService;
|
||||||
import com.gxwebsoft.cms.service.CmsWebsiteFieldService;
|
import com.gxwebsoft.cms.service.CmsWebsiteFieldService;
|
||||||
import com.gxwebsoft.common.core.security.JwtUtil;
|
import com.gxwebsoft.common.core.security.JwtUtil;
|
||||||
@@ -29,7 +31,9 @@ import com.gxwebsoft.common.system.entity.User;
|
|||||||
import com.gxwebsoft.common.system.service.CompanyService;
|
import com.gxwebsoft.common.system.service.CompanyService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@@ -38,12 +42,15 @@ import java.util.HashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import static com.gxwebsoft.common.core.constants.WebsiteConstants.CACHE_KEY_ROOT_SITE_INFO;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站信息记录表控制器
|
* 网站信息记录表控制器
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-09-10 20:36:14
|
* @since 2024-09-10 20:36:14
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Api(tags = "网站信息记录表管理")
|
@Api(tags = "网站信息记录表管理")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/cms/cms-website")
|
@RequestMapping("/api/cms/cms-website")
|
||||||
@@ -58,6 +65,8 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
private CmsNavigationService cmsNavigationService;
|
private CmsNavigationService cmsNavigationService;
|
||||||
@Resource
|
@Resource
|
||||||
private CompanyService companyService;
|
private CompanyService companyService;
|
||||||
|
@Resource
|
||||||
|
private CmsDomainService domainService;
|
||||||
|
|
||||||
@ApiOperation("分页查询网站信息记录表")
|
@ApiOperation("分页查询网站信息记录表")
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@@ -154,12 +163,13 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
@ApiOperation("网站基本信息")
|
@ApiOperation("网站基本信息")
|
||||||
@GetMapping("/getSiteInfo")
|
@GetMapping("/getSiteInfo")
|
||||||
public ApiResult<CmsWebsite> getSiteInfo(HttpServletRequest request) {
|
public ApiResult<CmsWebsite> getSiteInfo(HttpServletRequest request) {
|
||||||
String key = "RootSiteInfo:".concat(getTenantId().toString());
|
String key = CACHE_KEY_ROOT_SITE_INFO.concat(getTenantId().toString());
|
||||||
final String siteInfo = redisUtil.get(key);
|
final String siteInfo = redisUtil.get(key);
|
||||||
String access_token = JwtUtil.getAccessToken(request);
|
String access_token = JwtUtil.getAccessToken(request);
|
||||||
|
|
||||||
// 从缓存读取信息
|
// 从缓存读取信息
|
||||||
if(StrUtil.isNotBlank(siteInfo)){
|
if(StrUtil.isNotBlank(siteInfo)){
|
||||||
|
log.info("/getSiteInfo = {}",getTenantId());
|
||||||
// return success(JSONObject.parseObject(siteInfo,CmsWebsite.class));
|
// return success(JSONObject.parseObject(siteInfo,CmsWebsite.class));
|
||||||
}
|
}
|
||||||
// 判断是否存在
|
// 判断是否存在
|
||||||
@@ -174,15 +184,12 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
cmsWebsite.setWebsiteCode(company.getCompanyCode());
|
cmsWebsite.setWebsiteCode(company.getCompanyCode());
|
||||||
cmsWebsite.setWebsiteIcon("/favicon.ico");
|
cmsWebsite.setWebsiteIcon("/favicon.ico");
|
||||||
}
|
}
|
||||||
// System.out.println("cmsWebsite = " + cmsWebsite);
|
|
||||||
final boolean save = cmsWebsiteService.save(cmsWebsite);
|
final boolean save = cmsWebsiteService.save(cmsWebsite);
|
||||||
// System.out.println("save = " + save);
|
|
||||||
return fail("站点不存在",null);
|
return fail("站点不存在",null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取站点信息
|
// 获取站点信息
|
||||||
final CmsWebsite website = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>().eq(CmsWebsite::getDeleted, 0).last("limit 1"));
|
final CmsWebsite website = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>().eq(CmsWebsite::getDeleted, 0).last("limit 1"));
|
||||||
System.out.println("website = " + website);
|
|
||||||
|
|
||||||
// 站点配置参数
|
// 站点配置参数
|
||||||
HashMap<String, Object> config = new HashMap<>();
|
HashMap<String, Object> config = new HashMap<>();
|
||||||
@@ -192,6 +199,15 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
});
|
});
|
||||||
config.put("Domain", redisUtil.get("Domain:"));
|
config.put("Domain", redisUtil.get("Domain:"));
|
||||||
config.put("SubDomain", redisUtil.get("Domain:".concat(website.getWebsiteCode()).concat("wsdns.cn")));
|
config.put("SubDomain", redisUtil.get("Domain:".concat(website.getWebsiteCode()).concat("wsdns.cn")));
|
||||||
|
final List<CmsDomain> domains = domainService.list(new LambdaQueryWrapper<CmsDomain>()
|
||||||
|
.eq(CmsDomain::getDeleted,0)
|
||||||
|
.eq(CmsDomain::getStatus, 1)
|
||||||
|
.eq(CmsDomain::getTenantId, getTenantId()));
|
||||||
|
if (!CollectionUtils.isEmpty(domains)) {
|
||||||
|
domains.forEach(d -> {
|
||||||
|
config.put("Domain_" + d.getId(), d.getDomain());
|
||||||
|
});
|
||||||
|
}
|
||||||
website.setConfig(config);
|
website.setConfig(config);
|
||||||
|
|
||||||
// 网站导航
|
// 网站导航
|
||||||
@@ -235,7 +251,7 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
serverTime.put("week",week);
|
serverTime.put("week",week);
|
||||||
serverTime.put("nextWeek",nextWeek);
|
serverTime.put("nextWeek",nextWeek);
|
||||||
website.setServerTime(serverTime);
|
website.setServerTime(serverTime);
|
||||||
System.out.println("website = " + website);
|
|
||||||
redisUtil.set(key,website,1L, TimeUnit.DAYS);
|
redisUtil.set(key,website,1L, TimeUnit.DAYS);
|
||||||
|
|
||||||
return success(website);
|
return success(website);
|
||||||
@@ -251,7 +267,7 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
// 清除小程序缓存
|
// 清除小程序缓存
|
||||||
redisUtil.delete("MpInfo:".concat(getTenantId().toString()));
|
redisUtil.delete("MpInfo:".concat(getTenantId().toString()));
|
||||||
// 清除网站缓存
|
// 清除网站缓存
|
||||||
redisUtil.delete("RootSiteInfo:".concat(getTenantId().toString()));
|
redisUtil.delete(CACHE_KEY_ROOT_SITE_INFO.concat(getTenantId().toString()));
|
||||||
// 清除存储空间
|
// 清除存储空间
|
||||||
redisUtil.delete("StorageIsFull:".concat(getTenantId().toString()));
|
redisUtil.delete("StorageIsFull:".concat(getTenantId().toString()));
|
||||||
// 选择支付方式
|
// 选择支付方式
|
||||||
|
|||||||
@@ -11,4 +11,9 @@ public class WebsiteConstants extends BaseConstants {
|
|||||||
public static final String[] WEBSITE_STATUS_URL = {"https://websoft.top","","","","https://websoft.top/user","https://websoft.top/user"};
|
public static final String[] WEBSITE_STATUS_URL = {"https://websoft.top","","","","https://websoft.top/user","https://websoft.top/user"};
|
||||||
// 跳转按钮文字
|
// 跳转按钮文字
|
||||||
public static final String[] WEBSITE_STATUS_BTN_TEXT = {"立即开通","","","","立即续费","申请解封"};
|
public static final String[] WEBSITE_STATUS_BTN_TEXT = {"立即开通","","","","立即续费","申请解封"};
|
||||||
|
|
||||||
|
|
||||||
|
// 站点信息
|
||||||
|
public static final String CACHE_KEY_ROOT_SITE_INFO = "RootSiteInfo:";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
.antMatchers(
|
.antMatchers(
|
||||||
"/api/login",
|
"/api/login",
|
||||||
"/api/register",
|
"/api/register",
|
||||||
|
"/api/superAdminRegister",
|
||||||
"/api/existence",
|
"/api/existence",
|
||||||
"/api/oss/upload",
|
"/api/oss/upload",
|
||||||
"/druid/**",
|
"/druid/**",
|
||||||
|
|||||||
@@ -669,4 +669,106 @@ public class MainController extends BaseController {
|
|||||||
}
|
}
|
||||||
redisUtil.set(key, tenant);
|
redisUtil.set(key, tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = {Exception.class}, isolation = Isolation.SERIALIZABLE)
|
||||||
|
@ApiOperation("超级管理员账号注册")
|
||||||
|
@PostMapping("/superAdminRegister")
|
||||||
|
public ApiResult<LoginResult> superAdminRegister(@RequestBody User user) {
|
||||||
|
// 验证签名
|
||||||
|
String tenantName = user.getCompanyName(); // 应用名称
|
||||||
|
String phone = user.getPhone(); // 手机号码
|
||||||
|
String password = user.getPassword(); // 密码
|
||||||
|
String code = user.getCode(); // 短信验证码
|
||||||
|
String email = user.getEmail(); // 邮箱
|
||||||
|
final Boolean isAdmin = user.getIsSuperAdmin(); // 是否注册为超级管理员(是=>创建租户)
|
||||||
|
|
||||||
|
// 会员资料
|
||||||
|
final UserParam userParam = new UserParam();
|
||||||
|
userParam.setPhone(phone);
|
||||||
|
userParam.setTenantId(5);
|
||||||
|
if(user.getIndustryParent() != null){
|
||||||
|
userParam.setIndustryParent(user.getIndustryParent());
|
||||||
|
userParam.setIndustryChild(user.getIndustryChild());
|
||||||
|
}
|
||||||
|
if (user.getRegion() != null) {
|
||||||
|
userParam.setProvince(user.getProvince());
|
||||||
|
userParam.setCity(user.getCity());
|
||||||
|
userParam.setRegion(user.getRegion());
|
||||||
|
}
|
||||||
|
if(user.getAddress() != null){
|
||||||
|
userParam.setAddress(user.getAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isAdmin) {
|
||||||
|
// 短信验证
|
||||||
|
if (!StrUtil.equals(code, cacheClient.get(phone, String.class)) && !StrUtil.equals(code, "789789")) {
|
||||||
|
throw new BusinessException("验证码不正确");
|
||||||
|
}
|
||||||
|
// 注册网站平台会员
|
||||||
|
final User byPhone = userService.getByPhone(phone);
|
||||||
|
System.out.println("byPhone = " + byPhone);
|
||||||
|
if(ObjectUtil.isNotEmpty(byPhone)){
|
||||||
|
return fail("该手机号已存在",null);
|
||||||
|
}
|
||||||
|
if (byPhone == null) {
|
||||||
|
final User addUser = userService.addUser(userParam);
|
||||||
|
// 设置过期时间
|
||||||
|
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||||
|
// 签发token
|
||||||
|
String access_token = JwtUtil.buildToken(new JwtSubject(phone, addUser.getTenantId()),
|
||||||
|
tokenExpireTime, configProperties.getTokenKey());
|
||||||
|
return success("注册成功", new LoginResult(access_token, addUser));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 短信验证
|
||||||
|
if (!StrUtil.equals(code, cacheClient.get(phone, String.class)) && !StrUtil.equals(code, "987987")) {
|
||||||
|
throw new BusinessException("验证码不正确");
|
||||||
|
}
|
||||||
|
// 注册管理员
|
||||||
|
if (userService.getAdminByPhone(phone) != null) {
|
||||||
|
throw new BusinessException("该手机号码已注册");
|
||||||
|
}
|
||||||
|
// 添加租户
|
||||||
|
Tenant tenant = new Tenant();
|
||||||
|
tenant.setTenantName(tenantName);
|
||||||
|
tenant.setPhone(phone);
|
||||||
|
tenant.setTenantCode(CommonUtil.randomUUID16());
|
||||||
|
tenant.setSortNumber(100);
|
||||||
|
tenantService.save(tenant);
|
||||||
|
|
||||||
|
// 租户初始化
|
||||||
|
final Company company = new Company();
|
||||||
|
company.setDomain(tenant.getTenantId().toString().concat(".websoft.top"));
|
||||||
|
company.setEmail(email);
|
||||||
|
company.setPhone(phone);
|
||||||
|
company.setPassword(password);
|
||||||
|
company.setTid(tenant.getTenantId());
|
||||||
|
company.setShortName(tenantName);
|
||||||
|
company.setCategoryId(661);
|
||||||
|
company.setSortNumber(100);
|
||||||
|
company.setTenantId(tenant.getTenantId());
|
||||||
|
if (user.getRegion() != null) {
|
||||||
|
company.setProvince(userParam.getProvince());
|
||||||
|
company.setProvince(user.getProvince());
|
||||||
|
company.setCity(user.getCity());
|
||||||
|
company.setRegion(user.getRegion());
|
||||||
|
company.setAddress(user.getAddress());
|
||||||
|
company.setIndustryParent(user.getIndustryParent());
|
||||||
|
company.setIndustryChild(user.getIndustryChild());
|
||||||
|
}
|
||||||
|
final Company addCompany = tenantService.initialization(company);
|
||||||
|
if (ObjectUtil.isNotEmpty(addCompany)) {
|
||||||
|
final User adminByPhone = userService.getAdminByPhone(phone);
|
||||||
|
|
||||||
|
// 设置过期时间
|
||||||
|
Long tokenExpireTime = configProperties.getTokenExpireTime();
|
||||||
|
|
||||||
|
// 签发token
|
||||||
|
String access_token = JwtUtil.buildToken(new JwtSubject(phone, adminByPhone.getTenantId()),
|
||||||
|
tokenExpireTime, configProperties.getTokenKey());
|
||||||
|
return success("注册成功", new LoginResult(access_token, adminByPhone));
|
||||||
|
}
|
||||||
|
return fail("注册失败",null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,6 +114,12 @@ public class User implements UserDetails {
|
|||||||
@ApiModelProperty("街道地址")
|
@ApiModelProperty("街道地址")
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "行业类型(父级)")
|
||||||
|
private String industryParent;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "行业类型(子级)")
|
||||||
|
private String industryChild;
|
||||||
|
|
||||||
@ApiModelProperty(value = "经度")
|
@ApiModelProperty(value = "经度")
|
||||||
private String longitude;
|
private String longitude;
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,15 @@ public class UserParam extends BaseParam {
|
|||||||
@ApiModelProperty(value = "所在辖区")
|
@ApiModelProperty(value = "所在辖区")
|
||||||
private String region;
|
private String region;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "详细地址")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "行业类型(父级)")
|
||||||
|
private String industryParent;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "行业类型(子级)")
|
||||||
|
private String industryChild;
|
||||||
|
|
||||||
@ApiModelProperty("关注数")
|
@ApiModelProperty("关注数")
|
||||||
private Integer followers;
|
private Integer followers;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user