OrganizationApiService.java
6.56 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package cn.com.glsx.admin.modules.service;
import cn.com.glsx.admin.modules.model.BaseOrgDto;
import cn.com.glsx.admin.modules.model.OrgVehicleTree;
import cn.com.glsx.admin.modules.model.ReportOrgDto;
import cn.com.glsx.admin.modules.model.param.VehicleTreeSearch;
import cn.com.glsx.usercenter.api.dto.request.FindOrgRequest;
import cn.com.glsx.usercenter.api.dto.response.Organization;
import cn.com.glsx.usercenter.api.dto.response.User;
import cn.com.glsx.usercenter.api.dto.tree.OrgTreeModel;
import cn.com.glsx.usercenter.api.feign.OrganizationService;
import cn.hutool.core.collection.CollectionUtil;
import com.glsx.plat.core.web.R;
import com.google.common.collect.Lists;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@Slf4j
@Service
public class OrganizationApiService {
private static final int BATCH_COUNT = 300;
@Autowired
private OrganizationService organizationService;
@Autowired
private UserApiService userApiService;
public void drawOrganization(List<? extends BaseOrgDto> list) {
if (CollectionUtils.isEmpty(list)) {
return;
}
List<Long> userIds = list.stream().map(BaseOrgDto::getCreatedBy).collect(Collectors.toList());
R<List<Organization>> orgsR = organizationService.getTenantPathsByUserIds(userIds);
List<Organization> orgList = orgsR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
if (CollectionUtils.isNotEmpty(orgList)) {
list.forEach(efd -> {
List<Organization> organizations = orgList.stream().filter(index -> index.getUserId().equals(efd.getCreatedBy())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(organizations)) {
int size = organizations.size();
if (size < 2) {
return;
} else {
efd.setArea(organizations.get(1).getOrgName());
if (size > 2) {
efd.setProvince(organizations.get(2).getOrgName());
}
if (size > 3) {
efd.setCity(organizations.get(3).getOrgName());
}
}
}
});
}
}
public List<Organization> getRootOrganizations() {
R<List<Organization>> listR = organizationService.getRootOrganizations();
List<Organization> orgList = listR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
return orgList;
}
public List<Organization> getSubOrganizations(Long orgId) {
R<List<Organization>> listR = organizationService.getSubOrganizations(orgId);
List<Organization> orgList = listR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
return orgList;
}
public List<Organization> getSpecialLevelOrganizations(Integer level) {
R<List<Organization>> orgListR = organizationService.getSpecialLevelOrganizations(level);
List<Organization> orgList = orgListR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
return orgList;
}
public Organization getOrganizationInfo(Long orgId) {
return null;
}
public List<Organization> getBatchOrganizationInfo(Collection<Long> orgIds) {
R<List<Organization>> listR = organizationService.getOrgsByUserIds(orgIds);
List<Organization> orgList = listR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
return orgList;
}
public List<OrgTreeModel> orgTree(VehicleTreeSearch search) {
FindOrgRequest request = new FindOrgRequest();
request.setHasUserLeaf(true);
request.setSubOrgIds(search.getOrgIds());
request.setUserIds(search.getUserIds());
R<List<OrgTreeModel>> listR = organizationService.orgTree(request);
List<OrgVehicleTree> orgList = listR.getDataList(new TypeToken<List<OrgVehicleTree>>() {
}.getType());
return convertTreeNodes(orgList);
}
public List<OrgTreeModel> convertTreeNodes(List<OrgVehicleTree> orgList) {
List<OrgTreeModel> list = Lists.newArrayList();
if (CollectionUtils.isNotEmpty(orgList)) {
orgList.forEach(ovt -> {
list.add(new OrgTreeModel(ovt.getOrigin()));
});
}
return list;
}
public void drawReportOrganization(List<? extends ReportOrgDto> list) {
if (CollectionUtils.isEmpty(list)) {
return;
}
Set<Long> userIds = list.stream().map(ReportOrgDto::getCreatedBy).collect(Collectors.toSet());
R<List<Organization>> orgsR = organizationService.getTenantPathsByUserIds(userIds);
List<Organization> orgList = orgsR.getDataList(new TypeToken<List<Organization>>() {
}.getType());
log.info("查询组织机构的结果的大小===" + orgList.size());
if (CollectionUtils.isNotEmpty(orgList)) {
list.forEach(efd -> {
List<Organization> organizations = orgList.stream().filter(index -> index.getUserId().equals(efd.getCreatedBy())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(organizations)) {
int size = organizations.size();
if (size < 2) {
return;
} else {
efd.setArea(organizations.get(1).getOrgName());
if (size > 2) {
efd.setProvince(organizations.get(2).getOrgName());
}
if (size > 3) {
efd.setCity(organizations.get(3).getOrgName());
}
}
}
});
Map<Long, User> superiorUserMap = userApiService.getSuperiorUserMapByIds(userIds);
log.info("superiorUserMap的大小===" + superiorUserMap.size());
if (CollectionUtil.isNotEmpty(superiorUserMap)) {
list.forEach(efd -> {
User user = superiorUserMap.get(efd.getCreatedBy());
if (user != null) {
efd.setItineracy(user.getUsername());
}
});
}
}
}
}