@@ -27,7 +27,7 @@ public class DeptController { | |||
private IDeptService deptService; | |||
/** | |||
* 查询部门列表 | |||
* 查询部门树形列表 | |||
*/ | |||
@GetMapping("/list/tree") | |||
public JsonResult getListTree() { | |||
@@ -35,6 +35,15 @@ public class DeptController { | |||
return deptService.getListTree(); | |||
} | |||
/** | |||
* 根据id查询子部门列表 | |||
*/ | |||
@GetMapping("/child/list/{id}") | |||
public JsonResult getChildList(@PathVariable("id") String id) { | |||
log.info("进入获取子部门列表列表接口, id:{}", id); | |||
return deptService.getChildList(id); | |||
} | |||
/** | |||
* 获取部门详细信息 | |||
*/ |
@@ -0,0 +1,50 @@ | |||
package com.tuoheng.admin.enums.dept; | |||
/** | |||
* 获取子部门列表返回码 | |||
* 模块代码:20(部门管理) | |||
* 接口代码:06 (获取子部门列表) | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-11-22 | |||
*/ | |||
public enum DeptChildListCodeEnum { | |||
DEPT_LIST_IS_FAILED(1200600, "子部门列表失败"), | |||
DEPT_ID_IS_NULL(1200601, "部门id为空"), | |||
DEPT_IS_NOT_EXIST(1200602, "部门不存在"), | |||
DEPT_LIST_IS_NULL(1200603, "子部门列表为空"); | |||
/** | |||
* 错误码 | |||
*/ | |||
private int code; | |||
/** | |||
* 错误信息 | |||
*/ | |||
private String msg; | |||
DeptChildListCodeEnum(int code, String msg){ | |||
this.code = code; | |||
this.msg = msg; | |||
} | |||
public int getCode() { | |||
return code; | |||
} | |||
public void setCode(int code) { | |||
this.code = code; | |||
} | |||
public String getMsg() { | |||
return msg; | |||
} | |||
public void setMsg(String msg) { | |||
this.msg = msg; | |||
} | |||
} |
@@ -11,7 +11,7 @@ package com.tuoheng.admin.enums.dept; | |||
*/ | |||
public enum DeptTreeCodeListEnum { | |||
DEPT_LIST_NULL(1200101, "部门列表为空"); | |||
DEPT_LIST_IS_NULL(1200101, "部门列表为空"); | |||
/** | |||
* 错误码 |
@@ -6,6 +6,7 @@ import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.service.dept.add.AddDeptService; | |||
import com.tuoheng.admin.service.dept.delete.DeleteDeptService; | |||
import com.tuoheng.admin.service.dept.query.QueryChildListService; | |||
import com.tuoheng.admin.service.dept.query.QueryDeptInfoService; | |||
import com.tuoheng.admin.service.dept.query.QueryListTreeService; | |||
import com.tuoheng.admin.service.dept.update.UpdateDeptService; | |||
@@ -31,6 +32,9 @@ public class DeptServiceImpl implements IDeptService { | |||
@Autowired | |||
private QueryListTreeService queryListTreeService; | |||
@Autowired | |||
private QueryChildListService queryChildListService; | |||
@Autowired | |||
private QueryDeptInfoService queryDeptInfoService; | |||
@@ -44,7 +48,7 @@ public class DeptServiceImpl implements IDeptService { | |||
private DeleteDeptService deleteDeptService; | |||
/** | |||
* 查询部门列表 | |||
* 查询部门树形列表 | |||
* | |||
* @return 部门 | |||
*/ | |||
@@ -53,6 +57,16 @@ public class DeptServiceImpl implements IDeptService { | |||
return queryListTreeService.getListTree(); | |||
} | |||
/** | |||
* 根据id查询子部门列表 | |||
* | |||
* @return 部门 | |||
*/ | |||
@Override | |||
public JsonResult getChildList(String id) { | |||
return queryChildListService.getChildList(id); | |||
} | |||
/** | |||
* 查询部门 | |||
* |
@@ -25,12 +25,20 @@ public interface IDeptService { | |||
JsonResult getDeptInfo(String id); | |||
/** | |||
* 查询部门列表 | |||
* 查询部门树形列表 | |||
* | |||
* @return 部门集合 | |||
*/ | |||
JsonResult getListTree(); | |||
/** | |||
* 根据id查询子部门列表 | |||
* | |||
* @return 部门集合 | |||
*/ | |||
JsonResult getChildList(String id); | |||
/** | |||
* 新增部门 | |||
* |
@@ -0,0 +1,88 @@ | |||
package com.tuoheng.admin.service.dept.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.tuoheng.admin.conver.DeptConverMapper; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.enums.dept.DeleteDeptCodeEnum; | |||
import com.tuoheng.admin.enums.dept.DeptChildListCodeEnum; | |||
import com.tuoheng.admin.enums.dept.DeptTreeCodeListEnum; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.utils.ShiroUtils; | |||
import com.tuoheng.admin.vo.DeptTreeVo; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import com.tuoheng.common.core.utils.StringUtils; | |||
import lombok.extern.slf4j.Slf4j; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import java.util.ArrayList; | |||
import java.util.HashMap; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 根据id查询子部门列表业务层处理 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-11-22 | |||
*/ | |||
@Slf4j | |||
@Service | |||
public class QueryChildListService { | |||
@Autowired | |||
private DeptMapper deptMapper; | |||
/** | |||
* 获取部门树形列表 | |||
* | |||
* @return | |||
*/ | |||
public JsonResult getChildList(String id) { | |||
log.info("进入查询子部门列表业务"); | |||
String tenantId = ShiroUtils.getTenantId(); | |||
JsonResult result = this.check(tenantId, id); | |||
if (0 != result.getCode()) { | |||
log.info("根据id查询子部门列表业务:校验失败:{}", result.getMsg()); | |||
return result; | |||
} | |||
// 查询所有有效的子部门数据 | |||
List<Dept> deptList = deptMapper.selectList(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getPid, id) | |||
.eq(Dept::getMark, 1)); | |||
if (CollectionUtil.isEmpty(deptList)) { | |||
log.info("获取子部门列表为空"); | |||
return JsonResult.error(DeptChildListCodeEnum.DEPT_LIST_IS_NULL.getCode(), DeptChildListCodeEnum.DEPT_LIST_IS_NULL.getMsg()); | |||
} | |||
return JsonResult.success(deptList); | |||
} | |||
/** | |||
* 检查参数 | |||
* @param tenantId | |||
* @param id | |||
* @return | |||
*/ | |||
private JsonResult check(String tenantId, String id) { | |||
// 判断id是否为空 | |||
if (StringUtils.isEmpty(id)) { | |||
return JsonResult.error(DeptChildListCodeEnum.DEPT_ID_IS_NULL.getCode(), DeptChildListCodeEnum.DEPT_ID_IS_NULL.getMsg()); | |||
} | |||
// 判断部门是否存在 | |||
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, tenantId) | |||
.eq(Dept::getId, id) | |||
.eq(Dept::getMark, 1)); | |||
if (null == dept) { | |||
return JsonResult.error(DeptChildListCodeEnum.DEPT_IS_NOT_EXIST.getCode(), DeptChildListCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} |
@@ -45,7 +45,7 @@ public class QueryListTreeService { | |||
if (CollectionUtil.isEmpty(deptList)) { | |||
log.info("获取部门列表为空"); | |||
return JsonResult.error(DeptTreeCodeListEnum.DEPT_LIST_NULL.getCode(), DeptTreeCodeListEnum.DEPT_LIST_NULL.getMsg()); | |||
return JsonResult.error(DeptTreeCodeListEnum.DEPT_LIST_IS_NULL.getCode(), DeptTreeCodeListEnum.DEPT_LIST_IS_NULL.getMsg()); | |||
} | |||
List<DeptTreeVo> deptTreeVoListTmp = DeptConverMapper.INSTANCE.deptListToDeptVoList(deptList); |