生产bug和配置管理代码提交
This commit is contained in:
parent
76fd0dd25a
commit
6f0d216a6e
|
|
@ -0,0 +1,141 @@
|
|||
package com.bonus.sgzb.base.controller;
|
||||
|
||||
import com.bonus.sgzb.base.domain.MaConfig;
|
||||
import com.bonus.sgzb.base.service.ISysConfigService;
|
||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.sgzb.common.core.web.controller.BaseController;
|
||||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.core.web.page.TableDataInfo;
|
||||
import com.bonus.sgzb.common.log.annotation.Log;
|
||||
import com.bonus.sgzb.common.log.enums.BusinessType;
|
||||
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import com.bonus.sgzb.largeScreen.util.RsaUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 信息操作处理
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/config")
|
||||
public class SysConfigController extends BaseController
|
||||
{
|
||||
private final String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKoR8mX0rGKLqzcWmOzbfj64K8ZIgOdHnzkXSOVOZbFu/TJhZ7rFAN+eaGkl3C4buccQd/EjEsj9ir7ijT7h96MCAwEAAQ==";
|
||||
private final String CONFIG_KEY = "sys.user.initPassword";
|
||||
|
||||
@Autowired
|
||||
private ISysConfigService configService;
|
||||
|
||||
/**
|
||||
* 获取参数配置列表
|
||||
*/
|
||||
@RequiresPermissions("system:config:list")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(MaConfig config) throws Exception {
|
||||
startPage();
|
||||
List<MaConfig> list = configService.selectConfigList(config);
|
||||
for (MaConfig sysConfig : list) {
|
||||
if (CONFIG_KEY.equals(sysConfig.getConfigKey()) && StringUtils.isNotBlank(sysConfig.getConfigValue())) {
|
||||
String configValue = RsaUtil.encryptByPublicKey(sysConfig.getConfigValue(), publicKey);
|
||||
sysConfig.setConfigValue(configValue);
|
||||
}
|
||||
}
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
@Log(title = "参数管理", businessType = BusinessType.EXPORT)
|
||||
@RequiresPermissions("system:config:export")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, MaConfig config)
|
||||
{
|
||||
List<MaConfig> list = configService.selectConfigList(config);
|
||||
ExcelUtil<MaConfig> util = new ExcelUtil<MaConfig>(MaConfig.class);
|
||||
util.exportExcel(response, list, "参数数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数编号获取详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{configId}")
|
||||
public AjaxResult getInfo(@PathVariable Long configId)
|
||||
{
|
||||
return success(configService.selectConfigById(configId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据参数键名查询参数值
|
||||
*/
|
||||
@GetMapping(value = "/configKey/{configKey}")
|
||||
public AjaxResult getConfigKey(@PathVariable String configKey) throws Exception {
|
||||
String configByKey = configService.selectConfigByKey(configKey);
|
||||
if (CONFIG_KEY.equals(configKey) && StringUtils.isNotBlank(configByKey)) {
|
||||
String configValue = RsaUtil.encryptByPublicKey(configByKey, publicKey);
|
||||
return AjaxResult.success(configValue);
|
||||
}
|
||||
return success(configByKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*/
|
||||
@RequiresPermissions("system:config:add")
|
||||
@Log(title = "参数管理", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@Validated @RequestBody MaConfig config)
|
||||
{
|
||||
if (!configService.checkConfigKeyUnique(config))
|
||||
{
|
||||
return error("新增参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
config.setCreateBy(SecurityUtils.getUsername());
|
||||
return toAjax(configService.insertConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*/
|
||||
@RequiresPermissions("system:config:edit")
|
||||
@Log(title = "参数管理", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@Validated @RequestBody MaConfig config)
|
||||
{
|
||||
if (!configService.checkConfigKeyUnique(config))
|
||||
{
|
||||
return error("修改参数'" + config.getConfigName() + "'失败,参数键名已存在");
|
||||
}
|
||||
config.setUpdateBy(SecurityUtils.getUsername());
|
||||
return toAjax(configService.updateConfig(config));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*/
|
||||
@RequiresPermissions("system:config:remove")
|
||||
@Log(title = "参数管理", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{configIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] configIds)
|
||||
{
|
||||
configService.deleteConfigByIds(configIds);
|
||||
return success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新参数缓存
|
||||
*/
|
||||
@RequiresPermissions("system:config:remove")
|
||||
@Log(title = "参数管理", businessType = BusinessType.CLEAN)
|
||||
@DeleteMapping("/refreshCache")
|
||||
public AjaxResult refreshCache()
|
||||
{
|
||||
configService.resetConfigCache();
|
||||
return success();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,112 @@
|
|||
package com.bonus.sgzb.base.domain;
|
||||
|
||||
import com.bonus.sgzb.common.core.annotation.Excel;
|
||||
import com.bonus.sgzb.common.core.annotation.Excel.ColumnType;
|
||||
import com.bonus.sgzb.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;
|
||||
|
||||
/**
|
||||
* 参数配置表 sys_config
|
||||
*
|
||||
* @author bns
|
||||
*/
|
||||
public class MaConfig extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 参数主键 */
|
||||
@Excel(name = "参数主键", cellType = ColumnType.NUMERIC)
|
||||
private Long configId;
|
||||
|
||||
/** 参数名称 */
|
||||
@Excel(name = "参数名称")
|
||||
private String configName;
|
||||
|
||||
/** 参数键名 */
|
||||
@Excel(name = "参数键名")
|
||||
private String configKey;
|
||||
|
||||
/** 参数键值 */
|
||||
@Excel(name = "参数键值")
|
||||
private String configValue;
|
||||
|
||||
/** 系统内置(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();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.bonus.sgzb.base.mapper;
|
||||
|
||||
import com.bonus.sgzb.base.domain.MaConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface MaConfigMapper
|
||||
{
|
||||
/**
|
||||
* 查询参数配置信息
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
public MaConfig selectConfig(MaConfig config);
|
||||
|
||||
/**
|
||||
* 通过ID查询配置
|
||||
*
|
||||
* @param configId 参数ID
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
public MaConfig selectConfigById(Long configId);
|
||||
|
||||
/**
|
||||
* 查询参数配置列表
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 参数配置集合
|
||||
*/
|
||||
public List<MaConfig> selectConfigList(MaConfig config);
|
||||
|
||||
/**
|
||||
* 根据键名查询参数配置信息
|
||||
*
|
||||
* @param configKey 参数键名
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
public MaConfig checkConfigKeyUnique(String configKey);
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertConfig(MaConfig config);
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateConfig(MaConfig config);
|
||||
|
||||
/**
|
||||
* 删除参数配置
|
||||
*
|
||||
* @param configId 参数ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteConfigById(Long configId);
|
||||
|
||||
/**
|
||||
* 批量删除参数信息
|
||||
*
|
||||
* @param configIds 需要删除的参数ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteConfigByIds(Long[] configIds);
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package com.bonus.sgzb.base.service;
|
||||
|
||||
import com.bonus.sgzb.base.domain.MaConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 服务层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface ISysConfigService
|
||||
{
|
||||
/**
|
||||
* 查询参数配置信息
|
||||
*
|
||||
* @param configId 参数配置ID
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
public MaConfig selectConfigById(Long configId);
|
||||
|
||||
/**
|
||||
* 根据键名查询参数配置信息
|
||||
*
|
||||
* @param configKey 参数键名
|
||||
* @return 参数键值
|
||||
*/
|
||||
public String selectConfigByKey(String configKey);
|
||||
|
||||
/**
|
||||
* 查询参数配置列表
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 参数配置集合
|
||||
*/
|
||||
public List<MaConfig> selectConfigList(MaConfig config);
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertConfig(MaConfig config);
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateConfig(MaConfig config);
|
||||
|
||||
/**
|
||||
* 批量删除参数信息
|
||||
*
|
||||
* @param configIds 需要删除的参数ID
|
||||
*/
|
||||
public void deleteConfigByIds(Long[] configIds);
|
||||
|
||||
/**
|
||||
* 加载参数缓存数据
|
||||
*/
|
||||
public void loadingConfigCache();
|
||||
|
||||
/**
|
||||
* 清空参数缓存数据
|
||||
*/
|
||||
public void clearConfigCache();
|
||||
|
||||
/**
|
||||
* 重置参数缓存数据
|
||||
*/
|
||||
public void resetConfigCache();
|
||||
|
||||
/**
|
||||
* 校验参数键名是否唯一
|
||||
*
|
||||
* @param config 参数信息
|
||||
* @return 结果
|
||||
*/
|
||||
public boolean checkConfigKeyUnique(MaConfig config);
|
||||
}
|
||||
|
|
@ -0,0 +1,214 @@
|
|||
package com.bonus.sgzb.base.service.impl;
|
||||
|
||||
import com.bonus.sgzb.base.domain.MaConfig;
|
||||
import com.bonus.sgzb.base.mapper.MaConfigMapper;
|
||||
import com.bonus.sgzb.base.service.ISysConfigService;
|
||||
import com.bonus.sgzb.common.core.constant.CacheConstants;
|
||||
import com.bonus.sgzb.common.core.constant.UserConstants;
|
||||
import com.bonus.sgzb.common.core.exception.ServiceException;
|
||||
import com.bonus.sgzb.common.core.text.Convert;
|
||||
import com.bonus.sgzb.common.core.utils.StringUtils;
|
||||
import com.bonus.sgzb.common.redis.service.RedisService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 参数配置 服务层实现
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Service
|
||||
public class SysConfigServiceImpl implements ISysConfigService
|
||||
{
|
||||
@Resource
|
||||
private MaConfigMapper configMapper;
|
||||
|
||||
@Resource
|
||||
private RedisService redisService;
|
||||
|
||||
/**
|
||||
* 项目启动时,初始化参数到缓存
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init()
|
||||
{
|
||||
loadingConfigCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询参数配置信息
|
||||
*
|
||||
* @param configId 参数配置ID
|
||||
* @return 参数配置信息
|
||||
*/
|
||||
@Override
|
||||
public MaConfig selectConfigById(Long configId)
|
||||
{
|
||||
MaConfig config = new MaConfig();
|
||||
config.setConfigId(configId);
|
||||
return configMapper.selectConfig(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据键名查询参数配置信息
|
||||
*
|
||||
* @param configKey 参数key
|
||||
* @return 参数键值
|
||||
*/
|
||||
@Override
|
||||
public String selectConfigByKey(String configKey)
|
||||
{
|
||||
String configValue = Convert.toStr(redisService.getCacheObject(getCacheKey(configKey)));
|
||||
if (StringUtils.isNotEmpty(configValue))
|
||||
{
|
||||
return configValue;
|
||||
}
|
||||
MaConfig config = new MaConfig();
|
||||
config.setConfigKey(configKey);
|
||||
MaConfig retConfig = configMapper.selectConfig(config);
|
||||
if (StringUtils.isNotNull(retConfig))
|
||||
{
|
||||
redisService.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
|
||||
return retConfig.getConfigValue();
|
||||
}
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询参数配置列表
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 参数配置集合
|
||||
*/
|
||||
@Override
|
||||
public List<MaConfig> selectConfigList(MaConfig config)
|
||||
{
|
||||
return configMapper.selectConfigList(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertConfig(MaConfig config)
|
||||
{
|
||||
int row = configMapper.insertConfig(config);
|
||||
if (row > 0)
|
||||
{
|
||||
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改参数配置
|
||||
*
|
||||
* @param config 参数配置信息
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateConfig(MaConfig config)
|
||||
{
|
||||
MaConfig temp = configMapper.selectConfigById(config.getConfigId());
|
||||
if (!StringUtils.equals(temp.getConfigKey(), config.getConfigKey()))
|
||||
{
|
||||
redisService.deleteObject(getCacheKey(temp.getConfigKey()));
|
||||
}
|
||||
|
||||
int row = configMapper.updateConfig(config);
|
||||
if (row > 0)
|
||||
{
|
||||
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
|
||||
}
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除参数信息
|
||||
*
|
||||
* @param configIds 需要删除的参数ID
|
||||
*/
|
||||
@Override
|
||||
public void deleteConfigByIds(Long[] configIds)
|
||||
{
|
||||
for (Long configId : configIds)
|
||||
{
|
||||
MaConfig config = selectConfigById(configId);
|
||||
if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
|
||||
{
|
||||
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
|
||||
}
|
||||
configMapper.deleteConfigById(configId);
|
||||
redisService.deleteObject(getCacheKey(config.getConfigKey()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载参数缓存数据
|
||||
*/
|
||||
@Override
|
||||
public void loadingConfigCache()
|
||||
{
|
||||
List<MaConfig> configsList = configMapper.selectConfigList(new MaConfig());
|
||||
for (MaConfig 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 结果
|
||||
*/
|
||||
@Override
|
||||
public boolean checkConfigKeyUnique(MaConfig config)
|
||||
{
|
||||
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
|
||||
MaConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
|
||||
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
|
||||
{
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置cache key
|
||||
*
|
||||
* @param configKey 参数键
|
||||
* @return 缓存键key
|
||||
*/
|
||||
private String getCacheKey(String configKey)
|
||||
{
|
||||
return CacheConstants.SYS_CONFIG_KEY + configKey;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
package com.bonus.sgzb.largeScreen.util;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* @Author ma_sh
|
||||
* @create 2024/5/25 16:07
|
||||
*/
|
||||
public class RsaUtil {
|
||||
//签名算法名称
|
||||
private static final String RSA_KEY_ALGORITHM = "RSA";
|
||||
|
||||
//RSA密钥长度,默认密钥长度是1024,密钥长度必须是64的倍数,在512到65536位之间,不管是RSA还是RSA2长度推荐使用2048
|
||||
private static final int KEY_SIZE = 2048;
|
||||
|
||||
/**
|
||||
* 公钥加密(用于数据加密)
|
||||
*
|
||||
* @param data 加密前的字符串
|
||||
* @param publicKeyStr base64编码后的公钥
|
||||
* @return base64编码后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encryptByPublicKey(String data, String publicKeyStr) throws Exception {
|
||||
//Java原生base64解码
|
||||
byte[] pubKey = Base64.getDecoder().decode(publicKeyStr);
|
||||
//创建X509编码密钥规范
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey);
|
||||
//返回转换指定算法的KeyFactory对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
|
||||
//根据X509编码密钥规范产生公钥对象
|
||||
PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
|
||||
//根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
//用公钥初始化此Cipher对象(加密模式)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
//对数据加密
|
||||
byte[] encrypt = cipher.doFinal(data.getBytes());
|
||||
//返回base64编码后的字符串
|
||||
return Base64.getEncoder().encodeToString(encrypt);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 私钥解密(用于数据解密)
|
||||
*
|
||||
* @param data 解密前的字符串
|
||||
* @param privateKeyStr 私钥
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decryptByPrivateKey(String data, String privateKeyStr) throws Exception {
|
||||
//Java原生base64解码
|
||||
byte[] priKey = Base64.getDecoder().decode(privateKeyStr);
|
||||
//创建PKCS8编码密钥规范
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(priKey);
|
||||
//返回转换指定算法的KeyFactory对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
|
||||
//根据PKCS8编码密钥规范产生私钥对象
|
||||
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
//根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
//用私钥初始化此Cipher对象(解密模式)
|
||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
//对数据解密
|
||||
byte[] decrypt = cipher.doFinal(Base64.getDecoder().decode(data));
|
||||
//返回字符串
|
||||
return new String(decrypt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 私钥加密(用于数据签名)
|
||||
*
|
||||
* @param data 加密前的字符串
|
||||
* @param privateKeyStr base64编码后的私钥
|
||||
* @return base64编码后后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String encryptByPrivateKey(String data, String privateKeyStr) throws Exception {
|
||||
//Java原生base64解码
|
||||
byte[] priKey = Base64.getDecoder().decode(privateKeyStr);
|
||||
//创建PKCS8编码密钥规范
|
||||
PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(priKey);
|
||||
//返回转换指定算法的KeyFactory对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
|
||||
//根据PKCS8编码密钥规范产生私钥对象
|
||||
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);
|
||||
//根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
//用私钥初始化此Cipher对象(加密模式)
|
||||
cipher.init(Cipher.ENCRYPT_MODE, privateKey);
|
||||
//对数据加密
|
||||
byte[] encrypt = cipher.doFinal(data.getBytes());
|
||||
//返回base64编码后的字符串
|
||||
return Base64.getEncoder().encodeToString(encrypt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 公钥解密(用于数据验签)
|
||||
*
|
||||
* @param data 解密前的字符串
|
||||
* @param publicKeyStr base64编码后的公钥
|
||||
* @return 解密后的字符串
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decryptByPublicKey(String data, String publicKeyStr) throws Exception {
|
||||
//Java原生base64解码
|
||||
byte[] pubKey = Base64.getDecoder().decode(publicKeyStr);
|
||||
//创建X509编码密钥规范
|
||||
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(pubKey);
|
||||
//返回转换指定算法的KeyFactory对象
|
||||
KeyFactory keyFactory = KeyFactory.getInstance(RSA_KEY_ALGORITHM);
|
||||
//根据X509编码密钥规范产生公钥对象
|
||||
PublicKey publicKey = keyFactory.generatePublic(x509KeySpec);
|
||||
//根据转换的名称获取密码对象Cipher(转换的名称:算法/工作模式/填充模式)
|
||||
Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
|
||||
//用公钥初始化此Cipher对象(解密模式)
|
||||
cipher.init(Cipher.DECRYPT_MODE, publicKey);
|
||||
//对数据解密
|
||||
byte[] decrypt = cipher.doFinal(Base64.getDecoder().decode(data));
|
||||
//返回字符串
|
||||
return new String(decrypt);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.bonus.sgzb.base.mapper.MaConfigMapper">
|
||||
<resultMap type="com.bonus.sgzb.base.domain.MaConfig" id="SysConfigResult">
|
||||
<id property="configId" column="config_id" />
|
||||
<result property="configName" column="config_name" />
|
||||
<result property="configKey" column="config_key" />
|
||||
<result property="configValue" column="config_value" />
|
||||
<result property="configType" column="config_type" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectConfigVo">
|
||||
select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark
|
||||
from ma_config
|
||||
</sql>
|
||||
|
||||
<!-- 查询条件 -->
|
||||
<sql id="sqlwhereSearch">
|
||||
<where>
|
||||
<if test="configId !=null">
|
||||
and config_id = #{configId}
|
||||
</if>
|
||||
<if test="configKey !=null and configKey != ''">
|
||||
and config_key = #{configKey}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="selectConfig" parameterType="com.bonus.sgzb.base.domain.MaConfig" resultMap="SysConfigResult">
|
||||
<include refid="selectConfigVo"/>
|
||||
<include refid="sqlwhereSearch"/>
|
||||
</select>
|
||||
|
||||
<select id="selectConfigList" parameterType="com.bonus.sgzb.base.domain.MaConfig" resultMap="SysConfigResult">
|
||||
<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') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectConfigById" parameterType="Long" resultMap="SysConfigResult">
|
||||
<include refid="selectConfigVo"/>
|
||||
where config_id = #{configId}
|
||||
</select>
|
||||
|
||||
<select id="checkConfigKeyUnique" parameterType="String" resultMap="SysConfigResult">
|
||||
<include refid="selectConfigVo"/>
|
||||
where config_key = #{configKey} limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertConfig" parameterType="com.bonus.sgzb.base.domain.MaConfig">
|
||||
insert into ma_config (
|
||||
<if test="configName != null and configName != '' ">config_name,</if>
|
||||
<if test="configKey != null and configKey != '' ">config_key,</if>
|
||||
<if test="configValue != null and configValue != '' ">config_value,</if>
|
||||
<if test="configType != null and configType != '' ">config_type,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="remark != null and remark != ''">remark,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="configName != null and configName != ''">#{configName},</if>
|
||||
<if test="configKey != null and configKey != ''">#{configKey},</if>
|
||||
<if test="configValue != null and configValue != ''">#{configValue},</if>
|
||||
<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>
|
||||
|
||||
<update id="updateConfig" parameterType="com.bonus.sgzb.base.domain.MaConfig">
|
||||
update ma_config
|
||||
<set>
|
||||
<if test="configName != null and configName != ''">config_name = #{configName},</if>
|
||||
<if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
|
||||
<if test="configValue != null and configValue != ''">config_value = #{configValue},</if>
|
||||
<if test="configType != null and configType != ''">config_type = #{configType},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where config_id = #{configId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteConfigById" parameterType="Long">
|
||||
delete from ma_config where config_id = #{configId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteConfigByIds" parameterType="Long">
|
||||
delete from ma_config where config_id in
|
||||
<foreach item="configId" collection="array" open="(" separator="," close=")">
|
||||
#{configId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -199,7 +199,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<select id="selectPurchaseCheckDetailsStatus" resultType="int">
|
||||
select count(*) from purchase_check_details where task_id = #{taskId} and status != 3
|
||||
</select>
|
||||
<select id="selectInputNumByTypeId" resultType="java.math.BigDecimal">
|
||||
<select id="selectInputNumByTypeId" resultType="java.lang.Integer">
|
||||
select IFNULL(input_num,0) from purchase_check_details where task_id = #{taskId} and type_id = #{typeId}
|
||||
</select>
|
||||
<select id="selectBindNumByTypeId" resultType="java.lang.Integer">
|
||||
|
|
|
|||
Loading…
Reference in New Issue