add
This commit is contained in:
@ -3,16 +3,10 @@ package com.qiaoba.api.tenant.entity;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.qiaoba.common.base.entity.BaseEntity;
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
import com.qiaoba.common.base.validate.EditGroup;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@ -31,52 +25,28 @@ public class SysTenant extends BaseEntity {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
@NotNull(message = "ID不能为空", groups = {EditGroup.class})
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "企业名称")
|
||||
@NotBlank(message = "企业名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Size(max = 30, message = "企业名称不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String companyName;
|
||||
|
||||
@Schema(description = "联系人")
|
||||
@Size(max = 30, message = "联系人不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String contactName;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
@Size(max = 30, message = "联系电话不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String contactPhone;
|
||||
|
||||
@Schema(description = "地址")
|
||||
@Size(max = 30, message = "地址不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String address;
|
||||
|
||||
@Schema(description = "企业简介")
|
||||
@Size(max = 30, message = "企业简介不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String profile;
|
||||
|
||||
@Schema(description = "统一社会信用代码")
|
||||
@Size(max = 20, message = "企业简介不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String licenseNumber;
|
||||
|
||||
@Schema(description = "域名")
|
||||
private String domain;
|
||||
|
||||
@Schema(description = "备注")
|
||||
@Size(max = 20, message = "备注不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String remark;
|
||||
|
||||
@NotNull(message = "过期时间不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "过期时间")
|
||||
private Date expireTime;
|
||||
|
||||
@NotNull(message = "用户数量不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "用户数量")
|
||||
private Long accountCount;
|
||||
|
||||
@Schema(description = "状态")
|
||||
@NotNull(message = "状态不能为空", groups = {EditGroup.class})
|
||||
@Size(max = 1, message = "状态不能超过{max}个字符", groups = {EditGroup.class})
|
||||
private String status;
|
||||
|
||||
private String mode;
|
||||
@ -88,5 +58,4 @@ public class SysTenant extends BaseEntity {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,69 @@
|
||||
package com.qiaoba.api.tenant.entity.dto;
|
||||
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
import com.qiaoba.common.base.validate.EditGroup;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 租户 dto
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/7/14 0014 上午 10:25
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SysTenantDto implements Serializable {
|
||||
|
||||
@NotNull(message = "ID不能为空", groups = {EditGroup.class})
|
||||
private String tenantId;
|
||||
|
||||
@Schema(description = "企业名称")
|
||||
@NotBlank(message = "企业名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Size(max = 30, message = "企业名称不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String companyName;
|
||||
|
||||
@Schema(description = "联系人")
|
||||
@Size(max = 30, message = "联系人不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String contactName;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
@Size(max = 11, message = "联系电话不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String contactPhone;
|
||||
|
||||
@Schema(description = "地址")
|
||||
@Size(max = 255, message = "地址不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String address;
|
||||
|
||||
@Schema(description = "企业简介")
|
||||
@Size(max = 500, message = "企业简介不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String profile;
|
||||
|
||||
@Schema(description = "统一社会信用代码")
|
||||
@Size(max = 20, message = "企业简介不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String licenseNumber;
|
||||
|
||||
@Schema(description = "域名")
|
||||
private String domain;
|
||||
|
||||
@Schema(description = "备注")
|
||||
@Size(max = 500, message = "备注不能超过{max}个字符", groups = {AddGroup.class, EditGroup.class})
|
||||
private String remark;
|
||||
|
||||
@NotNull(message = "过期时间不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "过期时间")
|
||||
private Date expireTime;
|
||||
|
||||
@NotNull(message = "用户数量不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "用户数量")
|
||||
private Long accountCount;
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import com.qiaoba.api.job.annotation.Log;
|
||||
import com.qiaoba.api.job.enums.BusinessType;
|
||||
import com.qiaoba.api.tenant.entity.SysTenant;
|
||||
import com.qiaoba.api.tenant.entity.dto.SysTenantDto;
|
||||
import com.qiaoba.api.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
@ -38,8 +39,8 @@ public class SysTenantController {
|
||||
@PostMapping
|
||||
@Operation(summary = "新增租户")
|
||||
@Log(title = "新增租户", businessType = BusinessType.INSERT)
|
||||
public AjaxResult add(@Validated(AddGroup.class) @RequestBody SysTenant sysTenant) {
|
||||
return AjaxResult.toAjax(sysTenantService.insert(sysTenant));
|
||||
public AjaxResult add(@Validated(AddGroup.class) @RequestBody SysTenantDto dto) {
|
||||
return AjaxResult.toAjax(sysTenantService.insert(dto));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:query')")
|
||||
@ -53,8 +54,8 @@ public class SysTenantController {
|
||||
@PutMapping
|
||||
@Operation(summary = "修改租户")
|
||||
@Log(title = "修改租户", businessType = BusinessType.UPDATE)
|
||||
public AjaxResult edit(@Validated(EditGroup.class) @RequestBody SysTenant sysTenant) {
|
||||
return AjaxResult.toAjax(sysTenantService.update(sysTenant));
|
||||
public AjaxResult edit(@Validated(EditGroup.class) @RequestBody SysTenantDto dto) {
|
||||
return AjaxResult.toAjax(sysTenantService.update(dto));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:list')")
|
||||
@ -71,10 +72,10 @@ public class SysTenantController {
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:edit')")
|
||||
@PutMapping("/setting")
|
||||
@PutMapping("/update-mode")
|
||||
@Operation(summary = "修改模式")
|
||||
public AjaxResult setting(TenantSettingDto dto) {
|
||||
return AjaxResult.success(sysTenantService.update(BeanUtil.copyProperties(dto, SysTenant.class)));
|
||||
public AjaxResult updateMode(TenantSettingDto dto) {
|
||||
return AjaxResult.toAjax(sysTenantService.updateMode(dto));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:remove')")
|
||||
|
@ -1,9 +1,11 @@
|
||||
package com.qiaoba.module.tenant.service;
|
||||
|
||||
import com.qiaoba.api.tenant.entity.SysTenant;
|
||||
import com.qiaoba.api.tenant.entity.dto.SysTenantDto;
|
||||
import com.qiaoba.api.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.tenant.entity.dto.TenantSettingDto;
|
||||
|
||||
/**
|
||||
* 租户管理 服务层
|
||||
@ -17,18 +19,18 @@ public interface SysTenantService {
|
||||
/**
|
||||
* 新增租户
|
||||
*
|
||||
* @param sysTenant 租户信息
|
||||
* @param dto 租户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(SysTenant sysTenant);
|
||||
int insert(SysTenantDto dto);
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
*
|
||||
* @param sysTenant 租户信息
|
||||
* @param dto 租户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int update(SysTenant sysTenant);
|
||||
int update(SysTenantDto dto);
|
||||
|
||||
/**
|
||||
* 获取租户列表
|
||||
@ -76,4 +78,19 @@ public interface SysTenantService {
|
||||
* 更新缓存
|
||||
*/
|
||||
void resetCache();
|
||||
|
||||
/**
|
||||
* 修改模式
|
||||
*
|
||||
* @param dto dto
|
||||
* @return 结果
|
||||
*/
|
||||
int updateMode(TenantSettingDto dto);
|
||||
|
||||
/**
|
||||
* 完成初始化
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
int initCompleted(String tenantId);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ import com.qiaoba.api.tenant.entity.SysTenantDatasource;
|
||||
import com.qiaoba.api.tenant.enums.TenantModeEnum;
|
||||
import com.qiaoba.common.base.code.DatasourceErrorCode;
|
||||
import com.qiaoba.common.base.code.TenantErrorCode;
|
||||
import com.qiaoba.common.base.constant.BaseConstant;
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.common.base.enums.DataBaseEnum;
|
||||
import com.qiaoba.common.base.exception.ServiceException;
|
||||
@ -161,10 +162,10 @@ public class SysTenantInitServiceImpl implements SysTenantInitService {
|
||||
|
||||
@Override
|
||||
public void initCompleted(String tenantId) {
|
||||
SysTenant sysTenant = new SysTenant();
|
||||
sysTenant.setTenantId(tenantId);
|
||||
sysTenant.setInitialized(BaseEnum.YES.getCode());
|
||||
sysTenantService.update(sysTenant);
|
||||
int result = sysTenantService.initCompleted(tenantId);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
// 缓存相关 todo
|
||||
}
|
||||
}
|
||||
|
||||
private void checkInitialized(SysTenant sysTenant) {
|
||||
|
@ -1,8 +1,11 @@
|
||||
package com.qiaoba.module.tenant.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiaoba.api.tenant.entity.SysTenant;
|
||||
import com.qiaoba.api.tenant.entity.dto.SysTenantDto;
|
||||
import com.qiaoba.api.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.api.tenant.service.SysTenantApiService;
|
||||
import com.qiaoba.api.auth.utils.SecurityUtil;
|
||||
@ -15,6 +18,7 @@ import com.qiaoba.common.base.exception.ServiceException;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.common.redis.service.RedisService;
|
||||
import com.qiaoba.module.tenant.entity.dto.TenantSettingDto;
|
||||
import com.qiaoba.module.tenant.mapper.SysTenantMapper;
|
||||
import com.qiaoba.module.tenant.service.SysTenantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@ -42,7 +46,8 @@ public class SysTenantServiceImpl implements SysTenantService, SysTenantApiServi
|
||||
private final RedisService redisService;
|
||||
|
||||
@Override
|
||||
public int insert(SysTenant sysTenant) {
|
||||
public int insert(SysTenantDto dto) {
|
||||
SysTenant sysTenant = BeanUtil.copyProperties(dto, SysTenant.class);
|
||||
checkCompanyNameIsExist(sysTenant);
|
||||
sysTenant.setCreateTime(new Date());
|
||||
sysTenant.setCreateUser(SecurityUtil.getLoginUsername());
|
||||
@ -56,13 +61,21 @@ public class SysTenantServiceImpl implements SysTenantService, SysTenantApiServi
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(SysTenant sysTenant) {
|
||||
public int update(SysTenantDto dto) {
|
||||
SysTenant oldTenant = selectById(dto.getTenantId());
|
||||
if (BaseEnum.ABNORMAL.getCode().equals(oldTenant.getStatus())) {
|
||||
throw new ServiceException(TenantErrorCode.DISABLE.getCode(), TenantErrorCode.DISABLE.getMsg());
|
||||
}
|
||||
SysTenant sysTenant = BeanUtil.copyProperties(dto, SysTenant.class);
|
||||
checkCompanyNameIsExist(sysTenant);
|
||||
if (DateUtil.compare(sysTenant.getExpireTime(), new Date()) > 0) {
|
||||
sysTenant.setStatus(BaseEnum.NORMAL.getCode());
|
||||
}
|
||||
sysTenant.setUpdateTime(new Date());
|
||||
sysTenant.setUpdateUser(SecurityUtil.getLoginUsername());
|
||||
int result = sysTenantMapper.updateById(sysTenant);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
toCache(sysTenant);
|
||||
toCache(selectById(sysTenant.getTenantId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -111,6 +124,28 @@ public class SysTenantServiceImpl implements SysTenantService, SysTenantApiServi
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateMode(TenantSettingDto dto) {
|
||||
SysTenant sysTenant = BeanUtil.copyProperties(dto, SysTenant.class);
|
||||
int result = sysTenantMapper.updateById(sysTenant);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
toCache(selectById(sysTenant.getTenantId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int initCompleted(String tenantId) {
|
||||
SysTenant sysTenant = new SysTenant();
|
||||
sysTenant.setTenantId(tenantId);
|
||||
sysTenant.setInitialized(BaseEnum.YES.getCode());
|
||||
int result = sysTenantMapper.updateById(sysTenant);
|
||||
if (result > BaseConstant.HANDLE_ERROR) {
|
||||
toCache(selectById(sysTenant.getTenantId()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private QueryWrapper<SysTenant> param2Wrapper(SysTenantParam param) {
|
||||
QueryWrapper<SysTenant> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
|
Reference in New Issue
Block a user