commit
ac1ced7459
@ -1,9 +0,0 @@
|
|||||||
package cn.iocoder.yudao.adminserver.framework.async.config;
|
|
||||||
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
|
||||||
|
|
||||||
@Configuration
|
|
||||||
@EnableAsync
|
|
||||||
public class AsyncConfiguration {
|
|
||||||
}
|
|
||||||
@ -0,0 +1,106 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.controller.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.*;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.convert.tenant.SysTenantConvert;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.service.tenant.SysTenantService;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||||
|
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||||
|
|
||||||
|
@Api(tags = "租户")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/tenant")
|
||||||
|
public class SysTenantController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysTenantService tenantService;
|
||||||
|
|
||||||
|
@GetMapping("/get-id-by-name")
|
||||||
|
@ApiOperation(value = "使用租户名,获得租户编号", notes = "登录界面,根据用户的租户名,获得租户编号")
|
||||||
|
@ApiImplicitParam(name = "name", value = "租户名", required = true, example = "芋道源码", dataTypeClass = Long.class)
|
||||||
|
public CommonResult<Long> getTenantIdByName(@RequestParam("name") String name) {
|
||||||
|
SysTenantDO tenantDO = tenantService.getTenantByName(name);
|
||||||
|
return success(tenantDO != null ? tenantDO.getId() : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@ApiOperation("创建租户")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:create')")
|
||||||
|
public CommonResult<Long> createTenant(@Valid @RequestBody SysTenantCreateReqVO createReqVO) {
|
||||||
|
return success(tenantService.createTenant(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@ApiOperation("更新租户")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:update')")
|
||||||
|
public CommonResult<Boolean> updateTenant(@Valid @RequestBody SysTenantUpdateReqVO updateReqVO) {
|
||||||
|
tenantService.updateTenant(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@ApiOperation("删除租户")
|
||||||
|
@ApiImplicitParam(name = "id", value = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:delete')")
|
||||||
|
public CommonResult<Boolean> deleteTenant(@RequestParam("id") Long id) {
|
||||||
|
tenantService.deleteTenant(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@ApiOperation("获得租户")
|
||||||
|
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:query')")
|
||||||
|
public CommonResult<SysTenantRespVO> getTenant(@RequestParam("id") Long id) {
|
||||||
|
SysTenantDO tenant = tenantService.getTenant(id);
|
||||||
|
return success(SysTenantConvert.INSTANCE.convert(tenant));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("获得租户列表")
|
||||||
|
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:query')")
|
||||||
|
public CommonResult<List<SysTenantRespVO>> getTenantList(@RequestParam("ids") Collection<Long> ids) {
|
||||||
|
List<SysTenantDO> list = tenantService.getTenantList(ids);
|
||||||
|
return success(SysTenantConvert.INSTANCE.convertList(list));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("获得租户分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:query')")
|
||||||
|
public CommonResult<PageResult<SysTenantRespVO>> getTenantPage(@Valid SysTenantPageReqVO pageVO) {
|
||||||
|
PageResult<SysTenantDO> pageResult = tenantService.getTenantPage(pageVO);
|
||||||
|
return success(SysTenantConvert.INSTANCE.convertPage(pageResult));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@ApiOperation("导出租户 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:tenant:export')")
|
||||||
|
@OperateLog(type = EXPORT)
|
||||||
|
public void exportTenantExcel(@Valid SysTenantExportReqVO exportReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
List<SysTenantDO> list = tenantService.getTenantList(exportReqVO);
|
||||||
|
// 导出 Excel
|
||||||
|
List<SysTenantExcelVO> datas = SysTenantConvert.INSTANCE.convertList02(list);
|
||||||
|
ExcelUtils.write(response, "租户.xls", "数据", SysTenantExcelVO.class, datas);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,14 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
@ApiModel("租户创建 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class SysTenantCreateReqVO extends SysTenantBaseVO {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,19 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
|
||||||
|
@ApiModel("租户 Response VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class SysTenantRespVO extends SysTenantBaseVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "租户编号", required = true, example = "1024")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间", required = true)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo;
|
||||||
|
|
||||||
|
import lombok.*;
|
||||||
|
import java.util.*;
|
||||||
|
import io.swagger.annotations.*;
|
||||||
|
import javax.validation.constraints.*;
|
||||||
|
|
||||||
|
@ApiModel("租户更新 Request VO")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
public class SysTenantUpdateReqVO extends SysTenantBaseVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "租户编号", required = true, example = "1024")
|
||||||
|
@NotNull(message = "租户编号不能为空")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,3 +1,4 @@
|
|||||||
### 请求 /system/user/page 接口 => 没有权限
|
### 请求 /system/user/page 接口 => 没有权限
|
||||||
GET {{baseUrl}}/system/user/page?pageNo=1&pageSize=10
|
GET {{baseUrl}}/system/user/page?pageNo=1&pageSize=10
|
||||||
Authorization: Bearer test104 # 使用测试账号
|
Authorization: Bearer test1 # 使用测试账号
|
||||||
|
tenant-id: 1
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.convert.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantCreateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantExcelVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantRespVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import org.mapstruct.Mapper;
|
||||||
|
import org.mapstruct.factory.Mappers;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 Convert
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysTenantConvert {
|
||||||
|
|
||||||
|
SysTenantConvert INSTANCE = Mappers.getMapper(SysTenantConvert.class);
|
||||||
|
|
||||||
|
SysTenantDO convert(SysTenantCreateReqVO bean);
|
||||||
|
|
||||||
|
SysTenantDO convert(SysTenantUpdateReqVO bean);
|
||||||
|
|
||||||
|
SysTenantRespVO convert(SysTenantDO bean);
|
||||||
|
|
||||||
|
List<SysTenantRespVO> convertList(List<SysTenantDO> list);
|
||||||
|
|
||||||
|
PageResult<SysTenantRespVO> convertPage(PageResult<SysTenantDO> page);
|
||||||
|
|
||||||
|
List<SysTenantExcelVO> convertList02(List<SysTenantDO> list);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,44 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.dal.mysql.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantExportReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantPageReqVO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 Mapper
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface SysTenantMapper extends BaseMapperX<SysTenantDO> {
|
||||||
|
|
||||||
|
default PageResult<SysTenantDO> selectPage(SysTenantPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new QueryWrapperX<SysTenantDO>()
|
||||||
|
.likeIfPresent("name", reqVO.getName())
|
||||||
|
.likeIfPresent("contact_name", reqVO.getContactName())
|
||||||
|
.likeIfPresent("contact_mobile", reqVO.getContactMobile())
|
||||||
|
.eqIfPresent("status", reqVO.getStatus())
|
||||||
|
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||||
|
.orderByDesc("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
default List<SysTenantDO> selectList(SysTenantExportReqVO reqVO) {
|
||||||
|
return selectList(new QueryWrapperX<SysTenantDO>()
|
||||||
|
.likeIfPresent("name", reqVO.getName())
|
||||||
|
.likeIfPresent("contact_name", reqVO.getContactName())
|
||||||
|
.likeIfPresent("contact_mobile", reqVO.getContactMobile())
|
||||||
|
.eqIfPresent("status", reqVO.getStatus())
|
||||||
|
.betweenIfPresent("create_time", reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||||
|
.orderByDesc("id"));
|
||||||
|
}
|
||||||
|
|
||||||
|
default SysTenantDO selectByName(String name) {
|
||||||
|
return selectOne("name", name);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.framework.datapermission.config;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
|
||||||
|
import cn.iocoder.yudao.framework.datapermission.core.dept.rule.DeptDataPermissionRuleCustomizer;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* system 模块的数据权限 Configuration
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class SysDataPermissionConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public DeptDataPermissionRuleCustomizer sysDeptDataPermissionRuleCustomizer() {
|
||||||
|
return rule -> {
|
||||||
|
rule.addDeptColumn(SysUserDO.class);
|
||||||
|
rule.addDeptColumn(SysDeptDO.class, "id");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
/**
|
||||||
|
* system 模块的数据权限配置
|
||||||
|
*/
|
||||||
|
package cn.iocoder.yudao.adminserver.modules.system.framework.datapermission;
|
||||||
@ -0,0 +1,83 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.service.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantCreateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantExportReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantPageReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 Service 接口
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
public interface SysTenantService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建租户
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createTenant(@Valid SysTenantCreateReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新租户
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateTenant(@Valid SysTenantUpdateReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除租户
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteTenant(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得租户
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 租户
|
||||||
|
*/
|
||||||
|
SysTenantDO getTenant(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得租户列表
|
||||||
|
*
|
||||||
|
* @param ids 编号
|
||||||
|
* @return 租户列表
|
||||||
|
*/
|
||||||
|
List<SysTenantDO> getTenantList(Collection<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得租户分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 租户分页
|
||||||
|
*/
|
||||||
|
PageResult<SysTenantDO> getTenantPage(SysTenantPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得租户列表, 用于 Excel 导出
|
||||||
|
*
|
||||||
|
* @param exportReqVO 查询条件
|
||||||
|
* @return 租户列表
|
||||||
|
*/
|
||||||
|
List<SysTenantDO> getTenantList(SysTenantExportReqVO exportReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得名字对应的租户
|
||||||
|
*
|
||||||
|
* @param name 组户名
|
||||||
|
* @return 租户
|
||||||
|
*/
|
||||||
|
SysTenantDO getTenantByName(String name);
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.service.tenant.impl;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantCreateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantExportReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantPageReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.convert.tenant.SysTenantConvert;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.tenant.SysTenantMapper;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.service.tenant.SysTenantService;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.TENANT_NOT_EXISTS;
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 租户 Service 实现类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class SysTenantServiceImpl implements SysTenantService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysTenantMapper tenantMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createTenant(SysTenantCreateReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
SysTenantDO tenant = SysTenantConvert.INSTANCE.convert(createReqVO);
|
||||||
|
tenantMapper.insert(tenant);
|
||||||
|
// 返回
|
||||||
|
return tenant.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTenant(SysTenantUpdateReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
this.validateTenantExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
SysTenantDO updateObj = SysTenantConvert.INSTANCE.convert(updateReqVO);
|
||||||
|
tenantMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteTenant(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
this.validateTenantExists(id);
|
||||||
|
// 删除
|
||||||
|
tenantMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void validateTenantExists(Long id) {
|
||||||
|
if (tenantMapper.selectById(id) == null) {
|
||||||
|
throw exception(TENANT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTenantDO getTenant(Long id) {
|
||||||
|
return tenantMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysTenantDO> getTenantList(Collection<Long> ids) {
|
||||||
|
return tenantMapper.selectBatchIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<SysTenantDO> getTenantPage(SysTenantPageReqVO pageReqVO) {
|
||||||
|
return tenantMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SysTenantDO> getTenantList(SysTenantExportReqVO exportReqVO) {
|
||||||
|
return tenantMapper.selectList(exportReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTenantDO getTenantByName(String name) {
|
||||||
|
return tenantMapper.selectByName(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,181 @@
|
|||||||
|
package cn.iocoder.yudao.adminserver.modules.system.service.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.adminserver.BaseDbUnitTest;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantCreateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantExportReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantPageReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.controller.tenant.vo.SysTenantUpdateReqVO;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.dal.mysql.tenant.SysTenantMapper;
|
||||||
|
import cn.iocoder.yudao.adminserver.modules.system.service.tenant.impl.SysTenantServiceImpl;
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.TENANT_NOT_EXISTS;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.buildTime;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link SysTenantServiceImpl} 的单元测试类
|
||||||
|
*
|
||||||
|
* @author 芋道源码
|
||||||
|
*/
|
||||||
|
@Import(SysTenantServiceImpl.class)
|
||||||
|
public class SysTenantServiceTest extends BaseDbUnitTest {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysTenantServiceImpl tenantService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private SysTenantMapper tenantMapper;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateTenant_success() {
|
||||||
|
// 准备参数
|
||||||
|
SysTenantCreateReqVO reqVO = randomPojo(SysTenantCreateReqVO.class, o -> o.setStatus(randomCommonStatus()));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
Long tenantId = tenantService.createTenant(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertNotNull(tenantId);
|
||||||
|
// 校验记录的属性是否正确
|
||||||
|
SysTenantDO tenant = tenantMapper.selectById(tenantId);
|
||||||
|
assertPojoEquals(reqVO, tenant);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTenant_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysTenantDO dbTenant = randomPojo(SysTenantDO.class, o -> o.setStatus(randomCommonStatus()));
|
||||||
|
tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
SysTenantUpdateReqVO reqVO = randomPojo(SysTenantUpdateReqVO.class, o -> {
|
||||||
|
o.setId(dbTenant.getId()); // 设置更新的 ID
|
||||||
|
o.setStatus(randomCommonStatus());
|
||||||
|
});
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
tenantService.updateTenant(reqVO);
|
||||||
|
// 校验是否更新正确
|
||||||
|
SysTenantDO tenant = tenantMapper.selectById(reqVO.getId()); // 获取最新的
|
||||||
|
assertPojoEquals(reqVO, tenant);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testUpdateTenant_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
SysTenantUpdateReqVO reqVO = randomPojo(SysTenantUpdateReqVO.class);
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> tenantService.updateTenant(reqVO), TENANT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTenant_success() {
|
||||||
|
// mock 数据
|
||||||
|
SysTenantDO dbTenant = randomPojo(SysTenantDO.class,
|
||||||
|
o -> o.setStatus(randomCommonStatus()));
|
||||||
|
tenantMapper.insert(dbTenant);// @Sql: 先插入出一条存在的数据
|
||||||
|
// 准备参数
|
||||||
|
Long id = dbTenant.getId();
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
tenantService.deleteTenant(id);
|
||||||
|
// 校验数据不存在了
|
||||||
|
assertNull(tenantMapper.selectById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteTenant_notExists() {
|
||||||
|
// 准备参数
|
||||||
|
Long id = randomLongId();
|
||||||
|
|
||||||
|
// 调用, 并断言异常
|
||||||
|
assertServiceException(() -> tenantService.deleteTenant(id), TENANT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTenantPage() {
|
||||||
|
// mock 数据
|
||||||
|
SysTenantDO dbTenant = randomPojo(SysTenantDO.class, o -> { // 等会查询到
|
||||||
|
o.setName("芋道源码");
|
||||||
|
o.setContactName("芋艿");
|
||||||
|
o.setContactMobile("15601691300");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
o.setCreateTime(buildTime(2020, 12, 12));
|
||||||
|
});
|
||||||
|
tenantMapper.insert(dbTenant);
|
||||||
|
// 测试 name 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setName(randomString())));
|
||||||
|
// 测试 contactName 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactName(randomString())));
|
||||||
|
// 测试 contactMobile 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactMobile(randomString())));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setCreateTime(buildTime(2021, 12, 12))));
|
||||||
|
// 准备参数
|
||||||
|
SysTenantPageReqVO reqVO = new SysTenantPageReqVO();
|
||||||
|
reqVO.setName("芋道");
|
||||||
|
reqVO.setContactName("艿");
|
||||||
|
reqVO.setContactMobile("1560");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
reqVO.setBeginCreateTime(buildTime(2020, 12, 1));
|
||||||
|
reqVO.setEndCreateTime(buildTime(2020, 12, 24));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
PageResult<SysTenantDO> pageResult = tenantService.getTenantPage(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, pageResult.getTotal());
|
||||||
|
assertEquals(1, pageResult.getList().size());
|
||||||
|
assertPojoEquals(dbTenant, pageResult.getList().get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetTenantList() {
|
||||||
|
// mock 数据
|
||||||
|
SysTenantDO dbTenant = randomPojo(SysTenantDO.class, o -> { // 等会查询到
|
||||||
|
o.setName("芋道源码");
|
||||||
|
o.setContactName("芋艿");
|
||||||
|
o.setContactMobile("15601691300");
|
||||||
|
o.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
o.setCreateTime(buildTime(2020, 12, 12));
|
||||||
|
});
|
||||||
|
tenantMapper.insert(dbTenant);
|
||||||
|
// 测试 name 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setName(randomString())));
|
||||||
|
// 测试 contactName 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactName(randomString())));
|
||||||
|
// 测试 contactMobile 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setContactMobile(randomString())));
|
||||||
|
// 测试 status 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus())));
|
||||||
|
// 测试 createTime 不匹配
|
||||||
|
tenantMapper.insert(cloneIgnoreId(dbTenant, o -> o.setCreateTime(buildTime(2021, 12, 12))));
|
||||||
|
// 准备参数
|
||||||
|
SysTenantExportReqVO reqVO = new SysTenantExportReqVO();
|
||||||
|
reqVO.setName("芋道");
|
||||||
|
reqVO.setContactName("艿");
|
||||||
|
reqVO.setContactMobile("1560");
|
||||||
|
reqVO.setStatus(CommonStatusEnum.ENABLE.getStatus());
|
||||||
|
reqVO.setBeginCreateTime(buildTime(2020, 12, 1));
|
||||||
|
reqVO.setEndCreateTime(buildTime(2020, 12, 24));
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
List<SysTenantDO> list = tenantService.getTenantList(reqVO);
|
||||||
|
// 断言
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
assertPojoEquals(dbTenant, list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
import request from '@/utils/request'
|
||||||
|
|
||||||
|
// 创建租户
|
||||||
|
export function createTenant(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/create',
|
||||||
|
method: 'post',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新租户
|
||||||
|
export function updateTenant(data) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/update',
|
||||||
|
method: 'put',
|
||||||
|
data: data
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除租户
|
||||||
|
export function deleteTenant(id) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/delete?id=' + id,
|
||||||
|
method: 'delete'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得租户
|
||||||
|
export function getTenant(id) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/get?id=' + id,
|
||||||
|
method: 'get'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获得租户分页
|
||||||
|
export function getTenantPage(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/page',
|
||||||
|
method: 'get',
|
||||||
|
params: query
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 导出租户 Excel
|
||||||
|
export function exportTenantExcel(query) {
|
||||||
|
return request({
|
||||||
|
url: '/system/tenant/export-excel',
|
||||||
|
method: 'get',
|
||||||
|
params: query,
|
||||||
|
responseType: 'blob'
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package cn.iocoder.yudao.coreservice.modules.system.dal.mysql.tenant;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.tenant.SysTenantDO;
|
||||||
|
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface SysTenantCoreMapper extends BaseMapperX<SysTenantDO> {
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue