From bdfb5b88942eb3fa10f885a06a1f53ca19778d8d Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 3 Nov 2023 09:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A5=E9=94=80=EF=BC=9A=E8=A3=85=E4=BF=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/util/collection/CollectionUtils.java | 6 +++++- .../app/diy/AppDiyTemplateController.java | 9 ++++++--- .../app/diy/vo/AppDiyTemplatePropertyRespVO.java | 16 ++++++++++------ .../convert/diy/DiyTemplateConvert.java | 2 +- .../service/diy/DiyTemplateService.java | 2 +- .../service/diy/DiyTemplateServiceImpl.java | 2 +- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 394651a98..689ce0dd0 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -223,10 +223,14 @@ public class CollectionUtils { } public static T findFirst(List from, Predicate predicate) { + return findFirst(from, predicate, Function.identity()); + } + + public static U findFirst(List from, Predicate predicate, Function func) { if (CollUtil.isEmpty(from)) { return null; } - return from.stream().filter(predicate).findFirst().orElse(null); + return from.stream().filter(predicate).findFirst().map(func).orElse(null); } public static > V getMaxValue(Collection from, Function valueFunc) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java index 9ee567585..c42f0e29b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java @@ -20,6 +20,7 @@ import javax.annotation.Resource; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; @Tag(name = "用户 APP - 装修模板") @RestController @@ -34,8 +35,8 @@ public class AppDiyTemplateController { @GetMapping("/used") @Operation(summary = "使用中的装修模板") - public CommonResult getDiyTemplateProperty() { - DiyTemplateDO diyTemplate = diyTemplateService.getUsedTemplate(); + public CommonResult getUsedDiyTemplate() { + DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate(); return success(buildVo(diyTemplate)); } @@ -53,8 +54,10 @@ public class AppDiyTemplateController { } // 查询模板下的页面 List pages = diyPageService.getDiyPageByTemplateId(diyTemplate.getId()); + String home = findFirst(pages, page -> "首页".equals(page.getName()), DiyPageDO::getProperty); + String user = findFirst(pages, page -> "我的".equals(page.getName()), DiyPageDO::getProperty); // 拼接返回 - return DiyTemplateConvert.INSTANCE.convertPropertyVo2(diyTemplate, pages); + return DiyTemplateConvert.INSTANCE.convertPropertyVo2(diyTemplate, home, user); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java index c9bcf0788..aa237e088 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java @@ -1,12 +1,10 @@ package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePropertyRespVO; +import com.fasterxml.jackson.annotation.JsonRawValue; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.ToString; -import java.util.List; - @Schema(description = "用户 App - 装修模板属性 Response VO") @Data @ToString(callSuper = true) @@ -18,10 +16,16 @@ public class AppDiyTemplatePropertyRespVO { @Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "默认主题") private String name; - @Schema(description = "模板属性,JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @Schema(description = "模板属性", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @JsonRawValue private String property; - @Schema(description = "模板页面", requiredMode = Schema.RequiredMode.REQUIRED, example = "[]") - private List pages; + @Schema(description = "首页", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @JsonRawValue + private String home; + + @Schema(description = "我的", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @JsonRawValue + private String user; } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyTemplateConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyTemplateConvert.java index b1400740a..a579c6087 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyTemplateConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyTemplateConvert.java @@ -32,7 +32,7 @@ public interface DiyTemplateConvert { DiyTemplatePropertyRespVO convertPropertyVo(DiyTemplateDO diyTemplate, List pages); - AppDiyTemplatePropertyRespVO convertPropertyVo2(DiyTemplateDO diyTemplate, List pages); + AppDiyTemplatePropertyRespVO convertPropertyVo2(DiyTemplateDO diyTemplate, String home, String user); DiyTemplateDO convert(DiyTemplatePropertyUpdateRequestVO updateReqVO); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java index c352b5f70..4f0c0c7aa 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateService.java @@ -73,6 +73,6 @@ public interface DiyTemplateService { * * @return 装修模板 */ - DiyTemplateDO getUsedTemplate(); + DiyTemplateDO getUsedDiyTemplate(); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java index e49fd3032..41025c5d6 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyTemplateServiceImpl.java @@ -147,7 +147,7 @@ public class DiyTemplateServiceImpl implements DiyTemplateService { } @Override - public DiyTemplateDO getUsedTemplate() { + public DiyTemplateDO getUsedDiyTemplate() { return diyTemplateMapper.selectByUsed(true); }