From 1af2baea05b6846f4e22930ce3e93dae95294f2a Mon Sep 17 00:00:00 2001 From: dongzeliang <2746733890@qq.com> Date: Tue, 7 Jan 2025 15:55:52 +0800 Subject: [PATCH] =?UTF-8?q?fix():=20=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=20feat()=EF=BC=9A=E5=A2=9E=E5=8A=A0=E8=B6=85?= =?UTF-8?q?=E7=BA=A7=E5=9F=BA=E7=A1=80=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/utils/reflect/ReflectUtils.java | 38 ++++++-------- .../com/muyu/common/core/web/SuperBasic.java | 41 ++++++++++++++++ .../common/core/web/model/QueryModel.java | 3 +- .../system/controller/SysDeptController.java | 14 +++--- .../controller/SysDictDataController.java | 4 +- .../system/controller/SysRoleController.java | 2 +- .../system/controller/SysUserController.java | 4 +- .../domain/model/SysDeptPageQueryModel.java | 28 ++++++++--- .../muyu/system/service/SysDeptService.java | 18 +++---- .../service/impl/SysDeptServiceImpl.java | 49 +++++++++---------- 10 files changed, 127 insertions(+), 74 deletions(-) create mode 100644 cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/SuperBasic.java diff --git a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/utils/reflect/ReflectUtils.java b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/utils/reflect/ReflectUtils.java index 2ec7e4f..9f9bd63 100644 --- a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/utils/reflect/ReflectUtils.java +++ b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/utils/reflect/ReflectUtils.java @@ -2,13 +2,13 @@ package com.muyu.common.core.utils.reflect; import com.muyu.common.core.text.Convert; import com.muyu.common.core.utils.DateUtils; +import lombok.extern.log4j.Log4j2; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.apache.poi.ss.usermodel.DateUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.lang.reflect.*; +import java.util.Arrays; import java.util.Date; /** @@ -17,6 +17,7 @@ import java.util.Date; * @author muyu */ @SuppressWarnings("rawtypes") +@Log4j2 public class ReflectUtils { private static final String SETTER_PREFIX = "set"; @@ -24,8 +25,6 @@ public class ReflectUtils { private static final String CGLIB_CLASS_SEPARATOR = "$$"; - private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class); - /** * 调用Getter方法. * 支持多级,如:对象名.对象名.方法 @@ -65,14 +64,14 @@ public class ReflectUtils { public static E getFieldValue (final Object obj, final String fieldName) { Field field = getAccessibleField(obj, fieldName); if (field == null) { - logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); + log.debug("在 [{}] 中,没有找到 [{}] 字段 ", obj.getClass(), fieldName); return null; } E result = null; try { result = (E) field.get(obj); } catch (IllegalAccessException e) { - logger.error("不可能抛出的异常{}", e.getMessage()); + log.error("不可能抛出的异常{}", e.getMessage()); } return result; } @@ -84,13 +83,13 @@ public class ReflectUtils { Field field = getAccessibleField(obj, fieldName); if (field == null) { // throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); - logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); + log.debug("在 [{}] 中,没有找到 [{}] 字段 ", obj.getClass(), fieldName); return; } try { field.set(obj, value); } catch (IllegalAccessException e) { - logger.error("不可能抛出的异常: {}", e.getMessage()); + log.error("不可能抛出的异常: {}", e.getMessage()); } } @@ -107,13 +106,13 @@ public class ReflectUtils { } Method method = getAccessibleMethod(obj, methodName, parameterTypes); if (method == null) { - logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); + log.debug("在 [{}] 中,没有找到 [{}] 方法 ", obj.getClass(), methodName); return null; } try { return (E) method.invoke(obj, args); } catch (Exception e) { - String msg = "method: " + method + ", obj: " + obj + ", args: " + args + ""; + String msg = "method: " + method + ", obj: " + obj + ", args: " + Arrays.toString(args); throw convertReflectionExceptionToUnchecked(msg, e); } } @@ -128,7 +127,7 @@ public class ReflectUtils { Method method = getAccessibleMethodByName(obj, methodName, args.length); if (method == null) { // 如果为空不报错,直接返回空。 - logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); + log.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); return null; } try { @@ -182,9 +181,7 @@ public class ReflectUtils { Field field = superClass.getDeclaredField(fieldName); makeAccessible(field); return field; - } catch (NoSuchFieldException e) { - continue; - } + } catch (NoSuchFieldException ignored) {} } return null; } @@ -207,9 +204,7 @@ public class ReflectUtils { Method method = searchType.getDeclaredMethod(methodName, parameterTypes); makeAccessible(method); return method; - } catch (NoSuchMethodException e) { - continue; - } + } catch (NoSuchMethodException ignored) {} } return null; } @@ -275,19 +270,18 @@ public class ReflectUtils { Type genType = clazz.getGenericSuperclass(); if (!(genType instanceof ParameterizedType)) { - logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); + log.debug("{}'s superclass not ParameterizedType", clazz.getSimpleName()); return Object.class; } Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); if (index >= params.length || index < 0) { - logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " - + params.length); + log.debug("Index: {}, Size of {}'s Parameterized Type: {}", index, clazz.getSimpleName(), params.length); return Object.class; } if (!(params[index] instanceof Class)) { - logger.debug(clazz.getSimpleName() + " not set the actual class on superclass generic parameter"); + log.debug("{} not set the actual class on superclass generic parameter", clazz.getSimpleName()); return Object.class; } @@ -299,7 +293,7 @@ public class ReflectUtils { throw new RuntimeException("Instance must not be null"); } Class clazz = instance.getClass(); - if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { + if (clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { Class superClass = clazz.getSuperclass(); if (superClass != null && !Object.class.equals(superClass)) { return superClass; diff --git a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/SuperBasic.java b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/SuperBasic.java new file mode 100644 index 0000000..b471250 --- /dev/null +++ b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/SuperBasic.java @@ -0,0 +1,41 @@ +package com.muyu.common.core.web; + +import com.muyu.common.core.utils.reflect.ReflectUtils; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import java.io.Serial; +import java.io.Serializable; + +/** + * 列表查询模型 + * + * @author DongZeLiang + * @date 2024-01-07 10:01 + */ +@Data +@SuperBuilder +@NoArgsConstructor +@AllArgsConstructor +public class SuperBasic implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + /** + * 业务ID - 暂时可以不用 + * + * 设计上可以用来重写日志的tracId + */ + private String serviceId; + + /** + * 创建空对象 + * @return 空类型对象 + */ + public static OC ofNull(){ + return (OC) builder().build(); + } +} diff --git a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/model/QueryModel.java b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/model/QueryModel.java index 8a2609e..6dfd192 100644 --- a/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/model/QueryModel.java +++ b/cloud-common/cloud-common-core/src/main/java/com/muyu/common/core/web/model/QueryModel.java @@ -4,6 +4,7 @@ package com.muyu.common.core.web.model; import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.muyu.common.core.utils.StringUtils; +import com.muyu.common.core.web.SuperBasic; import com.muyu.common.core.web.page.PageReq; import lombok.AllArgsConstructor; import lombok.Data; @@ -22,7 +23,7 @@ import java.util.List; @SuperBuilder @NoArgsConstructor @AllArgsConstructor -public class QueryModel { +public class QueryModel extends SuperBasic { /** * 当前记录起始索引 diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java index 4db25b8..8bcd88c 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDeptController.java @@ -9,6 +9,8 @@ import com.muyu.common.log.enums.BusinessType; import com.muyu.common.security.annotation.RequiresPermissions; import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.system.domain.SysDept; +import com.muyu.system.domain.model.SysDeptPageQueryModel; +import com.muyu.system.domain.rep.SysDeptListReq; import com.muyu.system.service.SysDeptService; import io.swagger.v3.oas.annotations.tags.Tag; import org.apache.commons.lang3.ArrayUtils; @@ -36,9 +38,9 @@ public class SysDeptController extends BaseController { */ @RequiresPermissions("system:dept:list") @PostMapping("/list") - public Result list (@RequestBody SysDept dept) { - List depts = deptService.selectDeptList(dept); - return success(depts); + public Result> list (@RequestBody SysDeptListReq sysDeptListReq) { + List deptList = deptService.queryList(SysDeptPageQueryModel.reqBuild(sysDeptListReq)); + return success(deptList); } /** @@ -47,9 +49,9 @@ public class SysDeptController extends BaseController { @RequiresPermissions("system:dept:list") @GetMapping("/list/exclude/{deptId}") public Result excludeChild (@PathVariable(value = "deptId", required = false) Long deptId) { - List depts = deptService.selectDeptList(new SysDept()); - depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); - return success(depts); + List deptList = deptService.queryList(SysDeptPageQueryModel.builder().build()); + deptList.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId)); + return success(deptList); } /** diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDictDataController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDictDataController.java index 79a9cab..376e1c7 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDictDataController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysDictDataController.java @@ -66,7 +66,7 @@ public class SysDictDataController extends BaseController { public Result dictType (@PathVariable("dictType") String dictType) { List data = dictTypeService.selectDictDataByType(dictType); if (StringUtils.isNull(data)) { - data = new ArrayList(); + data = new ArrayList<>(); } return success(data); } @@ -99,7 +99,7 @@ public class SysDictDataController extends BaseController { @RequiresPermissions("system:dict:remove") @Log(title = "字典类型", businessType = BusinessType.DELETE) @DeleteMapping("/{dictCodes}") - public Result remove (@PathVariable("dictCode") Long[] dictCodes) { + public Result remove (@PathVariable("dictCodes") Long[] dictCodes) { dictDataService.deleteDictDataByIds(dictCodes); return success(); } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysRoleController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysRoleController.java index 84066a9..9c45f4c 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysRoleController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysRoleController.java @@ -204,7 +204,7 @@ public class SysRoleController extends BaseController { public Result deptTree (@PathVariable("roleId") Long roleId) { return Result.success( DeptTreeResp.builder() - .depts(deptService.selectDeptTreeList(new SysDept())) + .depts(deptService.selectDeptTreeList()) .checkedKeys(deptService.selectDeptListByRoleId(roleId)) .build() ); diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java index 0bd1796..54a14de 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/controller/SysUserController.java @@ -286,7 +286,7 @@ public class SysUserController extends BaseController { */ @RequiresPermissions("system:user:list") @GetMapping("/deptTree") - public Result deptTree (SysDept dept) { - return success(deptService.selectDeptTreeList(dept)); + public Result deptTree () { + return success(deptService.selectDeptTreeList()); } } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/model/SysDeptPageQueryModel.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/model/SysDeptPageQueryModel.java index 260f3a1..06fd114 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/model/SysDeptPageQueryModel.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/domain/model/SysDeptPageQueryModel.java @@ -1,7 +1,6 @@ package com.muyu.system.domain.model; import com.muyu.common.core.web.model.QueryModel; -import com.muyu.system.domain.rep.SysConfigListReq; import com.muyu.system.domain.rep.SysDeptListReq; import lombok.AllArgsConstructor; import lombok.Data; @@ -9,8 +8,6 @@ import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import lombok.experimental.SuperBuilder; -import java.util.Date; - /** * 参数配置 分页 模型 */ @@ -21,6 +18,11 @@ import java.util.Date; @EqualsAndHashCode(callSuper = false) public class SysDeptPageQueryModel extends QueryModel { + /** + * 部门ID + */ + private Long deptId; + /** * 部门名称 */ @@ -32,12 +34,26 @@ public class SysDeptPageQueryModel extends QueryModel { private String status; + /** + * 根据部门请求对象构建查询对象 + * @param sysDeptListReq 部门列表请求对象 + * @return 部门请求构建查询对象 + */ public static SysDeptPageQueryModel reqBuild(SysDeptListReq sysDeptListReq) { - SysDeptPageQueryModel sysDeptPageQueryModel = SysDeptPageQueryModel.builder() + return SysDeptPageQueryModel.builder() .deptName(sysDeptListReq.getDeptName()) .status(sysDeptListReq.getStatus()) .build(); - sysDeptPageQueryModel.domainBuild(sysDeptListReq); - return sysDeptPageQueryModel; + } + + /** + * 根据部门ID构建查询对象 + * @param deptId 部门ID + * @return 部门查询对象 + */ + public static SysDeptPageQueryModel ofToDeptId(Long deptId) { + return SysDeptPageQueryModel.builder() + .deptId(deptId) + .build(); } } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java index aae0ce7..a252608 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/SysDeptService.java @@ -1,10 +1,7 @@ package com.muyu.system.service; import com.baomidou.mybatisplus.extension.service.IService; -import com.muyu.common.core.web.page.PageQueryModel; import com.muyu.common.system.domain.SysDept; -import com.muyu.system.domain.SysConfig; -import com.muyu.system.domain.model.SysConfigPageQueryModel; import com.muyu.system.domain.model.SysDeptPageQueryModel; import com.muyu.system.domain.vo.TreeSelect; @@ -19,20 +16,18 @@ public interface SysDeptService extends IService { /** * 查询部门管理数据 * - * @param dept 部门信息 + * @param deptPageQueryModel 部门信息 * * @return 部门信息集合 */ - public List selectDeptList (SysDept dept); + public List selectDeptList (SysDeptPageQueryModel deptPageQueryModel); /** * 查询部门树结构信息 * - * @param dept 部门信息 - * * @return 部门树信息集合 */ - public List selectDeptTreeList (SysDept dept); + public List selectDeptTreeList (); /** * 构建前端所需要树结构 @@ -140,5 +135,10 @@ public interface SysDeptService extends IService { */ public int deleteDeptById (Long deptId); - PageQueryModel pageQuery(SysDeptPageQueryModel sysDeptPageQueryModel); + /** + * 查询部门信息 + * @param sysDeptPageQueryModel 部门查询模型 + * @return 分页返回结果 + */ + List queryList(SysDeptPageQueryModel sysDeptPageQueryModel); } diff --git a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java index 40bb9a5..57ad332 100644 --- a/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java +++ b/cloud-modules/cloud-modules-system/src/main/java/com/muyu/system/service/impl/SysDeptServiceImpl.java @@ -1,20 +1,17 @@ package com.muyu.system.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.muyu.common.core.constant.UserConstants; import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.text.Convert; import com.muyu.common.core.utils.SpringUtils; import com.muyu.common.core.utils.StringUtils; -import com.muyu.common.core.web.page.PageQueryModel; import com.muyu.common.datascope.annotation.DataScope; import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.system.domain.SysDept; import com.muyu.common.system.domain.SysRole; import com.muyu.common.system.domain.SysUser; -import com.muyu.system.domain.SysConfig; import com.muyu.system.domain.model.SysDeptPageQueryModel; import com.muyu.system.domain.vo.TreeSelect; import com.muyu.system.mapper.SysDeptMapper; @@ -24,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -45,39 +41,45 @@ public class SysDeptServiceImpl extends ServiceImpl @Override - public PageQueryModel pageQuery(SysDeptPageQueryModel sysDeptPageQueryModel) { + public List queryList(SysDeptPageQueryModel sysDeptPageQueryModel) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName()); queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus()); - Page page = this.page(sysDeptPageQueryModel.buildPage(), queryWrapper); - return PageQueryModel.of(page); + return this.list(queryWrapper); } /** * 查询部门管理数据 * - * @param dept 部门信息 + * @param sysDeptPageQueryModel 部门信息 * * @return 部门信息集合 */ @Override @DataScope(deptAlias = "d") - public List selectDeptList (SysDept dept) { - return deptMapper.selectDeptList(dept); + public List selectDeptList (SysDeptPageQueryModel sysDeptPageQueryModel) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq( + StringUtils.isNotNull(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName() + ); + queryWrapper.eq(Objects.nonNull(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus()); + queryWrapper.eq(sysDeptPageQueryModel.getDeptId() != null,SysDept::getDeptId,sysDeptPageQueryModel.getDeptId()); + return this.list(queryWrapper); } /** * 查询部门树结构信息 * - * @param dept 部门信息 - * * @return 部门树信息集合 */ @Override - public List selectDeptTreeList (SysDept dept) { - List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); - return buildDeptTreeSelect(depts); + public List selectDeptTreeList () { + return buildDeptTreeSelect( + SpringUtils.getAopProxy(this).selectDeptList( + SysDeptPageQueryModel.ofNull() + ) + ); } /** @@ -89,8 +91,8 @@ public class SysDeptServiceImpl extends ServiceImpl */ @Override public List buildDeptTree (List depts) { - List returnList = new ArrayList(); - List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); + List returnList = new ArrayList<>(); + List tempList = depts.stream().map(SysDept::getDeptId).toList(); for (SysDept dept : depts) { // 如果是顶级节点, 遍历该父节点的所有子节点 if (!tempList.contains(dept.getParentId())) { @@ -205,9 +207,8 @@ public class SysDeptServiceImpl extends ServiceImpl @Override public void checkDeptDataScope (Long deptId) { if (!SysUser.isAdmin(SecurityUtils.getUserId())) { - SysDept dept = new SysDept(); - dept.setDeptId(deptId); - List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + List depts = SpringUtils.getAopProxy(this) + .selectDeptList(SysDeptPageQueryModel.ofToDeptId(deptId)); if (StringUtils.isEmpty(depts)) { throw new ServiceException("没有权限访问部门数据!"); } @@ -281,7 +282,7 @@ public class SysDeptServiceImpl extends ServiceImpl for (SysDept child : children) { child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); } - if (children.size() > 0) { + if (!children.isEmpty()) { deptMapper.updateDeptChildren(children); } } @@ -319,9 +320,7 @@ public class SysDeptServiceImpl extends ServiceImpl */ private List getChildList (List list, SysDept t) { List tlist = new ArrayList(); - Iterator it = list.iterator(); - while (it.hasNext()) { - SysDept n = (SysDept) it.next(); + for (SysDept n : list) { if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { tlist.add(n); } @@ -333,6 +332,6 @@ public class SysDeptServiceImpl extends ServiceImpl * 判断是否有子节点 */ private boolean hasChild (List list, SysDept t) { - return getChildList(list, t).size() > 0 ? true : false; + return !getChildList(list, t).isEmpty(); } }