|
@@ -0,0 +1,58 @@
|
|
|
|
+package com.fdkankan.sale.service.impl;
|
|
|
|
+
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.fdkankan.sale.entity.Dict;
|
|
|
|
+import com.fdkankan.sale.mapper.IDictMapper;
|
|
|
|
+import com.fdkankan.sale.service.IDictService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author
|
|
|
|
+ * @since 2025-01-16
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class DictServiceImpl extends ServiceImpl<IDictMapper, Dict> implements IDictService {
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object getListByKey(String dictKey) {
|
|
|
|
+ LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(Dict::getDictKey,dictKey);
|
|
|
|
+ return this.list(wrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object getTreeByKey(String dictKey) {
|
|
|
|
+ LambdaQueryWrapper<Dict> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ wrapper.eq(Dict::getDictKey,dictKey);
|
|
|
|
+ List<Dict> list = this.list(wrapper);
|
|
|
|
+ if(list.isEmpty()){
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+ List<Dict> parent = list.stream().filter(e -> e.getParentId() == null).collect(Collectors.toList());
|
|
|
|
+ if(list.size() == parent.size()){
|
|
|
|
+ return list;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return getVoList(parent,list);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private List<Dict> getVoList (List<Dict> oneList,List<Dict> allList){
|
|
|
|
+ for (Dict dict : oneList) {
|
|
|
|
+ List<Dict> twoList = allList.stream().filter(e -> e.getParentId() !=null && e.getParentId().equals(dict.getId())).collect(Collectors.toList());
|
|
|
|
+ if(!twoList.isEmpty()){
|
|
|
|
+ dict.setChildren(getVoList(twoList,allList));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return oneList;
|
|
|
|
+ }
|
|
|
|
+}
|