Просмотр исходного кода

:ambulance: 优化懒加载代码

smallchill 6 лет назад
Родитель
Сommit
61b6ec84a1

+ 1 - 2
src/main/java/org/springblade/modules/system/controller/DeptController.java

@@ -32,7 +32,6 @@ import org.springblade.core.tool.node.INode;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.system.entity.Dept;
 import org.springblade.modules.system.service.IDeptService;
-import org.springblade.modules.system.vo.DeptLazyVO;
 import org.springblade.modules.system.vo.DeptVO;
 import org.springblade.modules.system.wrapper.DeptWrapper;
 import org.springframework.cache.annotation.CacheEvict;
@@ -97,7 +96,7 @@ public class DeptController extends BladeController {
 	@ApiOperationSupport(order = 3)
 	@ApiOperation(value = "懒加载列表", notes = "传入dept")
 	public R<List<INode>> lazyList(@ApiIgnore @RequestParam Map<String, Object> dept, @RequestParam(required = false, defaultValue = "0") Long parentId, BladeUser bladeUser) {
-		List<DeptLazyVO> list = deptService.lazyList(bladeUser.getTenantId(), parentId, dept);
+		List<DeptVO> list = deptService.lazyList(bladeUser.getTenantId(), parentId, dept);
 		return R.data(DeptWrapper.build().listNodeLazyVO(list));
 	}
 

+ 2 - 2
src/main/java/org/springblade/modules/system/mapper/DeptMapper.java

@@ -18,7 +18,7 @@ package org.springblade.modules.system.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.springblade.modules.system.entity.Dept;
-import org.springblade.modules.system.vo.DeptLazyVO;
+import org.springblade.modules.system.vo.DeptVO;
 import org.springblade.modules.system.vo.DeptVO;
 
 import java.util.List;
@@ -39,7 +39,7 @@ public interface DeptMapper extends BaseMapper<Dept> {
 	 * @param param
 	 * @return
 	 */
-	List<DeptLazyVO> lazyList(String tenantId, Long parentId, Map<String, Object> param);
+	List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param);
 
 	/**
 	 * 获取树形节点

+ 2 - 2
src/main/java/org/springblade/modules/system/mapper/DeptMapper.xml

@@ -15,7 +15,7 @@
         <result column="is_deleted" property="isDeleted"/>
     </resultMap>
 
-    <resultMap id="deptLazyVOResultMap" type="org.springblade.modules.system.vo.DeptLazyVO">
+    <resultMap id="deptLazyVOResultMap" type="org.springblade.modules.system.vo.DeptVO">
         <id column="id" property="id"/>
         <result column="parent_id" property="parentId"/>
         <result column="dept_name" property="deptName"/>
@@ -88,7 +88,7 @@
             dept.id AS "key",
             (
                 SELECT
-                    count( 1 ) > 0
+                    CASE WHEN count(1) > 0 THEN 1 ELSE 0 END
                 FROM
                     blade_dept
                 WHERE

+ 1 - 2
src/main/java/org/springblade/modules/system/service/IDeptService.java

@@ -18,7 +18,6 @@ package org.springblade.modules.system.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import org.springblade.modules.system.entity.Dept;
-import org.springblade.modules.system.vo.DeptLazyVO;
 import org.springblade.modules.system.vo.DeptVO;
 
 import java.util.List;
@@ -39,7 +38,7 @@ public interface IDeptService extends IService<Dept> {
 	 * @param param
 	 * @return
 	 */
-	List<DeptLazyVO> lazyList(String tenantId, Long parentId, Map<String, Object> param);
+	List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param);
 
 	/**
 	 * 树形结构

+ 2 - 2
src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java

@@ -28,7 +28,7 @@ import org.springblade.core.tool.utils.StringPool;
 import org.springblade.modules.system.entity.Dept;
 import org.springblade.modules.system.mapper.DeptMapper;
 import org.springblade.modules.system.service.IDeptService;
-import org.springblade.modules.system.vo.DeptLazyVO;
+import org.springblade.modules.system.vo.DeptVO;
 import org.springblade.modules.system.vo.DeptVO;
 import org.springframework.stereotype.Service;
 
@@ -44,7 +44,7 @@ import java.util.Map;
 public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
 
 	@Override
-	public List<DeptLazyVO> lazyList(String tenantId, Long parentId, Map<String, Object> param) {
+	public List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param) {
 		if (AuthUtil.isAdministrator()) {
 			tenantId = StringPool.EMPTY;
 		}

+ 0 - 38
src/main/java/org/springblade/modules/system/vo/DeptLazyVO.java

@@ -1,38 +0,0 @@
-/*
- *      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.modules.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;
-
-}

+ 15 - 0
src/main/java/org/springblade/modules/system/vo/DeptVO.java

@@ -57,6 +57,12 @@ public class DeptVO extends Dept implements INode {
 	@JsonInclude(JsonInclude.Include.NON_EMPTY)
 	private List<INode> children;
 
+	/**
+	 * 是否有子孙节点
+	 */
+	@JsonInclude(JsonInclude.Include.NON_EMPTY)
+	private Boolean hasChildren;
+
 	@Override
 	public List<INode> getChildren() {
 		if (this.children == null) {
@@ -65,6 +71,15 @@ public class DeptVO extends Dept implements INode {
 		return this.children;
 	}
 
+	@Override
+	public Boolean getHasChildren() {
+		if (children.size() > 0) {
+			return true;
+		} else {
+			return this.hasChildren;
+		}
+	}
+
 	/**
 	 * 上级机构
 	 */

+ 1 - 2
src/main/java/org/springblade/modules/system/wrapper/DeptWrapper.java

@@ -25,7 +25,6 @@ import org.springblade.core.tool.node.INode;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.modules.system.entity.Dept;
-import org.springblade.modules.system.vo.DeptLazyVO;
 import org.springblade.modules.system.vo.DeptVO;
 
 import java.util.List;
@@ -67,7 +66,7 @@ public class DeptWrapper extends BaseEntityWrapper<Dept, DeptVO> {
 		return ForestNodeMerger.merge(collect);
 	}
 
-	public List<INode> listNodeLazyVO(List<DeptLazyVO> list) {
+	public List<INode> listNodeLazyVO(List<DeptVO> list) {
 		List<INode> collect = list.stream().peek(dept -> {
 			String category = DictCache.getValue("org_category", dept.getDeptCategory());
 			Objects.requireNonNull(dept).setDeptCategoryName(category);