refactor(billing): 移除任务回调中的冗余字段和逻辑
- 移除了TaskRecord中parentCreateTime、taskRootId、parentTaskId等换哒新表补充字段 - 注释掉了chargeType相关变量和逻辑处理 - 移除了TaskRecordHistoryDO的创建和插入操作 - 移除了ConsumptionHistoryDO的创建和插入操作 - 移除了数据库余额查询和扣费相关逻辑 - 移除了taskRecordId返回值以简化回调响应 - 移除了TaskCallbackReq中taskId、parentTaskId、parentCreateTime、taskRootId等字段的验证注解
This commit is contained in:
parent
44c77a8a83
commit
16167f3111
|
|
@ -32,7 +32,7 @@ public class TaskCallbackReq {
|
||||||
* 任务订单号
|
* 任务订单号
|
||||||
*/
|
*/
|
||||||
@Schema(description = "任务订单号")
|
@Schema(description = "任务订单号")
|
||||||
@NotBlank(message = "任务订单号不能为空")
|
// @NotBlank(message = "任务订单号不能为空")
|
||||||
private String taskId;
|
private String taskId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -117,14 +117,14 @@ public class TaskCallbackReq {
|
||||||
@Schema(description = "文件类型")
|
@Schema(description = "文件类型")
|
||||||
private String fileType;
|
private String fileType;
|
||||||
|
|
||||||
@Schema(description = "父任务ID")
|
// @Schema(description = "父任务ID")
|
||||||
private String parentTaskId;
|
// private String parentTaskId;
|
||||||
|
|
||||||
@Schema(description = "父任务创建时间")
|
// @Schema(description = "父任务创建时间")
|
||||||
private String parentCreateTime;
|
// private String parentCreateTime;
|
||||||
|
|
||||||
@Schema(description = "根任务ID")
|
// @Schema(description = "根任务ID")
|
||||||
@NotBlank(message = "根任务ID不能为空")
|
// @NotBlank(message = "根任务ID不能为空")
|
||||||
private String taskRootId;
|
// private String taskRootId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -326,13 +326,6 @@ public class BillingServiceImpl implements BillingService {
|
||||||
taskRecord.setPlatformCode(req.getPlatformCode());
|
taskRecord.setPlatformCode(req.getPlatformCode());
|
||||||
taskRecord.setAccountType(deductSource);
|
taskRecord.setAccountType(deductSource);
|
||||||
|
|
||||||
//换哒新表补充字段
|
|
||||||
taskRecord.setParentCreateTime(extractDateTime(req.getParentCreateTime()));
|
|
||||||
taskRecord.setTaskRootId(req.getTaskRootId());
|
|
||||||
if (req.getParentTaskId() != null) {
|
|
||||||
taskRecord.setParentTaskId(req.getParentTaskId());
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置文件路径或文字内容
|
// 设置文件路径或文字内容
|
||||||
if (req.getTaskType() == 0 || !StringUtils.hasText(req.getFileUrl())) { // token类型或文字类型
|
if (req.getTaskType() == 0 || !StringUtils.hasText(req.getFileUrl())) { // token类型或文字类型
|
||||||
taskRecord.setResult(req.getResult());
|
taskRecord.setResult(req.getResult());
|
||||||
|
|
@ -789,7 +782,7 @@ public class BillingServiceImpl implements BillingService {
|
||||||
TaskPreDeductDO preDeductRecord,
|
TaskPreDeductDO preDeductRecord,
|
||||||
Long userId) {
|
Long userId) {
|
||||||
String deductSource = preDeductRecord.getDeductSource();
|
String deductSource = preDeductRecord.getDeductSource();
|
||||||
Integer chargeType = req.getChargeType();
|
// Integer chargeType = req.getChargeType();
|
||||||
|
|
||||||
// 使用第三方平台传入的实际消费金额
|
// 使用第三方平台传入的实际消费金额
|
||||||
Long actualConsumptionPoints = req.getActualAmount();
|
Long actualConsumptionPoints = req.getActualAmount();
|
||||||
|
|
@ -800,53 +793,53 @@ public class BillingServiceImpl implements BillingService {
|
||||||
log.info("使用第三方传入的实际消费金额, actualAmount: {}", actualConsumptionPoints);
|
log.info("使用第三方传入的实际消费金额, actualAmount: {}", actualConsumptionPoints);
|
||||||
|
|
||||||
// 2. 创建任务记录
|
// 2. 创建任务记录
|
||||||
TaskRecordHistoryDO taskRecord = new TaskRecordHistoryDO();
|
// TaskRecordHistoryDO taskRecord = new TaskRecordHistoryDO();
|
||||||
taskRecord.setUserId(userId);
|
// taskRecord.setUserId(userId);
|
||||||
taskRecord.setPlatformId(req.getPlatformId());
|
// taskRecord.setPlatformId(req.getPlatformId());
|
||||||
taskRecord.setTaskId(req.getTaskId());
|
// taskRecord.setTaskId(req.getTaskId());
|
||||||
taskRecord.setTitle(req.getTitle());
|
// taskRecord.setTitle(req.getTitle());
|
||||||
taskRecord.setTaskType(req.getTaskType());
|
// taskRecord.setTaskType(req.getTaskType());
|
||||||
taskRecord.setChargeType(req.getChargeType());
|
// taskRecord.setChargeType(req.getChargeType());
|
||||||
taskRecord.setModelName(req.getModelName());
|
// taskRecord.setModelName(req.getModelName());
|
||||||
taskRecord.setConsumptionPoints(actualConsumptionPoints);
|
// taskRecord.setConsumptionPoints(actualConsumptionPoints);
|
||||||
taskRecord.setPlatformCode(req.getPlatformCode());
|
// taskRecord.setPlatformCode(req.getPlatformCode());
|
||||||
taskRecord.setAccountType(deductSource);
|
// taskRecord.setAccountType(deductSource);
|
||||||
|
|
||||||
//换哒新表补充字段
|
//换哒新表补充字段
|
||||||
taskRecord.setParentCreateTime(extractDateTime(req.getParentCreateTime()));
|
// taskRecord.setParentCreateTime(extractDateTime(req.getParentCreateTime()));
|
||||||
taskRecord.setTaskRootId(req.getTaskRootId());
|
// taskRecord.setTaskRootId(req.getTaskRootId());
|
||||||
if (req.getParentTaskId() != null) {
|
// if (req.getParentTaskId() != null) {
|
||||||
taskRecord.setParentTaskId(req.getParentTaskId());
|
// taskRecord.setParentTaskId(req.getParentTaskId());
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// 设置文件路径或文字内容
|
// // 设置文件路径或文字内容
|
||||||
if (req.getTaskType() == 0 || !StringUtils.hasText(req.getFileUrl())) { // token类型或文字类型
|
// if (req.getTaskType() == 0 || !StringUtils.hasText(req.getFileUrl())) { // token类型或文字类型
|
||||||
taskRecord.setResult(req.getResult());
|
// taskRecord.setResult(req.getResult());
|
||||||
taskRecord.setTokens(req.getTokens());
|
// taskRecord.setTokens(req.getTokens());
|
||||||
taskRecordHistoryMapper.insert(taskRecord);
|
// taskRecordHistoryMapper.insert(taskRecord);
|
||||||
} else { // 音视频图片类型(2,3,4,5)
|
// } else { // 音视频图片类型(2,3,4,5)
|
||||||
addTaskRecordHistory(taskRecord, req);
|
// addTaskRecordHistory(taskRecord, req);
|
||||||
}
|
// }
|
||||||
|
|
||||||
// 3. 创建消费记录
|
// 3. 创建消费记录
|
||||||
ConsumptionHistoryDO consumption = new ConsumptionHistoryDO();
|
// ConsumptionHistoryDO consumption = new ConsumptionHistoryDO();
|
||||||
consumption.setUserId(userId);
|
// consumption.setUserId(userId);
|
||||||
consumption.setPlatformId(req.getPlatformId());
|
// consumption.setPlatformId(req.getPlatformId());
|
||||||
consumption.setTaskType(req.getTaskType());
|
// consumption.setTaskType(req.getTaskType());
|
||||||
consumption.setChargePoints(actualConsumptionPoints);
|
// consumption.setChargePoints(actualConsumptionPoints);
|
||||||
|
|
||||||
// 4. 根据扣减来源进行实际扣费和清零预扣减
|
// 4. 根据扣减来源进行实际扣费和清零预扣减
|
||||||
if (deductSource != null && deductSource.startsWith("sub_account_")) {
|
if (deductSource != null && deductSource.startsWith("sub_account_")) {
|
||||||
// 子账户扣费(chargeType特定的子账户)
|
// 子账户扣费(chargeType特定的子账户)
|
||||||
Integer extractedChargeType = Integer.parseInt(deductSource.substring("sub_account_".length()));
|
Integer extractedChargeType = Integer.parseInt(deductSource.substring("sub_account_".length()));
|
||||||
|
|
||||||
PlantformBalanceDO balance = plantformBalanceMapper.selectOne(new LambdaQueryWrapper<PlantformBalanceDO>()
|
// PlantformBalanceDO balance = plantformBalanceMapper.selectOne(new LambdaQueryWrapper<PlantformBalanceDO>()
|
||||||
.eq(PlantformBalanceDO::getUserId, userId)
|
// .eq(PlantformBalanceDO::getUserId, userId)
|
||||||
.eq(PlantformBalanceDO::getChargeType, extractedChargeType));
|
// .eq(PlantformBalanceDO::getChargeType, extractedChargeType));
|
||||||
|
|
||||||
consumption.setRemainingPoints(balance.getBalance() - actualConsumptionPoints);
|
// consumption.setRemainingPoints(balance.getBalance() - actualConsumptionPoints);
|
||||||
consumption.setType(req.getType()); // 消费类型
|
// consumption.setType(req.getType()); // 消费类型
|
||||||
consumption.setAccountType(1); // 1子账号
|
// consumption.setAccountType(1); // 1子账号
|
||||||
|
|
||||||
// 扣减实际金额并清零预扣减
|
// 扣减实际金额并清零预扣减
|
||||||
plantformBalanceMapper.update(null, new LambdaUpdateWrapper<PlantformBalanceDO>()
|
plantformBalanceMapper.update(null, new LambdaUpdateWrapper<PlantformBalanceDO>()
|
||||||
|
|
@ -858,13 +851,13 @@ public class BillingServiceImpl implements BillingService {
|
||||||
log.info("子账户扣费完成(第三方金额), chargeType: {}, actualConsumption: {}", extractedChargeType, actualConsumptionPoints);
|
log.info("子账户扣费完成(第三方金额), chargeType: {}, actualConsumption: {}", extractedChargeType, actualConsumptionPoints);
|
||||||
} else if ("kexuedou_account".equals(deductSource)) {
|
} else if ("kexuedou_account".equals(deductSource)) {
|
||||||
// 可学豆子账户扣费(chargeType=11的子账户)
|
// 可学豆子账户扣费(chargeType=11的子账户)
|
||||||
PlantformBalanceDO balance = plantformBalanceMapper.selectOne(new LambdaQueryWrapper<PlantformBalanceDO>()
|
// PlantformBalanceDO balance = plantformBalanceMapper.selectOne(new LambdaQueryWrapper<PlantformBalanceDO>()
|
||||||
.eq(PlantformBalanceDO::getUserId, userId)
|
// .eq(PlantformBalanceDO::getUserId, userId)
|
||||||
.eq(PlantformBalanceDO::getChargeType, 11));
|
// .eq(PlantformBalanceDO::getChargeType, 11));
|
||||||
|
|
||||||
consumption.setRemainingPoints(balance.getBalance() - actualConsumptionPoints);
|
// consumption.setRemainingPoints(balance.getBalance() - actualConsumptionPoints);
|
||||||
consumption.setType(req.getType()); // 消费类型
|
// consumption.setType(req.getType()); // 消费类型
|
||||||
consumption.setAccountType(1); // 1子账号
|
// consumption.setAccountType(1); // 1子账号
|
||||||
|
|
||||||
// 扣减实际金额并清零预扣减
|
// 扣减实际金额并清零预扣减
|
||||||
plantformBalanceMapper.update(null, new LambdaUpdateWrapper<PlantformBalanceDO>()
|
plantformBalanceMapper.update(null, new LambdaUpdateWrapper<PlantformBalanceDO>()
|
||||||
|
|
@ -876,10 +869,10 @@ public class BillingServiceImpl implements BillingService {
|
||||||
log.info("可学豆子账户扣费完成(第三方金额), actualConsumption: {}", actualConsumptionPoints);
|
log.info("可学豆子账户扣费完成(第三方金额), actualConsumption: {}", actualConsumptionPoints);
|
||||||
} else if ("main_account".equals(deductSource)) {
|
} else if ("main_account".equals(deductSource)) {
|
||||||
// 主账户sys_beans扣费
|
// 主账户sys_beans扣费
|
||||||
UserDO user = userMapper.selectById(userId);
|
// UserDO user = userMapper.selectById(userId);
|
||||||
consumption.setRemainingPoints(user.getSysBeans().longValue() - actualConsumptionPoints);
|
// consumption.setRemainingPoints(user.getSysBeans().longValue() - actualConsumptionPoints);
|
||||||
consumption.setType(req.getType()); // 消费类型
|
// consumption.setType(req.getType()); // 消费类型
|
||||||
consumption.setAccountType(0); // 0主账号
|
// consumption.setAccountType(0); // 0主账号
|
||||||
|
|
||||||
// 原子操作:扣减实际金额并清零预扣减 单位为分
|
// 原子操作:扣减实际金额并清零预扣减 单位为分
|
||||||
int updateResult = userMapper.deductActualAndClearPreDeduct(userId, preDeductRecord
|
int updateResult = userMapper.deductActualAndClearPreDeduct(userId, preDeductRecord
|
||||||
|
|
@ -894,7 +887,7 @@ public class BillingServiceImpl implements BillingService {
|
||||||
throw new RuntimeException("未知的扣减来源: " + deductSource);
|
throw new RuntimeException("未知的扣减来源: " + deductSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
consumptionHistoryMapper.insert(consumption);
|
// consumptionHistoryMapper.insert(consumption);
|
||||||
|
|
||||||
// 5. 更新预扣减记录状态
|
// 5. 更新预扣减记录状态
|
||||||
preDeductRecord.setStatus(1); // 1: 已完成
|
preDeductRecord.setStatus(1); // 1: 已完成
|
||||||
|
|
@ -903,11 +896,7 @@ public class BillingServiceImpl implements BillingService {
|
||||||
log.info("任务成功回调完成(第三方金额), taskId: {}, userId: {}, platformCode: {}, preDeduct: {}, actual: {}", req
|
log.info("任务成功回调完成(第三方金额), taskId: {}, userId: {}, platformCode: {}, preDeduct: {}, actual: {}", req
|
||||||
.getTaskId(), userId, req.getPlatformCode(), preDeductRecord.getPreDeductAmount(), actualConsumptionPoints);
|
.getTaskId(), userId, req.getPlatformCode(), preDeductRecord.getPreDeductAmount(), actualConsumptionPoints);
|
||||||
|
|
||||||
return TaskCallbackResp.builder()
|
return TaskCallbackResp.builder().success(true).message("任务成功,扣费完成(第三方金额)").build();
|
||||||
.success(true)
|
|
||||||
.message("任务成功,扣费完成(第三方金额)")
|
|
||||||
.taskRecordId(taskRecord.getId())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 过滤非法文件名字符(Windows/Linux兼容)
|
// 过滤非法文件名字符(Windows/Linux兼容)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue