feat:礼物代码生成

This commit is contained in:
dzc committed 2025-11-10 14:22:09 +08:00
1 parent 262dd1b8ee
commit 96e12a1549
11 files changed
+436 -5

No files matched your search

+23 -2
View File
@@ -179,7 +179,7 @@ CREATE TABLE `member_open_type`
`original_price` int NOT NULL COMMENT '价格(原价)',
`duration` int NOT NULL COMMENT '时长(天)',
`status` char(32) NOT NULL COMMENT '状态',
`is_hot` bit(1) NOT NULL COMMENT '是否热门',
`is_hot` bit(1) NOT NULL COMMENT '是否热门',
`sort` int DEFAULT 0 NOT NULL COMMENT '排序',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
@@ -210,4 +210,25 @@ CREATE TABLE `member_open_type_user`
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 32 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '会员开通类型与用户关联表';
) ENGINE = InnoDB AUTO_INCREMENT = 32 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '会员开通类型与用户关联表';
-- ----------------------------
-- Table structure for trade_gift
-- ----------------------------
DROP TABLE IF EXISTS `trade_gift`;
CREATE TABLE `trade_gift`
(
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '礼物商品id',
`title` bigint NOT NULL COMMENT '礼物标题',
`price` int NOT NULL COMMENT '礼物价格(分)',
`image` varchar(256) NOT NULL COMMENT '礼物图片',
`status` char(32) NOT NULL COMMENT '礼物状态',
`creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者',
`update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除',
`tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 32 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin COMMENT = '礼物商品';
@@ -4,7 +4,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
/**
* Product 错误码枚举类
*
* <p>
* product 系统,使用 1-008-000-000 段
*/
public interface ErrorCodeConstants {
@@ -53,4 +53,7 @@ public interface ErrorCodeConstants {
ErrorCode FAVORITE_EXISTS = new ErrorCode(1_008_008_000, "该商品已经被收藏");
ErrorCode FAVORITE_NOT_EXISTS = new ErrorCode(1_008_008_001, "商品收藏不存在");
// ========== 礼物 商品 1-008-009-000 ==========
ErrorCode GIFT_NOT_EXISTS = new ErrorCode(1_008_009_001, "礼物不存在");
}
@@ -0,0 +1,99 @@
package cn.iocoder.yudao.module.product.controller.admin.gift;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftRespVO;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.gift.GiftDO;
import cn.iocoder.yudao.module.product.service.gift.GiftService;
import org.springframework.web.bind.annotation.*;
import javax.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 javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
@Tag(name = "管理后台 - 礼物商品")
@RestController
@RequestMapping("/trade/gift")
@Validated
public class GiftController {
@Resource
private GiftService giftService;
@PostMapping("/create")
@Operation(summary = "创建礼物商品")
@PreAuthorize("@ss.hasPermission('trade:gift:create')")
public CommonResult<Long> createGift(@Valid @RequestBody GiftSaveReqVO createReqVO) {
return success(giftService.createGift(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新礼物商品")
@PreAuthorize("@ss.hasPermission('trade:gift:update')")
public CommonResult<Boolean> updateGift(@Valid @RequestBody GiftSaveReqVO updateReqVO) {
giftService.updateGift(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除礼物商品")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('trade:gift:delete')")
public CommonResult<Boolean> deleteGift(@RequestParam("id") Long id) {
giftService.deleteGift(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得礼物商品")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('trade:gift:query')")
public CommonResult<GiftRespVO> getGift(@RequestParam("id") Long id) {
GiftDO gift = giftService.getGift(id);
return success(BeanUtils.toBean(gift, GiftRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得礼物商品分页")
@PreAuthorize("@ss.hasPermission('trade:gift:query')")
public CommonResult<PageResult<GiftRespVO>> getGiftPage(@Valid GiftPageReqVO pageReqVO) {
PageResult<GiftDO> pageResult = giftService.getGiftPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, GiftRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出礼物商品 Excel")
@PreAuthorize("@ss.hasPermission('trade:gift:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportGiftExcel(@Valid GiftPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<GiftDO> list = giftService.getGiftPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "礼物商品.xls", "数据", GiftRespVO.class, BeanUtils.toBean(list, GiftRespVO.class));
}
}
@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.product.controller.admin.gift.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 礼物商品分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class GiftPageReqVO extends PageParam {
@Schema(description = "礼物标题")
private Long title;
@Schema(description = "礼物价格(分)", example = "31512")
private Integer price;
@Schema(description = "礼物图片")
private String image;
@Schema(description = "礼物状态", example = "2")
private String status;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}
@@ -0,0 +1,39 @@
package cn.iocoder.yudao.module.product.controller.admin.gift.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 礼物商品 Response VO")
@Data
@ExcelIgnoreUnannotated
public class GiftRespVO {
@Schema(description = "礼物商品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15694")
@ExcelProperty("礼物商品id")
private Long id;
@Schema(description = "礼物标题", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("礼物标题")
private Long title;
@Schema(description = "礼物价格(分)", requiredMode = Schema.RequiredMode.REQUIRED, example = "31512")
@ExcelProperty("礼物价格(分)")
private Integer price;
@Schema(description = "礼物图片", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("礼物图片")
private String image;
@Schema(description = "礼物状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@ExcelProperty("礼物状态")
private String status;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}
@@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.product.controller.admin.gift.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import javax.validation.constraints.*;
@Schema(description = "管理后台 - 礼物商品新增/修改 Request VO")
@Data
public class GiftSaveReqVO {
@Schema(description = "礼物商品id", requiredMode = Schema.RequiredMode.REQUIRED, example = "15694")
private Long id;
@Schema(description = "礼物标题", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "礼物标题不能为空")
private Long title;
@Schema(description = "礼物价格(分)", requiredMode = Schema.RequiredMode.REQUIRED, example = "31512")
@NotNull(message = "礼物价格(分)不能为空")
private Integer price;
@Schema(description = "礼物图片", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "礼物图片不能为空")
private String image;
@Schema(description = "礼物状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
@NotEmpty(message = "礼物状态不能为空")
private String status;
}
@@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.product.dal.dataobject.gift;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* 礼物商品 DO
*
* @author 聊天交友
*/
@TableName("trade_gift")
@KeySequence("trade_gift_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GiftDO extends BaseDO {
/**
* 礼物商品id
*/
@TableId
private Long id;
/**
* 礼物标题
*/
private Long title;
/**
* 礼物价格(分)
*/
private Integer price;
/**
* 礼物图片
*/
private String image;
/**
* 礼物状态
*/
private String status;
}
@@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.product.dal.mysql.gift;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftPageReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.gift.GiftDO;
import org.apache.ibatis.annotations.Mapper;
/**
* 礼物商品 Mapper
*/
@Mapper
public interface GiftMapper extends BaseMapperX<GiftDO> {
default PageResult<GiftDO> selectPage(GiftPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<GiftDO>()
.eqIfPresent(GiftDO::getTitle, reqVO.getTitle())
.eqIfPresent(GiftDO::getPrice, reqVO.getPrice())
.eqIfPresent(GiftDO::getImage, reqVO.getImage())
.eqIfPresent(GiftDO::getStatus, reqVO.getStatus())
.betweenIfPresent(GiftDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(GiftDO::getId));
}
}
@@ -0,0 +1,40 @@
package cn.iocoder.yudao.module.product.service.gift;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.gift.GiftDO;
/**
* 礼物商品 Service 接口
*/
public interface GiftService {
/**
* 创建礼物商品
*/
Long createGift(@Valid GiftSaveReqVO createReqVO);
/**
* 更新礼物商品
*/
void updateGift(@Valid GiftSaveReqVO updateReqVO);
/**
* 删除礼物商品
*/
void deleteGift(Long id);
/**
* 获得礼物商品
*/
GiftDO getGift(Long id);
/**
* 获得礼物商品分页
*/
PageResult<GiftDO> getGiftPage(GiftPageReqVO pageReqVO);
}
@@ -0,0 +1,91 @@
package cn.iocoder.yudao.module.product.service.gift;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftPageReqVO;
import cn.iocoder.yudao.module.product.controller.admin.gift.vo.GiftSaveReqVO;
import cn.iocoder.yudao.module.product.dal.dataobject.gift.GiftDO;
import cn.iocoder.yudao.module.product.dal.mysql.gift.GiftMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.GIFT_NOT_EXISTS;
/**
* 礼物商品 Service 实现类
*
* @author 聊天交友
*/
@Service
@Validated
public class GiftServiceImpl implements GiftService {
@Resource
private GiftMapper giftMapper;
/**
* 创建礼物商品
*/
@Override
public Long createGift(GiftSaveReqVO createReqVO) {
// 插入
GiftDO gift = BeanUtils.toBean(createReqVO, GiftDO.class);
giftMapper.insert(gift);
// 返回
return gift.getId();
}
/**
* 更新礼物商品
*/
@Override
public void updateGift(GiftSaveReqVO updateReqVO) {
// 校验存在
validateGiftExists(updateReqVO.getId());
// 更新
GiftDO updateObj = BeanUtils.toBean(updateReqVO, GiftDO.class);
giftMapper.updateById(updateObj);
}
/**
* 删除礼物商品
*/
@Override
public void deleteGift(Long id) {
// 校验存在
validateGiftExists(id);
// 删除
giftMapper.deleteById(id);
}
/**
* 获得礼物商品
*/
@Override
public GiftDO getGift(Long id) {
return giftMapper.selectById(id);
}
/**
* 获得礼物商品分页
*/
@Override
public PageResult<GiftDO> getGiftPage(GiftPageReqVO pageReqVO) {
return giftMapper.selectPage(pageReqVO);
}
private void validateGiftExists(Long id) {
if (giftMapper.selectById(id) == null) {
throw exception(GIFT_NOT_EXISTS);
}
}
}
@@ -46,8 +46,6 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
/**
* 朋友圈 Service 实现类
*
* @author 聊天交友
*/
@Slf4j
@Service