feat(tenant-balance): 新增提现站内信通知功能

在提现流程中,向租户联系人发送站内信通知,模板码 tx-001,携带提现金额参数。
This commit is contained in:
2025-12-26 21:42:42 +08:00
parent cfa2c89600
commit 128f840f7e

View File

@@ -10,6 +10,8 @@ import com.yolo.keyboard.framework.common.util.collection.CollectionUtils;
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yolo.keyboard.framework.tenant.core.context.TenantContextHolder;
import com.yolo.keyboard.module.infra.api.config.ConfigApi;
import com.yolo.keyboard.module.system.api.notify.NotifyMessageSendApi;
import com.yolo.keyboard.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
import com.yolo.keyboard.utils.BizNoGenerator;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
@@ -59,7 +61,11 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
@Resource
private KeyboardTenantWithdrawOrderMapper tenantWithdrawOrderMapper;
@Resource
private NotifyMessageSendApi notifyMessageSendApi;
private static final String WITHDRAW_DAYS_CONFIG_KEY = "WITHDRAW-DAYS";
private static final String WITHDRAW_NOTIFY_TEMPLATE_CODE = "tx-001";
@Override
public Long createTenantBalance(TenantBalanceSaveReqVO createReqVO) {
@@ -262,7 +268,7 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
// 6. 创建冻结交易记录
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
.bizNo(bizNo)
.points(withdrawAmount.negate()) // 冻结金额(负数表示冻结扣减)
.points(withdrawAmount.negate()) // 冻结金额(负数表示冻结扣减)
.balance(newBalance) // 扣减后的余额
.tenantId(tenantId)
.type("FREEZE")
@@ -300,6 +306,32 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
.updatedAt(now)
.build();
tenantWithdrawOrderMapper.insert(withdrawOrder);
// 8. 发送站内信通知
sendWithdrawNotify(tenantId, withdrawAmount);
}
/**
* 发送提现站内信通知
*
* @param tenantId 租户ID
* @param withdrawAmount 提现金额
*/
private void sendWithdrawNotify(Long tenantId, BigDecimal withdrawAmount) {
// 获取租户信息找到联系人用户ID
TenantDO tenant = tenantMapper.selectById(tenantId);
if (tenant == null || tenant.getContactUserId() == null) {
return;
}
// 构建站内信请求
NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO();
reqDTO.setUserId(tenant.getContactUserId());
reqDTO.setTemplateCode(WITHDRAW_NOTIFY_TEMPLATE_CODE);
reqDTO.setTemplateParams(Map.of("amount", withdrawAmount.toPlainString()));
// 发送站内信
notifyMessageSendApi.sendSingleMessageToAdmin(reqDTO);
}
/**