From 82fabd96236fc937955b802e97cd0cf41baef102 Mon Sep 17 00:00:00 2001 From: xixiaowei Date: Mon, 27 Dec 2021 09:59:39 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=907.1.6=E3=80=91=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/SysThemeTemplateExceptionEnum.java | 7 +- .../SysThemeTemplateFieldExceptionEnum.java | 7 +- .../SysThemeTemplateRelExceptionEnum.java | 30 +++++ .../theme/SysThemeTemplateFieldRequest.java | 5 +- .../theme/SysThemeTemplateRelRequest.java | 40 ++++++ .../pojo/theme/SysThemeTemplateRequest.java | 7 ++ .../SysThemeTemplateFieldController.java | 39 +++++- .../SysThemeTemplateRelController.java | 51 ++++++++ .../theme/service/SysThemeService.java | 1 - .../service/SysThemeTemplateFieldService.java | 31 ++++- .../service/SysThemeTemplateRelService.java | 16 +++ .../service/SysThemeTemplateService.java | 2 +- .../service/impl/SysThemeServiceImpl.java | 1 - .../SysThemeTemplateFieldServiceImpl.java | 116 +++++++++++++++--- .../impl/SysThemeTemplateRelServiceImpl.java | 36 ++++++ .../impl/SysThemeTemplateServiceImpl.java | 34 ++--- 16 files changed, 372 insertions(+), 51 deletions(-) create mode 100644 kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateRelExceptionEnum.java create mode 100644 kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRelRequest.java create mode 100644 kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateRelController.java diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateExceptionEnum.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateExceptionEnum.java index 7b829a3d6..0bb9f204d 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateExceptionEnum.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateExceptionEnum.java @@ -27,7 +27,12 @@ public enum SysThemeTemplateExceptionEnum implements AbstractExceptionEnum { /** * 系统主题模板正在被使用,不允许操作 */ - TEMPLATE_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "113", "系统主题模板正在被使用,不允许操作"); + TEMPLATE_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "113", "系统主题模板正在被使用,不允许操作"), + + /** + * 系统主题模板没有属性,不允许启用 + */ + TEMPLATE_NOT_ATTRIBUTE(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "114", "系统主题模板没有属性,不允许启用"); /** * 错误编码 diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateFieldExceptionEnum.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateFieldExceptionEnum.java index 96e328406..a88558081 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateFieldExceptionEnum.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateFieldExceptionEnum.java @@ -17,7 +17,12 @@ public enum SysThemeTemplateFieldExceptionEnum implements AbstractExceptionEnum /** * 系统主题模板属性不存在 */ - FIELD_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "系统主题模板属性不存在"); + FIELD_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "101", "系统主题模板属性不存在"), + + /** + * 系统主题模板属性被使用 + */ + FIELD_IS_USED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "102", "系统主题模板属性正在被使用,不允许操作"); /** * 错误编码 diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateRelExceptionEnum.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateRelExceptionEnum.java new file mode 100644 index 000000000..24828d8d8 --- /dev/null +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/exception/enums/theme/SysThemeTemplateRelExceptionEnum.java @@ -0,0 +1,30 @@ +package cn.stylefeng.roses.kernel.system.api.exception.enums.theme; + +import cn.stylefeng.roses.kernel.rule.constants.RuleConstants; +import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; +import cn.stylefeng.roses.kernel.system.api.constants.SystemConstants; +import lombok.Getter; + +@Getter +public enum SysThemeTemplateRelExceptionEnum implements AbstractExceptionEnum { + + /** + * 系统主题模板属性关系不存在 + */ + RELATION_NOT_EXIST(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + SystemConstants.SYSTEM_EXCEPTION_STEP_CODE + "131", "系统主题模板属性关系不存在"); + + /** + * 错误编码 + */ + private final String errorCode; + + /** + * 提示用户信息 + */ + private final String userTip; + + SysThemeTemplateRelExceptionEnum(String errorCode, String userTip) { + this.errorCode = errorCode; + this.userTip = userTip; + } +} diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateFieldRequest.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateFieldRequest.java index 9fb87f352..616658f76 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateFieldRequest.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateFieldRequest.java @@ -28,7 +28,6 @@ public class SysThemeTemplateFieldRequest extends BaseRequest { /** * 模板ID */ - @NotNull(message = "模板ID不能为空", groups = {add.class, delete.class}) @ChineseDescription("模板ID") private Long templateId; @@ -39,6 +38,10 @@ public class SysThemeTemplateFieldRequest extends BaseRequest { @ChineseDescription("属性名称") private String fieldName; + @NotNull(message = "属性编码不能为空", groups = {add.class, edit.class}) + @ChineseDescription("属性编码") + private String fieldCode; + /** * 属性展示类型(字典维护) */ diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRelRequest.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRelRequest.java new file mode 100644 index 000000000..23e8bcd19 --- /dev/null +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRelRequest.java @@ -0,0 +1,40 @@ +package cn.stylefeng.roses.kernel.system.api.pojo.theme; + +import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; +import cn.stylefeng.roses.kernel.scanner.api.annotation.field.ChineseDescription; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * 系统主题模板属性关系参数 + * + * @author xixiaowei + * @date 2021/12/24 10:42 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class SysThemeTemplateRelRequest extends BaseRequest { + + /** + * 主键ID + */ + @ChineseDescription("主键ID") + private Long relationId; + + /** + * 模板ID + */ + @NotNull(message = "模板ID不能为空", groups = {add.class}) + @ChineseDescription("模板ID") + private Long templateId; + + /** + * 属性编码集合 + */ + @NotEmpty(message = "属性编码集合不能为空", groups = {add.class, delete.class}) + @ChineseDescription("属性编码集合") + private String[] fieldCodes; +} diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRequest.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRequest.java index 66d1c796f..7aea74411 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRequest.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/pojo/theme/SysThemeTemplateRequest.java @@ -32,6 +32,13 @@ public class SysThemeTemplateRequest extends BaseRequest { @ChineseDescription("主题模板名称") private String templateName; + /** + * 主题模板编码 + */ + @NotNull(message = "主题模板编码不能为空", groups = {add.class, edit.class}) + @ChineseDescription("主题模板编码") + private String templateCode; + /** * 主题模板类型:1-系统类型,2-业务类型 */ diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateFieldController.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateFieldController.java index 710ec6ac4..6ae7ab393 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateFieldController.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateFieldController.java @@ -63,13 +63,46 @@ public class SysThemeTemplateFieldController { } /** - * 查询系统主题模板属性 + * 查询系统主题模板属性详情 * * @author xixiaowei * @date 2021/12/17 11:49 */ - @GetResource(name = "查询系统主题模板属性", path = "/sysThemeTemplateField/detail") - public ResponseData detail(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) { + @GetResource(name = "查询系统主题模板属性详情", path = "/sysThemeTemplateField/detail") + public ResponseData detail(@Validated(SysThemeTemplateFieldRequest.detail.class) SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) { return new SuccessResponseData(sysThemeTemplateFieldService.detail(sysThemeTemplateFieldParam)); } + + /** + * 查询系统主题模板属性列表 + * + * @author xixiaowei + * @date 2021/12/24 9:47 + */ + @GetResource(name = "查询系统主题模板属性列表", path = "/sysThemeTemplateField/findPage") + public ResponseData findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) { + return new SuccessResponseData(sysThemeTemplateFieldService.findPage(sysThemeTemplateFieldParam)); + } + + /** + * 查询系统主题模板属性已有关系列表 + * + * @author xixiaowei + * @date 2021/12/24 14:42 + */ + @GetResource(name = "查询系统主题模板属性已有关系列表", path = "/sysThemeTemplateField/findRelList") + public ResponseData findRelPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) { + return new SuccessResponseData(sysThemeTemplateFieldService.findRelList(sysThemeTemplateFieldParam)); + } + + /** + * 查询系统主题模板属性未有关系列表 + * + * @author xixiaowei + * @date 2021/12/24 14:44 + */ + @GetResource(name = "查询系统主题模板属性未有关系列表", path = "/sysThemeTemplateField/findNotRelList") + public ResponseData findNotRelPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldParam) { + return new SuccessResponseData(sysThemeTemplateFieldService.findNotRelList(sysThemeTemplateFieldParam)); + } } diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateRelController.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateRelController.java new file mode 100644 index 000000000..9403db1b0 --- /dev/null +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/controller/SysThemeTemplateRelController.java @@ -0,0 +1,51 @@ +package cn.stylefeng.roses.kernel.system.modular.theme.controller; + +import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData; +import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData; +import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; +import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource; +import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest; +import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 系统主题模板属性关系控制器 + * + * @author xixiaowei + * @date 2021/12/24 10:55 + */ +@RestController +@ApiResource(name = "系统主题模板属性关系管理") +public class SysThemeTemplateRelController { + + @Resource + private SysThemeTemplateRelService sysThemeTemplateRelService; + + /** + * 增加系统主题模板属性关系 + * + * @author xixiaowei + * @date 2021/12/24 11:17 + */ + @PostResource(name = "增加系统主题模板属性关系", path = "/sysThemeTemplateRel/add") + public ResponseData add(@RequestBody @Validated(SysThemeTemplateRelRequest.add.class) SysThemeTemplateRelRequest sysThemeTemplateParam) { + sysThemeTemplateRelService.add(sysThemeTemplateParam); + return new SuccessResponseData(); + } + + /** + * 删除系统主题模板属性关系 + * + * @author xixiaowei + * @date 2021/12/24 11:23 + */ + @PostResource(name = "删除系统主题模板属性关系", path = "/sysThemeTemplateRel/del") + public ResponseData del(@RequestBody SysThemeTemplateRelRequest sysThemeTemplateRelParam) { + sysThemeTemplateRelService.del(sysThemeTemplateRelParam); + return new SuccessResponseData(); + } +} diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeService.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeService.java index 81b33f362..3248a032c 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeService.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeService.java @@ -5,7 +5,6 @@ import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeRequest; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme; import com.baomidou.mybatisplus.extension.service.IService; - /** * 系统主题service接口 * diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateFieldService.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateFieldService.java index 6444e6847..e059730fd 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateFieldService.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateFieldService.java @@ -1,9 +1,12 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service; +import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateFieldRequest; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** * 系统主题模板属性service接口 * @@ -37,10 +40,36 @@ public interface SysThemeTemplateFieldService extends IService findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest); + + + /** + * 查询系统主题模板属性已有关系列表 + * + * @author xixiaowei + * @date 2021/12/24 11:35 + */ + List findRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest); + + /** + * 查询系统主题模板属性未有关系列表 + * + * @author xixiaowei + * @date 2021/12/24 11:49 + */ + List findNotRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest); } diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateRelService.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateRelService.java index 63484b403..61acfd319 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateRelService.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateRelService.java @@ -1,5 +1,6 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service; +import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel; import com.baomidou.mybatisplus.extension.service.IService; @@ -11,4 +12,19 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface SysThemeTemplateRelService extends IService { + /** + * 增加系统主题模板属性关系 + * + * @author xixiaowei + * @date 2021/12/24 10:56 + */ + void add(SysThemeTemplateRelRequest sysThemeTemplateRelRequest); + + /** + * 删除系统主题模板属性关系 + * + * @author xixiaowei + * @date 2021/12/24 11:18 + */ + void del(SysThemeTemplateRelRequest sysThemeTemplateRelRequest); } diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateService.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateService.java index 38228d81f..caf40318d 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateService.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/SysThemeTemplateService.java @@ -41,7 +41,7 @@ public interface SysThemeTemplateService extends IService { void del(SysThemeTemplateRequest sysThemeTemplateRequest); /** - * 查找系统主题模板 + * 查询系统主题模板列表 * * @return 分页结果 * @author xixiaowei diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeServiceImpl.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeServiceImpl.java index b3a9823ea..5727a7fc5 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeServiceImpl.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeServiceImpl.java @@ -54,7 +54,6 @@ public class SysThemeServiceImpl extends ServiceImpl i public void add(SysThemeRequest sysThemeRequest) { // 查询模板状态 SysThemeTemplate sysThemeTemplate = sysThemeTemplateService.getById(sysThemeRequest.getTemplateId()); - // 判断模板启用状态:如果为禁用状态不允许使用 if (YesOrNotEnum.N.getCode().equals(sysThemeTemplate.getStatusFlag().toString())) { throw new SystemModularException(SysThemeExceptionEnum.THEME_TEMPLATE_IS_DISABLE); diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateFieldServiceImpl.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateFieldServiceImpl.java index 30af63a79..f92b438a8 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateFieldServiceImpl.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateFieldServiceImpl.java @@ -2,6 +2,10 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; +import cn.stylefeng.roses.kernel.db.api.factory.PageFactory; +import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory; +import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; import cn.stylefeng.roses.kernel.system.api.exception.SystemModularException; import cn.stylefeng.roses.kernel.system.api.exception.enums.theme.SysThemeTemplateFieldExceptionEnum; @@ -12,13 +16,14 @@ import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateFie import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService; import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.List; +import java.util.stream.Collectors; /** * 系统主题模板属性service接口实现类 @@ -33,47 +38,54 @@ public class SysThemeTemplateFieldServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); - queryWrapper.eq(SysThemeTemplateRel::getFieldCode, sysThemeTemplateField.getFieldCode()); - sysThemeTemplateRelService.remove(queryWrapper); + // 校验系统主题模板属性使用 + this.verificationAttributeUsage(sysThemeTemplateField); this.removeById(sysThemeTemplateField.getFieldId()); } + /** + * 校验系统主题模板属性使用 + * + * @author xixiaowei + * @date 2021/12/24 9:16 + */ + private void verificationAttributeUsage(SysThemeTemplateField sysThemeTemplateField) { + // 查询当前属性是否被使用 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysThemeTemplateRel::getFieldCode, sysThemeTemplateField.getFieldCode()); + + List themeTemplateRels = sysThemeTemplateRelService.list(queryWrapper); + + // 被使用,抛出异常 + if (themeTemplateRels.size() > 0) { + throw new SystemModularException(SysThemeTemplateFieldExceptionEnum.FIELD_IS_USED); + } + } + @Override public void edit(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) { SysThemeTemplateField sysThemeTemplateField = this.queryThemeTemplateFieldById(sysThemeTemplateFieldRequest); + // 校验系统主题模板属性使用 + this.verificationAttributeUsage(sysThemeTemplateField); + // 更新属性 BeanUtil.copyProperties(sysThemeTemplateFieldRequest, sysThemeTemplateField); @@ -88,6 +100,72 @@ public class SysThemeTemplateFieldServiceImpl extends ServiceImpl findPage(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + // 根据属性名称模糊查询 + queryWrapper.like(StrUtil.isNotBlank(sysThemeTemplateFieldRequest.getFieldName()), SysThemeTemplateField::getFieldName, sysThemeTemplateFieldRequest.getFieldName()); + + Page page = page(PageFactory.defaultPage(), queryWrapper); + + return PageResultFactory.createPageResult(page); + } + + @Override + public List findRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) { + List fieldCodes = this.getFieldCodes(sysThemeTemplateFieldRequest, sysThemeTemplateRelService); + + // 查询具体属性信息 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + List sysThemeTemplateFields = null; + // 如果关联属性非空,拼接查询条件 + if (fieldCodes.size() > 0) { + queryWrapper.in(SysThemeTemplateField::getFieldCode, fieldCodes); + sysThemeTemplateFields = this.list(queryWrapper); + } + + return sysThemeTemplateFields; + } + + /** + * 查询所有关联的属性编码 + * + * @author xixiaowei + * @date 2021/12/24 14:38 + */ + private List getFieldCodes(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest, SysThemeTemplateRelService sysThemeTemplateRelService) { + // 查询有关联的属性 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplateFieldRequest.getTemplateId()); + List sysThemeTemplateRels = sysThemeTemplateRelService.list(queryWrapper); + + // 过滤出所有的属性编码 + List fieldCodes = sysThemeTemplateRels.stream().map(SysThemeTemplateRel::getFieldCode).collect(Collectors.toList()); + + return fieldCodes; + } + + @Override + public List findNotRelList(SysThemeTemplateFieldRequest sysThemeTemplateFieldRequest) { + // 查询有关联的属性 + List fieldCodes = getFieldCodes(sysThemeTemplateFieldRequest, sysThemeTemplateRelService); + + // 查询没有关联的属性 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + + List sysThemeTemplateFields; + // 如果关联属性非空,拼接条件;否者查询全部 + if (fieldCodes.size() > 0) { + queryWrapper.notIn(SysThemeTemplateField::getFieldCode, fieldCodes); + sysThemeTemplateFields = this.list(queryWrapper); + } else { + sysThemeTemplateFields = this.list(); + } + + return sysThemeTemplateFields; + } + /** * 获取主题模板属性 * diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateRelServiceImpl.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateRelServiceImpl.java index e2257a166..7f1152421 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateRelServiceImpl.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateRelServiceImpl.java @@ -1,11 +1,16 @@ package cn.stylefeng.roses.kernel.system.modular.theme.service.impl; +import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRelRequest; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel; import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateRelMapper; import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; + /** * 系统主题模板属性关系service接口实现类 * @@ -15,4 +20,35 @@ import org.springframework.stereotype.Service; @Service public class SysThemeTemplateRelServiceImpl extends ServiceImpl implements SysThemeTemplateRelService { + @Override + public void add(SysThemeTemplateRelRequest sysThemeTemplateRelRequest) { + // 获取请求中的所有属性编码 + String[] fieldCodes = sysThemeTemplateRelRequest.getFieldCodes(); + + List sysThemeTemplateRels = new ArrayList<>(); + + // 填充对象 + for (String fieldCode : fieldCodes) { + SysThemeTemplateRel sysThemeTemplateRel = new SysThemeTemplateRel(); + sysThemeTemplateRel.setTemplateId(sysThemeTemplateRelRequest.getTemplateId()); + sysThemeTemplateRel.setFieldCode(fieldCode); + + sysThemeTemplateRels.add(sysThemeTemplateRel); + } + + // 保存关系 + this.saveBatch(sysThemeTemplateRels); + } + + @Override + public void del(SysThemeTemplateRelRequest sysThemeTemplateRelRequest) { + // 获取请求中的所有属性编码 + String[] fieldCodes = sysThemeTemplateRelRequest.getFieldCodes(); + + // 构建删除条件 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.in(SysThemeTemplateRel::getFieldCode, fieldCodes); + + this.remove(queryWrapper); + } } diff --git a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateServiceImpl.java b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateServiceImpl.java index e3845df6c..987189c82 100644 --- a/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateServiceImpl.java +++ b/kernel-s-system/system-business-theme/src/main/java/cn/stylefeng/roses/kernel/system/modular/theme/service/impl/SysThemeTemplateServiceImpl.java @@ -13,15 +13,12 @@ import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateDataDTO; import cn.stylefeng.roses.kernel.system.api.pojo.theme.SysThemeTemplateRequest; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysTheme; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplate; -import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateField; import cn.stylefeng.roses.kernel.system.modular.theme.entity.SysThemeTemplateRel; import cn.stylefeng.roses.kernel.system.modular.theme.mapper.SysThemeTemplateMapper; import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeService; -import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateFieldService; import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateRelService; import cn.stylefeng.roses.kernel.system.modular.theme.service.SysThemeTemplateService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; @@ -29,7 +26,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.List; -import java.util.stream.Collectors; /** * 系统主题模板service接口实现类 @@ -49,9 +45,6 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplate.getTemplateId()); - // 查询所有关联属性的编码 - List SysThemeTemplateRels = sysThemeTemplateRelService.list(queryWrapper.select(SysThemeTemplateRel::getFieldCode)); - List sysThemeTemplateFieldCodes = SysThemeTemplateRels.stream().map(SysThemeTemplateRel::getFieldCode).collect(Collectors.toList()); - - LambdaQueryWrapper delFieldWrapper = new LambdaQueryWrapper<>(); - delFieldWrapper.in(SysThemeTemplateField::getFieldCode, sysThemeTemplateFieldCodes); - - // 删除关联属性 - if (sysThemeTemplateFieldCodes.size() > 0) { - sysThemeTemplateFieldService.remove(delFieldWrapper); - } // 删除关联关系 sysThemeTemplateRelService.remove(queryWrapper); @@ -139,9 +119,19 @@ public class SysThemeTemplateServiceImpl extends ServiceImpl wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(SysThemeTemplateRel::getTemplateId, sysThemeTemplate.getTemplateId()); + + List sysThemeTemplateRels = sysThemeTemplateRelService.list(wrapper); + + if (sysThemeTemplateRels.size() <= 0) { + throw new SystemModularException(SysThemeTemplateExceptionEnum.TEMPLATE_NOT_ATTRIBUTE); + } + sysThemeTemplate.setStatusFlag(YesOrNotEnum.Y.getCode().charAt(0)); } - + this.updateById(sysThemeTemplate); }