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 394651a980..689ce0dd00 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 new file mode 100644 index 0000000000..c42f0e29be --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java @@ -0,0 +1,63 @@ +package cn.iocoder.yudao.module.promotion.controller.app.diy; + +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.promotion.controller.app.diy.vo.AppDiyTemplatePropertyRespVO; +import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert; +import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; +import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; +import cn.iocoder.yudao.module.promotion.service.diy.DiyPageService; +import cn.iocoder.yudao.module.promotion.service.diy.DiyTemplateService; +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.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +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.framework.common.util.collection.CollectionUtils.findFirst; + +@Tag(name = "用户 APP - 装修模板") +@RestController +@RequestMapping("/promotion/diy-template") +@Validated +public class AppDiyTemplateController { + + @Resource + private DiyTemplateService diyTemplateService; + @Resource + private DiyPageService diyPageService; + + @GetMapping("/used") + @Operation(summary = "使用中的装修模板") + public CommonResult getUsedDiyTemplate() { + DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate(); + return success(buildVo(diyTemplate)); + } + + @GetMapping("/get") + @Operation(summary = "获得装修模板") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + public CommonResult getDiyTemplate(@RequestParam("id") Long id) { + DiyTemplateDO diyTemplate = diyTemplateService.getDiyTemplate(id); + return success(buildVo(diyTemplate)); + } + + private AppDiyTemplatePropertyRespVO buildVo(DiyTemplateDO diyTemplate) { + if (diyTemplate == null) { + return null; + } + // 查询模板下的页面 + 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, home, user); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyPagePropertyRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyPagePropertyRespVO.java new file mode 100644 index 0000000000..9d623f5d47 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyPagePropertyRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +@Schema(description = "用户 App - 装修页面属性 Response VO") +@Data +@ToString(callSuper = true) +public class AppDiyPagePropertyRespVO { + + @Schema(description = "装修页面编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + private Long id; + + @Schema(description = "页面名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + private String name; + + @Schema(description = "页面属性", example = "[]") + private String property; + +} 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 new file mode 100644 index 0000000000..aa237e088e --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; + +import com.fasterxml.jackson.annotation.JsonRawValue; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +@Schema(description = "用户 App - 装修模板属性 Response VO") +@Data +@ToString(callSuper = true) +public class AppDiyTemplatePropertyRespVO { + + @Schema(description = "装修模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + private Long id; + + @Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "默认主题") + private String name; + + @Schema(description = "模板属性", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @JsonRawValue + private String property; + + @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 4f5add6add..a579c60873 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 @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.diy; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.*; +import cn.iocoder.yudao.module.promotion.controller.app.diy.vo.AppDiyTemplatePropertyRespVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; import org.mapstruct.Mapper; @@ -31,6 +32,8 @@ public interface DiyTemplateConvert { DiyTemplatePropertyRespVO convertPropertyVo(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 0bf45163ff..4f0c0c7aa9 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 @@ -68,4 +68,11 @@ public interface DiyTemplateService { */ void updateDiyTemplateProperty(DiyTemplatePropertyUpdateRequestVO updateReqVO); + /** + * 获取使用中的装修模板 + * + * @return 装修模板 + */ + 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 500e237d33..41025c5d68 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 @@ -146,6 +146,11 @@ public class DiyTemplateServiceImpl implements DiyTemplateService { diyTemplateMapper.updateById(updateObj); } + @Override + public DiyTemplateDO getUsedDiyTemplate() { + return diyTemplateMapper.selectByUsed(true); + } + /** * 更新模板是否使用 *