From 4be2f81508b2e9dfb858ba082a4e1ae6e2a872a2 Mon Sep 17 00:00:00 2001
From: Administrator <admin>
Date: Fri, 20 Aug 2021 17:08:07 +0800
Subject: [PATCH] 派遣单位新增字段,工作汇报接收人接口修改

---
 src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java |   60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java b/src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java
index adf630d..4f1cad3 100644
--- a/src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java
+++ b/src/main/java/org/springblade/modules/system/service/impl/DeptServiceImpl.java
@@ -19,20 +19,29 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.AllArgsConstructor;
 import org.springblade.common.cache.SysCache;
 import org.springblade.core.log.exception.ServiceException;
+import org.springblade.core.mp.support.Condition;
 import org.springblade.core.secure.utils.AuthUtil;
 import org.springblade.core.tool.constant.BladeConstant;
 import org.springblade.core.tool.node.ForestNodeMerger;
 import org.springblade.core.tool.utils.Func;
 import org.springblade.core.tool.utils.StringPool;
+import org.springblade.modules.information.entity.Information;
+import org.springblade.modules.information.service.IInformationService;
+import org.springblade.modules.jurisdiction.entity.Jurisdiction;
+import org.springblade.modules.jurisdiction.service.JurisdictionService;
 import org.springblade.modules.system.entity.Dept;
 import org.springblade.modules.system.mapper.DeptMapper;
+import org.springblade.modules.system.node.TreeNodes;
 import org.springblade.modules.system.service.IDeptService;
 import org.springblade.modules.system.vo.DeptVO;
 import org.springblade.modules.system.wrapper.DeptWrapper;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -43,9 +52,14 @@
  * @author Chill
  */
 @Service
+@AllArgsConstructor
 public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {
 	private static final String TENANT_ID = "tenantId";
 	private static final String PARENT_ID = "parentId";
+
+	private final IInformationService iInformationService;
+
+	private final JurisdictionService jurisdictionService;
 
 	@Override
 	public List<DeptVO> lazyList(String tenantId, Long parentId, Map<String, Object> param) {
@@ -211,4 +225,50 @@
 		return ForestNodeMerger.merge(baseMapper.lazyTreeUser(tenantId, parentId));
 	}
 
+	/**
+	 * 懒加载获取部门树形结构(包含用户数据),只查下一级的数据
+	 * @return
+	 */
+	@Override
+	public List<TreeNodes> lazyTreeUsers(Integer type, Long deptId) {
+		Map<Long,TreeNodes> map = new HashMap<>();
+		//保安向保安汇报
+		if(type==1){
+			map = baseMapper.lazyTreeUsers(type,deptId,null);
+		}
+		//保安向民警汇报
+		if(type==2){
+			//查询当前保安所在的辖区
+			Information information = new Information();
+			information.setDepartmentid(deptId.toString());
+
+			Information one = iInformationService.getOne(Condition.getQueryWrapper(information));
+			if (null!=one) {
+				//找辖区对应的组织机构id
+				Jurisdiction jurisdiction = jurisdictionService.getById(one.getJurisdiction());
+				if (null != jurisdiction) {
+					Dept dept = new Dept();
+					dept.setDeptName(jurisdiction.getDeptName());
+					Dept dept1 = this.getOne(Condition.getQueryWrapper(dept));
+					map = baseMapper.lazyTreeUsersPublicSecurity(type, dept1.getId(), one.getJurisdiction());
+				}
+			}
+		}
+		//民警向民警汇报,需要南昌市及当前民警所在辖区的部门数据
+		if(type==3){
+			//当前取所有的民警数据
+			map = baseMapper.lazyTreeUsersPublicSecuritys(type,null,null);
+		}
+		List<TreeNodes> tree = new ArrayList<>();
+		Map<Long, TreeNodes> finalMap = map;
+		map.forEach((id, treeNodes) ->{
+			if (finalMap.containsKey(treeNodes.getParentId())){
+				finalMap.get(treeNodes.getParentId()).getChildren().add(treeNodes);
+			}else {
+				tree.add(treeNodes);
+			}
+		});
+		return tree;
+	}
+
 }

--
Gitblit v1.9.3