From c3de25e760a66523d17ea3a5cf8ace57f6b821ec Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 16 Aug 2023 22:11:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A5=E9=94=80=EF=BC=9A=201.=20=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=BA=97=E9=93=BA=E8=A3=85=E4=BF=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../enums/decorate/DecorateComponentEnum.java | 45 +++++++++++++++---- .../enums/decorate/DecoratePageEnum.java | 7 +-- .../decorate/DecorateComponentController.http | 18 ++++++++ .../decorate/DecorateComponentController.java | 32 +++++++------ .../decorate/vo/DecorateComponentRespVO.java | 26 +++-------- .../vo/DecorateComponentSaveReqVO.java | 31 ++++--------- .../app/decorate/AppDecorateController.java | 17 ++++--- .../vo/AppDecorateComponentRespVO.java | 24 +++------- .../decorate/DecorateComponentConvert.java | 27 ++--------- .../decorate/DecorateComponentDO.java | 10 +++-- .../decorate/DecorateComponentMapper.java | 14 ++++-- .../decorate/DecorateComponentService.java | 11 ++--- .../DecorateComponentServiceImpl.java | 30 +++++-------- .../DecorateComponentServiceImplTest.java | 8 ++-- 14 files changed, 149 insertions(+), 151 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.http diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecorateComponentEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecorateComponentEnum.java index e9b9a902b..45bc1fe4d 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecorateComponentEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecorateComponentEnum.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.enums.decorate; +import lombok.AllArgsConstructor; import lombok.Getter; /** @@ -8,11 +9,44 @@ import lombok.Getter; * @author jason */ @Getter +@AllArgsConstructor +@SuppressWarnings("JavadocLinkAsPlainText") public enum DecorateComponentEnum { - NAV_MENU("nav-menu", "导航菜单"), - ROLLING_BANNER("rolling-banner", "滚动横幅广告"), - PRODUCT_CATEGORY("product-category", "商品分类"); + /** + * 格式:[{ + * "name": "标题" + * "picUrl": "https://www.iocoder.cn/xxx.png", + * "url": "/pages/users/index" + * }] + * + * 最多 10 个 + */ + MENU("menu", "菜单"), + /** + * 格式:[{ + * "name": "标题" + * "url": "/pages/users/index" + * }] + */ + ROLLING_NEWS("scrolling-news", "滚动新闻"), + /** + * 格式:[{ + * "picUrl": "https://www.iocoder.cn/xxx.png", + * "url": "/pages/users/index" + * }] + */ + SLIDE_SHOW("slide-show", "轮播图"), + /** + * 格式:[{ + * "name": "标题" + * "type": "类型", // best、hot、new、benefit、good + * "tag": "标签" // 例如说:多买多省 + * }] + * + * 最多 4 个 + */ + PRODUCT_RECOMMEND("product-recommend", "商品推荐"); /** * 页面组件代码 @@ -24,9 +58,4 @@ public enum DecorateComponentEnum { */ private final String desc; - DecorateComponentEnum(String code, String desc) { - this.code = code; - this.desc = desc; - } - } diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageEnum.java index 7e6ae2122..a618fa7e3 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageEnum.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/decorate/DecoratePageEnum.java @@ -17,12 +17,13 @@ public enum DecoratePageEnum implements IntArrayValuable { INDEX(1, "首页"); - private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageEnum::getId).toArray(); + private static final int[] ARRAYS = Arrays.stream(values()).mapToInt(DecoratePageEnum::getPage).toArray(); /** - * 页面 id + * 页面编号 */ - private final Integer id; + private final Integer page; + /** * 页面名称 */ diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.http b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.http new file mode 100644 index 000000000..79975c590 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.http @@ -0,0 +1,18 @@ +### /promotion/decorate/save 保存页面装修组件 +POST {{baseUrl}}/promotion/decorate/save +Content-Type: application/json +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +{ + "page": 1, + "code": "slide-show", + "status": 0, + "value": "null" +} + +### /promotion/decorate/list 获取指定页面的组件列表 +GET {{baseUrl}}/promotion/decorate/list?page=1 +Content-Type: application/json +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.java index 9536df7f0..0690bab35 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/DecorateComponentController.java @@ -2,45 +2,49 @@ package cn.iocoder.yudao.module.promotion.controller.admin.decorate; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.validation.InEnum; -import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO; +import cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum; import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; @Tag(name = "管理后台 - 店铺页面装修") @RestController @RequestMapping("/promotion/decorate") @Validated public class DecorateComponentController { + @Resource private DecorateComponentService decorateComponentService; - @PostMapping("/page-save") - @Operation(summary = "保存页面装修") - // TODO 加权限 - public CommonResult savePageComponents(@Valid @RequestBody DecorateComponentSaveReqVO reqVO) { - decorateComponentService.savePageComponents(reqVO); + @PostMapping("/save") + @Operation(summary = "保存页面装修组件") + @PreAuthorize("@ss.hasPermission('promotion:decorate:save')") + public CommonResult saveDecorateComponent(@Valid @RequestBody DecorateComponentSaveReqVO reqVO) { + decorateComponentService.saveDecorateComponent(reqVO); return success(true); } - @GetMapping("/get-page-components") - @Operation(summary = "获取装修页面组件") - @Parameter(name = "pageId", description = "页面 id", required = true) - // TODO 加权限 - public CommonResult getPageComponents( - @RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) { - return success(INSTANCE.convert2(pageId, decorateComponentService.getPageComponents(pageId))); + @GetMapping("/list") + @Operation(summary = "获取指定页面的组件列表") + @Parameter(name = "page", description = "页面 id", required = true) + @PreAuthorize("@ss.hasPermission('promotion:decorate:query')") + public CommonResult> getDecorateComponentListByPage( + @RequestParam("page") @InEnum(DecoratePageEnum.class) Integer page) { + return success(DecorateComponentConvert.INSTANCE.convertList02( + decorateComponentService.getDecorateComponentListByPage(page, null))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentRespVO.java index 5928034a4..6996d58e8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentRespVO.java @@ -3,31 +3,17 @@ package cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import java.util.List; - @Schema(description = "管理后台 - 页面装修 Resp VO") @Data public class DecorateComponentRespVO { - @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer pageId; + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") + private String code; - @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") - private List components; + @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") + private String value; - @Schema(description = "管理后台 - 页面组件 Resp VO") - @Data - public static class ComponentRespVO { - - @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Long id; - - @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") - private String code; - - @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") - private String value; - - } + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentSaveReqVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentSaveReqVO.java index f3838a763..0d01818f4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentSaveReqVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/decorate/vo/DecorateComponentSaveReqVO.java @@ -5,10 +5,8 @@ import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; -import java.util.List; @Schema(description = "管理后台 - 页面装修的保存 Request VO ") @Data @@ -17,28 +15,17 @@ public class DecorateComponentSaveReqVO { @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @NotNull(message = "页面 id 不能为空") @InEnum(DecoratePageEnum.class) - private Integer pageId; + private Integer page; - @Schema(description = "页面组件列表", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") - @NotEmpty(message = "页面组件列表不能为空") - @Valid - private List components; + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") + @NotEmpty(message = "组件编码不能为空") + private String code; - @Schema(description = "管理后台 - 页面装修组件 Request VO") - @Data - public static class ComponentReqVO { + @Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "组件值为空") + private String value; - @Schema(description = "组件编码", example = "1") - private Long id; - - @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") - @NotEmpty(message = "组件编码不能为空") - private String code; - - @Schema(description = "组件对应值, json 字符串, 含内容配置,具体数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") - @NotEmpty(message = "组件值为空") - private String value; - - } + @Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") + private Integer status; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java index 1f5e64b19..98aff1cc4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/AppDecorateController.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.promotion.controller.app.decorate; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.validation.InEnum; import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO; +import cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert; import cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum; import cn.iocoder.yudao.module.promotion.service.decorate.DecorateComponentService; import io.swagger.v3.oas.annotations.Operation; @@ -15,9 +17,9 @@ import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; @Tag(name = "用户 APP - 店铺装修") @RestController @@ -28,12 +30,13 @@ public class AppDecorateController { @Resource private DecorateComponentService decorateComponentService; - @GetMapping("/get-page-components") - @Operation(summary = "获取装修页面组件") - @Parameter(name = "pageId", description = "页面 id", required = true) - public CommonResult getPageComponents( - @RequestParam("pageId") @InEnum(DecoratePageEnum.class) Integer pageId) { - return success(INSTANCE.appConvert(pageId, decorateComponentService.getPageComponents(pageId))); + @GetMapping("/get-component-list") + @Operation(summary = "获取指定页面的组件列表") + @Parameter(name = "page", description = "页面编号", required = true) + public CommonResult> getDecorateComponentListByPage( + @RequestParam("page") @InEnum(DecoratePageEnum.class) Integer page) { + return success(DecorateComponentConvert.INSTANCE.convertList( + decorateComponentService.getDecorateComponentListByPage(page, CommonStatusEnum.ENABLE.getStatus()))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/vo/AppDecorateComponentRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/vo/AppDecorateComponentRespVO.java index 9f52f5923..8926db26e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/vo/AppDecorateComponentRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/decorate/vo/AppDecorateComponentRespVO.java @@ -3,28 +3,14 @@ package cn.iocoder.yudao.module.promotion.controller.app.decorate.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -import java.util.List; - -@Schema(description = "用户 App - 页面装修 Resp VO") +@Schema(description = "用户 App - 页面组件 Resp VO") @Data public class AppDecorateComponentRespVO { - @Schema(description = "页面 id ", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") - private Integer pageId; + @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") + private String code; - @Schema(description = "页面组件", requiredMode = Schema.RequiredMode.REQUIRED, example = "TODO") - private List components; - - @Schema(description = "用户 App - 页面组件 Resp VO") - @Data - public static class AppComponentRespVO { - - @Schema(description = "组件编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "nav-menu") - private String code; - - @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") - private String value; - - } + @Schema(description = "组件的内容配置项", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "TODO") + private String value; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecorateComponentConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecorateComponentConvert.java index c815220ee..df6613b97 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecorateComponentConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/decorate/DecorateComponentConvert.java @@ -1,8 +1,7 @@ package cn.iocoder.yudao.module.promotion.convert.decorate; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO; import cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; import org.mapstruct.Mapper; @@ -10,33 +9,15 @@ import org.mapstruct.factory.Mappers; import java.util.List; -import static cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentRespVO.*; -import static cn.iocoder.yudao.module.promotion.controller.app.decorate.vo.AppDecorateComponentRespVO.*; - @Mapper public interface DecorateComponentConvert { DecorateComponentConvert INSTANCE = Mappers.getMapper(DecorateComponentConvert.class); - default List convertList(Integer pageId, List components) { - return CollectionUtils.convertList(components, c -> convert(pageId, c)); - } + List convertList02(List list); - default DecorateComponentRespVO convert2(Integer pageId, List list) { - List components = CollectionUtils.convertList(list, this::convert3); - return new DecorateComponentRespVO().setPageId(pageId).setComponents(components); - } + DecorateComponentDO convert(DecorateComponentSaveReqVO bean); - DecorateComponentDO convert(Integer pageId, DecorateComponentSaveReqVO.ComponentReqVO reqVO); - - ComponentRespVO convert3(DecorateComponentDO componentDO); - - // ========== App convert ========== - default AppDecorateComponentRespVO appConvert(Integer pageId, List list) { - List components = CollectionUtils.convertList(list, this::appConvert2); - return new AppDecorateComponentRespVO().setPageId(pageId).setComponents(components); - } - - AppComponentRespVO appConvert2(DecorateComponentDO bean); + List convertList(List list); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/DecorateComponentDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/DecorateComponentDO.java index f33401c77..876431772 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/DecorateComponentDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/decorate/DecorateComponentDO.java @@ -26,13 +26,14 @@ public class DecorateComponentDO extends BaseDO { /** * 所属页面 id - * 枚举 {@link DecoratePageEnum#getId()} + * + * 枚举 {@link DecoratePageEnum#getPage()} */ - private Integer pageId; + private Integer page; /** - * 组件编码 - * 枚举 {@link DecorateComponentEnum#getCode()} + * 组件编码 + * 枚举 {@link DecorateComponentEnum#getCode()} */ private String code; @@ -47,4 +48,5 @@ public class DecorateComponentDO extends BaseDO { * 枚举 {@link CommonStatusEnum} */ private Integer status; + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/DecorateComponentMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/DecorateComponentMapper.java index 4773d40bc..38b448e8a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/DecorateComponentMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/decorate/DecorateComponentMapper.java @@ -1,7 +1,8 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.decorate; -import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; import org.apache.ibatis.annotations.Mapper; import java.util.List; @@ -9,8 +10,15 @@ import java.util.List; @Mapper public interface DecorateComponentMapper extends BaseMapperX { - default List selectByPage(Integer pageId){ - return selectList(DecorateComponentDO::getPageId, pageId); + default List selectListByPageAndStatus(Integer page, Integer status) { + return selectList(new LambdaQueryWrapperX() + .eq(DecorateComponentDO::getPage, page) + .eqIfPresent(DecorateComponentDO::getStatus, status)); + } + + default DecorateComponentDO selectByPageAndCode(Integer page, String code) { + return selectOne(DecorateComponentDO::getPage, page, + DecorateComponentDO::getCode, code); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentService.java index cf1431fe8..82f0b0f5b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentService.java @@ -14,17 +14,18 @@ import java.util.List; public interface DecorateComponentService { /** - * 店铺装修页面保存 + * 保存页面的组件信息 * * @param reqVO 请求 VO */ - void savePageComponents(DecorateComponentSaveReqVO reqVO); + void saveDecorateComponent(DecorateComponentSaveReqVO reqVO); /** - * 根据页面 id。获取页面的组件信息 + * 根据页面 id,获取页面的组件信息 * - * @param pageId 页面类型 {@link DecoratePageEnum#getId()} + * @param page 页面编号 {@link DecoratePageEnum#getPage()} + * @param status 状态 */ - List getPageComponents(Integer pageId); + List getDecorateComponentListByPage(Integer page, Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImpl.java index 73256922a..b9e3fbc84 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImpl.java @@ -1,19 +1,13 @@ package cn.iocoder.yudao.module.promotion.service.decorate; -import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.decorate.vo.DecorateComponentSaveReqVO.ComponentReqVO; +import cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.decorate.DecorateComponentDO; import cn.iocoder.yudao.module.promotion.dal.mysql.decorate.DecorateComponentMapper; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; -import java.util.Objects; -import java.util.Set; - -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.module.promotion.convert.decorate.DecorateComponentConvert.INSTANCE; /** * 装修组件 Service 实现 @@ -27,22 +21,20 @@ public class DecorateComponentServiceImpl implements DecorateComponentService { private DecorateComponentMapper decorateComponentMapper; @Override - public void savePageComponents(DecorateComponentSaveReqVO reqVO) { - // 1.新增或修改页面组件 - List oldList = decorateComponentMapper.selectByPage(reqVO.getPageId()); - - decorateComponentMapper.saveOrUpdateBatch(INSTANCE.convertList(reqVO.getPageId(), reqVO.getComponents())); - // 2.删除相关组件 - Set deleteIds = convertSet(oldList, DecorateComponentDO::getId); - deleteIds.removeAll(convertSet(reqVO.getComponents(), ComponentReqVO::getId, vo->Objects.nonNull(vo.getId()))); - if (CollUtil.isNotEmpty(deleteIds)) { - decorateComponentMapper.deleteBatchIds(deleteIds); + public void saveDecorateComponent(DecorateComponentSaveReqVO reqVO) { + // 1. 如果存在,则进行更新 + DecorateComponentDO dbComponent = decorateComponentMapper.selectByPageAndCode(reqVO.getPage(), reqVO.getCode()); + if (dbComponent != null) { + decorateComponentMapper.updateById(DecorateComponentConvert.INSTANCE.convert(reqVO).setId(dbComponent.getId())); + return; } + // 2. 不存在,则进行新增 + decorateComponentMapper.insert(DecorateComponentConvert.INSTANCE.convert(reqVO)); } @Override - public List getPageComponents(Integer pageId) { - return decorateComponentMapper.selectByPage(pageId); + public List getDecorateComponentListByPage(Integer page, Integer status) { + return decorateComponentMapper.selectListByPageAndStatus(page, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java index 067397905..fa291e5fa 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/test/java/cn/iocoder/yudao/module/promotion/service/decorate/DecorateComponentServiceImplTest.java @@ -12,7 +12,7 @@ import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; -import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_BANNER; +import static cn.iocoder.yudao.module.promotion.enums.decorate.DecorateComponentEnum.ROLLING_NEWS; import static cn.iocoder.yudao.module.promotion.enums.decorate.DecoratePageEnum.INDEX; import static org.mockito.ArgumentMatchers.eq; @@ -37,10 +37,10 @@ public class DecorateComponentServiceImplTest extends BaseMockitoUnitTest { void testResp(){ List list = new ArrayList<>(1); DecorateComponentDO decorateDO = new DecorateComponentDO() - .setPageId(INDEX.getId()).setValue("") - .setCode(ROLLING_BANNER.getCode()).setId(1L); + .setPage(INDEX.getPage()).setValue("") + .setCode(ROLLING_NEWS.getCode()).setId(1L); list.add(decorateDO); //mock 方法 - Mockito.when(decorateComponentMapper.selectByPage(eq(1))).thenReturn(list); + Mockito.when(decorateComponentMapper.selectListByPageAndStatus(eq(1))).thenReturn(list); } }