SyncServiceImpl.java
30.9 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
/**
* Copyright (C) 2004-2018 ALL Rights Reserved
*/
package com.example;
import com.model.UserInfo;
import com.tbc.paas.open.domain.uc.OpenOrganize;
import com.tbc.paas.open.domain.uc.OpenPosition;
import com.tbc.paas.open.domain.uc.OpenUser;
import com.tbc.paas.open.service.uc.OpenOrganizeService;
import com.tbc.paas.open.service.uc.OpenPositionService;
import com.tbc.paas.open.service.uc.OpenUserService;
import com.tbc.paas.sdk.core.ServiceManager;
import com.tbc.paas.sdk.util.SdkContext;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dom4j.*;
import javax.jws.WebService;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author ChenChao
* @since 2018-04-16 10:11:26
*/
@WebService
public class SyncServiceImpl implements SyncService {
private static String corp_code = "tbea.com";
private static Log logger = LogFactory.getLog(SyncServiceImpl.class);
private static void initSdk() {
SdkContext.serverName = "v4.21tb.com";
SdkContext.appKey = "A10808C03FD84ED8ACBE1D31E03AF25F";
SdkContext.appSecret = "281B7CB1AF6C4AAC9F693434B6920699";
}
@Override
public String syncOrganize(UserInfo userInfo) {
logger.info("********************************sync organize began *************************");
logger.info("userInfo : " + userInfo.toString());
logger.info("--------start writer org xml to file");
//writerXmlResultToFile(userInfo, "org");
logger.info("--------writer org xml to file end");
return "123";
/* initSdk();
*//* return null;*//*
Document document = null;
HashMap<String, Map<String,String>> dataMap = new HashMap<String, Map<String,String>>();
Map<String, String> uuidMap = new HashMap<String, String>();
try {
document = DocumentHelper.parseText(organizeDate);
Element rootElt = document.getRootElement();
getOrganizeNodes(rootElt, dataMap);
getDataInfosUUId(rootElt, uuidMap);
} catch (DocumentException e) {
logger.error("analysis organize xml Data false!",e);
e.printStackTrace();
}
String uuid = uuidMap.get("UUID");
logger.info("+++++++++++++++++++++++datainfos uuid = :" + uuid);
if (MapUtils.isEmpty(dataMap)) {
logger.info("dataMap is null when syncOrganize");
return getReturnData("E",uuid);
}
List<OpenOrganize> organizes = new ArrayList<OpenOrganize>();
Map<String, String> uuidAndOrganizeCodeMap = new HashMap<String, String>(dataMap.size());
StringBuilder stringBuilder = new StringBuilder();
for (String keyString : dataMap.keySet()) {
OpenOrganize openOrganize = new OpenOrganize();
Map<String, String> organizeDateMap = dataMap.get(keyString);
String organizeName = dealString(organizeDateMap.get("DESC1"),50);
String organizeCode = dealString(organizeDateMap.get("CODE"),50);
String parentCode = dealString(organizeDateMap.get("PARENTCODE"),50);
uuidAndOrganizeCodeMap.put(organizeCode, keyString);
if (StringUtils.isBlank(organizeName) || StringUtils.isBlank(organizeCode)) {
logger.info("necessary data is null when organizeName = " + organizeName + " ;organizeCode = " + organizeCode);
continue;
}
if (StringUtils.isBlank(parentCode) || parentCode.equals(organizeCode)) {
logger.info("root organize is organizeName = " + organizeName + " ;organizeCode = " + organizeCode + " ;parentCode = " + parentCode);
parentCode = "*";
}
openOrganize.setCorpCode(corp_code);
openOrganize.setOrganizeCode(organizeCode);
openOrganize.setOrganizeName(organizeName);
openOrganize.setParentCode(parentCode);
stringBuilder.append(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> organizeCode:"+organizeCode+" ; organizeName:"+organizeName+" ; parentCode:"+parentCode);
organizes.add(openOrganize);
}
try {
logger.info("--------start writer org xml to file");
writerXmlResultToFile(stringBuilder.toString(), "orgSync");
logger.info("--------writer org xml to file end");
} catch (IOException e) {
logger.error("--------writer org xml to file exception", e);
}
if (CollectionUtils.isEmpty(organizes)) {
logger.info("******************************** need sync organizes num is null");
return getReturnData("E",uuid);
}
logger.info("******************************** need sync organizes num is " + organizes.size());
// Map<String, String> dateMap = syncOrganizePort(organizes);
OpenOrganizeService openOrganizeService = ServiceManager.getService(OpenOrganizeService.class);
Map<String, String> dateMap = openOrganizeService.syncOrganizes(organizes);
int successNum = 0;
Map<String, String> uuidAndStatus = new HashMap<String, String>(uuidAndOrganizeCodeMap.size());
for (String organizeCode : uuidAndOrganizeCodeMap.keySet()) {
String value = dateMap.get(organizeCode);
if (StringUtils.isBlank(value)) {
uuidAndStatus.put(uuidAndOrganizeCodeMap.get(organizeCode), "ERROR");
} else if (value.toLowerCase().contains("error")) {
uuidAndStatus.put(uuidAndOrganizeCodeMap.get(organizeCode), value);
} else {
uuidAndStatus.put(uuidAndOrganizeCodeMap.get(organizeCode), "SUCCESS");
successNum++;
}
}
logger.info("******************************** sync organizes success num is " + successNum);
logger.info("******************************** organize sync end *****************************");
if (successNum > 0) {
return getReturnData("S",uuidAndStatus,uuid);
}
return getReturnData("E",uuidAndStatus,uuid);*/
}
@Override
public String syncPosition(String positionData) {
logger.info("********************************sync position began *************************");
logger.info("positionDate : " + positionData);
try {
logger.info("--------start writer position xml to file");
writerXmlResultToFile(positionData, "position");
logger.info("--------writer position xml to file end");
} catch (IOException e) {
logger.error("--------writer position xml to file exception", e);
}
initSdk();
Document document = null;
HashMap<String, Map<String, String>> dataMap = new HashMap<String, Map<String, String>>();
Map<String, String> uuidMap = new HashMap<String, String>();
try {
document = DocumentHelper.parseText(positionData);
Element rootElt = document.getRootElement();
getPositionNodes(rootElt, dataMap);
getDataInfosUUId(rootElt, uuidMap);
} catch (DocumentException e) {
logger.error("analysis position xml Data false!", e);
e.printStackTrace();
}
String uuid = uuidMap.get("UUID");
logger.info("+++++++++++++++++++++++ uuid = :" + uuid);
if (MapUtils.isEmpty(dataMap)) {
logger.info("dataMap is null when syncPosition");
return getReturnData("E", uuid);
}
ArrayList<OpenPosition> openPositions = new ArrayList<OpenPosition>();
Map<String, String> uuidAndPositionCodeMap = new HashMap<String, String>(dataMap.size());
StringBuilder stringBuilder = new StringBuilder();
for (String keyString : dataMap.keySet()) {
OpenPosition openPosition = new OpenPosition();
Map<String, String> positionDateMap = dataMap.get(keyString);
String positionName = dealString(positionDateMap.get("DESC1"), 50);
String positionCode = dealString(positionDateMap.get("CODE"), 50);
String categoryName = dealString(positionDateMap.get("DESC11"), 50);
String categoryCode = dealString(positionDateMap.get("DESC10"), 50);
uuidAndPositionCodeMap.put(positionCode, keyString);
if (StringUtils.isBlank(positionName) || StringUtils.isBlank(positionCode)) {
logger.info("necessary data is null when positionName = " + positionName + " ;positionCode = " + positionCode
+ " ;categoryName = " + categoryName + " ;categoryCode = " + categoryCode);
continue;
}
if (StringUtils.isBlank(categoryName) || StringUtils.isBlank(categoryCode)) {
categoryName = "特变电工岗位类别";
categoryCode = "特变电工岗位类别编码";
}
openPosition.setCorpCode(corp_code);
openPosition.setPositionName(positionName);
openPosition.setPositionCode(positionCode);
openPosition.setCategoryName(categoryName);
openPosition.setCategoryCode(categoryCode);
stringBuilder.append("+++++++++++++++++++++++++++ positionName:" + positionName + " ; positionCode:" + positionCode + " ; categoryName:" + categoryName + " ; categoryCode:" + categoryCode);
openPositions.add(openPosition);
}
try {
logger.info("--------start writer position xml to file");
writerXmlResultToFile(stringBuilder.toString(), "positionSync");
logger.info("--------writer position xml to file end");
} catch (IOException e) {
logger.error("--------writer position xml to file exception", e);
}
if (CollectionUtils.isEmpty(openPositions)) {
logger.info("******************************** need sync position num is null");
return getReturnData("E", uuid);
}
logger.info("******************************** need sync position num is " + openPositions.size());
// Map<String, String> positionCodeAndIdMap = syncPositionPort(openPositions);
OpenPositionService openPositionService = ServiceManager.getService(OpenPositionService.class);
Map<String, String> positionCodeAndIdMap = openPositionService.syncPositions(openPositions);
int successNum = 0;
Map<String, String> uuidAndStatus = new HashMap<String, String>(uuidAndPositionCodeMap.size());
for (String positionCode : uuidAndPositionCodeMap.keySet()) {
String value = positionCodeAndIdMap.get(positionCode);
if (StringUtils.isBlank(value)) {
uuidAndStatus.put(uuidAndPositionCodeMap.get(positionCode), "ERROR");
} else if (value.toLowerCase().contains("error")) {
uuidAndStatus.put(uuidAndPositionCodeMap.get(positionCode), value);
} else {
uuidAndStatus.put(uuidAndPositionCodeMap.get(positionCode), "SUCCESS");
successNum++;
}
}
logger.info("******************************** position sync success num is " + successNum);
logger.info("******************************** position sync end *****************************");
if (successNum > 0) {
return getReturnData("S", uuidAndStatus, uuid);
}
return getReturnData("E", uuidAndStatus, uuid);
}
@Override
public String syncUser(String userData) {
logger.info("********************************sync user began *************************");
logger.info("userData : " + userData);
userData = userData.replaceAll("<", "<").replaceAll(">", ">");
try {
logger.info("--------start writer user xml to file");
writerXmlResultToFile(userData, "user");
logger.info("--------writer user xml to file end");
} catch (IOException e) {
logger.error("--------writer user xml to file exception", e);
}
return "2222";
/*initSdk();
Document document = null;
HashMap<String, Map<String, String>> dataMap = new HashMap<String, Map<String, String>>();
Map<String, String> uuidMap = new HashMap<String, String>();
try {
document = DocumentHelper.parseText(userData);
Element rootElt = document.getRootElement();
getUserNodes(rootElt, dataMap);
getDataInfosUUId(rootElt, uuidMap);
} catch (DocumentException e) {
logger.error("analysis user xml Data false!", e);
e.printStackTrace();
}
String uuid = uuidMap.get("UUID");
logger.info("+++++++++++++++++++++++ uuid = :" + uuid);
if (MapUtils.isEmpty(dataMap)) {
logger.info("dataMap is null when syncUser");
return getReturnData("E", uuid);
}
ArrayList<OpenUser> openUsers = new ArrayList<OpenUser>();
Map<String, String> uuidAndEmployeeCodeMap = new HashMap<String, String>(dataMap.size());
StringBuilder stringBuilder = new StringBuilder("");
for (String keyString : dataMap.keySet()) {
OpenUser openUser = new OpenUser();
Map<String, String> userDateMap = dataMap.get(keyString);
String employeeCode = dealString(userDateMap.get("DESC1"), 32);
String username = dealString(userDateMap.get("DESC2"), 50);
String organizeCode = dealString(userDateMap.get("DESC8"), 50);
String loginName = dealString(userDateMap.get("CODE"), 50);
uuidAndEmployeeCodeMap.put(employeeCode, keyString);
if (StringUtils.isBlank(employeeCode) || StringUtils.isBlank(username) || StringUtils.isBlank(organizeCode) || StringUtils.isBlank(loginName)) {
logger.warn("user can not sync because missing necessary data!");
logger.warn("user employeeCode =" + employeeCode + "; username =" + username + "; organizeCode =" + organizeCode + "; loginName =" + loginName);
continue;
}
openUser.setCorpCode(corp_code);
openUser.setEmployeeCode(employeeCode);
openUser.setLoginName(loginName);
openUser.setUserName(username);
openUser.setOrganizeCode(organizeCode);
String accountStatus = dealString(userDateMap.get("DESC21"), 10);
if (StringUtils.isNotBlank(accountStatus) && "Y".equals(accountStatus.toUpperCase())) {
openUser.setAccountStatus("ENABLE");
} else {
openUser.setAccountStatus("FORBIDDEN");
}
String sexString = dealString(userDateMap.get("DESC4"), 32);
if ("男".equals(sexString)) {
openUser.setSex("MAN");
} else if ("女".equals(sexString)) {
openUser.setSex("WOMAN");
} else {
openUser.setSex("OTHER");
}
String idCard = dealString(userDateMap.get("DESC11"), 20);
String mobile = dealString(userDateMap.get("DESC12"), 32);
String email = dealString(userDateMap.get("DESC14"), 50);
String dutyLevel = dealString(userDateMap.get("DESC17"), 10);
String positionCode = dealString(userDateMap.get("DESC15"), 40);
openUser.setIdCard(idCard);
openUser.setMobile(mobile);
openUser.setEmail(email);
openUser.setRank(dutyLevel);
openUser.setPositionCode(positionCode);
String onBoadingString = dealString(userDateMap.get("DESC18"), 10);
Date onBoading = parseStringToDate(onBoadingString);
openUser.setOnBoarding(onBoading);
stringBuilder.append("----------------------->>>>>> employeeCode:" + employeeCode + " ; loginName:" + loginName + " ; username:" + username + " ; organizeCode:" + organizeCode +
" ; accountStatus:" + accountStatus + " ; organizeCode:" + organizeCode + " ; idCard:" + idCard + " ; positionCode:" + positionCode + " ; mobile:" + mobile);
openUsers.add(openUser);
}
try {
logger.info("--------start writer user xml to file");
writerXmlResultToFile(stringBuilder.toString(), "userSync");
logger.info("--------writer user xml to file end");
} catch (IOException e) {
logger.error("--------writer user xml to file exception", e);
}
if (CollectionUtils.isEmpty(openUsers)) {
logger.info("******************************** need sync openUsers num is null");
return getReturnData("E", uuid);
}
logger.info("******************************** need sync openUsers num is " + openUsers.size());
Map<String, String> employeeCodeAndUserIdMap = syncUserPort(openUsers);
logger.info("******************************** openUsers sync success num is " + employeeCodeAndUserIdMap.size());
Set<String> successEmployeeCode = employeeCodeAndUserIdMap.keySet();
Map<String, String> uuidAndStatus = new HashMap<String, String>(uuidAndEmployeeCodeMap.size());
for (String employeeCode : uuidAndEmployeeCodeMap.keySet()) {
if (successEmployeeCode.contains(employeeCode)) {
uuidAndStatus.put(uuidAndEmployeeCodeMap.get(employeeCode), "SUCCESS");
} else {
uuidAndStatus.put(uuidAndEmployeeCodeMap.get(employeeCode), "ERROR");
}
}
logger.info("******************************** openUsers sync end *****************************");
if (employeeCodeAndUserIdMap.size() > 0) {
return getReturnData("S", uuidAndStatus, uuid);
}
return getReturnData("E", uuidAndStatus, uuid);*/
}
private static void getUserNodes(Element element, Map<String, Map<String, String>> dateMap) {
List<Element> listElement = element.elements();
for (Element e : listElement) {
if ("DATAINFO".equals(e.getName())) {
List<Element> elements = e.elements();
HashMap<String, String> userDataMap = new HashMap<String, String>();
for (Element el : elements) {
String name = el.getName();
if ("DESC1".equals(name)) {
//员工工号
userDataMap.put("DESC1", el.getText());
}
if ("DESC2".equals(name)) {
//姓名
userDataMap.put("DESC2", el.getText());
}
if ("DESC4".equals(name)) {
//性别
userDataMap.put("DESC4", el.getText());
}
if ("DESC8".equals(name)) {
//所属部门编码
userDataMap.put("DESC8", el.getText());
}
if ("DESC11".equals(name)) {
//证件号码
userDataMap.put("DESC11", el.getText());
}
if ("DESC12".equals(name)) {
//手机
userDataMap.put("DESC12", el.getText());
}
if ("DESC13".equals(name)) {
//电话号码
userDataMap.put("DESC13", el.getText());
}
if ("DESC14".equals(name)) {
//电子邮箱
userDataMap.put("DESC14", el.getText());
}
if ("DESC15".equals(name)) {
//岗位编码
userDataMap.put("DESC15", el.getText());
}
if ("DESC17".equals(name)) {
//职务级别
userDataMap.put("DESC17", el.getText());
}
if ("DESC18".equals(name)) {
//入职日期
userDataMap.put("DESC18", el.getText());
}
if ("DESC21".equals(name)) {
//是否在岗
userDataMap.put("DESC21", el.getText());
}
if ("CODE".equals(name)) {
//主编码
userDataMap.put("CODE", el.getText());
}
if ("UUID".equals(name)) {
dateMap.put(el.getText(), userDataMap);
}
}
}
getUserNodes(e, dateMap);
}
}
private static void getOrganizeNodes(Element element, Map<String, Map<String, String>> dateMap) {
List<Element> listElement = element.elements();
for (Element e : listElement) {
if ("DATAINFO".equals(e.getName())) {
List<Element> elements = e.elements();
HashMap<String, String> organizeDataMap = new HashMap<String, String>();
for (Element el : elements) {
String name = el.getName();
if ("DESC1".equals(name)) {
organizeDataMap.put("DESC1", el.getText());
}
if ("PARENTCODE".equals(name)) {
organizeDataMap.put("PARENTCODE", el.getText());
}
if ("CODE".equals(name)) {
organizeDataMap.put("CODE", el.getText());
}
if ("UUID".equals(name)) {
dateMap.put(el.getText(), organizeDataMap);
}
}
}
getOrganizeNodes(e, dateMap);
}
}
private static void getPositionNodes(Element element, Map<String, Map<String, String>> dateMap) {
List<Element> listElement = element.elements();
for (Element e : listElement) {
if ("DATAINFO".equals(e.getName())) {
List<Element> elements = e.elements();
HashMap<String, String> positionDataMap = new HashMap<String, String>();
for (Element el : elements) {
String name = el.getName();
if ("DESC1".equals(name)) {
positionDataMap.put("DESC1", el.getText());
}
if ("DESC10".equals(name)) {
positionDataMap.put("DESC10", el.getText());
}
if ("DESC11".equals(name)) {
positionDataMap.put("DESC11", el.getText());
}
if ("CODE".equals(name)) {
positionDataMap.put("CODE", el.getText());
}
if ("UUID".equals(name)) {
dateMap.put(el.getText(), positionDataMap);
}
}
}
getPositionNodes(e, dateMap);
}
}
private static void getDataInfosUUId(Element element, Map<String, String> uuidMap) {
if ("DATAINFOS".equals(element.getName().toUpperCase())) {
Attribute uuid = element.attribute("uuid");
if (uuid == null) {
uuid = element.attribute("UUID");
}
if (null != uuid) {
uuidMap.put("UUID", uuid.getText());
}
return;
}
List<Element> listElement = element.elements();
for (Element e : listElement) {
if ("DATAINFOS".equals(e.getName().toUpperCase())) {
Attribute uuid = e.attribute("uuid");
if (uuid == null) {
uuid = e.attribute("UUID");
}
if (null != uuid) {
uuidMap.put("UUID", uuid.getText());
}
}
getDataInfosUUId(e, uuidMap);
}
}
private static Map<String, String> syncOrganizePort(List<OpenOrganize> openOrganize) {
OpenOrganizeService openOrganizeService = ServiceManager.getService(OpenOrganizeService.class);
int pageSize = 500;
int i = 1;
Map<String, String> result = new HashMap<String, String>(openOrganize.size());
List<List<OpenOrganize>> organizeLists = separateIntoPieces(openOrganize, pageSize);
logger.info(" totalRound :" + organizeLists.size());
for (List<OpenOrganize> sub : organizeLists) {
logger.info("this is :" + i + " round");
i++;
try {
Map<String, String> resultMap = openOrganizeService.syncOrganizes(sub);
if (MapUtils.isNotEmpty(resultMap)) {
result.putAll(resultMap);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
private static Map<String, String> syncUserPort(List<OpenUser> openUserList) {
OpenUserService openUserService = ServiceManager.getService(OpenUserService.class);
int pageSize = 200;
int i = 1;
Map<String, String> result = new HashMap<String, String>(openUserList.size());
List<List<OpenUser>> userList = separateIntoPieces(openUserList, pageSize);
logger.info(" totalRound :" + userList.size());
logger.info("========syn_start============");
for (List<OpenUser> openUsers : userList) {
logger.info("this is :" + i + " round");
i++;
try {
if (CollectionUtils.isEmpty(openUsers)) {
continue;
}
Map<String, String> dataResult = openUserService.syncUsers(openUsers, true);
if (MapUtils.isNotEmpty(dataResult)) {
result.putAll(dataResult);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
private static Map<String, String> syncPositionPort(List<OpenPosition> openPosition) {
OpenPositionService openPositionService = ServiceManager.getService(OpenPositionService.class);
int pageSize = 500;
int i = 1;
Map<String, String> result = new HashMap<String, String>(openPosition.size());
List<List<OpenPosition>> positionLists = separateIntoPieces(openPosition, pageSize);
logger.info(" totalRound :" + positionLists.size());
for (List<OpenPosition> sub : positionLists) {
logger.info("this is :" + i + " round");
i++;
try {
Map<String, String> resultMap = openPositionService.syncPositions(sub);
if (MapUtils.isNotEmpty(resultMap)) {
result.putAll(resultMap);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return result;
}
private static <T> List<List<T>> separateIntoPieces(List<T> source, int pieceSize) {
List<List<T>> result = new ArrayList<List<T>>();
int sourceSize = source.size();
if (sourceSize <= pieceSize) {
result.add(source);
} else {
int piece = sourceSize / pieceSize;
int fromIndex = 0;
for (int i = 0; i < piece; i++) {
result.add(source.subList(fromIndex, fromIndex + pieceSize));
fromIndex += pieceSize;
}
result.add(source.subList(fromIndex, sourceSize));
}
return result;
}
private static String dealString(String string, int num) {
if (null == string) {
return null;
}
if ("null".equals(string.toLowerCase())) {
return null;
}
if (string.length() > num) {
logger.info("this data is too long : " + string);
return string.substring(0, num);
}
return string;
}
private static Date parseStringToDate(String string) {
if ("null".equals(string) || StringUtils.isBlank(string)) {
return null;
}
Date date = null;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
date = simpleDateFormat.parse(string);
} catch (Exception e) {
e.printStackTrace();
}
return date;
}
private static String getReturnData(String code, String uuid) {
String returnData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
return returnData + "<ESB>" + "<CODE>" + code + "</CODE>" + "<DESC>没有获取需要同步的数据<DESC>" + "<DATAINFOS UUID=\"" + uuid + "\">" + "</DATAINFOS></ESB>";
}
private static String getReturnData(String code, Map<String, String> uuidAndStatusMap, String uuid) {
String returnData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
returnData += "<ESB>" + "<CODE>" + code + "</CODE>" + "<DATAINFOS UUID=\"" + uuid + "\">";
for (String dataInfoUUID : uuidAndStatusMap.keySet()) {
String status = uuidAndStatusMap.get(dataInfoUUID);
if ("SUCCESS".equals(status)) {
returnData += "<DATAINFO uuid=\"" + dataInfoUUID + "\" status=\"0\" errorText=\"\"></DATAINFO>";
} else if ("ERROR".equals(status)) {
returnData += "<DATAINFO uuid=\"" + dataInfoUUID + "\" status=\"1\" errorText=\"缺失必填数据或同步出错\"></DATAINFO>";
} else {
returnData += "<DATAINFO uuid=\"" + dataInfoUUID + "\" status=\"1\" errorText=\"" + status + "\"></DATAINFO>";
}
}
returnData += "</DATAINFOS></ESB >";
logger.info("-------------------------> returnData:" + returnData);
return returnData;
}
private void writerXmlResultToFile(String xmlResult, String type) throws IOException {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new FileWriter(getFile(type), true));
writer.write(xmlResult);
writer.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static final DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
private File getFile(String type) throws IOException {
String today = dateFormat.format(new Date());
String path = "xmlResult" + File.separator + today + File.separator + type + ".txt";
File file = new File(path);
if (!file.exists()) {
File parentFile = file.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
file.createNewFile();
}
return file;
}
}