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); }