refactor(system): 重构业务流水号生成器并优化租户转账描述
- 将 BizNoGenerator 改为基于 Hutool Snowflake 的全局唯一 ID,移除每日自增序列逻辑 - TenantBalanceTransferReqVO 用 password/remark 替换原 description 字段 - TenantPointsDO 新增 remark 字段 - 转账记录自动生成“转账给租户 X,金额:Y”与“转账来自租户 X,金额:Y”描述,并写入 remark
This commit is contained in:
@@ -21,11 +21,11 @@ public class TenantBalanceTransferReqVO {
|
||||
@NotNull(message = "增加的余额不能为空")
|
||||
private Integer transferAmount;
|
||||
|
||||
@Schema(description = "变动描述", example = "充值")
|
||||
@NotNull(message = "变动描述不能为空")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "登录密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "123456")
|
||||
@NotNull(message = "登录密码不能为空")
|
||||
private String password;
|
||||
|
||||
@Schema(description = "备注", example = "转账")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
@@ -64,4 +64,5 @@ public class TenantPointsDO {
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
private String remark;
|
||||
}
|
||||
@@ -237,8 +237,9 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
tenantPointsDO.setBalance(tenantNewBalance); // 设置变动后的余额
|
||||
tenantPointsDO.setOperatorId(loginUserId); // 设置操作人ID
|
||||
tenantPointsDO.setType(TRANSFER.getDesc()); // 设置交易类型为转账
|
||||
tenantPointsDO.setDescription(transferReqVO.getDescription()); // 设置交易描述
|
||||
tenantPointsDO.setDescription("转账给租户" + transferReqVO.getTargetTenantId() + ",金额:" + transferReqVO.getTransferAmount()); // 设置交易描述
|
||||
tenantPointsDO.setBizNo(transfer); // 设置业务流水号
|
||||
tenantPointsDO.setRemark(transferReqVO.getRemark());
|
||||
int tenantInsert = tenantPointsMapper.insert(tenantPointsDO); // 插入记录
|
||||
|
||||
// 创建转入方的积分变动记录
|
||||
@@ -248,7 +249,7 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
targetPointsDO.setBalance(targetTenantNewBalance); // 设置变动后的余额
|
||||
targetPointsDO.setOperatorId(loginUserId); // 设置操作人ID
|
||||
targetPointsDO.setType(TRANSFER.getDesc()); // 设置交易类型为转账
|
||||
targetPointsDO.setDescription(transferReqVO.getDescription()); // 设置交易描述
|
||||
targetPointsDO.setDescription("转账来自租户" + tenantId + ",金额:" + transferReqVO.getTransferAmount()); // 设置交易描述
|
||||
targetPointsDO.setBizNo(transfer); // 设置业务流水号(与转出方使用同一个流水号)
|
||||
int targetInsert = tenantPointsMapper.insert(targetPointsDO); // 插入记录
|
||||
|
||||
|
||||
@@ -1,34 +1,9 @@
|
||||
package cn.iocoder.yudao.module.system.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
|
||||
public class BizNoGenerator {
|
||||
|
||||
private static final AtomicInteger SEQUENCE = new AtomicInteger(0);
|
||||
private static final int MAX_SEQUENCE = 999999;
|
||||
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMMdd");
|
||||
|
||||
/**
|
||||
* 生成通用业务流水号
|
||||
* 格式:PREFIX-yyyyMMdd-000001
|
||||
*/
|
||||
public static String generate(String prefix) {
|
||||
String date = DATE_FORMAT.format(new Date());
|
||||
|
||||
// 自增序列(每天重置)
|
||||
int seq = SEQUENCE.incrementAndGet();
|
||||
if (seq > MAX_SEQUENCE) {
|
||||
synchronized (BizNoGenerator.class) {
|
||||
if (SEQUENCE.get() > MAX_SEQUENCE) {
|
||||
SEQUENCE.set(1);
|
||||
seq = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + "-" + date + "-" + String.format("%06d", seq);
|
||||
return prefix + "-" + IdUtil.getSnowflakeNextIdStr();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user