feat(product): 新增商品及SKU实体和相关配置

- 添加商品实体类MtProduct及其Mapper接口
- 添加商品SKU实体类MtProductSku及其Mapper接口
- 配置MyBatis-Plus分页插件和自动填充处理器
- 完善实体字段注释和数据类型定义
- 集成SLF4J日志功能并添加详细使用指南文档
This commit is contained in:
2025-12-19 17:52:06 +08:00
parent 8cfe9e00e0
commit c338571dc1
7 changed files with 471 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package com.mtkj.mtpay.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* MyBatis-Plus配置类
*/
@Slf4j
@Configuration
@MapperScan("com.mtkj.mtpay.mapper")
public class MyBatisPlusConfig {
/**
* 分页插件配置
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
log.info("初始化MyBatis-Plus分页插件数据库类型: {}", DbType.MYSQL);
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 添加分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
log.info("MyBatis-Plus分页插件配置完成");
return interceptor;
}
}

View File

@@ -0,0 +1,31 @@
package com.mtkj.mtpay.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
/**
* MyBatis-Plus自动填充处理器
* 用于自动填充创建时间和更新时间
*/
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.debug("开始插入填充...");
this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
}
@Override
public void updateFill(MetaObject metaObject) {
log.debug("开始更新填充...");
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
}
}

View File

@@ -0,0 +1,64 @@
package com.mtkj.mtpay.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 商品实体类
*/
@TableName(value = "mt_product")
@Data
public class MtProduct {
/**
* 商品ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 商品名称
*/
@TableField(value = "name", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String name;
/**
* 商品价格基础价格SKU可能有不同价格
*/
@TableField(value = "price", jdbcType = org.apache.ibatis.type.JdbcType.DECIMAL)
private BigDecimal price;
/**
* 主图URL最大4000字符
*/
@TableField(value = "main_image", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String mainImage;
/**
* 商品状态ACTIVE-上架INACTIVE-下架DELETED-已删除
*/
@TableField(value = "status", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String status;
/**
* 店铺ID
*/
@TableField(value = "shop_id", jdbcType = org.apache.ibatis.type.JdbcType.BIGINT)
private Long shopId;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,100 @@
package com.mtkj.mtpay.entity;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 商品SKU实体类
*/
@TableName(value = "mt_product_sku")
@Data
public class MtProductSku {
/**
* SKU ID
*/
@TableId(value = "id", type = IdType.AUTO)
private Long id;
/**
* 商品ID
*/
@TableField(value = "product_id", jdbcType = org.apache.ibatis.type.JdbcType.BIGINT)
private Long productId;
/**
* SKU编码最大2000字符
*/
@TableField(value = "sku", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String sku;
/**
* 价格
*/
@TableField(value = "price", jdbcType = org.apache.ibatis.type.JdbcType.DECIMAL)
private BigDecimal price;
/**
* 货币ISO 4217三位币种代码如USD、CNY
*/
@TableField(value = "currency", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String currency;
/**
* 库存数量
*/
@TableField(value = "stock", jdbcType = org.apache.ibatis.type.JdbcType.INTEGER)
private Integer stock;
/**
* 销售属性名称LONGTEXTJSON格式[{"name":"颜色","value":"红色"},{"name":"尺寸","value":"大号"}]
*/
@TableField(value = "sales_attrs", jdbcType = org.apache.ibatis.type.JdbcType.LONGVARCHAR)
private String salesAttrs;
/**
* SKU图片URL最大4000字符
*/
@TableField(value = "sku_image", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String skuImage;
/**
* 重量(单位:克)
*/
@TableField(value = "weight", jdbcType = org.apache.ibatis.type.JdbcType.DECIMAL)
private BigDecimal weight;
/**
* 大小/尺寸JSON格式{"length":10,"width":5,"height":3},单位:厘米)
*/
@TableField(value = "size", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String size;
/**
* 规格文本描述最大2000字符
*/
@TableField(value = "specification", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String specification;
/**
* SKU状态ACTIVE-启用INACTIVE-禁用
*/
@TableField(value = "status", jdbcType = org.apache.ibatis.type.JdbcType.VARCHAR)
private String status;
/**
* 创建时间
*/
@TableField(value = "create_time", fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,13 @@
package com.mtkj.mtpay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mtkj.mtpay.entity.MtProduct;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品Mapper接口
*/
@Mapper
public interface MtProductMapper extends BaseMapper<MtProduct> {
}

View File

@@ -0,0 +1,13 @@
package com.mtkj.mtpay.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.mtkj.mtpay.entity.MtProductSku;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品SKU Mapper接口
*/
@Mapper
public interface MtProductSkuMapper extends BaseMapper<MtProductSku> {
}