升级 Knife4j 版本 , 增加租户管理的功能
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -28,7 +28,7 @@
|
|||||||
</scm>
|
</scm>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>17</java.version>
|
||||||
<knife4j.version>4.3.0</knife4j.version>
|
<knife4j.version>4.5.0</knife4j.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
* <p>常用调试与文档访问地址:</p>
|
* <p>常用调试与文档访问地址:</p>
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>统一网关代理: https://npmgg.huayang-star.com/nginx/proxy</li>
|
* <li>统一网关代理: https://npmgg.huayang-star.com/nginx/proxy</li>
|
||||||
* <li>本地接口文档: http://localhost:9060/doc.html#/home</li>
|
* <li>本地接口文档: http://localhost:8090/doc.html#/home</li>
|
||||||
* <li>公共接口(硅谷): https://apig.huayang-star.com/doc.html#/home (43.153.123.65)</li>
|
* <li>公共接口(硅谷): https://apig.huayang-star.com/doc.html#/home (43.153.123.65)</li>
|
||||||
* <li>公共接口(上海): https://api.huayang-star.com/doc.html#/home (101.35.52.237)</li>
|
* <li>公共接口(上海): https://api.huayang-star.com/doc.html#/home (101.35.52.237)</li>
|
||||||
* <li>SwaggerUI: http://localhost:9060/swagger-ui/index.html?urls.primaryName=public-api</li>
|
* <li>SwaggerUI: http://localhost:9060/swagger-ui/index.html?urls.primaryName=public-api</li>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.rj.controller;
|
package com.rj.controller;
|
||||||
|
|
||||||
|
import com.rj.entity.Tenant;
|
||||||
import com.rj.service.ITenantService;
|
import com.rj.service.ITenantService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -81,5 +82,56 @@ public class TenantController {
|
|||||||
expireStartTime, expireEndTime);
|
expireStartTime, expireEndTime);
|
||||||
return ResponseEntity.ok(result);
|
return ResponseEntity.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增租户
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "新增租户", description = "添加新的租户信息")
|
||||||
|
public ResponseEntity<Map<String, Object>> addTenant(
|
||||||
|
@Parameter(description = "租户信息", required = true)
|
||||||
|
@RequestBody Tenant tenant) {
|
||||||
|
Map<String, Object> result = tenantService.addTenant(tenant);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新租户信息
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新租户信息", description = "更新租户详细信息")
|
||||||
|
public ResponseEntity<Map<String, Object>> updateTenant(
|
||||||
|
@Parameter(description = "租户信息", required = true)
|
||||||
|
@RequestBody Tenant tenant) {
|
||||||
|
Map<String, Object> result = tenantService.updateTenant(tenant);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除租户
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
@Operation(summary = "删除租户", description = "根据租户ID删除租户信息")
|
||||||
|
public ResponseEntity<Map<String, Object>> deleteTenant(
|
||||||
|
@Parameter(description = "租户ID", required = true)
|
||||||
|
@PathVariable String id) {
|
||||||
|
Map<String, Object> result = tenantService.deleteTenant(id);
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,5 +47,26 @@ public interface ITenantService extends IService<Tenant> {
|
|||||||
Integer status, String contactName,
|
Integer status, String contactName,
|
||||||
String contactPhone, String expireStartTime,
|
String contactPhone, String expireStartTime,
|
||||||
String expireEndTime);
|
String expireEndTime);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增租户
|
||||||
|
* @param tenant 租户信息
|
||||||
|
* @return 操作结果
|
||||||
|
*/
|
||||||
|
Map<String, Object> addTenant(Tenant tenant);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新租户信息
|
||||||
|
* @param tenant 租户信息
|
||||||
|
* @return 操作结果
|
||||||
|
*/
|
||||||
|
Map<String, Object> updateTenant(Tenant tenant);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID删除租户
|
||||||
|
* @param id 租户ID
|
||||||
|
* @return 操作结果
|
||||||
|
*/
|
||||||
|
Map<String, Object> deleteTenant(String id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.time.format.DateTimeFormatter;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -139,5 +140,141 @@ public class TenantServiceImpl extends ServiceImpl<TenantMapper, Tenant> impleme
|
|||||||
|
|
||||||
return queryWrapper;
|
return queryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> addTenant(Tenant tenant) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
// 验证必填字段
|
||||||
|
if (tenant.getTenantCode() == null || tenant.getTenantCode().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户编码不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
if (tenant.getTenantName() == null || tenant.getTenantName().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户名称不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查租户编码是否已存在
|
||||||
|
LambdaQueryWrapper<Tenant> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(Tenant::getTenantCode, tenant.getTenantCode());
|
||||||
|
long count = this.count(queryWrapper);
|
||||||
|
if (count > 0) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户编码已存在");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成UUID作为主键
|
||||||
|
tenant.setId(UUID.randomUUID().toString().replace("-", ""));
|
||||||
|
tenant.setCreateTime(LocalDateTime.now());
|
||||||
|
tenant.setUpdateTime(LocalDateTime.now());
|
||||||
|
|
||||||
|
// 设置默认状态为启用
|
||||||
|
if (tenant.getStatus() == null) {
|
||||||
|
tenant.setStatus(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = this.save(tenant);
|
||||||
|
if (success) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "租户添加成功");
|
||||||
|
result.put("data", tenant);
|
||||||
|
} else {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户添加失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户添加异常:" + e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> updateTenant(Tenant tenant) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (tenant.getId() == null || tenant.getId().trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户ID不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查租户是否存在
|
||||||
|
Tenant existingTenant = this.getById(tenant.getId());
|
||||||
|
if (existingTenant == null) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户不存在");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果修改了租户编码,检查新编码是否已存在
|
||||||
|
if (tenant.getTenantCode() != null && !tenant.getTenantCode().equals(existingTenant.getTenantCode())) {
|
||||||
|
LambdaQueryWrapper<Tenant> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
queryWrapper.eq(Tenant::getTenantCode, tenant.getTenantCode());
|
||||||
|
long count = this.count(queryWrapper);
|
||||||
|
if (count > 0) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户编码已存在");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置更新时间
|
||||||
|
tenant.setUpdateTime(LocalDateTime.now());
|
||||||
|
// 不更新创建时间
|
||||||
|
tenant.setCreateTime(existingTenant.getCreateTime());
|
||||||
|
|
||||||
|
boolean success = this.updateById(tenant);
|
||||||
|
if (success) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "租户信息更新成功");
|
||||||
|
result.put("data", tenant);
|
||||||
|
} else {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户信息更新失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "更新异常:" + e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> deleteTenant(String id) {
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
try {
|
||||||
|
if (id == null || id.trim().isEmpty()) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户ID不能为空");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查租户是否存在
|
||||||
|
Tenant tenant = this.getById(id);
|
||||||
|
if (tenant == null) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户不存在");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean success = this.removeById(id);
|
||||||
|
if (success) {
|
||||||
|
result.put("success", true);
|
||||||
|
result.put("message", "租户删除成功");
|
||||||
|
} else {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "租户删除失败");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
result.put("success", false);
|
||||||
|
result.put("message", "删除异常:" + e.getMessage());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,6 +201,7 @@ springdoc:
|
|||||||
path: /v3/api-docs # OpenAPI 描述文件路径
|
path: /v3/api-docs # OpenAPI 描述文件路径
|
||||||
default-consumes-media-type: application/json
|
default-consumes-media-type: application/json
|
||||||
default-produces-media-type: application/json
|
default-produces-media-type: application/json
|
||||||
|
override-with-generic-response: false # 禁用通用响应覆盖,解决版本兼容性问题
|
||||||
|
|
||||||
swagger:
|
swagger:
|
||||||
api:
|
api:
|
||||||
|
|||||||
Reference in New Issue
Block a user