2024-07-08 17:47:02 +08:00
|
|
|
package com.gunshi.project.xyt.service;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.gunshi.project.xyt.mapper.SysDictBMapper;
|
|
|
|
|
import com.gunshi.project.xyt.model.SysDictB;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2024-07-18 18:00:27 +08:00
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
2024-07-08 17:47:02 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
2024-07-19 14:26:20 +08:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2024-07-18 18:00:27 +08:00
|
|
|
import java.util.stream.Collectors;
|
2024-07-08 17:47:02 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 描述: 系统字典表
|
|
|
|
|
* author: xusan
|
|
|
|
|
* date: 2024-07-08 17:30:38
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public class SysDictBService extends ServiceImpl<SysDictBMapper, SysDictB>
|
|
|
|
|
{
|
|
|
|
|
|
2024-07-18 18:00:27 +08:00
|
|
|
|
|
|
|
|
public List<SysDictB> tree() {
|
2024-08-20 13:59:43 +08:00
|
|
|
List<SysDictB> list = list();
|
2024-07-18 18:00:27 +08:00
|
|
|
if (CollectionUtils.isEmpty(list)){
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
Map<Long, List<SysDictB>> listMap = list.stream().collect(Collectors.groupingBy(SysDictB::getPid));
|
|
|
|
|
|
|
|
|
|
list.forEach(o -> o.setChildren(listMap.get(o.getId())));
|
2024-08-20 13:59:43 +08:00
|
|
|
List<SysDictB> parentList = list.stream().filter(o -> 0L == o.getPid()).collect(Collectors.toList());
|
2024-07-18 18:00:27 +08:00
|
|
|
return sorted(parentList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<SysDictB> sorted( List<SysDictB> tree) {
|
|
|
|
|
|
|
|
|
|
List<SysDictB> sorteds = null;
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(tree)){
|
|
|
|
|
sorteds = tree.stream().sorted(Comparator.comparing(SysDictB::getSortOn)
|
|
|
|
|
).collect(Collectors.toList());
|
|
|
|
|
sorteds.forEach(o->{
|
|
|
|
|
o.setChildren(sorted(o.getChildren()));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sorteds;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-28 17:43:20 +08:00
|
|
|
public List<SysDictB> listByCd(String dictCd) {
|
|
|
|
|
return this.baseMapper.listByCd(dictCd);
|
|
|
|
|
}
|
2024-07-08 17:47:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|