diff --git a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java index acbf715b..1124861c 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/controller/SysDeptController.java @@ -28,7 +28,6 @@ import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; import java.util.*; -import java.util.stream.Collectors; /** * 部门管理 @@ -58,20 +57,11 @@ public class SysDeptController { @ApiOperation("分页") @ApiImplicitParams({ @ApiImplicitParam(name = Constant.PAGE, value = "当前页码,从1开始", paramType = "query", required = true, dataType = "int"), - @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int") + @ApiImplicitParam(name = Constant.LIMIT, value = "每页显示记录数", paramType = "query", required = true, dataType = "int"), + @ApiImplicitParam(name = "deptName", value = "部门名称", paramType = "query", dataType = "String") }) public Result> page(@ApiIgnore @RequestParam Map params) { - long curPage = 1; - long limit = 10; - if (params.get(Constant.PAGE) != null) { - curPage = Long.parseLong((String) params.get(Constant.PAGE)); - } - if (params.get(Constant.LIMIT) != null) { - limit = Long.parseLong((String) params.get(Constant.LIMIT)); - } - List dtoList = sysDeptService.list(new HashMap<>(1)); - List result = dtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList()); - return new Result>().ok(new PageData(result, dtoList.size())); + return new Result>().ok(sysDeptService.page(params)); } @GetMapping("listForRegion") diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java index b2337d7c..3646cd25 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/SysDeptService.java @@ -1,5 +1,6 @@ package io.renren.modules.sys.service; +import io.renren.common.page.PageData; import io.renren.common.service.BaseService; import io.renren.modules.sys.dto.SysDeptDTO; import io.renren.modules.sys.entity.SysDeptEntity; @@ -12,6 +13,8 @@ import java.util.Map; */ public interface SysDeptService extends BaseService { + PageData page(Map params); + List list(Map params); SysDeptDTO get(Long id); diff --git a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java index 7000bf06..2d098c84 100644 --- a/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java +++ b/renren-admin/src/main/java/io/renren/modules/sys/service/impl/SysDeptServiceImpl.java @@ -3,6 +3,7 @@ package io.renren.modules.sys.service.impl; import io.renren.common.constant.Constant; import io.renren.common.exception.ErrorCode; import io.renren.common.exception.RenException; +import io.renren.common.page.PageData; import io.renren.common.service.impl.BaseServiceImpl; import io.renren.common.utils.ConvertUtils; import io.renren.common.utils.TreeUtils; @@ -23,6 +24,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; @Service @@ -30,6 +32,28 @@ public class SysDeptServiceImpl extends BaseServiceImpl page(Map params) { + long curPage = 1; + long limit = 10; + if (params.get(Constant.PAGE) != null) { + curPage = Long.parseLong((String) params.get(Constant.PAGE)); + } + if (params.get(Constant.LIMIT) != null) { + limit = Long.parseLong((String) params.get(Constant.LIMIT)); + } + //普通管理员,只能查询所属部门及子部门的数据 + UserDetail user = SecurityUser.getUser(); + if (user.getSuperAdmin() == SuperAdminEnum.NO.value()) { + params.put("deptIdList", getSubDeptIdList(user.getDeptId())); + } + //查询部门列表 + List entityList = baseDao.getList(params); + List dtoList = ConvertUtils.sourceToTarget(entityList, SysDeptDTO.class); + List result = dtoList.stream().skip((curPage - 1) * limit).limit(limit).collect(Collectors.toList()); + return new PageData( TreeUtils.build(result), dtoList.size()); + } + @Override public List list(Map params) { //普通管理员,只能查询所属部门及子部门的数据 diff --git a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml index 54e7a2b0..0d4aec95 100644 --- a/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml +++ b/renren-admin/src/main/resources/mapper/sys/SysDeptDao.xml @@ -12,6 +12,9 @@ #{id} + + and t1.name LIKE CONCAT( '%', #{deptName}, '%' ) + order by t1.sort asc