From 5067a85bba03e5320c728b0c0ca713242beb8779 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期六, 22 二月 2025 17:06:19 +0800
Subject: [PATCH] 首页统计数量、金额问题、待办展示剩余时间的bug
---
system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java | 120 +++++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 94 insertions(+), 26 deletions(-)
diff --git a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
index f356ada..358a7eb 100644
--- a/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
+++ b/system/src/main/java/com/ycl/system/service/impl/SysDeptServiceImpl.java
@@ -1,12 +1,12 @@
package com.ycl.system.service.impl;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
import com.ycl.common.base.Result;
+import com.ycl.common.core.domain.StringTreeSelect;
import com.ycl.system.domain.base.BaseSelect;
+import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ycl.common.annotation.DataScope;
@@ -30,13 +30,12 @@
* @author ycl
*/
@Service
+@RequiredArgsConstructor
public class SysDeptServiceImpl implements ISysDeptService
{
- @Autowired
- private SysDeptMapper deptMapper;
- @Autowired
- private SysRoleMapper roleMapper;
+ private final SysDeptMapper deptMapper;
+ private final SysRoleMapper roleMapper;
/**
* 鏌ヨ閮ㄩ棬绠$悊鏁版嵁
@@ -62,6 +61,48 @@
{
List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
return buildDeptTreeSelect(depts);
+ }
+
+ @Override
+ public List<TreeSelect> deptTreeNoDataAuth(SysDept dept) {
+ List<SysDept> depts = deptMapper.selectDeptList(dept);;
+ return buildDeptTreeSelect(depts);
+ }
+
+ @Override
+ public List<StringTreeSelect> flowDeptTree(SysDept dept) {
+ List<SysDept> depts = deptMapper.selectDeptList(dept);
+ List<StringTreeSelect> list = depts.stream().map(item -> {
+ StringTreeSelect d = new StringTreeSelect();
+ d.setId("dept:" + item.getDeptId());
+ d.setLabel(item.getDeptName());
+ d.setParentId("dept:" + item.getParentId());
+ return d;
+ }).collect(Collectors.toList());
+
+
+ Map<String, StringTreeSelect> nodeMap = new HashMap<>();
+ // 灏嗘墍鏈夎妭鐐规斁鍏ap涓紝鏂逛究鍚庣画鏌ユ壘
+ for (StringTreeSelect node : list) {
+ nodeMap.put(node.getId(), node);
+ }
+ List<StringTreeSelect> treeList = new ArrayList<>();
+ // 鏋勫缓鏍戠粨鏋�
+ for (StringTreeSelect node : list) {
+ StringTreeSelect root = null;
+ if ("dept:0".equals(node.getParentId()) || node.getParentId().isEmpty()) {
+ // 鏍硅妭鐐�
+ root = node;
+ treeList.add(root);
+ } else {
+ // 鎵惧埌鐖惰妭鐐癸紝骞跺皢褰撳墠鑺傜偣娣诲姞鍒扮埗鑺傜偣鐨刢hildren鍒楄〃涓�
+ StringTreeSelect parentNode = nodeMap.get(node.getParentId());
+ if (parentNode != null) {
+ parentNode.getChildren().add(node);
+ }
+ }
+ }
+ return treeList;
}
/**
@@ -90,6 +131,8 @@
}
return returnList;
}
+
+
/**
* 鏋勫缓鍓嶇鎵�闇�瑕佷笅鎷夋爲缁撴瀯
@@ -127,6 +170,11 @@
public SysDept selectDeptById(Long deptId)
{
return deptMapper.selectDeptById(deptId);
+ }
+
+ @Override
+ public List<SysDept> selectDeptByIds(List<Long> deptIds) {
+ return deptMapper.selectDeptByIds(deptIds);
}
/**
@@ -214,13 +262,18 @@
@Override
public int insertDept(SysDept dept)
{
- SysDept info = deptMapper.selectDeptById(dept.getParentId());
- // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
- if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
- {
- throw new ServiceException("閮ㄩ棬鍋滅敤锛屼笉鍏佽鏂板");
+ if (Objects.nonNull(dept.getParentId())) {
+ SysDept info = deptMapper.selectDeptById(dept.getParentId());
+ // 濡傛灉鐖惰妭鐐逛笉涓烘甯哥姸鎬�,鍒欎笉鍏佽鏂板瀛愯妭鐐�
+ if (!UserConstants.DEPT_NORMAL.equals(info.getStatus()))
+ {
+ throw new ServiceException("涓婄骇閮ㄩ棬宸插仠鐢紝涓嶅厑璁告柊澧炰笅绾ч儴闂�");
+ }
+ dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
+ } else {
+ dept.setParentId(0L);
+ dept.setAncestors("");
}
- dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
return deptMapper.insertDept(dept);
}
@@ -233,22 +286,23 @@
@Override
public int updateDept(SysDept dept)
{
- SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
SysDept oldDept = deptMapper.selectDeptById(dept.getDeptId());
- if (StringUtils.isNotNull(newParentDept) && StringUtils.isNotNull(oldDept))
- {
- String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
- String oldAncestors = oldDept.getAncestors();
- dept.setAncestors(newAncestors);
- updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+ if (Objects.isNull(oldDept)) {
+ throw new RuntimeException("淇敼閮ㄩ棬琚垹闄ゆ垨涓嶅瓨鍦�");
+ }
+ if (Objects.nonNull(dept.getParentId())) {
+ SysDept newParentDept = deptMapper.selectDeptById(dept.getParentId());
+ if (Objects.nonNull(newParentDept)) {
+ String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
+ String oldAncestors = oldDept.getAncestors();
+ dept.setAncestors(newAncestors);
+ updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
+ }
+ } else {
+ dept.setParentId(0L);
+ dept.setAncestors("");
}
int result = deptMapper.updateDept(dept);
- if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
- && !StringUtils.equals("0", dept.getAncestors()))
- {
- // 濡傛灉璇ラ儴闂ㄦ槸鍚敤鐘舵�侊紝鍒欏惎鐢ㄨ閮ㄩ棬鐨勬墍鏈変笂绾ч儴闂�
- updateParentDeptStatusNormal(dept);
- }
return result;
}
@@ -354,4 +408,18 @@
).collect(Collectors.toList());
return Result.ok().data(vos);
}
+
+
+ @Override
+ public List<StringTreeSelect> flowableAll() {
+ List<StringTreeSelect> list = deptMapper.selectDeptList(new SysDept()).stream().map(sysDept -> {
+ StringTreeSelect stringTreeSelect = new StringTreeSelect();
+ stringTreeSelect.setId("dept:" + sysDept.getDeptId());
+ stringTreeSelect.setLabel(sysDept.getDeptName());
+ return stringTreeSelect;
+ }).collect(Collectors.toList());
+ return list;
+ }
+
+
}
--
Gitblit v1.8.0