EntmicroDepartmentPathService.java
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package cn.com.glsx.entmicro.service;
import cn.com.glsx.entmicro.constants.Constants;
import cn.com.glsx.entmicro.entity.EntmicroDepartmentPath;
import cn.com.glsx.entmicro.mapper.EntmicroDepartmentPathMapper;
import cn.com.glsx.entmicro.model.request.EntmicroDepartmentRequest;
import cn.com.glsx.entmicro.model.response.DepartmentPathResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Lichongyuan
* @Description:
* @date 2021/9/17 15:07
*/
@Service
public class EntmicroDepartmentPathService {
@Resource
private EntmicroDepartmentPathMapper entmicroDepartmentPathMapper;
/**
* 保存闭包树
*
* @param entmicroDepartmentPath
*/
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = RpcServiceException.class)
public Boolean saveEntmicroDepartmentPath(EntmicroDepartmentPath entmicroDepartmentPath) {
return entmicroDepartmentPathMapper.saveEntmicroDepartmentPath(entmicroDepartmentPath);
}
/**
* 查询组织树
*/
public List<DepartmentPathResponse> selectDepartmentTree(EntmicroDepartmentRequest entmicroDepartmentRequest) {
return entmicroDepartmentPathMapper.selectDepartmentTree(entmicroDepartmentRequest);
}
/**
* 删除组织关联(包括本身)
* @param entmicroDepartmentPath
*/
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = RpcServiceException.class)
public void deleteDepartmentPath(EntmicroDepartmentPath entmicroDepartmentPath) {
//删除当前节点到父节点的关联和当前节点下到所有子节点关联(包括本身)
entmicroDepartmentPath.setDelFlag(Constants.DEL_FLAG);
entmicroDepartmentPathMapper.deleteDepartmentPath(entmicroDepartmentPath);
}
/**
* 更新组织关联
*/
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = RpcServiceException.class)
public void updateDepartmentPath(EntmicroDepartmentPath entmicroDepartmentPath) {
//删除当前节点父节点到本身和子节点的所有关联(不包括本身)
entmicroDepartmentPath.setDelFlag(Constants.DEL_FLAG);
entmicroDepartmentPathMapper.updateDepartmentPath(entmicroDepartmentPath);
}
/**
* 插入更新后的组织关联
*/
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = RpcServiceException.class)
public void saveNewDepartmentPath(EntmicroDepartmentPath entmicroDepartmentPath) {
entmicroDepartmentPathMapper.saveNewDepartmentPath(entmicroDepartmentPath);
}
/**
* 构造部门闭包表参数入库
*
* @return
*/
protected EntmicroDepartmentPath buildPath(Integer subId, Integer parentId, Integer createdBy) {
EntmicroDepartmentPath entmicroDepartmentPath = new EntmicroDepartmentPath();
entmicroDepartmentPath.setCreatedTime(new Date());
entmicroDepartmentPath.setDelFlag(Constants.NORMAL_FLAG);
entmicroDepartmentPath.setSubId(subId);
entmicroDepartmentPath.setSuperiorId(parentId);
return entmicroDepartmentPath;
}
public List<Integer> findSubordinateDep(Integer parentId){
List<EntmicroDepartmentPath> subordinateDep = entmicroDepartmentPathMapper.findSubordinateDep(parentId);
return subordinateDep.stream().map(EntmicroDepartmentPath::getSubId).collect(Collectors.toList());
}
}