fix(): 修复代码格式

feat():增加超级基础类
boot3.0
dongzeliang 2025-01-07 15:55:52 +08:00
parent 25888aa95a
commit 1af2baea05
10 changed files with 127 additions and 74 deletions

View File

@ -2,13 +2,13 @@ package com.muyu.common.core.utils.reflect;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.DateUtils; import com.muyu.common.core.utils.DateUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.Validate;
import org.apache.poi.ss.usermodel.DateUtil; import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
/** /**
@ -17,6 +17,7 @@ import java.util.Date;
* @author muyu * @author muyu
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@Log4j2
public class ReflectUtils { public class ReflectUtils {
private static final String SETTER_PREFIX = "set"; private static final String SETTER_PREFIX = "set";
@ -24,8 +25,6 @@ public class ReflectUtils {
private static final String CGLIB_CLASS_SEPARATOR = "$$"; private static final String CGLIB_CLASS_SEPARATOR = "$$";
private static Logger logger = LoggerFactory.getLogger(ReflectUtils.class);
/** /**
* Getter. * Getter.
* .. * ..
@ -65,14 +64,14 @@ public class ReflectUtils {
public static <E> E getFieldValue (final Object obj, final String fieldName) { public static <E> E getFieldValue (final Object obj, final String fieldName) {
Field field = getAccessibleField(obj, fieldName); Field field = getAccessibleField(obj, fieldName);
if (field == null) { if (field == null) {
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); log.debug("在 [{}] 中,没有找到 [{}] 字段 ", obj.getClass(), fieldName);
return null; return null;
} }
E result = null; E result = null;
try { try {
result = (E) field.get(obj); result = (E) field.get(obj);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
logger.error("不可能抛出的异常{}", e.getMessage()); log.error("不可能抛出的异常{}", e.getMessage());
} }
return result; return result;
} }
@ -84,13 +83,13 @@ public class ReflectUtils {
Field field = getAccessibleField(obj, fieldName); Field field = getAccessibleField(obj, fieldName);
if (field == null) { if (field == null) {
// throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); // throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 "); log.debug("在 [{}] 中,没有找到 [{}] 字段 ", obj.getClass(), fieldName);
return; return;
} }
try { try {
field.set(obj, value); field.set(obj, value);
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
logger.error("不可能抛出的异常: {}", e.getMessage()); log.error("不可能抛出的异常: {}", e.getMessage());
} }
} }
@ -107,13 +106,13 @@ public class ReflectUtils {
} }
Method method = getAccessibleMethod(obj, methodName, parameterTypes); Method method = getAccessibleMethod(obj, methodName, parameterTypes);
if (method == null) { if (method == null) {
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); log.debug("在 [{}] 中,没有找到 [{}] 方法 ", obj.getClass(), methodName);
return null; return null;
} }
try { try {
return (E) method.invoke(obj, args); return (E) method.invoke(obj, args);
} catch (Exception e) { } 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); throw convertReflectionExceptionToUnchecked(msg, e);
} }
} }
@ -128,7 +127,7 @@ public class ReflectUtils {
Method method = getAccessibleMethodByName(obj, methodName, args.length); Method method = getAccessibleMethodByName(obj, methodName, args.length);
if (method == null) { if (method == null) {
// 如果为空不报错,直接返回空。 // 如果为空不报错,直接返回空。
logger.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 "); log.debug("在 [" + obj.getClass() + "] 中,没有找到 [" + methodName + "] 方法 ");
return null; return null;
} }
try { try {
@ -182,9 +181,7 @@ public class ReflectUtils {
Field field = superClass.getDeclaredField(fieldName); Field field = superClass.getDeclaredField(fieldName);
makeAccessible(field); makeAccessible(field);
return field; return field;
} catch (NoSuchFieldException e) { } catch (NoSuchFieldException ignored) {}
continue;
}
} }
return null; return null;
} }
@ -207,9 +204,7 @@ public class ReflectUtils {
Method method = searchType.getDeclaredMethod(methodName, parameterTypes); Method method = searchType.getDeclaredMethod(methodName, parameterTypes);
makeAccessible(method); makeAccessible(method);
return method; return method;
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException ignored) {}
continue;
}
} }
return null; return null;
} }
@ -275,19 +270,18 @@ public class ReflectUtils {
Type genType = clazz.getGenericSuperclass(); Type genType = clazz.getGenericSuperclass();
if (!(genType instanceof ParameterizedType)) { if (!(genType instanceof ParameterizedType)) {
logger.debug(clazz.getSimpleName() + "'s superclass not ParameterizedType"); log.debug("{}'s superclass not ParameterizedType", clazz.getSimpleName());
return Object.class; return Object.class;
} }
Type[] params = ((ParameterizedType) genType).getActualTypeArguments(); Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
if (index >= params.length || index < 0) { if (index >= params.length || index < 0) {
logger.debug("Index: " + index + ", Size of " + clazz.getSimpleName() + "'s Parameterized Type: " log.debug("Index: {}, Size of {}'s Parameterized Type: {}", index, clazz.getSimpleName(), params.length);
+ params.length);
return Object.class; return Object.class;
} }
if (!(params[index] instanceof 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; return Object.class;
} }
@ -299,7 +293,7 @@ public class ReflectUtils {
throw new RuntimeException("Instance must not be null"); throw new RuntimeException("Instance must not be null");
} }
Class clazz = instance.getClass(); Class clazz = instance.getClass();
if (clazz != null && clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) { if (clazz.getName().contains(CGLIB_CLASS_SEPARATOR)) {
Class<?> superClass = clazz.getSuperclass(); Class<?> superClass = clazz.getSuperclass();
if (superClass != null && !Object.class.equals(superClass)) { if (superClass != null && !Object.class.equals(superClass)) {
return superClass; return superClass;

View File

@ -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<OC> implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* ID -
*
* tracId
*/
private String serviceId;
/**
*
* @return
*/
public static <OC> OC ofNull(){
return (OC) builder().build();
}
}

View File

@ -4,6 +4,7 @@ package com.muyu.common.core.web.model;
import com.baomidou.mybatisplus.core.metadata.OrderItem; import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.common.core.utils.StringUtils; import com.muyu.common.core.utils.StringUtils;
import com.muyu.common.core.web.SuperBasic;
import com.muyu.common.core.web.page.PageReq; import com.muyu.common.core.web.page.PageReq;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -22,7 +23,7 @@ import java.util.List;
@SuperBuilder @SuperBuilder
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class QueryModel<T> { public class QueryModel<T> extends SuperBasic<T> {
/** /**
* *

View File

@ -9,6 +9,8 @@ import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions; import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept; 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 com.muyu.system.service.SysDeptService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
@ -36,9 +38,9 @@ public class SysDeptController extends BaseController {
*/ */
@RequiresPermissions("system:dept:list") @RequiresPermissions("system:dept:list")
@PostMapping("/list") @PostMapping("/list")
public Result list (@RequestBody SysDept dept) { public Result<List<SysDept>> list (@RequestBody SysDeptListReq sysDeptListReq) {
List<SysDept> depts = deptService.selectDeptList(dept); List<SysDept> deptList = deptService.queryList(SysDeptPageQueryModel.reqBuild(sysDeptListReq));
return success(depts); return success(deptList);
} }
/** /**
@ -47,9 +49,9 @@ public class SysDeptController extends BaseController {
@RequiresPermissions("system:dept:list") @RequiresPermissions("system:dept:list")
@GetMapping("/list/exclude/{deptId}") @GetMapping("/list/exclude/{deptId}")
public Result excludeChild (@PathVariable(value = "deptId", required = false) Long deptId) { public Result excludeChild (@PathVariable(value = "deptId", required = false) Long deptId) {
List<SysDept> depts = deptService.selectDeptList(new SysDept()); List<SysDept> deptList = deptService.queryList(SysDeptPageQueryModel.builder().build());
depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); deptList.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId));
return success(depts); return success(deptList);
} }
/** /**

View File

@ -66,7 +66,7 @@ public class SysDictDataController extends BaseController {
public Result dictType (@PathVariable("dictType") String dictType) { public Result dictType (@PathVariable("dictType") String dictType) {
List<SysDictData> data = dictTypeService.selectDictDataByType(dictType); List<SysDictData> data = dictTypeService.selectDictDataByType(dictType);
if (StringUtils.isNull(data)) { if (StringUtils.isNull(data)) {
data = new ArrayList<SysDictData>(); data = new ArrayList<>();
} }
return success(data); return success(data);
} }
@ -99,7 +99,7 @@ public class SysDictDataController extends BaseController {
@RequiresPermissions("system:dict:remove") @RequiresPermissions("system:dict:remove")
@Log(title = "字典类型", businessType = BusinessType.DELETE) @Log(title = "字典类型", businessType = BusinessType.DELETE)
@DeleteMapping("/{dictCodes}") @DeleteMapping("/{dictCodes}")
public Result remove (@PathVariable("dictCode") Long[] dictCodes) { public Result remove (@PathVariable("dictCodes") Long[] dictCodes) {
dictDataService.deleteDictDataByIds(dictCodes); dictDataService.deleteDictDataByIds(dictCodes);
return success(); return success();
} }

View File

@ -204,7 +204,7 @@ public class SysRoleController extends BaseController {
public Result deptTree (@PathVariable("roleId") Long roleId) { public Result deptTree (@PathVariable("roleId") Long roleId) {
return Result.success( return Result.success(
DeptTreeResp.builder() DeptTreeResp.builder()
.depts(deptService.selectDeptTreeList(new SysDept())) .depts(deptService.selectDeptTreeList())
.checkedKeys(deptService.selectDeptListByRoleId(roleId)) .checkedKeys(deptService.selectDeptListByRoleId(roleId))
.build() .build()
); );

View File

@ -286,7 +286,7 @@ public class SysUserController extends BaseController {
*/ */
@RequiresPermissions("system:user:list") @RequiresPermissions("system:user:list")
@GetMapping("/deptTree") @GetMapping("/deptTree")
public Result deptTree (SysDept dept) { public Result deptTree () {
return success(deptService.selectDeptTreeList(dept)); return success(deptService.selectDeptTreeList());
} }
} }

View File

@ -1,7 +1,6 @@
package com.muyu.system.domain.model; package com.muyu.system.domain.model;
import com.muyu.common.core.web.model.QueryModel; import com.muyu.common.core.web.model.QueryModel;
import com.muyu.system.domain.rep.SysConfigListReq;
import com.muyu.system.domain.rep.SysDeptListReq; import com.muyu.system.domain.rep.SysDeptListReq;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
@ -9,8 +8,6 @@ import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder; import lombok.experimental.SuperBuilder;
import java.util.Date;
/** /**
* *
*/ */
@ -21,6 +18,11 @@ import java.util.Date;
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class SysDeptPageQueryModel extends QueryModel<SysDeptPageQueryModel> { public class SysDeptPageQueryModel extends QueryModel<SysDeptPageQueryModel> {
/**
* ID
*/
private Long deptId;
/** /**
* *
*/ */
@ -32,12 +34,26 @@ public class SysDeptPageQueryModel extends QueryModel<SysDeptPageQueryModel> {
private String status; private String status;
/**
*
* @param sysDeptListReq
* @return
*/
public static SysDeptPageQueryModel reqBuild(SysDeptListReq sysDeptListReq) { public static SysDeptPageQueryModel reqBuild(SysDeptListReq sysDeptListReq) {
SysDeptPageQueryModel sysDeptPageQueryModel = SysDeptPageQueryModel.builder() return SysDeptPageQueryModel.builder()
.deptName(sysDeptListReq.getDeptName()) .deptName(sysDeptListReq.getDeptName())
.status(sysDeptListReq.getStatus()) .status(sysDeptListReq.getStatus())
.build(); .build();
sysDeptPageQueryModel.domainBuild(sysDeptListReq); }
return sysDeptPageQueryModel;
/**
* ID
* @param deptId ID
* @return
*/
public static SysDeptPageQueryModel ofToDeptId(Long deptId) {
return SysDeptPageQueryModel.builder()
.deptId(deptId)
.build();
} }
} }

View File

@ -1,10 +1,7 @@
package com.muyu.system.service; package com.muyu.system.service;
import com.baomidou.mybatisplus.extension.service.IService; 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.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.model.SysDeptPageQueryModel;
import com.muyu.system.domain.vo.TreeSelect; import com.muyu.system.domain.vo.TreeSelect;
@ -19,20 +16,18 @@ public interface SysDeptService extends IService<SysDept> {
/** /**
* *
* *
* @param dept * @param deptPageQueryModel
* *
* @return * @return
*/ */
public List<SysDept> selectDeptList (SysDept dept); public List<SysDept> selectDeptList (SysDeptPageQueryModel deptPageQueryModel);
/** /**
* *
* *
* @param dept
*
* @return * @return
*/ */
public List<TreeSelect> selectDeptTreeList (SysDept dept); public List<TreeSelect> selectDeptTreeList ();
/** /**
* *
@ -140,5 +135,10 @@ public interface SysDeptService extends IService<SysDept> {
*/ */
public int deleteDeptById (Long deptId); public int deleteDeptById (Long deptId);
PageQueryModel<SysDept> pageQuery(SysDeptPageQueryModel sysDeptPageQueryModel); /**
*
* @param sysDeptPageQueryModel
* @return
*/
List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel);
} }

View File

@ -1,20 +1,17 @@
package com.muyu.system.service.impl; package com.muyu.system.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.muyu.common.core.constant.UserConstants; import com.muyu.common.core.constant.UserConstants;
import com.muyu.common.core.exception.ServiceException; import com.muyu.common.core.exception.ServiceException;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.SpringUtils; import com.muyu.common.core.utils.SpringUtils;
import com.muyu.common.core.utils.StringUtils; 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.datascope.annotation.DataScope;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.SysDept; import com.muyu.common.system.domain.SysDept;
import com.muyu.common.system.domain.SysRole; import com.muyu.common.system.domain.SysRole;
import com.muyu.common.system.domain.SysUser; 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.model.SysDeptPageQueryModel;
import com.muyu.system.domain.vo.TreeSelect; import com.muyu.system.domain.vo.TreeSelect;
import com.muyu.system.mapper.SysDeptMapper; import com.muyu.system.mapper.SysDeptMapper;
@ -24,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -45,39 +41,45 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
@Override @Override
public PageQueryModel<SysDept> pageQuery(SysDeptPageQueryModel sysDeptPageQueryModel) { public List<SysDept> queryList(SysDeptPageQueryModel sysDeptPageQueryModel) {
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName()); queryWrapper.like(StringUtils.isNotEmpty(sysDeptPageQueryModel.getDeptName()),SysDept::getDeptName, sysDeptPageQueryModel.getDeptName());
queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus()); queryWrapper.eq(StringUtils.isNotEmpty(sysDeptPageQueryModel.getStatus()),SysDept::getStatus,sysDeptPageQueryModel.getStatus());
Page<SysDept> page = this.page(sysDeptPageQueryModel.buildPage(), queryWrapper); return this.list(queryWrapper);
return PageQueryModel.of(page);
} }
/** /**
* *
* *
* @param dept * @param sysDeptPageQueryModel
* *
* @return * @return
*/ */
@Override @Override
@DataScope(deptAlias = "d") @DataScope(deptAlias = "d")
public List<SysDept> selectDeptList (SysDept dept) { public List<SysDept> selectDeptList (SysDeptPageQueryModel sysDeptPageQueryModel) {
return deptMapper.selectDeptList(dept); LambdaQueryWrapper<SysDept> 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 * @return
*/ */
@Override @Override
public List<TreeSelect> selectDeptTreeList (SysDept dept) { public List<TreeSelect> selectDeptTreeList () {
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); return buildDeptTreeSelect(
return buildDeptTreeSelect(depts); SpringUtils.getAopProxy(this).selectDeptList(
SysDeptPageQueryModel.ofNull()
)
);
} }
/** /**
@ -89,8 +91,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
*/ */
@Override @Override
public List<SysDept> buildDeptTree (List<SysDept> depts) { public List<SysDept> buildDeptTree (List<SysDept> depts) {
List<SysDept> returnList = new ArrayList<SysDept>(); List<SysDept> returnList = new ArrayList<>();
List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); List<Long> tempList = depts.stream().map(SysDept::getDeptId).toList();
for (SysDept dept : depts) { for (SysDept dept : depts) {
// 如果是顶级节点, 遍历该父节点的所有子节点 // 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId())) { if (!tempList.contains(dept.getParentId())) {
@ -205,9 +207,8 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
@Override @Override
public void checkDeptDataScope (Long deptId) { public void checkDeptDataScope (Long deptId) {
if (!SysUser.isAdmin(SecurityUtils.getUserId())) { if (!SysUser.isAdmin(SecurityUtils.getUserId())) {
SysDept dept = new SysDept(); List<SysDept> depts = SpringUtils.getAopProxy(this)
dept.setDeptId(deptId); .selectDeptList(SysDeptPageQueryModel.ofToDeptId(deptId));
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
if (StringUtils.isEmpty(depts)) { if (StringUtils.isEmpty(depts)) {
throw new ServiceException("没有权限访问部门数据!"); throw new ServiceException("没有权限访问部门数据!");
} }
@ -281,7 +282,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
for (SysDept child : children) { for (SysDept child : children) {
child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors)); child.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
} }
if (children.size() > 0) { if (!children.isEmpty()) {
deptMapper.updateDeptChildren(children); deptMapper.updateDeptChildren(children);
} }
} }
@ -319,9 +320,7 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
*/ */
private List<SysDept> getChildList (List<SysDept> list, SysDept t) { private List<SysDept> getChildList (List<SysDept> list, SysDept t) {
List<SysDept> tlist = new ArrayList<SysDept>(); List<SysDept> tlist = new ArrayList<SysDept>();
Iterator<SysDept> it = list.iterator(); for (SysDept n : list) {
while (it.hasNext()) {
SysDept n = (SysDept) it.next();
if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) {
tlist.add(n); tlist.add(n);
} }
@ -333,6 +332,6 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
* *
*/ */
private boolean hasChild (List<SysDept> list, SysDept t) { private boolean hasChild (List<SysDept> list, SysDept t) {
return getChildList(list, t).size() > 0 ? true : false; return !getChildList(list, t).isEmpty();
} }
} }