test
This commit is contained in:
@@ -118,7 +118,21 @@ public class ClassTreeController {
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
String className = param.get("className").toString();
|
String className = param.get("className").toString();
|
||||||
List<ClassTree> list = classTreeService.getClassTreeByClassName(className);
|
boolean onlyMapped = false;
|
||||||
|
if (param.get("onlyMapped") != null) {
|
||||||
|
onlyMapped = Boolean.parseBoolean(param.get("onlyMapped").toString());
|
||||||
|
}
|
||||||
|
Integer fondId = null;
|
||||||
|
if (param.get("fondId") != null) {
|
||||||
|
fondId = Integer.parseInt(param.get("fondId").toString());
|
||||||
|
}
|
||||||
|
Integer deptId = null;
|
||||||
|
if (param.get("deptId") != null) {
|
||||||
|
deptId = Integer.parseInt(param.get("deptId").toString());
|
||||||
|
}
|
||||||
|
List<ClassTree> list = onlyMapped
|
||||||
|
? classTreeService.getClassTreeByClassNameMappedUnion(className, fondId, deptId)
|
||||||
|
: classTreeService.getClassTreeByClassName(className);
|
||||||
json = new AjaxJson();
|
json = new AjaxJson();
|
||||||
json.getBody().put("list",list);
|
json.getBody().put("list",list);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
|
|||||||
@@ -42,4 +42,8 @@ public interface ClassTreeMapper {
|
|||||||
List<ClassTree> getClassByUserId(@Param("userId") Integer userId);
|
List<ClassTree> getClassByUserId(@Param("userId") Integer userId);
|
||||||
|
|
||||||
List<ClassTree> getClassByDeptId(@Param("deptId") Integer deptId);
|
List<ClassTree> getClassByDeptId(@Param("deptId") Integer deptId);
|
||||||
|
|
||||||
|
List<Integer> getMappedClassIdsUnion();
|
||||||
|
|
||||||
|
List<Integer> getMappedClassIdsUnionBySelection(@Param("fondId") Integer fondId, @Param("deptId") Integer deptId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -335,6 +335,53 @@ public class ClassTreeService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回“门类树”但仅包含已在 t_fondclass 或 t_departmentclass 中出现过的门类(并集),并保留必要的父节点以形成树结构。
|
||||||
|
*/
|
||||||
|
public List<ClassTree> getClassTreeByClassNameMappedUnion(String className, Integer fondId, Integer deptId) {
|
||||||
|
List<ClassTree> fullTree = getClassTreeByClassName(className);
|
||||||
|
List<Integer> mappedIds;
|
||||||
|
if (fondId == null && deptId == null) {
|
||||||
|
mappedIds = classTreeMapper.getMappedClassIdsUnion();
|
||||||
|
} else {
|
||||||
|
mappedIds = classTreeMapper.getMappedClassIdsUnionBySelection(fondId, deptId);
|
||||||
|
}
|
||||||
|
if (mappedIds == null || mappedIds.isEmpty() || fullTree == null || fullTree.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
Set<Integer> allowedIds = new HashSet<>(mappedIds);
|
||||||
|
List<ClassTree> filtered = new ArrayList<>();
|
||||||
|
for (ClassTree node : fullTree) {
|
||||||
|
ClassTree kept = filterTreeByAllowedIds(node, allowedIds);
|
||||||
|
if (kept != null) {
|
||||||
|
filtered.add(kept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClassTree filterTreeByAllowedIds(ClassTree node, Set<Integer> allowedIds) {
|
||||||
|
if (node == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<ClassTree> children = node.getChildClass();
|
||||||
|
List<ClassTree> keptChildren = new ArrayList<>();
|
||||||
|
if (children != null && !children.isEmpty()) {
|
||||||
|
for (ClassTree child : children) {
|
||||||
|
ClassTree keptChild = filterTreeByAllowedIds(child, allowedIds);
|
||||||
|
if (keptChild != null) {
|
||||||
|
keptChildren.add(keptChild);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean keepSelf = node.getId() != null && allowedIds.contains(node.getId());
|
||||||
|
if (!keepSelf && keptChildren.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
node.setChildClass(keptChildren);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 知识产权树
|
* 知识产权树
|
||||||
* @param className
|
* @param className
|
||||||
@@ -1025,5 +1072,3 @@ public class ClassTreeService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -155,5 +155,25 @@
|
|||||||
where t1.id=#{userId} and t5.class_type='C'
|
where t1.id=#{userId} and t5.class_type='C'
|
||||||
order by t5.class_order asc
|
order by t5.class_order asc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getMappedClassIdsUnion" resultType="int">
|
||||||
|
select distinct classid from t_fondclass
|
||||||
|
union
|
||||||
|
select distinct classid from t_departmentclass
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="getMappedClassIdsUnionBySelection" resultType="int">
|
||||||
|
select distinct classid from (
|
||||||
|
<if test="fondId != null">
|
||||||
|
select classid from t_fondclass where fondid = #{fondId,jdbcType=INTEGER}
|
||||||
|
</if>
|
||||||
|
<if test="fondId != null and deptId != null">
|
||||||
|
union
|
||||||
|
</if>
|
||||||
|
<if test="deptId != null">
|
||||||
|
select classid from t_departmentclass where deptid = #{deptId,jdbcType=INTEGER}
|
||||||
|
</if>
|
||||||
|
) t
|
||||||
|
</select>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|||||||
Reference in New Issue
Block a user