feat: 数据字典相关接口提交

This commit is contained in:
2025-12-05 09:52:40 +08:00
parent ae87849a5f
commit 3d471121d0
2 changed files with 11 additions and 6 deletions

View File

@ -16,8 +16,8 @@ public class DictionaryItemController {
private final DictionaryItemService dictionaryItemService;
@GetMapping("/tree")
public ApiResponse<List<DictionaryItemVO>> tree(DictionaryItemDTO record) {
@PostMapping("/tree")
public ApiResponse<List<DictionaryItemVO>> tree(@RequestBody DictionaryItemDTO record) {
return ApiResponse.success(dictionaryItemService.tree(record.getDictionaryId()));
}

View File

@ -23,7 +23,12 @@ public class DictionaryItemServiceImpl implements DictionaryItemService {
@Override
public List<DictionaryItemVO> tree(String dictionaryId) {
List<DictionaryItem> records = dictionaryItemMapper.findAllByDictionaryId(dictionaryId);
return list2tree(records);
List<DictionaryItem> sortedRecords = records.stream().sorted((item1, item2) -> {
int sort1 = item1.getSort() == null ? 0 : item1.getSort();
int sort2 = item2.getSort() == null ? 0 : item2.getSort();
return sort2 - sort1;
}).toList();
return list2tree(sortedRecords);
}
@Override
@ -47,10 +52,10 @@ public class DictionaryItemServiceImpl implements DictionaryItemService {
}
if (record.getSort() == null) {
dictionaryItem.setSort(0);
} else {
dictionaryItem.setSort(record.getSort());
}
if (Strings.isNotBlank(record.getDescription())) {
dictionaryItem.setDescription(record.getDescription());
}
dictionaryItem.setDescription(record.getDescription());
dictionaryItem.setUpdateTime(Timestamp.from(Instant.now()));
return dictionaryItemMapper.updateById(dictionaryItem) > 0;
}