| | |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | 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.ServiceException; |
| | | import com.ruoyi.common.utils.JsonUtils; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.ruoyi.common.utils.RedisUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.oss.constant.CloudConstant; |
| | | import com.ruoyi.system.domain.SysOssConfig; |
| | |
| | | import com.ruoyi.system.mapper.SysOssConfigMapper; |
| | | import com.ruoyi.system.service.ISysOssConfigService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 云存储配置Service业务层处理 |
| | | * 对象存储配置Service业务层处理 |
| | | * |
| | | * @author Lion Li |
| | | * @author 孤舟烟雨 |
| | | * @date 2021-08-13 |
| | | */ |
| | | @Slf4j |
| | | @RequiredArgsConstructor(onConstructor_ = @Autowired) |
| | | @Service |
| | | public class SysOssConfigServiceImpl extends ServicePlusImpl<SysOssConfigMapper, SysOssConfig, SysOssConfigVo> implements ISysOssConfigService { |
| | | |
| | | private final RedisCache redisCache; |
| | | |
| | | /** |
| | | * 项目启动时,初始化参数到缓存,加载配置类 |
| | |
| | | for (SysOssConfig config : list) { |
| | | String configKey = config.getConfigKey(); |
| | | if ("0".equals(config.getStatus())) { |
| | | redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, configKey); |
| | | RedisUtils.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, configKey); |
| | | } |
| | | setConfigCache(true, config); |
| | | } |
| | |
| | | public Boolean updateByBo(SysOssConfigBo bo) { |
| | | SysOssConfig config = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | validEntityBeforeSave(config); |
| | | return setConfigCache(updateById(config), config); |
| | | LambdaUpdateWrapper<SysOssConfig> luw = new LambdaUpdateWrapper<>(); |
| | | luw.set(StringUtils.isBlank(config.getPrefix()), SysOssConfig::getPrefix, ""); |
| | | luw.set(StringUtils.isBlank(config.getRegion()), SysOssConfig::getRegion, ""); |
| | | luw.set(StringUtils.isBlank(config.getExt1()), SysOssConfig::getExt1, ""); |
| | | luw.eq(SysOssConfig::getOssConfigId, config.getOssConfigId()); |
| | | return setConfigCache(update(config, luw), config); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (flag) { |
| | | for (Long configId : ids) { |
| | | SysOssConfig config = getById(configId); |
| | | redisCache.deleteObject(getCacheKey(config.getConfigKey())); |
| | | RedisUtils.deleteObject(getCacheKey(config.getConfigKey())); |
| | | } |
| | | } |
| | | return flag; |
| | |
| | | .set(SysOssConfig::getStatus, "1")); |
| | | row += baseMapper.updateById(sysOssConfig); |
| | | if (row > 0) { |
| | | redisCache.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); |
| | | RedisUtils.setCacheObject(CloudConstant.CACHE_CONFIG_KEY, sysOssConfig.getConfigKey()); |
| | | } |
| | | return row; |
| | | } |
| | |
| | | */ |
| | | private boolean setConfigCache(boolean flag, SysOssConfig config) { |
| | | if (flag) { |
| | | redisCache.setCacheObject( |
| | | RedisUtils.setCacheObject( |
| | | getCacheKey(config.getConfigKey()), |
| | | JsonUtils.toJsonString(config)); |
| | | RedisUtils.publish(CloudConstant.CACHE_CONFIG_KEY, config.getConfigKey(), msg -> { |
| | | log.info("发布刷新OSS配置 => " + msg); |
| | | }); |
| | | } |
| | | return flag; |
| | | } |