@@ -3,6 +3,7 @@ package com.tuoheng.admin.controller; | |||
import com.alibaba.fastjson.JSON; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.request.dept.QueryDeptChildPageListRequest; | |||
import com.tuoheng.admin.service.dept.IDeptService; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import lombok.extern.slf4j.Slf4j; | |||
@@ -38,10 +39,10 @@ public class DeptController { | |||
/** | |||
* 根据id查询子部门列表 | |||
*/ | |||
@GetMapping("/child/list/{id}") | |||
public JsonResult getChildList(@PathVariable("id") String id) { | |||
log.info("进入获取子部门列表列表接口, id:{}", id); | |||
return deptService.getChildList(id); | |||
@GetMapping("/child/page/list/{id}") | |||
public JsonResult getChildList(@RequestBody QueryDeptChildPageListRequest queryDeptChildPageListRequest) { | |||
log.info("进入获取子部门分页列表列表接口, id:{}", queryDeptChildPageListRequest.getId()); | |||
return deptService.getChildPageList(queryDeptChildPageListRequest); | |||
} | |||
/** |
@@ -11,7 +11,7 @@ package com.tuoheng.admin.enums.dept; | |||
*/ | |||
public enum DeptChildListCodeEnum { | |||
DEPT_LIST_IS_FAILED(1200600, "子部门列表失败"), | |||
DEPT_LIST_IS_FAILED(1200600, "获取子部门列表失败"), | |||
DEPT_ID_IS_NULL(1200601, "部门id为空"), | |||
DEPT_IS_NOT_EXIST(1200602, "部门不存在"), | |||
DEPT_LIST_IS_NULL(1200603, "子部门列表为空"); |
@@ -0,0 +1,27 @@ | |||
package com.tuoheng.admin.request.dept; | |||
import com.tuoheng.admin.dto.RoadSectionDto; | |||
import com.tuoheng.common.core.common.BaseQuery; | |||
import lombok.Data; | |||
import javax.validation.constraints.NotBlank; | |||
import java.util.List; | |||
/** | |||
* 根据部门id查询子部门列表请求参数 | |||
* | |||
* @author wanjing | |||
* @team tuoheng | |||
* @date 2022-11-22 | |||
*/ | |||
@Data | |||
public class QueryDeptChildPageListRequest extends BaseQuery { | |||
private static final long serialVersionUID = 1L; | |||
/** | |||
* 部门id | |||
*/ | |||
private String id; | |||
} |
@@ -4,6 +4,7 @@ import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.mapper.DeptMapper; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.request.dept.QueryDeptChildPageListRequest; | |||
import com.tuoheng.admin.service.dept.add.AddDeptService; | |||
import com.tuoheng.admin.service.dept.delete.DeleteDeptService; | |||
import com.tuoheng.admin.service.dept.query.QueryChildListService; | |||
@@ -63,8 +64,8 @@ public class DeptServiceImpl implements IDeptService { | |||
* @return 部门 | |||
*/ | |||
@Override | |||
public JsonResult getChildList(String id) { | |||
return queryChildListService.getChildList(id); | |||
public JsonResult getChildPageList(QueryDeptChildPageListRequest queryDeptChildPageListRequest) { | |||
return queryChildListService.getChildPageList(queryDeptChildPageListRequest); | |||
} | |||
/** |
@@ -3,6 +3,7 @@ package com.tuoheng.admin.service.dept; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.request.dept.AddDeptRequest; | |||
import com.tuoheng.admin.request.dept.EditDeptRequest; | |||
import com.tuoheng.admin.request.dept.QueryDeptChildPageListRequest; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
import java.util.List; | |||
@@ -36,7 +37,7 @@ public interface IDeptService { | |||
* | |||
* @return 部门集合 | |||
*/ | |||
JsonResult getChildList(String id); | |||
JsonResult getChildPageList(QueryDeptChildPageListRequest queryDeptChildPageListRequest); | |||
/** |
@@ -2,12 +2,17 @@ package com.tuoheng.admin.service.dept.query; | |||
import cn.hutool.core.collection.CollectionUtil; | |||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | |||
import com.baomidou.mybatisplus.core.metadata.IPage; | |||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | |||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | |||
import com.tuoheng.admin.conver.DeptConverMapper; | |||
import com.tuoheng.admin.entity.Dept; | |||
import com.tuoheng.admin.entity.RoadInformation; | |||
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.request.dept.QueryDeptChildPageListRequest; | |||
import com.tuoheng.admin.utils.ShiroUtils; | |||
import com.tuoheng.admin.vo.DeptTreeVo; | |||
import com.tuoheng.common.core.utils.JsonResult; | |||
@@ -40,26 +45,36 @@ public class QueryChildListService { | |||
* | |||
* @return | |||
*/ | |||
public JsonResult getChildList(String id) { | |||
public JsonResult getChildPageList(QueryDeptChildPageListRequest queryDeptChildPageListRequest) { | |||
log.info("进入查询子部门列表业务"); | |||
String tenantId = ShiroUtils.getTenantId(); | |||
JsonResult result = this.check(tenantId, id); | |||
String deptId = queryDeptChildPageListRequest.getId(); | |||
JsonResult result = this.check(tenantId, deptId); | |||
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)); | |||
IPage<Dept> page = new Page<>(queryDeptChildPageListRequest.getPage(), queryDeptChildPageListRequest.getLimit()); | |||
IPage<Dept> pageData = deptMapper.selectPage(page, Wrappers.<Dept>lambdaQuery() | |||
.eq(Dept::getMark, 1) | |||
.eq(Dept::getTenantId, tenantId) | |||
.orderByDesc(Dept::getCreateTime)); | |||
List<Dept> deptList = pageData.getRecords(); | |||
List<Dept> list = new ArrayList<>(); | |||
for (Dept record : deptList) { | |||
list.add(record); | |||
} | |||
pageData.setRecords(list); | |||
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); | |||
return JsonResult.success(pageData); | |||
} | |||
/** | |||
@@ -75,14 +90,13 @@ public class QueryChildListService { | |||
} | |||
// 判断部门是否存在 | |||
Dept dept = deptMapper.selectOne(new LambdaQueryWrapper<Dept>() | |||
Integer count = deptMapper.selectCount(new LambdaQueryWrapper<Dept>() | |||
.eq(Dept::getTenantId, tenantId) | |||
.eq(Dept::getId, id) | |||
.eq(Dept::getMark, 1)); | |||
if (null == dept) { | |||
if (count <= 0) { | |||
return JsonResult.error(DeptChildListCodeEnum.DEPT_IS_NOT_EXIST.getCode(), DeptChildListCodeEnum.DEPT_IS_NOT_EXIST.getMsg()); | |||
} | |||
return JsonResult.success(); | |||
} | |||
} | |||
} |