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