diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/KeyboardUserWalletController.java b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/KeyboardUserWalletController.java new file mode 100644 index 0000000..098e681 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/KeyboardUserWalletController.java @@ -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 createUserWallet(@Valid @RequestBody KeyboardUserWalletSaveReqVO createReqVO) { + return success(userWalletService.createUserWallet(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新用户钱包") + @PreAuthorize("@ss.hasPermission('keyboard:user-wallet:update')") + public CommonResult 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 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 deleteUserWalletList(@RequestParam("ids") List 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 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> getUserWalletPage(@Valid KeyboardUserWalletPageReqVO pageReqVO) { + PageResult 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 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> 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 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 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 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 deleteWalletTransactionList(@RequestParam("ids") List 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 getWalletTransaction(@RequestParam("id") Long id) { + return success(userWalletService.getWalletTransaction(id)); + } + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletPageReqVO.java b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletPageReqVO.java new file mode 100644 index 0000000..45df652 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletPageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletRespVO.java b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletRespVO.java new file mode 100644 index 0000000..9d9664c --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletRespVO.java @@ -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; + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletSaveReqVO.java b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletSaveReqVO.java new file mode 100644 index 0000000..f087f80 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/controller/admin/userwallet/vo/KeyboardUserWalletSaveReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardUserWalletDO.java b/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardUserWalletDO.java new file mode 100644 index 0000000..d33aad5 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardUserWalletDO.java @@ -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; + + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardWalletTransactionDO.java b/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardWalletTransactionDO.java new file mode 100644 index 0000000..e6757d1 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/dal/dataobject/userwallet/KeyboardWalletTransactionDO.java @@ -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; + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardUserWalletMapper.java b/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardUserWalletMapper.java new file mode 100644 index 0000000..2e61eb2 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardUserWalletMapper.java @@ -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 { + + default PageResult selectPage(KeyboardUserWalletPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .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)); + } + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardWalletTransactionMapper.java b/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardWalletTransactionMapper.java new file mode 100644 index 0000000..99e6dd5 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/dal/mysql/userwallet/KeyboardWalletTransactionMapper.java @@ -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 { + + default PageResult selectPage(PageParam reqVO, Long userId) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eq(KeyboardWalletTransactionDO::getUserId, userId) + .orderByDesc(KeyboardWalletTransactionDO::getId)); + } + + default int deleteByUserId(Long userId) { + return delete(KeyboardWalletTransactionDO::getUserId, userId); + } + + default int deleteByUserIds(List userIds) { + return deleteBatch(KeyboardWalletTransactionDO::getUserId, userIds); + } + +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletService.java b/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletService.java new file mode 100644 index 0000000..1147410 --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletService.java @@ -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 ids); + + /** + * 获得用户钱包 + * + * @param id 编号 + * @return 用户钱包 + */ + KeyboardUserWalletDO getUserWallet(Long id); + + /** + * 获得用户钱包分页 + * + * @param pageReqVO 分页查询 + * @return 用户钱包分页 + */ + PageResult getUserWalletPage(KeyboardUserWalletPageReqVO pageReqVO); +// ==================== 子表(钱包交易记录) ==================== + + /** + * 获得钱包交易记录分页 + * + * @param pageReqVO 分页查询 + * @param userId 用户 Id + * @return 钱包交易记录分页 + */ + PageResult 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 ids); + + /** + * 获得钱包交易记录 + * + * @param id 编号 + * @return 钱包交易记录 + */ + KeyboardWalletTransactionDO getWalletTransaction(Long id); +} \ No newline at end of file diff --git a/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletServiceImpl.java b/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletServiceImpl.java new file mode 100644 index 0000000..0ed987f --- /dev/null +++ b/keyboard-server/src/main/java/com/yolo/keyboard/service/userwallet/KeyboardUserWalletServiceImpl.java @@ -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 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 getUserWalletPage(KeyboardUserWalletPageReqVO pageReqVO) { + return userWalletMapper.selectPage(pageReqVO); + } + + // ==================== 子表(钱包交易记录) ==================== + + @Override + public PageResult 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 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 userIds) { + walletTransactionMapper.deleteByUserIds(userIds); + } + + +} \ No newline at end of file diff --git a/keyboard-server/src/main/resources/mapper/userwallet/KeyboardUserWalletMapper.xml b/keyboard-server/src/main/resources/mapper/userwallet/KeyboardUserWalletMapper.xml new file mode 100644 index 0000000..28875da --- /dev/null +++ b/keyboard-server/src/main/resources/mapper/userwallet/KeyboardUserWalletMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yolo-module-infra/src/main/java/com/yolo/keyboard/module/infra/enums/ErrorCodeConstants.java b/yolo-module-infra/src/main/java/com/yolo/keyboard/module/infra/enums/ErrorCodeConstants.java index 4f3355e..f1309e4 100644 --- a/yolo-module-infra/src/main/java/com/yolo/keyboard/module/infra/enums/ErrorCodeConstants.java +++ b/yolo-module-infra/src/main/java/com/yolo/keyboard/module/infra/enums/ErrorCodeConstants.java @@ -76,5 +76,7 @@ public interface ErrorCodeConstants { ErrorCode KEYBOARD_THEME_STYLES_NOT_EXISTS = new ErrorCode(1_001_202_002, "主题风格不存在"); ErrorCode THEME_PURCHASE_NOT_EXISTS = new ErrorCode(1_001_202_003, "皮肤购买记录表(积分支付)不存在"); ErrorCode CHARACTER_NOT_EXISTS = new ErrorCode(1_001_202_004, "键盘人设不存在"); + ErrorCode USER_WALLET_NOT_EXISTS = new ErrorCode(1_001_202_005, "用户钱包不存在"); + } diff --git a/yolo-server/src/main/resources/application-local.yaml b/yolo-server/src/main/resources/application-local.yaml index f085267..da33cf1 100644 --- a/yolo-server/src/main/resources/application-local.yaml +++ b/yolo-server/src/main/resources/application-local.yaml @@ -180,6 +180,7 @@ logging: com.yolo.keyboard.module.iot.dal.tdengine: DEBUG com.yolo.keyboard.module.iot.service.rule: debug com.yolo.keyboard.module.ai.dal.mysql: debug + com.yolo.keyboard: debug org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 芋艿:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 debug: false