add
This commit is contained in:
25
qiaoba-modules/qiaoba-module-tenant/pom.xml
Normal file
25
qiaoba-modules/qiaoba-module-tenant/pom.xml
Normal file
@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>qiaoba-modules</artifactId>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<version>1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>qiaoba-module-tenant</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-api-system</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.qiaoba</groupId>
|
||||
<artifactId>qiaoba-auth</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,73 @@
|
||||
package com.qiaoba.module.tenant.controller;
|
||||
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.common.base.result.AjaxResult;
|
||||
import com.qiaoba.common.base.validate.AddGroup;
|
||||
import com.qiaoba.common.base.validate.EditGroup;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.tenant.entity.SysTenant;
|
||||
import com.qiaoba.module.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.module.tenant.service.SysTenantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 租户管理 Web层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 10:52
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/tenant")
|
||||
@RequiredArgsConstructor
|
||||
@Tag(name = "租户管理")
|
||||
public class SysTenantController {
|
||||
|
||||
private final SysTenantService sysTenantService;
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:add')")
|
||||
@PostMapping
|
||||
@Operation(summary = "新增租户")
|
||||
public AjaxResult add(@Validated(AddGroup.class) @RequestBody SysTenant sysTenant) {
|
||||
return AjaxResult.toAjax(sysTenantService.insert(sysTenant));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:query')")
|
||||
@GetMapping(value = "/{tenantId}")
|
||||
@Operation(summary = "获取详情")
|
||||
public AjaxResult getInfo(@PathVariable String tenantId) {
|
||||
return AjaxResult.success(sysTenantService.selectById(tenantId));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:edit')")
|
||||
@PutMapping
|
||||
@Operation(summary = "修改租户")
|
||||
public AjaxResult edit(@Validated(EditGroup.class) @RequestBody SysTenant sysTenant) {
|
||||
return AjaxResult.toAjax(sysTenantService.update(sysTenant));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('tenant:list')")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获取列表")
|
||||
public TableDataInfo<SysTenant> list(SysTenantParam param, PageQuery pageQuery) {
|
||||
return sysTenantService.selectPageList(param, pageQuery);
|
||||
}
|
||||
|
||||
@GetMapping("/normal-list")
|
||||
@Operation(summary = "获取正常列表")
|
||||
public TableDataInfo<SysTenant> normalPageList(SysTenantParam param, PageQuery pageQuery) {
|
||||
param.setTime(new Date());
|
||||
param.setStatus(BaseEnum.NORMAL.getCode());
|
||||
param.setType(SysTenantParam.TYPE_NOT_EXPIRED);
|
||||
param.setIsLogin(true);
|
||||
return sysTenantService.selectPageList(param, pageQuery);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.qiaoba.module.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 jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 租户 sys_tenant
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 10:20
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("sys_tenant")
|
||||
public class SysTenant extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId
|
||||
@NotNull(message = "id不能为空", groups = {EditGroup.class})
|
||||
private String tenantId;
|
||||
|
||||
@NotBlank(message = "企业名称不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "企业名称")
|
||||
private String companyName;
|
||||
|
||||
@Schema(description = "联系人")
|
||||
private String contactName;
|
||||
|
||||
@Schema(description = "联系电话")
|
||||
private String contactPhone;
|
||||
|
||||
@Schema(description = "地址")
|
||||
private String address;
|
||||
|
||||
@Schema(description = "企业简介")
|
||||
private String profile;
|
||||
|
||||
@Schema(description = "统一社会信用代码")
|
||||
private String licenseNumber;
|
||||
|
||||
@Schema(description = "域名")
|
||||
private String domain;
|
||||
|
||||
@Schema(description = "备注")
|
||||
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;
|
||||
|
||||
@NotNull(message = "状态不能为空", groups = {AddGroup.class, EditGroup.class})
|
||||
@Schema(description = "状态")
|
||||
private String status;
|
||||
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.qiaoba.module.tenant.entity.param;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 租户查询条件
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 11:02
|
||||
*/
|
||||
@Data
|
||||
public class SysTenantParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 未过期
|
||||
*/
|
||||
public static final String TYPE_NOT_EXPIRED = "1";
|
||||
|
||||
/**
|
||||
* 已过期
|
||||
*/
|
||||
public static final String TYPE_EXPIRED = "2";
|
||||
|
||||
private String companyName;
|
||||
|
||||
private String contactName;
|
||||
|
||||
@Schema(description = "帐号状态(1正常 0停用)")
|
||||
private String status;
|
||||
|
||||
private Date time;
|
||||
|
||||
@Schema(description = "类型(1正常 2过期)")
|
||||
private String type;
|
||||
|
||||
private Boolean isLogin = false;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.qiaoba.module.tenant.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.qiaoba.module.tenant.entity.SysTenant;
|
||||
|
||||
/**
|
||||
* 租户管理 数据层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 11:08
|
||||
*/
|
||||
public interface SysTenantMapper extends BaseMapper<SysTenant> {
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.qiaoba.module.tenant.service;
|
||||
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.tenant.entity.SysTenant;
|
||||
import com.qiaoba.module.tenant.entity.param.SysTenantParam;
|
||||
|
||||
/**
|
||||
* 租户管理 服务层
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 10:55
|
||||
*/
|
||||
public interface SysTenantService {
|
||||
|
||||
/**
|
||||
* 新增租户
|
||||
*
|
||||
* @param sysTenant 租户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int insert(SysTenant sysTenant);
|
||||
|
||||
/**
|
||||
* 修改租户
|
||||
*
|
||||
* @param sysTenant 租户信息
|
||||
* @return 结果
|
||||
*/
|
||||
int update(SysTenant sysTenant);
|
||||
|
||||
/**
|
||||
* 获取租户列表
|
||||
*
|
||||
* @param param param
|
||||
* @param pageQuery 分页参数
|
||||
* @return list
|
||||
*/
|
||||
TableDataInfo<SysTenant> selectPageList(SysTenantParam param, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询详情
|
||||
*
|
||||
* @param tenantId tenantId
|
||||
* @return info
|
||||
*/
|
||||
SysTenant selectById(String tenantId);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.qiaoba.module.tenant.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.qiaoba.auth.utils.SecurityUtil;
|
||||
import com.qiaoba.common.base.enums.BaseEnum;
|
||||
import com.qiaoba.common.database.entity.PageQuery;
|
||||
import com.qiaoba.common.database.entity.TableDataInfo;
|
||||
import com.qiaoba.module.tenant.entity.SysTenant;
|
||||
import com.qiaoba.module.tenant.entity.param.SysTenantParam;
|
||||
import com.qiaoba.module.tenant.mapper.SysTenantMapper;
|
||||
import com.qiaoba.module.tenant.service.SysTenantService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 租户管理 服务层实现
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/30 10:55
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysTenantServiceImpl implements SysTenantService {
|
||||
|
||||
private final SysTenantMapper sysTenantMapper;
|
||||
|
||||
@Override
|
||||
public int insert(SysTenant sysTenant) {
|
||||
sysTenant.setCreateTime(new Date());
|
||||
sysTenant.setCreateUser(SecurityUtil.getLoginUsername());
|
||||
sysTenant.setStatus(BaseEnum.NORMAL.getCode());
|
||||
return sysTenantMapper.insert(sysTenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(SysTenant sysTenant) {
|
||||
sysTenant.setUpdateTime(new Date());
|
||||
sysTenant.setUpdateUser(SecurityUtil.getLoginUsername());
|
||||
return sysTenantMapper.updateById(sysTenant);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<SysTenant> selectPageList(SysTenantParam param, PageQuery pageQuery) {
|
||||
return TableDataInfo.build(sysTenantMapper.selectPage(pageQuery.build(), param2Wrapper(param)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysTenant selectById(String tenantId) {
|
||||
return sysTenantMapper.selectById(tenantId);
|
||||
}
|
||||
|
||||
private QueryWrapper<SysTenant> param2Wrapper(SysTenantParam param) {
|
||||
QueryWrapper<SysTenant> wrapper = new QueryWrapper<>();
|
||||
wrapper.lambda()
|
||||
.eq(StrUtil.isNotBlank(param.getStatus()), SysTenant::getStatus, param.getStatus())
|
||||
.like(StrUtil.isNotBlank(param.getCompanyName()), SysTenant::getCompanyName, param.getCompanyName())
|
||||
.like(StrUtil.isNotBlank(param.getContactName()), SysTenant::getContactName, param.getContactName());
|
||||
|
||||
// 查未过期
|
||||
if (SysTenantParam.TYPE_NOT_EXPIRED.equals(param.getType())) {
|
||||
wrapper.lambda().ge(Objects.nonNull(param.getTime()), SysTenant::getExpireTime, param.getTime());
|
||||
}
|
||||
// 查已过期
|
||||
else {
|
||||
wrapper.lambda().lt(Objects.nonNull(param.getTime()), SysTenant::getExpireTime, param.getTime());
|
||||
}
|
||||
|
||||
// 登录接口
|
||||
if (param.getIsLogin()) {
|
||||
wrapper.lambda()
|
||||
.select(SysTenant::getCompanyName, SysTenant::getTenantId);
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user