Browse Source

修改根据部门id查询子部门列表接口,增加分页

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
7e99b21fc2
6 changed files with 62 additions and 18 deletions
  1. +5
    -4
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/DeptController.java
  2. +1
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/dept/DeptChildListCodeEnum.java
  3. +27
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/dept/QueryDeptChildPageListRequest.java
  4. +3
    -2
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/DeptServiceImpl.java
  5. +2
    -1
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/IDeptService.java
  6. +24
    -10
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/query/QueryChildListService.java

+ 5
- 4
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/controller/DeptController.java View File

@@ -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);
}

/**

+ 1
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/enums/dept/DeptChildListCodeEnum.java View File

@@ -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, "子部门列表为空");

+ 27
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/request/dept/QueryDeptChildPageListRequest.java View File

@@ -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;

}

+ 3
- 2
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/DeptServiceImpl.java View File

@@ -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);
}
/**

+ 2
- 1
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/IDeptService.java View File

@@ -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);
/**

+ 24
- 10
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/dept/query/QueryChildListService.java View File

@@ -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();
}

}
}

Loading…
Cancel
Save