|
@@ -1,21 +1,123 @@
|
|
|
package org.dromara.fulfiller.service.impl;
|
|
package org.dromara.fulfiller.service.impl;
|
|
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import org.dromara.common.core.constant.CacheNames;
|
|
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
+import org.dromara.fulfiller.domain.FlfLevelConfig;
|
|
|
|
|
+import org.dromara.fulfiller.domain.FlfLevelConfigRights;
|
|
|
|
|
+import org.dromara.fulfiller.domain.bo.FlfLevelConfigBo;
|
|
|
import org.dromara.fulfiller.domain.vo.FlfLevelConfigVo;
|
|
import org.dromara.fulfiller.domain.vo.FlfLevelConfigVo;
|
|
|
import org.dromara.fulfiller.mapper.FlfLevelConfigMapper;
|
|
import org.dromara.fulfiller.mapper.FlfLevelConfigMapper;
|
|
|
|
|
+import org.dromara.fulfiller.mapper.FlfLevelConfigRightsMapper;
|
|
|
import org.dromara.fulfiller.service.IFlfLevelConfigService;
|
|
import org.dromara.fulfiller.service.IFlfLevelConfigService;
|
|
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
@RequiredArgsConstructor
|
|
|
public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
|
|
|
|
|
|
private final FlfLevelConfigMapper baseMapper;
|
|
private final FlfLevelConfigMapper baseMapper;
|
|
|
|
|
+ private final FlfLevelConfigRightsMapper levelConfigRightsMapper;
|
|
|
|
|
|
|
|
|
|
+ @Cacheable(cacheNames = CacheNames.FLF_CONFIG, key = "'level_config'")
|
|
|
@Override
|
|
@Override
|
|
|
public List<FlfLevelConfigVo> listAll() {
|
|
public List<FlfLevelConfigVo> listAll() {
|
|
|
- return List.of();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ List<FlfLevelConfigVo> vos = baseMapper.selectVoList(Wrappers.lambdaQuery(FlfLevelConfig.class).orderByAsc(FlfLevelConfig::getLvNo));
|
|
|
|
|
+
|
|
|
|
|
+ List<Long> configIds = new ArrayList<>();
|
|
|
|
|
+ vos.forEach(e -> configIds.add(e.getId()));
|
|
|
|
|
+ if (!configIds.isEmpty()) {
|
|
|
|
|
+ Map<Long, List<Long>> map = new HashMap<>();
|
|
|
|
|
+ levelConfigRightsMapper.selectList(
|
|
|
|
|
+ Wrappers.lambdaQuery(FlfLevelConfigRights.class).in(FlfLevelConfigRights::getConfigId, configIds)
|
|
|
|
|
+ ).forEach(e -> map.computeIfAbsent(e.getConfigId(), k -> new ArrayList<>()).add(e.getRightsId()));
|
|
|
|
|
+ vos.forEach(e -> e.setRights(map.get(e.getId())));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return vos;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @CacheEvict(cacheNames = CacheNames.FLF_CONFIG, key = "'level_config'")
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean insertByBo(FlfLevelConfigBo bo) {
|
|
|
|
|
+
|
|
|
|
|
+ FlfLevelConfig config = MapstructUtils.convert(bo, FlfLevelConfig.class);
|
|
|
|
|
+ boolean configFlag = baseMapper.insert(config) == 0;
|
|
|
|
|
+ if (configFlag) {
|
|
|
|
|
+ throw new RuntimeException("新增配置信息");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<FlfLevelConfigRights> relations = new ArrayList<>();
|
|
|
|
|
+ bo.getRights().forEach(e -> {
|
|
|
|
|
+ FlfLevelConfigRights right = new FlfLevelConfigRights();
|
|
|
|
|
+ right.setConfigId(config.getId());
|
|
|
|
|
+ right.setRightsId(e);
|
|
|
|
|
+ relations.add(right);
|
|
|
|
|
+ });
|
|
|
|
|
+ boolean relationFlag = levelConfigRightsMapper.insertBatch(relations);
|
|
|
|
|
+ if (!relationFlag) {
|
|
|
|
|
+ throw new RuntimeException("新增关系失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @CacheEvict(cacheNames = CacheNames.FLF_CONFIG, key = "'level_config'")
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean updateByBo(FlfLevelConfigBo bo) {
|
|
|
|
|
+ FlfLevelConfig config = MapstructUtils.convert(bo, FlfLevelConfig.class);
|
|
|
|
|
+ boolean configFlag = baseMapper.updateById(config) == 0;
|
|
|
|
|
+ if (configFlag) {
|
|
|
|
|
+ throw new RuntimeException("修改配置信息");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean deleteFlag = levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, bo.getId())) == 0;
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ throw new RuntimeException("删除关系失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ List<FlfLevelConfigRights> relations = new ArrayList<>();
|
|
|
|
|
+ bo.getRights().forEach(e -> {
|
|
|
|
|
+ FlfLevelConfigRights right = new FlfLevelConfigRights();
|
|
|
|
|
+ right.setConfigId(config.getId());
|
|
|
|
|
+ right.setRightsId(e);
|
|
|
|
|
+ relations.add(right);
|
|
|
|
|
+ });
|
|
|
|
|
+ boolean relationFlag = levelConfigRightsMapper.insertBatch(relations);
|
|
|
|
|
+ if (!relationFlag) {
|
|
|
|
|
+ throw new RuntimeException("新增关系失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @CacheEvict(cacheNames = CacheNames.FLF_CONFIG, key = "'level_config'")
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public boolean deleteById(Long id) {
|
|
|
|
|
+
|
|
|
|
|
+ boolean configFlag = baseMapper.deleteById(id) == 0;
|
|
|
|
|
+ if (configFlag) {
|
|
|
|
|
+ throw new RuntimeException("删除配置信息");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ boolean deleteFlag = levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, id)) == 0;
|
|
|
|
|
+ if (deleteFlag) {
|
|
|
|
|
+ throw new RuntimeException("删除关系失败");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|