【config】整理config模块的字段和业务

pull/3/head
fengshuonan 2020-12-19 16:05:26 +08:00
parent 0e7cb3897e
commit fd374e81fa
5 changed files with 197 additions and 205 deletions

View File

@ -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();
}
}

View File

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

View File

@ -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.
GunsAPACHE 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;
}

View File

@ -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<SysConfig> {
/**
*
*
* @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<SysConfig> {
*/
List<SysConfig> 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);
}

View File

@ -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<SysConfigMapper, SysConfig> 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<SysConfig> page(SysConfigParam sysConfigParam) {
LambdaQueryWrapper<SysConfig> wrapper = createWrapper(sysConfigParam);
@ -47,63 +113,6 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
return this.list(wrapper);
}
@Override
public SysConfig detail(SysConfigParam sysConfigParam) {
return this.querySysConfig(sysConfigParam);
}
@Override
public void add(SysConfigParam sysConfigParam) {
// 1.构造实体
SysConfig sysConfig = new SysConfig();
BeanUtil.copyProperties(sysConfigParam, sysConfig);
sysConfig.setStatus(StatusEnum.ENABLE.getCode());
// 2.保存到库中
this.save(sysConfig);
// 3.添加对应context
ConfigContext.me().putConfig(sysConfigParam.getCode(), sysConfigParam.getValue());
}
@Override
public void delete(SysConfigParam sysConfigParam) {
// 1.根据id获取常量
SysConfig sysConfig = this.querySysConfig(sysConfigParam);
// 2.不能删除系统参数
if (YesOrNotEnum.Y.getCode().equals(sysConfig.getSysFlag())) {
throw new ConfigException(CONFIG_SYS_CAN_NOT_DELETE);
}
// 3.设置状态为已删除
sysConfig.setStatus(StatusEnum.DISABLE.getCode());
this.updateById(sysConfig);
// 4.删除对应context
ConfigContext.me().deleteConfig(sysConfigParam.getCode());
}
@Override
public void edit(SysConfigParam sysConfigParam) {
// 1.根据id获取常量信息
SysConfig sysConfig = this.querySysConfig(sysConfigParam);
// 2.请求参数转化为实体
BeanUtil.copyProperties(sysConfigParam, sysConfig);
// 不能修改状态,用修改状态接口修改状态
sysConfig.setStatus(null);
// 3.更新记录
this.updateById(sysConfig);
// 4.更新对应常量context
ConfigContext.me().putConfig(sysConfigParam.getCode(), sysConfigParam.getValue());
}
/**
*
*
@ -111,10 +120,10 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* @date 2020/4/14 11:19
*/
private SysConfig querySysConfig(SysConfigParam sysConfigParam) {
SysConfig sysConfig = this.getById(sysConfigParam.getId());
if (ObjectUtil.isEmpty(sysConfig)) {
String userTip = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getId());
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, userTip);
SysConfig sysConfig = this.getById(sysConfigParam.getConfigId());
if (ObjectUtil.isEmpty(sysConfig) || sysConfig.getDelFlag().equals(YesOrNotEnum.Y.getCode())) {
String userTip = StrUtil.format(CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getConfigId());
throw new ConfigException(CONFIG_NOT_EXIST, userTip);
}
return sysConfig;
}
@ -130,13 +139,13 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
if (ObjectUtil.isNotNull(sysConfigParam)) {
// 如果名称不为空,则带上名称搜素搜条件
if (ObjectUtil.isNotEmpty(sysConfigParam.getName())) {
queryWrapper.like(SysConfig::getName, sysConfigParam.getName());
if (ObjectUtil.isNotEmpty(sysConfigParam.getConfigName())) {
queryWrapper.like(SysConfig::getConfigName, sysConfigParam.getConfigName());
}
// 如果常量编码不为空,则带上常量编码搜素搜条件
if (ObjectUtil.isNotEmpty(sysConfigParam.getCode())) {
queryWrapper.like(SysConfig::getCode, sysConfigParam.getCode());
if (ObjectUtil.isNotEmpty(sysConfigParam.getConfigCode())) {
queryWrapper.like(SysConfig::getConfigCode, sysConfigParam.getConfigCode());
}
// 如果分类编码不为空,则带上分类编码