feat(product-items): 新增内购商品管理功能
新增完整的内购商品模块,包含: - 控制层、服务层、数据访问层 - 分页查询、保存、响应 VO - MyBatis XML 映射 - 补充商品不存在错误码
This commit is contained in:
@@ -0,0 +1,104 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.productitems;
|
||||||
|
|
||||||
|
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.productitems.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.productitems.KeyboardProductItemsDO;
|
||||||
|
import com.yolo.keyboard.service.productitems.KeyboardProductItemsService;
|
||||||
|
|
||||||
|
@Tag(name = "管理后台 - 内购商品")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/keyboard/product-items")
|
||||||
|
@Validated
|
||||||
|
public class KeyboardProductItemsController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardProductItemsService productItemsService;
|
||||||
|
|
||||||
|
@PostMapping("/create")
|
||||||
|
@Operation(summary = "创建内购商品")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:create')")
|
||||||
|
public CommonResult<Long> createProductItems(@Valid @RequestBody KeyboardProductItemsSaveReqVO createReqVO) {
|
||||||
|
return success(productItemsService.createProductItems(createReqVO));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update")
|
||||||
|
@Operation(summary = "更新内购商品")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:update')")
|
||||||
|
public CommonResult<Boolean> updateProductItems(@Valid @RequestBody KeyboardProductItemsSaveReqVO updateReqVO) {
|
||||||
|
productItemsService.updateProductItems(updateReqVO);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
@Operation(summary = "删除内购商品")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:delete')")
|
||||||
|
public CommonResult<Boolean> deleteProductItems(@RequestParam("id") Long id) {
|
||||||
|
productItemsService.deleteProductItems(id);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete-list")
|
||||||
|
@Parameter(name = "ids", description = "编号", required = true)
|
||||||
|
@Operation(summary = "批量删除内购商品")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:delete')")
|
||||||
|
public CommonResult<Boolean> deleteProductItemsList(@RequestParam("ids") List<Long> ids) {
|
||||||
|
productItemsService.deleteProductItemsListByIds(ids);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/get")
|
||||||
|
@Operation(summary = "获得内购商品")
|
||||||
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:query')")
|
||||||
|
public CommonResult<KeyboardProductItemsRespVO> getProductItems(@RequestParam("id") Long id) {
|
||||||
|
KeyboardProductItemsDO productItems = productItemsService.getProductItems(id);
|
||||||
|
return success(BeanUtils.toBean(productItems, KeyboardProductItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得内购商品分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:query')")
|
||||||
|
public CommonResult<PageResult<KeyboardProductItemsRespVO>> getProductItemsPage(@Valid KeyboardProductItemsPageReqVO pageReqVO) {
|
||||||
|
PageResult<KeyboardProductItemsDO> pageResult = productItemsService.getProductItemsPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, KeyboardProductItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/export-excel")
|
||||||
|
@Operation(summary = "导出内购商品 Excel")
|
||||||
|
@PreAuthorize("@ss.hasPermission('keyboard:product-items:export')")
|
||||||
|
@ApiAccessLog(operateType = EXPORT)
|
||||||
|
public void exportProductItemsExcel(@Valid KeyboardProductItemsPageReqVO pageReqVO,
|
||||||
|
HttpServletResponse response) throws IOException {
|
||||||
|
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||||
|
List<KeyboardProductItemsDO> list = productItemsService.getProductItemsPage(pageReqVO).getList();
|
||||||
|
// 导出 Excel
|
||||||
|
ExcelUtils.write(response, "内购商品.xls", "数据", KeyboardProductItemsRespVO.class,
|
||||||
|
BeanUtils.toBean(list, KeyboardProductItemsRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.productitems.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 KeyboardProductItemsPageReqVO extends PageParam {
|
||||||
|
|
||||||
|
@Schema(description = "产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)", example = "15153")
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
@Schema(description = "产品类型,区分订阅(subscription)和内购(in-app-purchase)", example = "1")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Schema(description = "产品名称(如 100, 2)", example = "芋艿")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "产品单位(如 金币,个月)")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的数值部分(如 2)")
|
||||||
|
private Integer durationValue;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的单位部分(如 月,天)")
|
||||||
|
private String durationUnit;
|
||||||
|
|
||||||
|
@Schema(description = "产品价格", example = "25376")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
@Schema(description = "产品的货币单位,如美元($)")
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
@Schema(description = "产品的描述,提供更多细节信息", example = "你说的对")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的创建时间,默认当前时间")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的最后更新时间,更新时自动设置为当前时间")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的具体天数")
|
||||||
|
private Integer durationDays;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.productitems.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 KeyboardProductItemsRespVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键,自增,唯一标识每个产品项", requiredMode = Schema.RequiredMode.REQUIRED, example = "7855")
|
||||||
|
@ExcelProperty("主键,自增,唯一标识每个产品项")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)", requiredMode = Schema.RequiredMode.REQUIRED, example = "15153")
|
||||||
|
@ExcelProperty("产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)")
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
@Schema(description = "产品类型,区分订阅(subscription)和内购(in-app-purchase)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@ExcelProperty("产品类型,区分订阅(subscription)和内购(in-app-purchase)")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Schema(description = "产品名称(如 100, 2)", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||||
|
@ExcelProperty("产品名称(如 100, 2)")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "产品单位(如 金币,个月)")
|
||||||
|
@ExcelProperty("产品单位(如 金币,个月)")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的数值部分(如 2)")
|
||||||
|
@ExcelProperty("订阅时长的数值部分(如 2)")
|
||||||
|
private Integer durationValue;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的单位部分(如 月,天)")
|
||||||
|
@ExcelProperty("订阅时长的单位部分(如 月,天)")
|
||||||
|
private String durationUnit;
|
||||||
|
|
||||||
|
@Schema(description = "产品价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "25376")
|
||||||
|
@ExcelProperty("产品价格")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
@Schema(description = "产品的货币单位,如美元($)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("产品的货币单位,如美元($)")
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
@Schema(description = "产品的描述,提供更多细节信息", example = "你说的对")
|
||||||
|
@ExcelProperty("产品的描述,提供更多细节信息")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的创建时间,默认当前时间")
|
||||||
|
@ExcelProperty("产品项的创建时间,默认当前时间")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的最后更新时间,更新时自动设置为当前时间")
|
||||||
|
@ExcelProperty("产品项的最后更新时间,更新时自动设置为当前时间")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的具体天数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@ExcelProperty("订阅时长的具体天数")
|
||||||
|
private Integer durationDays;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.yolo.keyboard.controller.admin.productitems.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 KeyboardProductItemsSaveReqVO {
|
||||||
|
|
||||||
|
@Schema(description = "主键,自增,唯一标识每个产品项", requiredMode = Schema.RequiredMode.REQUIRED, example = "7855")
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@Schema(description = "产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)", requiredMode = Schema.RequiredMode.REQUIRED, example = "15153")
|
||||||
|
@NotEmpty(message = "产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)不能为空")
|
||||||
|
private String productId;
|
||||||
|
|
||||||
|
@Schema(description = "产品类型,区分订阅(subscription)和内购(in-app-purchase)", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||||
|
@NotEmpty(message = "产品类型,区分订阅(subscription)和内购(in-app-purchase)不能为空")
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
@Schema(description = "产品名称(如 100, 2)", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
|
||||||
|
@NotEmpty(message = "产品名称(如 100, 2)不能为空")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "产品单位(如 金币,个月)")
|
||||||
|
private String unit;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的数值部分(如 2)")
|
||||||
|
private Integer durationValue;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的单位部分(如 月,天)")
|
||||||
|
private String durationUnit;
|
||||||
|
|
||||||
|
@Schema(description = "产品价格", requiredMode = Schema.RequiredMode.REQUIRED, example = "25376")
|
||||||
|
@NotNull(message = "产品价格不能为空")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
@Schema(description = "产品的货币单位,如美元($)", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotEmpty(message = "产品的货币单位,如美元($)不能为空")
|
||||||
|
private String currency;
|
||||||
|
|
||||||
|
@Schema(description = "产品的描述,提供更多细节信息", example = "你说的对")
|
||||||
|
private String description;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的创建时间,默认当前时间")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
@Schema(description = "产品项的最后更新时间,更新时自动设置为当前时间")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
@Schema(description = "订阅时长的具体天数", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
@NotNull(message = "订阅时长的具体天数不能为空")
|
||||||
|
private Integer durationDays;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
package com.yolo.keyboard.dal.dataobject.productitems;
|
||||||
|
|
||||||
|
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_product_items")
|
||||||
|
@KeySequence("keyboard_product_items_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||||
|
@Data
|
||||||
|
@ToString(callSuper = true)
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@TenantIgnore
|
||||||
|
public class KeyboardProductItemsDO{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主键,自增,唯一标识每个产品项
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 产品标识符,唯一标识每个产品(如 com.loveKey.nyx.2month)
|
||||||
|
*/
|
||||||
|
private String productId;
|
||||||
|
/**
|
||||||
|
* 产品类型,区分订阅(subscription)和内购(in-app-purchase)
|
||||||
|
*/
|
||||||
|
private String type;
|
||||||
|
/**
|
||||||
|
* 产品名称(如 100, 2)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 产品单位(如 金币,个月)
|
||||||
|
*/
|
||||||
|
private String unit;
|
||||||
|
/**
|
||||||
|
* 订阅时长的数值部分(如 2)
|
||||||
|
*/
|
||||||
|
private Integer durationValue;
|
||||||
|
/**
|
||||||
|
* 订阅时长的单位部分(如 月,天)
|
||||||
|
*/
|
||||||
|
private String durationUnit;
|
||||||
|
/**
|
||||||
|
* 产品价格
|
||||||
|
*/
|
||||||
|
private BigDecimal price;
|
||||||
|
/**
|
||||||
|
* 产品的货币单位,如美元($)
|
||||||
|
*/
|
||||||
|
private String currency;
|
||||||
|
/**
|
||||||
|
* 产品的描述,提供更多细节信息
|
||||||
|
*/
|
||||||
|
private String description;
|
||||||
|
/**
|
||||||
|
* 产品项的创建时间,默认当前时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
/**
|
||||||
|
* 产品项的最后更新时间,更新时自动设置为当前时间
|
||||||
|
*/
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
/**
|
||||||
|
* 订阅时长的具体天数
|
||||||
|
*/
|
||||||
|
private Integer durationDays;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package com.yolo.keyboard.dal.mysql.productitems;
|
||||||
|
|
||||||
|
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.productitems.KeyboardProductItemsDO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import com.yolo.keyboard.controller.admin.productitems.vo.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内购商品 Mapper
|
||||||
|
*
|
||||||
|
* @author ziin
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface KeyboardProductItemsMapper extends BaseMapperX<KeyboardProductItemsDO> {
|
||||||
|
|
||||||
|
default PageResult<KeyboardProductItemsDO> selectPage(KeyboardProductItemsPageReqVO reqVO) {
|
||||||
|
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardProductItemsDO>()
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getProductId, reqVO.getProductId())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getType, reqVO.getType())
|
||||||
|
.likeIfPresent(KeyboardProductItemsDO::getName, reqVO.getName())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getUnit, reqVO.getUnit())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getDurationValue, reqVO.getDurationValue())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getDurationUnit, reqVO.getDurationUnit())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getPrice, reqVO.getPrice())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getCurrency, reqVO.getCurrency())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getDescription, reqVO.getDescription())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getCreatedAt, reqVO.getCreatedAt())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||||
|
.eqIfPresent(KeyboardProductItemsDO::getDurationDays, reqVO.getDurationDays())
|
||||||
|
.orderByDesc(KeyboardProductItemsDO::getId));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.yolo.keyboard.service.productitems;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import jakarta.validation.*;
|
||||||
|
import com.yolo.keyboard.controller.admin.productitems.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.productitems.KeyboardProductItemsDO;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||||
|
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内购商品 Service 接口
|
||||||
|
*
|
||||||
|
* @author ziin
|
||||||
|
*/
|
||||||
|
public interface KeyboardProductItemsService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建内购商品
|
||||||
|
*
|
||||||
|
* @param createReqVO 创建信息
|
||||||
|
* @return 编号
|
||||||
|
*/
|
||||||
|
Long createProductItems(@Valid KeyboardProductItemsSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新内购商品
|
||||||
|
*
|
||||||
|
* @param updateReqVO 更新信息
|
||||||
|
*/
|
||||||
|
void updateProductItems(@Valid KeyboardProductItemsSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除内购商品
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
*/
|
||||||
|
void deleteProductItems(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除内购商品
|
||||||
|
*
|
||||||
|
* @param ids 编号
|
||||||
|
*/
|
||||||
|
void deleteProductItemsListByIds(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得内购商品
|
||||||
|
*
|
||||||
|
* @param id 编号
|
||||||
|
* @return 内购商品
|
||||||
|
*/
|
||||||
|
KeyboardProductItemsDO getProductItems(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得内购商品分页
|
||||||
|
*
|
||||||
|
* @param pageReqVO 分页查询
|
||||||
|
* @return 内购商品分页
|
||||||
|
*/
|
||||||
|
PageResult<KeyboardProductItemsDO> getProductItemsPage(KeyboardProductItemsPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.yolo.keyboard.service.productitems;
|
||||||
|
|
||||||
|
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.productitems.vo.*;
|
||||||
|
import com.yolo.keyboard.dal.dataobject.productitems.KeyboardProductItemsDO;
|
||||||
|
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.productitems.KeyboardProductItemsMapper;
|
||||||
|
|
||||||
|
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.PRODUCT_ITEMS_NOT_EXISTS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内购商品 Service 实现类
|
||||||
|
*
|
||||||
|
* @author ziin
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@Validated
|
||||||
|
public class KeyboardProductItemsServiceImpl implements KeyboardProductItemsService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private KeyboardProductItemsMapper productItemsMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long createProductItems(KeyboardProductItemsSaveReqVO createReqVO) {
|
||||||
|
// 插入
|
||||||
|
KeyboardProductItemsDO productItems = BeanUtils.toBean(createReqVO, KeyboardProductItemsDO.class);
|
||||||
|
productItemsMapper.insert(productItems);
|
||||||
|
|
||||||
|
// 返回
|
||||||
|
return productItems.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateProductItems(KeyboardProductItemsSaveReqVO updateReqVO) {
|
||||||
|
// 校验存在
|
||||||
|
validateProductItemsExists(updateReqVO.getId());
|
||||||
|
// 更新
|
||||||
|
KeyboardProductItemsDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardProductItemsDO.class);
|
||||||
|
productItemsMapper.updateById(updateObj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteProductItems(Long id) {
|
||||||
|
// 校验存在
|
||||||
|
validateProductItemsExists(id);
|
||||||
|
// 删除
|
||||||
|
productItemsMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteProductItemsListByIds(List<Long> ids) {
|
||||||
|
// 删除
|
||||||
|
productItemsMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void validateProductItemsExists(Long id) {
|
||||||
|
if (productItemsMapper.selectById(id) == null) {
|
||||||
|
throw exception(PRODUCT_ITEMS_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyboardProductItemsDO getProductItems(Long id) {
|
||||||
|
return productItemsMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PageResult<KeyboardProductItemsDO> getProductItemsPage(KeyboardProductItemsPageReqVO pageReqVO) {
|
||||||
|
return productItemsMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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.productitems.KeyboardProductItemsMapper">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||||
|
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||||
|
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||||
|
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||||
|
-->
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -78,6 +78,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode CHARACTER_NOT_EXISTS = new ErrorCode(1_001_202_004, "键盘人设不存在");
|
ErrorCode CHARACTER_NOT_EXISTS = new ErrorCode(1_001_202_004, "键盘人设不存在");
|
||||||
ErrorCode USER_WALLET_NOT_EXISTS = new ErrorCode(1_001_202_005, "用户钱包不存在");
|
ErrorCode USER_WALLET_NOT_EXISTS = new ErrorCode(1_001_202_005, "用户钱包不存在");
|
||||||
ErrorCode USER_PURCHASE_RECORDS_NOT_EXISTS = new ErrorCode(1_001_202_006, "用户内购记录不存在");
|
ErrorCode USER_PURCHASE_RECORDS_NOT_EXISTS = new ErrorCode(1_001_202_006, "用户内购记录不存在");
|
||||||
|
ErrorCode PRODUCT_ITEMS_NOT_EXISTS = new ErrorCode(1_001_202_007, "内购商品不存在");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user