Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit. On branch develop Your branch is ahead of 'goflyapp/develop' by 1 commit. (use "git push" to publish your local commits) Changes to be committed: new file: zlt-business/user-center/src/main/java/com/central/user/config/TenantConfiguration.java new file: zlt-business/user-center/src/main/java/com/central/user/controller/SysTenantController.java modified: zlt-business/user-center/src/main/java/com/central/user/mapper/SysTenantMapper.java modified: zlt-business/user-center/src/main/java/com/central/user/model/SysTenant.java new file: zlt-business/user-center/src/main/java/com/central/user/service/ISysTenantService.java new file: zlt-business/user-center/src/main/java/com/central/user/service/impl/SysTenantServiceImpl.java new file: zlt-business/user-center/src/main/java/com/central/user/service/impl/TenantInitServiceImpl.java modified: zlt-business/user-center/src/main/resources/application.yml new file: zlt-business/user-center/src/main/resources/mapper/SysTenantMapper.xml modified: zlt-commons/zlt-common-core/src/main/java/com/central/common/properties/TenantProperties.java modified: zlt-web/react-web/src/main/frontend/config/routes.ts new file: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/components/UpdateForm.less modified: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/components/UpdateForm.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/constants.ts modified: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.less modified: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/index.tsx modified: zlt-web/react-web/src/main/frontend/src/pages/orders/Refund/types.ts new file: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/components/CreateForm.tsx new file: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/components/UpdateForm.tsx new file: zlt-web/react-web/src/main/frontend/src/pages/system/Tenant/index.tsx modified: zlt-web/react-web/src/main/frontend/src/services/system/api.ts modified: zlt-web/react-web/src/main/frontend/src/services/system/typings.d.ts
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
|||||||
|
package com.central.user.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.handler.TenantLineHandler;
|
||||||
|
import com.central.common.context.TenantContextHolder;
|
||||||
|
import com.central.common.filter.TenantFilter;
|
||||||
|
import com.central.common.properties.TenantProperties;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import net.sf.jsqlparser.expression.Expression;
|
||||||
|
import net.sf.jsqlparser.expression.StringValue;
|
||||||
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableConfigurationProperties(TenantProperties.class)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class TenantConfiguration {
|
||||||
|
private final TenantProperties tenantProperties;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TenantLineHandler tenantLineHandler() {
|
||||||
|
return new TenantLineHandler() {
|
||||||
|
@Override
|
||||||
|
public String getTenantIdColumn() {
|
||||||
|
return "tenant_id";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean ignoreTable(String tableName) {
|
||||||
|
return tenantProperties.getIgnoreTables().stream().anyMatch(
|
||||||
|
(t) -> t.equalsIgnoreCase(tableName)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Expression getTenantId() {
|
||||||
|
String tenant = TenantContextHolder.getTenant();
|
||||||
|
if (tenant != null) {
|
||||||
|
return new StringValue(tenant);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public TenantFilter tenantFilter() {
|
||||||
|
return new TenantFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
+59
@@ -0,0 +1,59 @@
|
|||||||
|
package com.central.user.controller;
|
||||||
|
|
||||||
|
import com.central.common.context.TenantContextHolder;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.user.model.SysTenant;
|
||||||
|
import com.central.user.service.ISysTenantService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/tenant")
|
||||||
|
@Tag(name = "租户管理")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysTenantController {
|
||||||
|
private final ISysTenantService sysTenantService;
|
||||||
|
|
||||||
|
@Operation(summary = "查询租户列表")
|
||||||
|
@GetMapping("/list")
|
||||||
|
public PageResult<SysTenant> list(@RequestParam Map<String, Object> params) {
|
||||||
|
return sysTenantService.findList(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询租户详情")
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public Result<SysTenant> get(@PathVariable String id) {
|
||||||
|
return Result.succeed(sysTenantService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "新增/更新租户")
|
||||||
|
@PostMapping("/save")
|
||||||
|
public Result save(@RequestBody SysTenant tenant) {
|
||||||
|
return sysTenantService.saveOrUpdateTenant(tenant);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "删除租户")
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public Result delete(@PathVariable String id) {
|
||||||
|
return sysTenantService.deleteTenant(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新租户状态")
|
||||||
|
@PutMapping("/status/{id}/{status}")
|
||||||
|
public Result updateStatus(@PathVariable String id, @PathVariable Integer status) {
|
||||||
|
return sysTenantService.updateStatus(id, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "查询当前租户")
|
||||||
|
@GetMapping("/current")
|
||||||
|
public Result<String> getCurrentTenant() {
|
||||||
|
return Result.succeed(TenantContextHolder.getTenant());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
|
package com.central.user.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.central.db.mapper.SuperMapper;
|
import com.central.db.mapper.SuperMapper;
|
||||||
|
import com.central.user.model.SysTenant;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
|
|||||||
@@ -1,9 +1,27 @@
|
|||||||
|
package com.central.user.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
import com.central.common.model.SuperEntity;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@TableName("sys_tenant")
|
@TableName("sys_tenant")
|
||||||
public class SysTenant extends SuperEntity {
|
public class SysTenant extends SuperEntity {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户名称
|
* 租户名称
|
||||||
*/
|
*/
|
||||||
@@ -20,37 +38,28 @@ public class SysTenant extends SuperEntity {
|
|||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 租户类型:1-免费版,2-标准版,3-企业版
|
* 租户类型
|
||||||
*/
|
*/
|
||||||
private Integer type;
|
private Integer type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 开始时间
|
* 租户域名
|
||||||
*/
|
*/
|
||||||
private Date startTime;
|
private String domain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 结束时间
|
* 租户数据源名称
|
||||||
*/
|
*/
|
||||||
private Date endTime;
|
private String datasourceConfigId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 联系人
|
* 是否删除
|
||||||
*/
|
*/
|
||||||
private String contactName;
|
@TableLogic
|
||||||
|
private Boolean isDeleted;
|
||||||
/**
|
|
||||||
* 联系电话
|
|
||||||
*/
|
|
||||||
private String contactPhone;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 联系邮箱
|
|
||||||
*/
|
|
||||||
private String contactEmail;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 备注
|
* 备注
|
||||||
*/
|
*/
|
||||||
private String remark;
|
private String remarks;
|
||||||
}
|
}
|
||||||
|
|||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
package com.central.user.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.user.model.SysTenant;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface ISysTenantService extends IService<SysTenant> {
|
||||||
|
PageResult<SysTenant> findList(Map<String, Object> params);
|
||||||
|
Result saveOrUpdateTenant(SysTenant tenant);
|
||||||
|
Result deleteTenant(String id);
|
||||||
|
Result updateStatus(String id, Integer status);
|
||||||
|
}
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
package com.central.user.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.central.common.constant.CommonConstant;
|
||||||
|
import com.central.common.model.PageResult;
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.user.mapper.SysTenantMapper;
|
||||||
|
import com.central.user.model.SysTenant;
|
||||||
|
import com.central.user.service.ISysTenantService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.apache.commons.collections4.MapUtils;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import com.central.user.config.TenantProperties;
|
||||||
|
import com.central.user.context.TenantContextHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class SysTenantServiceImpl extends ServiceImpl<SysTenantMapper, SysTenant> implements ISysTenantService {
|
||||||
|
private final RedisTemplate<String, Object> redisTemplate;
|
||||||
|
private final TenantProperties tenantProperties;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<SysTenant> findList(Map<String, Object> params) {
|
||||||
|
// 清除租户上下文,查询所有租户
|
||||||
|
TenantContextHolder.clear();
|
||||||
|
try {
|
||||||
|
Page<SysTenant> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
|
||||||
|
LambdaQueryWrapper<SysTenant> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
// 查询条件
|
||||||
|
if (StrUtil.isNotEmpty(MapUtils.getString(params, "name"))) {
|
||||||
|
wrapper.like(SysTenant::getName, MapUtils.getString(params, "name"));
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(MapUtils.getString(params, "code"))) {
|
||||||
|
wrapper.eq(SysTenant::getCode, MapUtils.getString(params, "code"));
|
||||||
|
}
|
||||||
|
if (params.get("status") != null) {
|
||||||
|
wrapper.eq(SysTenant::getStatus, MapUtils.getInteger(params, "status"));
|
||||||
|
}
|
||||||
|
wrapper.orderByDesc(SysTenant::getCreateTime);
|
||||||
|
|
||||||
|
IPage<SysTenant> list = baseMapper.selectPage(page, wrapper);
|
||||||
|
return PageResult.<SysTenant>builder().data(list.getRecords()).count(list.getTotal()).build();
|
||||||
|
} finally {
|
||||||
|
// 恢复租户上下文
|
||||||
|
TenantContextHolder.setTenant(MapUtils.getString(params, "tenantId"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result saveOrUpdateTenant(SysTenant tenant) {
|
||||||
|
// 清除租户上下文
|
||||||
|
TenantContextHolder.clear();
|
||||||
|
try {
|
||||||
|
if (tenant.getId() == null) {
|
||||||
|
// 新增租户
|
||||||
|
tenant.setCode(generateTenantCode());
|
||||||
|
tenant.setStatus(CommonConstant.STATUS_NORMAL);
|
||||||
|
// 检查租户编码是否重复
|
||||||
|
if (checkTenantCodeExists(tenant.getCode())) {
|
||||||
|
return Result.failed("租户编码已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean result = saveOrUpdate(tenant);
|
||||||
|
if (result) {
|
||||||
|
refreshTenantCache(tenant);
|
||||||
|
return Result.succeed("操作成功");
|
||||||
|
}
|
||||||
|
return Result.failed("操作失败");
|
||||||
|
} finally {
|
||||||
|
// 恢复租户上下文
|
||||||
|
TenantContextHolder.setTenant(tenant.getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result deleteTenant(String id) {
|
||||||
|
// 清除租户上下文
|
||||||
|
TenantContextHolder.clear();
|
||||||
|
try {
|
||||||
|
SysTenant tenant = getById(id);
|
||||||
|
if (tenant == null) {
|
||||||
|
return Result.failed("租户不存在");
|
||||||
|
}
|
||||||
|
// 逻辑删除租户
|
||||||
|
boolean result = removeById(id);
|
||||||
|
if (result) {
|
||||||
|
clearTenantCache(tenant.getCode());
|
||||||
|
return Result.succeed("删除成功");
|
||||||
|
}
|
||||||
|
return Result.failed("删除失败");
|
||||||
|
} finally {
|
||||||
|
// 恢复租户上下文
|
||||||
|
TenantContextHolder.setTenant(getById(id).getCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean checkTenantCodeExists(String code) {
|
||||||
|
LambdaQueryWrapper<SysTenant> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.eq(SysTenant::getCode, code);
|
||||||
|
return baseMapper.selectCount(wrapper) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String generateTenantCode() {
|
||||||
|
return "T" + IdUtil.getSnowflake().nextIdStr();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void refreshTenantCache(SysTenant tenant) {
|
||||||
|
String key = CommonConstant.TENANT_PREFIX + tenant.getCode();
|
||||||
|
redisTemplate.opsForValue().set(key, tenant);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearTenantCache(String tenantCode) {
|
||||||
|
String key = CommonConstant.TENANT_PREFIX + tenantCode;
|
||||||
|
redisTemplate.delete(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
+49
@@ -0,0 +1,49 @@
|
|||||||
|
package com.central.user.service.impl;
|
||||||
|
|
||||||
|
import com.central.common.model.Result;
|
||||||
|
import com.central.user.service.ISysTenantService;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.jdbc.datasource.init.DataSourceInitializer;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class TenantInitServiceImpl {
|
||||||
|
private final ISysTenantService tenantService;
|
||||||
|
private final DataSourceInitializer dataSourceInitializer;
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Result initTenantData(String tenantId) {
|
||||||
|
try {
|
||||||
|
// 1. 初始化租户数据源
|
||||||
|
dataSourceInitializer.initTenantDataSource(tenantId);
|
||||||
|
|
||||||
|
// 2. 初始化租户基础数据
|
||||||
|
initBasicData(tenantId);
|
||||||
|
|
||||||
|
// 3. 初始化租户配置
|
||||||
|
initTenantConfig(tenantId);
|
||||||
|
|
||||||
|
return Result.succeed("租户初始化成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("租户初始化失败", e);
|
||||||
|
return Result.failed("租户初始化失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initBasicData(String tenantId) {
|
||||||
|
// 初始化基础数据
|
||||||
|
// 1. 初始化管理员账号
|
||||||
|
// 2. 初始化基础角色
|
||||||
|
// 3. 初始化基础权限
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTenantConfig(String tenantId) {
|
||||||
|
// 初始化租户配置
|
||||||
|
// 1. 初始化系统配置
|
||||||
|
// 2. 初始化业务配置
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -39,11 +39,14 @@ zlt:
|
|||||||
- sys_user
|
- sys_user
|
||||||
- sys_role_user
|
- sys_role_user
|
||||||
- sys_role_menu
|
- sys_role_menu
|
||||||
|
- sys_tenant
|
||||||
ignoreSqls:
|
ignoreSqls:
|
||||||
# 用户关联角色时,显示所有角色
|
# 用户关联角色时,显示所有角色
|
||||||
- com.central.user.mapper.SysRoleMapper.findAll
|
- com.central.user.mapper.SysRoleMapper.findAll
|
||||||
# 用户列表显示用户所关联的所有角色
|
# 用户列表显示用户所关联的所有角色
|
||||||
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
|
- com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds
|
||||||
|
# 租户列表
|
||||||
|
- com.central.user.mapper.SysTenantMapper.findList
|
||||||
# 数据权限
|
# 数据权限
|
||||||
datascope:
|
datascope:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.central.user.mapper.SysTenantMapper">
|
||||||
|
<select id="findList" resultType="com.central.user.model.SysTenant">
|
||||||
|
select * from sys_tenant t
|
||||||
|
<where>
|
||||||
|
<if test="p.name != null and p.name != ''">
|
||||||
|
and t.name like concat('%', #{p.name}, '%')
|
||||||
|
</if>
|
||||||
|
<if test="p.code != null and p.code != ''">
|
||||||
|
and t.code = #{p.code}
|
||||||
|
</if>
|
||||||
|
<if test="p.status != null">
|
||||||
|
and t.status = #{p.status}
|
||||||
|
</if>
|
||||||
|
and t.is_deleted = 0
|
||||||
|
</where>
|
||||||
|
order by t.create_time desc
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
+14
-9
@@ -1,11 +1,11 @@
|
|||||||
package com.central.common.properties;
|
package com.central.common.properties;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Data;
|
||||||
import lombok.Setter;
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,8 +13,7 @@ import java.util.List;
|
|||||||
* @author zlt
|
* @author zlt
|
||||||
* @date 2019/8/5
|
* @date 2019/8/5
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Data
|
||||||
@Getter
|
|
||||||
@ConfigurationProperties(prefix = "zlt.tenant")
|
@ConfigurationProperties(prefix = "zlt.tenant")
|
||||||
@RefreshScope
|
@RefreshScope
|
||||||
public class TenantProperties {
|
public class TenantProperties {
|
||||||
@@ -24,13 +23,19 @@ public class TenantProperties {
|
|||||||
private Boolean enable = false;
|
private Boolean enable = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置不进行多租户隔离的表名
|
* 忽略租户的表名
|
||||||
*/
|
*/
|
||||||
private List<String> ignoreTables = new ArrayList<>();
|
private List<String> ignoreTables = Arrays.asList(
|
||||||
|
"sys_user",
|
||||||
|
"sys_role_user",
|
||||||
|
"sys_role_menu"
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配置不进行多租户隔离的sql
|
* 忽略租户的SQL
|
||||||
* 需要配置mapper的全路径如:com.central.user.mapper.SysUserMapper.findList
|
|
||||||
*/
|
*/
|
||||||
private List<String> ignoreSqls = new ArrayList<>();
|
private List<String> ignoreSqls = Arrays.asList(
|
||||||
|
"com.central.user.mapper.SysRoleMapper.findAll",
|
||||||
|
"com.central.user.mapper.SysUserRoleMapper.findRolesByUserIds"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,10 @@
|
|||||||
path: '/system/role.html',
|
path: '/system/role.html',
|
||||||
component: './system/Role',
|
component: './system/Role',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/system/tenant.html',
|
||||||
|
component: './system/Tenant',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/system/tokens.html',
|
path: '/system/tokens.html',
|
||||||
component: './system/Token',
|
component: './system/Token',
|
||||||
|
|||||||
+68
@@ -0,0 +1,68 @@
|
|||||||
|
.auditModal {
|
||||||
|
:global {
|
||||||
|
.ant-modal-body {
|
||||||
|
padding: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.orderInfo {
|
||||||
|
margin-bottom: 24px;
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-descriptions {
|
||||||
|
background: #fafafa;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-descriptions-item-label {
|
||||||
|
width: 100px;
|
||||||
|
background: #f5f5f5;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-descriptions-item-content {
|
||||||
|
background: #fff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.formContent {
|
||||||
|
padding: 16px 0;
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-form-item-label {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.codeText {
|
||||||
|
font-family: 'Roboto Mono', monospace;
|
||||||
|
color: #1890ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount {
|
||||||
|
font-family: 'Roboto Mono', monospace;
|
||||||
|
color: #262626;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.selectField {
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-select-selector {
|
||||||
|
border-radius: 4px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.textArea {
|
||||||
|
border-radius: 4px;
|
||||||
|
resize: none;
|
||||||
|
|
||||||
|
&:hover, &:focus {
|
||||||
|
border-color: #1890ff;
|
||||||
|
}
|
||||||
|
}
|
||||||
+76
-59
@@ -2,80 +2,97 @@ import {
|
|||||||
ModalForm,
|
ModalForm,
|
||||||
ProForm,
|
ProForm,
|
||||||
ProFormSelect,
|
ProFormSelect,
|
||||||
ProFormText,
|
ProFormTextArea,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Form } from 'antd';
|
import { Typography, Descriptions, Space, Tag } from 'antd';
|
||||||
import { useEffect } from 'react';
|
import React from 'react';
|
||||||
|
import { ORDER_STATUS, REFUND_STATUS } from '../constants';
|
||||||
|
import styles from './UpdateForm.less';
|
||||||
|
|
||||||
export type FormValueType = Partial<ORDERS.Refund>;
|
const { Text } = Typography;
|
||||||
|
|
||||||
export type UpdateFormProps = {
|
interface UpdateFormProps {
|
||||||
onVisibleChange: (flag: boolean) => void;
|
onSubmit: (values: any) => Promise<void>;
|
||||||
onSubmit: (values: FormValueType) => Promise<void>;
|
onVisibleChange: (visible: boolean) => void;
|
||||||
updateModalVisible: boolean;
|
updateModalVisible: boolean;
|
||||||
values?: ORDERS.Refund;
|
values?: any;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 金额转换:分转元
|
||||||
|
const formatAmount = (amount?: string | number | null) => {
|
||||||
|
if (!amount && amount !== 0) return '-';
|
||||||
|
return `¥ ${(Number(amount) / 100).toFixed(2)}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||||
const [form] = Form.useForm();
|
|
||||||
const { values } = props;
|
const { values } = props;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
form.setFieldsValue(values);
|
|
||||||
}, [form, values]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ModalForm
|
<ModalForm
|
||||||
title="退款审核"
|
title="退款审核"
|
||||||
form={form}
|
width={600}
|
||||||
visible={props.updateModalVisible}
|
visible={props.updateModalVisible}
|
||||||
onFinish={props.onSubmit}
|
|
||||||
onVisibleChange={props.onVisibleChange}
|
onVisibleChange={props.onVisibleChange}
|
||||||
|
onFinish={props.onSubmit}
|
||||||
|
modalProps={{
|
||||||
|
destroyOnClose: true,
|
||||||
|
className: styles.auditModal
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<ProForm.Group>
|
<div className={styles.orderInfo}>
|
||||||
<ProFormText
|
<Descriptions column={2} bordered size="small">
|
||||||
readonly = {true}
|
<Descriptions.Item label="退款单号" span={2}>
|
||||||
width="md"
|
<Text copyable className={styles.codeText}>{values?.refundNo}</Text>
|
||||||
name="orderNo"
|
</Descriptions.Item>
|
||||||
label="订单编号"
|
<Descriptions.Item label="订单编号" span={2}>
|
||||||
/>
|
<Text copyable className={styles.codeText}>{values?.orderNo}</Text>
|
||||||
<ProFormText
|
</Descriptions.Item>
|
||||||
readonly={true}
|
<Descriptions.Item label="订单金额">
|
||||||
width="md"
|
<span className={styles.amount}>{formatAmount(values?.orderAmount)}</span>
|
||||||
name="refundNo"
|
</Descriptions.Item>
|
||||||
label="退款编号"
|
<Descriptions.Item label="退款金额">
|
||||||
/>
|
<span className={styles.amount}>{formatAmount(values?.refundAmount)}</span>
|
||||||
<ProFormText
|
</Descriptions.Item>
|
||||||
rules={[
|
<Descriptions.Item label="订单状态">
|
||||||
{
|
<Tag color={ORDER_STATUS[values?.status]?.color}>
|
||||||
required: true,
|
{ORDER_STATUS[values?.status]?.text || '未知状态'}
|
||||||
message: '审核理由不为空',
|
</Tag>
|
||||||
},
|
</Descriptions.Item>
|
||||||
]}
|
<Descriptions.Item label="退款状态">
|
||||||
width="md"
|
<Tag color={REFUND_STATUS[values?.state]?.color}>
|
||||||
name="approveReason"
|
{REFUND_STATUS[values?.state]?.text || '未知状态'}
|
||||||
label="审核理由"
|
</Tag>
|
||||||
placeholder="输入审核理由"
|
</Descriptions.Item>
|
||||||
/>
|
<Descriptions.Item label="申请时间" span={2}>
|
||||||
|
{values?.createTime}
|
||||||
|
</Descriptions.Item>
|
||||||
|
</Descriptions>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={styles.formContent}>
|
||||||
<ProFormSelect
|
<ProFormSelect
|
||||||
rules={[
|
name="state"
|
||||||
{
|
label="审核结果"
|
||||||
required: true,
|
rules={[{ required: true, message: '请选择审核结果' }]}
|
||||||
message: '审核状态不为空',
|
options={[
|
||||||
},
|
{ label: '同意退款', value: 1 },
|
||||||
]}
|
{ label: '拒绝退款', value: 2 },
|
||||||
width="md"
|
]}
|
||||||
name="state"
|
fieldProps={{
|
||||||
label="状态"
|
className: styles.selectField,
|
||||||
placeholder="请选择审核状态"
|
}}
|
||||||
options={[
|
/>
|
||||||
{ label: '审核中', value: 0 },
|
<ProFormTextArea
|
||||||
{ label: '已通过', value: 1 },
|
name="approveReason"
|
||||||
{ label: '已拒绝', value: 2 },
|
label="审核意见"
|
||||||
// 添加更多选项...
|
placeholder="请输入审核意见"
|
||||||
]}
|
rules={[{ required: true, message: '请输入审核意见' }]}
|
||||||
/>
|
fieldProps={{
|
||||||
</ProForm.Group>
|
rows: 4,
|
||||||
|
className: styles.textArea,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</ModalForm>
|
</ModalForm>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,27 @@
|
|||||||
// 将常量配置提取到单独文件
|
// 订单状态配置(与后端 OrderStatus 枚举保持一致)
|
||||||
export const STATUS_CONFIG = {
|
export const ORDER_STATUS = {
|
||||||
7: { color: 'yellow', text: '退款申请中' },
|
0: { text: '待支付', color: 'default' },
|
||||||
8: { color: 'green', text: '已退款' },
|
1: { text: '已支付排队中', color: 'processing' },
|
||||||
9: { color: 'red', text: '退款失败' },
|
2: { text: '已取消', color: 'default' },
|
||||||
|
3: { text: '设备执行完成', color: 'success' },
|
||||||
|
4: { text: '正在服务中', color: 'processing' },
|
||||||
|
5: { text: '素材上传中', color: 'processing' },
|
||||||
|
6: { text: '素材上传完成', color: 'success' },
|
||||||
|
7: { text: '退款中', color: 'warning' },
|
||||||
|
8: { text: '已退款', color: 'success' },
|
||||||
|
9: { text: '退款失败', color: 'error' },
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export const STATE_CONFIG = {
|
// 退款状态配置(与订单状态保持一致)
|
||||||
0: { color: 'yellow', text: '待审核' },
|
export const REFUND_STATUS = {
|
||||||
1: { color: 'green', text: '已通过' },
|
0: { text: '待审核', color: 'default' },
|
||||||
2: { color: 'red', text: '已拒绝' },
|
1: { text: '已同意', color: 'success' },
|
||||||
} as const;
|
2: { text: '已拒绝', color: 'error' },
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
// 退款相关状态(用于筛选)
|
||||||
|
export const REFUND_ORDER_STATUS = {
|
||||||
|
7: ORDER_STATUS[7],
|
||||||
|
8: ORDER_STATUS[8],
|
||||||
|
9: ORDER_STATUS[9],
|
||||||
|
} as const;
|
||||||
@@ -1 +1,76 @@
|
|||||||
@import (reference) '~antd/es/style/themes/index';
|
@import (reference) '~antd/es/style/themes/index';
|
||||||
|
|
||||||
|
.queryCard {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
|
||||||
|
:global {
|
||||||
|
.ant-card-body {
|
||||||
|
padding: 16px 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tableCard {
|
||||||
|
:global {
|
||||||
|
.ant-card-body {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.customTable {
|
||||||
|
:global {
|
||||||
|
.ant-table-thead > tr > th {
|
||||||
|
background: #fafafa;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-table-row:hover {
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.statusTag {
|
||||||
|
min-width: 72px;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.amount {
|
||||||
|
font-family: 'Roboto Mono', monospace;
|
||||||
|
color: #262626;
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
.codeText {
|
||||||
|
font-family: 'Roboto Mono', monospace;
|
||||||
|
color: #1890ff;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.actionLink {
|
||||||
|
&:hover {
|
||||||
|
color: #1890ff;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.queryFilter {
|
||||||
|
:global {
|
||||||
|
.ant-form-item {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-select-selector {
|
||||||
|
border-radius: 4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ant-input {
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,149 +3,236 @@ import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
|||||||
import {
|
import {
|
||||||
PageContainer,
|
PageContainer,
|
||||||
ProFormText,
|
ProFormText,
|
||||||
|
ProFormSelect,
|
||||||
ProTable,
|
ProTable,
|
||||||
QueryFilter,
|
QueryFilter,
|
||||||
} from '@ant-design/pro-components';
|
} from '@ant-design/pro-components';
|
||||||
import { Typography, Tag, Space, message } from 'antd';
|
import { Typography, Tag, Space, message, Card } from 'antd';
|
||||||
import React, { useRef, useState, useCallback } from 'react';
|
import React, { useRef, useState } from 'react';
|
||||||
import { STATUS_CONFIG, STATE_CONFIG } from './constants';
|
import { ORDER_STATUS, REFUND_STATUS, REFUND_ORDER_STATUS } from './constants';
|
||||||
import UpdateForm from './components/UpdateForm';
|
import UpdateForm from './components/UpdateForm';
|
||||||
import type { RefundItem } from './types';
|
import type { RefundItem } from './types';
|
||||||
|
import styles from './index.less';
|
||||||
|
|
||||||
const { Link } = Typography;
|
const { Link } = Typography;
|
||||||
|
|
||||||
// 将渲染标签的函数移到组件外部
|
// 金额转换:分转元,处理字符串或数字类型的金额
|
||||||
const renderTag = (value: number, config: typeof STATUS_CONFIG | typeof STATE_CONFIG) => {
|
const formatAmount = (amount?: string | number | null) => {
|
||||||
const info = config[value] || { color: 'gray', text: '未知状态' };
|
if (!amount && amount !== 0) return '-';
|
||||||
return <Tag color={info.color}>{info.text}</Tag>;
|
return `¥ ${(Number(amount) / 100).toFixed(2)}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 状态标签渲染函数
|
||||||
|
const renderStatusTag = (value: any, statusConfig: Record<number, { text: string; color: string }>) => {
|
||||||
|
const statusValue = typeof value === 'string' ? parseInt(value, 10) : value;
|
||||||
|
|
||||||
|
if (statusValue === undefined || statusValue === null || isNaN(statusValue)) {
|
||||||
|
return <Tag color="default">未知状态</Tag>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const status = statusConfig[statusValue] || { text: `未知状态(${statusValue})`, color: 'default' };
|
||||||
|
return (
|
||||||
|
<Tag color={status.color} className={styles.statusTag}>
|
||||||
|
{status.text}
|
||||||
|
</Tag>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const TableList: React.FC = () => {
|
const TableList: React.FC = () => {
|
||||||
// 1. 所有 hooks 放在组件最顶部
|
|
||||||
const actionRef = useRef<ActionType>();
|
const actionRef = useRef<ActionType>();
|
||||||
const [params, setParams] = useState<Record<string, string | number>>({});
|
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||||
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
const [updateModalVisible, setUpdateModalVisible] = useState<boolean>(false);
|
||||||
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
const [currentRow, setCurrentRow] = useState<RefundItem>();
|
||||||
|
|
||||||
// 2. 处理编辑的回调函数
|
|
||||||
const handleEdit = useCallback(async (fields: RefundItem) => {
|
|
||||||
const hide = message.loading('正在更新');
|
|
||||||
try {
|
|
||||||
const result = await updateRefund({ ...fields });
|
|
||||||
hide();
|
|
||||||
if (result.resp_code === 0) {
|
|
||||||
message.success('审核成功');
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
message.error(result.resp_msg);
|
|
||||||
return false;
|
|
||||||
} catch (error) {
|
|
||||||
hide();
|
|
||||||
message.error('审核失败');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
// 3. 处理表单提交的回调函数
|
|
||||||
const handleSubmit = useCallback(async (values: Partial<RefundItem>) => {
|
|
||||||
if (!currentRow) return;
|
|
||||||
|
|
||||||
const success = await handleEdit({ ...currentRow, ...values });
|
|
||||||
if (success) {
|
|
||||||
setUpdateModalVisible(false);
|
|
||||||
actionRef.current?.reload();
|
|
||||||
setCurrentRow(undefined);
|
|
||||||
}
|
|
||||||
}, [currentRow, handleEdit]);
|
|
||||||
|
|
||||||
// 4. 定义表格列
|
|
||||||
const columns: ProColumns<RefundItem>[] = [
|
const columns: ProColumns<RefundItem>[] = [
|
||||||
{
|
{
|
||||||
dataIndex: 'index',
|
dataIndex: 'index',
|
||||||
valueType: 'indexBorder',
|
valueType: 'indexBorder',
|
||||||
|
width: 48,
|
||||||
|
align: 'center',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '订单ID',
|
title: '退款单号',
|
||||||
dataIndex: 'id',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: '退款订单编号',
|
|
||||||
dataIndex: 'refundNo',
|
dataIndex: 'refundNo',
|
||||||
|
copyable: true,
|
||||||
|
width: 200,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (text) => (
|
||||||
|
<span className={styles.codeText}>{text}</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '订单编号',
|
||||||
|
dataIndex: 'orderNo',
|
||||||
|
copyable: true,
|
||||||
|
width: 200,
|
||||||
|
ellipsis: true,
|
||||||
|
render: (text) => (
|
||||||
|
<span className={styles.codeText}>{text}</span>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '订单金额',
|
title: '订单金额',
|
||||||
dataIndex: 'orderAmount',
|
dataIndex: 'orderAmount',
|
||||||
valueType: 'money',
|
width: 120,
|
||||||
|
align: 'right',
|
||||||
|
render: (_, record) => (
|
||||||
|
<span className={styles.amount}>{formatAmount(record.orderAmount)}</span>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '退款金额',
|
title: '退款金额',
|
||||||
dataIndex: 'refundAmount',
|
dataIndex: 'refundAmount',
|
||||||
valueType: 'money',
|
width: 120,
|
||||||
|
align: 'right',
|
||||||
|
render: (_, record) => (
|
||||||
|
<span className={styles.amount}>{formatAmount(record.refundAmount)}</span>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '订单状态',
|
title: '订单状态',
|
||||||
dataIndex: 'status',
|
dataIndex: 'status',
|
||||||
render: (status) => renderTag(status as number, STATUS_CONFIG),
|
width: 120,
|
||||||
|
align: 'center',
|
||||||
|
render: (status) => renderStatusTag(status, ORDER_STATUS),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '退款状态',
|
title: '退款状态',
|
||||||
dataIndex: 'state',
|
dataIndex: 'state',
|
||||||
render: (state) => renderTag(state as number, STATE_CONFIG),
|
width: 100,
|
||||||
|
align: 'center',
|
||||||
|
render: (state) => renderStatusTag(state, REFUND_STATUS),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '退款时间',
|
||||||
|
dataIndex: 'refundTime',
|
||||||
|
valueType: 'dateTime',
|
||||||
|
width: 180,
|
||||||
|
align: 'center',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '创建时间',
|
title: '创建时间',
|
||||||
dataIndex: 'createTime',
|
dataIndex: 'createTime',
|
||||||
valueType: 'dateTime',
|
valueType: 'dateTime',
|
||||||
|
width: 180,
|
||||||
|
align: 'center',
|
||||||
|
sorter: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '操作',
|
title: '操作',
|
||||||
key: 'action',
|
key: 'action',
|
||||||
render: (_, entity) => (
|
fixed: 'right',
|
||||||
<Space>
|
width: 120,
|
||||||
<Link
|
align: 'center',
|
||||||
onClick={() => {
|
render: (_, record) => (
|
||||||
setCurrentRow(entity);
|
<Space size="middle">
|
||||||
setUpdateModalVisible(true);
|
{record.state === 0 && (
|
||||||
}}
|
<Link
|
||||||
>
|
className={styles.actionLink}
|
||||||
修改
|
onClick={() => {
|
||||||
</Link>
|
setCurrentRow(record);
|
||||||
|
setUpdateModalVisible(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
审核
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
</Space>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer header={{ subTitle: '退款管理' }}>
|
<PageContainer
|
||||||
<QueryFilter
|
header={{
|
||||||
defaultCollapsed
|
title: '退款管理',
|
||||||
split
|
subTitle: '管理订单退款申请及审核',
|
||||||
span={6}
|
}}
|
||||||
className="query-filter"
|
>
|
||||||
onFinish={async (values) => setParams(values)}
|
<Card bordered={false} className={styles.queryCard}>
|
||||||
>
|
<QueryFilter
|
||||||
<ProFormText name="name" label="搜索" placeholder="输入关键字" />
|
defaultCollapsed={false}
|
||||||
</QueryFilter>
|
split
|
||||||
|
span={6}
|
||||||
<ProTable<RefundItem>
|
className={styles.queryFilter}
|
||||||
rowKey="id"
|
onFinish={async (values) => setParams(values)}
|
||||||
headerTitle="退款列表"
|
>
|
||||||
request={refund}
|
<ProFormText
|
||||||
actionRef={actionRef}
|
name="refundNo"
|
||||||
columns={columns}
|
label="退款单号"
|
||||||
search={false}
|
placeholder="请输入退款单号"
|
||||||
params={params}
|
/>
|
||||||
pagination={{
|
<ProFormText
|
||||||
showSizeChanger: true,
|
name="orderNo"
|
||||||
showQuickJumper: true,
|
label="订单编号"
|
||||||
}}
|
placeholder="请输入订单编号"
|
||||||
/>
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="status"
|
||||||
|
label="订单状态"
|
||||||
|
placeholder="请选择订单状态"
|
||||||
|
options={Object.entries(REFUND_ORDER_STATUS).map(([key, value]) => ({
|
||||||
|
label: value.text,
|
||||||
|
value: Number(key),
|
||||||
|
}))}
|
||||||
|
fieldProps={{
|
||||||
|
allowClear: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<ProFormSelect
|
||||||
|
name="state"
|
||||||
|
label="退款状态"
|
||||||
|
placeholder="请选择退款状态"
|
||||||
|
options={Object.entries(REFUND_STATUS).map(([key, value]) => ({
|
||||||
|
label: value.text,
|
||||||
|
value: Number(key),
|
||||||
|
}))}
|
||||||
|
fieldProps={{
|
||||||
|
allowClear: true,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</QueryFilter>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card bordered={false} className={styles.tableCard}>
|
||||||
|
<ProTable<RefundItem>
|
||||||
|
rowKey="id"
|
||||||
|
headerTitle="退款列表"
|
||||||
|
actionRef={actionRef}
|
||||||
|
request={refund}
|
||||||
|
columns={columns}
|
||||||
|
search={false}
|
||||||
|
params={params}
|
||||||
|
pagination={{
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
defaultPageSize: 10,
|
||||||
|
showTotal: (total) => `共 ${total} 条记录`,
|
||||||
|
}}
|
||||||
|
scroll={{ x: 'max-content' }}
|
||||||
|
dateFormatter="string"
|
||||||
|
className={styles.customTable}
|
||||||
|
/>
|
||||||
|
</Card>
|
||||||
|
|
||||||
<UpdateForm
|
<UpdateForm
|
||||||
onSubmit={handleSubmit}
|
onSubmit={async (values) => {
|
||||||
|
if (!currentRow) return false;
|
||||||
|
const success = await updateRefund({ ...currentRow, ...values });
|
||||||
|
if (success) {
|
||||||
|
setUpdateModalVisible(false);
|
||||||
|
actionRef.current?.reload();
|
||||||
|
setCurrentRow(undefined);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}}
|
||||||
onVisibleChange={setUpdateModalVisible}
|
onVisibleChange={setUpdateModalVisible}
|
||||||
updateModalVisible={updateModalVisible}
|
updateModalVisible={updateModalVisible}
|
||||||
values={currentRow}
|
values={currentRow}
|
||||||
|
refundStatusOptions={Object.entries(REFUND_STATUS).map(([key, value]) => ({
|
||||||
|
label: value.text,
|
||||||
|
value: Number(key),
|
||||||
|
}))}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ export interface RefundItem {
|
|||||||
refundNo: string;
|
refundNo: string;
|
||||||
orderAmount: number;
|
orderAmount: number;
|
||||||
refundAmount: number;
|
refundAmount: number;
|
||||||
status: number;
|
status: string;
|
||||||
state: number;
|
state: string;
|
||||||
|
reason?: string;
|
||||||
createTime: string;
|
createTime: string;
|
||||||
|
remark?: string;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import {
|
||||||
|
ModalForm,
|
||||||
|
ProForm,
|
||||||
|
ProFormText,
|
||||||
|
ProFormTextArea,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface CreateFormProps {
|
||||||
|
visible: boolean;
|
||||||
|
onVisibleChange: (visible: boolean) => void;
|
||||||
|
onSubmit: (values: SYSTEM.Tenant) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const CreateForm: React.FC<CreateFormProps> = (props) => {
|
||||||
|
return (
|
||||||
|
<ModalForm
|
||||||
|
title="新增租户"
|
||||||
|
visible={props.visible}
|
||||||
|
onVisibleChange={props.onVisibleChange}
|
||||||
|
onFinish={props.onSubmit}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
>
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormText
|
||||||
|
name="name"
|
||||||
|
label="租户名称"
|
||||||
|
rules={[{ required: true, message: '请输入租户名称' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="code"
|
||||||
|
label="租户编码"
|
||||||
|
rules={[{ required: true, message: '请输入租户编码' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="contactPerson"
|
||||||
|
label="联系人"
|
||||||
|
rules={[{ required: true, message: '请输入联系人' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="contactPhone"
|
||||||
|
label="联系电话"
|
||||||
|
rules={[{ required: true, message: '请输入联系电话' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormTextArea
|
||||||
|
name="address"
|
||||||
|
label="地址"
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreateForm;
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import {
|
||||||
|
ModalForm,
|
||||||
|
ProForm,
|
||||||
|
ProFormText,
|
||||||
|
ProFormTextArea,
|
||||||
|
} from '@ant-design/pro-components';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface UpdateFormProps {
|
||||||
|
visible: boolean;
|
||||||
|
onVisibleChange: (visible: boolean) => void;
|
||||||
|
onSubmit: (values: SYSTEM.Tenant) => Promise<void>;
|
||||||
|
values?: SYSTEM.Tenant;
|
||||||
|
}
|
||||||
|
|
||||||
|
const UpdateForm: React.FC<UpdateFormProps> = (props) => {
|
||||||
|
return (
|
||||||
|
<ModalForm
|
||||||
|
title="修改租户"
|
||||||
|
visible={props.visible}
|
||||||
|
onVisibleChange={props.onVisibleChange}
|
||||||
|
onFinish={props.onSubmit}
|
||||||
|
initialValues={props.values}
|
||||||
|
modalProps={{ destroyOnClose: true }}
|
||||||
|
>
|
||||||
|
<ProForm.Group>
|
||||||
|
<ProFormText
|
||||||
|
name="name"
|
||||||
|
label="租户名称"
|
||||||
|
rules={[{ required: true, message: '请输入租户名称' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="code"
|
||||||
|
label="租户编码"
|
||||||
|
rules={[{ required: true, message: '请输入租户编码' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="contactPerson"
|
||||||
|
label="联系人"
|
||||||
|
rules={[{ required: true, message: '请输入联系人' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormText
|
||||||
|
name="contactPhone"
|
||||||
|
label="联系电话"
|
||||||
|
rules={[{ required: true, message: '请输入联系电话' }]}
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
<ProFormTextArea
|
||||||
|
name="address"
|
||||||
|
label="地址"
|
||||||
|
width="md"
|
||||||
|
/>
|
||||||
|
</ProForm.Group>
|
||||||
|
</ModalForm>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default UpdateForm;
|
||||||
@@ -0,0 +1,213 @@
|
|||||||
|
import {
|
||||||
|
getTenantList,
|
||||||
|
saveOrUpdateTenant,
|
||||||
|
deleteTenant,
|
||||||
|
updateTenantStatus
|
||||||
|
} from '@/services/system/api';
|
||||||
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
|
import type { ActionType, ProColumns } from '@ant-design/pro-components';
|
||||||
|
import { PageContainer, ProFormText, ProTable, QueryFilter } from '@ant-design/pro-components';
|
||||||
|
import { Typography, message, Popconfirm, Button, Space, Switch } from 'antd';
|
||||||
|
import React, { useRef, useState } from 'react';
|
||||||
|
import CreateForm from './components/CreateForm';
|
||||||
|
import UpdateForm from './components/UpdateForm';
|
||||||
|
|
||||||
|
const { Link } = Typography;
|
||||||
|
|
||||||
|
// 统一的错误处理
|
||||||
|
const handleApiRequest = async (
|
||||||
|
apiCall: () => Promise<any>,
|
||||||
|
loadingMessage: string,
|
||||||
|
successMessage: string,
|
||||||
|
) => {
|
||||||
|
const hide = message.loading(loadingMessage);
|
||||||
|
try {
|
||||||
|
const result = await apiCall();
|
||||||
|
hide();
|
||||||
|
if (result.code === 0) {
|
||||||
|
message.success(successMessage);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
message.error(result.message || '操作失败');
|
||||||
|
return false;
|
||||||
|
} catch (error) {
|
||||||
|
hide();
|
||||||
|
message.error('操作失败');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const TenantList: React.FC = () => {
|
||||||
|
const [params, setParams] = useState<Record<string, string | number>>({});
|
||||||
|
const actionRef = useRef<ActionType>();
|
||||||
|
const [createModalVisible, handleCreateModalVisible] = useState<boolean>(false);
|
||||||
|
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
|
||||||
|
const [currentRow, setCurrentRow] = useState<any>();
|
||||||
|
|
||||||
|
// 处理状态切换
|
||||||
|
const handleStatusChange = async (checked: boolean, record: SYSTEM.Tenant) => {
|
||||||
|
const success = await handleApiRequest(
|
||||||
|
() => updateTenantStatus(record.id!, checked ? 1 : 0),
|
||||||
|
'正在更新状态',
|
||||||
|
'状态更新成功'
|
||||||
|
);
|
||||||
|
if (success && actionRef.current) {
|
||||||
|
actionRef.current.reload();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const columns: ProColumns<SYSTEM.Tenant>[] = [
|
||||||
|
{
|
||||||
|
dataIndex: 'index',
|
||||||
|
valueType: 'indexBorder',
|
||||||
|
width: 48,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '租户名称',
|
||||||
|
dataIndex: 'name',
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '租户编码',
|
||||||
|
dataIndex: 'code',
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '联系人',
|
||||||
|
dataIndex: 'contactPerson',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '联系电话',
|
||||||
|
dataIndex: 'contactPhone',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '地址',
|
||||||
|
dataIndex: 'address',
|
||||||
|
ellipsis: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '状态',
|
||||||
|
dataIndex: 'status',
|
||||||
|
width: 100,
|
||||||
|
render: (_, record) => (
|
||||||
|
<Switch
|
||||||
|
checked={record.status === 1}
|
||||||
|
onChange={(checked) => handleStatusChange(checked, record)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '创建时间',
|
||||||
|
dataIndex: 'createTime',
|
||||||
|
valueType: 'dateTime',
|
||||||
|
width: 180,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '操作',
|
||||||
|
key: 'action',
|
||||||
|
fixed: 'right',
|
||||||
|
width: 180,
|
||||||
|
render: (_, record) => (
|
||||||
|
<Space>
|
||||||
|
<Link
|
||||||
|
onClick={() => {
|
||||||
|
setCurrentRow(record);
|
||||||
|
handleUpdateModalVisible(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
修改
|
||||||
|
</Link>
|
||||||
|
<Popconfirm
|
||||||
|
title={`确认删除租户[${record.name}]?`}
|
||||||
|
onConfirm={async () => {
|
||||||
|
const success = await handleApiRequest(
|
||||||
|
() => deleteTenant(record.id!),
|
||||||
|
'正在删除',
|
||||||
|
'删除成功'
|
||||||
|
);
|
||||||
|
if (success && actionRef.current) {
|
||||||
|
actionRef.current.reload();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Link>删除</Link>
|
||||||
|
</Popconfirm>
|
||||||
|
</Space>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<PageContainer header={{ title: '租户管理' }}>
|
||||||
|
<QueryFilter
|
||||||
|
defaultCollapsed
|
||||||
|
split
|
||||||
|
span={6}
|
||||||
|
className="query-filter"
|
||||||
|
onFinish={async (values) => setParams(values)}
|
||||||
|
>
|
||||||
|
<ProFormText name="name" label="租户名称" placeholder="请输入租户名称" />
|
||||||
|
<ProFormText name="code" label="租户编码" placeholder="请输入租户编码" />
|
||||||
|
</QueryFilter>
|
||||||
|
|
||||||
|
<ProTable
|
||||||
|
rowKey="id"
|
||||||
|
headerTitle="租户列表"
|
||||||
|
actionRef={actionRef}
|
||||||
|
request={getTenantList}
|
||||||
|
columns={columns}
|
||||||
|
search={false}
|
||||||
|
params={params}
|
||||||
|
pagination={{
|
||||||
|
showSizeChanger: true,
|
||||||
|
showQuickJumper: true,
|
||||||
|
}}
|
||||||
|
toolBarRender={() => [
|
||||||
|
<Button
|
||||||
|
key="add"
|
||||||
|
type="primary"
|
||||||
|
onClick={() => handleCreateModalVisible(true)}
|
||||||
|
>
|
||||||
|
<PlusOutlined /> 新增租户
|
||||||
|
</Button>,
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<CreateForm
|
||||||
|
visible={createModalVisible}
|
||||||
|
onVisibleChange={handleCreateModalVisible}
|
||||||
|
onSubmit={async (values) => {
|
||||||
|
const success = await handleApiRequest(
|
||||||
|
() => saveOrUpdateTenant(values),
|
||||||
|
'正在添加',
|
||||||
|
'添加成功'
|
||||||
|
);
|
||||||
|
if (success) {
|
||||||
|
handleCreateModalVisible(false);
|
||||||
|
actionRef.current?.reload();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<UpdateForm
|
||||||
|
visible={updateModalVisible}
|
||||||
|
onVisibleChange={handleUpdateModalVisible}
|
||||||
|
values={currentRow}
|
||||||
|
onSubmit={async (values) => {
|
||||||
|
const success = await handleApiRequest(
|
||||||
|
() => saveOrUpdateTenant({ ...currentRow, ...values }),
|
||||||
|
'正在更新',
|
||||||
|
'更新成功'
|
||||||
|
);
|
||||||
|
if (success) {
|
||||||
|
handleUpdateModalVisible(false);
|
||||||
|
setCurrentRow(undefined);
|
||||||
|
actionRef.current?.reload();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</PageContainer>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TenantList;
|
||||||
@@ -247,3 +247,42 @@ export async function deleteToken(token: string) {
|
|||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取租户列表
|
||||||
|
export async function getTenantList(params?: { [key: string]: string | number }) {
|
||||||
|
const { current, pageSize, ...rest } = params ?? {};
|
||||||
|
const result = await request<SYSTEM.Page<SYSTEM.Tenant>>('/api-user/tenant/list', {
|
||||||
|
method: 'GET',
|
||||||
|
params: { page: current, limit: pageSize, ...rest },
|
||||||
|
});
|
||||||
|
return { data: result.data, total: result.count };
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取租户详情
|
||||||
|
export async function getTenantDetail(id: string) {
|
||||||
|
return request<API.Result<SYSTEM.Tenant>>(`/api-user/tenant/${id}`, {
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 保存或更新租户
|
||||||
|
export async function saveOrUpdateTenant(data: SYSTEM.Tenant): Promise<API.Result<SYSTEM.Tenant>> {
|
||||||
|
return request<API.Result<SYSTEM.Tenant>>('/api-user/tenant/save', {
|
||||||
|
method: 'POST',
|
||||||
|
data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除租户
|
||||||
|
export async function deleteTenant(id: string) {
|
||||||
|
return request<API.Result<void>>(`/api-user/tenant/${id}`, {
|
||||||
|
method: 'DELETE',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新租户状态
|
||||||
|
export async function updateTenantStatus(id: string, status: number) {
|
||||||
|
return request<API.Result<void>>(`/api-user/tenant/status/${id}/${status}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,4 +101,16 @@ declare namespace SYSTEM {
|
|||||||
tenantId?: string;
|
tenantId?: string;
|
||||||
updateTime?: string;
|
updateTime?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Tenant = {
|
||||||
|
id?: number;
|
||||||
|
name: string; // 租户名称
|
||||||
|
code: string; // 租户编码
|
||||||
|
contactPerson: string; // 联系人
|
||||||
|
contactPhone: string; // 联系电话
|
||||||
|
address?: string; // 地址
|
||||||
|
status: number; // 状态:0-禁用,1-启用
|
||||||
|
createTime?: Date; // 创建时间
|
||||||
|
updateTime?: Date; // 更新时间
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user