| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.CacheNames; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.MapstructUtils; |
| | | import com.ruoyi.common.core.utils.StreamUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.json.utils.JsonUtils; |
| | |
| | | |
| | | @Override |
| | | public Boolean insertByBo(SysOssConfigBo bo) { |
| | | SysOssConfig config = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | SysOssConfig config = MapstructUtils.convert(bo, SysOssConfig.class); |
| | | validEntityBeforeSave(config); |
| | | boolean flag = baseMapper.insert(config) > 0; |
| | | if (flag) { |
| | |
| | | |
| | | @Override |
| | | public Boolean updateByBo(SysOssConfigBo bo) { |
| | | SysOssConfig config = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | SysOssConfig config = MapstructUtils.convert(bo, SysOssConfig.class); |
| | | validEntityBeforeSave(config); |
| | | LambdaUpdateWrapper<SysOssConfig> luw = new LambdaUpdateWrapper<>(); |
| | | luw.set(ObjectUtil.isNull(config.getPrefix()), SysOssConfig::getPrefix, ""); |
| | |
| | | */ |
| | | private void validEntityBeforeSave(SysOssConfig entity) { |
| | | if (StringUtils.isNotEmpty(entity.getConfigKey()) |
| | | && UserConstants.NOT_UNIQUE.equals(checkConfigKeyUnique(entity))) { |
| | | && !checkConfigKeyUnique(entity)) { |
| | | throw new ServiceException("操作配置'" + entity.getConfigKey() + "'失败, 配置key已存在!"); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 判断configKey是否唯一 |
| | | */ |
| | | private String checkConfigKeyUnique(SysOssConfig sysOssConfig) { |
| | | private boolean checkConfigKeyUnique(SysOssConfig sysOssConfig) { |
| | | long ossConfigId = ObjectUtil.isNull(sysOssConfig.getOssConfigId()) ? -1L : sysOssConfig.getOssConfigId(); |
| | | SysOssConfig info = baseMapper.selectOne(new LambdaQueryWrapper<SysOssConfig>() |
| | | .select(SysOssConfig::getOssConfigId, SysOssConfig::getConfigKey) |
| | | .eq(SysOssConfig::getConfigKey, sysOssConfig.getConfigKey())); |
| | | if (ObjectUtil.isNotNull(info) && info.getOssConfigId() != ossConfigId) { |
| | | return UserConstants.NOT_UNIQUE; |
| | | return false; |
| | | } |
| | | return UserConstants.UNIQUE; |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public int updateOssConfigStatus(SysOssConfigBo bo) { |
| | | SysOssConfig sysOssConfig = BeanUtil.toBean(bo, SysOssConfig.class); |
| | | SysOssConfig sysOssConfig = MapstructUtils.convert(bo, SysOssConfig.class); |
| | | int row = baseMapper.update(null, new LambdaUpdateWrapper<SysOssConfig>() |
| | | .set(SysOssConfig::getStatus, "1")); |
| | | row += baseMapper.updateById(sysOssConfig); |