liuxiaolong
2019-05-06 a7bed6b4cfecd61ec153818945f982c5bb796b98
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.cloud.attendance.service.impl;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cloud.attendance.service.TokenService;
import com.cloud.attendance.service.UserService;
import com.cloud.attendance.utils.EnumStr;
import com.cloud.common.utils.RestTemplateUtil;
import com.cloud.model.sys.LoginAppUser;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
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;
import java.util.stream.Stream;
 
@Service
public class UserServiceImpl implements UserService {
 
    @Autowired
    private EnumStr enumStr;
    @Autowired
    private TokenService tokenService;
 
    //    BbEmployee/feign/findEmpById
    @Override
    public Map<String, Object> findEmpById(String personId, Integer orgId) {
// 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.findEmpByIdUrl;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
 
        JSONObject dataBaseParams = new JSONObject();
        dataBaseParams.put("id",personId);
        dataBaseParams.put("orgId",orgId);
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_FORM_URLENCODED, false);
        Map map = JSONObject.parseObject(resp, Map.class);
        if (map != null){
            if ("200".equals(map.get("type"))){  //  学生类型
                map.put("phone",null);         // 手机号 处理为空
            }else if ("100".equals(map.get("type"))){
                map.put("no",null);             //  学号处理为空
            }
        }else {
            map = new HashMap();  //  防止  后面调用数据为空
        }
        return map;
    }
    // /BbEmployee/list
//     "id=选择的部门id/001-总库"  "start-->起始页-->true," "length-->条数--> true"
//    "orgId-->分库orgId--> false, -->String", "groupInformation-->人员姓名 身份证号 学号,手机号,组织机构名称等组合信息",
//             "type-->人员类型-学生 教师 校外", "distributionIds-->集群数组","phone"
 
    @Override
    public List<String> queryPersonByContent(String contentValue, String gradeValue, String classValue,
                                             String identity, String orgId,Boolean delFlag,List<String> orgIds){
// 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonList;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
        JSONObject dataBaseParams = new JSONObject();
        if (classValue != null){
            dataBaseParams.put("id",classValue);
        }else if (gradeValue != null){
            dataBaseParams.put("id",gradeValue);
        }else {
            LoginAppUser appUser = tokenService.currentUser();
            Long orgId1 = appUser.getOrgId();
            Integer officeId = appUser.getOfficeId();
            dataBaseParams.put("id",officeId);
            if (StringUtils.isBlank(orgId)){
                orgId = orgId1.toString();
            }
        }
 
        if (orgIds != null && orgIds .size() > 0){
            dataBaseParams.put("orgIds",orgIds);
        }
        dataBaseParams.put("start",0);
        dataBaseParams.put("length",5000);
        dataBaseParams.put("orgId",orgId);
        dataBaseParams.put("delFlag",delFlag);
        dataBaseParams.put("groupInformation",contentValue);
        dataBaseParams.put("type",identity);
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        JSONObject map = JSONObject.parseObject(resp);
        Integer total = map.getInteger("total");
        if (total > 5000){
             // 接着查询
        }
        if (map == null){
            map = new JSONObject();  //  防止  后面调用数据为空
        }
        JSONArray data = map.getJSONArray("data");
//        data.parallelStream().map
        List<String> usrIds = Lists.transform(data, jsonObj->((JSONObject)jsonObj).getString("id"));
        return usrIds;
    }
 
    @Override
    public List queryPersonByContentForAll(String contentValue, String gradeValue,
                                                String classValue, String identity, String orgId){
// 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonList;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
        JSONObject dataBaseParams = new JSONObject();
        if (classValue != null){
            dataBaseParams.put("id",classValue);
        }else if (gradeValue != null){
            dataBaseParams.put("id",gradeValue);
        }else {
            LoginAppUser appUser = tokenService.currentUser();
            Long orgId1 = appUser.getOrgId();
            Integer officeId = appUser.getOfficeId();
            dataBaseParams.put("id",officeId);
            if (StringUtils.isBlank(orgId)){
                orgId = orgId1.toString();
            }
        }
        dataBaseParams.put("start",0);
        dataBaseParams.put("length",5000);
        dataBaseParams.put("orgId",orgId);
        dataBaseParams.put("groupInformation",contentValue);
        dataBaseParams.put("type",identity);
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        JSONObject map = JSONObject.parseObject(resp);
        Integer total = map.getInteger("total");
        if (total > 5000){
            // 接着查询
        }
        if (map == null){
            map = new JSONObject();  //  防止  后面调用数据为空
        }
        JSONArray data = map.getJSONArray("data");
        return data;
    }
 
    // /BbEmployee/queryPersonSimpleInfoById
    @Override
    public Map<String, Object> getPersonInfoById(String perId) {
// 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonSimpleInfoById;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
        JSONObject dataBaseParams = new JSONObject();
        dataBaseParams.put("personId",perId);
        dataBaseParams.put("delFlag",true);
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_FORM_URLENCODED, false);
        Map map = JSONObject.parseObject(resp, Map.class);
        if (map != null){
            if ("200".equals(map.get("type"))){  //  学生类型
                map.put("phone",null);         // 手机号 处理为空
            }else if ("100".equals(map.get("type"))){
                map.put("no",null);             //  学号处理为空
            }
        }else {
            map = new HashMap();  //  防止  后面调用数据为空
        }
        return map;
    }
 
 
    @Override
    public Map<String, JSONObject> queryAllPersonId() {
        // 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonList;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
        JSONObject dataBaseParams = new JSONObject();
        dataBaseParams.put("id","001");
        dataBaseParams.put("start",0);
        dataBaseParams.put("length",5000);
        dataBaseParams.put("orgId",null);
        dataBaseParams.put("groupInformation",null);
        dataBaseParams.put("type",null);
        dataBaseParams.put("delFlag",true);   //  是否查询全部
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        JSONObject map = JSONObject.parseObject(resp);
        Integer total = map.getInteger("total");
        if (total > 5000){
            // 接着查询
        }
        if (map == null){
            map = new JSONObject();  //  防止  后面调用数据为空
        }
        JSONArray data = map.getJSONArray("data");
//        data.parallelStream().map
//        List<String> usrIds = Lists.transform(data, jsonObj->((JSONObject)jsonObj).getString("id"));
        Map<String, JSONObject> maps = data.stream().collect(Collectors.toMap(user->((JSONObject)user).getString("id"), user -> (JSONObject) user));
        return maps;
    }
 
    public JSONArray queryAllPersonList() {
        // 调用 人员模块
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonList;
        String queryUrl = "http://"+userHOSTNAME+":"+userHTTP_port+userQueryPerIdUrl;
        JSONObject dataBaseParams = new JSONObject();
        dataBaseParams.put("id","001");
        dataBaseParams.put("start",0);
        dataBaseParams.put("length",5000);
        dataBaseParams.put("orgId",null);
        dataBaseParams.put("groupInformation",null);
        dataBaseParams.put("type",null);
        String resp = RestTemplateUtil.post(queryUrl,
                dataBaseParams, MediaType.APPLICATION_JSON_UTF8, false);
        JSONObject map = JSONObject.parseObject(resp);
        Integer total = map.getInteger("total");
        if (total > 5000){
            // 接着查询
        }
        if (map == null){
            map = new JSONObject();  //  防止  后面调用数据为空
        }
        JSONArray data = map.getJSONArray("data");
        return data;
    }
 
    @Override
    public Map<String, String> queryPersonType() {
        String userHOSTNAME = enumStr.getUserHOSTNAME();
        int userHTTP_port = enumStr.getUserHTTP_PORT();
        String userQueryPerIdUrl = EnumStr.queryPersonList;
        String queryUrl = "http://"+enumStr.getUserHOSTNAME()+":"+enumStr.getUserHTTP_PORT()
                +"/data/api-u/dict/getSysDictByType";  // ?orgId=1&type=PEO_TYPE&module=SYSTEM
// loginData/api-u/dict/getSysDictByType?orgId=1&type=PEO_TYPE&module=SYSTEM
        JSONObject params = new JSONObject();
        params.put("orgId","1");
        params.put("type","PEO_TYPE");
        params.put("module","SYSTEM");
        String s = RestTemplateUtil.get(queryUrl, params, true);
        JSONObject resp = JSONObject.parseObject(s);
        Map<String, String> personType = new HashMap<>();
        if ("0".equals(resp.getString("code"))){
            JSONArray data = resp.getJSONArray("data");
            if (data!=null &&data.size()>0){
                personType = data.parallelStream().collect(Collectors.toMap(
                        perType -> ((JSONObject) perType).getString("value"),
                        perType -> ((JSONObject) perType).getString("lable")));
            }
        }else {
            throw new RuntimeException(resp.getString("message"));
        }
        return personType;
    }
}