diff --git a/pom.xml b/pom.xml index cdd1f9e4..3d195505 100644 --- a/pom.xml +++ b/pom.xml @@ -234,6 +234,7 @@ ruoyi-demo ruoyi-extend ruoyi-oss + ruoyi-mall pom diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 8b633f85..472e1ac3 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -103,7 +103,7 @@ token: # 令牌密钥 secret: abcdefghijklmnopqrstuvwxyz # 令牌有效期(默认30分钟) - expireTime: 30 + expireTime: 300 # 重复提交 repeat-submit: diff --git a/ruoyi-common/pom.xml b/ruoyi-common/pom.xml index d32051ad..49642584 100644 --- a/ruoyi-common/pom.xml +++ b/ruoyi-common/pom.xml @@ -2,182 +2,198 @@ - - ruoyi-vue-plus - com.ruoyi - 3.0.0 - - 4.0.0 + + ruoyi-vue-plus + com.ruoyi + 3.0.0 + + 4.0.0 - ruoyi-common + ruoyi-common - - common通用工具 - + + common通用工具 + - + - - - org.springframework - spring-context-support - + + + org.springframework + spring-context-support + - - - org.springframework - spring-web - + + + org.springframework + spring-web + - - - org.springframework.boot - spring-boot-starter-security - + + + org.springframework.boot + spring-boot-starter-security + - - - javax.validation - validation-api - + + + javax.validation + validation-api + - - - org.apache.commons - commons-lang3 - + + + org.apache.commons + commons-lang3 + - - - com.fasterxml.jackson.core - jackson-databind - + + + com.fasterxml.jackson.core + jackson-databind + - - - org.apache.poi - poi-ooxml - + + + org.apache.poi + poi-ooxml + - - com.alibaba - easyexcel - + + com.alibaba + easyexcel + - - - org.yaml - snakeyaml - + + + org.yaml + snakeyaml + - - - io.jsonwebtoken - jjwt - + + + io.jsonwebtoken + jjwt + - - - org.springframework.boot - spring-boot-starter-data-redis - + + + org.springframework.boot + spring-boot-starter-data-redis + - - - org.apache.commons - commons-pool2 - + + + org.apache.commons + commons-pool2 + - - - javax.servlet - javax.servlet-api - + + + javax.servlet + javax.servlet-api + - - com.baomidou - mybatis-plus-boot-starter - - - com.baomidou - mybatis-plus-extension - - - cn.hutool - hutool-all - - - org.projectlombok - lombok - + + com.baomidou + mybatis-plus-boot-starter + + + com.baomidou + mybatis-plus-extension + + + cn.hutool + hutool-all + + + org.projectlombok + lombok + - - org.springframework.cloud - spring-cloud-starter-openfeign - + + org.springframework.cloud + spring-cloud-starter-openfeign + - - io.github.openfeign - feign-okhttp - + + io.github.openfeign + feign-okhttp + - - de.codecentric - spring-boot-admin-starter-client - + + de.codecentric + spring-boot-admin-starter-client + - - com.github.xiaoymin - knife4j-spring-boot-starter - + + com.github.xiaoymin + knife4j-spring-boot-starter + - - org.springframework.boot - spring-boot-starter-actuator - - - - org.springframework.boot - spring-boot-configuration-processor - + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-configuration-processor + - - - org.redisson - redisson-spring-boot-starter - + + + org.redisson + redisson-spring-boot-starter + - - - com.baomidou - dynamic-datasource-spring-boot-starter - - - - p6spy - p6spy - + + + com.baomidou + dynamic-datasource-spring-boot-starter + + + + p6spy + p6spy + - - com.baomidou - lock4j-redisson-spring-boot-starter - + + com.baomidou + lock4j-redisson-spring-boot-starter + - - - - com.github.atool - fluent-mybatis - 1.7.2 - - - - com.github.atool - fluent-mybatis-processor - 1.7.2 - provided - + + + + com.github.atool + fluent-mybatis + 1.7.2 + + + + com.github.atool + fluent-mybatis-processor + 1.7.2 + provided + - + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + mysql + mysql-connector-java + + diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/config/MapperConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/config/MapperConfig.java new file mode 100644 index 00000000..7cb74c8c --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/config/MapperConfig.java @@ -0,0 +1,24 @@ +package com.ruoyi.common.config; + +import cn.org.atool.fluent.mybatis.spring.MapperFactory; +import com.ruoyi.common.core.domain.entity.test.relation.ProductCategoryRelationEntity; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * Mapper配置类 + * @author Geniou + * @create 2021/9/10 12:11 + */ +@Configuration +public class MapperConfig { + + @Bean + public MapperFactory mapperFactory() { + return new MapperFactory(); + } + + @Bean + public ProductCategoryRelationEntity entityRelation() { return new ProductCategoryRelationEntity(); } + +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/Product.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/Product.java deleted file mode 100644 index 7ec248d9..00000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/Product.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.ruoyi.common.core.domain.entity.test; - -import cn.org.atool.fluent.mybatis.annotation.FluentMybatis; -import cn.org.atool.fluent.mybatis.base.IEntity; -import com.baomidou.mybatisplus.annotation.*; -import lombok.Data; -import lombok.NoArgsConstructor; -import lombok.experimental.Accessors; -import java.io.Serializable; -import java.util.Date; -import java.math.BigDecimal; - -/** - * 商品对象 product - * - * @author ruoyi - * @date 2021-09-03 - */ - -@Data -@FluentMybatis -public class Product implements IEntity { - - private static final long serialVersionUID=1L; - - /** - * 商品id - */ - @TableId(value = "id") - private Long id; - - /** - * 创建时间 - */ - private Date createDateTime; - - /** - * 更新时间 - */ - private Date updateDateTime; - - /** - * 商品唯一编号 - */ - private String productCode; - - /** - * 商品名称 - */ - private String productName; - - /** - * 单价 - */ - private BigDecimal unitPrice; - - /** - * 运费 - */ - private BigDecimal freight; - -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/ProductTest.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/ProductTest.java deleted file mode 100644 index b4234654..00000000 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/ProductTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.ruoyi.common.core.domain.entity.test; - -import com.ruoyi.common.core.domain.entity.mapper.ProductMapper; -import org.springframework.beans.factory.annotation.Autowired; - -/** - * 商品测试 - * @author Geniou - * @create 2021/9/6 18:41 - */ -public class ProductTest { - - @Autowired - private ProductMapper productMapper; - - - -} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryDaoImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryDaoImpl.java new file mode 100644 index 00000000..525446d8 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryDaoImpl.java @@ -0,0 +1,16 @@ +package com.ruoyi.common.core.domain.entity.test.dao.impl; + +import com.ruoyi.common.core.domain.entity.test.dao.base.ProductCategoryBaseDao; +import com.ruoyi.common.core.domain.entity.test.dao.intf.ProductCategoryDao; +import org.springframework.stereotype.Repository; + +/** + * ProductCategoryDaoImpl: 数据操作接口实现 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +@Repository +public class ProductCategoryDaoImpl extends ProductCategoryBaseDao implements ProductCategoryDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryRelationDaoImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryRelationDaoImpl.java new file mode 100644 index 00000000..4a68fd75 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductCategoryRelationDaoImpl.java @@ -0,0 +1,16 @@ +package com.ruoyi.common.core.domain.entity.test.dao.impl; + +import com.ruoyi.common.core.domain.entity.test.dao.base.ProductCategoryRelationBaseDao; +import com.ruoyi.common.core.domain.entity.test.dao.intf.ProductCategoryRelationDao; +import org.springframework.stereotype.Repository; + +/** + * ProductCategoryRelationDaoImpl: 数据操作接口实现 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +@Repository +public class ProductCategoryRelationDaoImpl extends ProductCategoryRelationBaseDao implements ProductCategoryRelationDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductDaoImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductDaoImpl.java new file mode 100644 index 00000000..ee42587c --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductDaoImpl.java @@ -0,0 +1,16 @@ +package com.ruoyi.common.core.domain.entity.test.dao.impl; + +import com.ruoyi.common.core.domain.entity.test.dao.base.ProductBaseDao; +import com.ruoyi.common.core.domain.entity.test.dao.intf.ProductDao; +import org.springframework.stereotype.Repository; + +/** + * ProductDaoImpl: 数据操作接口实现 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +@Repository +public class ProductDaoImpl extends ProductBaseDao implements ProductDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductInventoryDaoImpl.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductInventoryDaoImpl.java new file mode 100644 index 00000000..f67c0737 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/impl/ProductInventoryDaoImpl.java @@ -0,0 +1,16 @@ +package com.ruoyi.common.core.domain.entity.test.dao.impl; + +import com.ruoyi.common.core.domain.entity.test.dao.base.ProductInventoryBaseDao; +import com.ruoyi.common.core.domain.entity.test.dao.intf.ProductInventoryDao; +import org.springframework.stereotype.Repository; + +/** + * ProductInventoryDaoImpl: 数据操作接口实现 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +@Repository +public class ProductInventoryDaoImpl extends ProductInventoryBaseDao implements ProductInventoryDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryDao.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryDao.java new file mode 100644 index 00000000..7c2a5c07 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryDao.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.core.domain.entity.test.dao.intf; + +import cn.org.atool.fluent.mybatis.base.IBaseDao; +import com.ruoyi.common.core.domain.entity.test.entity.ProductCategory; + +/** + * ProductCategoryDao: 数据操作接口 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +public interface ProductCategoryDao extends IBaseDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryRelationDao.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryRelationDao.java new file mode 100644 index 00000000..50633326 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductCategoryRelationDao.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.core.domain.entity.test.dao.intf; + +import cn.org.atool.fluent.mybatis.base.IBaseDao; +import com.ruoyi.common.core.domain.entity.test.entity.ProductCategoryRelation; + +/** + * ProductCategoryRelationDao: 数据操作接口 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +public interface ProductCategoryRelationDao extends IBaseDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductDao.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductDao.java new file mode 100644 index 00000000..dcf1a694 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductDao.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.core.domain.entity.test.dao.intf; + +import cn.org.atool.fluent.mybatis.base.IBaseDao; +import com.ruoyi.common.core.domain.entity.test.entity.Product; + +/** + * ProductDao: 数据操作接口 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +public interface ProductDao extends IBaseDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductInventoryDao.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductInventoryDao.java new file mode 100644 index 00000000..fce76371 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/dao/intf/ProductInventoryDao.java @@ -0,0 +1,14 @@ +package com.ruoyi.common.core.domain.entity.test.dao.intf; + +import cn.org.atool.fluent.mybatis.base.IBaseDao; +import com.ruoyi.common.core.domain.entity.test.entity.ProductInventory; + +/** + * ProductInventoryDao: 数据操作接口 + * + * 这只是一个减少手工创建的模板文件 + * 可以任意添加方法和实现, 更改作者和重定义类名 + *

@author Powered By Fluent Mybatis + */ +public interface ProductInventoryDao extends IBaseDao { +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/Product.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/Product.java new file mode 100644 index 00000000..f49a0b7c --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/Product.java @@ -0,0 +1,128 @@ +package com.ruoyi.common.core.domain.entity.test.entity; + +import cn.org.atool.fluent.mybatis.annotation.FluentMybatis; +import cn.org.atool.fluent.mybatis.annotation.RefMethod; +import cn.org.atool.fluent.mybatis.annotation.TableField; +import cn.org.atool.fluent.mybatis.annotation.TableId; +import cn.org.atool.fluent.mybatis.base.IEntity; +import cn.org.atool.fluent.mybatis.base.RichEntity; +import cn.org.atool.fluent.mybatis.functions.TableSupplier; +import java.io.Serializable; +import java.lang.Class; +import java.lang.Long; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * Product: 数据映射实体定义 + * + * @author Powered By Fluent Mybatis + */ +@SuppressWarnings({"unchecked"}) +@Data +@Accessors( + chain = true +) +@EqualsAndHashCode( + callSuper = false +) +@FluentMybatis( + table = "product", + schema = "ruoyi", + suffix = "" +) +public class Product extends RichEntity { + private static final long serialVersionUID = 1L; + + /** + * id + */ + @TableId("id") + private Long id; + + /** + * 创建时间 + */ + @TableField( + value = "create_date_time", + insert = "now()" + ) + private Date createDateTime; + + /** + * 更新时间 + */ + @TableField( + value = "update_date_time", + insert = "now()", + update = "now()" + ) + private Date updateDateTime; + + /** + * 运费 + */ + @TableField("freight") + private BigDecimal freight; + + /** + * 商品唯一编号 + */ + @TableField("product_code") + private String productCode; + + /** + * 商品名称 + */ + @TableField("product_name") + private String productName; + + /** + * 单价 + */ + @TableField("unit_price") + private BigDecimal unitPrice; + + @Override + public Serializable findPk() { + return this.id; + } + + @Override + public final Class entityClass() { + return Product.class; + } + + @Override + public final Product changeTableBelongTo(TableSupplier supplier) { + return super.changeTableBelongTo(supplier); + } + + @Override + public final Product changeTableBelongTo(String table) { + return super.changeTableBelongTo(table); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod + public List findProductCategoryList() { + return super.invoke("findProductCategoryList", true); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod("productId = id") + public List findProductInventoryList() { + return super.invoke("findProductInventoryList", true); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategory.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategory.java new file mode 100644 index 00000000..666bc84e --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategory.java @@ -0,0 +1,148 @@ +package com.ruoyi.common.core.domain.entity.test.entity; + +import cn.org.atool.fluent.mybatis.annotation.FluentMybatis; +import cn.org.atool.fluent.mybatis.annotation.RefMethod; +import cn.org.atool.fluent.mybatis.annotation.TableField; +import cn.org.atool.fluent.mybatis.annotation.TableId; +import cn.org.atool.fluent.mybatis.base.IEntity; +import cn.org.atool.fluent.mybatis.base.RichEntity; +import cn.org.atool.fluent.mybatis.functions.TableSupplier; +import java.io.Serializable; +import java.lang.Class; +import java.lang.Integer; +import java.lang.Long; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import java.util.Date; +import java.util.List; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * ProductCategory: 数据映射实体定义 + * + * @author Powered By Fluent Mybatis + */ +@SuppressWarnings({"unchecked"}) +@Data +@Accessors( + chain = true +) +@EqualsAndHashCode( + callSuper = false +) +@FluentMybatis( + table = "product_category", + schema = "ruoyi", + suffix = "" +) +public class ProductCategory extends RichEntity { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId("id") + private Long id; + + /** + * 创建时间 + */ + @TableField( + value = "create_date_time", + insert = "now()" + ) + private Date createDateTime; + + /** + * 更新时间 + */ + @TableField( + value = "update_date_time", + insert = "now()", + update = "now()" + ) + private Date updateDateTime; + + /** + * 分类名称 + */ + @TableField("category_name") + private String categoryName; + + /** + * 分类类型(Title-标题,Value-值) + */ + @TableField("category_type") + private String categoryType; + + /** + * 层级 + */ + @TableField("level_no") + private Integer levelNo; + + /** + * 父级分类主键 + */ + @TableField("parent_id") + private Long parentId; + + /** + * 排序号 + */ + @TableField("sort_num") + private Integer sortNum; + + /** + * 分类状态(Enable-启用,Disable-禁用,Delete-删除) + */ + @TableField("status_type") + private String statusType; + + @Override + public Serializable findPk() { + return this.id; + } + + @Override + public final Class entityClass() { + return ProductCategory.class; + } + + @Override + public final ProductCategory changeTableBelongTo(TableSupplier supplier) { + return super.changeTableBelongTo(supplier); + } + + @Override + public final ProductCategory changeTableBelongTo(String table) { + return super.changeTableBelongTo(table); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod + public List findProductList() { + return super.invoke("findProductList", true); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod("parentId = id") + public List findProductCategoryList() { + return super.invoke("findProductCategoryList", true); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod("id = parentId") + public ProductCategory findProductCategory() { + return super.invoke("findProductCategory", true); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategoryRelation.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategoryRelation.java new file mode 100644 index 00000000..48f3764a --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductCategoryRelation.java @@ -0,0 +1,64 @@ +package com.ruoyi.common.core.domain.entity.test.entity; + +import cn.org.atool.fluent.mybatis.annotation.FluentMybatis; +import cn.org.atool.fluent.mybatis.annotation.TableField; +import cn.org.atool.fluent.mybatis.base.IEntity; +import cn.org.atool.fluent.mybatis.base.RichEntity; +import cn.org.atool.fluent.mybatis.functions.TableSupplier; +import java.lang.Class; +import java.lang.Long; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * ProductCategoryRelation: 数据映射实体定义 + * + * @author Powered By Fluent Mybatis + */ +@SuppressWarnings({"unchecked"}) +@Data +@Accessors( + chain = true +) +@EqualsAndHashCode( + callSuper = false +) +@FluentMybatis( + table = "product_category_relation", + schema = "ruoyi", + suffix = "" +) +public class ProductCategoryRelation extends RichEntity { + private static final long serialVersionUID = 1L; + + /** + * 商品分类主键 + */ + @TableField("product_category_id") + private Long productCategoryId; + + /** + * 商品主键 + */ + @TableField("product_id") + private Long productId; + + @Override + public final Class entityClass() { + return ProductCategoryRelation.class; + } + + @Override + public final ProductCategoryRelation changeTableBelongTo(TableSupplier supplier) { + return super.changeTableBelongTo(supplier); + } + + @Override + public final ProductCategoryRelation changeTableBelongTo(String table) { + return super.changeTableBelongTo(table); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductInventory.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductInventory.java new file mode 100644 index 00000000..315bf5e6 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/entity/ProductInventory.java @@ -0,0 +1,105 @@ +package com.ruoyi.common.core.domain.entity.test.entity; + +import cn.org.atool.fluent.mybatis.annotation.FluentMybatis; +import cn.org.atool.fluent.mybatis.annotation.RefMethod; +import cn.org.atool.fluent.mybatis.annotation.TableField; +import cn.org.atool.fluent.mybatis.annotation.TableId; +import cn.org.atool.fluent.mybatis.annotation.Version; +import cn.org.atool.fluent.mybatis.base.IEntity; +import cn.org.atool.fluent.mybatis.base.RichEntity; +import cn.org.atool.fluent.mybatis.functions.TableSupplier; +import java.io.Serializable; +import java.lang.Class; +import java.lang.Integer; +import java.lang.Long; +import java.lang.Override; +import java.lang.String; +import java.lang.SuppressWarnings; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * ProductInventory: 数据映射实体定义 + * + * @author Powered By Fluent Mybatis + */ +@SuppressWarnings({"unchecked"}) +@Data +@Accessors( + chain = true +) +@EqualsAndHashCode( + callSuper = false +) +@FluentMybatis( + table = "product_inventory", + schema = "ruoyi", + suffix = "" +) +public class ProductInventory extends RichEntity { + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId("id") + private Long id; + + /** + * 库存数量 + */ + @TableField("inventory_quantity") + private Integer inventoryQuantity; + + /** + * 乐观锁 + */ + @TableField( + value = "lock_version", + insert = "0", + update = "`lock_version` + 1" + ) + @Version + private Long lockVersion; + + /** + * 商品主键 + */ + @TableField("product_id") + private Long productId; + + /** + * 库存状态(Enable-在售,Disable-停售,Delete-删除) + */ + @TableField("status_type") + private String statusType; + + @Override + public Serializable findPk() { + return this.id; + } + + @Override + public final Class entityClass() { + return ProductInventory.class; + } + + @Override + public final ProductInventory changeTableBelongTo(TableSupplier supplier) { + return super.changeTableBelongTo(supplier); + } + + @Override + public final ProductInventory changeTableBelongTo(String table) { + return super.changeTableBelongTo(table); + } + + /** + * 实现定义在{@link cn.org.atool.fluent.mybatis.base.IRefs}子类Refs上 + */ + @RefMethod("id = productId") + public Product findProduct() { + return super.invoke("findProduct", true); + } +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/relation/ProductCategoryRelationEntity.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/relation/ProductCategoryRelationEntity.java new file mode 100644 index 00000000..8e36aa4d --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/test/relation/ProductCategoryRelationEntity.java @@ -0,0 +1,50 @@ +package com.ruoyi.common.core.domain.entity.test.relation; + +import cn.org.atool.fluent.mybatis.refs.IEntityRelation; +import com.ruoyi.common.core.domain.entity.test.entity.Product; +import com.ruoyi.common.core.domain.entity.test.entity.ProductCategory; +import com.ruoyi.common.core.domain.entity.test.wrapper.ProductCategoryQuery; +import com.ruoyi.common.core.domain.entity.test.wrapper.ProductCategoryRelationQuery; +import com.ruoyi.common.core.domain.entity.test.wrapper.ProductQuery; + +import java.util.List; + +/** + * 商品与分类关联关系实现 + * @author Geniou + * @create 2021/9/13 19:08 + */ +public class ProductCategoryRelationEntity implements IEntityRelation { + + /** + * {@link Product#findProductCategoryList} + * @param entity + */ + @Override + public List findProductCategoryListOfProduct(Product entity) { + return ProductCategoryQuery.defaultQuery() + .where.id().in( + ProductCategoryRelationQuery.defaultQuery() + .select.productCategoryId().end() + .where.productId().eq(entity.getId()) + .end() + ).end() + .to().listEntity(); + } + + /** + * {@link ProductCategory#findProductList} + * @param entity + */ + @Override + public List findProductListOfProductCategory(ProductCategory entity) { + return ProductQuery.defaultQuery() + .where.id().in( + ProductCategoryRelationQuery.defaultQuery() + .select.productId().end() + .where.productCategoryId().eq(entity.getId()) + .end() + ).end() + .to().listEntity(); + } +} diff --git a/ruoyi-common/src/test/java/com/ruoyi/common/GeneratorTest.java b/ruoyi-common/src/test/java/com/ruoyi/common/GeneratorTest.java new file mode 100644 index 00000000..d7d18ca8 --- /dev/null +++ b/ruoyi-common/src/test/java/com/ruoyi/common/GeneratorTest.java @@ -0,0 +1,46 @@ +package com.ruoyi.common; + +import cn.org.atool.generator.FileGenerator; +import cn.org.atool.generator.annotation.Relation; +import cn.org.atool.generator.annotation.RelationType; +import cn.org.atool.generator.annotation.Table; +import cn.org.atool.generator.annotation.Tables; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; + +/** + * 代码生成测试 + * @author Geniou + * @create 2021/9/9 12:17 + */ +@Slf4j +public class GeneratorTest { + + static final String url = + "jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true"; + static final String basePackage = "com.ruoyi.common.core.domain.entity.test"; + + @Test + void contextLoads() { + FileGenerator.build(RelationMTM.class); + } + + @Tables( + url = url, username = "root", password = "123456", + basePack = basePackage, + srcDir = "src\\main\\java\\", + tables = {@Table(value = {"product", "product_category", "product_category_relation"}), + @Table(value = {"product_inventory"}, version = "lock_version")}, + gmtCreated = "create_date_time", gmtModified = "update_date_time", + relations = { + @Relation(source = "product", target = "product_category", type = RelationType.TwoWay_N_N), + @Relation(source = "product_category", target = "product_category", type = RelationType.TwoWay_1_N, + where = "id = parent_id"), + @Relation(source = "product", target = "product_inventory", type = RelationType.TwoWay_1_N, + where = "id = product_id") + }, + entitySuffix = "" + ) + static class RelationMTM{} + +} diff --git a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ProductTestController.java b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ProductTestController.java index e005fcfc..2402c1aa 100644 --- a/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ProductTestController.java +++ b/ruoyi-demo/src/main/java/com/ruoyi/demo/controller/ProductTestController.java @@ -1,18 +1,39 @@ package com.ruoyi.demo.controller; -import com.ruoyi.common.core.domain.entity.mapper.ProductMapper; -import com.ruoyi.common.core.domain.entity.test.Product; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.RandomUtil; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import cn.org.atool.fluent.mybatis.base.model.FieldType; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.test.entity.Product; +import com.ruoyi.common.core.domain.entity.test.entity.ProductCategory; +import com.ruoyi.common.core.domain.entity.test.entity.ProductCategoryRelation; +import com.ruoyi.common.core.domain.entity.test.helper.ProductCategoryRelationWrapperHelper; +import com.ruoyi.common.core.domain.entity.test.helper.ProductWrapperHelper; +import com.ruoyi.common.core.domain.entity.test.mapper.ProductCategoryMapper; +import com.ruoyi.common.core.domain.entity.test.mapper.ProductCategoryRelationMapper; +import com.ruoyi.common.core.domain.entity.test.mapper.ProductMapper; +import com.ruoyi.common.core.domain.entity.test.wrapper.ProductCategoryRelationQuery; +import com.ruoyi.common.core.domain.entity.test.wrapper.ProductQuery; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Date; +import java.util.List; /** * 商品测试控制 @@ -23,26 +44,225 @@ import java.util.Date; @Api(value = "商品测试控制方法", tags = {"商品测试控制方法"}) @RestController @RequestMapping("/demo/product") -public class ProductTestController { +public class ProductTestController extends BaseController { @Autowired private ProductMapper productMapper; + @Autowired + private ProductCategoryMapper productCategoryMapper; + @Autowired + private ProductCategoryRelationMapper productCategoryRelationMapper; + /** - * 查询测试树表列表 + * 测试插入 */ - @ApiOperation("测试语句") - @GetMapping("/mapperTest") - public void list() { + @ApiOperation("测试插入商品") + @PostMapping("/insertProduct") + public AjaxResult insertProduct() { Product product = new Product(); - product.setProductCode("M10001"); - product.setProductName("测试商品"); - product.setUnitPrice(BigDecimal.valueOf(2.5)); - product.setFreight(BigDecimal.valueOf(1.5)); - product.setCreateDateTime(new Date()); - product.setUpdateDateTime(new Date()); + + String productCode = "P" + RandomUtil.randomNumbers(12); + product.setProductCode(productCode); + product.setProductName("海口一年级语文"); + product.setUnitPrice(BigDecimal.valueOf(12.5)); + product.setFreight(BigDecimal.valueOf(8)); productMapper.insert(product); + List ids = new ArrayList<>(); + ids.add(7l); + ids.add(22l); + ids.add(29l); + // 查出所有需要关联的商品分类 + List categoryList = productCategoryMapper.listByIds(ids); + + Long productId = product.getId(); + + // 遍历商品分类集合,每次创建一条商品与分类关联关系的实体 + List relations = new ArrayList<>(); + for (ProductCategory productCategory : categoryList) { + ProductCategoryRelation relation = new ProductCategoryRelation(); + relation.setProductId(productId); + relation.setProductCategoryId(productCategory.getId()); + relations.add(relation); + } + // 保存中间表 + productCategoryRelationMapper.insertBatch(relations); + return AjaxResult.success(productId); + } + + /** + * 测试插入 + */ + @ApiOperation("测试插入商品库存") + @PostMapping("/insertProductInventory") + public void insertProductInventory() { + } + @ApiOperation("测试插入商品分类") + @PostMapping("/insertProductCategory") + public AjaxResult insertProductCategory() { + List categories = new ArrayList<>(); + + ProductCategory productCategory = new ProductCategory(); + productCategory.setCategoryName("适用阶段"); + productCategory.setCategoryType("Title"); + productCategory.setLevelNo(1); + productCategory.setSortNum(1); + categories.add(productCategory); + + ProductCategory productCategory1 = new ProductCategory(); + productCategory1.setCategoryName("适用区域"); + productCategory1.setCategoryType("Title"); + productCategory1.setLevelNo(1); + productCategory1.setSortNum(2); + categories.add(productCategory1); + + ProductCategory productCategory2 = new ProductCategory(); + productCategory2.setCategoryName("教辅类型"); + productCategory2.setCategoryType("Title"); + productCategory2.setLevelNo(1); + productCategory2.setSortNum(3); + categories.add(productCategory2); + + return toAjax(productCategoryMapper.insertBatch(categories)); + } + + @ApiOperation("测试插入商品分类(根据父级)") + @PostMapping("/insertProductCategoryByParent") + public AjaxResult insertProductCategoryByParent(@Validated ProductCategory productCategory) { + return toAjax(productCategoryMapper.insert(productCategory)); + } + + @ApiOperation("根据分类查询") + @GetMapping("/queryByCategory") + public AjaxResult queryByCategory(@Validated String categoryIdsString) { + String[] categoryIds = categoryIdsString.split(","); + + ProductQuery productQuery = productMapper.query(); + ProductWrapperHelper.QueryWhere queryWhere = productQuery.where; + + for (String categoryId : categoryIds) { + queryWhere.exists(productCategoryRelationMapper.query().where.productId().apply("= product.id").productCategoryId() + .eq(Long.parseLong(categoryId)).end()); + } + + List products = productMapper.listEntity(queryWhere.end()); + return AjaxResult.success(JSONUtil.parseArray(products)); + } + + @ApiOperation("查询商品所属分类") + @GetMapping("/queryProductBelongCategory") + public AjaxResult queryProductBelongCategory(@Validated Long productId) { + Product product = productMapper.findById(productId); + List productCategoryList = product.findProductCategoryList(); + return AjaxResult.success(JSONUtil.parseArray(productCategoryList)); + } + + @ApiOperation("查询分类树") + @GetMapping("/queryCategoryTree") + public AjaxResult queryCategoryTree(@Validated Long productCategoryId) { + ProductCategory productCategory = productCategoryMapper.findById(productCategoryId); + JSONObject respBody = buildCategory(productCategory); + return AjaxResult.success(respBody); + } + + private JSONObject buildCategory(ProductCategory productCategory) { + JSONObject categoryJSON = new JSONObject(); + Long id = productCategory.getId(); + Integer levelNo = productCategory.getLevelNo(); + Long parentId = productCategory.getParentId(); + String categoryName = productCategory.getCategoryName(); + String categoryType = productCategory.getCategoryType(); + + categoryJSON.set("id", id); + categoryJSON.set("parentId", parentId); + categoryJSON.set("levelNo", levelNo); + categoryJSON.set("categoryName", categoryName); + categoryJSON.set("categoryType", categoryType); + + List childList = productCategory.findProductCategoryList(); + + if (CollUtil.isNotEmpty(childList)) { + JSONArray childArray = new JSONArray(); + + for (ProductCategory childCategory : childList) { + JSONObject childJSON = buildCategory(childCategory); + childArray.add(childJSON); + } + categoryJSON.set("child", childArray); + } + + return categoryJSON; + } + + /** + * 测试查询 + */ + @ApiOperation("测试查询") + @GetMapping("/queryTest") + public AjaxResult query(@Validated Product bo) { + Product product = productMapper.findById(bo.getId()); + return new AjaxResult().setData(product); + } + + /** + * 测试查询2(根据实体类字段) + */ + @ApiOperation("测试查询2") + @GetMapping("/query2Test") + public AjaxResult> query2(@Validated Product bo) { + ProductQuery productQuery = productMapper.query().where.eqByEntity(bo).end(); + List products = productMapper.listEntity(productQuery); + log.info("query2 rows = {}", CollUtil.size(products)); + return new AjaxResult>().setData(products); + } + + /** + * 测试删除 + */ + @ApiOperation("测试删除") + @DeleteMapping("/deleteTest") + public AjaxResult delete(@Validated Product bo) { + return toAjax(productMapper.deleteById(bo.getId())); + } + + /** + * 测试删除2 + */ + @ApiOperation("测试删除2(根据相关参数)") + @DeleteMapping("/delete2Test") + public AjaxResult delete2(@Validated Product bo) { + ProductQuery productQuery = productMapper.query().where.eqByEntity(bo).end(); + int row = productMapper.delete(productQuery); + return toAjax(row); + } + + // + // static final String url = + // "jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull + // &useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true"; + // static final String basePackage = "com.ruoyi.common.core.domain.entity.test"; + + // /** + // * 测试删除2 + // */ + // @ApiOperation("生成测试") + // @DeleteMapping("/generatorTest") + // public AjaxResult generatorTest() { + // FileGenerator.build(Noting.class); + // return toAjax(true); + // } + // + // @Tables( + // url = url, username = "root", password = "123456", + // basePack = basePackage, + // srcDir = "src/main/java/com/ruoyi/common/core/domain/entity/test", + // tables = @Table(value = {"product_category", "product", "product_category_relation"}) + // ) + // static class Noting{} + + + } diff --git a/ruoyi-mall/pom.xml b/ruoyi-mall/pom.xml new file mode 100644 index 00000000..a7d44008 --- /dev/null +++ b/ruoyi-mall/pom.xml @@ -0,0 +1,14 @@ + + + + ruoyi-vue-plus + com.ruoyi + 3.0.0 + + 4.0.0 + + ruoyi-mall + + \ No newline at end of file