From 32499be98f646ecae95adb9fd019e87cc1c53e02 Mon Sep 17 00:00:00 2001 From: owen Date: Tue, 31 Oct 2023 16:01:23 +0800 Subject: [PATCH] =?UTF-8?q?=E8=90=A5=E9=94=80=EF=BC=9A=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=95=86=E5=9F=8E=E8=A3=85=E4=BF=AE=201.=20=E6=8B=86=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=AE=BE=E8=AE=A1=E7=94=A8=E7=9A=84=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=202.=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=A8=A1=E6=9D=BF=E7=9A=84=E9=A1=B5=E9=9D=A2=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=203.=20=E5=A2=9E=E5=8A=A0=E5=94=AF=E4=B8=80=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E6=A0=A1=E9=AA=8C=204.=20=E5=A2=9E=E5=8A=A0=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=BC=96=E8=BE=91=E5=99=A8=EF=BC=8C=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=BB=84=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/ErrorCodeConstants.java | 4 +- .../admin/diy/DiyPageController.java | 22 +++++-- .../admin/diy/DiyTemplateController.java | 29 ++++++-- .../admin/diy/vo/page/DiyPageBaseVO.java | 3 - .../diy/vo/page/DiyPagePropertyRespVO.java | 20 ++++++ .../page/DiyPagePropertyUpdateRequestVO.java | 23 +++++++ .../diy/vo/template/DiyTemplateBaseVO.java | 3 - .../template/DiyTemplatePropertyRespVO.java | 26 ++++++++ .../DiyTemplatePropertyUpdateRequestVO.java | 23 +++++++ .../promotion/convert/diy/DiyPageConvert.java | 10 ++- .../convert/diy/DiyTemplateConvert.java | 9 ++- .../dal/mysql/diy/DiyPageMapper.java | 13 ++++ .../dal/mysql/diy/DiyTemplateMapper.java | 4 ++ .../promotion/service/diy/DiyPageService.java | 16 +++++ .../service/diy/DiyPageServiceImpl.java | 39 +++++++++++ .../service/diy/DiyTemplateService.java | 8 +++ .../service/diy/DiyTemplateServiceImpl.java | 66 ++++++++++++++++++- 17 files changed, 295 insertions(+), 23 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyUpdateRequestVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyRespVO.java create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyUpdateRequestVO.java diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java index 7000bcc59..3b19d616a 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/ErrorCodeConstants.java @@ -118,9 +118,11 @@ public interface ErrorCodeConstants { // ========== 装修模板 1-013-017-000 ========== ErrorCode DIY_TEMPLATE_NOT_EXISTS = new ErrorCode(1_013_017_000, "装修模板不存在"); - ErrorCode DIY_TEMPLATE_USED_CANNOT_DELETE = new ErrorCode(1_013_017_001, "不能删除正在使用的装修模板"); + ErrorCode DIY_TEMPLATE_NAME_USED = new ErrorCode(1_013_017_001, "装修模板名称({})已经被使用"); + ErrorCode DIY_TEMPLATE_USED_CANNOT_DELETE = new ErrorCode(1_013_017_002, "不能删除正在使用的装修模板"); // ========== 装修页面 1-013-018-000 ========== ErrorCode DIY_PAGE_NOT_EXISTS = new ErrorCode(1_013_018_000, "装修页面不存在"); + ErrorCode DIY_PAGE_NAME_USED = new ErrorCode(1_013_018_001, "装修页面名称({})已经被使用"); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyPageController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyPageController.java index 850d38568..4da7064d0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyPageController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyPageController.java @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.diy; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.*; import cn.iocoder.yudao.module.promotion.convert.diy.DiyPageConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; import cn.iocoder.yudao.module.promotion.service.diy.DiyPageService; @@ -82,4 +79,21 @@ public class DiyPageController { return success(DiyPageConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/get-property") + @Operation(summary = "获得装修页面属性") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('promotion:diy-page:query')") + public CommonResult getDiyPageProperty(@RequestParam("id") Long id) { + DiyPageDO diyPage = diyPageService.getDiyPage(id); + return success(DiyPageConvert.INSTANCE.convertPropertyVo(diyPage)); + } + + @PutMapping("/update-property") + @Operation(summary = "更新装修页面属性") + @PreAuthorize("@ss.hasPermission('promotion:diy-page:update')") + public CommonResult updateDiyPageProperty(@Valid @RequestBody DiyPagePropertyUpdateRequestVO updateReqVO) { + diyPageService.updateDiyPageProperty(updateReqVO); + return success(true); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java index dcbf22cec..a84c647f7 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/DiyTemplateController.java @@ -2,12 +2,11 @@ package cn.iocoder.yudao.module.promotion.controller.admin.diy; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePageReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.*; 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; @@ -19,6 +18,8 @@ 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; @Tag(name = "管理后台 - 装修模板") @@ -29,6 +30,8 @@ public class DiyTemplateController { @Resource private DiyTemplateService diyTemplateService; + @Resource + private DiyPageService diyPageService; @PostMapping("/create") @Operation(summary = "创建装修模板") @@ -79,4 +82,22 @@ public class DiyTemplateController { return success(DiyTemplateConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/get-property") + @Operation(summary = "获得装修模板属性") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('promotion:diy-template:query')") + public CommonResult getDiyTemplateProperty(@RequestParam("id") Long id) { + DiyTemplateDO diyTemplate = diyTemplateService.getDiyTemplate(id); + List pages = diyPageService.getDiyPageByTemplateId(id); + return success(DiyTemplateConvert.INSTANCE.convertPropertyVo(diyTemplate, pages)); + } + + @PutMapping("/update-property") + @Operation(summary = "更新装修模板属性") + @PreAuthorize("@ss.hasPermission('promotion:diy-template:update')") + public CommonResult updateDiyTemplateProperty(@Valid @RequestBody DiyTemplatePropertyUpdateRequestVO updateReqVO) { + diyTemplateService.updateDiyTemplateProperty(updateReqVO); + return success(true); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPageBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPageBaseVO.java index 3ec390a8d..8806e4544 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPageBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPageBaseVO.java @@ -26,7 +26,4 @@ public class DiyPageBaseVO { @Schema(description = "预览图") private List previewImageUrls; - @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/admin/diy/vo/page/DiyPagePropertyRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyRespVO.java new file mode 100644 index 000000000..2fdd54682 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +@Schema(description = "管理后台 - 装修页面属性 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class DiyPagePropertyRespVO extends DiyPageBaseVO { + + @Schema(description = "装修页面编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + private Long id; + + @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/admin/diy/vo/page/DiyPagePropertyUpdateRequestVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyUpdateRequestVO.java new file mode 100644 index 000000000..ebfa36420 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/page/DiyPagePropertyUpdateRequestVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 装修页面属性更新 Request VO") +@Data +@ToString(callSuper = true) +public class DiyPagePropertyUpdateRequestVO { + + @Schema(description = "装修页面编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + @NotNull(message = "装修页面编号不能为空") + private Long id; + + @Schema(description = "页面属性,JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @NotBlank(message = "页面属性不能为空") + private String property; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java index 1bfc6a725..7959b6c26 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplateBaseVO.java @@ -23,7 +23,4 @@ public class DiyTemplateBaseVO { @Schema(description = "预览图", example = "[https://www.iocoder.cn/1.jpg]") private List previewImageUrls; - @Schema(description = "模板属性,JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") - private String property; - } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyRespVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyRespVO.java new file mode 100644 index 000000000..21dd46f3f --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyRespVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template; + +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePropertyRespVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.util.List; + +@Schema(description = "管理后台 - 装修模板属性 Response VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class DiyTemplatePropertyRespVO extends DiyTemplateBaseVO { + + @Schema(description = "装修模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + private Long id; + + @Schema(description = "模板属性,JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + private String property; + + @Schema(description = "模板页面", requiredMode = Schema.RequiredMode.REQUIRED, example = "[]") + private List pages; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyUpdateRequestVO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyUpdateRequestVO.java new file mode 100644 index 000000000..84b80f227 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/diy/vo/template/DiyTemplatePropertyUpdateRequestVO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.ToString; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 装修模板属性更新 Request VO") +@Data +@ToString(callSuper = true) +public class DiyTemplatePropertyUpdateRequestVO { + + @Schema(description = "装修模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31209") + @NotNull(message = "装修模板编号不能为空") + private Long id; + + @Schema(description = "模板属性,JSON 格式", requiredMode = Schema.RequiredMode.REQUIRED, example = "{}") + @NotBlank(message = "模板属性不能为空") + private String property; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyPageConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyPageConvert.java index a8b22d318..3443fd862 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyPageConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/diy/DiyPageConvert.java @@ -1,9 +1,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.page.DiyPageCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.*; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -30,4 +28,10 @@ public interface DiyPageConvert { PageResult convertPage(PageResult page); + DiyPageCreateReqVO convertCreateVo(Long templateId, String name, String remark); + + DiyPagePropertyRespVO convertPropertyVo(DiyPageDO diyPage); + + DiyPageDO convert(DiyPagePropertyUpdateRequestVO updateReqVO); + } 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 6f338e918..4f5add6ad 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 @@ -1,9 +1,8 @@ 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.DiyTemplateCreateReqVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateRespVO; -import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.*; +import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -30,4 +29,8 @@ public interface DiyTemplateConvert { PageResult convertPage(PageResult page); + DiyTemplatePropertyRespVO convertPropertyVo(DiyTemplateDO diyTemplate, List pages); + + DiyTemplateDO convert(DiyTemplatePropertyUpdateRequestVO updateReqVO); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyPageMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyPageMapper.java index a0ef3714c..979b93f25 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyPageMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyPageMapper.java @@ -7,6 +7,8 @@ import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePag import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; import org.apache.ibatis.annotations.Mapper; +import java.util.List; + /** * 装修页面 Mapper * @@ -19,8 +21,19 @@ public interface DiyPageMapper extends BaseMapperX { return selectPage(reqVO, new LambdaQueryWrapperX() .likeIfPresent(DiyPageDO::getName, reqVO.getName()) .betweenIfPresent(DiyPageDO::getCreateTime, reqVO.getCreateTime()) + // 模板下面的页面,在模板中管理 .isNull(DiyPageDO::getTemplateId) .orderByDesc(DiyPageDO::getId)); } + default List selectListByTemplateId(Long templateId) { + return selectList(DiyPageDO::getTemplateId, templateId); + } + + default DiyPageDO selectByNameAndTemplateIdIsNull(String name) { + return selectOne(new LambdaQueryWrapperX() + .eq(DiyPageDO::getName, name) + .isNull(DiyPageDO::getTemplateId)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java index 5ac1d99fc..ca3c6284e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/diy/DiyTemplateMapper.java @@ -29,4 +29,8 @@ public interface DiyTemplateMapper extends BaseMapperX { return selectOne(DiyTemplateDO::getUsed, used); } + default DiyTemplateDO selectByName(String name) { + return selectOne(DiyTemplateDO::getName, name); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageService.java index 94a065ffe..31900e7a4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageService.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.diy; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePropertyUpdateRequestVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; @@ -63,4 +64,19 @@ public interface DiyPageService { */ PageResult getDiyPagePage(DiyPagePageReqVO pageReqVO); + /** + * 更新装修页面属性 + * + * @param updateReqVO 更新信息 + */ + void updateDiyPageProperty(DiyPagePropertyUpdateRequestVO updateReqVO); + + /** + * 获得模板所属的页面列表 + * + * @param templateId 模板编号 + * @return 装修页面列表 + */ + List getDiyPageByTemplateId(Long templateId); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageServiceImpl.java index 26371e36a..d82b9b8ed 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/diy/DiyPageServiceImpl.java @@ -2,9 +2,11 @@ package cn.iocoder.yudao.module.promotion.service.diy; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPagePropertyUpdateRequestVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.page.DiyPageUpdateReqVO; import cn.iocoder.yudao.module.promotion.convert.diy.DiyPageConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyPageDO; @@ -17,6 +19,7 @@ import java.util.Collection; import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.DIY_PAGE_NAME_USED; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.DIY_PAGE_NOT_EXISTS; /** @@ -33,8 +36,11 @@ public class DiyPageServiceImpl implements DiyPageService { @Override public Long createDiyPage(DiyPageCreateReqVO createReqVO) { + // 校验名称唯一 + validateNameUnique(null, createReqVO.getTemplateId(), createReqVO.getName()); // 插入 DiyPageDO diyPage = DiyPageConvert.INSTANCE.convert(createReqVO); + diyPage.setProperty("{}"); diyPageMapper.insert(diyPage); // 返回 return diyPage.getId(); @@ -44,11 +50,30 @@ public class DiyPageServiceImpl implements DiyPageService { public void updateDiyPage(DiyPageUpdateReqVO updateReqVO) { // 校验存在 validateDiyPageExists(updateReqVO.getId()); + // 校验名称唯一 + validateNameUnique(updateReqVO.getId(), updateReqVO.getTemplateId(), updateReqVO.getName()); // 更新 DiyPageDO updateObj = DiyPageConvert.INSTANCE.convert(updateReqVO); diyPageMapper.updateById(updateObj); } + void validateNameUnique(Long id, Long templateId, String name) { + if (templateId != null || StrUtil.isBlank(name)) { + return; + } + DiyPageDO page = diyPageMapper.selectByNameAndTemplateIdIsNull(name); + if (page == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的页面 + if (id == null) { + throw exception(DIY_PAGE_NAME_USED, name); + } + if (!page.getId().equals(id)) { + throw exception(DIY_PAGE_NAME_USED, name); + } + } + @Override public void deleteDiyPage(Long id) { // 校验存在 @@ -81,4 +106,18 @@ public class DiyPageServiceImpl implements DiyPageService { return diyPageMapper.selectPage(pageReqVO); } + @Override + public List getDiyPageByTemplateId(Long templateId) { + return diyPageMapper.selectListByTemplateId(templateId); + } + + @Override + public void updateDiyPageProperty(DiyPagePropertyUpdateRequestVO updateReqVO) { + // 校验存在 + validateDiyPageExists(updateReqVO.getId()); + // 更新 + DiyPageDO updateObj = DiyPageConvert.INSTANCE.convert(updateReqVO); + diyPageMapper.updateById(updateObj); + } + } 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 b8611a0a9..0bf45163f 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 @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.service.diy; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePropertyUpdateRequestVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateUpdateReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; @@ -60,4 +61,11 @@ public interface DiyTemplateService { */ void useDiyTemplate(Long id); + /** + * 更新装修模板属性 + * + * @param updateReqVO 更新信息 + */ + void updateDiyTemplateProperty(DiyTemplatePropertyUpdateRequestVO updateReqVO); + } 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 1e2de3ba4..500e237d3 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 @@ -1,22 +1,25 @@ package cn.iocoder.yudao.module.promotion.service.diy; import cn.hutool.core.util.BooleanUtil; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateCreateReqVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePageReqVO; +import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplatePropertyUpdateRequestVO; import cn.iocoder.yudao.module.promotion.controller.admin.diy.vo.template.DiyTemplateUpdateReqVO; +import cn.iocoder.yudao.module.promotion.convert.diy.DiyPageConvert; import cn.iocoder.yudao.module.promotion.convert.diy.DiyTemplateConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.diy.DiyTemplateDO; import cn.iocoder.yudao.module.promotion.dal.mysql.diy.DiyTemplateMapper; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.DIY_TEMPLATE_NOT_EXISTS; -import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.DIY_TEMPLATE_USED_CANNOT_DELETE; +import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; /** * 装修模板 Service 实现类 @@ -29,25 +32,63 @@ public class DiyTemplateServiceImpl implements DiyTemplateService { @Resource private DiyTemplateMapper diyTemplateMapper; + @Resource + private DiyPageService diyPageService; @Override public Long createDiyTemplate(DiyTemplateCreateReqVO createReqVO) { + // 校验名称唯一 + validateNameUnique(null, createReqVO.getName()); // 插入 DiyTemplateDO diyTemplate = DiyTemplateConvert.INSTANCE.convert(createReqVO); + diyTemplate.setProperty("{}"); diyTemplateMapper.insert(diyTemplate); + // 创建默认页面 + createDefaultPage(diyTemplate); // 返回 return diyTemplate.getId(); } + /** + * 创建模板下面的默认页面 + * 默认创建两个页面:首页、我的 + * + * @param diyTemplate 模板对象 + */ + private void createDefaultPage(DiyTemplateDO diyTemplate) { + String remark = String.format("模板【%s】自动创建", diyTemplate.getName()); + diyPageService.createDiyPage(DiyPageConvert.INSTANCE.convertCreateVo(diyTemplate.getId(), "首页", remark)); + diyPageService.createDiyPage(DiyPageConvert.INSTANCE.convertCreateVo(diyTemplate.getId(), "我的", remark)); + } + @Override public void updateDiyTemplate(DiyTemplateUpdateReqVO updateReqVO) { // 校验存在 validateDiyTemplateExists(updateReqVO.getId()); + // 校验名称唯一 + validateNameUnique(updateReqVO.getId(), updateReqVO.getName()); // 更新 DiyTemplateDO updateObj = DiyTemplateConvert.INSTANCE.convert(updateReqVO); diyTemplateMapper.updateById(updateObj); } + void validateNameUnique(Long id, String name) { + if (StrUtil.isBlank(name)) { + return; + } + DiyTemplateDO template = diyTemplateMapper.selectByName(name); + if (template == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的模板 + if (id == null) { + throw exception(DIY_TEMPLATE_NAME_USED, name); + } + if (!template.getId().equals(id)) { + throw exception(DIY_TEMPLATE_NAME_USED, name); + } + } + @Override public void deleteDiyTemplate(Long id) { // 校验存在 @@ -85,12 +126,33 @@ public class DiyTemplateServiceImpl implements DiyTemplateService { // 已使用的更新为未使用 DiyTemplateDO used = diyTemplateMapper.selectByUsed(true); if (used != null) { + // 如果 id 相同,说明未发生变化 + if (used.getId().equals(id)) { + return; + } this.updateUsed(used.getId(), false, null); } // 更新为已使用 this.updateUsed(id, true, LocalDateTime.now()); } + @Transactional(rollbackFor = Exception.class) + @Override + public void updateDiyTemplateProperty(DiyTemplatePropertyUpdateRequestVO updateReqVO) { + // 校验存在 + validateDiyTemplateExists(updateReqVO.getId()); + // 更新模板属性 + DiyTemplateDO updateObj = DiyTemplateConvert.INSTANCE.convert(updateReqVO); + diyTemplateMapper.updateById(updateObj); + } + + /** + * 更新模板是否使用 + * + * @param id 模板编号 + * @param used 是否使用 + * @param usedTime 使用时间 + */ private void updateUsed(Long id, Boolean used, LocalDateTime usedTime) { DiyTemplateDO updateObj = new DiyTemplateDO().setId(id) .setUsed(used).setUsedTime(usedTime);