From ceac706e09569d9e39df197b7532a3d754ca7320 Mon Sep 17 00:00:00 2001 From: wanggeng888 <450292408@qq.com> Date: Sun, 23 May 2021 21:11:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E7=BC=93=E5=AD=98=E3=80=81=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=BC=82=E6=AD=A5=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DepartmentResourceController.java | 59 +++++++++++-------- .../impl/DepartmentServiceImpl.java | 11 ++-- .../system/department/department-mapper.xml | 2 +- 3 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/cm/serviceusercenter/controller/resources/system/department/DepartmentResourceController.java b/src/main/java/com/cm/serviceusercenter/controller/resources/system/department/DepartmentResourceController.java index 23ddcf8..8cb7956 100644 --- a/src/main/java/com/cm/serviceusercenter/controller/resources/system/department/DepartmentResourceController.java +++ b/src/main/java/com/cm/serviceusercenter/controller/resources/system/department/DepartmentResourceController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.Callable; /** * When you feel like quitting. Think about why you started @@ -44,10 +45,12 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("listdepartments/{departmentParentId}") - public List listDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { - Map params = new HashMap<>(0); - params.put("departmentParentId", departmentParentId); - return departmentService.listZTreeDepartment(params); + public Callable> listDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { + return () -> { + Map params = new HashMap<>(0); + params.put("departmentParentId", departmentParentId); + return departmentService.listZTreeDepartment(params); + }; } @ApiOperation(value = "组织部门全部列表", notes = "组织部门全部列表接口") @@ -57,10 +60,12 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @PostMapping("listalldepartments/{departmentParentId}") - public List listAllDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { - Map params = new HashMap<>(0); - params.put("departmentParentId", departmentParentId); - return departmentService.listDepartmentsAll(params); + public Callable> listAllDepartments(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { + return () -> { + Map params = new HashMap<>(0); + params.put("departmentParentId", departmentParentId); + return departmentService.listDepartmentsAll(params); + }; } @ApiOperation(value = "zTree列表(包括人员)", notes = "zTree列表(包括人员)接口") @@ -69,12 +74,14 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listztreedepartmentwithuser") - public List listZTreeDepartmentWithUser(@RequestParam(required = false) String id) throws SearchException { - String departmentParentId = "0"; - if (!StringUtils.isBlank(id)) { - departmentParentId = id; - } - return departmentService.listZTreeDepartmentWithUser(departmentParentId); + public Callable> listZTreeDepartmentWithUser(@RequestParam(required = false) String id) throws SearchException { + return () -> { + String departmentParentId = "0"; + if (!StringUtils.isBlank(id)) { + departmentParentId = id; + } + return departmentService.listZTreeDepartmentWithUser(departmentParentId); + }; } @ApiOperation(value = "zTree列表", notes = "zTree列表接口") @@ -101,8 +108,8 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentid/{departmentParentId}") - public List listDepartmentSimpleByParentId(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { - return departmentService.listDepartmentSimpleByParentId(departmentParentId); + public Callable> listDepartmentSimpleByParentId(@PathVariable("departmentParentId") String departmentParentId) throws SearchException { + return () -> departmentService.listDepartmentSimpleByParentId(departmentParentId); } @ApiOperation(value = "通过上级ID和添加获取组织部门全部增量列表(简单格式)", notes = "通过上级ID和添加获取组织部门全部增量列表(简单格式)接口") @@ -113,11 +120,11 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentidandadddate/{departmentParentId}/{addDate}") - public List listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("addDate") String addDate) throws SearchException { + public Callable> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("addDate") String addDate) throws SearchException { if (!RegexUtil.isDate(addDate)) { throw new ParamsException("日期格式错误"); } - return departmentService.listDepartmentSimpleByParentIdAndAddDate(departmentParentId, addDate); + return () -> departmentService.listDepartmentSimpleByParentIdAndAddDate(departmentParentId, addDate); } @ApiOperation(value = "通过上级ID和更新获取组织部门全部新增和修改的列表(简单格式)", notes = "通过上级ID和更新获取组织部门全部新增和修改的列表(简单格式)接口") @@ -128,11 +135,11 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentidandupdatedate/{departmentParentId}/{updateDate}") - public List listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("updateDate") String updateDate) throws SearchException { + public Callable> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentId") String departmentParentId, @PathVariable("updateDate") String updateDate) throws SearchException { if (!RegexUtil.isDate(updateDate)) { throw new ParamsException("日期格式错误"); } - return departmentService.listDepartmentSimpleByParentIdAndUpdateDate(departmentParentId, updateDate); + return () -> departmentService.listDepartmentSimpleByParentIdAndUpdateDate(departmentParentId, updateDate); } @ApiOperation(value = "通过部门ID获取组织部门详情(简单格式)", notes = "通过部门ID获取组织部门详情(简单格式)接口") @@ -153,8 +160,8 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentid/{departmentParentIntId}") - public List listDepartmentSimpleByParentId(@PathVariable("departmentParentIntId") Long departmentParentIntId) throws SearchException { - return departmentService.listDepartmentSimpleByParentIntId(departmentParentIntId); + public Callable> listDepartmentSimpleByParentId(@PathVariable("departmentParentIntId") Long departmentParentIntId) throws SearchException { + return () -> departmentService.listDepartmentSimpleByParentIntId(departmentParentIntId); } @ApiOperation(value = "通过上级ID和添加获取组织部门全部增量列表(简单格式)", notes = "通过上级ID和添加获取组织部门全部增量列表(简单格式)接口") @@ -165,11 +172,11 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentidandadddate/{departmentParentIntId}/{addDate}") - public List listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("addDate") String addDate) throws SearchException { + public Callable> listDepartmentSimpleByParentIdAndAddDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("addDate") String addDate) throws SearchException { if (!RegexUtil.isDate(addDate)) { throw new ParamsException("日期格式错误"); } - return departmentService.listDepartmentSimpleByParentIntIdAndAddDate(departmentParentIntId, addDate); + return () -> departmentService.listDepartmentSimpleByParentIntIdAndAddDate(departmentParentIntId, addDate); } @ApiOperation(value = "通过上级ID和更新获取组织部门全部新增和修改的列表(简单格式)", notes = "通过上级ID和更新获取组织部门全部新增和修改的列表(简单格式)接口") @@ -180,11 +187,11 @@ public class DepartmentResourceController extends BaseController { }) @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)}) @GetMapping("listdepartmentsimplebyparentidandupdatedate/{departmentParentIntId}/{updateDate}") - public List listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("updateDate") String updateDate) throws SearchException { + public Callable> listDepartmentSimpleByParentIdAndUpdateDate(@PathVariable("departmentParentIntId") Long departmentParentIntId, @PathVariable("updateDate") String updateDate) throws SearchException { if (!RegexUtil.isDate(updateDate)) { throw new ParamsException("日期格式错误"); } - return departmentService.listDepartmentSimpleByParentIntIdAndUpdateDate(departmentParentIntId, updateDate); + return () -> departmentService.listDepartmentSimpleByParentIntIdAndUpdateDate(departmentParentIntId, updateDate); } @ApiOperation(value = "通过部门ID获取组织部门详情(简单格式)", notes = "通过部门ID获取组织部门详情(简单格式)接口") diff --git a/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java b/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java index 0aa5a5c..00b3f15 100644 --- a/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java +++ b/src/main/java/com/cm/serviceusercenter/service/system/department/impl/DepartmentServiceImpl.java @@ -228,7 +228,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer @Override public List listDepartmentsAll(Map params) throws SearchException { - List departmentDTOs = departmentDao.listDepartments(params); + List departmentDTOs = listDepartments(params); listSubDepartments(departmentDTOs, params); return departmentDTOs; } @@ -267,7 +267,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer @Override public SuccessResultList> listPageDepartment(ListPage page) throws SearchException { PageHelper.startPage(page.getPage(), page.getRows()); - List departmentDTOs = departmentDao.listDepartments(page.getParams()); + List departmentDTOs = listDepartments(page.getParams()); PageInfo pageInfo = new PageInfo<>(departmentDTOs); return new SuccessResultList<>(departmentDTOs, pageInfo.getPageNum(), pageInfo.getTotal()); } @@ -294,7 +294,8 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer @Override public List listDepartments(Map params) throws SearchException { - return departmentDao.listDepartments(params); + List departmentDTOs = departmentDao.listDepartments(params); + return ArrayListUtil.deepClone(departmentDTOs, DepartmentDTO.class); } @Override @@ -338,7 +339,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer @Override public List listDepartmentId(Map params) throws SearchException { List departmentIds = new ArrayList<>(); - List departmentDTOs = departmentDao.listDepartments(params); + List departmentDTOs = listDepartments(params); for (DepartmentDTO departmentDTO : departmentDTOs) { departmentIds.add(departmentDTO.getDepartmentId()); } @@ -779,7 +780,7 @@ public class DepartmentServiceImpl extends BaseService implements IDepartmentSer private void listSubDepartments(List departmentDTOs, Map params) throws SearchException { for (DepartmentDTO departmentDTO : departmentDTOs) { params.put("departmentParentId", departmentDTO.getDepartmentId()); - List subDepartmentDTOs = departmentDao.listDepartments(params); + List subDepartmentDTOs = listDepartments(params); departmentDTO.setSubDepartments(subDepartmentDTOs); listSubDepartments(subDepartmentDTOs, params); } diff --git a/src/main/resources/mybatis/mapper/system/department/department-mapper.xml b/src/main/resources/mybatis/mapper/system/department/department-mapper.xml index 343777c..9947341 100644 --- a/src/main/resources/mybatis/mapper/system/department/department-mapper.xml +++ b/src/main/resources/mybatis/mapper/system/department/department-mapper.xml @@ -424,7 +424,7 @@ - SELECT department_id, department_parent_id,