Commit 20b11092c2a4dd6d6b4369abfef117d352a5e17c
Committed by
Gitee
!712 商城装修
Merge pull request !712 from 疯狂的世界/feature/mall_product
Showing
7 changed files
with
135 additions
and
1 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
| @@ -223,10 +223,14 @@ public class CollectionUtils { | @@ -223,10 +223,14 @@ public class CollectionUtils { | ||
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | public static <T> T findFirst(List<T> from, Predicate<T> predicate) { | 225 | public static <T> T findFirst(List<T> from, Predicate<T> predicate) { |
| 226 | + return findFirst(from, predicate, Function.identity()); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + public static <T, U> U findFirst(List<T> from, Predicate<T> predicate, Function<T, U> func) { | ||
| 226 | if (CollUtil.isEmpty(from)) { | 230 | if (CollUtil.isEmpty(from)) { |
| 227 | return null; | 231 | return null; |
| 228 | } | 232 | } |
| 229 | - return from.stream().filter(predicate).findFirst().orElse(null); | 233 | + return from.stream().filter(predicate).findFirst().map(func).orElse(null); |
| 230 | } | 234 | } |
| 231 | 235 | ||
| 232 | public static <T, V extends Comparable<? super V>> V getMaxValue(Collection<T> from, Function<T, V> valueFunc) { | 236 | public static <T, V extends Comparable<? super V>> V getMaxValue(Collection<T> from, Function<T, V> valueFunc) { |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/AppDiyTemplateController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.app.diy; | ||
| 2 | + | ||
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | +import cn.iocoder.yudao.module.promotion.controller.app.diy.vo.AppDiyTemplatePropertyRespVO; | ||
| 5 | +import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert; | ||
| 6 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; | ||
| 7 | +import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; | ||
| 8 | +import cn.iocoder.yudao.module.promotion.service.diy.DiyPageService; | ||
| 9 | +import cn.iocoder.yudao.module.promotion.service.diy.DiyTemplateService; | ||
| 10 | +import io.swagger.v3.oas.annotations.Operation; | ||
| 11 | +import io.swagger.v3.oas.annotations.Parameter; | ||
| 12 | +import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 13 | +import org.springframework.validation.annotation.Validated; | ||
| 14 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.RequestParam; | ||
| 17 | +import org.springframework.web.bind.annotation.RestController; | ||
| 18 | + | ||
| 19 | +import javax.annotation.Resource; | ||
| 20 | +import java.util.List; | ||
| 21 | + | ||
| 22 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 23 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; | ||
| 24 | + | ||
| 25 | +@Tag(name = "用户 APP - 装修模板") | ||
| 26 | +@RestController | ||
| 27 | +@RequestMapping("/promotion/diy-template") | ||
| 28 | +@Validated | ||
| 29 | +public class AppDiyTemplateController { | ||
| 30 | + | ||
| 31 | + @Resource | ||
| 32 | + private DiyTemplateService diyTemplateService; | ||
| 33 | + @Resource | ||
| 34 | + private DiyPageService diyPageService; | ||
| 35 | + | ||
| 36 | + @GetMapping("/used") | ||
| 37 | + @Operation(summary = "使用中的装修模板") | ||
| 38 | + public CommonResult<AppDiyTemplatePropertyRespVO> getUsedDiyTemplate() { | ||
| 39 | + DiyTemplateDO diyTemplate = diyTemplateService.getUsedDiyTemplate(); | ||
| 40 | + return success(buildVo(diyTemplate)); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + @GetMapping("/get") | ||
| 44 | + @Operation(summary = "获得装修模板") | ||
| 45 | + @Parameter(name = "id", description = "编号", required = true, example = "1024") | ||
| 46 | + public CommonResult<AppDiyTemplatePropertyRespVO> getDiyTemplate(@RequestParam("id") Long id) { | ||
| 47 | + DiyTemplateDO diyTemplate = diyTemplateService.getDiyTemplate(id); | ||
| 48 | + return success(buildVo(diyTemplate)); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + private AppDiyTemplatePropertyRespVO buildVo(DiyTemplateDO diyTemplate) { | ||
| 52 | + if (diyTemplate == null) { | ||
| 53 | + return null; | ||
| 54 | + } | ||
| 55 | + // 查询模板下的页面 | ||
| 56 | + List<DiyPageDO> pages = diyPageService.getDiyPageByTemplateId(diyTemplate.getId()); | ||
| 57 | + String home = findFirst(pages, page -> "首页".equals(page.getName()), DiyPageDO::getProperty); | ||
| 58 | + String user = findFirst(pages, page -> "我的".equals(page.getName()), DiyPageDO::getProperty); | ||
| 59 | + // 拼接返回 | ||
| 60 | + return DiyTemplateConvert.INSTANCE.convertPropertyVo2(diyTemplate, home, user); | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyPagePropertyRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; | ||
| 2 | + | ||
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | +import lombok.Data; | ||
| 5 | +import lombok.ToString; | ||
| 6 | + | ||
| 7 | +@Schema(description = "用户 App - 装修页面属性 Response VO") | ||
| 8 | +@Data | ||
| 9 | +@ToString(callSuper = true) | ||
| 10 | +public class AppDiyPagePropertyRespVO { | ||
| 11 | + | ||
| 12 | + @Schema(description = "装修页面编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") | ||
| 13 | + private Long id; | ||
| 14 | + | ||
| 15 | + @Schema(description = "页面名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") | ||
| 16 | + private String name; | ||
| 17 | + | ||
| 18 | + @Schema(description = "页面属性", example = "[]") | ||
| 19 | + private String property; | ||
| 20 | + | ||
| 21 | +} |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/diy/vo/AppDiyTemplatePropertyRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.promotion.controller.app.diy.vo; | ||
| 2 | + | ||
| 3 | +import com.fasterxml.jackson.annotation.JsonRawValue; | ||
| 4 | +import io.swagger.v3.oas.annotations.media.Schema; | ||
| 5 | +import lombok.Data; | ||
| 6 | +import lombok.ToString; | ||
| 7 | + | ||
| 8 | +@Schema(description = "用户 App - 装修模板属性 Response VO") | ||
| 9 | +@Data | ||
| 10 | +@ToString(callSuper = true) | ||
| 11 | +public class AppDiyTemplatePropertyRespVO { | ||
| 12 | + | ||
| 13 | + @Schema(description = "装修模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") | ||
| 14 | + private Long id; | ||
| 15 | + | ||
| 16 | + @Schema(description = "模板名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "默认主题") | ||
| 17 | + private String name; | ||
| 18 | + | ||
| 19 | + @Schema(description = "模板属性", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") | ||
| 20 | + @JsonRawValue | ||
| 21 | + private String property; | ||
| 22 | + | ||
| 23 | + @Schema(description = "首页", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") | ||
| 24 | + @JsonRawValue | ||
| 25 | + private String home; | ||
| 26 | + | ||
| 27 | + @Schema(description = "我的", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") | ||
| 28 | + @JsonRawValue | ||
| 29 | + private String user; | ||
| 30 | + | ||
| 31 | +} |
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; | @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.convert.diy; | ||
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.*; | 4 | import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.*; |
| 5 | +import cn.iocoder.yudao.module.promotion.controller.app.diy.vo.AppDiyTemplatePropertyRespVO; | ||
| 5 | import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; | 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; |
| 6 | import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; | 7 | import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; |
| 7 | import org.mapstruct.Mapper; | 8 | import org.mapstruct.Mapper; |
| @@ -31,6 +32,8 @@ public interface DiyTemplateConvert { | @@ -31,6 +32,8 @@ public interface DiyTemplateConvert { | ||
| 31 | 32 | ||
| 32 | DiyTemplatePropertyRespVO convertPropertyVo(DiyTemplateDO diyTemplate, List<DiyPageDO> pages); | 33 | DiyTemplatePropertyRespVO convertPropertyVo(DiyTemplateDO diyTemplate, List<DiyPageDO> pages); |
| 33 | 34 | ||
| 35 | + AppDiyTemplatePropertyRespVO convertPropertyVo2(DiyTemplateDO diyTemplate, String home, String user); | ||
| 36 | + | ||
| 34 | DiyTemplateDO convert(DiyTemplatePropertyUpdateRequestVO updateReqVO); | 37 | DiyTemplateDO convert(DiyTemplatePropertyUpdateRequestVO updateReqVO); |
| 35 | 38 | ||
| 36 | } | 39 | } |
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 { | @@ -68,4 +68,11 @@ public interface DiyTemplateService { | ||
| 68 | */ | 68 | */ |
| 69 | void updateDiyTemplateProperty(DiyTemplatePropertyUpdateRequestVO updateReqVO); | 69 | void updateDiyTemplateProperty(DiyTemplatePropertyUpdateRequestVO updateReqVO); |
| 70 | 70 | ||
| 71 | + /** | ||
| 72 | + * 获取使用中的装修模板 | ||
| 73 | + * | ||
| 74 | + * @return 装修模板 | ||
| 75 | + */ | ||
| 76 | + DiyTemplateDO getUsedDiyTemplate(); | ||
| 77 | + | ||
| 71 | } | 78 | } |
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 { | @@ -146,6 +146,11 @@ public class DiyTemplateServiceImpl implements DiyTemplateService { | ||
| 146 | diyTemplateMapper.updateById(updateObj); | 146 | diyTemplateMapper.updateById(updateObj); |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | + @Override | ||
| 150 | + public DiyTemplateDO getUsedDiyTemplate() { | ||
| 151 | + return diyTemplateMapper.selectByUsed(true); | ||
| 152 | + } | ||
| 153 | + | ||
| 149 | /** | 154 | /** |
| 150 | * 更新模板是否使用 | 155 | * 更新模板是否使用 |
| 151 | * | 156 | * |