update 优化代码小改动

This commit is contained in:
疯狂的狮子Li
2025-06-30 10:45:49 +08:00
parent 1ab8750cd5
commit d37a00497d
7 changed files with 35 additions and 37 deletions

View File

@@ -19,6 +19,7 @@ import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@@ -117,7 +118,7 @@ public class SysDictDataController extends BaseController {
@Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictCodes}")
public R<Void> remove(@PathVariable Long[] dictCodes) {
dictDataService.deleteDictDataByIds(dictCodes);
dictDataService.deleteDictDataByIds(Arrays.asList(dictCodes));
return R.ok();
}
}

View File

@@ -16,6 +16,8 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
/**
@@ -99,7 +101,7 @@ public class SysDictTypeController extends BaseController {
@Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictIds}")
public R<Void> remove(@PathVariable Long[] dictIds) {
dictTypeService.deleteDictTypeByIds(dictIds);
dictTypeService.deleteDictTypeByIds(Arrays.asList(dictIds));
return R.ok();
}

View File

@@ -47,7 +47,7 @@ public interface ISysDictDataService {
*
* @param dictCodes 需要删除的字典数据ID
*/
void deleteDictDataByIds(Long[] dictCodes);
void deleteDictDataByIds(List<Long> dictCodes);
/**
* 新增保存字典数据信息

View File

@@ -62,7 +62,7 @@ public interface ISysDictTypeService {
*
* @param dictIds 需要删除的字典ID
*/
void deleteDictTypeByIds(Long[] dictIds);
void deleteDictTypeByIds(List<Long> dictIds);
/**
* 重置字典缓存数据

View File

@@ -8,7 +8,6 @@ import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.CacheNames;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.ObjectUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
@@ -95,12 +94,10 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
* @param dictCodes 需要删除的字典数据ID
*/
@Override
public void deleteDictDataByIds(Long[] dictCodes) {
for (Long dictCode : dictCodes) {
SysDictData data = baseMapper.selectById(dictCode);
baseMapper.deleteById(dictCode);
CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType());
}
public void deleteDictDataByIds(List<Long> dictCodes) {
List<SysDictData> list = baseMapper.selectByIds(dictCodes);
baseMapper.deleteByIds(dictCodes);
list.forEach(x -> CacheUtils.evict(CacheNames.SYS_DICT, x.getDictType()));
}
/**
@@ -145,13 +142,11 @@ public class SysDictDataServiceImpl implements ISysDictDataService {
*/
@Override
public boolean checkDictDataUnique(SysDictDataBo dict) {
Long dictCode = ObjectUtils.notNull(dict.getDictCode(), -1L);
SysDictData entity = baseMapper.selectOne(new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getDictType, dict.getDictType()).eq(SysDictData::getDictValue, dict.getDictValue()));
if (ObjectUtil.isNotNull(entity) && !dictCode.equals(entity.getDictCode())) {
return false;
}
return true;
boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getDictType, dict.getDictType())
.eq(SysDictData::getDictValue, dict.getDictValue())
.ne(ObjectUtil.isNotNull(dict.getDictCode()), SysDictData::getDictCode, dict.getDictCode()));
return !exist;
}
}

View File

@@ -28,7 +28,6 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -94,10 +93,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService {
@Override
public List<SysDictDataVo> selectDictDataByType(String dictType) {
List<SysDictDataVo> dictDatas = dictDataMapper.selectDictDataByType(dictType);
if (CollUtil.isNotEmpty(dictDatas)) {
return dictDatas;
}
return null;
return CollUtil.isNotEmpty(dictDatas) ? dictDatas : null;
}
/**
@@ -129,17 +125,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService {
* @param dictIds 需要删除的字典ID
*/
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
for (Long dictId : dictIds) {
SysDictType dictType = baseMapper.selectById(dictId);
if (dictDataMapper.exists(new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getDictType, dictType.getDictType()))) {
throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
public void deleteDictTypeByIds(List<Long> dictIds) {
List<SysDictType> list = baseMapper.selectByIds(dictIds);
list.forEach(x -> {
boolean assigned = dictDataMapper.exists(new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getDictType, x.getDictType()));
if (assigned) {
throw new ServiceException(String.format("%1$s已分配,不能删除", x.getDictName()));
}
CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType());
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, dictType.getDictType());
}
baseMapper.deleteByIds(Arrays.asList(dictIds));
});
baseMapper.deleteByIds(dictIds);
list.forEach(x -> {
CacheUtils.evict(CacheNames.SYS_DICT, x.getDictType());
CacheUtils.evict(CacheNames.SYS_DICT_TYPE, x.getDictType());
});
}
/**

View File

@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.constant.Constants;
import org.dromara.common.core.constant.SystemConstants;
import org.dromara.common.core.utils.MapstructUtils;
import org.dromara.common.core.utils.StreamUtils;
@@ -142,7 +143,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
} else {
menus = baseMapper.selectMenuTreeByUserId(userId);
}
return getChildPerms(menus, 0);
return getChildPerms(menus, Constants.TOP_PARENT_ID);
}
/**
@@ -221,7 +222,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
children.setQuery(menu.getQueryParam());
childrenList.add(children);
router.setChildren(childrenList);
} else if (menu.getParentId().intValue() == 0 && menu.isInnerLink()) {
} else if (menu.getParentId().equals(Constants.TOP_PARENT_ID) && menu.isInnerLink()) {
router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
router.setPath("/");
List<RouterVo> childrenList = new ArrayList<>();
@@ -375,11 +376,11 @@ public class SysMenuServiceImpl implements ISysMenuService {
* @param parentId 传入的父节点ID
* @return String
*/
private List<SysMenu> getChildPerms(List<SysMenu> list, int parentId) {
private List<SysMenu> getChildPerms(List<SysMenu> list, Long parentId) {
List<SysMenu> returnList = new ArrayList<>();
for (SysMenu t : list) {
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId() == parentId) {
if (t.getParentId().equals(parentId)) {
recursionFn(list, t);
returnList.add(t);
}