Browse Source

优化懒加载代码

test
smallchill 5 years ago
parent
commit
ac7f7844e2
  1. 38
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptLazyVO.java
  2. 15
      blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptVO.java
  3. 3
      blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java
  4. 4
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java
  5. 4
      blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml
  6. 4
      blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java
  7. 4
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java
  8. 3
      blade-service/blade-system/src/main/java/org/springblade/system/wrapper/DeptWrapper.java

38
blade-service-api/blade-system-api/src/main/java/org/springblade/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.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
blade-service-api/blade-system-api/src/main/java/org/springblade/system/vo/DeptVO.java

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

3
blade-service/blade-system/src/main/java/org/springblade/system/controller/DeptController.java

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

4
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.java

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

4
blade-service/blade-system/src/main/java/org/springblade/system/mapper/DeptMapper.xml

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

4
blade-service/blade-system/src/main/java/org/springblade/system/service/IDeptService.java

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

4
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/DeptServiceImpl.java

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

3
blade-service/blade-system/src/main/java/org/springblade/system/wrapper/DeptWrapper.java

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

Loading…
Cancel
Save