| | |
| | | import com.ruoyi.common.core.page.PagePlus; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.oss.constant.CloudConstant; |
| | | import com.ruoyi.oss.factory.OssFactory; |
| | | import com.ruoyi.system.domain.SysOssConfig; |
| | | import com.ruoyi.system.domain.bo.SysOssConfigBo; |
| | | import com.ruoyi.system.domain.vo.SysOssConfigVo; |
| | |
| | | if ("0".equals(config.getStatus())) { |
| | | redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, configKey); |
| | | } |
| | | redisCache.setCacheObject(getCacheKey(configKey), JsonUtils.toJsonString(config)); |
| | | setConfigCache(true, config); |
| | | } |
| | | } |
| | | |
| | |
| | | public Boolean insertByBo(SysOssConfigBo bo) { |
| | | SysOssConfig config = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | validEntityBeforeSave(config); |
| | | boolean flag = save(config); |
| | | if (flag) { |
| | | redisCache.setCacheObject( |
| | | getCacheKey(config.getConfigKey()), |
| | | JsonUtils.toJsonString(config)); |
| | | } |
| | | return flag; |
| | | return setConfigCache(save(config), config); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean updateByBo(SysOssConfigBo bo) { |
| | | SysOssConfig config = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | validEntityBeforeSave(config); |
| | | boolean flag = updateById(config); |
| | | if (flag) { |
| | | OssFactory.destroy(config.getConfigKey()); |
| | | redisCache.setCacheObject( |
| | | getCacheKey(config.getConfigKey()), |
| | | JsonUtils.toJsonString(config)); |
| | | } |
| | | return flag; |
| | | return setConfigCache(updateById(config), config); |
| | | } |
| | | |
| | | /** |
| | |
| | | private void validEntityBeforeSave(SysOssConfig entity){ |
| | | if (StringUtils.isNotEmpty(entity.getConfigKey()) |
| | | && UserConstants.NOT_UNIQUE.equals(checkConfigKeyUnique(entity))) { |
| | | throw new CustomException("操作配置'" + entity.getConfigKey() + "'失败, 配置key已存在!"); |
| | | throw new ServiceException("操作配置'" + entity.getConfigKey() + "'失败, 配置key已存在!"); |
| | | } |
| | | } |
| | | |
| | |
| | | public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) { |
| | | if(isValid) { |
| | | if (CollUtil.containsAny(ids, CloudConstant.SYSTEM_DATA_IDS)) { |
| | | throw new CustomException("系统内置, 不可删除!"); |
| | | throw new ServiceException("系统内置, 不可删除!"); |
| | | } |
| | | } |
| | | boolean flag = removeByIds(ids); |
| | | if (flag) { |
| | | for (Long configId : ids) { |
| | | SysOssConfig config = getById(configId); |
| | | OssFactory.destroy(config.getConfigKey()); |
| | | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| | | } |
| | | } |
| | |
| | | private String getCacheKey(String configKey) { |
| | | return CloudConstant.SYS_OSS_KEY + configKey; |
| | | } |
| | | |
| | | /** |
| | | * 如果操作成功 则更新缓存 |
| | | * @param flag 操作状态 |
| | | * @param config 配置 |
| | | * @return 返回操作状态 |
| | | */ |
| | | private boolean setConfigCache(boolean flag, SysOssConfig config) { |
| | | if (flag) { |
| | | redisCache.setCacheObject( |
| | | getCacheKey(config.getConfigKey()), |
| | | JsonUtils.toJsonString(config)); |
| | | } |
| | | return flag; |
| | | } |
| | | } |