Compare commits
21 Commits
2eaf9a37d5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| a99f05d029 | |||
| bd315fcbd9 | |||
| 716cde6ea0 | |||
| 04755188d6 | |||
| b12f232f56 | |||
| d75a3e0212 | |||
| 299bc5e28b | |||
| d7ed10f45d | |||
| ca6e3d20f6 | |||
| 6fad3b45fe | |||
| a8da54c130 | |||
| d105bd4fa6 | |||
| be54601cdd | |||
| 2207add193 | |||
| 98e427c65a | |||
| baf38df6c3 | |||
| eb4b615ed6 | |||
| 2ed121926b | |||
| c07367ea53 | |||
| 7c72e60a32 | |||
| 0cab423604 |
@@ -0,0 +1,55 @@
|
||||
package com.yolo.keyboard.api.invitecode;
|
||||
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.yolo.keyboard.dal.dataobject.userinvitecodes.KeyboardUserInviteCodesDO;
|
||||
import com.yolo.keyboard.dal.mysql.userinvitecodes.KeyboardUserInviteCodesMapper;
|
||||
import com.yolo.keyboard.module.system.api.invitecode.UserInviteCodeApi;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 用户邀请码 API 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
public class UserInviteCodeApiImpl implements UserInviteCodeApi {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserInviteCodesMapper userInviteCodesMapper;
|
||||
|
||||
@Override
|
||||
public String createInviteCodeForAgent(Long userId, Long tenantId) {
|
||||
String inviteCode = generateUniqueInviteCode();
|
||||
KeyboardUserInviteCodesDO inviteCodeDO = KeyboardUserInviteCodesDO.builder()
|
||||
.code(inviteCode)
|
||||
.ownerSystemUserId(userId)
|
||||
.ownerTenantId(tenantId)
|
||||
.status((short) 1)
|
||||
.createdAt(LocalDateTime.now())
|
||||
.usedCount(0)
|
||||
.inviteType("AGENT")
|
||||
.build();
|
||||
userInviteCodesMapper.insert(inviteCodeDO);
|
||||
return inviteCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成唯一的6位邀请码(字母和数字混合)
|
||||
*/
|
||||
private String generateUniqueInviteCode() {
|
||||
String code;
|
||||
int maxAttempts = 100;
|
||||
int attempt = 0;
|
||||
do {
|
||||
code = RandomUtil.randomString("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 6);
|
||||
attempt++;
|
||||
if (attempt >= maxAttempts) {
|
||||
throw new RuntimeException("无法生成唯一的邀请码,请稍后重试");
|
||||
}
|
||||
} while (userInviteCodesMapper.selectOne(KeyboardUserInviteCodesDO::getCode, code) != null);
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yolo.keyboard.api.tenantbalance;
|
||||
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
import com.yolo.keyboard.module.system.api.tenantbalance.TenantBalanceApi;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 租户余额 API 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class TenantBalanceApiImpl implements TenantBalanceApi {
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Override
|
||||
public void initTenantBalance(Long tenantId) {
|
||||
// 检查是否已存在
|
||||
TenantBalanceDO existingBalance = tenantBalanceMapper.selectById(tenantId);
|
||||
if (existingBalance != null) {
|
||||
log.info("[initTenantBalance] 租户 {} 钱包已存在,跳过初始化", tenantId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 初始化租户钱包
|
||||
TenantBalanceDO balance = new TenantBalanceDO();
|
||||
balance.setId(tenantId);
|
||||
balance.setBalance(BigDecimal.ZERO);
|
||||
balance.setWithdrawableBalance(BigDecimal.ZERO);
|
||||
balance.setFrozenAmt(BigDecimal.ZERO);
|
||||
balance.setVersion(0);
|
||||
tenantBalanceMapper.insert(balance);
|
||||
|
||||
log.info("[initTenantBalance] 租户 {} 钱包初始化成功", tenantId);
|
||||
}
|
||||
}
|
||||
@@ -141,9 +141,10 @@ public class TenantBalanceController {
|
||||
@Operation(summary = "获得租户积分记录分页")
|
||||
@Parameter(name = "tenantId", description = "租户 Id")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-balance:query')")
|
||||
public CommonResult<PageResult<TenantBalanceTransactionDO>> getTenantBalanceTransactionPage(PageParam pageReqVO,
|
||||
public CommonResult<PageResult<TenantBalanceTransactionRespVO>> getTenantBalanceTransactionPage(PageParam pageReqVO,
|
||||
@RequestParam("tenantId") Long tenantId) {
|
||||
return success(tenantBalanceService.getTenantBalanceTransactionPage(pageReqVO, tenantId));
|
||||
PageResult<TenantBalanceTransactionDO> pageResult = tenantBalanceService.getTenantBalanceTransactionPage(pageReqVO, tenantId);
|
||||
return success(BeanUtils.toBean(pageResult, TenantBalanceTransactionRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/tenant-balance-transaction/create")
|
||||
@@ -183,7 +184,8 @@ public class TenantBalanceController {
|
||||
@Operation(summary = "获得租户积分记录")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-balance:query')")
|
||||
public CommonResult<TenantBalanceTransactionDO> getTenantBalanceTransaction(@RequestParam("id") Long id) {
|
||||
return success(tenantBalanceService.getTenantBalanceTransaction(id));
|
||||
public CommonResult<TenantBalanceTransactionRespVO> getTenantBalanceTransaction(@RequestParam("id") Long id) {
|
||||
TenantBalanceTransactionDO transaction = tenantBalanceService.getTenantBalanceTransaction(id);
|
||||
return success(BeanUtils.toBean(transaction, TenantBalanceTransactionRespVO.class));
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import static com.yolo.keyboard.framework.common.util.date.DateUtils.FORMAT_YEAR
|
||||
public class TenantBalancePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "当前积分余额")
|
||||
private Integer balance;
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号")
|
||||
private Integer version;
|
||||
@@ -27,4 +27,7 @@ public class TenantBalancePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "冻结金额")
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
@Schema(description = "可提现金额")
|
||||
private BigDecimal withdrawableBalance;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public class TenantBalanceRespVO {
|
||||
|
||||
@Schema(description = "当前积分余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("当前积分余额")
|
||||
private Integer balance;
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("乐观锁版本号")
|
||||
@@ -32,4 +32,7 @@ public class TenantBalanceRespVO {
|
||||
|
||||
@Schema(description = "冻结金额")
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
@Schema(description = "可提现金额")
|
||||
private BigDecimal withdrawableBalance;
|
||||
}
|
||||
@@ -18,7 +18,7 @@ public class TenantBalanceSaveReqVO {
|
||||
|
||||
@Schema(description = "当前积分余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "当前积分余额不能为空")
|
||||
private Integer balance;
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "乐观锁版本号不能为空")
|
||||
@@ -31,4 +31,6 @@ public class TenantBalanceSaveReqVO {
|
||||
@Schema(description = "冻结金额")
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
@Schema(description = "可提现金额")
|
||||
private BigDecimal withdrawableBalance;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.yolo.keyboard.controller.admin.tenantbalance.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 租户积分记录 Response VO")
|
||||
@Data
|
||||
public class TenantBalanceTransactionRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "本次变动点数,正加负减", requiredMode = Schema.RequiredMode.REQUIRED, example = "100.00")
|
||||
private BigDecimal points;
|
||||
|
||||
@Schema(description = "变动后余额快照", example = "1000.00")
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "变动后冻结金额快照", example = "200.00")
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
@Schema(description = "变动后可提现余额快照", example = "800.00")
|
||||
private BigDecimal withdrawableBalance;
|
||||
|
||||
@Schema(description = "变动类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "RECHARGE")
|
||||
private String type;
|
||||
|
||||
@Schema(description = "变动描述", example = "余额充值")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "订单Id/业务单号", example = "ORD123456")
|
||||
private String orderId;
|
||||
|
||||
@Schema(description = "业务流水号", example = "BIZ123456")
|
||||
private String bizNo;
|
||||
|
||||
@Schema(description = "操作人Id", example = "1")
|
||||
private Long operatorId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "备注", example = "管理员充值")
|
||||
private String remark;
|
||||
|
||||
@Schema(description = "租户Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.yolo.keyboard.controller.admin.tenantcommission;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.CommonResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
import static com.yolo.keyboard.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.yolo.keyboard.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.yolo.keyboard.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.yolo.keyboard.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.yolo.keyboard.controller.admin.tenantcommission.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.service.tenantcommission.KeyboardTenantCommissionService;
|
||||
|
||||
@Tag(name = "管理后台 - 租户内购分成记录")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/tenant-commission")
|
||||
@Validated
|
||||
public class KeyboardTenantCommissionController {
|
||||
|
||||
@Resource
|
||||
private KeyboardTenantCommissionService tenantCommissionService;
|
||||
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建租户内购分成记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:create')")
|
||||
public CommonResult<Long> createTenantCommission(@Valid @RequestBody KeyboardTenantCommissionSaveReqVO createReqVO) {
|
||||
|
||||
return success(tenantCommissionService.createTenantCommission(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新租户内购分成记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:update')")
|
||||
public CommonResult<Boolean> updateTenantCommission(@Valid @RequestBody KeyboardTenantCommissionSaveReqVO updateReqVO) {
|
||||
tenantCommissionService.updateTenantCommission(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除租户内购分成记录")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:delete')")
|
||||
public CommonResult<Boolean> deleteTenantCommission(@RequestParam("id") Long id) {
|
||||
tenantCommissionService.deleteTenantCommission(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除租户内购分成记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:delete')")
|
||||
public CommonResult<Boolean> deleteTenantCommissionList(@RequestParam("ids") List<Long> ids) {
|
||||
tenantCommissionService.deleteTenantCommissionListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得租户内购分成记录")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:query')")
|
||||
public CommonResult<KeyboardTenantCommissionRespVO> getTenantCommission(@RequestParam("id") Long id) {
|
||||
KeyboardTenantCommissionDO tenantCommission = tenantCommissionService.getTenantCommission(id);
|
||||
return success(BeanUtils.toBean(tenantCommission, KeyboardTenantCommissionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得租户内购分成记录分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:query')")
|
||||
public CommonResult<PageResult<KeyboardTenantCommissionRespVO>> getTenantCommissionPage(@Valid KeyboardTenantCommissionPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardTenantCommissionDO> pageResult = tenantCommissionService.getTenantCommissionPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardTenantCommissionRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出租户内购分成记录 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-commission:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportTenantCommissionExcel(@Valid KeyboardTenantCommissionPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardTenantCommissionDO> list = tenantCommissionService.getTenantCommissionPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "租户内购分成记录.xls", "数据", KeyboardTenantCommissionRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardTenantCommissionRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.yolo.keyboard.controller.admin.tenantcommission.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 租户内购分成记录分页 Request VO")
|
||||
@Data
|
||||
public class KeyboardTenantCommissionPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "租户ID", example = "1", hidden = true)
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "内购记录ID", example = "20900")
|
||||
private Integer purchaseRecordId;
|
||||
|
||||
@Schema(description = "内购交易ID", example = "30383")
|
||||
private String transactionId;
|
||||
|
||||
@Schema(description = "被邀请用户ID(购买用户)", example = "2447")
|
||||
private Integer inviteeUserId;
|
||||
|
||||
@Schema(description = "邀请人用户ID", example = "1012")
|
||||
private Long inviterUserId;
|
||||
|
||||
@Schema(description = "内购金额")
|
||||
private BigDecimal purchaseAmount;
|
||||
|
||||
@Schema(description = "分成比例")
|
||||
private BigDecimal commissionRate;
|
||||
|
||||
@Schema(description = "分成金额")
|
||||
private BigDecimal commissionAmount;
|
||||
|
||||
@Schema(description = "状态:PENDING-待结算,SETTLED-已结算,REFUNDED-已退款", example = "2")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "内购时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] purchaseTime;
|
||||
|
||||
@Schema(description = "结算时间")
|
||||
private LocalDateTime settledAt;
|
||||
|
||||
@Schema(description = "关联的余额交易记录ID", example = "29131")
|
||||
private Long balanceTransactionId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.yolo.keyboard.controller.admin.tenantcommission.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import cn.idev.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 租户内购分成记录 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class KeyboardTenantCommissionRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3144")
|
||||
@ExcelProperty("主键")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "内购记录ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20900")
|
||||
@ExcelProperty("内购记录ID")
|
||||
private Integer purchaseRecordId;
|
||||
|
||||
@Schema(description = "内购交易ID", example = "30383")
|
||||
@ExcelProperty("内购交易ID")
|
||||
private String transactionId;
|
||||
|
||||
@Schema(description = "被邀请用户ID(购买用户)", example = "2447")
|
||||
@ExcelProperty("被邀请用户ID(购买用户)")
|
||||
private Integer inviteeUserId;
|
||||
|
||||
@Schema(description = "邀请人用户ID", example = "1012")
|
||||
@ExcelProperty("邀请人用户ID")
|
||||
private Long inviterUserId;
|
||||
|
||||
@Schema(description = "内购金额")
|
||||
@ExcelProperty("内购金额")
|
||||
private BigDecimal purchaseAmount;
|
||||
|
||||
@Schema(description = "分成比例")
|
||||
@ExcelProperty("分成比例")
|
||||
private BigDecimal commissionRate;
|
||||
|
||||
@Schema(description = "分成金额")
|
||||
@ExcelProperty("分成金额")
|
||||
private BigDecimal commissionAmount;
|
||||
|
||||
@Schema(description = "状态:PENDING-待结算,SETTLED-已结算,REFUNDED-已退款", example = "2")
|
||||
@ExcelProperty("状态:PENDING-待结算,SETTLED-已结算,REFUNDED-已退款")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "内购时间")
|
||||
@ExcelProperty("内购时间")
|
||||
private LocalDateTime purchaseTime;
|
||||
|
||||
@Schema(description = "结算时间")
|
||||
@ExcelProperty("结算时间")
|
||||
private LocalDateTime settledAt;
|
||||
|
||||
@Schema(description = "关联的余额交易记录ID", example = "29131")
|
||||
@ExcelProperty("关联的余额交易记录ID")
|
||||
private Long balanceTransactionId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
@ExcelProperty("备注")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.yolo.keyboard.controller.admin.tenantcommission.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
import java.math.BigDecimal;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 租户内购分成记录新增/修改 Request VO")
|
||||
@Data
|
||||
public class KeyboardTenantCommissionSaveReqVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "3144")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "内购记录ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "20900")
|
||||
@NotNull(message = "内购记录ID不能为空")
|
||||
private Integer purchaseRecordId;
|
||||
|
||||
@Schema(description = "内购交易ID", example = "30383")
|
||||
private String transactionId;
|
||||
|
||||
@Schema(description = "被邀请用户ID(购买用户)", example = "2447")
|
||||
private Integer inviteeUserId;
|
||||
|
||||
@Schema(description = "邀请人用户ID", example = "1012")
|
||||
private Long inviterUserId;
|
||||
|
||||
@Schema(description = "内购金额")
|
||||
private BigDecimal purchaseAmount;
|
||||
|
||||
@Schema(description = "分成比例")
|
||||
private BigDecimal commissionRate;
|
||||
|
||||
@Schema(description = "分成金额")
|
||||
private BigDecimal commissionAmount;
|
||||
|
||||
@Schema(description = "状态:PENDING-待结算,SETTLED-已结算,REFUNDED-已退款", example = "2")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "内购时间")
|
||||
private LocalDateTime purchaseTime;
|
||||
|
||||
@Schema(description = "结算时间")
|
||||
private LocalDateTime settledAt;
|
||||
|
||||
@Schema(description = "关联的余额交易记录ID", example = "29131")
|
||||
private Long balanceTransactionId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "备注", example = "随便")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -84,8 +84,8 @@ public class KeyboardTenantWithdrawOrderController {
|
||||
@Operation(summary = "获得租户提现订单表(申请-审核-打款-完成/失败)分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tenant-withdraw-order:query')")
|
||||
public CommonResult<PageResult<KeyboardTenantWithdrawOrderRespVO>> getTenantWithdrawOrderPage(@Valid KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> pageResult = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardTenantWithdrawOrderRespVO.class));
|
||||
PageResult<KeyboardTenantWithdrawOrderRespVO> pageResult = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO);
|
||||
return success(pageResult);
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@@ -95,10 +95,9 @@ public class KeyboardTenantWithdrawOrderController {
|
||||
public void exportTenantWithdrawOrderExcel(@Valid KeyboardTenantWithdrawOrderPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardTenantWithdrawOrderDO> list = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO).getList();
|
||||
List<KeyboardTenantWithdrawOrderRespVO> list = tenantWithdrawOrderService.getTenantWithdrawOrderPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "租户提现订单表(申请-审核-打款-完成/失败).xls", "数据", KeyboardTenantWithdrawOrderRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardTenantWithdrawOrderRespVO.class));
|
||||
ExcelUtils.write(response, "租户提现订单表(申请-审核-打款-完成/失败).xls", "数据", KeyboardTenantWithdrawOrderRespVO.class, list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,4 +111,7 @@ public class KeyboardTenantWithdrawOrderPageReqVO extends PageParam {
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "租户ID列表(用于下级租户过滤)", hidden = true)
|
||||
private List<Long> tenantIds;
|
||||
|
||||
}
|
||||
@@ -142,4 +142,12 @@ public class KeyboardTenantWithdrawOrderRespVO {
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "租户编号", example = "1")
|
||||
@ExcelProperty("租户编号")
|
||||
private Long tenantId;
|
||||
|
||||
@Schema(description = "租户名称", example = "芋道源码")
|
||||
@ExcelProperty("租户名称")
|
||||
private String tenantName;
|
||||
|
||||
}
|
||||
@@ -34,14 +34,11 @@ public class KeyboardUserInviteCodesPageReqVO extends PageParam {
|
||||
@Schema(description = "邀请码已使用次数", example = "25037")
|
||||
private Integer usedCount;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户ID(邀请人)", example = "20047")
|
||||
private Long systemUserId;
|
||||
|
||||
@Schema(description = "邀请码所属租户", example = "17355")
|
||||
private Long ownerTenantId;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户", example = "772")
|
||||
private Long owenrSystemUserId;
|
||||
private Long ownerSystemUserId;
|
||||
|
||||
@Schema(description = "邀请码类型", example = "1")
|
||||
private String inviteType;
|
||||
|
||||
@@ -44,17 +44,13 @@ public class KeyboardUserInviteCodesRespVO {
|
||||
@ExcelProperty("邀请码已使用次数")
|
||||
private Integer usedCount;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户ID(邀请人)", example = "20047")
|
||||
@ExcelProperty("邀请码所属系统用户ID(邀请人)")
|
||||
private Long systemUserId;
|
||||
|
||||
@Schema(description = "邀请码所属租户", example = "17355")
|
||||
@ExcelProperty("邀请码所属租户")
|
||||
private Long ownerTenantId;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户", example = "772")
|
||||
@Schema(description = "邀请码所属系统用户ID(邀请人)", example = "772")
|
||||
@ExcelProperty("邀请码所属系统用户")
|
||||
private Long owenrSystemUserId;
|
||||
private Long ownerSystemUserId;
|
||||
|
||||
@Schema(description = "邀请码类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@ExcelProperty("邀请码类型")
|
||||
|
||||
@@ -40,14 +40,11 @@ public class KeyboardUserInviteCodesSaveReqVO {
|
||||
@NotNull(message = "邀请码已使用次数不能为空")
|
||||
private Integer usedCount;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户ID(邀请人)", example = "20047")
|
||||
private Long systemUserId;
|
||||
|
||||
@Schema(description = "邀请码所属租户", example = "17355")
|
||||
private Long ownerTenantId;
|
||||
|
||||
@Schema(description = "邀请码所属系统用户", example = "772")
|
||||
private Long owenrSystemUserId;
|
||||
private Long ownerSystemUserId;
|
||||
|
||||
@Schema(description = "邀请码类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
@NotEmpty(message = "邀请码类型不能为空")
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("system_tenant_balance")
|
||||
@KeySequence("system_tenant_balance_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
//@KeySequence("system_tenant_balance_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@@ -49,4 +49,5 @@ public class TenantBalanceDO extends BaseDO {
|
||||
*/
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
private BigDecimal withdrawableBalance;
|
||||
}
|
||||
@@ -67,4 +67,8 @@ public class TenantBalanceTransactionDO {
|
||||
private String remark;
|
||||
|
||||
private Long tenantId;
|
||||
|
||||
private BigDecimal frozenAmt;
|
||||
|
||||
private BigDecimal withdrawableBalance;
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package com.yolo.keyboard.dal.dataobject.tenantcommission;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import lombok.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 租户分成记录 DO
|
||||
* 记录每笔内购订单的分成计算结果
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@TableName("keyboard_tenant_commission")
|
||||
@KeySequence("keyboard_tenant_commission_seq")
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardTenantCommissionDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 内购记录ID
|
||||
*/
|
||||
private Integer purchaseRecordId;
|
||||
|
||||
/**
|
||||
* 内购交易ID(唯一标识)
|
||||
*/
|
||||
private String transactionId;
|
||||
|
||||
/**
|
||||
* 被邀请用户ID(购买用户)
|
||||
*/
|
||||
private Integer inviteeUserId;
|
||||
|
||||
/**
|
||||
* 邀请人用户ID
|
||||
*/
|
||||
private Long inviterUserId;
|
||||
|
||||
/**
|
||||
* 收益归属租户ID
|
||||
*/
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 内购金额
|
||||
*/
|
||||
private BigDecimal purchaseAmount;
|
||||
|
||||
/**
|
||||
* 分成比例
|
||||
*/
|
||||
private BigDecimal commissionRate;
|
||||
|
||||
/**
|
||||
* 分成金额
|
||||
*/
|
||||
private BigDecimal commissionAmount;
|
||||
|
||||
/**
|
||||
* 状态:PENDING-待结算,SETTLED-已结算,REFUNDED-已退款
|
||||
*/
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 内购时间
|
||||
*/
|
||||
private LocalDateTime purchaseTime;
|
||||
|
||||
/**
|
||||
* 结算时间
|
||||
*/
|
||||
private LocalDateTime settledAt;
|
||||
|
||||
/**
|
||||
* 关联的余额交易记录ID
|
||||
*/
|
||||
private Long balanceTransactionId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
/**
|
||||
* 可提现时间(结算时间 + 30天)
|
||||
*/
|
||||
private LocalDateTime withdrawableAt;
|
||||
|
||||
/**
|
||||
* 是否已处理转可提现:false-未处理,true-已处理
|
||||
*/
|
||||
private Boolean withdrawableProcessed;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
* @author ziin
|
||||
*/
|
||||
@TableName("keyboard_user_invite_codes")
|
||||
@KeySequence("keyboard_user_invite_codes_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@KeySequence("invite_codes_id_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@@ -56,10 +56,6 @@ public class KeyboardUserInviteCodesDO {
|
||||
* 邀请码已使用次数
|
||||
*/
|
||||
private Integer usedCount;
|
||||
/**
|
||||
* 邀请码所属系统用户ID(邀请人)
|
||||
*/
|
||||
private Long systemUserId;
|
||||
/**
|
||||
* 邀请码所属租户
|
||||
*/
|
||||
@@ -67,7 +63,7 @@ public class KeyboardUserInviteCodesDO {
|
||||
/**
|
||||
* 邀请码所属系统用户
|
||||
*/
|
||||
private Long owenrSystemUserId;
|
||||
private Long ownerSystemUserId;
|
||||
/**
|
||||
* 邀请码类型
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.yolo.keyboard.dal.mysql.tenantcommission;
|
||||
|
||||
import com.yolo.keyboard.controller.admin.tenantcommission.vo.KeyboardTenantCommissionPageReqVO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 租户分成记录 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardTenantCommissionMapper extends BaseMapperX<KeyboardTenantCommissionDO> {
|
||||
|
||||
/**
|
||||
* 根据交易ID查询分成记录
|
||||
*/
|
||||
default KeyboardTenantCommissionDO selectByTransactionId(String transactionId) {
|
||||
return selectOne(KeyboardTenantCommissionDO::getTransactionId, transactionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据内购记录ID查询分成记录
|
||||
*/
|
||||
default KeyboardTenantCommissionDO selectByPurchaseRecordId(Integer purchaseRecordId) {
|
||||
return selectOne(KeyboardTenantCommissionDO::getPurchaseRecordId, purchaseRecordId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据内购记录ID和租户ID查询分成记录
|
||||
* 用于检查某个租户是否已经对某条内购记录计算过分成
|
||||
*/
|
||||
default KeyboardTenantCommissionDO selectByPurchaseRecordIdAndTenantId(Integer purchaseRecordId, Long tenantId) {
|
||||
return selectOne(new LambdaQueryWrapperX<KeyboardTenantCommissionDO>()
|
||||
.eq(KeyboardTenantCommissionDO::getPurchaseRecordId, purchaseRecordId)
|
||||
.eq(KeyboardTenantCommissionDO::getTenantId, tenantId));
|
||||
}
|
||||
|
||||
default PageResult<KeyboardTenantCommissionDO> selectPage(KeyboardTenantCommissionPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardTenantCommissionDO>()
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getTenantId, reqVO.getTenantId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getPurchaseRecordId, reqVO.getPurchaseRecordId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getTransactionId, reqVO.getTransactionId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getInviteeUserId, reqVO.getInviteeUserId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getInviterUserId, reqVO.getInviterUserId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getPurchaseAmount, reqVO.getPurchaseAmount())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getCommissionRate, reqVO.getCommissionRate())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getCommissionAmount, reqVO.getCommissionAmount())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getStatus, reqVO.getStatus())
|
||||
.betweenIfPresent(KeyboardTenantCommissionDO::getPurchaseTime, reqVO.getPurchaseTime())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getSettledAt, reqVO.getSettledAt())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getBalanceTransactionId, reqVO.getBalanceTransactionId())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getCreatedAt, reqVO.getCreatedAt())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.eqIfPresent(KeyboardTenantCommissionDO::getRemark, reqVO.getRemark())
|
||||
.orderByDesc(KeyboardTenantCommissionDO::getId));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public interface KeyboardTenantWithdrawOrderMapper extends BaseMapperX<KeyboardT
|
||||
|
||||
default PageResult<KeyboardTenantWithdrawOrderDO> selectPage(KeyboardTenantWithdrawOrderPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardTenantWithdrawOrderDO>()
|
||||
.inIfPresent(KeyboardTenantWithdrawOrderDO::getTenantId, reqVO.getTenantIds())
|
||||
.eqIfPresent(KeyboardTenantWithdrawOrderDO::getWithdrawNo, reqVO.getWithdrawNo())
|
||||
.eqIfPresent(KeyboardTenantWithdrawOrderDO::getBizNo, reqVO.getBizNo())
|
||||
.eqIfPresent(KeyboardTenantWithdrawOrderDO::getCurrency, reqVO.getCurrency())
|
||||
|
||||
@@ -26,9 +26,8 @@ public interface KeyboardUserInviteCodesMapper extends BaseMapperX<KeyboardUserI
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getExpiresAt, reqVO.getExpiresAt())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getMaxUses, reqVO.getMaxUses())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getUsedCount, reqVO.getUsedCount())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getSystemUserId, reqVO.getSystemUserId())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getOwnerTenantId, reqVO.getOwnerTenantId())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getOwenrSystemUserId, reqVO.getOwenrSystemUserId())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getOwnerSystemUserId, reqVO.getOwnerSystemUserId())
|
||||
.eqIfPresent(KeyboardUserInviteCodesDO::getInviteType, reqVO.getInviteType())
|
||||
.orderByDesc(KeyboardUserInviteCodesDO::getId));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
package com.yolo.keyboard.job;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalancetransaction.TenantBalanceTransactionDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalancetransaction.TenantBalanceTransactionMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantcommission.KeyboardTenantCommissionMapper;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.yolo.keyboard.framework.quartz.core.handler.JobHandler;
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.yolo.keyboard.utils.BizNoGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 分成可提现转换定时任务
|
||||
* 每小时执行一次,将满30天的分成金额转为可提现余额
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CommissionWithdrawableJob implements JobHandler {
|
||||
|
||||
@Resource
|
||||
private KeyboardTenantCommissionMapper commissionMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceTransactionMapper balanceTransactionMapper;
|
||||
|
||||
private static final String WITHDRAWABLE_TYPE = "WITHDRAWABLE";
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String execute(String param) {
|
||||
log.info("[CommissionWithdrawableJob] 开始执行分成可提现转换任务");
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 1. 查询已到可提现时间且未处理的分成记录
|
||||
List<KeyboardTenantCommissionDO> commissions = commissionMapper.selectList(
|
||||
new LambdaQueryWrapperX<KeyboardTenantCommissionDO>()
|
||||
.le(KeyboardTenantCommissionDO::getWithdrawableAt, now)
|
||||
.eq(KeyboardTenantCommissionDO::getWithdrawableProcessed, false)
|
||||
.eq(KeyboardTenantCommissionDO::getStatus, "SETTLED")
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(commissions)) {
|
||||
log.info("[CommissionWithdrawableJob] 没有需要处理的分成记录");
|
||||
return "没有需要处理的分成记录";
|
||||
}
|
||||
|
||||
// 2. 按租户分组汇总金额
|
||||
Map<Long, List<KeyboardTenantCommissionDO>> tenantCommissionsMap = commissions.stream()
|
||||
.collect(Collectors.groupingBy(KeyboardTenantCommissionDO::getTenantId));
|
||||
|
||||
int tenantCount = 0;
|
||||
int commissionCount = 0;
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
|
||||
// 3. 逐个租户处理
|
||||
for (Map.Entry<Long, List<KeyboardTenantCommissionDO>> entry : tenantCommissionsMap.entrySet()) {
|
||||
Long tenantId = entry.getKey();
|
||||
List<KeyboardTenantCommissionDO> tenantCommissions = entry.getValue();
|
||||
|
||||
// 计算该租户的总可提现金额
|
||||
BigDecimal tenantTotalAmount = tenantCommissions.stream()
|
||||
.map(KeyboardTenantCommissionDO::getCommissionAmount)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
|
||||
// 更新租户可提现余额
|
||||
TenantBalanceDO balance = tenantBalanceMapper.selectById(tenantId);
|
||||
if (balance == null) {
|
||||
log.warn("[CommissionWithdrawableJob] 租户 {} 余额记录不存在,跳过", tenantId);
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal currentWithdrawable = balance.getWithdrawableBalance() != null
|
||||
? balance.getWithdrawableBalance() : BigDecimal.ZERO;
|
||||
BigDecimal newWithdrawable = currentWithdrawable.add(tenantTotalAmount);
|
||||
balance.setWithdrawableBalance(newWithdrawable);
|
||||
tenantBalanceMapper.updateById(balance);
|
||||
|
||||
// 创建余额交易记录
|
||||
String bizNo = BizNoGenerator.generate("WDB");
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(bizNo)
|
||||
.points(tenantTotalAmount)
|
||||
.balance(balance.getBalance())
|
||||
.frozenAmt(balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO)
|
||||
.withdrawableBalance(newWithdrawable)
|
||||
.tenantId(tenantId)
|
||||
.type(WITHDRAWABLE_TYPE)
|
||||
.description("分成转可提现")
|
||||
.createdAt(now)
|
||||
.remark("共 " + tenantCommissions.size() + " 笔分成转为可提现")
|
||||
.build();
|
||||
balanceTransactionMapper.insert(transaction);
|
||||
|
||||
// 标记分成记录为已处理
|
||||
for (KeyboardTenantCommissionDO commission : tenantCommissions) {
|
||||
commission.setWithdrawableProcessed(true);
|
||||
commission.setUpdatedAt(now);
|
||||
commissionMapper.updateById(commission);
|
||||
}
|
||||
|
||||
tenantCount++;
|
||||
commissionCount += tenantCommissions.size();
|
||||
totalAmount = totalAmount.add(tenantTotalAmount);
|
||||
|
||||
log.info("[CommissionWithdrawableJob] 处理租户 {},分成 {} 笔,金额 {}",
|
||||
tenantId, tenantCommissions.size(), tenantTotalAmount);
|
||||
}
|
||||
|
||||
String result = String.format("处理租户 %d 个,分成记录 %d 条,总金额 %s",
|
||||
tenantCount, commissionCount, totalAmount.toPlainString());
|
||||
log.info("[CommissionWithdrawableJob] 任务执行完成: {}", result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
package com.yolo.keyboard.job;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalancetransaction.TenantBalanceTransactionDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.dal.dataobject.userinvites.KeyboardUserInvitesDO;
|
||||
import com.yolo.keyboard.dal.dataobject.userpurchaserecords.KeyboardUserPurchaseRecordsDO;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalancetransaction.TenantBalanceTransactionMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantcommission.KeyboardTenantCommissionMapper;
|
||||
import com.yolo.keyboard.dal.mysql.userinvites.KeyboardUserInvitesMapper;
|
||||
import com.yolo.keyboard.dal.mysql.userpurchaserecords.KeyboardUserPurchaseRecordsMapper;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.yolo.keyboard.framework.quartz.core.handler.JobHandler;
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.dal.mysql.tenant.TenantMapper;
|
||||
import com.yolo.keyboard.utils.BizNoGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 租户分成计算定时任务
|
||||
* 每小时执行一次,计算邀请用户的内购分成
|
||||
* 支持一级代理和二级代理的分成计算
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class TenantCommissionCalculateJob implements JobHandler {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserPurchaseRecordsMapper purchaseRecordsMapper;
|
||||
|
||||
@Resource
|
||||
private KeyboardUserInvitesMapper userInvitesMapper;
|
||||
|
||||
@Resource
|
||||
private KeyboardTenantCommissionMapper commissionMapper;
|
||||
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceTransactionMapper balanceTransactionMapper;
|
||||
|
||||
private static final String COMMISSION_TYPE = "COMMISSION";
|
||||
private static final String STATUS_PAID = "PAID";
|
||||
private static final String INVITE_TYPE_AGENT = "AGENT";
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String execute(String param) {
|
||||
log.info("[TenantCommissionCalculateJob] 开始执行分成计算任务");
|
||||
|
||||
// 1. 查询最近一小时内已支付的内购记录
|
||||
LocalDateTime endTime = LocalDateTime.now();
|
||||
LocalDateTime startTime = endTime.minusHours(1);
|
||||
|
||||
List<KeyboardUserPurchaseRecordsDO> purchaseRecords = purchaseRecordsMapper.selectList(
|
||||
new LambdaQueryWrapperX<KeyboardUserPurchaseRecordsDO>()
|
||||
.eq(KeyboardUserPurchaseRecordsDO::getStatus, STATUS_PAID)
|
||||
.between(KeyboardUserPurchaseRecordsDO::getPurchaseTime, startTime, endTime)
|
||||
);
|
||||
|
||||
if (CollUtil.isEmpty(purchaseRecords)) {
|
||||
log.info("[TenantCommissionCalculateJob] 最近一小时内没有已支付的内购记录");
|
||||
return "没有需要处理的内购记录";
|
||||
}
|
||||
|
||||
int processedCount = 0;
|
||||
int commissionCount = 0;
|
||||
BigDecimal totalCommission = BigDecimal.ZERO;
|
||||
|
||||
// 2. 遍历内购记录,检查是否有邀请关系
|
||||
for (KeyboardUserPurchaseRecordsDO record : purchaseRecords) {
|
||||
// 检查是否已经计算过分成
|
||||
if (commissionMapper.selectByPurchaseRecordId(record.getId()) != null) {
|
||||
log.debug("[TenantCommissionCalculateJob] 内购记录 {} 已计算过分成,跳过", record.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
processedCount++;
|
||||
|
||||
// 查询该用户的邀请关系
|
||||
KeyboardUserInvitesDO invite = userInvitesMapper.selectOne(
|
||||
KeyboardUserInvitesDO::getInviteeUserId, record.getUserId().longValue()
|
||||
);
|
||||
|
||||
if (invite == null) {
|
||||
log.debug("[TenantCommissionCalculateJob] 用户 {} 没有邀请关系,跳过", record.getUserId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 只处理代理邀请类型
|
||||
if (!INVITE_TYPE_AGENT.equals(invite.getInviteType())) {
|
||||
log.debug("[TenantCommissionCalculateJob] 用户 {} 的邀请类型不是代理,跳过", record.getUserId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取收益归属租户(邀请人所属租户)
|
||||
Long inviterTenantId = invite.getProfitTenantId();
|
||||
if (inviterTenantId == null) {
|
||||
inviterTenantId = invite.getInviterTenantId();
|
||||
}
|
||||
if (inviterTenantId == null) {
|
||||
log.warn("[TenantCommissionCalculateJob] 用户 {} 的邀请关系没有关联租户,跳过", record.getUserId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取邀请人租户信息
|
||||
TenantDO inviterTenant = tenantMapper.selectById(inviterTenantId);
|
||||
if (inviterTenant == null) {
|
||||
log.warn("[TenantCommissionCalculateJob] 租户 {} 不存在,跳过", inviterTenantId);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取内购金额
|
||||
BigDecimal purchaseAmount = record.getPrice();
|
||||
if (purchaseAmount == null || purchaseAmount.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
log.debug("[TenantCommissionCalculateJob] 内购记录 {} 金额无效,跳过", record.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime withdrawableAt = now.plusDays(30);
|
||||
|
||||
// 判断是否是二级代理(有上级租户)
|
||||
if (inviterTenant.getParentId() != null) {
|
||||
// 二级代理场景:需要给一级代理和二级代理都分成
|
||||
TenantDO parentTenant = tenantMapper.selectById(inviterTenant.getParentId());
|
||||
if (parentTenant == null) {
|
||||
log.warn("[TenantCommissionCalculateJob] 上级租户 {} 不存在,跳过", inviterTenant.getParentId());
|
||||
continue;
|
||||
}
|
||||
|
||||
// 使用一级代理的分成比例计算总分成
|
||||
BigDecimal totalCommissionRate = parentTenant.getProfitShareRatio();
|
||||
if (totalCommissionRate == null || totalCommissionRate.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
log.debug("[TenantCommissionCalculateJob] 一级代理租户 {} 没有设置分成比例,跳过", parentTenant.getId());
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal totalCommissionAmount = purchaseAmount.multiply(totalCommissionRate)
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 获取二级代理的返点比例
|
||||
BigDecimal rebateRatio = inviterTenant.getUpstreamRebateRatio();
|
||||
if (rebateRatio == null || rebateRatio.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
// 如果没有设置返点比例,全部归一级代理
|
||||
log.debug("[TenantCommissionCalculateJob] 二级代理租户 {} 没有设置返点比例,全部归一级代理", inviterTenantId);
|
||||
int count = createCommissionRecord(record, invite, parentTenant.getId(), purchaseAmount,
|
||||
totalCommissionRate, totalCommissionAmount, now, withdrawableAt,
|
||||
"一级代理分成(二级代理无返点)");
|
||||
commissionCount += count;
|
||||
totalCommission = totalCommission.add(totalCommissionAmount);
|
||||
} else {
|
||||
// 计算二级代理分成
|
||||
BigDecimal secondLevelAmount = totalCommissionAmount.multiply(rebateRatio)
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
// 计算一级代理分成
|
||||
BigDecimal firstLevelAmount = totalCommissionAmount.subtract(secondLevelAmount);
|
||||
|
||||
// 为二级代理创建分成记录
|
||||
if (secondLevelAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
int count = createCommissionRecord(record, invite, inviterTenantId, purchaseAmount,
|
||||
rebateRatio, secondLevelAmount, now, withdrawableAt,
|
||||
"二级代理分成");
|
||||
commissionCount += count;
|
||||
totalCommission = totalCommission.add(secondLevelAmount);
|
||||
log.info("[TenantCommissionCalculateJob] 内购记录 {}, 二级代理 {}, 分成金额 {}",
|
||||
record.getId(), inviterTenantId, secondLevelAmount);
|
||||
}
|
||||
|
||||
// 为一级代理创建分成记录
|
||||
if (firstLevelAmount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
BigDecimal firstLevelRate = BigDecimal.ONE.subtract(rebateRatio);
|
||||
int count = createCommissionRecord(record, invite, parentTenant.getId(), purchaseAmount,
|
||||
firstLevelRate, firstLevelAmount, now, withdrawableAt,
|
||||
"一级代理分成(扣除二级返点)");
|
||||
commissionCount += count;
|
||||
totalCommission = totalCommission.add(firstLevelAmount);
|
||||
log.info("[TenantCommissionCalculateJob] 内购记录 {}, 一级代理 {}, 分成金额 {}",
|
||||
record.getId(), parentTenant.getId(), firstLevelAmount);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 一级代理场景:全部分成归一级代理
|
||||
BigDecimal commissionRate = inviterTenant.getProfitShareRatio();
|
||||
if (commissionRate == null || commissionRate.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
log.debug("[TenantCommissionCalculateJob] 租户 {} 没有设置分成比例,跳过", inviterTenantId);
|
||||
continue;
|
||||
}
|
||||
|
||||
BigDecimal commissionAmount = purchaseAmount.multiply(commissionRate)
|
||||
.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
int count = createCommissionRecord(record, invite, inviterTenantId, purchaseAmount,
|
||||
commissionRate, commissionAmount, now, withdrawableAt,
|
||||
"一级代理分成");
|
||||
commissionCount += count;
|
||||
totalCommission = totalCommission.add(commissionAmount);
|
||||
|
||||
log.info("[TenantCommissionCalculateJob] 内购记录 {}, 一级代理 {}, 分成金额 {}",
|
||||
record.getId(), inviterTenantId, commissionAmount);
|
||||
}
|
||||
}
|
||||
|
||||
String result = String.format("处理内购记录 %d 条,生成分成 %d 条,总分成金额 %s",
|
||||
processedCount, commissionCount, totalCommission.toPlainString());
|
||||
log.info("[TenantCommissionCalculateJob] 任务执行完成: {}", result);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分成记录并更新租户余额
|
||||
*
|
||||
* @return 创建的分成记录数量
|
||||
*/
|
||||
private int createCommissionRecord(KeyboardUserPurchaseRecordsDO record,
|
||||
KeyboardUserInvitesDO invite,
|
||||
Long tenantId,
|
||||
BigDecimal purchaseAmount,
|
||||
BigDecimal commissionRate,
|
||||
BigDecimal commissionAmount,
|
||||
LocalDateTime now,
|
||||
LocalDateTime withdrawableAt,
|
||||
String remark) {
|
||||
// 0. 检查该租户是否已对该内购记录计算过分成(防止重复计算)
|
||||
KeyboardTenantCommissionDO existingCommission = commissionMapper.selectByPurchaseRecordIdAndTenantId(record.getId(), tenantId);
|
||||
if (existingCommission != null) {
|
||||
log.debug("[TenantCommissionCalculateJob] 租户 {} 已对内购记录 {} 计算过分成,跳过", tenantId, record.getId());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 1. 创建分成记录
|
||||
KeyboardTenantCommissionDO commission = KeyboardTenantCommissionDO.builder()
|
||||
.purchaseRecordId(record.getId())
|
||||
.transactionId(record.getTransactionId())
|
||||
.inviteeUserId(record.getUserId())
|
||||
.inviterUserId(invite.getProfitEmployeeId())
|
||||
.tenantId(tenantId)
|
||||
.purchaseAmount(purchaseAmount)
|
||||
.commissionRate(commissionRate)
|
||||
.commissionAmount(commissionAmount)
|
||||
.status("SETTLED")
|
||||
.purchaseTime(record.getPurchaseTime())
|
||||
.settledAt(now)
|
||||
.withdrawableAt(withdrawableAt)
|
||||
.withdrawableProcessed(false)
|
||||
.createdAt(now)
|
||||
.updatedAt(now)
|
||||
.remark(remark)
|
||||
.build();
|
||||
|
||||
// 2. 更新租户余额(分成金额先计入总余额,30天后才可提现)
|
||||
TenantBalanceDO balance = tenantBalanceMapper.selectById(tenantId);
|
||||
if (balance == null) {
|
||||
balance = new TenantBalanceDO();
|
||||
balance.setId(tenantId);
|
||||
balance.setBalance(commissionAmount);
|
||||
balance.setWithdrawableBalance(BigDecimal.ZERO);
|
||||
balance.setFrozenAmt(BigDecimal.ZERO);
|
||||
balance.setVersion(0);
|
||||
tenantBalanceMapper.insert(balance);
|
||||
} else {
|
||||
BigDecimal newBalance = balance.getBalance().add(commissionAmount);
|
||||
balance.setBalance(newBalance);
|
||||
tenantBalanceMapper.updateById(balance);
|
||||
}
|
||||
|
||||
// 3. 创建余额交易记录
|
||||
String bizNo = BizNoGenerator.generate("COMM");
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(bizNo)
|
||||
.points(commissionAmount)
|
||||
.balance(balance.getBalance())
|
||||
.frozenAmt(balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO)
|
||||
.withdrawableBalance(balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO)
|
||||
.tenantId(tenantId)
|
||||
.type(COMMISSION_TYPE)
|
||||
.description("邀请用户内购分成")
|
||||
.orderId(record.getTransactionId())
|
||||
.createdAt(now)
|
||||
.remark("内购记录ID: " + record.getId() + ", 被邀请用户: " + record.getUserId() + ", " + remark)
|
||||
.build();
|
||||
balanceTransactionMapper.insert(transaction);
|
||||
|
||||
// 4. 更新分成记录的关联交易ID并保存
|
||||
commission.setBalanceTransactionId(transaction.getId());
|
||||
commissionMapper.insert(commission);
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
@@ -140,6 +140,8 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
.bizNo(BizNoGenerator.generate("RECHARGE")) // 生成充值业务编号
|
||||
.points(new BigDecimal(String.valueOf(addReqVO.getAmount()))) // 充值金额
|
||||
.balance(newBalance) // 充值后余额
|
||||
.frozenAmt(balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO) // 当前冻结金额
|
||||
.withdrawableBalance(balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO) // 当前可提现金额
|
||||
.tenantId(addReqVO.getId())
|
||||
.type("RECHARGE") // 交易类型:充值
|
||||
.description("余额充值") // 交易描述
|
||||
@@ -243,18 +245,18 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
throw exception(TENANT_BALANCE_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 3. 校验可用余额是否充足(可用余额 = 余额 - 冻结金额)
|
||||
// 3. 校验可提现金额是否充足
|
||||
BigDecimal withdrawAmount = withdrawReqVO.getAmount();
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal availableBalance = balance.getBalance().subtract(frozenAmt);
|
||||
if (availableBalance.compareTo(withdrawAmount) < 0) {
|
||||
BigDecimal withdrawableBalance = balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO;
|
||||
if (withdrawableBalance.compareTo(withdrawAmount) < 0) {
|
||||
throw exception(TENANT_BALANCE_WITHDRAW_INSUFFICIENT);
|
||||
}
|
||||
|
||||
// 4. 扣减余额并增加冻结金额
|
||||
BigDecimal newBalance = balance.getBalance().subtract(withdrawAmount);
|
||||
// 4. 从可提现金额中扣减并增加冻结金额
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal newWithdrawableBalance = withdrawableBalance.subtract(withdrawAmount);
|
||||
BigDecimal newFrozenAmt = frozenAmt.add(withdrawAmount);
|
||||
balance.setBalance(newBalance);
|
||||
balance.setWithdrawableBalance(newWithdrawableBalance);
|
||||
balance.setFrozenAmt(newFrozenAmt);
|
||||
int updateCount = tenantBalanceMapper.updateById(balance);
|
||||
if (updateCount == 0) {
|
||||
@@ -269,7 +271,9 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(bizNo)
|
||||
.points(withdrawAmount.negate()) // 冻结金额(负数表示冻结扣减)
|
||||
.balance(newBalance) // 扣减后的余额
|
||||
.balance(balance.getBalance()) // 当前总余额
|
||||
.frozenAmt(newFrozenAmt) // 冻结后的冻结金额
|
||||
.withdrawableBalance(newWithdrawableBalance) // 扣减后的可提现余额
|
||||
.tenantId(tenantId)
|
||||
.type("FREEZE")
|
||||
.description("提现冻结")
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.yolo.keyboard.service.tenantcommission;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.tenantcommission.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 租户内购分成记录 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardTenantCommissionService {
|
||||
|
||||
/**
|
||||
* 创建租户内购分成记录
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createTenantCommission(@Valid KeyboardTenantCommissionSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新租户内购分成记录
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTenantCommission(@Valid KeyboardTenantCommissionSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除租户内购分成记录
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTenantCommission(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除租户内购分成记录
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteTenantCommissionListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得租户内购分成记录
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 租户内购分成记录
|
||||
*/
|
||||
KeyboardTenantCommissionDO getTenantCommission(Long id);
|
||||
|
||||
/**
|
||||
* 获得租户内购分成记录分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 租户内购分成记录分页
|
||||
*/
|
||||
PageResult<KeyboardTenantCommissionDO> getTenantCommissionPage(KeyboardTenantCommissionPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得当前登录租户的分成记录分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 租户内购分成记录分页
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.yolo.keyboard.service.tenantcommission;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.yolo.keyboard.controller.admin.tenantcommission.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantcommission.KeyboardTenantCommissionDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.yolo.keyboard.dal.mysql.tenantcommission.KeyboardTenantCommissionMapper;
|
||||
import com.yolo.keyboard.framework.tenant.core.context.TenantContextHolder;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.dal.mysql.tenant.TenantMapper;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.TENANT_COMMISSION_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 租户内购分成记录 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardTenantCommissionServiceImpl implements KeyboardTenantCommissionService {
|
||||
|
||||
@Resource
|
||||
private KeyboardTenantCommissionMapper tenantCommissionMapper;
|
||||
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
|
||||
@Override
|
||||
public Long createTenantCommission(KeyboardTenantCommissionSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardTenantCommissionDO tenantCommission = BeanUtils.toBean(createReqVO, KeyboardTenantCommissionDO.class);
|
||||
tenantCommissionMapper.insert(tenantCommission);
|
||||
|
||||
// 返回
|
||||
return tenantCommission.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTenantCommission(KeyboardTenantCommissionSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTenantCommissionExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardTenantCommissionDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantCommissionDO.class);
|
||||
tenantCommissionMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantCommission(Long id) {
|
||||
// 校验存在
|
||||
validateTenantCommissionExists(id);
|
||||
// 删除
|
||||
tenantCommissionMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantCommissionListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
tenantCommissionMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateTenantCommissionExists(Long id) {
|
||||
if (tenantCommissionMapper.selectById(id) == null) {
|
||||
throw exception(TENANT_COMMISSION_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardTenantCommissionDO getTenantCommission(Long id) {
|
||||
return tenantCommissionMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardTenantCommissionDO> getTenantCommissionPage(KeyboardTenantCommissionPageReqVO pageReqVO) {
|
||||
// 如果当前租户的 tenantLevel 不等于 0,只能查询属于自己的数据
|
||||
Long currentTenantId = TenantContextHolder.getTenantId();
|
||||
if (currentTenantId != null) {
|
||||
TenantDO currentTenant = tenantMapper.selectById(currentTenantId);
|
||||
if (currentTenant != null && currentTenant.getTenantLevel() != null
|
||||
&& currentTenant.getTenantLevel() != 0) {
|
||||
pageReqVO.setTenantId(currentTenantId);
|
||||
}
|
||||
}
|
||||
return tenantCommissionMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,6 +57,6 @@ public interface KeyboardTenantWithdrawOrderService {
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 租户提现订单表(申请-审核-打款-完成/失败)分页
|
||||
*/
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO);
|
||||
PageResult<KeyboardTenantWithdrawOrderRespVO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -1,23 +1,34 @@
|
||||
package com.yolo.keyboard.service.tenantwithdraworder;
|
||||
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderPageReqVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderRespVO;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.KeyboardTenantWithdrawOrderSaveReqVO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantbalancetransaction.TenantBalanceTransactionDO;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantbalancetransaction.TenantBalanceTransactionMapper;
|
||||
import com.yolo.keyboard.dal.mysql.tenantwithdraworder.KeyboardTenantWithdrawOrderMapper;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
import com.yolo.keyboard.framework.tenant.core.context.TenantContextHolder;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.dal.mysql.tenant.TenantMapper;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.yolo.keyboard.controller.admin.tenantwithdraworder.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tenantwithdraworder.KeyboardTenantWithdrawOrderDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.yolo.keyboard.dal.mysql.tenantwithdraworder.KeyboardTenantWithdrawOrderMapper;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.TENANT_WITHDRAW_ORDER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -32,6 +43,15 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
@Resource
|
||||
private KeyboardTenantWithdrawOrderMapper tenantWithdrawOrderMapper;
|
||||
|
||||
@Resource
|
||||
private TenantMapper tenantMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Resource
|
||||
private TenantBalanceTransactionMapper tenantBalanceTransactionMapper;
|
||||
|
||||
@Override
|
||||
public Long createTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
@@ -43,12 +63,145 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateTenantWithdrawOrder(KeyboardTenantWithdrawOrderSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTenantWithdrawOrderExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardTenantWithdrawOrderDO existingOrder = tenantWithdrawOrderMapper.selectById(updateReqVO.getId());
|
||||
if (existingOrder == null) {
|
||||
throw exception(TENANT_WITHDRAW_ORDER_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 更新订单
|
||||
KeyboardTenantWithdrawOrderDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTenantWithdrawOrderDO.class);
|
||||
tenantWithdrawOrderMapper.updateById(updateObj);
|
||||
|
||||
String newStatus = updateReqVO.getStatus();
|
||||
String oldStatus = existingOrder.getStatus();
|
||||
|
||||
// 如果提现状态更新为成功(PAID),则扣除提现用户的冻结金额并创建流水记录
|
||||
if ("PAID".equals(newStatus) && !"PAID".equals(oldStatus)) {
|
||||
handleWithdrawSuccess(existingOrder);
|
||||
}
|
||||
// 如果提现状态更新为已拒绝、已取消、打款失败,则返还冻结金额到可提现余额并创建流水记录
|
||||
else if (isRefundStatus(newStatus) && !isRefundStatus(oldStatus)) {
|
||||
handleWithdrawRefund(existingOrder, newStatus, updateReqVO.getReason());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为需要退还冻结金额的状态
|
||||
*/
|
||||
private boolean isRefundStatus(String status) {
|
||||
return "REJECTED".equals(status) || "CANCELED".equals(status) || "FAILED".equals(status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理提现成功:扣除冻结金额并记录流水
|
||||
*/
|
||||
private void handleWithdrawSuccess(KeyboardTenantWithdrawOrderDO order) {
|
||||
TenantBalanceDO balance = tenantBalanceMapper.selectById(order.getTenantId());
|
||||
if (balance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 扣除冻结金额
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal withdrawAmount = order.getAmount();
|
||||
BigDecimal newFrozenAmt = frozenAmt.subtract(withdrawAmount);
|
||||
if (newFrozenAmt.compareTo(BigDecimal.ZERO) < 0) {
|
||||
newFrozenAmt = BigDecimal.ZERO;
|
||||
}
|
||||
balance.setFrozenAmt(newFrozenAmt);
|
||||
tenantBalanceMapper.updateById(balance);
|
||||
|
||||
// 创建提现成功的流水记录
|
||||
BigDecimal currentWithdrawableBalance = balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO;
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(order.getBizNo())
|
||||
.points(withdrawAmount.negate()) // 提现金额(负数表示支出)
|
||||
.balance(balance.getBalance()) // 当前总余额
|
||||
.frozenAmt(newFrozenAmt) // 扣除后的冻结金额
|
||||
.withdrawableBalance(currentWithdrawableBalance) // 当前可提现余额
|
||||
.tenantId(order.getTenantId())
|
||||
.type("WITHDRAW_SUCCESS")
|
||||
.description("提现成功")
|
||||
.orderId(order.getWithdrawNo())
|
||||
.operatorId(TenantContextHolder.getTenantId())
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build();
|
||||
tenantBalanceTransactionMapper.insert(transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理提现退还:返还冻结金额到可提现余额并记录流水
|
||||
*
|
||||
* @param order 提现订单
|
||||
* @param newStatus 新状态
|
||||
* @param reason 拒绝/失败/取消原因
|
||||
*/
|
||||
private void handleWithdrawRefund(KeyboardTenantWithdrawOrderDO order, String newStatus, String reason) {
|
||||
TenantBalanceDO balance = tenantBalanceMapper.selectById(order.getTenantId());
|
||||
if (balance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BigDecimal withdrawAmount = order.getAmount();
|
||||
|
||||
// 扣除冻结金额
|
||||
BigDecimal frozenAmt = balance.getFrozenAmt() != null ? balance.getFrozenAmt() : BigDecimal.ZERO;
|
||||
BigDecimal newFrozenAmt = frozenAmt.subtract(withdrawAmount);
|
||||
if (newFrozenAmt.compareTo(BigDecimal.ZERO) < 0) {
|
||||
newFrozenAmt = BigDecimal.ZERO;
|
||||
}
|
||||
balance.setFrozenAmt(newFrozenAmt);
|
||||
|
||||
// 返还到可提现余额
|
||||
BigDecimal withdrawableBalance = balance.getWithdrawableBalance() != null ? balance.getWithdrawableBalance() : BigDecimal.ZERO;
|
||||
BigDecimal newWithdrawableBalance = withdrawableBalance.add(withdrawAmount);
|
||||
balance.setWithdrawableBalance(newWithdrawableBalance);
|
||||
|
||||
tenantBalanceMapper.updateById(balance);
|
||||
|
||||
// 根据状态确定流水类型和描述
|
||||
String type;
|
||||
String description;
|
||||
switch (newStatus) {
|
||||
case "REJECTED":
|
||||
type = "WITHDRAW_REJECTED";
|
||||
description = "提现被拒绝,金额已退还";
|
||||
break;
|
||||
case "CANCELED":
|
||||
type = "WITHDRAW_CANCELED";
|
||||
description = "提现已取消,金额已退还";
|
||||
break;
|
||||
case "FAILED":
|
||||
type = "WITHDRAW_FAILED";
|
||||
description = "提现打款失败,金额已退还";
|
||||
break;
|
||||
default:
|
||||
type = "WITHDRAW_REFUND";
|
||||
description = "提现退还";
|
||||
}
|
||||
|
||||
// 备注:优先使用传入的原因,如果没有则使用默认描述
|
||||
String remark = (reason != null && !reason.trim().isEmpty()) ? reason : description;
|
||||
|
||||
// 创建退还流水记录
|
||||
TenantBalanceTransactionDO transaction = TenantBalanceTransactionDO.builder()
|
||||
.bizNo(order.getBizNo())
|
||||
.points(withdrawAmount) // 退还金额(正数表示收入)
|
||||
.balance(balance.getBalance()) // 当前总余额
|
||||
.frozenAmt(newFrozenAmt) // 扣除后的冻结金额
|
||||
.withdrawableBalance(newWithdrawableBalance) // 退还后的可提现余额
|
||||
.tenantId(order.getTenantId())
|
||||
.type(type)
|
||||
.description(description)
|
||||
.remark(remark)
|
||||
.orderId(order.getWithdrawNo())
|
||||
.operatorId(TenantContextHolder.getTenantId())
|
||||
.createdAt(LocalDateTime.now())
|
||||
.build();
|
||||
tenantBalanceTransactionMapper.insert(transaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,8 +231,67 @@ public class KeyboardTenantWithdrawOrderServiceImpl implements KeyboardTenantWit
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardTenantWithdrawOrderDO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
return tenantWithdrawOrderMapper.selectPage(pageReqVO);
|
||||
public PageResult<KeyboardTenantWithdrawOrderRespVO> getTenantWithdrawOrderPage(KeyboardTenantWithdrawOrderPageReqVO pageReqVO) {
|
||||
// 根据当前租户级别过滤下级租户的提现申请
|
||||
Long currentTenantId = TenantContextHolder.getTenantId();
|
||||
if (currentTenantId != null) {
|
||||
TenantDO currentTenant = tenantMapper.selectById(currentTenantId);
|
||||
if (currentTenant != null && currentTenant.getTenantLevel() != null) {
|
||||
if (currentTenant.getTenantLevel() == 0) {
|
||||
// 系统管理员:只能查看1级代理的提现申请
|
||||
List<TenantDO> firstLevelAgents = tenantMapper.selectList(
|
||||
new LambdaQueryWrapper<TenantDO>().eq(TenantDO::getTenantLevel, 1));
|
||||
List<Long> firstLevelAgentIds = firstLevelAgents.stream()
|
||||
.map(TenantDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(firstLevelAgentIds)) {
|
||||
// 没有1级代理,返回空结果
|
||||
return PageResult.empty(0L);
|
||||
}
|
||||
pageReqVO.setTenantIds(firstLevelAgentIds);
|
||||
} else {
|
||||
// 非系统管理员:只能查看直属下级租户的提现申请
|
||||
List<TenantDO> subordinateTenants = tenantMapper.selectList(
|
||||
new LambdaQueryWrapper<TenantDO>().eq(TenantDO::getParentId, currentTenantId));
|
||||
List<Long> subordinateTenantIds = subordinateTenants.stream()
|
||||
.map(TenantDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(subordinateTenantIds)) {
|
||||
// 没有下级租户,返回空结果
|
||||
return PageResult.empty(0L);
|
||||
}
|
||||
pageReqVO.setTenantIds(subordinateTenantIds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 分页查询租户提现订单数据
|
||||
PageResult<KeyboardTenantWithdrawOrderDO> pageResult = tenantWithdrawOrderMapper.selectPage(pageReqVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return PageResult.empty(pageResult.getTotal());
|
||||
}
|
||||
|
||||
// 批量获取租户名称 - 提升性能,避免N+1查询
|
||||
List<Long> tenantIds = pageResult.getList().stream()
|
||||
.map(KeyboardTenantWithdrawOrderDO::getTenantId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
List<TenantDO> tenants = tenantMapper.selectBatchIds(tenantIds);
|
||||
Map<Long, String> tenantNameMap = CollUtil.isEmpty(tenants)
|
||||
? new HashMap<>() // 如果没有查询到租户数据,返回空map
|
||||
: tenants.stream().collect(Collectors.toMap(TenantDO::getId, TenantDO::getName, (a, b) -> a)); // 构建租户ID到名称的映射
|
||||
|
||||
// 转换为 VO 并填充租户名称
|
||||
List<KeyboardTenantWithdrawOrderRespVO> voList = pageResult.getList().stream().map(order -> {
|
||||
// 将DO转换为VO
|
||||
KeyboardTenantWithdrawOrderRespVO vo = BeanUtils.toBean(order, KeyboardTenantWithdrawOrderRespVO.class);
|
||||
// 根据租户ID获取并设置租户名称
|
||||
vo.setTenantName(tenantNameMap.get(order.getTenantId()));
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 返回包含VO列表和总数的分页结果
|
||||
return new PageResult<>(voList, pageResult.getTotal());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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.yolo.keyboard.module.keyboard.dal.mysql.tenantcommission.KeyboardTenantCommissionMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
2
pom.xml
2
pom.xml
@@ -46,6 +46,8 @@
|
||||
<spring.boot.version>3.5.5</spring.boot.version>
|
||||
<mapstruct.version>1.6.3</mapstruct.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<!-- 覆盖 Spring Boot 默认的 Quartz 版本 -->
|
||||
<quartz.version>2.5.2</quartz.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"local": {
|
||||
"baseUrl": "http://127.0.0.1:48080/admin-api",
|
||||
"baseUrl": "http://127.0.0.1:48081/admin-api",
|
||||
"token": "test1",
|
||||
"adminTenantId": "1",
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
<flatten-maven-plugin.version>1.7.2</flatten-maven-plugin.version>
|
||||
<!-- 统一依赖管理 -->
|
||||
<spring.boot.version>3.5.8</spring.boot.version>
|
||||
<!-- 覆盖 Spring Boot 默认的 Quartz 版本 -->
|
||||
<quartz.version>2.5.2</quartz.version>
|
||||
<!-- Web 相关 -->
|
||||
<springdoc.version>2.8.14</springdoc.version>
|
||||
<knife4j.version>4.5.0</knife4j.version>
|
||||
@@ -95,6 +97,13 @@
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 覆盖 Spring Boot 默认的 Quartz 版本 -->
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>${quartz.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<dependency>
|
||||
<groupId>io.github.mouzt</groupId>
|
||||
|
||||
@@ -28,8 +28,19 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>quartz</artifactId>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.quartz-scheduler</groupId>
|
||||
<artifactId>quartz</artifactId>
|
||||
<version>2.5.2</version>
|
||||
</dependency>
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
|
||||
@@ -22,55 +22,8 @@ public class BannerApplicationRunner implements ApplicationRunner {
|
||||
ThreadUtil.sleep(1, TimeUnit.SECONDS); // 延迟 1 秒,保证输出到结尾
|
||||
log.info("\n----------------------------------------------------------\n\t" +
|
||||
"项目启动成功!\n\t" +
|
||||
"接口文档: \t{} \n\t" +
|
||||
"开发文档: \t{} \n\t" +
|
||||
"视频教程: \t{} \n" +
|
||||
"----------------------------------------------------------",
|
||||
"https://doc.iocoder.cn/api-doc/",
|
||||
"https://doc.iocoder.cn",
|
||||
"https://t.zsxq.com/02Yf6M7Qn");
|
||||
|
||||
// 数据报表
|
||||
if (isNotPresent("com.yolo.keyboard.module.report.framework.security.config.SecurityConfiguration")) {
|
||||
System.out.println("[报表模块 yolo-module-report - 已禁用][参考 https://doc.iocoder.cn/report/ 开启]");
|
||||
}
|
||||
// 工作流
|
||||
if (isNotPresent("com.yolo.keyboard.module.bpm.framework.flowable.config.BpmFlowableConfiguration")) {
|
||||
System.out.println("[工作流模块 yolo-module-bpm - 已禁用][参考 https://doc.iocoder.cn/bpm/ 开启]");
|
||||
}
|
||||
// 商城系统
|
||||
if (isNotPresent("com.yolo.keyboard.module.trade.framework.web.config.TradeWebConfiguration")) {
|
||||
System.out.println("[商城系统 yolo-module-mall - 已禁用][参考 https://doc.iocoder.cn/mall/build/ 开启]");
|
||||
}
|
||||
// ERP 系统
|
||||
if (isNotPresent("com.yolo.keyboard.module.erp.framework.web.config.ErpWebConfiguration")) {
|
||||
System.out.println("[ERP 系统 yolo-module-erp - 已禁用][参考 https://doc.iocoder.cn/erp/build/ 开启]");
|
||||
}
|
||||
// CRM 系统
|
||||
if (isNotPresent("com.yolo.keyboard.module.crm.framework.web.config.CrmWebConfiguration")) {
|
||||
System.out.println("[CRM 系统 yolo-module-crm - 已禁用][参考 https://doc.iocoder.cn/crm/build/ 开启]");
|
||||
}
|
||||
// 微信公众号
|
||||
if (isNotPresent("com.yolo.keyboard.module.mp.framework.mp.config.MpConfiguration")) {
|
||||
System.out.println("[微信公众号 yolo-module-mp - 已禁用][参考 https://doc.iocoder.cn/mp/build/ 开启]");
|
||||
}
|
||||
// 支付平台
|
||||
if (isNotPresent("com.yolo.keyboard.module.pay.framework.pay.config.PayConfiguration")) {
|
||||
System.out.println("[支付系统 yolo-module-pay - 已禁用][参考 https://doc.iocoder.cn/pay/build/ 开启]");
|
||||
}
|
||||
// AI 大模型
|
||||
if (isNotPresent("com.yolo.keyboard.module.ai.framework.web.config.AiWebConfiguration")) {
|
||||
System.out.println("[AI 大模型 yolo-module-ai - 已禁用][参考 https://doc.iocoder.cn/ai/build/ 开启]");
|
||||
}
|
||||
// IoT 物联网
|
||||
if (isNotPresent("com.yolo.keyboard.module.iot.framework.web.config.IotWebConfiguration")) {
|
||||
System.out.println("[IoT 物联网 yolo-module-iot - 已禁用][参考 https://doc.iocoder.cn/iot/build/ 开启]");
|
||||
}
|
||||
"----------------------------------------------------------");
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isNotPresent(String className) {
|
||||
return !ClassUtils.isPresent(className, ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -93,5 +93,7 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode TENANT_WITHDRAW_ORDER_NOT_EXISTS = new ErrorCode(1_001_202_019, "租户提现订单表(申请-审核-打款-完成/失败)不存在");
|
||||
ErrorCode USER_INVITE_CODES_NOT_EXISTS = new ErrorCode(1_001_202_020, "用户生成的邀请码表,用于邀请新用户注册/安装并建立邀请关系不存在");
|
||||
ErrorCode USER_INVITES_NOT_EXISTS = new ErrorCode(1_001_202_021, "用户邀请关系绑定台账表,记录新用户最终归属的邀请人不存在");
|
||||
ErrorCode TENANT_COMMISSION_NOT_EXISTS = new ErrorCode(1_001_202_022, "租户内购分成记录不存在");
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yolo.keyboard.module.system.api.invitecode;
|
||||
|
||||
/**
|
||||
* 用户邀请码 API 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface UserInviteCodeApi {
|
||||
|
||||
/**
|
||||
* 为代理租户创建邀请码
|
||||
*
|
||||
* @param userId 系统用户ID
|
||||
* @param tenantId 租户ID
|
||||
* @return 生成的邀请码
|
||||
*/
|
||||
String createInviteCodeForAgent(Long userId, Long tenantId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yolo.keyboard.module.system.api.tenantbalance;
|
||||
|
||||
/**
|
||||
* 租户余额 API 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface TenantBalanceApi {
|
||||
|
||||
/**
|
||||
* 初始化租户钱包
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
void initTenantBalance(Long tenantId);
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.yolo.keyboard.module.system.controller.admin.tenant.vo.tenant.TenantPageReqVO;
|
||||
import com.yolo.keyboard.module.system.controller.admin.tenant.vo.tenant.TenantRespVO;
|
||||
import com.yolo.keyboard.module.system.controller.admin.tenant.vo.tenant.TenantSaveReqVO;
|
||||
import com.yolo.keyboard.module.system.controller.admin.tenant.vo.tenant.TenantInfoRespVO;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.service.tenant.TenantService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -113,6 +114,13 @@ public class TenantController {
|
||||
return success(BeanUtils.toBean(tenant, TenantRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/current")
|
||||
@Operation(summary = "获得当前登录租户信息")
|
||||
public CommonResult<TenantInfoRespVO> getCurrentTenant() {
|
||||
TenantDO tenant = tenantService.getCurrentTenant();
|
||||
return success(BeanUtils.toBean(tenant, TenantInfoRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得租户分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant:query')")
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.yolo.keyboard.module.system.controller.admin.tenant.vo.tenant;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - 当前租户信息 Response VO")
|
||||
@Data
|
||||
public class TenantInfoRespVO {
|
||||
|
||||
@Schema(description = "租户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "上级租户编号", example = "1")
|
||||
private Long parentId;
|
||||
|
||||
@Schema(description = "代理级别", example = "1")
|
||||
private Integer tenantLevel;
|
||||
|
||||
@Schema(description = "分润比例", example = "0.3")
|
||||
private BigDecimal profitShareRatio;
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ public interface TenantMapper extends BaseMapperX<TenantDO> {
|
||||
.likeIfPresent(TenantDO::getContactName, reqVO.getContactName())
|
||||
.likeIfPresent(TenantDO::getContactMobile, reqVO.getContactMobile())
|
||||
.eqIfPresent(TenantDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(TenantDO::getParentId, reqVO.getParentId())
|
||||
.betweenIfPresent(TenantDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(TenantDO::getId));
|
||||
}
|
||||
|
||||
@@ -142,4 +142,11 @@ public interface TenantService {
|
||||
*/
|
||||
void validTenant(Long id);
|
||||
|
||||
/**
|
||||
* 获取当前登录租户信息
|
||||
*
|
||||
* @return 当前租户
|
||||
*/
|
||||
TenantDO getCurrentTenant();
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.yolo.keyboard.module.system.dal.dataobject.permission.RoleDO;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantDO;
|
||||
import com.yolo.keyboard.module.system.dal.dataobject.tenant.TenantPackageDO;
|
||||
import com.yolo.keyboard.module.system.dal.mysql.tenant.TenantMapper;
|
||||
import com.yolo.keyboard.module.system.api.invitecode.UserInviteCodeApi;
|
||||
import com.yolo.keyboard.module.system.api.tenantbalance.TenantBalanceApi;
|
||||
import com.yolo.keyboard.module.system.enums.permission.RoleCodeEnum;
|
||||
import com.yolo.keyboard.module.system.enums.permission.RoleTypeEnum;
|
||||
import com.yolo.keyboard.module.system.service.permission.MenuService;
|
||||
@@ -75,6 +77,12 @@ public class TenantServiceImpl implements TenantService {
|
||||
@Resource
|
||||
private PermissionService permissionService;
|
||||
|
||||
@Autowired(required = false)
|
||||
private UserInviteCodeApi userInviteCodeApi;
|
||||
|
||||
@Autowired(required = false)
|
||||
private TenantBalanceApi tenantBalanceApi;
|
||||
|
||||
@Override
|
||||
public List<Long> getTenantIdList() {
|
||||
List<TenantDO> tenants = tenantMapper.selectList();
|
||||
@@ -124,6 +132,11 @@ public class TenantServiceImpl implements TenantService {
|
||||
}
|
||||
tenant.setParentId(currentTenantId);
|
||||
tenant.setTenantLevel(parentTenant != null && parentTenant.getTenantLevel() != null ? parentTenant.getTenantLevel() + 1 : 1);
|
||||
|
||||
// 如果当前用户是1级代理,下级分成比例沿用自己的分成比例,不允许单独设置
|
||||
if (parentTenant != null && parentTenant.getTenantLevel() != null && parentTenant.getTenantLevel() == 1) {
|
||||
tenant.setProfitShareRatio(parentTenant.getProfitShareRatio());
|
||||
}
|
||||
}
|
||||
}
|
||||
tenantMapper.insert(tenant);
|
||||
@@ -135,6 +148,14 @@ public class TenantServiceImpl implements TenantService {
|
||||
Long userId = createUser(roleId, createReqVO);
|
||||
// 修改租户的管理员
|
||||
tenantMapper.updateById(new TenantDO().setId(tenant.getId()).setContactUserId(userId));
|
||||
// 为代理租户创建邀请码
|
||||
if ("代理".equals(createReqVO.getTenantType()) && userInviteCodeApi != null) {
|
||||
userInviteCodeApi.createInviteCodeForAgent(userId, tenant.getId());
|
||||
}
|
||||
// 为代理租户初始化钱包
|
||||
if ("代理".equals(createReqVO.getTenantType()) && tenantBalanceApi != null) {
|
||||
tenantBalanceApi.initTenantBalance(tenant.getId());
|
||||
}
|
||||
});
|
||||
return tenant.getId();
|
||||
}
|
||||
@@ -269,6 +290,15 @@ public class TenantServiceImpl implements TenantService {
|
||||
|
||||
@Override
|
||||
public PageResult<TenantDO> getTenantPage(TenantPageReqVO pageReqVO) {
|
||||
// 如果当前租户是一级代理(tenantLevel=1),只能查询自己的下级租户
|
||||
Long currentTenantId = TenantContextHolder.getTenantId();
|
||||
if (currentTenantId != null) {
|
||||
TenantDO currentTenant = tenantMapper.selectById(currentTenantId);
|
||||
if (currentTenant != null && currentTenant.getTenantLevel() != null
|
||||
&& currentTenant.getTenantLevel() == 1) {
|
||||
pageReqVO.setParentId(currentTenantId);
|
||||
}
|
||||
}
|
||||
return tenantMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@@ -336,4 +366,10 @@ public class TenantServiceImpl implements TenantService {
|
||||
return tenantProperties == null || Boolean.FALSE.equals(tenantProperties.getEnable());
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantDO getCurrentTenant() {
|
||||
Long tenantId = TenantContextHolder.getRequiredTenantId();
|
||||
return getTenant(tenantId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ spring:
|
||||
isClustered: true # 是集群模式
|
||||
clusterCheckinInterval: 15000 # 集群检查频率,单位:毫秒。默认为 15000,即 15 秒
|
||||
misfireThreshold: 60000 # misfire 阀值,单位:毫秒。
|
||||
acquireTriggersWithinLock: true # 获取触发器时加锁,防止并发问题
|
||||
# 线程池相关配置
|
||||
threadPool:
|
||||
threadCount: 25 # 线程池大小。默认为 10 。
|
||||
|
||||
@@ -6,7 +6,7 @@ spring:
|
||||
autoconfigure:
|
||||
# noinspection SpringBootApplicationYaml
|
||||
exclude:
|
||||
- org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
|
||||
# - org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration # 默认 local 环境,不开启 Quartz 的自动配置
|
||||
- org.springframework.ai.vectorstore.qdrant.autoconfigure.QdrantVectorStoreAutoConfiguration # 禁用 AI 模块的 Qdrant,手动创建
|
||||
- org.springframework.ai.vectorstore.milvus.autoconfigure.MilvusVectorStoreAutoConfiguration # 禁用 AI 模块的 Milvus,手动创建
|
||||
# 数据源配置项
|
||||
@@ -97,9 +97,11 @@ spring:
|
||||
jobStore:
|
||||
# JobStore 实现类。可见博客:https://blog.csdn.net/weixin_42458219/article/details/122247162
|
||||
class: org.springframework.scheduling.quartz.LocalDataSourceJobStore
|
||||
driverDelegateClass: org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
|
||||
isClustered: true # 是集群模式
|
||||
clusterCheckinInterval: 15000 # 集群检查频率,单位:毫秒。默认为 15000,即 15 秒
|
||||
misfireThreshold: 60000 # misfire 阀值,单位:毫秒。
|
||||
acquireTriggersWithinLock: true # 获取触发器时加锁,防止并发问题
|
||||
# 线程池相关配置
|
||||
threadPool:
|
||||
threadCount: 25 # 线程池大小。默认为 10 。
|
||||
|
||||
Reference in New Issue
Block a user