This commit is contained in:
sxu 2024-09-26 16:22:00 +08:00
parent 48a4ab38ab
commit 6c4b379203
9 changed files with 239 additions and 910 deletions

View File

@ -1,169 +1,113 @@
package com.bonus.material.screen.controller; package com.bonus.material.screen.controller;
import com.bonus.common.core.utils.poi.ExcelUtil; import java.util.List;
import com.bonus.common.core.web.controller.BaseController; import javax.servlet.http.HttpServletResponse;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.OperaType; import com.bonus.common.log.enums.OperaType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.security.annotation.RequiresPermissions; import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.common.security.utils.SecurityUtils;
import com.bonus.material.screen.domain.BmConfig; import com.bonus.material.screen.domain.BmConfig;
import com.bonus.material.screen.service.IBmConfigService; import com.bonus.material.screen.service.IBmConfigService;
import lombok.extern.slf4j.Slf4j; import com.bonus.common.core.web.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired; import com.bonus.common.core.web.domain.AjaxResult;
import org.springframework.validation.annotation.Validated; import com.bonus.common.core.utils.poi.ExcelUtil;
import org.springframework.web.bind.annotation.*; import com.bonus.common.core.web.page.TableDataInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/** /**
* 参数配置 信息操作处理 * 功能参数配置Controller
* *
* @author bonus * @author xsheng
* @date 2024-09-26
*/ */
@Api(tags = "功能参数配置接口")
@RestController @RestController
@RequestMapping("/config") @RequestMapping("/config")
@Slf4j public class BmConfigController extends BaseController
public class BmConfigController extends BaseController { {
@Autowired @Autowired
private IBmConfigService bmConfigService; private IBmConfigService bmConfigService;
/** /**
* 获取参数配置列表 * 查询功能参数配置列表
*/ */
@ApiOperation(value = "查询功能参数配置列表")
@RequiresPermissions("screen:config:list")
// @ApiOperation("获取参数配置列表")
@RequiresPermissions("material:config:list")
@GetMapping("/list") @GetMapping("/list")
@SysLog(title = "参数配置", businessType = OperaType.QUERY,logType = 0,module = "系统管理->参数配置") public TableDataInfo list(BmConfig bmConfig)
// @ApiResponses(value = { {
// @ApiResponse(code = 200, message = "成功", response = TableDataInfo.class),
// @ApiResponse(code = 400, message = "无效的ID"),
// @ApiResponse(code = 404, message = "未找到用户")
// })
public TableDataInfo list(BmConfig config) {
try{
startPage(); startPage();
List<BmConfig> list = bmConfigService.selectConfigList(config); List<BmConfig> list = bmConfigService.selectBmConfigList(bmConfig);
return getDataTable(list); return getDataTable(list);
}catch (Exception e){
log.error(e.toString(),e);
}
return getDataTableError(new ArrayList<BmConfig>());
} }
@RequiresPermissions("material:config:export") /**
* 导出功能参数配置列表
*/
@ApiOperation(value = "导出功能参数配置列表")
@RequiresPermissions("screen:config:export")
@SysLog(title = "功能参数配置", businessType = OperaType.EXPORT, logType = 1,module = "仓储管理->导出功能参数配置")
@PostMapping("/export") @PostMapping("/export")
@SysLog(title = "参数配置", businessType = OperaType.EXPORT,logType = 0,module = "系统管理->参数配置") public void export(HttpServletResponse response, BmConfig bmConfig)
public void export(HttpServletResponse response, BmConfig config) { {
try{ List<BmConfig> list = bmConfigService.selectBmConfigList(bmConfig);
List<BmConfig> list = bmConfigService.selectConfigList(config);
ExcelUtil<BmConfig> util = new ExcelUtil<BmConfig>(BmConfig.class); ExcelUtil<BmConfig> util = new ExcelUtil<BmConfig>(BmConfig.class);
util.exportExcel(response, list, "参数数据"); util.exportExcel(response, list, "功能参数配置数据");
}catch (Exception e){
ExcelUtil<BmConfig> util = new ExcelUtil<BmConfig>(BmConfig.class);
util.exportExcel(response, new ArrayList<BmConfig>(), "参数数据");
log.error(e.toString(),e);
}
} }
/** /**
* 根据参数编号获取详细信息 * 获取功能参数配置详细信息
*/ */
@GetMapping(value = "/{configId}") @ApiOperation(value = "获取功能参数配置详细信息")
public AjaxResult getInfo(@PathVariable Long configId) { @RequiresPermissions("screen:config:query")
try{ @GetMapping(value = "/{id}")
return success(bmConfigService.selectConfigById(configId)); public AjaxResult getInfo(@PathVariable("id") Long id)
}catch (Exception e){ {
log.error(e.toString(),e); return success(bmConfigService.selectBmConfigById(id));
return error("系统异常");
}
} }
/** /**
* 根据参数键名查询参数值 * 新增功能参数配置
*/ */
@GetMapping(value = "/configKey/{configKey}") @ApiOperation(value = "新增功能参数配置")
public AjaxResult getConfigKey(@PathVariable String configKey) { @RequiresPermissions("screen:config:add")
try{ @SysLog(title = "功能参数配置", businessType = OperaType.INSERT, logType = 1,module = "仓储管理->新增功能参数配置")
return success(bmConfigService.selectConfigByKey(configKey));
}catch (Exception e){
log.error(e.toString(),e);
return error("系统异常");
}
}
/**
* 新增参数配置
*/
@RequiresPermissions("material:config:add")
@SysLog(title = "参数配置", businessType = OperaType.INSERT,logType = 0,module = "系统管理->参数配置")
@PostMapping @PostMapping
public AjaxResult add(@Validated @RequestBody BmConfig config) { public AjaxResult add(@RequestBody BmConfig bmConfig)
try{ {
if (!bmConfigService.checkConfigKeyUnique(config)) { return toAjax(bmConfigService.insertBmConfig(bmConfig));
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setCreateBy(SecurityUtils.getUsername());
return toAjax(bmConfigService.insertConfig(config));
}catch (Exception e){
log.error(e.toString(),e);
return error("系统异常");
}
} }
/** /**
* 修改参数配置 * 修改功能参数配置
*/ */
@RequiresPermissions("material:config:edit") @ApiOperation(value = "修改功能参数配置")
@RequiresPermissions("screen:config:edit")
@SysLog(title = "功能参数配置", businessType = OperaType.UPDATE, logType = 1,module = "仓储管理->修改功能参数配置")
@PutMapping @PutMapping
@SysLog(title = "参数配置", businessType = OperaType.UPDATE,logType = 0,module = "系统管理->参数配置") public AjaxResult edit(@RequestBody BmConfig bmConfig)
public AjaxResult edit(@Validated @RequestBody BmConfig config) { {
try{ return toAjax(bmConfigService.updateBmConfig(bmConfig));
if (!bmConfigService.checkConfigKeyUnique(config)) {
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
}
config.setUpdateBy(SecurityUtils.getUsername());
return toAjax(bmConfigService.updateConfig(config));
}catch (Exception e){
log.error(e.toString(),e);
return error("系统异常");
}
} }
/** /**
* 删除参数配置 * 删除功能参数配置
*/ */
@RequiresPermissions("material:config:remove") @ApiOperation(value = "删除功能参数配置")
@SysLog(title = "参数配置", businessType = OperaType.DELETE,logType = 0,module = "系统管理->参数配置") @RequiresPermissions("screen:config:remove")
@DeleteMapping("/{configIds}") @SysLog(title = "功能参数配置", businessType = OperaType.DELETE, logType = 1,module = "仓储管理->删除功能参数配置")
public AjaxResult remove(@PathVariable Long[] configIds) { @DeleteMapping("/{ids}")
try{ public AjaxResult remove(@PathVariable Long[] ids)
bmConfigService.deleteConfigByIds(configIds); {
return success(); return toAjax(bmConfigService.deleteBmConfigByIds(ids));
}catch (Exception e){
log.error(e.toString(),e);
return error("系统异常");
}
}
/**
* 刷新参数缓存
*/
@RequiresPermissions("material:config:remove")
@DeleteMapping("/refreshCache")
@SysLog(title = "参数配置", businessType = OperaType.FLASH,logType = 0,module = "系统管理->参数配置",details = "刷新参数缓存")
public AjaxResult refreshCache() {
try{
bmConfigService.resetConfigCache();
return success();
}catch (Exception e){
log.error(e.toString(),e);
return error("系统异常");
}
} }
} }

View File

@ -1,115 +1,37 @@
package com.bonus.material.screen.domain; package com.bonus.material.screen.domain;
import com.bonus.common.core.annotation.Excel; import com.bonus.common.core.annotation.Excel;
import com.bonus.common.core.annotation.Excel.ColumnType; import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.ToString;
import com.bonus.common.core.web.domain.BaseEntity; import com.bonus.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
/** /**
* 参数配置表 bm_config * 功能参数配置对象 bm_config
* *
* @author bonus * @author xsheng
* @date 2024-09-26
*/ */
@Data
@ToString
public class BmConfig extends BaseEntity public class BmConfig extends BaseEntity
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
//用于excel导出的序号一列,不需要业务逻辑处理
@Excel(name = "序号", isSequence = true, type = Excel.Type.EXPORT)
int sequence;
/** 参数主键 */ /** 参数主键 */
@Excel(name = "参数主键", cellType = ColumnType.NUMERIC) private Long id;
private Long configId;
/** 参数名称 */
@Excel(name = "参数名称")
private String configName;
/** 参数键名 */ /** 参数键名 */
@Excel(name = "参数键名") @Excel(name = "参数键名")
private String configKey; @ApiModelProperty(value = "参数键名")
private String itemName;
/** 参数键值 */ /** 参数键值 */
@Excel(name = "参数键值") @Excel(name = "参数键值")
private String configValue; @ApiModelProperty(value = "参数键值")
private String itemValue;
/** 系统内置Y是 N否 */
@Excel(name = "系统内置", readConverterExp = "Y=是,N=否")
private String configType;
public Long getConfigId()
{
return configId;
}
public void setConfigId(Long configId)
{
this.configId = configId;
}
@NotBlank(message = "参数名称不能为空")
@Size(min = 0, max = 100, message = "参数名称不能超过100个字符")
public String getConfigName()
{
return configName;
}
public void setConfigName(String configName)
{
this.configName = configName;
}
@NotBlank(message = "参数键名长度不能为空")
@Size(min = 0, max = 100, message = "参数键名长度不能超过100个字符")
public String getConfigKey()
{
return configKey;
}
public void setConfigKey(String configKey)
{
this.configKey = configKey;
}
@NotBlank(message = "参数键值不能为空")
@Size(min = 0, max = 500, message = "参数键值长度不能超过500个字符")
public String getConfigValue()
{
return configValue;
}
public void setConfigValue(String configValue)
{
this.configValue = configValue;
}
public String getConfigType()
{
return configType;
}
public void setConfigType(String configType)
{
this.configType = configType;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("configId", getConfigId())
.append("configName", getConfigName())
.append("configKey", getConfigKey())
.append("configValue", getConfigValue())
.append("configType", getConfigType())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("remark", getRemark())
.toString();
}
} }

View File

@ -1,106 +0,0 @@
package com.bonus.material.screen.domain.vo;
import com.bonus.common.core.utils.StringUtils;
/**
* 路由显示信息
*
* @author bonus
*/
public class MetaVo
{
/**
* 设置该路由在侧边栏和面包屑中展示的名字
*/
private String title;
/**
* 设置该路由的图标对应路径src/assets/icons/svg
*/
private String icon;
/**
* 设置为true则不会被 <keep-alive>缓存
*/
private boolean noCache;
/**
* 内链地址http(s)://开头
*/
private String link;
public MetaVo()
{
}
public MetaVo(String title, String icon)
{
this.title = title;
this.icon = icon;
}
public MetaVo(String title, String icon, boolean noCache)
{
this.title = title;
this.icon = icon;
this.noCache = noCache;
}
public MetaVo(String title, String icon, String link)
{
this.title = title;
this.icon = icon;
this.link = link;
}
public MetaVo(String title, String icon, boolean noCache, String link)
{
this.title = title;
this.icon = icon;
this.noCache = noCache;
if (StringUtils.ishttp(link))
{
this.link = link;
}
}
public boolean isNoCache()
{
return noCache;
}
public void setNoCache(boolean noCache)
{
this.noCache = noCache;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getIcon()
{
return icon;
}
public void setIcon(String icon)
{
this.icon = icon;
}
public String getLink()
{
return link;
}
public void setLink(String link)
{
this.link = link;
}
}

View File

@ -1,149 +0,0 @@
package com.bonus.material.screen.domain.vo;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.List;
/**
* 路由配置信息
*
* @author bonus
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class RouterVo
{
/**
* 路由名字
*/
private String name;
/**
* 路由地址
*/
private String path;
/**
* 是否隐藏路由当设置 true 的时候该路由不会再侧边栏出现
*/
private boolean hidden;
/**
* 重定向地址当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
*/
private String redirect;
/**
* 组件地址
*/
private String component;
/**
* 路由参数 {"id": 1, "name": "ry"}
*/
private String query;
/**
* 当你一个路由下面的 children 声明的路由大于1个时自动会变成嵌套的模式--如组件页面
*/
private Boolean alwaysShow;
/**
* 其他元素
*/
private MetaVo meta;
/**
* 子路由
*/
private List<RouterVo> children;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getPath()
{
return path;
}
public void setPath(String path)
{
this.path = path;
}
public boolean getHidden()
{
return hidden;
}
public void setHidden(boolean hidden)
{
this.hidden = hidden;
}
public String getRedirect()
{
return redirect;
}
public void setRedirect(String redirect)
{
this.redirect = redirect;
}
public String getComponent()
{
return component;
}
public void setComponent(String component)
{
this.component = component;
}
public String getQuery()
{
return query;
}
public void setQuery(String query)
{
this.query = query;
}
public Boolean getAlwaysShow()
{
return alwaysShow;
}
public void setAlwaysShow(Boolean alwaysShow)
{
this.alwaysShow = alwaysShow;
}
public MetaVo getMeta()
{
return meta;
}
public void setMeta(MetaVo meta)
{
this.meta = meta;
}
public List<RouterVo> getChildren()
{
return children;
}
public void setChildren(List<RouterVo> children)
{
this.children = children;
}
}

View File

@ -1,87 +0,0 @@
package com.bonus.material.screen.domain.vo;
import com.bonus.system.api.domain.SysDept;
import com.bonus.system.api.domain.SysMenu;
import com.fasterxml.jackson.annotation.JsonInclude;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/**
* Treeselect树结构实体类
*
* @author bonus
*/
public class TreeSelect implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 节点ID
*/
private Long id;
/**
* 节点名称
*/
private String label;
private String status;
/**
* 子节点
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> children;
public TreeSelect() {
}
public TreeSelect(SysDept dept) {
this.id = dept.getDeptId();
this.status = dept.getStatus();
this.label = dept.getDeptName();
this.children = dept.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public TreeSelect(SysMenu menu) {
this.id = menu.getMenuId();
this.label = menu.getMenuName();
this.status = menu.getStatus();
this.children = menu.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList());
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public List<TreeSelect> getChildren() {
return children;
}
public void setChildren(List<TreeSelect> children) {
this.children = children;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View File

@ -1,76 +1,61 @@
package com.bonus.material.screen.mapper; package com.bonus.material.screen.mapper;
import com.bonus.material.screen.domain.BmConfig;
import java.util.List; import java.util.List;
import com.bonus.material.screen.domain.BmConfig;
/** /**
* 参数配置 数据层 * 功能参数配置Mapper接口
* *
* @author bonus * @author xsheng
* @date 2024-09-26
*/ */
public interface BmConfigMapper public interface BmConfigMapper
{ {
/** /**
* 查询参数配置信息 * 查询功能参数配置
* *
* @param config 参数配置信息 * @param id 功能参数配置主键
* @return 参数配置信息 * @return 功能参数配置
*/ */
public BmConfig selectConfig(BmConfig config); public BmConfig selectBmConfigById(Long id);
/** /**
* 通过ID查询配置 * 查询功能参数配置列表
* *
* @param configId 参数ID * @param bmConfig 功能参数配置
* @return 参数配置信息 * @return 功能参数配置集合
*/ */
public BmConfig selectConfigById(Long configId); public List<BmConfig> selectBmConfigList(BmConfig bmConfig);
/** /**
* 查询参数配置列表 * 新增功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 参数配置集合
*/
public List<BmConfig> selectConfigList(BmConfig config);
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数键名
* @return 参数配置信息
*/
public BmConfig checkConfigKeyUnique(String configKey);
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果 * @return 结果
*/ */
public int insertConfig(BmConfig config); public int insertBmConfig(BmConfig bmConfig);
/** /**
* 修改参数配置 * 修改功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 结果 * @return 结果
*/ */
public int updateConfig(BmConfig config); public int updateBmConfig(BmConfig bmConfig);
/** /**
* 删除参数配置 * 删除功能参数配置
* *
* @param configId 参数ID * @param id 功能参数配置主键
* @return 结果 * @return 结果
*/ */
public int deleteConfigById(Long configId); public int deleteBmConfigById(Long id);
/** /**
* 批量删除参数信息 * 批量删除功能参数配置
* *
* @param configIds 需要删除的参数ID * @param ids 需要删除的数据主键集合
* @return 结果 * @return 结果
*/ */
public int deleteConfigByIds(Long[] configIds); public int deleteBmConfigByIds(Long[] ids);
} }

View File

@ -1,83 +1,61 @@
package com.bonus.material.screen.service; package com.bonus.material.screen.service;
import java.util.List;
import com.bonus.material.screen.domain.BmConfig; import com.bonus.material.screen.domain.BmConfig;
import java.util.List;
/** /**
* 参数配置 服务层 * 功能参数配置Service接口
* *
* @author bonus * @author xsheng
* @date 2024-09-26
*/ */
public interface IBmConfigService public interface IBmConfigService
{ {
/** /**
* 查询参数配置信息 * 查询功能参数配置
* *
* @param configId 参数配置ID * @param id 功能参数配置主键
* @return 参数配置信息 * @return 功能参数配置
*/ */
public BmConfig selectConfigById(Long configId); public BmConfig selectBmConfigById(Long id);
/** /**
* 根据键名查询参数配置信息 * 查询功能参数配置列表
* *
* @param configKey 参数键名 * @param bmConfig 功能参数配置
* @return 参数键值 * @return 功能参数配置集合
*/ */
public String selectConfigByKey(String configKey); public List<BmConfig> selectBmConfigList(BmConfig bmConfig);
/** /**
* 查询参数配置列表 * 新增功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 参数配置集合
*/
public List<BmConfig> selectConfigList(BmConfig config);
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果 * @return 结果
*/ */
public int insertConfig(BmConfig config); public int insertBmConfig(BmConfig bmConfig);
/** /**
* 修改参数配置 * 修改功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 结果 * @return 结果
*/ */
public int updateConfig(BmConfig config); public int updateBmConfig(BmConfig bmConfig);
/** /**
* 批量删除参数信息 * 批量删除功能参数配置
* *
* @param configIds 需要删除的参数ID * @param ids 需要删除的功能参数配置主键集合
*/
public void deleteConfigByIds(Long[] configIds);
/**
* 加载参数缓存数据
*/
public void loadingConfigCache();
/**
* 清空参数缓存数据
*/
public void clearConfigCache();
/**
* 重置参数缓存数据
*/
public void resetConfigCache();
/**
* 校验参数键名是否唯一
*
* @param config 参数信息
* @return 结果 * @return 结果
*/ */
public boolean checkConfigKeyUnique(BmConfig config); public int deleteBmConfigByIds(Long[] ids);
/**
* 删除功能参数配置信息
*
* @param id 功能参数配置主键
* @return 结果
*/
public int deleteBmConfigById(Long id);
} }

View File

@ -1,24 +1,18 @@
package com.bonus.material.screen.service.impl; package com.bonus.material.screen.service.impl;
import com.bonus.common.core.constant.CacheConstants; import java.util.List;
import com.bonus.common.core.constant.UserConstants; import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.text.Convert;
import com.bonus.common.core.utils.StringUtils;
import com.bonus.common.redis.service.RedisService;
import com.bonus.material.screen.domain.BmConfig;
import com.bonus.material.screen.mapper.BmConfigMapper;
import com.bonus.material.screen.service.IBmConfigService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import com.bonus.material.screen.mapper.BmConfigMapper;
import java.util.Collection; import com.bonus.material.screen.domain.BmConfig;
import java.util.List; import com.bonus.material.screen.service.IBmConfigService;
/** /**
* 参数配置 服务层实现 * 功能参数配置Service业务层处理
* *
* @author bonus * @author xsheng
* @date 2024-09-26
*/ */
@Service @Service
public class BmConfigServiceImpl implements IBmConfigService public class BmConfigServiceImpl implements IBmConfigService
@ -26,188 +20,77 @@ public class BmConfigServiceImpl implements IBmConfigService
@Autowired @Autowired
private BmConfigMapper bmConfigMapper; private BmConfigMapper bmConfigMapper;
@Autowired
private RedisService redisService;
/** /**
* 项目启动时初始化参数到缓存 * 查询功能参数配置
*/
@PostConstruct
public void init()
{
loadingConfigCache();
}
/**
* 查询参数配置信息
* *
* @param configId 参数配置ID * @param id 功能参数配置主键
* @return 参数配置信息 * @return 功能参数配置
*/ */
@Override @Override
public BmConfig selectConfigById(Long configId) public BmConfig selectBmConfigById(Long id)
{ {
BmConfig config = new BmConfig(); return bmConfigMapper.selectBmConfigById(id);
config.setConfigId(configId);
return bmConfigMapper.selectConfig(config);
} }
/** /**
* 根据键名查询参数配置信息 * 查询功能参数配置列表
* *
* @param configKey 参数key * @param bmConfig 功能参数配置
* @return 参数键值 * @return 功能参数配置
*/ */
@Override @Override
public String selectConfigByKey(String configKey) public List<BmConfig> selectBmConfigList(BmConfig bmConfig)
{ {
String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey))); return bmConfigMapper.selectBmConfigList(bmConfig);
if (StringUtils.isNotEmpty(configValue))
{
return configValue;
}
BmConfig config = new BmConfig();
config.setConfigKey(configKey);
BmConfig retConfig = bmConfigMapper.selectConfig(config);
if (StringUtils.isNotNull(retConfig))
{
redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
} }
/** /**
* 查询参数配置列表 * 新增功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 参数配置集合
*/
@Override
public List<BmConfig> selectConfigList(BmConfig config)
{
return bmConfigMapper.selectConfigList(config);
}
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertConfig(BmConfig config) public int insertBmConfig(BmConfig bmConfig)
{ {
int row = bmConfigMapper.insertConfig(config); bmConfig.setCreateTime(DateUtils.getNowDate());
if (row > 0) return bmConfigMapper.insertBmConfig(bmConfig);
{
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
} }
/** /**
* 修改参数配置 * 修改功能参数配置
* *
* @param config 参数配置信息 * @param bmConfig 功能参数配置
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateConfig(BmConfig config) public int updateBmConfig(BmConfig bmConfig)
{ {
BmConfig temp = bmConfigMapper.selectConfigById(config.getConfigId()); bmConfig.setUpdateTime(DateUtils.getNowDate());
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey())) return bmConfigMapper.updateBmConfig(bmConfig);
{
redisService.deleteObject(getCacheKey(temp.getConfigKey()));
}
int row = bmConfigMapper.updateConfig(config);
if (row > 0)
{
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
} }
/** /**
* 批量删除参数信息 * 批量删除功能参数配置
* *
* @param configIds 需要删除的参数ID * @param ids 需要删除的功能参数配置主键
*/
@Override
public void deleteConfigByIds(Long[] configIds)
{
for (Long configId : configIds)
{
BmConfig config = selectConfigById(configId);
if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
{
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
}
bmConfigMapper.deleteConfigById(configId);
redisService.deleteObject(getCacheKey(config.getConfigKey()));
}
}
/**
* 加载参数缓存数据
*/
@Override
public void loadingConfigCache()
{
List<BmConfig> configsList = bmConfigMapper.selectConfigList(new BmConfig());
for (BmConfig config : configsList)
{
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
/**
* 清空参数缓存数据
*/
@Override
public void clearConfigCache()
{
Collection<String> keys = redisService.keys(CacheConstants.SYS_CONFIG_KEY + "*");
redisService.deleteObject(keys);
}
/**
* 重置参数缓存数据
*/
@Override
public void resetConfigCache()
{
clearConfigCache();
loadingConfigCache();
}
/**
* 校验参数键名是否唯一
*
* @param config 参数配置信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public boolean checkConfigKeyUnique(BmConfig config) public int deleteBmConfigByIds(Long[] ids)
{ {
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId(); return bmConfigMapper.deleteBmConfigByIds(ids);
BmConfig info = bmConfigMapper.checkConfigKeyUnique(config.getConfigKey());
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
{
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
} }
/** /**
* 设置cache key * 删除功能参数配置信息
* *
* @param configKey 参数 * @param id 功能参数配置主键
* @return 缓存键key * @return 结果
*/ */
private String getCacheKey(String configKey) @Override
public int deleteBmConfigById(Long id)
{ {
return CacheConstants.SYS_CONFIG_KEY + configKey; return bmConfigMapper.deleteBmConfigById(id);
} }
} }

View File

@ -3,115 +3,74 @@
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.material.screen.mapper.BmConfigMapper"> <mapper namespace="com.bonus.material.screen.mapper.BmConfigMapper">
<resultMap type="com.bonus.material.screen.domain.BmConfig" id="BmConfigResult"> <resultMap type="com.bonus.material.screen.domain.BmConfig" id="BmConfigResult">
<id property="configId" column="config_id" /> <result property="id" column="id" />
<result property="configName" column="config_name" /> <result property="itemName" column="item_name" />
<result property="configKey" column="config_key" /> <result property="itemValue" column="item_value" />
<result property="configValue" column="config_value" />
<result property="configType" column="config_type" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" /> <result property="updateTime" column="update_time" />
</resultMap> </resultMap>
<sql id="selectConfigVo"> <sql id="selectBmConfigVo">
select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark select id, item_name, item_value, create_by, create_time, update_by, update_time from bm_config
from sys_config
</sql> </sql>
<!-- 查询条件 --> <select id="selectBmConfigList" parameterType="com.bonus.material.screen.domain.BmConfig" resultMap="BmConfigResult">
<sql id="sqlwhereSearch"> <include refid="selectBmConfigVo"/>
<where> <where>
<if test="configId !=null"> <if test="itemName != null and itemName != ''"> and item_name like concat('%', #{itemName}, '%')</if>
and config_id = #{configId} <if test="itemValue != null and itemValue != ''"> and item_value = #{itemValue}</if>
</if>
<if test="configKey !=null and configKey != ''">
and config_key = #{configKey}
</if>
</where>
</sql>
<select id="selectConfig" parameterType="com.bonus.material.screen.domain.BmConfig" resultMap="BmConfigResult">
<include refid="selectConfigVo"/>
<include refid="sqlwhereSearch"/>
</select>
<select id="selectConfigList" parameterType="com.bonus.material.screen.domain.BmConfig" resultMap="BmConfigResult">
<include refid="selectConfigVo"/>
<where>
<if test="configName != null and configName != ''">
AND config_name like concat('%', #{configName}, '%')
</if>
<if test="configType != null and configType != ''">
AND config_type = #{configType}
</if>
<if test="configKey != null and configKey != ''">
AND config_key like concat('%', #{configKey}, '%')
</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
and date_format(create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
and date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where> </where>
</select> </select>
<select id="selectConfigById" parameterType="Long" resultMap="BmConfigResult"> <select id="selectBmConfigById" parameterType="Long" resultMap="BmConfigResult">
<include refid="selectConfigVo"/> <include refid="selectBmConfigVo"/>
where config_id = #{configId} where id = #{id}
</select> </select>
<select id="checkConfigKeyUnique" parameterType="String" resultMap="BmConfigResult"> <insert id="insertBmConfig" parameterType="com.bonus.material.screen.domain.BmConfig" useGeneratedKeys="true" keyProperty="id">
<include refid="selectConfigVo"/> insert into bm_config
where config_key = #{configKey} limit 1 <trim prefix="(" suffix=")" suffixOverrides=",">
</select> <if test="itemName != null">item_name,</if>
<if test="itemValue != null">item_value,</if>
<insert id="insertConfig" parameterType="com.bonus.material.screen.domain.BmConfig"> <if test="createBy != null">create_by,</if>
insert into sys_config ( <if test="createTime != null">create_time,</if>
<if test="configName != null and configName != '' ">config_name,</if> <if test="updateBy != null">update_by,</if>
<if test="configKey != null and configKey != '' ">config_key,</if> <if test="updateTime != null">update_time,</if>
<if test="configValue != null and configValue != '' ">config_value,</if> </trim>
<if test="configType != null and configType != '' ">config_type,</if> <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="createBy != null and createBy != ''">create_by,</if> <if test="itemName != null">#{itemName},</if>
<if test="remark != null and remark != ''">remark,</if> <if test="itemValue != null">#{itemValue},</if>
create_time <if test="createBy != null">#{createBy},</if>
)values( <if test="createTime != null">#{createTime},</if>
<if test="configName != null and configName != ''">#{configName},</if> <if test="updateBy != null">#{updateBy},</if>
<if test="configKey != null and configKey != ''">#{configKey},</if> <if test="updateTime != null">#{updateTime},</if>
<if test="configValue != null and configValue != ''">#{configValue},</if> </trim>
<if test="configType != null and configType != ''">#{configType},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
<if test="remark != null and remark != ''">#{remark},</if>
sysdate()
)
</insert> </insert>
<update id="updateConfig" parameterType="com.bonus.material.screen.domain.BmConfig"> <update id="updateBmConfig" parameterType="com.bonus.material.screen.domain.BmConfig">
update sys_config update bm_config
<set> <trim prefix="SET" suffixOverrides=",">
<if test="configName != null and configName != ''">config_name = #{configName},</if> <if test="itemName != null">item_name = #{itemName},</if>
<if test="configKey != null and configKey != ''">config_key = #{configKey},</if> <if test="itemValue != null">item_value = #{itemValue},</if>
<if test="configValue != null and configValue != ''">config_value = #{configValue},</if> <if test="createBy != null">create_by = #{createBy},</if>
<if test="configType != null and configType != ''">config_type = #{configType},</if> <if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if> <if test="updateTime != null">update_time = #{updateTime},</if>
update_time = sysdate() </trim>
</set> where id = #{id}
where config_id = #{configId}
</update> </update>
<delete id="deleteConfigById" parameterType="Long"> <delete id="deleteBmConfigById" parameterType="Long">
delete from sys_config where config_id = #{configId} delete from bm_config where id = #{id}
</delete> </delete>
<delete id="deleteConfigByIds" parameterType="Long"> <delete id="deleteBmConfigByIds" parameterType="String">
delete from sys_config where config_id in delete from bm_config where id in
<foreach item="configId" collection="array" open="(" separator="," close=")"> <foreach item="id" collection="array" open="(" separator="," close=")">
#{configId} #{id}
</foreach> </foreach>
</delete> </delete>
</mapper> </mapper>