Commit ad1f656dfa42346c85a346db6f53cd27c86b4767
1 parent
1dfbe459
页面装修修改,后端只负责存取
Showing
24 changed files
with
327 additions
and
414 deletions
sql/mysql/optional/mall.sql
| ... | ... | @@ -448,10 +448,10 @@ CREATE TABLE `trade_delivery_express` ( |
| 448 | 448 | ) ENGINE=InnoDB COMMENT='快递公司'; |
| 449 | 449 | |
| 450 | 450 | -- ---------------------------- |
| 451 | --- 页面装修表结构 | |
| 451 | +-- 页面装修表 | |
| 452 | 452 | -- ---------------------------- |
| 453 | -DROP TABLE IF EXISTS `promotion_page_decorate`; | |
| 454 | -CREATE TABLE `promotion_page_decorate` ( | |
| 453 | +DROP TABLE IF EXISTS `promotion_decorate_component`; | |
| 454 | +CREATE TABLE `promotion_decorate_component` ( | |
| 455 | 455 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', |
| 456 | 456 | `type` int NOT NULL COMMENT '页面类型', |
| 457 | 457 | `component_code` varchar(64) NOT NULL COMMENT '组件编码', |
| ... | ... | @@ -464,7 +464,7 @@ CREATE TABLE `promotion_page_decorate` ( |
| 464 | 464 | `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', |
| 465 | 465 | `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', |
| 466 | 466 | PRIMARY KEY (`id`) USING BTREE |
| 467 | -) ENGINE=InnoDB COMMENT='页面装修'; | |
| 467 | +) ENGINE=InnoDB COMMENT='页面装修表'; | |
| 468 | 468 | |
| 469 | 469 | SET FOREIGN_KEY_CHECKS = 1; |
| 470 | 470 | ... | ... |
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
| ... | ... | @@ -113,7 +113,6 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { |
| 113 | 113 | Db.saveBatch(entities, size); |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - // @芋艿 是不是叫 updateByDo 或者 updateByEntity 更合适;回复:因为是使用实体作为条件去批量更新,所以没加 ByEntity,保持和 mybatis plus 风格一致 | |
| 117 | 116 | default void updateBatch(T update) { |
| 118 | 117 | update(update, new QueryWrapper<>()); |
| 119 | 118 | } |
| ... | ... | @@ -131,4 +130,12 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { |
| 131 | 130 | Db.updateBatchById(entities, size); |
| 132 | 131 | } |
| 133 | 132 | |
| 133 | + /** | |
| 134 | + * 批量修改插入, 会根据实体的主键是否为空,更新还是修改。默认为 1000 | |
| 135 | + * @param entities 实体们 | |
| 136 | + */ | |
| 137 | + default void saveOrUpdateBatch(Collection<T> entities){ | |
| 138 | + Db.saveOrUpdateBatch(entities); | |
| 139 | + } | |
| 140 | + | |
| 134 | 141 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/CommonStyle.java deleted
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/decorate/dto/NavMenuComponent.java deleted
| 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 deleted
| 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 deleted
| 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 deleted
| 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/PageComponentEnum.java renamed to yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecorateComponentEnum.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.enums.decorate; |
| 2 | 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 | 3 | import lombok.Getter; |
| 8 | 4 | |
| 9 | -import java.lang.reflect.Type; | |
| 10 | -import java.util.List; | |
| 11 | - | |
| 12 | 5 | /** |
| 13 | 6 | * 页面组件枚举 |
| 14 | 7 | * |
| 15 | 8 | * @author jason |
| 16 | 9 | */ |
| 17 | 10 | @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 代替 | |
| 11 | +public enum DecorateComponentEnum { | |
| 12 | + NAV_MENU("nav-menu", "导航菜单"), | |
| 13 | + ROLLING_BANNER("rolling-banner", "滚动横幅广告"), | |
| 14 | + PRODUCT_CATEGORY("product-category", "商品分类"); | |
| 25 | 15 | |
| 26 | 16 | /** |
| 27 | 17 | * 页面组件代码 |
| ... | ... | @@ -33,22 +23,8 @@ public enum PageComponentEnum { |
| 33 | 23 | */ |
| 34 | 24 | private final String desc; |
| 35 | 25 | |
| 36 | - /** | |
| 37 | - * 具体组件的类型 | |
| 38 | - */ | |
| 39 | - private final Type componentType; | |
| 40 | - | |
| 41 | - PageComponentEnum(String code, String desc, Type componentType) { | |
| 26 | + DecorateComponentEnum(String code, String desc) { | |
| 42 | 27 | this.code = code; |
| 43 | 28 | 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 | 29 | } |
| 54 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageTypeEnum.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.enums.decorate; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 3 | 4 | import lombok.AllArgsConstructor; |
| 4 | 5 | import lombok.Getter; |
| 5 | 6 | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 6 | 9 | /** |
| 7 | - * 装修页面枚举 | |
| 10 | + * 装修页面类型枚举 | |
| 8 | 11 | * |
| 9 | 12 | * @author jason |
| 10 | 13 | */ |
| 11 | 14 | @AllArgsConstructor |
| 12 | 15 | @Getter |
| 13 | -public enum DecoratePageTypeEnum { | |
| 16 | +public enum DecoratePageTypeEnum implements IntArrayValuable { | |
| 14 | 17 | INDEX(1, "首页"); |
| 15 | 18 | |
| 19 | + private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageTypeEnum::getType).toArray(); | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * 页面类型 | |
| 23 | + */ | |
| 16 | 24 | private final Integer type; |
| 17 | 25 | /** |
| 18 | - * 名字 | |
| 26 | + * 页面名称 | |
| 19 | 27 | */ |
| 20 | 28 | private final String name; |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public int[] array() { | |
| 32 | + return ARRAYS; | |
| 33 | + } | |
| 21 | 34 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.admin.decorate; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; | |
| 8 | +import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; | |
| 9 | +import io.swagger.v3.oas.annotations.Operation; | |
| 10 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 11 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 12 | +import org.springframework.validation.annotation.Validated; | |
| 13 | +import org.springframework.web.bind.annotation.*; | |
| 14 | + | |
| 15 | +import javax.annotation.Resource; | |
| 16 | +import javax.validation.Valid; | |
| 17 | + | |
| 18 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 19 | +import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; | |
| 20 | + | |
| 21 | +@Tag(name = "管理后台 - 店铺页面装修") | |
| 22 | +@RestController | |
| 23 | +@RequestMapping("/promotion/decorate") | |
| 24 | +@Validated | |
| 25 | +public class DecorateComponentController { | |
| 26 | + @Resource | |
| 27 | + private DecorateComponentService decorateComponentService; | |
| 28 | + | |
| 29 | + @PostMapping("/page-save") | |
| 30 | + @Operation(summary = "页面装修保存") | |
| 31 | + // TODO 加权限 | |
| 32 | + public CommonResult<Boolean> pageSave(@Valid @RequestBody DecorateComponentReqVO reqVO) { | |
| 33 | + decorateComponentService.pageSave(reqVO); | |
| 34 | + return success(true); | |
| 35 | + } | |
| 36 | + | |
| 37 | + @GetMapping("/get-page-components") | |
| 38 | + @Operation(summary = "获取装修页面组件") | |
| 39 | + @Parameter(name = "type", description = "页面类型", required = true) | |
| 40 | + // TODO 加权限 | |
| 41 | + public CommonResult<DecorateComponentRespVO> getPageComponents(@RequestParam("type") | |
| 42 | + @InEnum(DecoratePageTypeEnum.class) Integer type) { | |
| 43 | + return success(INSTANCE.convert2(type, decorateComponentService.getPageComponents(type))); | |
| 44 | + } | |
| 45 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecoratePageReqVO.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentReqVO.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 4 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; | |
| 3 | 5 | import io.swagger.v3.oas.annotations.media.Schema; |
| 4 | 6 | import lombok.Data; |
| 5 | 7 | |
| ... | ... | @@ -11,20 +13,23 @@ import java.util.List; |
| 11 | 13 | /** |
| 12 | 14 | * @author jason |
| 13 | 15 | */ |
| 14 | -@Schema(description = "管理后台 - 页面装,整个页面 Request VO ") | |
| 16 | +@Schema(description = "管理后台 - 页面装修 Request VO ") | |
| 15 | 17 | @Data |
| 16 | -public class DecoratePageReqVO { | |
| 18 | +public class DecorateComponentReqVO { | |
| 17 | 19 | @Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 18 | 20 | @NotNull(message = "页面类型不能为空") |
| 21 | + @InEnum(DecoratePageTypeEnum.class) | |
| 19 | 22 | private Integer type; |
| 20 | 23 | @Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") |
| 21 | 24 | @NotEmpty(message = "页面组件列表不能为空") |
| 22 | 25 | @Valid |
| 23 | 26 | private List<ComponentReqVO> components; |
| 24 | 27 | |
| 25 | - @Schema(description = "管理后台 - 页面组件 Request VO, 后面是不是可以做分组件保存?? ") | |
| 28 | + @Schema(description = "管理后台 - 页面装修组件 Request VO") | |
| 26 | 29 | @Data |
| 27 | 30 | public static class ComponentReqVO { |
| 31 | + @Schema(description = "组件编码", example = "1") | |
| 32 | + private Long id; | |
| 28 | 33 | |
| 29 | 34 | @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") |
| 30 | 35 | @NotEmpty(message = "组件编码不能为空") |
| ... | ... | @@ -32,7 +37,7 @@ public class DecoratePageReqVO { |
| 32 | 37 | |
| 33 | 38 | @Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") |
| 34 | 39 | @NotEmpty(message = "组件值为空") |
| 35 | - private String value; | |
| 40 | + private String componentValue; | |
| 36 | 41 | } |
| 37 | 42 | |
| 38 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecoratePageRespVO.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentRespVO.java
| ... | ... | @@ -10,7 +10,7 @@ import java.util.List; |
| 10 | 10 | */ |
| 11 | 11 | @Schema(description = "管理后台 - 页面装修 Resp VO") |
| 12 | 12 | @Data |
| 13 | -public class DecoratePageRespVO { | |
| 13 | +public class DecorateComponentRespVO { | |
| 14 | 14 | @Schema(description = "页面类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") |
| 15 | 15 | private Integer type; |
| 16 | 16 | @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") |
| ... | ... | @@ -19,16 +19,12 @@ public class DecoratePageRespVO { |
| 19 | 19 | @Schema(description = "管理后台 - 页面组件 Resp VO") |
| 20 | 20 | @Data |
| 21 | 21 | public static class ComponentRespVO { |
| 22 | - @Schema(description = "组件标题", requiredMode = Schema.RequiredMode.REQUIRED, example = "首页广告") | |
| 23 | - private String title; | |
| 22 | + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 23 | + private Long id; | |
| 24 | 24 | @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") |
| 25 | 25 | private String componentCode; |
| 26 | 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; | |
| 27 | + private String componentValue; | |
| 32 | 28 | } |
| 33 | 29 | |
| 34 | 30 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.app.decorate; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; | |
| 7 | +import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; | |
| 8 | +import io.swagger.v3.oas.annotations.Operation; | |
| 9 | +import io.swagger.v3.oas.annotations.Parameter; | |
| 10 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 11 | +import org.springframework.validation.annotation.Validated; | |
| 12 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 13 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 14 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 15 | +import org.springframework.web.bind.annotation.RestController; | |
| 16 | + | |
| 17 | +import javax.annotation.Resource; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 20 | +import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; | |
| 21 | + | |
| 22 | +@Tag(name = "用户 APP - 店铺装修") | |
| 23 | +@RestController | |
| 24 | +@RequestMapping("/promotion/decorate") | |
| 25 | +@Validated | |
| 26 | +public class AppDecorateController { | |
| 27 | + | |
| 28 | + @Resource | |
| 29 | + private DecorateComponentService decorateComponentService; | |
| 30 | + | |
| 31 | + @GetMapping("/get-page-components") | |
| 32 | + @Operation(summary = "获取装修页面组件") | |
| 33 | + @Parameter(name = "type", description = "页面类型", required = true) | |
| 34 | + public CommonResult<AppDecorateComponentRespVO> getPageComponents(@RequestParam("type") | |
| 35 | + @InEnum(DecoratePageTypeEnum.class) Integer type) { | |
| 36 | + return success(INSTANCE.appConvert(type, decorateComponentService.getPageComponents(type))); | |
| 37 | + } | |
| 38 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/vo/AppDecorateComponentRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.app.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 = "用户 App - 页面装修 Resp VO") | |
| 12 | +@Data | |
| 13 | +public class AppDecorateComponentRespVO { | |
| 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<AppComponentRespVO> components; | |
| 18 | + | |
| 19 | + @Schema(description = "用户 App - 页面组件 Resp VO") | |
| 20 | + @Data | |
| 21 | + public static class AppComponentRespVO { | |
| 22 | + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 23 | + private Long id; | |
| 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 String componentValue; | |
| 28 | + } | |
| 29 | + | |
| 30 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecorateComponentConvert.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.controller.admin.decorate.vo.DecorateComponentReqVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 8 | +import org.mapstruct.Mapper; | |
| 9 | +import org.mapstruct.factory.Mappers; | |
| 10 | + | |
| 11 | +import java.util.List; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO.*; | |
| 14 | +import static cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO.*; | |
| 15 | + | |
| 16 | +@Mapper | |
| 17 | +public interface DecorateComponentConvert { | |
| 18 | + | |
| 19 | + DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class); | |
| 20 | + | |
| 21 | + default List<DecorateComponentDO> convertList(Integer type, List<DecorateComponentReqVO.ComponentReqVO> components) { | |
| 22 | + return CollectionUtils.convertList(components, c -> convert(type, c)); | |
| 23 | + } | |
| 24 | + | |
| 25 | + default DecorateComponentRespVO convert2(Integer type, List<DecorateComponentDO> doList) { | |
| 26 | + List<ComponentRespVO> components = CollectionUtils.convertList(doList, this::convert3); | |
| 27 | + return new DecorateComponentRespVO().setType(type).setComponents(components); | |
| 28 | + } | |
| 29 | + | |
| 30 | + DecorateComponentDO convert(Integer type, DecorateComponentReqVO.ComponentReqVO reqVO); | |
| 31 | + | |
| 32 | + ComponentRespVO convert3(DecorateComponentDO componentDO); | |
| 33 | + | |
| 34 | + // ========== App convert ========== | |
| 35 | + default AppDecorateComponentRespVO appConvert(Integer type, List<DecorateComponentDO> doList) { | |
| 36 | + List<AppComponentRespVO> components = CollectionUtils.convertList(doList, this::appConvert2); | |
| 37 | + return new AppDecorateComponentRespVO().setType(type).setComponents(components); | |
| 38 | + } | |
| 39 | + | |
| 40 | + AppComponentRespVO appConvert2(DecorateComponentDO componentDO); | |
| 41 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecoratePageConvert.java deleted
| 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 renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/DecorateComponentDO.java
| ... | ... | @@ -3,20 +3,20 @@ package cn.iocoder.yudao.module.promotion.dal.dataobject.decorate; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 5 | 5 | import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; |
| 6 | -import cn.iocoder.yudao.module.promotion.enums.decorate.PageComponentEnum; | |
| 6 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum; | |
| 7 | 7 | import com.baomidou.mybatisplus.annotation.*; |
| 8 | 8 | |
| 9 | 9 | import lombok.Data; |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * 页面装修 DO | |
| 12 | + * 页面装修组件 DO, 一个页面由多个组件构成 | |
| 13 | 13 | * |
| 14 | 14 | * @author jason |
| 15 | 15 | */ |
| 16 | -@TableName(value ="promotion_page_decorate") | |
| 17 | -@KeySequence("promotion_page_decorate_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 16 | +@TableName(value ="promotion_decorate_component") | |
| 17 | +@KeySequence("promotion_decorate_component_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | |
| 18 | 18 | @Data |
| 19 | -public class PageDecorateDO extends BaseDO { | |
| 19 | +public class DecorateComponentDO extends BaseDO { | |
| 20 | 20 | /** |
| 21 | 21 | * 编号 |
| 22 | 22 | */ |
| ... | ... | @@ -31,7 +31,7 @@ public class PageDecorateDO extends BaseDO { |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * 组件编码 |
| 34 | - * 枚举 {@link PageComponentEnum#getCode()} | |
| 34 | + * 枚举 {@link DecorateComponentEnum#getCode()} | |
| 35 | 35 | */ |
| 36 | 36 | private String componentCode; |
| 37 | 37 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/PageDecorateMapper.java renamed to yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/DecorateComponentMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.dal.mysql.decorate; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.PageDecorateDO; | |
| 3 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 4 | 4 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 5 | 5 | import org.apache.ibatis.annotations.Mapper; |
| 6 | 6 | |
| 7 | 7 | import java.util.List; |
| 8 | 8 | |
| 9 | 9 | @Mapper |
| 10 | -public interface PageDecorateMapper extends BaseMapperX<PageDecorateDO> { | |
| 11 | - default List<PageDecorateDO> selectByPageType(Integer type){ | |
| 12 | - return selectList(PageDecorateDO::getType, type); | |
| 10 | +public interface DecorateComponentMapper extends BaseMapperX<DecorateComponentDO> { | |
| 11 | + default List<DecorateComponentDO> selectByPageType(Integer type){ | |
| 12 | + return selectList(DecorateComponentDO::getType, type); | |
| 13 | 13 | } |
| 14 | 14 | } |
| 15 | 15 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO; | |
| 4 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum; | |
| 6 | + | |
| 7 | +import java.util.List; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * 装修组件 Service 接口 | |
| 11 | + * | |
| 12 | + * @author jason | |
| 13 | + */ | |
| 14 | +public interface DecorateComponentService { | |
| 15 | + | |
| 16 | + /** | |
| 17 | + * 店铺装修页面保存 | |
| 18 | + * @param reqVO 请求 VO | |
| 19 | + */ | |
| 20 | + void pageSave(DecorateComponentReqVO reqVO); | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 根据页面类型。获取页面的组件信息 | |
| 24 | + * @param type 页面类型 {@link DecoratePageTypeEnum#getType()} | |
| 25 | + */ | |
| 26 | + List<DecorateComponentDO> getPageComponents(Integer type); | |
| 27 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | |
| 2 | + | |
| 3 | +import cn.hutool.core.collection.CollUtil; | |
| 4 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentReqVO.ComponentReqVO; | |
| 6 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 7 | +import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.DecorateComponentMapper; | |
| 8 | +import org.springframework.stereotype.Service; | |
| 9 | + | |
| 10 | +import javax.annotation.Resource; | |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Objects; | |
| 13 | +import java.util.Set; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 16 | +import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * 装修组件 Service 接口实现 | |
| 20 | + * @author jason | |
| 21 | + */ | |
| 22 | +@Service | |
| 23 | +public class DecorateComponentServiceImpl implements DecorateComponentService { | |
| 24 | + @Resource | |
| 25 | + private DecorateComponentMapper decorateComponentMapper; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public void pageSave(DecorateComponentReqVO reqVO) { | |
| 29 | + // 1.新增或修改页面组件 | |
| 30 | + List<DecorateComponentDO> oldList = decorateComponentMapper.selectByPageType(reqVO.getType()); | |
| 31 | + | |
| 32 | + decorateComponentMapper.saveOrUpdateBatch(INSTANCE.convertList(reqVO.getType(), reqVO.getComponents())); | |
| 33 | + // 2.删除相关组件 | |
| 34 | + Set<Long> deleteIds = convertSet(oldList, DecorateComponentDO::getId); | |
| 35 | + deleteIds.removeAll(convertSet(reqVO.getComponents(), ComponentReqVO::getId, vo->Objects.nonNull(vo.getId()))); | |
| 36 | + if (CollUtil.isNotEmpty(deleteIds)) { | |
| 37 | + decorateComponentMapper.deleteBatchIds(deleteIds); | |
| 38 | + } | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public List<DecorateComponentDO> getPageComponents(Integer type) { | |
| 43 | + return decorateComponentMapper.selectByPageType(type); | |
| 44 | + } | |
| 45 | +} | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecoratePageService.java deleted
| 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 deleted
| 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/DecorateComponentServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.service.decorate; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | |
| 4 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; | |
| 5 | +import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.DecorateComponentMapper; | |
| 6 | +import org.junit.jupiter.api.BeforeEach; | |
| 7 | +import org.junit.jupiter.api.Test; | |
| 8 | +import org.mockito.InjectMocks; | |
| 9 | +import org.mockito.Mock; | |
| 10 | +import org.mockito.Mockito; | |
| 11 | + | |
| 12 | +import java.util.ArrayList; | |
| 13 | +import java.util.List; | |
| 14 | + | |
| 15 | +import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_BANNER; | |
| 16 | +import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageTypeEnum.INDEX; | |
| 17 | +import static org.mockito.ArgumentMatchers.eq; | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * @author jason | |
| 21 | + */ | |
| 22 | +public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest { | |
| 23 | + | |
| 24 | + @InjectMocks | |
| 25 | + private DecorateComponentServiceImpl decoratePageService; | |
| 26 | + | |
| 27 | + @Mock | |
| 28 | + private DecorateComponentMapper decorateComponentMapper; | |
| 29 | + | |
| 30 | + @BeforeEach | |
| 31 | + public void init(){ | |
| 32 | + | |
| 33 | + } | |
| 34 | + | |
| 35 | + @Test | |
| 36 | + void testResp(){ | |
| 37 | + List<DecorateComponentDO> list = new ArrayList<>(1); | |
| 38 | + DecorateComponentDO decorateDO = new DecorateComponentDO() | |
| 39 | + .setType(INDEX.getType()).setComponentValue("") | |
| 40 | + .setComponentCode(ROLLING_BANNER.getCode()).setId(1L); | |
| 41 | + list.add(decorateDO); | |
| 42 | + //mock 方法 | |
| 43 | + Mockito.when(decorateComponentMapper.selectByPageType(eq(1))).thenReturn(list); | |
| 44 | + } | |
| 45 | +} | |
| 0 | 46 | \ No newline at end of file | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecoratePageServiceImplTest.java deleted
| 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 | -} | |
| 84 | 0 | \ No newline at end of file |