From ba927530a36fd746eb9b723aff9bb0fa459429a9 Mon Sep 17 00:00:00 2001 From: smallchill Date: Thu, 26 Dec 2019 15:27:06 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=A0=91=E6=94=B9=E4=B8=BA=E6=87=92=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/springblade/system/vo/DeptLazyVO.java | 38 +++++++++++ .../system/controller/DeptController.java | 33 ++++++++- .../springblade/system/mapper/DeptMapper.java | 21 ++++-- .../springblade/system/mapper/DeptMapper.xml | 67 ++++++++++++++++++- .../system/service/IDeptService.java | 21 ++++-- .../system/service/impl/DeptServiceImpl.java | 24 ++++++- .../system/wrapper/DeptWrapper.java | 9 +++ 7 files changed, 195 insertions(+), 18 deletions(-) create mode 100644 blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptLazyVO.java diff --git a/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptLazyVO.java b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptLazyVO.java new file mode 100644 index 00000000..3863409e --- /dev/null +++ b/blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptLazyVO.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * Neither the name of the dreamlu.net developer nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * Author: Chill 庄骞 (smallchill@163.com) + */ +package org.springblade.system.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 视图实体类 + * + * @author Chill + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ApiModel(value = "DeptLazyVO对象", description = "DeptLazyVO对象") +public class DeptLazyVO extends DeptVO { + private static final long serialVersionUID = 1L; + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Boolean hasChildren; + +} diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java index 5bd02cba..f0ce8384 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java @@ -31,6 +31,7 @@ import org.springblade.core.tool.node.INode; import org.springblade.core.tool.utils.Func; import org.springblade.system.entity.Dept; import org.springblade.system.service.IDeptService; +import org.springblade.system.vo.DeptLazyVO; import org.springblade.system.vo.DeptVO; import org.springblade.system.wrapper.DeptWrapper; import org.springframework.cache.annotation.CacheEvict; @@ -84,24 +85,50 @@ public class DeptController extends BladeController { return R.data(DeptWrapper.build().listNodeVO(list)); } + /** + * 懒加载列表 + */ + @GetMapping("/lazy-list") + @ApiImplicitParams({ + @ApiImplicitParam(name = "deptName", value = "部门名称", paramType = "query", dataType = "string"), + @ApiImplicitParam(name = "fullName", value = "部门全称", paramType = "query", dataType = "string") + }) + @ApiOperationSupport(order = 3) + @ApiOperation(value = "懒加载列表", notes = "传入dept") + public R> lazyList(@ApiIgnore @RequestParam Map dept, @RequestParam(required = false, defaultValue = "0") Long parentId, BladeUser bladeUser) { + List list = deptService.lazyList(bladeUser.getTenantId(), parentId, dept); + return R.data(DeptWrapper.build().listNodeLazyVO(list)); + } + /** * 获取部门树形结构 * * @return */ @GetMapping("/tree") - @ApiOperationSupport(order = 3) + @ApiOperationSupport(order = 4) @ApiOperation(value = "树形结构", notes = "树形结构") public R> tree(String tenantId, BladeUser bladeUser) { List tree = deptService.tree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId())); return R.data(tree); } + /** + * 懒加载获取部门树形结构 + */ + @GetMapping("/lazy-tree") + @ApiOperationSupport(order = 5) + @ApiOperation(value = "懒加载树形结构", notes = "树形结构") + public R> lazyTree(String tenantId, @RequestParam(required = false, defaultValue = "0") Long parentId, BladeUser bladeUser) { + List tree = deptService.lazyTree(Func.toStrWithEmpty(tenantId, bladeUser.getTenantId()), parentId); + return R.data(tree); + } + /** * 新增或修改 */ @PostMapping("/submit") - @ApiOperationSupport(order = 4) + @ApiOperationSupport(order = 6) @ApiOperation(value = "新增或修改", notes = "传入dept") @CacheEvict(cacheNames = {SYS_CACHE}, allEntries = true) public R submit(@Valid @RequestBody Dept dept) { @@ -112,7 +139,7 @@ public class DeptController extends BladeController { * 删除 */ @PostMapping("/remove") - @ApiOperationSupport(order = 5) + @ApiOperationSupport(order = 7) @ApiOperation(value = "删除", notes = "传入ids") @CacheEvict(cacheNames = {SYS_CACHE}, allEntries = true) public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java index 1b3905d8..db89eb9f 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java @@ -17,11 +17,12 @@ package org.springblade.system.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.baomidou.mybatisplus.core.metadata.IPage; import org.springblade.system.entity.Dept; +import org.springblade.system.vo.DeptLazyVO; import org.springblade.system.vo.DeptVO; import java.util.List; +import java.util.Map; /** * Mapper 接口 @@ -31,13 +32,14 @@ import java.util.List; public interface DeptMapper extends BaseMapper { /** - * 自定义分页 + * 懒加载部门列表 * - * @param page - * @param dept + * @param tenantId + * @param parentId + * @param param * @return */ - List selectDeptPage(IPage page, DeptVO dept); + List lazyList(String tenantId, Long parentId, Map param); /** * 获取树形节点 @@ -47,6 +49,15 @@ public interface DeptMapper extends BaseMapper { */ List tree(String tenantId); + /** + * 懒加载获取树形节点 + * + * @param tenantId + * @param parentId + * @return + */ + List lazyTree(String tenantId, Long parentId); + /** * 获取部门名 * diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml index e85ff7ba..ab9f9a85 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml +++ b/blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml @@ -15,12 +15,26 @@ + + + + + + + + + + + + + + @@ -29,8 +43,33 @@ id, parent_id, dept_name, full_name, sort, remark, is_deleted - + SELECT + dept.* , + ( + SELECT + CASE WHEN count(1) > 0 THEN 1 ELSE 0 END + FROM + blade_dept + WHERE + parent_id = dept.id + ) AS "has_children" + FROM + blade_dept dept + + + and tenant_id = #{param1} + + + and parent_id = #{param2} + + + and dept.dept_name like concat('%', #{param.deptName},'%') + + + and dept.full_name like concat('%', #{param.fullName},'%') + + + +