Parcourir la source

采购类型筛选不出现父节点或子节点修复

lizhenhao il y a 2 ans
Parent
commit
ac32962dfb

+ 1 - 1
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/materialType/controller/MaterialTypeController.java

@@ -74,7 +74,7 @@ public class MaterialTypeController {
     @ApiOperation(value = "新增/修改")
     @PostMapping("/save")
     public ResponseEntity<String> save(@RequestBody MaterialTypeInfo info) {
-        String s = service.save(info);
+        String s = service.saveM(info);
         return ResponseEntity.ok(s);
     }
 

+ 112 - 12
jeeplus-module/jeeplus-test/src/main/java/com/jeeplus/test/materialManagement/materialType/service/MaterialTypeService.java

@@ -1,40 +1,95 @@
 package com.jeeplus.test.materialManagement.materialType.service;
 
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jeeplus.core.domain.BaseEntity;
 import com.jeeplus.sys.service.dto.OfficeDTO;
 import com.jeeplus.sys.service.dto.UserDTO;
 import com.jeeplus.sys.utils.StringUtils;
 import com.jeeplus.sys.utils.UserUtils;
+import com.jeeplus.test.cw.projectBusinessType.domain.CwProjectBusinessType;
 import com.jeeplus.test.materialManagement.materialType.domain.MaterialTypeInfo;
 import com.jeeplus.test.materialManagement.materialType.mapper.MaterialTypeMapper;
+import com.jeeplus.test.program.configuration.typeDict.domain.ProgramTypeDict;
 import org.apache.commons.compress.utils.Lists;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.UUID;
+import java.util.stream.Collectors;
 
 /**
  * @author: 王强
  * @create: 2022-11-25 09:13
  **/
 @Service
-public class MaterialTypeService {
+public class MaterialTypeService extends ServiceImpl<MaterialTypeMapper,MaterialTypeInfo> {
 
     @Resource
     private MaterialTypeMapper mapper;
 
     public List<MaterialTypeInfo> list(MaterialTypeInfo info) {
         LambdaQueryWrapper<MaterialTypeInfo> wrapper = new LambdaQueryWrapper<>();
-        if (StringUtils.isNotEmpty(info.getName())) {
-            wrapper.like(MaterialTypeInfo::getName, info.getName());
-        }
-        if (info.getSort() != null) {
-            wrapper.like(MaterialTypeInfo::getSort, info.getSort());
+        if(StringUtils.isNotBlank(info.getName())){
+            //根据type模糊查询
+            List<MaterialTypeInfo> materialTypeInfoList = this.list(new QueryWrapper<MaterialTypeInfo>().lambda()
+                    .like(StringUtils.isNotBlank(info.getName()), MaterialTypeInfo::getName, info.getName())
+            );
+            List<String> collect = materialTypeInfoList.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList());
+            //materialTypeInfoList的父级id全部获取
+            List<String> cupIdList = materialTypeInfoList.stream().map(MaterialTypeInfo::getParentId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+            //获取materialTypeInfoList的父级id的父级id
+            List<String> cupIdPList = new ArrayList<>();
+            if (CollectionUtil.isNotEmpty(cupIdList)) {
+                cupIdList.stream().forEach(item -> {
+                    MaterialTypeInfo byId = this.getById(item);
+                    if (ObjectUtil.isNotEmpty(byId)) {
+                        if (StringUtils.isNotBlank(byId.getParentId())) {
+                            cupIdPList.add(byId.getParentId());
+                        }
+                    }
+                });
+            }
+            //获取collect的下级id
+            List<String> childIdList = new ArrayList<>();
+            collect.stream().forEach(item -> {
+                List<MaterialTypeInfo> list = this.list(new LambdaQueryWrapper<MaterialTypeInfo>().eq(MaterialTypeInfo::getParentId, item));
+                if (CollectionUtil.isNotEmpty(list)) {
+                    List<String> collect1 = list.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+                    if (CollectionUtil.isNotEmpty(collect1)) {
+                        childIdList.addAll(collect1);
+                        //获取collect的下级的下级的id
+                        collect1.stream().forEach(i -> {
+                            List<MaterialTypeInfo> l = this.list(new LambdaQueryWrapper<MaterialTypeInfo>().eq(MaterialTypeInfo::getParentId, i));
+                            if (CollectionUtil.isNotEmpty(l)) {
+                                List<String> collect2 = l.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+                                if (CollectionUtil.isNotEmpty(collect2)) {
+                                    childIdList.addAll(collect2);
+                                }
+                            }
+                        });
+                    }
+                }
+            });
+            //将获取到的这几个id集合融合到一起并去重,然后根据id查询,即可得到结果
+            collect.addAll(cupIdList);
+            collect.addAll(cupIdPList);
+            collect.addAll(childIdList);
+
+            List<String> idList = collect.stream().distinct().collect(Collectors.toList());
+            if(CollectionUtil.isNotEmpty(idList)){
+                wrapper.in(MaterialTypeInfo::getId,idList);
+            }
         }
+//        if (info.getSort() != null) {
+//            wrapper.like(MaterialTypeInfo::getSort, info.getSort());
+//        }
 //        wrapper.eq(CwReimbursementTypeInfo::getBusinessType, "1");
 
         wrapper.eq(BaseEntity::getDelFlag, 0);
@@ -69,11 +124,56 @@ public class MaterialTypeService {
 
     public List<MaterialTypeInfo> cgList(MaterialTypeInfo info) {
         LambdaQueryWrapper<MaterialTypeInfo> wrapper = new LambdaQueryWrapper<>();
-        if (StringUtils.isNotEmpty(info.getName())) {
-            wrapper.like(MaterialTypeInfo::getName, info.getName());
-        }
-        if (info.getSort() != null) {
-            wrapper.like(MaterialTypeInfo::getSort, info.getSort());
+        if(StringUtils.isNotBlank(info.getName())){
+            //根据type模糊查询
+            List<MaterialTypeInfo> materialTypeInfoList = this.list(new QueryWrapper<MaterialTypeInfo>().lambda()
+                    .like(StringUtils.isNotBlank(info.getName()), MaterialTypeInfo::getName, info.getName())
+            );
+            List<String> collect = materialTypeInfoList.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList());
+            //materialTypeInfoList的父级id全部获取
+            List<String> cupIdList = materialTypeInfoList.stream().map(MaterialTypeInfo::getParentId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+            //获取materialTypeInfoList的父级id的父级id
+            List<String> cupIdPList = new ArrayList<>();
+            if (CollectionUtil.isNotEmpty(cupIdList)) {
+                cupIdList.stream().forEach(item -> {
+                    MaterialTypeInfo byId = this.getById(item);
+                    if (ObjectUtil.isNotEmpty(byId)) {
+                        if (StringUtils.isNotBlank(byId.getParentId())) {
+                            cupIdPList.add(byId.getParentId());
+                        }
+                    }
+                });
+            }
+            //获取collect的下级id
+            List<String> childIdList = new ArrayList<>();
+            collect.stream().forEach(item -> {
+                List<MaterialTypeInfo> list = this.list(new LambdaQueryWrapper<MaterialTypeInfo>().eq(MaterialTypeInfo::getParentId, item));
+                if (CollectionUtil.isNotEmpty(list)) {
+                    List<String> collect1 = list.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+                    if (CollectionUtil.isNotEmpty(collect1)) {
+                        childIdList.addAll(collect1);
+                        //获取collect的下级的下级的id
+                        collect1.stream().forEach(i -> {
+                            List<MaterialTypeInfo> l = this.list(new LambdaQueryWrapper<MaterialTypeInfo>().eq(MaterialTypeInfo::getParentId, i));
+                            if (CollectionUtil.isNotEmpty(l)) {
+                                List<String> collect2 = l.stream().map(MaterialTypeInfo::getId).collect(Collectors.toList()).stream().distinct().collect(Collectors.toList());
+                                if (CollectionUtil.isNotEmpty(collect2)) {
+                                    childIdList.addAll(collect2);
+                                }
+                            }
+                        });
+                    }
+                }
+            });
+            //将获取到的这几个id集合融合到一起并去重,然后根据id查询,即可得到结果
+            collect.addAll(cupIdList);
+            collect.addAll(cupIdPList);
+            collect.addAll(childIdList);
+
+            List<String> idList = collect.stream().distinct().collect(Collectors.toList());
+            if(CollectionUtil.isNotEmpty(idList)){
+                wrapper.in(MaterialTypeInfo::getId,idList);
+            }
         }
 
         wrapper.eq(BaseEntity::getDelFlag, 0);
@@ -81,7 +181,7 @@ public class MaterialTypeService {
         return mapper.selectList(wrapper);
     }
 
-    public String save(MaterialTypeInfo info) {
+    public String saveM(MaterialTypeInfo info) {
         // parentId未传值,则表示一级菜单
         if(StringUtils.isEmpty(info.getParentId())) {
             info.setParentId("0");