一、递归及其调用
public Result<IPage<ZhxyTeacherInfo>> teacherPagelist(ZhxyTeacherInfo zhxyTeacherInfo,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
List<String> sysDeparts = new ArrayList<>();
//方法调用
List<String> sysDepartList = getAllDepartIdChild(zhxyTeacherInfo.getDeptId(),sysDeparts);
//加入根节点
sysDepartList.add(zhxyTeacherInfo.getDeptId());
// System.err.println("sysDepartList==========="+sysDepartList);
Page<ZhxyTeacherInfo> page = new Page<ZhxyTeacherInfo>(pageNo, pageSize);
// QueryWrapper<ZhxyTeacherInfo> queryWrapper = QueryGenerator.initQueryWrapper(zhxyTeacherInfo, req.getParameterMap());
// queryWrapper.in(true,"dept_id",sysDepartList);
IPage<ZhxyTeacherInfo> pageList = zhxyTeacherInfoService.teacherPagelist(page, zhxyTeacherInfo,sysDepartList);
return Result.OK(pageList);
}
//递归方法
private List<String> getAllDepartIdChild(String deptId,List<String> sysDepartIds){
List<SysDepart> sysDepartList = sysDepartService.list(new LambdaQueryWrapper<SysDepart>().eq(SysDepart::getParentId, deptId));
if (sysDepartList.size()>0){
sysDepartIds.addAll(sysDepartList.stream().map(sysDepart -> {return sysDepart.getId();}).collect(Collectors.toList()));
for (SysDepart sysDepart:sysDepartList){
getAllDepartIdChild(sysDepart.getId(),sysDepartIds);
}
}
return sysDepartIds;
}
二、list类型参数传递
public IPage<ZhxyTeacherInfo> teacherPagelist(Page<ZhxyTeacherInfo> page, ZhxyTeacherInfo zhxyTeacherInfo,@Param("sysDepartList") List<String> sysDepartList);
<select id="teacherPagelist" resultType="org.jeecg.modules.systems.entity.ZhxyTeacherInfo">
SELECT *
FROM zhxy_teacher_info a
WHERE 1=1
<if test="zhxyTeacherInfo != null and zhxyTeacherInfo.realname != ''">
and a.realname = #{zhxyTeacherInfo.realname}
</if>
<if test="zhxyTeacherInfo != null and zhxyTeacherInfo.teacherWorkNo != ''">
and a.realname = #{zhxyTeacherInfo.teacherWorkNo}
</if>
<if test="sysDepartList != null and sysDepartList.size()>0">
and a.dept_id in
<foreach collection="sysDepartList" item="deptId" open="(" separator="," close=")">
#{deptId}
</foreach>
and
</if>
a.del_flag = '0'
</select>