private IDeptService deptService; | private IDeptService deptService; | ||||
/** | /** | ||||
* 查询部门列表 | |||||
* 查询部门树形列表 | |||||
*/ | */ | ||||
@GetMapping("/list/tree") | @GetMapping("/list/tree") | ||||
public JsonResult getListTree() { | public JsonResult getListTree() { | ||||
return deptService.getListTree(); | return deptService.getListTree(); | ||||
} | } | ||||
/** | |||||
* 根据id查询子部门列表 | |||||
*/ | |||||
@GetMapping("/child/list/{id}") | |||||
public JsonResult getChildList(@PathVariable("id") String id) { | |||||
log.info("进入获取子部门列表列表接口, id:{}", id); | |||||
return deptService.getChildList(id); | |||||
} | |||||
/** | /** | ||||
* 获取部门详细信息 | * 获取部门详细信息 | ||||
*/ | */ |
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; | |||||
} | |||||
} |
*/ | */ | ||||
public enum DeptTreeCodeListEnum { | public enum DeptTreeCodeListEnum { | ||||
DEPT_LIST_NULL(1200101, "部门列表为空"); | |||||
DEPT_LIST_IS_NULL(1200101, "部门列表为空"); | |||||
/** | /** | ||||
* 错误码 | * 错误码 |
import com.tuoheng.admin.request.dept.EditDeptRequest; | import com.tuoheng.admin.request.dept.EditDeptRequest; | ||||
import com.tuoheng.admin.service.dept.add.AddDeptService; | import com.tuoheng.admin.service.dept.add.AddDeptService; | ||||
import com.tuoheng.admin.service.dept.delete.DeleteDeptService; | 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.QueryDeptInfoService; | ||||
import com.tuoheng.admin.service.dept.query.QueryListTreeService; | import com.tuoheng.admin.service.dept.query.QueryListTreeService; | ||||
import com.tuoheng.admin.service.dept.update.UpdateDeptService; | import com.tuoheng.admin.service.dept.update.UpdateDeptService; | ||||
@Autowired | @Autowired | ||||
private QueryListTreeService queryListTreeService; | private QueryListTreeService queryListTreeService; | ||||
@Autowired | |||||
private QueryChildListService queryChildListService; | |||||
@Autowired | @Autowired | ||||
private QueryDeptInfoService queryDeptInfoService; | private QueryDeptInfoService queryDeptInfoService; | ||||
private DeleteDeptService deleteDeptService; | private DeleteDeptService deleteDeptService; | ||||
/** | /** | ||||
* 查询部门列表 | |||||
* 查询部门树形列表 | |||||
* | * | ||||
* @return 部门 | * @return 部门 | ||||
*/ | */ | ||||
return queryListTreeService.getListTree(); | return queryListTreeService.getListTree(); | ||||
} | } | ||||
/** | |||||
* 根据id查询子部门列表 | |||||
* | |||||
* @return 部门 | |||||
*/ | |||||
@Override | |||||
public JsonResult getChildList(String id) { | |||||
return queryChildListService.getChildList(id); | |||||
} | |||||
/** | /** | ||||
* 查询部门 | * 查询部门 | ||||
* | * |
JsonResult getDeptInfo(String id); | JsonResult getDeptInfo(String id); | ||||
/** | /** | ||||
* 查询部门列表 | |||||
* 查询部门树形列表 | |||||
* | * | ||||
* @return 部门集合 | * @return 部门集合 | ||||
*/ | */ | ||||
JsonResult getListTree(); | JsonResult getListTree(); | ||||
/** | |||||
* 根据id查询子部门列表 | |||||
* | |||||
* @return 部门集合 | |||||
*/ | |||||
JsonResult getChildList(String id); | |||||
/** | /** | ||||
* 新增部门 | * 新增部门 | ||||
* | * |
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(); | |||||
} | |||||
} |
if (CollectionUtil.isEmpty(deptList)) { | if (CollectionUtil.isEmpty(deptList)) { | ||||
log.info("获取部门列表为空"); | 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); | List<DeptTreeVo> deptTreeVoListTmp = DeptConverMapper.INSTANCE.deptListToDeptVoList(deptList); |