From fd374e81fa6434609ff2609cd5b6c9f1aae95114 Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Sat, 19 Dec 2020 16:05:26 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90config=E3=80=91=E6=95=B4=E7=90=86confi?= =?UTF-8?q?g=E6=A8=A1=E5=9D=97=E7=9A=84=E5=AD=97=E6=AE=B5=E5=92=8C?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/SysConfigController.java | 95 +++++------ .../config/modular/entity/SysConfig.java | 28 ++-- .../config/modular/param/SysConfigParam.java | 52 ++---- .../modular/service/SysConfigService.java | 76 ++++----- .../service/impl/SysConfigServiceImpl.java | 151 ++++++++++-------- 5 files changed, 197 insertions(+), 205 deletions(-) diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/SysConfigController.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/SysConfigController.java index 4240deedd..61fc00eff 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/SysConfigController.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/SysConfigController.java @@ -27,6 +27,54 @@ public class SysConfigController { @Resource private SysConfigService sysConfigService; + /** + * 添加系统参数配置 + * + * @author fengshuonan + * @date 2020/4/14 11:11 + */ + @PostResource(name = "添加系统参数配置", path = "/sysConfig/add") + public ResponseData add(@RequestBody @Validated(SysConfigParam.add.class) SysConfigParam sysConfigParam) { + sysConfigService.add(sysConfigParam); + return new SuccessResponseData(); + } + + /** + * 编辑系统参数配置 + * + * @author fengshuonan + * @date 2020/4/14 11:11 + */ + @PostResource(name = "编辑系统参数配置", path = "/sysConfig/edit") + public ResponseData edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) { + sysConfigService.edit(sysConfigParam); + return new SuccessResponseData(); + } + + /** + * 删除系统参数配置 + * + * @author fengshuonan + * @date 2020/4/14 11:11 + */ + @PostResource(name = "删除系统参数配置", path = "/sysConfig/delete") + public ResponseData delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) { + sysConfigService.delete(sysConfigParam); + return new SuccessResponseData(); + } + + /** + * 查看系统参数配置 + * + * @author fengshuonan + * @date 2020/4/14 11:12 + */ + @GetResource(name = "查看系统参数配置", path = "/sysConfig/detail") + public ResponseData detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) { + return new SuccessResponseData(sysConfigService.detail(sysConfigParam)); + } + + /** * 分页查询配置列表 * @@ -49,53 +97,6 @@ public class SysConfigController { return new SuccessResponseData(sysConfigService.list(sysConfigParam)); } - /** - * 查看系统参数配置 - * - * @author fengshuonan - * @date 2020/4/14 11:12 - */ - @GetResource(name = "查看系统参数配置", path = "/sysConfig/detail") - public ResponseData detail(@Validated(SysConfigParam.detail.class) SysConfigParam sysConfigParam) { - return new SuccessResponseData(sysConfigService.detail(sysConfigParam)); - } - - /** - * 添加系统参数配置 - * - * @author fengshuonan - * @date 2020/4/14 11:11 - */ - @PostResource(name = "添加系统参数配置", path = "/sysConfig/add") - public ResponseData add(@RequestBody @Validated(SysConfigParam.add.class) SysConfigParam sysConfigParam) { - sysConfigService.add(sysConfigParam); - return new SuccessResponseData(); - } - - /** - * 删除系统参数配置 - * - * @author fengshuonan - * @date 2020/4/14 11:11 - */ - @PostResource(name = "删除系统参数配置", path = "/sysConfig/delete") - public ResponseData delete(@RequestBody @Validated(SysConfigParam.delete.class) SysConfigParam sysConfigParam) { - sysConfigService.delete(sysConfigParam); - return new SuccessResponseData(); - } - - /** - * 编辑系统参数配置 - * - * @author fengshuonan - * @date 2020/4/14 11:11 - */ - @PostResource(name = "编辑系统参数配置", path = "/sysConfig/edit") - public ResponseData edit(@RequestBody @Validated(SysConfigParam.edit.class) SysConfigParam sysConfigParam) { - sysConfigService.edit(sysConfigParam); - return new SuccessResponseData(); - } - } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/entity/SysConfig.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/entity/SysConfig.java index 30a7020ce..5306ebed1 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/entity/SysConfig.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/entity/SysConfig.java @@ -24,11 +24,11 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意 */ package cn.stylefeng.roses.kernel.config.modular.entity; +import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity; import lombok.Data; import lombok.EqualsAndHashCode; @@ -48,29 +48,29 @@ public class SysConfig extends BaseEntity { /** * 主键 */ - @TableId(type = IdType.ASSIGN_ID) - private Long id; + @TableId(value = "config_id", type = IdType.ASSIGN_ID) + private Long configId; /** * 名称 */ - @TableField("name") - private String name; + @TableField("config_name") + private String configName; /** * 编码 */ - @TableField("code") - private String code; + @TableField("config_code") + private String configCode; /** * 属性值 */ - @TableField("value") - private String value; + @TableField("config_value") + private String configValue; /** - * 是否是系统参数(Y-是,N-否) + * 是否是系统参数:Y-是,N-否 */ @TableField("sys_flag") private String sysFlag; @@ -82,10 +82,10 @@ public class SysConfig extends BaseEntity { private String remark; /** - * 状态(字典 1正常 2停用) + * 状态:1-正常,2停用 */ - @TableField("status") - private Integer status; + @TableField("status_flag") + private Integer statusFlag; /** * 常量所属分类的编码,来自于“常量的分类”字典 @@ -94,7 +94,7 @@ public class SysConfig extends BaseEntity { private String groupCode; /** - * 是否删除(Y-已删除,N-未删除) + * 是否删除:Y-被删除,N-未删除 */ @TableField("del_flag") private String delFlag; diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/param/SysConfigParam.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/param/SysConfigParam.java index 2af564faf..49e8add03 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/param/SysConfigParam.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/param/SysConfigParam.java @@ -1,27 +1,3 @@ -/* -Copyright [2020] [https://www.stylefeng.cn] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点: - -1.请不要删除和修改根目录下的LICENSE文件。 -2.请不要删除和修改Guns源码头部的版权声明。 -3.请保留源码和相关描述文件的项目出处,作者声明等。 -4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns-separation -5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns-separation -6.若您的项目无法满足以上几点,可申请商业授权,获取Guns商业授权许可,请在官网购买授权,地址为 https://www.stylefeng.cn - */ package cn.stylefeng.roses.kernel.config.modular.param; import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest; @@ -45,29 +21,29 @@ public class SysConfigParam extends BaseRequest { /** * 主键 */ - @NotNull(message = "id不能为空,请检查id参数", groups = {edit.class, delete.class, detail.class}) - private Long id; + @NotNull(message = "configId不能为空", groups = {edit.class, delete.class, detail.class}) + private Long configId; /** * 名称 */ - @NotBlank(message = "名称不能为空,请检查name参数", groups = {add.class, edit.class}) - private String name; + @NotBlank(message = "名称不能为空", groups = {add.class, edit.class}) + private String configName; /** * 编码 */ - @NotBlank(message = "编码不能为空,请检查code参数", groups = {add.class, edit.class}) - private String code; + @NotBlank(message = "编码不能为空", groups = {add.class, edit.class}) + private String configCode; /** - * 值 + * 配置值 */ - @NotBlank(message = "值不能为空,请检查value参数", groups = {add.class, edit.class}) - private String value; + @NotBlank(message = "配置值不能为空", groups = {add.class, edit.class}) + private String configValue; /** - * 是否是系统参数(Y-是,N-否) + * 是否是系统参数:Y-是,N-否 */ @NotBlank(message = "是否是系统参数不能为空,请检查sysFlag参数", groups = {add.class, edit.class}) @FlagValue(message = "是否是系统参数格式错误,正确格式应该Y或者N,请检查sysFlag参数", groups = {add.class, edit.class}) @@ -78,9 +54,15 @@ public class SysConfigParam extends BaseRequest { */ private String remark; + /** + * 状态:1-正常,2停用 + */ + private Integer statusFlag; + /** * 常量所属分类的编码,来自于“常量的分类”字典 */ - @NotBlank(message = "值不能为空,请检查value参数", groups = {add.class, edit.class}) + @NotBlank(message = "量所属分类的编码不能为空", groups = {add.class, edit.class}) private String groupCode; + } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java index 767a99855..d567b875b 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/SysConfigService.java @@ -24,10 +24,10 @@ Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意 */ package cn.stylefeng.roses.kernel.config.modular.service; -import com.baomidou.mybatisplus.extension.service.IService; import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig; import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam; import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult; +import com.baomidou.mybatisplus.extension.service.IService; import java.util.List; @@ -39,6 +39,43 @@ import java.util.List; */ public interface SysConfigService extends IService { + /** + * 添加系统参数配置 + * + * @param sysConfigParam 添加参数 + * @author fengshuonan + * @date 2020/4/14 11:14 + */ + void add(SysConfigParam sysConfigParam); + + /** + * 编辑系统参数配置 + * + * @param sysConfigParam 编辑参数 + * @author fengshuonan + * @date 2020/4/14 11:15 + */ + void edit(SysConfigParam sysConfigParam); + + /** + * 删除系统参数配置 + * + * @param sysConfigParam 删除参数 + * @author fengshuonan + * @date 2020/4/14 11:15 + */ + void delete(SysConfigParam sysConfigParam); + + /** + * 查看系统参数配置 + * + * @param sysConfigParam 查看参数 + * @return 系统参数配置 + * @author fengshuonan + * @date 2020/4/14 11:15 + */ + SysConfig detail(SysConfigParam sysConfigParam); + /** * 查询系统参数配置 * @@ -59,41 +96,4 @@ public interface SysConfigService extends IService { */ List list(SysConfigParam sysConfigParam); - /** - * 查看系统参数配置 - * - * @param sysConfigParam 查看参数 - * @return 系统参数配置 - * @author fengshuonan - * @date 2020/4/14 11:15 - */ - SysConfig detail(SysConfigParam sysConfigParam); - - /** - * 添加系统参数配置 - * - * @param sysConfigParam 添加参数 - * @author fengshuonan - * @date 2020/4/14 11:14 - */ - void add(SysConfigParam sysConfigParam); - - /** - * 删除系统参数配置 - * - * @param sysConfigParam 删除参数 - * @author fengshuonan - * @date 2020/4/14 11:15 - */ - void delete(SysConfigParam sysConfigParam); - - /** - * 编辑系统参数配置 - * - * @param sysConfigParam 编辑参数 - * @author fengshuonan - * @date 2020/4/14 11:15 - */ - void edit(SysConfigParam sysConfigParam); - } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java index a61f83bb0..fdf782afa 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/SysConfigServiceImpl.java @@ -3,25 +3,26 @@ package cn.stylefeng.roses.kernel.config.modular.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.config.modular.mapper.SysConfigMapper; -import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import cn.stylefeng.roses.kernel.config.api.context.ConfigContext; import cn.stylefeng.roses.kernel.config.api.exception.ConfigException; -import cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExceptionEnum; import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig; +import cn.stylefeng.roses.kernel.config.modular.mapper.SysConfigMapper; import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam; +import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService; 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.StatusEnum; import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +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 java.util.List; +import static cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExceptionEnum.CONFIG_NOT_EXIST; import static cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExceptionEnum.CONFIG_SYS_CAN_NOT_DELETE; @@ -34,6 +35,71 @@ import static cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExcepti @Service public class SysConfigServiceImpl extends ServiceImpl implements SysConfigService { + @Override + @Transactional(rollbackFor = Exception.class) + public void add(SysConfigParam sysConfigParam) { + + // 1.构造实体 + SysConfig sysConfig = new SysConfig(); + BeanUtil.copyProperties(sysConfigParam, sysConfig); + sysConfig.setStatusFlag(StatusEnum.ENABLE.getCode()); + + // 2.保存到库中 + this.save(sysConfig); + + // 3.添加对应context + ConfigContext.me().putConfig(sysConfigParam.getConfigCode(), sysConfigParam.getConfigValue()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void edit(SysConfigParam sysConfigParam) { + + // 1.根据id获取常量信息 + SysConfig sysConfig = this.querySysConfig(sysConfigParam); + + // 2.请求参数转化为实体 + BeanUtil.copyProperties(sysConfigParam, sysConfig); + // 不能修改状态,用修改状态接口修改状态 + sysConfig.setStatusFlag(null); + + // 3.更新记录 + this.updateById(sysConfig); + + // 4.更新对应常量context + ConfigContext.me().putConfig(sysConfigParam.getConfigCode(), sysConfigParam.getConfigValue()); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void delete(SysConfigParam sysConfigParam) { + + // 1.根据id获取常量 + SysConfig sysConfig = this.querySysConfig(sysConfigParam); + if (sysConfig == null) { + String userTip = StrUtil.format(CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getConfigId()); + throw new ConfigException(CONFIG_NOT_EXIST, userTip); + } + + // 2.不能删除系统参数 + if (YesOrNotEnum.Y.getCode().equals(sysConfig.getSysFlag())) { + throw new ConfigException(CONFIG_SYS_CAN_NOT_DELETE); + } + + // 3.设置状态为已删除 + sysConfig.setStatusFlag(StatusEnum.DISABLE.getCode()); + sysConfig.setDelFlag(YesOrNotEnum.Y.getCode()); + this.updateById(sysConfig); + + // 4.删除对应context + ConfigContext.me().deleteConfig(sysConfigParam.getConfigCode()); + } + + @Override + public SysConfig detail(SysConfigParam sysConfigParam) { + return this.querySysConfig(sysConfigParam); + } + @Override public PageResult page(SysConfigParam sysConfigParam) { LambdaQueryWrapper wrapper = createWrapper(sysConfigParam); @@ -47,63 +113,6 @@ public class SysConfigServiceImpl extends ServiceImpl