Ver Fonte

湖南只显示有计划的专业库数据

jinxia.mo há 1 semana atrás
pai
commit
153f6348f8

+ 62 - 6
ie-admin/src/main/java/com/ruoyi/web/controller/front/FrontSyMajorRelationController.java

@@ -5,6 +5,7 @@ import com.ruoyi.common.annotation.Anonymous;
 import com.ruoyi.common.core.controller.BaseController;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.core.page.TableDataInfo;
 import com.ruoyi.common.core.text.Convert;
 import com.ruoyi.common.enums.ExamType;
@@ -222,12 +223,39 @@ public class FrontSyMajorRelationController extends BaseController {
         query.setExamType(ConstantUtil.getExamTypeData(examType));
         List<SyMajor> majorList = syMajorService.selectSyMajorList(query);
         List<SyVocational> toList = new ArrayList<>();
-        majorList.forEach(major->{
-            SyVocational syVocational=new SyVocational();
-            BeanUtils.copyProperties(major,syVocational);
-            toList.add(syVocational);
-        });
-        return AjaxResult.success(vocationalService.buildVocationalTreeSelect(toList));
+
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        List<String>  majorListByPlan = new ArrayList<>();
+        //湖南:计划中有的专业加入
+        if (null != loginUser){
+            String location = loginUser.getUser().getLocation();
+            if ("湖南".equals(location)){
+                majorListByPlan = syMajorService.selectMajorsByPlan(location).stream().map(major->major.getName()).collect(Collectors.toList());
+            }
+        }
+        Boolean isFilter = false;
+        for (SyMajor major : majorList) {
+            if (CollectionUtils.isNotEmpty(majorListByPlan) ) {
+                if (major.getLevel()==3&&!majorListByPlan.contains(major.getName())) {
+                    isFilter = true;
+                }else {
+                    SyVocational syVocational = new SyVocational();
+                    BeanUtils.copyProperties(major, syVocational);
+                    toList.add(syVocational);
+                }
+            }else {
+                SyVocational syVocational = new SyVocational();
+                BeanUtils.copyProperties(major, syVocational);
+                toList.add(syVocational);
+            }
+        }
+        List<TreeSelectVocational> list = vocationalService.buildVocationalTreeSelect(toList);
+        if (isFilter){
+            //清除非第三级中children为空
+            list = filterEmptyChildren(list);
+        }
+
+        return AjaxResult.success(list);
     }
 
     /**
@@ -274,4 +302,32 @@ public class FrontSyMajorRelationController extends BaseController {
 
         return AjaxResult.success(resultList);
     }
+
+    /**
+     * 清除列表中 level != 3 且 children 为空的节点
+     */
+    public List<TreeSelectVocational> filterEmptyChildren(List<TreeSelectVocational> list) {
+        if (list == null) {
+            return new ArrayList<>();
+        }
+        return list.stream()
+                .filter(node -> {
+                    // 如果 level == 3,保留该节点
+                    if (Integer.valueOf(3).equals(node.getLevel())) {
+                        return true;
+                    }
+
+                    // 如果 level != 3,但有子节点,先递归处理子节点
+                    if (node.getChildren() != null && !node.getChildren().isEmpty()) {
+                        List<TreeSelectVocational> filteredChildren = filterEmptyChildren(node.getChildren());
+                        node.setChildren(filteredChildren);
+
+                        // 处理子节点后,如果还有子节点,则保留该节点
+                        return !filteredChildren.isEmpty();
+                    }
+                    // level != 3 且没有子节点,过滤掉
+                    return false;
+                })
+                .collect(Collectors.toList());
+    }
 }

+ 1 - 0
ie-system/src/main/java/com/ruoyi/sy/mapper/SyMajorMapper.java

@@ -66,4 +66,5 @@ public interface SyMajorMapper
     public int deleteSyMajorByIds(Long[] ids);
 
     public List<SyMajor> selectSyMajorByPlan(@Param("year") Integer year, @Param("examType") String examType, @Param("universityId") Long universityId, @Param("location") String location);
+    public List<SyMajor> selectMajorsByPlan( @Param("location") String location);
 }

+ 4 - 0
ie-system/src/main/java/com/ruoyi/sy/service/ISyMajorService.java

@@ -3,6 +3,7 @@ package com.ruoyi.sy.service;
 import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.enums.ExamType;
 import com.ruoyi.sy.domain.SyMajor;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -67,4 +68,7 @@ public interface ISyMajorService
 
 
     List<SyMajor> selectPlanMajorList(SysUser user, Long universityId);
+
+    public List<SyMajor> selectMajorsByPlan(String location);
+
 }

+ 5 - 0
ie-system/src/main/java/com/ruoyi/sy/service/impl/SyMajorServiceImpl.java

@@ -123,4 +123,9 @@ public class SyMajorServiceImpl implements ISyMajorService
         DzControl dzControl = dzControlService.selectDzControl(user);
         return syMajorMapper.selectSyMajorByPlan(dzControl.getPlanYear(), user.getExamType().title(), universityId, user.getLocation());
     }
+
+    @Override
+    public List<SyMajor> selectMajorsByPlan(String location) {
+        return syMajorMapper.selectMajorsByPlan(location);
+    }
 }

+ 1 - 1
ie-system/src/main/java/com/ruoyi/sy/service/impl/SyVocationalServiceImpl.java

@@ -58,7 +58,7 @@ public class SyVocationalServiceImpl implements ISyVocationalService
     public List<TreeSelectVocational> buildVocationalTreeSelect(List<SyVocational> vocationalList)
     {
         List<SyVocational> vocationalTrees = buildVocationalTree(vocationalList);
-        List<TreeSelectVocational> treeSelects =vocationalTrees.stream().map(TreeSelectVocational::new).sorted(Comparator.comparing(TreeSelectVocational::getId))
+        List<TreeSelectVocational> treeSelects =vocationalTrees.stream().map(TreeSelectVocational::new).sorted(Comparator.comparing(TreeSelectVocational::getCode))
                 .collect(Collectors.toList());
         return treeSelects;
     }

+ 6 - 0
ie-system/src/main/resources/mapper/sy/SyMajorMapper.xml

@@ -38,6 +38,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         order by code
     </select>
 
+
+
     <select id="selectSyMajorAndChildrenByCode" parameterType="SyMajor" resultMap="SyMajorResult">
         <include refid="selectSyMajorVo"/>
         <where>
@@ -127,4 +129,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         ORDER BY m.`type`, m.`code`
     </select>
 
+    <select id="selectMajorsByPlan" resultMap="SyMajorResult">
+        SELECT DISTINCT majorName name from a_marjor_plan where year=(SELECT max(year) from a_marjor_plan where LOCATION=#{location})
+    </select>
+
 </mapper>