Commit 6b1d996b6633364f0fc7f6eef0f2bed825f5ce90
1 parent
b0fcd96d
页面装修数据结构定义
Showing
18 changed files
with
607 additions
and
0 deletions
sql/mysql/optional/mall.sql
| @@ -447,6 +447,25 @@ CREATE TABLE `trade_delivery_express` ( | @@ -447,6 +447,25 @@ CREATE TABLE `trade_delivery_express` ( | ||
| 447 | PRIMARY KEY (`id`) USING BTREE | 447 | PRIMARY KEY (`id`) USING BTREE |
| 448 | ) ENGINE=InnoDB COMMENT='快递公司'; | 448 | ) ENGINE=InnoDB COMMENT='快递公司'; |
| 449 | 449 | ||
| 450 | +-- ---------------------------- | ||
| 451 | +-- 页面装修表结构 | ||
| 452 | +-- ---------------------------- | ||
| 453 | +DROP TABLE IF EXISTS `promotion_page_decorate`; | ||
| 454 | +CREATE TABLE `promotion_page_decorate` ( | ||
| 455 | + `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', | ||
| 456 | + `type` int NOT NULL COMMENT '页面类型', | ||
| 457 | + `component_code` varchar(64) NOT NULL COMMENT '组件编码', | ||
| 458 | + `component_value` json NOT NULL COMMENT '组件值:json 格式。包含配置和数据', | ||
| 459 | + `status` tinyint NOT NULL DEFAULT 0 COMMENT '状态', | ||
| 460 | + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | ||
| 461 | + `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 462 | + `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', | ||
| 463 | + `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 464 | + `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 465 | + `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', | ||
| 466 | + PRIMARY KEY (`id`) USING BTREE | ||
| 467 | +) ENGINE=InnoDB COMMENT='页面装修'; | ||
| 468 | + | ||
| 450 | SET FOREIGN_KEY_CHECKS = 1; | 469 | SET FOREIGN_KEY_CHECKS = 1; |
| 451 | 470 | ||
| 452 | BEGIN; | 471 | BEGIN; |
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java
| @@ -14,6 +14,7 @@ import lombok.experimental.UtilityClass; | @@ -14,6 +14,7 @@ import lombok.experimental.UtilityClass; | ||
| 14 | import lombok.extern.slf4j.Slf4j; | 14 | import lombok.extern.slf4j.Slf4j; |
| 15 | 15 | ||
| 16 | import java.io.IOException; | 16 | import java.io.IOException; |
| 17 | +import java.lang.reflect.Type; | ||
| 17 | import java.util.ArrayList; | 18 | import java.util.ArrayList; |
| 18 | import java.util.List; | 19 | import java.util.List; |
| 19 | 20 | ||
| @@ -72,6 +73,18 @@ public class JsonUtils { | @@ -72,6 +73,18 @@ public class JsonUtils { | ||
| 72 | } | 73 | } |
| 73 | } | 74 | } |
| 74 | 75 | ||
| 76 | + public static <T> T parseObject(String text, Type type) { | ||
| 77 | + if (StrUtil.isEmpty(text)) { | ||
| 78 | + return null; | ||
| 79 | + } | ||
| 80 | + try { | ||
| 81 | + return objectMapper.readValue(text, objectMapper.getTypeFactory().constructType(type)); | ||
| 82 | + } catch (IOException e) { | ||
| 83 | + log.error("json parse err,json:{}", text, e); | ||
| 84 | + throw new RuntimeException(e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + | ||
| 75 | /** | 88 | /** |
| 76 | * 将字符串解析成指定类型的对象 | 89 | * 将字符串解析成指定类型的对象 |
| 77 | * 使用 {@link #parseObject(String, Class)} 时,在@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) 的场景下, | 90 | * 使用 {@link #parseObject(String, Class)} 时,在@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS) 的场景下, |
yudao-module-mall/yudao-module-promotion-api/pom.xml
| @@ -28,6 +28,13 @@ | @@ -28,6 +28,13 @@ | ||
| 28 | <artifactId>spring-boot-starter-validation</artifactId> | 28 | <artifactId>spring-boot-starter-validation</artifactId> |
| 29 | <optional>true</optional> | 29 | <optional>true</optional> |
| 30 | </dependency> | 30 | </dependency> |
| 31 | + | ||
| 32 | + <!-- 工具类中使用了 --> | ||
| 33 | + <dependency> | ||
| 34 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
| 35 | + <artifactId>jackson-databind</artifactId> | ||
| 36 | + <optional>true</optional> | ||
| 37 | + </dependency> | ||
| 31 | </dependencies> | 38 | </dependencies> |
| 32 | 39 | ||
| 33 | </project> | 40 | </project> |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/CommonStyle.java
0 → 100644
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/NavMenuComponent.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.decorate.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 导航菜单组件的内容配置,数据结构 定义 | ||
| 7 | + * 不知道放哪里比较好 // TODO @芋艿 貌似放 api 这里不太合适。有什么建议没有? | ||
| 8 | + * | ||
| 9 | + * @author jason | ||
| 10 | + */ | ||
| 11 | +@Data | ||
| 12 | +public class NavMenuComponent { | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 导航菜单组件对内容的配置项 | ||
| 16 | + */ | ||
| 17 | + @Data | ||
| 18 | + public static class Config { | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 是否启用 | ||
| 22 | + */ | ||
| 23 | + private Boolean enabled; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 导航菜单组件的数据结构 | ||
| 28 | + */ | ||
| 29 | + @Data | ||
| 30 | + public static class DataStructure { | ||
| 31 | + /** | ||
| 32 | + * 显示名称 | ||
| 33 | + */ | ||
| 34 | + private String name; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 显示图片 | ||
| 38 | + */ | ||
| 39 | + private String img; | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 连接路径 | ||
| 43 | + */ | ||
| 44 | + private String path; | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 状态, 是否显示 | ||
| 48 | + */ | ||
| 49 | + private Integer status; | ||
| 50 | + | ||
| 51 | + } | ||
| 52 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/PageComponentDTO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.decorate.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 页面组件通用模板结构 DTO | ||
| 7 | + * 每个组件都有自己对应的内容配置, 样式配置, 具体数据,和其他组件不同的。但这个三个配置是必须的, 所以定义通用的模板结构 | ||
| 8 | + * 内容配置, 样式配置, 具体数据的结构 需要每个组件单独定义。 | ||
| 9 | + * 1. 内容配置 (不包括具体的内容) 例如是否启用,是否显示, 商品分类页的排版方式等 | ||
| 10 | + * 2. 样式设置,对应 crmeb php 版组件的样式配置。 暂时可能用不。 所以使用通用 CommonStyleDTO,后续可能用上 | ||
| 11 | + * 3. 具体数据, 有些组件(导航菜单组件)数据是通过装修配置, 需要定制数据。有些组件(如商品分类),数据从接口获取,不需要该项 | ||
| 12 | + * | ||
| 13 | + * @author jason | ||
| 14 | + */ | ||
| 15 | +@Data | ||
| 16 | +public class PageComponentDTO<Config, Style, Content> { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 组件标题, 每个组件都有的 | ||
| 20 | + */ | ||
| 21 | + private String title; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 组件的内容配置项 | ||
| 25 | + */ | ||
| 26 | + private Config config; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 组件的样式配置 | ||
| 30 | + */ | ||
| 31 | + private Style style; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 组件的具体数据 | ||
| 35 | + * | ||
| 36 | + */ | ||
| 37 | + private Content data; | ||
| 38 | + | ||
| 39 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/ProductCategoryComponent.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.decorate.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 商品分类组件的内容配置, 无数据结构定义。数据从接口获取 | ||
| 7 | + * | ||
| 8 | + * @author jason | ||
| 9 | + */ | ||
| 10 | +public class ProductCategoryComponent { | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * 商品分类组件组件的内容配置项 | ||
| 14 | + */ | ||
| 15 | + @Data | ||
| 16 | + public static class Config { | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 页面风格类型 | ||
| 20 | + */ | ||
| 21 | + private Integer layoutStyle; | ||
| 22 | + | ||
| 23 | + // TODO 其它 | ||
| 24 | + } | ||
| 25 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/RollingBannerComponent.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.api.decorate.dto; | ||
| 2 | + | ||
| 3 | +import lombok.Data; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 滚动横幅广告组件的内容配置,数据结构定义 | ||
| 7 | + * | ||
| 8 | + * @author jason | ||
| 9 | + */ | ||
| 10 | +public class RollingBannerComponent { | ||
| 11 | + /** | ||
| 12 | + * 滚动横幅广告组件的内容配置项 | ||
| 13 | + */ | ||
| 14 | + @Data | ||
| 15 | + public static class Config { | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 是否启用 | ||
| 19 | + */ | ||
| 20 | + private Boolean enabled; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 导航菜单组件的数据结构 | ||
| 25 | + */ | ||
| 26 | + @Data | ||
| 27 | + public static class DataStructure { | ||
| 28 | + /** | ||
| 29 | + * 显示图片 | ||
| 30 | + */ | ||
| 31 | + private String img; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 连接路径 | ||
| 35 | + */ | ||
| 36 | + private String path; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 状态, 是否显示 | ||
| 40 | + */ | ||
| 41 | + private Integer status; | ||
| 42 | + } | ||
| 43 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageTypeEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.enums.decorate; | ||
| 2 | + | ||
| 3 | +import lombok.AllArgsConstructor; | ||
| 4 | +import lombok.Getter; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 装修页面枚举 | ||
| 8 | + * | ||
| 9 | + * @author jason | ||
| 10 | + */ | ||
| 11 | +@AllArgsConstructor | ||
| 12 | +@Getter | ||
| 13 | +public enum DecoratePageTypeEnum { | ||
| 14 | + INDEX(1, "首页"); | ||
| 15 | + | ||
| 16 | + private final Integer type; | ||
| 17 | + /** | ||
| 18 | + * 名字 | ||
| 19 | + */ | ||
| 20 | + private final String name; | ||
| 21 | +} |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/PageComponentEnum.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.enums.decorate; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.lang.TypeReference; | ||
| 4 | +import cn.hutool.core.util.ArrayUtil; | ||
| 5 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.api.decorate.dto.*; | ||
| 7 | +import lombok.Getter; | ||
| 8 | + | ||
| 9 | +import java.lang.reflect.Type; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 页面组件枚举 | ||
| 14 | + * | ||
| 15 | + * @author jason | ||
| 16 | + */ | ||
| 17 | +@Getter | ||
| 18 | +public enum PageComponentEnum { | ||
| 19 | + NAV_MENU("nav-menu", "导航菜单", | ||
| 20 | + new TypeReference<PageComponentDTO<NavMenuComponent.Config, CommonStyle, List<NavMenuComponent.DataStructure>>>() {}.getType()), | ||
| 21 | + ROLLING_BANNER("rolling-banner", "滚动横幅广告", | ||
| 22 | + new TypeReference<PageComponentDTO<RollingBannerComponent.Config, CommonStyle, List<RollingBannerComponent.DataStructure>>>() {}.getType()), | ||
| 23 | + PRODUCT_CATEGORY("product-category", "商品分类", | ||
| 24 | + new TypeReference<PageComponentDTO<ProductCategoryComponent.Config, CommonStyle, Object>>() {}.getType()); // data 会为null 用 object 代替 | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 页面组件代码 | ||
| 28 | + */ | ||
| 29 | + private final String code; | ||
| 30 | + | ||
| 31 | + /** | ||
| 32 | + * 页面组件说明 | ||
| 33 | + */ | ||
| 34 | + private final String desc; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 具体组件的类型 | ||
| 38 | + */ | ||
| 39 | + private final Type componentType; | ||
| 40 | + | ||
| 41 | + PageComponentEnum(String code, String desc, Type componentType) { | ||
| 42 | + this.code = code; | ||
| 43 | + this.desc = desc; | ||
| 44 | + this.componentType = componentType; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static PageComponentEnum getOfCode(String code) { | ||
| 48 | + return ArrayUtil.firstMatch(component -> component.getCode().equals(code), PageComponentEnum.values()); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public <C, S, D> PageComponentDTO<C, S, D> parsePageComponent(String text) { | ||
| 52 | + return JsonUtils.parseObject(text, componentType); | ||
| 53 | + } | ||
| 54 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecoratePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import javax.validation.Valid; | ||
| 7 | +import javax.validation.constraints.NotEmpty; | ||
| 8 | +import javax.validation.constraints.NotNull; | ||
| 9 | +import java.util.List; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * @author jason | ||
| 13 | + */ | ||
| 14 | +@Schema(description = "管理后台 - 页面装,整个页面 Request VO ") | ||
| 15 | +@Data | ||
| 16 | +public class DecoratePageReqVO { | ||
| 17 | + @Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 18 | + @NotNull(message = "页面类型不能为空") | ||
| 19 | + private Integer type; | ||
| 20 | + @Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") | ||
| 21 | + @NotEmpty(message = "页面组件列表不能为空") | ||
| 22 | + @Valid | ||
| 23 | + private List<ComponentReqVO> components; | ||
| 24 | + | ||
| 25 | + @Schema(description = "管理后台 - 页面组件 Request VO, 后面是不是可以做分组件保存?? ") | ||
| 26 | + @Data | ||
| 27 | + public static class ComponentReqVO { | ||
| 28 | + | ||
| 29 | + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") | ||
| 30 | + @NotEmpty(message = "组件编码不能为空") | ||
| 31 | + private String componentCode; | ||
| 32 | + | ||
| 33 | + @Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") | ||
| 34 | + @NotEmpty(message = "组件值为空") | ||
| 35 | + private String value; | ||
| 36 | + } | ||
| 37 | + | ||
| 38 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecoratePageRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | + | ||
| 6 | +import java.util.List; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * @author jason | ||
| 10 | + */ | ||
| 11 | +@Schema(description = "管理后台 - 页面装修 Resp VO") | ||
| 12 | +@Data | ||
| 13 | +public class DecoratePageRespVO { | ||
| 14 | + @Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 15 | + private Integer type; | ||
| 16 | + @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") | ||
| 17 | + private List<ComponentRespVO> components; | ||
| 18 | + | ||
| 19 | + @Schema(description = "管理后台 - 页面组件 Resp VO") | ||
| 20 | + @Data | ||
| 21 | + public static class ComponentRespVO { | ||
| 22 | + @Schema(description = "组件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "首页广告") | ||
| 23 | + private String title; | ||
| 24 | + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") | ||
| 25 | + private String componentCode; | ||
| 26 | + @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") | ||
| 27 | + private Object config; | ||
| 28 | + @Schema(description = "组件的样式配置", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") | ||
| 29 | + private Object style; | ||
| 30 | + @Schema(description = "组件的具体数据", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") | ||
| 31 | + private Object data; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecoratePageConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.convert.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.api.decorate.dto.PageComponentDTO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageReqVO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageRespVO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.enums.decorate.PageComponentEnum; | ||
| 9 | +import org.mapstruct.Mapper; | ||
| 10 | +import org.mapstruct.factory.Mappers; | ||
| 11 | + | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +@Mapper | ||
| 15 | +public interface DecoratePageConvert { | ||
| 16 | + | ||
| 17 | + DecoratePageConvert INSTANCE = Mappers.getMapper(DecoratePageConvert.class); | ||
| 18 | + | ||
| 19 | + default List<PageDecorateDO> convert(Integer type, List<DecoratePageReqVO.ComponentReqVO> components) { | ||
| 20 | + return CollectionUtils.convertList(components, c -> { | ||
| 21 | + PageComponentEnum component = PageComponentEnum.getOfCode(c.getComponentCode()); | ||
| 22 | + if (component == null) { | ||
| 23 | + return null; | ||
| 24 | + } | ||
| 25 | + return new PageDecorateDO().setComponentCode(c.getComponentCode()) | ||
| 26 | + .setType(type).setComponentValue(c.getValue()); | ||
| 27 | + }); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + default DecoratePageRespVO convert2(Integer type, List<PageDecorateDO> doList) { | ||
| 31 | + List<DecoratePageRespVO.ComponentRespVO> components = CollectionUtils.convertList(doList, | ||
| 32 | + item -> { | ||
| 33 | + PageComponentEnum component = PageComponentEnum.getOfCode(item.getComponentCode()); | ||
| 34 | + if (component == null) { | ||
| 35 | + return null; | ||
| 36 | + } | ||
| 37 | + @SuppressWarnings("rawtypes") | ||
| 38 | + PageComponentDTO dto = component.parsePageComponent(item.getComponentValue()); | ||
| 39 | + return new DecoratePageRespVO.ComponentRespVO() | ||
| 40 | + .setTitle(dto.getTitle()).setStyle(dto.getStyle()).setComponentCode(item.getComponentCode()) | ||
| 41 | + .setConfig(dto.getConfig()).setData(dto.getData()); | ||
| 42 | + }); | ||
| 43 | + return new DecoratePageRespVO().setType(type).setComponents(components); | ||
| 44 | + } | ||
| 45 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/PageDecorateDO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.dataobject.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.enums.decorate.PageComponentEnum; | ||
| 7 | +import com.baomidou.mybatisplus.annotation.*; | ||
| 8 | + | ||
| 9 | +import lombok.Data; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 页面装修 DO | ||
| 13 | + * | ||
| 14 | + * @author jason | ||
| 15 | + */ | ||
| 16 | +@TableName(value ="promotion_page_decorate") | ||
| 17 | +@KeySequence("promotion_page_decorate_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 18 | +@Data | ||
| 19 | +public class PageDecorateDO extends BaseDO { | ||
| 20 | + /** | ||
| 21 | + * 编号 | ||
| 22 | + */ | ||
| 23 | + @TableId | ||
| 24 | + private Long id; | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * 页面类型 | ||
| 28 | + * 枚举 {@link DecoratePageTypeEnum#getType()} | ||
| 29 | + */ | ||
| 30 | + private Integer type; | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 组件编码 | ||
| 34 | + * 枚举 {@link PageComponentEnum#getCode()} | ||
| 35 | + */ | ||
| 36 | + private String componentCode; | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 组件值:json 格式。包含配置和数据 | ||
| 40 | + */ | ||
| 41 | + private String componentValue; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 状态 | ||
| 45 | + * 枚举 {@link CommonStatusEnum} | ||
| 46 | + */ | ||
| 47 | + private Integer status; | ||
| 48 | +} | ||
| 0 | \ No newline at end of file | 49 | \ No newline at end of file |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/PageDecorateMapper.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.dal.mysql.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | ||
| 4 | +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 5 | +import org.apache.ibatis.annotations.Mapper; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +@Mapper | ||
| 10 | +public interface PageDecorateMapper extends BaseMapperX<PageDecorateDO> { | ||
| 11 | + default List<PageDecorateDO> selectByPageType(Integer type){ | ||
| 12 | + return selectList(PageDecorateDO::getType, type); | ||
| 13 | + } | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecoratePageService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageReqVO; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | ||
| 6 | + | ||
| 7 | +import java.util.List; | ||
| 8 | + | ||
| 9 | +/** | ||
| 10 | + * 页面装修 Service 接口 | ||
| 11 | + * | ||
| 12 | + * @author jason | ||
| 13 | + */ | ||
| 14 | +public interface DecoratePageService { | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * 测试请求 | ||
| 18 | + */ | ||
| 19 | + List<PageDecorateDO> testReq(DecoratePageReqVO reqVO); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 测试响应 | ||
| 23 | + * @param type 页面类型 | ||
| 24 | + */ | ||
| 25 | + DecoratePageRespVO testResp(Integer type); | ||
| 26 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecoratePageServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageReqVO; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.PageDecorateMapper; | ||
| 7 | +import org.springframework.stereotype.Service; | ||
| 8 | + | ||
| 9 | +import javax.annotation.Resource; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +import static cn.iocoder.yudao.module.promotion.convert.decorate.DecoratePageConvert.INSTANCE; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * @author jason | ||
| 16 | + */ | ||
| 17 | +@Service | ||
| 18 | +public class DecoratePageServiceImpl implements DecoratePageService { | ||
| 19 | + @Resource | ||
| 20 | + private PageDecorateMapper pageDecorateMapper; | ||
| 21 | + @Override | ||
| 22 | + public List<PageDecorateDO> testReq(DecoratePageReqVO reqVO) { | ||
| 23 | + return INSTANCE.convert(reqVO.getType(), reqVO.getComponents()); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public DecoratePageRespVO testResp(Integer type) { | ||
| 28 | + return INSTANCE.convert2(type,pageDecorateMapper.selectByPageType(type)); | ||
| 29 | + } | ||
| 30 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecoratePageServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.api.decorate.dto.CommonStyle; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.api.decorate.dto.PageComponentDTO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.api.decorate.dto.RollingBannerComponent; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageReqVO; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecoratePageRespVO; | ||
| 10 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | ||
| 11 | +import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.PageDecorateMapper; | ||
| 12 | +import org.junit.jupiter.api.BeforeEach; | ||
| 13 | +import org.junit.jupiter.api.Test; | ||
| 14 | +import org.mockito.InjectMocks; | ||
| 15 | +import org.mockito.Mock; | ||
| 16 | +import org.mockito.Mockito; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import static cn.iocoder.yudao.framework.common.enums.CommonStatusEnum.ENABLE; | ||
| 22 | +import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum.INDEX; | ||
| 23 | +import static cn.iocoder.yudao.module.promotion.enums.decorate.PageComponentEnum.ROLLING_BANNER; | ||
| 24 | +import static org.assertj.core.api.Assertions.assertThat; | ||
| 25 | +import static org.mockito.ArgumentMatchers.eq; | ||
| 26 | + | ||
| 27 | +/** | ||
| 28 | + * @author jason | ||
| 29 | + */ | ||
| 30 | +public class DecoratePageServiceImplTest extends BaseMockitoUnitTest { | ||
| 31 | + | ||
| 32 | + @InjectMocks | ||
| 33 | + private DecoratePageServiceImpl decoratePageService; | ||
| 34 | + | ||
| 35 | + @Mock | ||
| 36 | + private PageDecorateMapper pageDecorateMapper; | ||
| 37 | + | ||
| 38 | + private PageComponentDTO<RollingBannerComponent.Config, | ||
| 39 | + CommonStyle, | ||
| 40 | + List<RollingBannerComponent.DataStructure>> bannerComponent; | ||
| 41 | + @BeforeEach | ||
| 42 | + public void init(){ | ||
| 43 | + CommonStyle commonStyle = new CommonStyle(); | ||
| 44 | + RollingBannerComponent.DataStructure banner1 = new RollingBannerComponent.DataStructure().setImg("http://127.0.0.1:8084/a.jpg") | ||
| 45 | + .setPath("/pages/coupon_center/coupon_center") | ||
| 46 | + .setStatus(ENABLE.getStatus()); | ||
| 47 | + List<RollingBannerComponent.DataStructure> banners = new ArrayList<>(1); | ||
| 48 | + banners.add(banner1); | ||
| 49 | + bannerComponent | ||
| 50 | + = new PageComponentDTO<RollingBannerComponent.Config, CommonStyle, List<RollingBannerComponent.DataStructure>>().setTitle("首页横幅广告") | ||
| 51 | + .setConfig(new RollingBannerComponent.Config().setEnabled(Boolean.TRUE)) | ||
| 52 | + .setStyle(commonStyle) | ||
| 53 | + .setData(banners); | ||
| 54 | + } | ||
| 55 | + @Test | ||
| 56 | + void testReq() { | ||
| 57 | + // 准备请求参数 | ||
| 58 | + DecoratePageReqVO.ComponentReqVO cReq = new DecoratePageReqVO.ComponentReqVO() | ||
| 59 | + .setComponentCode(ROLLING_BANNER.getCode()) | ||
| 60 | + .setValue(JsonUtils.toJsonString(bannerComponent)); | ||
| 61 | + List<DecoratePageReqVO.ComponentReqVO> cReqList = new ArrayList<>(); | ||
| 62 | + cReqList.add(cReq); | ||
| 63 | + DecoratePageReqVO reqVO = new DecoratePageReqVO(); | ||
| 64 | + reqVO.setType(1); | ||
| 65 | + reqVO.setComponents(cReqList); | ||
| 66 | + System.out.printf("请求数据:%s%n",JsonUtils.toJsonPrettyString(reqVO)); | ||
| 67 | + List<PageDecorateDO> list = decoratePageService.testReq(reqVO); | ||
| 68 | + assertThat(list).hasSize(1); | ||
| 69 | + } | ||
| 70 | + @Test | ||
| 71 | + void testResp(){ | ||
| 72 | + List<PageDecorateDO> list = new ArrayList<>(1); | ||
| 73 | + PageDecorateDO decorateDO = new PageDecorateDO() | ||
| 74 | + .setType(INDEX.getType()).setComponentValue(JsonUtils.toJsonString(bannerComponent)) | ||
| 75 | + .setComponentCode(ROLLING_BANNER.getCode()).setId(1L); | ||
| 76 | + list.add(decorateDO); | ||
| 77 | + //mock 方法 | ||
| 78 | + Mockito.when(pageDecorateMapper.selectByPageType(eq(1))).thenReturn(list); | ||
| 79 | + | ||
| 80 | + DecoratePageRespVO respVO = decoratePageService.testResp(1); | ||
| 81 | + System.out.printf("响应数据:%s%n",JsonUtils.toJsonPrettyString(respVO)); | ||
| 82 | + } | ||
| 83 | +} | ||
| 0 | \ No newline at end of file | 84 | \ No newline at end of file |