feat(userwallet): 新增用户钱包管理功能
新增用户钱包DO、Mapper、Service、Controller及交易流水DO,补充错误码USER_WALLET_NOT_EXISTS,并添加对应MyBatis XML与本地日志配置
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
package com.yolo.keyboard.controller.admin.userwallet;
|
||||
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardWalletTransactionDO;
|
||||
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.userwallet.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardUserWalletDO;
|
||||
import com.yolo.keyboard.service.userwallet.KeyboardUserWalletService;
|
||||
|
||||
@Tag(name = "管理后台 - 用户钱包")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/user-wallet")
|
||||
@Validated
|
||||
public class KeyboardUserWalletController {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserWalletService userWalletService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建用户钱包")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:create')")
|
||||
public CommonResult<Long> createUserWallet(@Valid @RequestBody KeyboardUserWalletSaveReqVO createReqVO) {
|
||||
return success(userWalletService.createUserWallet(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新用户钱包")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:update')")
|
||||
public CommonResult<Boolean> updateUserWallet(@Valid @RequestBody KeyboardUserWalletSaveReqVO updateReqVO) {
|
||||
userWalletService.updateUserWallet(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除用户钱包")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:delete')")
|
||||
public CommonResult<Boolean> deleteUserWallet(@RequestParam("id") Long id) {
|
||||
userWalletService.deleteUserWallet(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除用户钱包")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:delete')")
|
||||
public CommonResult<Boolean> deleteUserWalletList(@RequestParam("ids") List<Long> ids) {
|
||||
userWalletService.deleteUserWalletListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得用户钱包")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:query')")
|
||||
public CommonResult<KeyboardUserWalletRespVO> getUserWallet(@RequestParam("id") Long id) {
|
||||
KeyboardUserWalletDO userWallet = userWalletService.getUserWallet(id);
|
||||
return success(BeanUtils.toBean(userWallet, KeyboardUserWalletRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得用户钱包分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:query')")
|
||||
public CommonResult<PageResult<KeyboardUserWalletRespVO>> getUserWalletPage(@Valid KeyboardUserWalletPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardUserWalletDO> pageResult = userWalletService.getUserWalletPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardUserWalletRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出用户钱包 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUserWalletExcel(@Valid KeyboardUserWalletPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardUserWalletDO> list = userWalletService.getUserWalletPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "用户钱包.xls", "数据", KeyboardUserWalletRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardUserWalletRespVO.class));
|
||||
}
|
||||
|
||||
// ==================== 子表(钱包交易记录) ====================
|
||||
|
||||
@GetMapping("/wallet-transaction/page")
|
||||
@Operation(summary = "获得钱包交易记录分页")
|
||||
@Parameter(name = "userId", description = "用户 Id")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:query')")
|
||||
public CommonResult<PageResult<KeyboardWalletTransactionDO>> getWalletTransactionPage(PageParam pageReqVO,
|
||||
@RequestParam("userId") Long userId) {
|
||||
return success(userWalletService.getWalletTransactionPage(pageReqVO, userId));
|
||||
}
|
||||
|
||||
@PostMapping("/wallet-transaction/create")
|
||||
@Operation(summary = "创建钱包交易记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:create')")
|
||||
public CommonResult<Long> createWalletTransaction(@Valid @RequestBody KeyboardWalletTransactionDO walletTransaction) {
|
||||
return success(userWalletService.createWalletTransaction(walletTransaction));
|
||||
}
|
||||
|
||||
@PutMapping("/wallet-transaction/update")
|
||||
@Operation(summary = "更新钱包交易记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:update')")
|
||||
public CommonResult<Boolean> updateWalletTransaction(@Valid @RequestBody KeyboardWalletTransactionDO walletTransaction) {
|
||||
userWalletService.updateWalletTransaction(walletTransaction);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/wallet-transaction/delete")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@Operation(summary = "删除钱包交易记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:delete')")
|
||||
public CommonResult<Boolean> deleteWalletTransaction(@RequestParam("id") Long id) {
|
||||
userWalletService.deleteWalletTransaction(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/wallet-transaction/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除钱包交易记录")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:delete')")
|
||||
public CommonResult<Boolean> deleteWalletTransactionList(@RequestParam("ids") List<Long> ids) {
|
||||
userWalletService.deleteWalletTransactionListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/wallet-transaction/get")
|
||||
@Operation(summary = "获得钱包交易记录")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-wallet:query')")
|
||||
public CommonResult<KeyboardWalletTransactionDO> getWalletTransaction(@RequestParam("id") Long id) {
|
||||
return success(userWalletService.getWalletTransaction(id));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.yolo.keyboard.controller.admin.userwallet.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 KeyboardUserWalletPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "用户 id", example = "15535")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "余额")
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "状态", example = "2")
|
||||
private Short status;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yolo.keyboard.controller.admin.userwallet.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 KeyboardUserWalletRespVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6708")
|
||||
@ExcelProperty("主键 Id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15535")
|
||||
@ExcelProperty("用户 id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("余额")
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("乐观锁版本")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@ExcelProperty("状态")
|
||||
private Short status;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.yolo.keyboard.controller.admin.userwallet.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 KeyboardUserWalletSaveReqVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "6708")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "用户 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15535")
|
||||
@NotNull(message = "用户 id不能为空")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "余额不能为空")
|
||||
private BigDecimal balance;
|
||||
|
||||
@Schema(description = "乐观锁版本", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "乐观锁版本不能为空")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Short status;
|
||||
|
||||
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "创建时间不能为空")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "更新时间不能为空")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.yolo.keyboard.dal.dataobject.userwallet;
|
||||
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 用户钱包 DO
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@TableName("keyboard_user_wallet")
|
||||
@KeySequence("keyboard_user_wallet_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardUserWalletDO {
|
||||
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 用户 id
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
private BigDecimal balance;
|
||||
/**
|
||||
* 乐观锁版本
|
||||
*/
|
||||
private Integer version;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Short status;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.yolo.keyboard.dal.dataobject.userwallet;
|
||||
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 钱包交易记录 DO
|
||||
*
|
||||
* @author Ziin
|
||||
*/
|
||||
@TableName("keyboard_wallet_transaction")
|
||||
@KeySequence("keyboard_wallet_transaction_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardWalletTransactionDO {
|
||||
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 用户 Id
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 订单 Id
|
||||
*/
|
||||
private Long orderId;
|
||||
/**
|
||||
* 金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
/**
|
||||
* 变动类型
|
||||
*/
|
||||
private Short type;
|
||||
/**
|
||||
* 变动前余额
|
||||
*/
|
||||
private BigDecimal beforeBalance;
|
||||
/**
|
||||
* 变动后余额
|
||||
*/
|
||||
private BigDecimal afterBalance;
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yolo.keyboard.dal.mysql.userwallet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardUserWalletDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.yolo.keyboard.controller.admin.userwallet.vo.*;
|
||||
|
||||
/**
|
||||
* 用户钱包 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardUserWalletMapper extends BaseMapperX<KeyboardUserWalletDO> {
|
||||
|
||||
default PageResult<KeyboardUserWalletDO> selectPage(KeyboardUserWalletPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardUserWalletDO>()
|
||||
.eqIfPresent(KeyboardUserWalletDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(KeyboardUserWalletDO::getBalance, reqVO.getBalance())
|
||||
.eqIfPresent(KeyboardUserWalletDO::getVersion, reqVO.getVersion())
|
||||
.eqIfPresent(KeyboardUserWalletDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(KeyboardUserWalletDO::getCreatedAt, reqVO.getCreatedAt())
|
||||
.eqIfPresent(KeyboardUserWalletDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.orderByDesc(KeyboardUserWalletDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yolo.keyboard.dal.mysql.userwallet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardWalletTransactionDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 钱包交易记录 Mapper
|
||||
*
|
||||
* @author Ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardWalletTransactionMapper extends BaseMapperX<KeyboardWalletTransactionDO> {
|
||||
|
||||
default PageResult<KeyboardWalletTransactionDO> selectPage(PageParam reqVO, Long userId) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardWalletTransactionDO>()
|
||||
.eq(KeyboardWalletTransactionDO::getUserId, userId)
|
||||
.orderByDesc(KeyboardWalletTransactionDO::getId));
|
||||
}
|
||||
|
||||
default int deleteByUserId(Long userId) {
|
||||
return delete(KeyboardWalletTransactionDO::getUserId, userId);
|
||||
}
|
||||
|
||||
default int deleteByUserIds(List<Long> userIds) {
|
||||
return deleteBatch(KeyboardWalletTransactionDO::getUserId, userIds);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.yolo.keyboard.service.userwallet;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardWalletTransactionDO;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.userwallet.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardUserWalletDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 用户钱包 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardUserWalletService {
|
||||
|
||||
/**
|
||||
* 创建用户钱包
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createUserWallet(@Valid KeyboardUserWalletSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新用户钱包
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUserWallet(@Valid KeyboardUserWalletSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除用户钱包
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUserWallet(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用户钱包
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteUserWalletListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得用户钱包
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 用户钱包
|
||||
*/
|
||||
KeyboardUserWalletDO getUserWallet(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户钱包分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 用户钱包分页
|
||||
*/
|
||||
PageResult<KeyboardUserWalletDO> getUserWalletPage(KeyboardUserWalletPageReqVO pageReqVO);
|
||||
// ==================== 子表(钱包交易记录) ====================
|
||||
|
||||
/**
|
||||
* 获得钱包交易记录分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @param userId 用户 Id
|
||||
* @return 钱包交易记录分页
|
||||
*/
|
||||
PageResult<KeyboardWalletTransactionDO> getWalletTransactionPage(PageParam pageReqVO, Long userId);
|
||||
|
||||
/**
|
||||
* 创建钱包交易记录
|
||||
*
|
||||
* @param walletTransaction 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createWalletTransaction(@Valid KeyboardWalletTransactionDO walletTransaction);
|
||||
|
||||
/**
|
||||
* 更新钱包交易记录
|
||||
*
|
||||
* @param walletTransaction 更新信息
|
||||
*/
|
||||
void updateWalletTransaction(@Valid KeyboardWalletTransactionDO walletTransaction);
|
||||
|
||||
/**
|
||||
* 删除钱包交易记录
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteWalletTransaction(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除钱包交易记录
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteWalletTransactionListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得钱包交易记录
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 钱包交易记录
|
||||
*/
|
||||
KeyboardWalletTransactionDO getWalletTransaction(Long id);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.yolo.keyboard.service.userwallet;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardWalletTransactionDO;
|
||||
import com.yolo.keyboard.dal.mysql.userwallet.KeyboardWalletTransactionMapper;
|
||||
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.userwallet.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.userwallet.KeyboardUserWalletDO;
|
||||
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.userwallet.KeyboardUserWalletMapper;
|
||||
|
||||
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.USER_WALLET_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 用户钱包 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardUserWalletServiceImpl implements KeyboardUserWalletService {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserWalletMapper userWalletMapper;
|
||||
@Resource
|
||||
private KeyboardWalletTransactionMapper walletTransactionMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public Long createUserWallet(KeyboardUserWalletSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardUserWalletDO userWallet = BeanUtils.toBean(createReqVO, KeyboardUserWalletDO.class);
|
||||
userWalletMapper.insert(userWallet);
|
||||
|
||||
// 返回
|
||||
return userWallet.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserWallet(KeyboardUserWalletSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUserWalletExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardUserWalletDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardUserWalletDO.class);
|
||||
userWalletMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserWallet(Long id) {
|
||||
// 校验存在
|
||||
validateUserWalletExists(id);
|
||||
// 删除
|
||||
userWalletMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserWalletListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
userWalletMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateUserWalletExists(Long id) {
|
||||
if (userWalletMapper.selectById(id) == null) {
|
||||
throw exception(USER_WALLET_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardUserWalletDO getUserWallet(Long id) {
|
||||
return userWalletMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardUserWalletDO> getUserWalletPage(KeyboardUserWalletPageReqVO pageReqVO) {
|
||||
return userWalletMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
// ==================== 子表(钱包交易记录) ====================
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardWalletTransactionDO> getWalletTransactionPage(PageParam pageReqVO, Long userId) {
|
||||
return walletTransactionMapper.selectPage(pageReqVO, userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createWalletTransaction(KeyboardWalletTransactionDO walletTransaction) {
|
||||
walletTransactionMapper.insert(walletTransaction);
|
||||
return walletTransaction.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWalletTransaction(KeyboardWalletTransactionDO walletTransaction) {
|
||||
// 校验存在
|
||||
validateWalletTransactionExists(walletTransaction.getId());
|
||||
// 更新
|
||||
walletTransactionMapper.updateById(walletTransaction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWalletTransaction(Long id) {
|
||||
// 删除
|
||||
walletTransactionMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWalletTransactionListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
walletTransactionMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardWalletTransactionDO getWalletTransaction(Long id) {
|
||||
return walletTransactionMapper.selectById(id);
|
||||
}
|
||||
|
||||
private void validateWalletTransactionExists(Long id) {
|
||||
if (walletTransactionMapper.selectById(id) == null) {
|
||||
throw exception(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteWalletTransactionByUserId(Long userId) {
|
||||
walletTransactionMapper.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
private void deleteWalletTransactionByUserIds(List<Long> userIds) {
|
||||
walletTransactionMapper.deleteByUserIds(userIds);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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.userwallet.KeyboardUserWalletMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user