|
|
@@ -53,9 +53,8 @@ public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
|
public boolean insertByBo(FlfLevelConfigBo bo) {
|
|
|
|
|
|
FlfLevelConfig config = MapstructUtils.convert(bo, FlfLevelConfig.class);
|
|
|
- boolean configFlag = baseMapper.insert(config) == 0;
|
|
|
- if (configFlag) {
|
|
|
- throw new RuntimeException("新增配置信息");
|
|
|
+ if (baseMapper.insert(config) == 0) {
|
|
|
+ throw new RuntimeException("新增配置信息失败");
|
|
|
}
|
|
|
|
|
|
List<FlfLevelConfigRights> relations = new ArrayList<>();
|
|
|
@@ -65,9 +64,11 @@ public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
|
right.setRightsId(e);
|
|
|
relations.add(right);
|
|
|
});
|
|
|
- boolean relationFlag = levelConfigRightsMapper.insertBatch(relations);
|
|
|
- if (!relationFlag) {
|
|
|
- throw new RuntimeException("新增关系失败");
|
|
|
+ if (!relations.isEmpty()) {
|
|
|
+ boolean relationFlag = levelConfigRightsMapper.insertBatch(relations);
|
|
|
+ if (!relationFlag) {
|
|
|
+ throw new RuntimeException("新增关系失败");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
@@ -78,26 +79,25 @@ public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
|
@Override
|
|
|
public boolean updateByBo(FlfLevelConfigBo bo) {
|
|
|
FlfLevelConfig config = MapstructUtils.convert(bo, FlfLevelConfig.class);
|
|
|
- boolean configFlag = baseMapper.updateById(config) == 0;
|
|
|
- if (configFlag) {
|
|
|
- throw new RuntimeException("修改配置信息");
|
|
|
+ if (baseMapper.updateById(config) == 0) {
|
|
|
+ throw new RuntimeException("修改配置信息失败");
|
|
|
}
|
|
|
|
|
|
- boolean deleteFlag = levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, bo.getId())) == 0;
|
|
|
- if (deleteFlag) {
|
|
|
- throw new RuntimeException("删除关系失败");
|
|
|
- }
|
|
|
+ // 先删除原有关系,即使原本没有关系返回0也是正常的
|
|
|
+ levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, bo.getId()));
|
|
|
|
|
|
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("新增关系失败");
|
|
|
+ if (bo.getRights() != null && !bo.getRights().isEmpty()) {
|
|
|
+ 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;
|
|
|
@@ -108,15 +108,12 @@ public class FlfLevelConfigServiceImpl implements IFlfLevelConfigService {
|
|
|
@Override
|
|
|
public boolean deleteById(Long id) {
|
|
|
|
|
|
- boolean configFlag = baseMapper.deleteById(id) == 0;
|
|
|
- if (configFlag) {
|
|
|
- throw new RuntimeException("删除配置信息");
|
|
|
+ if (baseMapper.deleteById(id) == 0) {
|
|
|
+ throw new RuntimeException("删除配置信息失败");
|
|
|
}
|
|
|
|
|
|
- boolean deleteFlag = levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, id)) == 0;
|
|
|
- if (deleteFlag) {
|
|
|
- throw new RuntimeException("删除关系失败");
|
|
|
- }
|
|
|
+ // 即使没有关系返回0也是正常的
|
|
|
+ levelConfigRightsMapper.delete(Wrappers.lambdaQuery(FlfLevelConfigRights.class).eq(FlfLevelConfigRights::getConfigId, id));
|
|
|
|
|
|
return true;
|
|
|
}
|