ScriptImpl.java
77 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
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
package com.hotent.runtime.script;
import java.io.IOException;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.annotation.Resource;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.databind.node.*;
import com.hotent.base.datasource.DatabaseContext;
import com.hotent.base.manager.CommonManager;
import com.hotent.base.util.*;
import com.hotent.base.util.Base64;
import com.hotent.runtime.model.enums.UserParamsEnums;
import com.hotent.runtime.utils.SubCalcUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.JsonNode;
import com.hotent.base.cache.annotation.Cacheable;
import com.hotent.base.cache.annotation.FirstCache;
import com.hotent.base.constants.CacheKeyConst;
import com.hotent.base.context.BaseContext;
import com.hotent.base.exception.BaseException;
import com.hotent.base.feign.BpmRuntimeFeignService;
import com.hotent.base.feign.FormFeignService;
import com.hotent.base.feign.PortalFeignService;
import com.hotent.base.feign.UCFeignService;
import com.hotent.base.groovy.IScript;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.time.DateFormatUtil;
import com.hotent.base.util.time.DateUtil;
import com.hotent.base.util.time.TimeUtil;
import com.hotent.bpm.api.cmd.ActionCmd;
import com.hotent.bpm.api.constant.BpmConstants;
import com.hotent.bpm.api.constant.ExtractType;
import com.hotent.bpm.api.context.ContextThreadUtil;
import com.hotent.bpm.api.model.delegate.BpmDelegateTask;
import com.hotent.bpm.api.model.identity.BpmIdentity;
import com.hotent.bpm.api.service.BoDataService;
import com.hotent.bpm.api.service.BpmTaskActionService;
import com.hotent.bpm.engine.task.cmd.DefaultTaskFinishCmd;
import com.hotent.bpm.listener.BusDataUtil;
import com.hotent.bpm.model.identity.DefaultBpmIdentity;
import com.hotent.bpm.natapi.task.NatTaskService;
import com.hotent.bpm.persistence.manager.BpmBusLinkManager;
import com.hotent.bpm.persistence.manager.BpmDefinitionManager;
import com.hotent.bpm.persistence.manager.BpmProcessInstanceManager;
import com.hotent.bpm.persistence.model.BpmBusLink;
import com.hotent.bpm.persistence.model.BpmExeStack;
import com.hotent.bpm.persistence.model.DefaultBpmDefinition;
import com.hotent.bpm.persistence.model.DefaultBpmProcessInstance;
import com.hotent.bpm.persistence.model.DefaultBpmTask;
import com.hotent.bpm.util.BoDataUtil;
import com.hotent.runtime.manager.IProcessManager;
import com.hotent.runtime.params.StartFlowParamObject;
import com.hotent.runtime.params.StartResult;
import com.hotent.uc.api.constant.GroupTypeConstant;
import com.hotent.uc.api.impl.service.UserServiceImpl;
import com.hotent.uc.api.impl.util.ContextUtil;
import com.hotent.uc.api.model.IGroup;
import com.hotent.uc.api.model.IUser;
/**
* 系统配置中的常用脚本。
*
* @author ray
*/
@Component
public class ScriptImpl implements IScript {
@Resource
PortalFeignService portalFeignService;
@Resource
BpmProcessInstanceManager bpmProcessInstanceManager;
@Resource
BoDataService boDataService;
@Resource
UCFeignService uCFeignService;
@Resource
IProcessManager iProcessService;
@Resource
UserServiceImpl userServiceImpl;
@Resource
BaseContext baseContext;
@Resource
BpmDefinitionManager bpmDefinitionManager;
@Resource
NatTaskService natTaskService;
@Resource
DatabaseContext databaseContext;
@Resource
CommonManager commonManager;
private final String FIELD_PREFIX = "F_";
private final String CurrentGroupIdPrefix = "CurrentGroupId:";
/**
* 获取当前用户ID。
*
* @return
*/
public Set<String> getCurrentUserIdSet() {
Set<String> set = new HashSet<String>();
set.add(ContextUtil.getCurrentUser().getUserId());
return set;
}
/**
* 获取当前用户对象。
*
* @return
*/
public IUser getCurrentUser() {
return ContextUtil.getCurrentUser();
}
/**
* 获取当前用户ID。
*
* @return
*/
public String getCurrentUserId() {
return ContextUtil.getCurrentUser().getUserId();
}
/**
* 获取当前用户帐号。
*
* @return
*/
public String getCurrentAccount() {
return ContextUtil.getCurrentUser().getAccount();
}
/**
* 获取当前用户的当前组织id
*
* @return
* @throws Exception
*/
public String getCurrentGroupId() throws Exception {
String userId = ContextUtil.getCurrentUserId();
ScriptImpl bean = AppUtil.getBean(getClass());
String groupIdFromCache = bean.getCurrentGroupIdFromCache(userId);
return StringUtil.isEmpty(groupIdFromCache) ? ContextUtil.getCurrentGroupId() : groupIdFromCache;
}
/**
* 获取当前用户的当前组织名称。
*
* @return
* @throws IOException
*/
public String getCurrentGroupName() throws IOException {
IGroup currentGroup = ContextUtil.getCurrentGroup();
if (currentGroup == null) {
return null;
}
return currentGroup.getName();
}
/**
* 根据别名生成流水号。
*
* <pre>
* 使用方法:
* scriptImpl.getNextNo("globalNo");
* </pre>
*
* @param alias 流水号配置别名。
* @return
*/
public String getNextNo(String alias) {
return portalFeignService.getNextIdByAlias(alias);
}
/**
* 判断命令是否是 DefaultTaskFinishCmd
*
* @param processCmd
* @return
*/
public boolean isDefaultTaskFinishCmd(ActionCmd processCmd) {
return DefaultTaskFinishCmd.class.getName().equals(processCmd.getClass().getName());
}
/**
* 判断数据是否在系统中存在。
*
* @param boData
* @param fieldName 字段名
* @return
* @messages 消息
*/
public void validBoDataExist(ObjectNode boData, String fieldName, String messages) {
JdbcTemplate jdbcTemplate = (JdbcTemplate) AppUtil.getBean("jdbcTemplate");
ObjectNode boEnt = (ObjectNode) boData.get("boEnt");
boolean isAdd = true;
String pk = boEnt.get("pkKey").asText().toLowerCase();
if (boEnt.findValues("pk") != null && StringUtil.isNotEmpty(String.valueOf(boEnt.get(pk).asText()))) {
isAdd = false;
}
String sql = "";
Object[] aryObj = null;
Object obj = boData.get(fieldName);
String val = "";
if (BeanUtils.isNotEmpty(obj)) {
val = obj.toString().trim();
}
// 添加
if (isAdd) {
aryObj = new Object[1];
aryObj[0] = val;
sql = "select count(*) from " + boEnt.get("tableName").asText() + " where " + FIELD_PREFIX + fieldName
+ "=?";
}
// 更新数据
else {
aryObj = new Object[2];
aryObj[0] = val;
aryObj[1] = boData.get(boEnt.get("pkKey").asText());
sql = "select count(*) from " + boEnt.get("tableName").asText() + " where " + FIELD_PREFIX + fieldName
+ "=? and " + boEnt.get("pkKey").asText() + "!=?";
}
Integer rtn = jdbcTemplate.queryForObject(sql, aryObj, Integer.class);
if (rtn > 0) {
if (StringUtil.isNotEmpty(messages)) {
throw new RuntimeException(messages);
} else {
throw new RuntimeException(val + "数据已经存在,请检查表单数据!");
}
}
}
/**
* 全部角色
*
* @return
*/
public Set<BpmIdentity> getRoles() {
Set<BpmIdentity> set = new LinkedHashSet<BpmIdentity>();
List<ObjectNode> listRole = uCFeignService.getAllRole();
for (ObjectNode role : listRole) {
BpmIdentity identity = new DefaultBpmIdentity(role.get("id").asText(), role.get("name").asText(),
BpmIdentity.TYPE_GROUP);
identity.setType(BpmIdentity.TYPE_GROUP);
identity.setExtractType(ExtractType.EXACT_NOEXACT);
identity.setGroupType(GroupTypeConstant.ROLE.key());
set.add(identity);
}
return set;
}
/**
* 判断某个用户是否属于某个角色
*
* @param account 用户賬號
* @param roleAlias 角色别名
* @return
*/
public boolean isUserInRole(String account, String roleAlias) {
if (StringUtil.isEmpty(account) || StringUtil.isEmpty(roleAlias)) {
return false;
}
List<ObjectNode> listRole = uCFeignService.getRoleListByAccount(account);
if (BeanUtils.isNotEmpty(listRole)) {
for (ObjectNode role : listRole) {
if (roleAlias.equals(role.get("code").asText())) {
return true;
}
}
}
return false;
}
/**
* 获取cmd对象
*
* @return
*/
public ActionCmd getActionCmd() {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
return cmd;
}
/**
* 获取当前用户的主组织名称
*
* @return
*/
public String getIUserMainOrgName() {
ObjectNode org = uCFeignService.getMainGroup(ContextUtil.getCurrentUser().getUserId());
if (BeanUtils.isNotEmpty(org)) {
return org.get("name").asText();
}
return null;
}
/**
* 获取当前用户的主组织ID
*
* @return
*/
public String getIUserMainOrgID() {
ObjectNode org = uCFeignService.getMainGroup(ContextUtil.getCurrentUser().getUserId());
if (BeanUtils.isNotEmpty(org)) {
return org.get("id").asText();
}
return null;
}
/**
* 获取当前用户的岗位名称
*
* @return
*/
public Set<String> getIUserPostName() {
Set<String> set = new HashSet<String>();
List<ObjectNode> orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount());
if (BeanUtils.isNotEmpty(orgRels)) {
for (ObjectNode orgRel : orgRels) {
set.add(orgRel.get("name").asText());
}
}
return set;
}
/**
* 获取当前用户的岗位ID
*
* @return
*/
public Set<String> getIUserPostID() {
Set<String> set = new HashSet<String>();
List<ObjectNode> orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount());
if (BeanUtils.isNotEmpty(orgRels)) {
for (ObjectNode orgRel : orgRels) {
set.add(orgRel.get("id").asText());
}
}
return set;
}
/**
* 获取当前用户的角色名称
*
* @return
*/
public Set<String> getIUserRoleName() {
Set<String> set = new HashSet<String>();
List<ObjectNode> roles = uCFeignService.getRoleListByAccount(ContextUtil.getCurrentUser().getAccount());
if (BeanUtils.isNotEmpty(roles)) {
for (ObjectNode role : roles) {
set.add(role.get("name").asText());
}
}
return set;
}
/**
* 获取当前用户的角色ID
*
* @return
*/
public Set<String> getIUserRoleID() {
Set<String> set = new HashSet<String>();
List<ObjectNode> roles = uCFeignService.getRoleListByAccount(ContextUtil.getCurrentUser().getUserId());
if (BeanUtils.isNotEmpty(roles)) {
for (ObjectNode role : roles) {
set.add(role.get("id").asText());
}
}
return set;
}
/**
* 获取当前用户名称
*
* @return
*/
public String getCurrentUserName() {
return ContextUtil.getCurrentUser().getFullname();
}
/**
* 根据新闻公告id修改其数据审批状态为审批通过 1。审批中。2.审批通过
*/
public void getNewsStatusById() throws Exception {
ActionCmd actionCmd = getActionCmd();
BpmBusLinkManager bpmBusLinkManager = AppUtil.getBean(BpmBusLinkManager.class);
if (BeanUtils.isNotEmpty(actionCmd)) {
Map<String, BpmBusLink> linkMap = bpmBusLinkManager.getMapByInstId(actionCmd.getInstId());
ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(actionCmd.getBusData());
// BO Map数据。
Map<String, ObjectNode> jsonMap = BoDataUtil.getMap(jsonObject);
FormFeignService formFeignService = AppUtil.getBean(FormFeignService.class);
for (String key : jsonMap.keySet()) {
ObjectNode def = formFeignService.getBodefByAlias(key);
BpmBusLink busLink = linkMap.get(def.get("alias").asText());
PortalFeignService portalFeignService = AppUtil.getBean(PortalFeignService.class);
portalFeignService.publicMsgNews(busLink.getBusinesskeyStr());
}
}
}
public Boolean isSynchronize(String nodeIds, String actionName) throws Exception {
Boolean flag = true;
ActionCmd actionCmd = getActionCmd();
if (BeanUtils.isNotEmpty(actionCmd)) {
BpmRuntimeFeignService bean = AppUtil.getBean(BpmRuntimeFeignService.class);
String lastNodeIds = "";// 最后一个任务节点ID
if (BeanUtils.isNotEmpty(actionCmd.getTransitVars("parentStack"))) {
BpmExeStack bpmExeStack = (BpmExeStack) actionCmd.getTransitVars("parentStack");
lastNodeIds = bpmExeStack.getNodeId();
}
String lastActionName = actionCmd.getActionName();// 最后一个任务节点审批处理的状态
flag = bean.isSynchronize(actionCmd.getInstId(), nodeIds, actionName, lastActionName, lastNodeIds);
}
return flag;
}
/**
* 获取当前日期,例如"2002-11-06"
*
* @return
*/
public String getCurrentDate() {
return TimeUtil.getCurrentDate();
}
/**
* 获取当前日期,按指定格式输出
*
* @return
*/
public String getCurrentDateByStyle(String style) {
return DateUtil.getCurrentTime(style);
}
/**
* 更新主表字段值
*
* @param defCode 业务对象编码
* @param field 字段名称
* @param value 字段值
* @throws Exception
*/
public void updateMainField(String defCode, String field, Object value) throws Exception {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
String instId = cmd.getInstId();
DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId);
ObjectNode jsonObject = JsonUtil.createObjectNode();
//如果有实例信息,则根据实例信息取最新的表单数据来更新。
if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(field) && BeanUtils.isNotEmpty(instance)) {
List<ObjectNode> oldBoDatas = boDataService.getDataByInst(instance);
if (BeanUtils.isEmpty(oldBoDatas)) {
throw new RuntimeException(String.format("根据实例id:%s未查找到表单数据", instId));
}
boolean isUpdate = false;
for (ObjectNode obj : oldBoDatas) {
if (defCode.equals(JsonUtil.getString(obj, "boDefAlias")) && BeanUtils.isNotEmpty(obj.get("boEnt")) && BeanUtils.isNotEmpty(obj.get("boEnt").get("attributeList"))) {
ArrayNode attrs = (ArrayNode) obj.get("boEnt").get("attributeList");
for (JsonNode jsonNode : attrs) {
if (field.equals(jsonNode.get("name").asText())) {
isUpdate = true;
break;
}
}
}
}
// 如果从数据库取出来的bodata的attributeList,没找到这个字段。则该字段不存在,直接return不做更新。
if (!isUpdate) {
return;
}
jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas);
// 没有实例信息,但是cmd里面有busdata和流程实例对象,则用busdata来更新
} else if (StringUtil.isNotEmpty(cmd.getBusData()) && BeanUtils.isNotEmpty(cmd.getTransitVars(BpmConstants.PROCESS_INST))) {
instance = (DefaultBpmProcessInstance) cmd.getTransitVars(BpmConstants.PROCESS_INST);
jsonObject = (ObjectNode) JsonUtil.toJsonNode(cmd.getBusData());
} else { // 两者都没有。则return
return;
}
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String key = next.getKey();
if (key.equals(defCode)) {
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (BeanUtils.isNotEmpty(ywdxObj)) {
if (value instanceof Integer) {
ywdxObj.put(field, (int) value);
} else {
ywdxObj.put(field, (String) value);
}
}
}
}
BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject));
cmd.setBusData(JsonUtil.toJson(jsonObject));
}
/**
* 根据实例id更新主表字段值
*
* @param instId 实例id
* @param defCode 业务对象编码
* @param field 字段名称
* @param value 字段值
* @throws Exception
*/
public void updateMainField(String instId, String defCode, String field, Object value) throws Exception {
DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId);
if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(field) && BeanUtils.isNotEmpty(instance)) {
List<ObjectNode> oldBoDatas = boDataService.getDataByInst(instance);
ObjectNode jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas);
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
boolean isUpdate = false;
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String key = next.getKey();
if (key.equals(defCode)) {
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (BeanUtils.isNotEmpty(ywdxObj)) {
Iterator<Entry<String, JsonNode>> fieldIterator = ywdxObj.fields();
while (fieldIterator.hasNext()) {
String fieldKey = fieldIterator.next().getKey();
if (fieldKey.equals(field)) {
if (value instanceof Integer) {
ywdxObj.put(field, (int) value);
} else {
ywdxObj.put(field, (String) value);
}
isUpdate = true;
break;
}
}
}
}
}
if (isUpdate) {
BusDataUtil.updateBoData(instance, "", JsonUtil.toJsonString(jsonObject));
}
}
}
/**
* 更新子表字段值
*
* @param mainDefCode 主表bo定义编码
* @param subDefCode 子表bo定义编码
* @param index 更新子表数据行序号
* @param field 更新子表字段
* @param value 更新子表字段值
* @throws Exception
*/
public void updateSubField(String mainDefCode, String subDefCode, int index, String field, Object value)
throws Exception {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
if (StringUtil.isNotEmpty(mainDefCode) && StringUtil.isNotEmpty(field)) {
String busData = cmd.getBusData();
ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData);
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
boolean isUpdate = false;
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String key = next.getKey();
if (key.equals(mainDefCode)) {
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (BeanUtils.isNotEmpty(ywdxObj)) {
Iterator<Entry<String, JsonNode>> fieldIterator = ywdxObj.fields();
while (fieldIterator.hasNext()) {
Entry<String, JsonNode> mainNext = fieldIterator.next();
if (mainNext.getKey().contains("sub_")) {
String fieldKey = mainNext.getKey().replace("sub_", "");
if (fieldKey.equals(subDefCode)) {
ArrayNode subArrayObj = (ArrayNode) mainNext.getValue();
if (BeanUtils.isNotEmpty(subArrayObj) && subArrayObj.size() >= (index + 1)) {
ObjectNode subObj = (ObjectNode) subArrayObj.get(index);
Iterator<Entry<String, JsonNode>> subIterator = subObj.fields();
while (subIterator.hasNext()) {
Entry<String, JsonNode> subNext = subIterator.next();
String subFieldKey = subNext.getKey();
if (subFieldKey.equals(field)) {
if (value instanceof Integer) {
subObj.put(field, (int) value);
} else {
subObj.put(field, (String) value);
}
isUpdate = true;
break;
}
}
}
}
}
}
}
}
}
DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(cmd.getInstId());
if (isUpdate && BeanUtils.isNotEmpty(instance)) {
BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject));
cmd.setBusData(JsonUtil.toJson(jsonObject));
}
}
}
/**
* 获取子表字段值
*
* @param ywdxCode 业务对象编码
* @param subTableName 子表表名
* @param field 字段名称
* @return
* @throws IOException
*/
public Object getSubFiledValue(String defCode, String subTableName, String field) throws IOException {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(subTableName) && StringUtil.isNotEmpty(field)) {
String busData = cmd.getBusData();
ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData);
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
while (iterator.hasNext()) {
String key = iterator.next().getKey();
if (key.equals(defCode)) {
ObjectNode ywdxObj = (ObjectNode) jsonObject.get(key);
if (BeanUtils.isNotEmpty(ywdxObj)) {
Iterator<Entry<String, JsonNode>> fieldIterator = ywdxObj.fields();
while (fieldIterator.hasNext()) {
String fieldKey = fieldIterator.next().getKey();
String subName = "sub_" + subTableName;
if (fieldKey.equals(subName)) {
ObjectNode subObj = (ObjectNode) jsonObject.get(subName);
if (BeanUtils.isNotEmpty(subObj)) {
Iterator<Entry<String, JsonNode>> subIterator = ywdxObj.fields();
while (subIterator.hasNext()) {
String subFiledKey = fieldIterator.next().getKey();
if (subFiledKey.equals(field)) {
return ywdxObj.get(field);
}
}
}
}
}
}
}
}
}
return null;
}
/**
* 根据下标获取子表字段值
*
* @param defCode
* @param subTableCode
* @param subFieldCode
* @param index
* @return
* @throws Exception
*/
public String getSubFieldValueByIndex(String defCode, String subTableCode, String subFieldCode, int index)
throws Exception {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
if (StringUtil.isNotEmpty(defCode) && StringUtil.isNotEmpty(subTableCode)) {
String busData = cmd.getBusData();
ObjectNode jsonObject = (ObjectNode) JsonUtil.toJsonNode(busData);
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
String subTabName = "sub_" + subTableCode;
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String key = next.getKey();
if (key.equals(defCode)) {
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (BeanUtils.isNotEmpty(ywdxObj)) {
Iterator<Entry<String, JsonNode>> fieldIterator = ywdxObj.fields();
while (fieldIterator.hasNext()) {
Entry<String, JsonNode> mainNext = fieldIterator.next();
if (mainNext.getKey().equals(subTabName)) {
ArrayNode subArrayObj = (ArrayNode) mainNext.getValue();
if (BeanUtils.isNotEmpty(subArrayObj) && subArrayObj.size() >= index) {
return JsonUtil.getString(subArrayObj.get(index - 1), subFieldCode, "");
}
}
}
}
}
}
}
return "";
}
public static boolean littleThen(String st1, String st2) {
if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) {
return st1.compareTo(st2) < 0;
}
return false;
}
public static boolean LargeThen(String st1, String st2) {
if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) {
return st1.compareTo(st2) > 0;
}
return false;
}
public static boolean equals(String st1, String st2) {
if (BeanUtils.isEmpty(st1) && BeanUtils.isEmpty(st2)) {
return true;
}
if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) {
return st1.equals(st2);
}
return false;
}
public static boolean contains(String st1, String st2) {
if (BeanUtils.isNotEmpty(st1) && BeanUtils.isNotEmpty(st1)) {
return st1.contains(st2);
}
return false;
}
/**
* 判断子表子表中是否有某一行的字段名为指定值
*
* @param arr 子表集合
* @param field 字段名
* @param value 字段值
*/
public static boolean subContains(ArrayNode arr, String field, String value) throws Exception {
if (BeanUtils.isEmpty(arr)) {
return false;
}
for (JsonNode node : arr) {
JsonNode v = node.get(field);
if (null == v || v.getNodeType().equals(JsonNodeType.NULL)) {
continue;
}
if (v.getNodeType().equals(JsonNodeType.STRING)
|| v.getNodeType().equals(JsonNodeType.NUMBER)) {
if (v.asText().contains(value)) {
return true;
}
}
}
return false;
}
/**
* 开始时间是否大于结束时间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isDateLarge(LocalDateTime startTime, LocalDateTime endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) > 0;
}
public static boolean dateIsNull(LocalDateTime startTime) {
return BeanUtils.isEmpty(startTime);
}
public static boolean dateIsNull(String startTime) {
return BeanUtils.isEmpty(startTime);
}
public static boolean isDateLarge(LocalDateTime startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
try {
LocalDateTime date = DateFormatUtil.parse(endTime);
return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) > 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
public static boolean isDateLarge(String startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
try {
LocalDateTime sdate = DateFormatUtil.parse(startTime);
LocalDateTime date = DateFormatUtil.parse(endTime);
return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) > 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
/**
* 开始时间是否大于等于结束时间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isDateLargeEquals(LocalDateTime startTime, LocalDateTime endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) >= 0;
}
public static boolean isDateLargeEquals(LocalDateTime startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
try {
LocalDateTime date = DateFormatUtil.parse(endTime);
return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) >= 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
public static boolean isDateLargeEquals(String startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return false;
}
if (BeanUtils.isEmpty(endTime)) {
return true;
}
try {
LocalDateTime sdate = DateFormatUtil.parse(startTime);
LocalDateTime date = DateFormatUtil.parse(endTime);
return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) >= 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
/**
* 开始时间是否小于结束时间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isDateLittle(LocalDateTime startTime, LocalDateTime endTime) {
if (BeanUtils.isEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) < 0;
}
public static boolean isDateLittle(LocalDateTime startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
try {
LocalDateTime date = DateFormatUtil.parse(endTime);
return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
public static boolean isDateLittle(String startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
try {
LocalDateTime sdate = DateFormatUtil.parse(startTime);
LocalDateTime edate = DateFormatUtil.parse(endTime);
return sdate.toEpochSecond(ZoneOffset.of("+8")) - edate.toEpochSecond(ZoneOffset.of("+8")) < 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
/**
* 开始时间是否小于等于结束时间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isDateLittleEquals(LocalDateTime startTime, LocalDateTime endTime) {
if (BeanUtils.isEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) <= 0;
}
public static boolean isDateLittleEquals(LocalDateTime startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
try {
LocalDateTime date = DateFormatUtil.parse(endTime);
return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) <= 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
public static boolean isDateLittleEquals(String startTime, String endTime) {
if (BeanUtils.isEmpty(startTime)) {
return true;
}
if (BeanUtils.isEmpty(endTime)) {
return false;
}
try {
LocalDateTime sdate = DateFormatUtil.parse(startTime);
LocalDateTime edate = DateFormatUtil.parse(endTime);
return sdate.toEpochSecond(ZoneOffset.of("+8")) - edate.toEpochSecond(ZoneOffset.of("+8")) <= 0;
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
/**
* 开始时间是否等于结束时间
*
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isDateEquals(LocalDateTime startTime, LocalDateTime endTime) {
if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) {
return true;
}
if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) {
return startTime.toEpochSecond(ZoneOffset.of("+8")) - endTime.toEpochSecond(ZoneOffset.of("+8")) == 0;
}
return false;
}
public static boolean isDateEquals(LocalDateTime startTime, String endTime) {
if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) {
return true;
}
if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) {
try {
LocalDateTime date = DateFormatUtil.parse(endTime);
return startTime.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0;
} catch (ParseException e) {
e.printStackTrace();
}
}
return false;
}
public static boolean isDateEquals(String startTime, String endTime) {
if (BeanUtils.isEmpty(startTime) && BeanUtils.isEmpty(endTime)) {
return true;
}
if (BeanUtils.isNotEmpty(startTime) && BeanUtils.isNotEmpty(endTime)) {
try {
LocalDateTime sdate = DateFormatUtil.parse(startTime);
LocalDateTime date = DateFormatUtil.parse(endTime);
return sdate.toEpochSecond(ZoneOffset.of("+8")) - date.toEpochSecond(ZoneOffset.of("+8")) < 0;
} catch (ParseException e) {
e.printStackTrace();
}
}
return false;
}
/**
* 日期时间是否属于范围内
*
* @param time 需要比较的时间
* @param boundary 范围,两个时间逗号隔开:如 2020-05-06 00:00:00,2020-06-25 01:01:01
* @return
*/
public static boolean isDateBelongTo(String time, String boundary) {
if (BeanUtils.isEmpty(time) || BeanUtils.isEmpty(boundary)) {
return false;
}
try {
LocalDateTime date = DateFormatUtil.parse(time);
String[] boundaryArr = boundary.split(",");
if (boundaryArr.length != 2) {
return false;
}
LocalDateTime sdate = DateFormatUtil.parse(boundaryArr[0]);
LocalDateTime edate = DateFormatUtil.parse(boundaryArr[1]);
return date.toEpochSecond(ZoneOffset.of("+8")) >= sdate.toEpochSecond(ZoneOffset.of("+8"))
&& date.toEpochSecond(ZoneOffset.of("+8")) <= edate.toEpochSecond(ZoneOffset.of("+8"));
} catch (ParseException e) {
e.printStackTrace();
}
return false;
}
public void testStart(String instid) throws Exception {
StartFlowParamObject startFlowParamObject = new StartFlowParamObject();
startFlowParamObject.setFlowKey("csjdlc");
startFlowParamObject.setAccount("admin");
ContextThreadUtil.clearTaskMap();
ContextThreadUtil.cleanCommuVars();
ContextUtil.clearAll();
CompletableFuture<StartResult> start = iProcessService.start(startFlowParamObject);
System.out.println(start.get().getState());
}
public void startNewWithCurFlowData(String startUsers, String newFlowKey) throws Exception {
if (StringUtil.isEmpty(startUsers)) {
return;
}
List<IUser> users = userServiceImpl.getUserByAccounts(startUsers);
if (BeanUtils.isEmpty(users)) {
return;
}
ActionCmd actionCmd = getActionCmd();
StartFlowParamObject startFlowParamObject = new StartFlowParamObject();
startFlowParamObject.setFlowKey(newFlowKey);
startFlowParamObject.setData(Base64.getBase64(actionCmd.getBusData()));
ExecutorService executorService = Executors.newCachedThreadPool();
for (IUser iUser : users) {
executorService.execute(() -> {
try {
ContextUtil.setCurrentUser(iUser);
baseContext.setTempTenantId(iUser.getTenantId());
startFlowParamObject.setAccount(iUser.getAccount());
iProcessService.start(startFlowParamObject);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
/**
* 数字是否属于范围内
*
* @param num 需要比较的数字
* @param boundary 范围,两个时间逗号隔开:如 0,100
* @return
*/
public static boolean isNumberBelongTo(Integer num, String boundary) {
if (BeanUtils.isEmpty(num) || BeanUtils.isEmpty(boundary)) {
return false;
}
String[] boundaryArr = boundary.split(",");
if (boundaryArr.length != 2) {
return false;
}
Integer start = Integer.valueOf(boundaryArr[0]);
Integer end = Integer.valueOf(boundaryArr[1]);
return start <= num && num <= end;
}
/**
* 字符串是否属于数组集合内
*
* @param target 需要比较的字符串
* @param boundary 英文逗号隔开的字符串数组:如 aaa,bbb,ccc
* @return
*/
public static boolean isStringBelongTo(String target, String boundary) {
if (BeanUtils.isEmpty(target) || BeanUtils.isEmpty(boundary)) {
return false;
}
String[] boundaryArr = boundary.split(",");
if (boundaryArr.length <= 0) {
return false;
}
List<String> list = Arrays.asList(boundaryArr);
return list.contains(target);
}
/**
* demo脚本,根据所传账号查询用户,使用用户名更新表单字段
*
* @param account
* @param attrName
* @param formPath
* @throws Exception
*/
public void updateFormData(String account, String bodefName, String fileName) throws Exception {
if (StringUtil.isNotEmpty(account) && StringUtil.isNotEmpty(bodefName) && StringUtil.isNotEmpty(fileName)) {
ObjectNode header = JsonUtil.getMapper().createObjectNode();
String token = "admin:" + EncryptUtil.encrypt("feignCallEncry");
header.put("Authorization", "Basic " + Base64.getBase64(token));
String string = FluentUtil.get(
"http://ip:port/api/user/v1/user/getUser?userNumber" + "" + "&account="
+ account,
Base64.getBase64(JsonUtil.toJson(header)));
if (BeanUtils.isNotEmpty(string)) {
ObjectNode jsonNode = (ObjectNode) JsonUtil.toJsonNode(string);
String userName = jsonNode.get("fullname").asText();
updateMainField(bodefName, fileName, userName);
}
}
}
/**
* @param account
* @param checkValue
* @param destination
* @throws Exception
*/
public void getDataAndCheckBack(BpmDelegateTask delegateTask, String account, String checkValue, String skipNode)
throws Exception {
if (StringUtil.isNotEmpty(account) && StringUtil.isNotEmpty(checkValue)) {
ObjectNode header = JsonUtil.getMapper().createObjectNode();
String token = "admin:" + EncryptUtil.encrypt("feignCallEncry");
header.put("Authorization", "Basic " + Base64.getBase64(token));
String string = FluentUtil.get(
"http://ip:port/api/user/v1/user/getUser?userNumber" + "" + "&account="
+ account,
Base64.getBase64(JsonUtil.toJson(header)));
if (BeanUtils.isNotEmpty(string)) {
ObjectNode jsonNode = (ObjectNode) JsonUtil.toJsonNode(string);
String userName = jsonNode.get("fullname").asText();
if (userName.equals(checkValue)) {
ExecutorService executorService = Executors.newCachedThreadPool();
executorService.execute(() -> {
try {
IUser userByAccount = userServiceImpl.getUserByAccount("admin");
Thread.sleep(2000);
ContextUtil.setCurrentUser(userByAccount);
baseContext.setTempTenantId(userByAccount.getTenantId());
DefaultTaskFinishCmd cmd = new DefaultTaskFinishCmd();
ContextThreadUtil.setActionCmd(cmd);
cmd.setTaskId(delegateTask.getId());
if (StringUtil.isEmpty(skipNode)) {
cmd.addTransitVars(BpmConstants.SKIP_NODE, "UserTask4");
} else {
cmd.addTransitVars(BpmConstants.SKIP_NODE, skipNode);
}
cmd.setActionName("agree");
BpmTaskActionService bpmTaskActionService = AppUtil.getBean(BpmTaskActionService.class);
bpmTaskActionService.finishTask(cmd);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
}
}
/**
* 获取当前年份
*
* @return 年份
*/
public String getCurrentYear() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy");
return LocalDateTime.now().format(formatter);
}
/**
* 获取当前月份
*
* @return 月份
*/
public String getCurrentMonth() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM");
return LocalDateTime.now().format(formatter);
}
/**
* 获取当前用户填制单位id
*
* @return
* @throws Exception
*/
public String getFillOrgId(String demId) throws Exception {
String orgId = "";
CommonResult<Object> result = uCFeignService.getFillOrg(demId, "");
if (result.getState()) {
JsonNode orgNode = (JsonNode) result.getValue();
if (orgNode.has("id")) {
orgId = orgNode.get("id").asText();
}
}
if (StringUtil.isEmpty(orgId)) {
throw new RuntimeException("获取当前填制单位失败!");
}
return orgId;
}
/**
* 获取当前用户填制单位
*
* @return
* @throws Exception
*/
public Map<String, String> getFillOrg(String demId) throws Exception {
CommonResult<Object> result = uCFeignService.getFillOrg(demId, "");
Map<String, String> org = null;
if (result.getState()) {
JsonNode orgNode = (JsonNode) result.getValue();
if (orgNode.has("id")) {
org = new HashMap<String, String>();
org.put("id", orgNode.get("id").asText());
org.put("code", orgNode.get("code").asText());
org.put("name", orgNode.get("name").asText());
}
}
if (BeanUtils.isEmpty(org)) {
throw new RuntimeException("获取当前填制单位失败!");
}
return org;
}
/**
* 获取当前用户主岗位内容
*
* @return
*/
public String getMainPostName(String fileName) {
ObjectNode orgRels = getMainPost();
if (BeanUtils.isNotEmpty(orgRels) && orgRels.has(fileName)) {
return orgRels.get(fileName).asText();
}
return "";
}
/**
* 获取当前用户主岗位名称
*/
public String getCurrentMainPostName() {
return getMainPostName("name");
}
/**
* 获取当前用户主岗位ID
*/
public String getCurrentMainPostId() {
return getMainPostName("id");
}
/**
* 获取当前用户主岗位编码
*/
public String getCurrentMainPostCode() {
return getMainPostName("code");
}
private ObjectNode getMainPost() {
List<ObjectNode> orgRels = uCFeignService.getPosListByAccount(ContextUtil.getCurrentUser().getAccount());
ObjectNode orgRel = null;
if (BeanUtils.isNotEmpty(orgRels)) {
for (ObjectNode post : orgRels) {
if (1 == (post.get("isMaster").asInt())) {
orgRel = post;
break;
}
}
if (orgRels.size() == 1 && BeanUtils.isEmpty(orgRel)) {
orgRel = orgRels.get(0);
}
}
return orgRel;
}
public String getString(Object object) {
if (BeanUtils.isNotEmpty(object)) {
if (object instanceof LocalDateTime) {
return DateFormatUtil.formaDatetTime((LocalDateTime) object);
}
return object.toString();
}
return "";
}
public IUser getUser(String userId) throws IOException {
return userServiceImpl.getUserById(userId);
}
public List<Map<String, Object>> querySql(String datasourceAlias, String sql) {
List<Map<String, Object>> maps = databaseContext.switchDS(datasourceAlias, () -> commonManager.query(sql), e -> {
throw new BaseException(e.getMessage());
});
return maps;
}
public void executeSql(String datasourceAlias, String sql) {
databaseContext.switchDS(datasourceAlias, () -> commonManager.execute(sql), e -> {
throw new BaseException(e.getMessage());
});
}
public String executeSql(String sql) {
if (StringUtil.isEmpty(sql)) {
throw new BaseException("sql不能为空");
}
JdbcTemplate jdbcTemplate = (JdbcTemplate) AppUtil.getBean("jdbcTemplate");
if (sql.contains("<#id#>")) {
try {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
if (BeanUtils.isNotEmpty(cmd) && StringUtil.isNotEmpty(cmd.getInstId())) {
JsonNode node = JsonUtil.toJsonNode(cmd.getBusData());
if (node.fields().hasNext()) {
JsonNode boData = node.fields().next().getValue();
if (BeanUtils.isNotEmpty(boData) && BeanUtils.isNotEmpty(boData.get("id_"))) {
sql = sql.replace("<#id#>", boData.get("id_").asText());
}
}
}
} catch (Exception e) {
throw new BaseException("表单数据获取失败");
}
}
try {
if (StringUtil.isEmpty(sql))
return "";
if (isProcedure(sql)) {
//执行存储过程
executeSqlForUpdate(sql, jdbcTemplate);
return "";
} else {
sql = sql.replaceAll("''", "'");
List<String> list = jdbcTemplate.queryForList(sql, String.class);
if (list != null && list.size() > 0) {
return list.get(0);
} else {
return "";
}
}
} catch (Exception e) {
//e.printStackTrace();
//return "请检查sql 语句是否正确";
throw new BaseException("请检查sql语句是否正确");
}
}
/**
* 判断是否是执行存储过程
*/
private boolean isProcedure(String sql) {
sql = sql.trim().replace("\'", "");
if (StringUtil.isEmpty(sql)) {
return false;
}
sql = sql.toUpperCase();
return sql.startsWith("CALL") || sql.startsWith("BEGIN");
}
/**
* 执行存储过程
*/
private void executeSqlForUpdate(String sql, JdbcTemplate jdbcTemplate) {
jdbcTemplate.setQueryTimeout(30);
jdbcTemplate.execute(sql);
}
/**
* 判断当前用户是否有该角色
*/
public boolean isCurrentInRole(String roleAlias) {
return isUserInRole(ContextUtil.getCurrentUser().getAccount(), roleAlias);
}
/**
* 根据别名执行服务
*
* @param data
*/
public void executeServiceJob(String data) throws Exception {
if (StringUtil.isNotEmpty(data)) {
ActionCmd cmd = ContextThreadUtil.getActionCmd();
Map<String, Object> vars = cmd.getVariables();
String instId = cmd.getInstId();
DefaultBpmProcessInstance instance = bpmProcessInstanceManager.get(instId);
if (BeanUtils.isNotEmpty(instance)) {
List<ObjectNode> oldBoDatas = boDataService.getDataByInst(instance);
if (BeanUtils.isEmpty(oldBoDatas)) {
throw new RuntimeException(String.format("根据实例id:%s未查找到表单数据", instId));
}
BpmDelegateTask delegateTask = null;
DefaultBpmTask bpmTask = null;
if (BeanUtils.isNotEmpty(cmd.getTransitVars(BpmConstants.BPM_TASK))) {
bpmTask = (DefaultBpmTask) cmd.getTransitVars(BpmConstants.BPM_TASK);
if (BeanUtils.isNotEmpty(bpmTask)) {
//流程引擎任务
if (StringUtil.isNotZeroEmpty(bpmTask.getTaskId())) {
delegateTask = natTaskService.getByTaskId(bpmTask.getTaskId());
}
}
}
ObjectNode jsonObject = BoDataUtil.hanlerData(instance, "", oldBoDatas);
JsonNode jsonNode = JsonUtil.toJsonNode(data);
if (jsonNode.isArray()) {
ArrayNode excutorAry = (ArrayNode) jsonNode;
for (JsonNode item : excutorAry) {
Boolean isSuccess = true;
try {
//别名
String alias = item.get("alias").asText();
ArrayNode inputAry = (ArrayNode) item.get("inputs");
for (JsonNode input : inputAry) {
ObjectNode objectNode = (ObjectNode) input;
if (BeanUtils.isNotEmpty(objectNode.get("value"))) {
String value = objectNode.get("value").asText();
if (value.contains(".")) {
//表单变量
String[] obj = value.split("\\.");
if (obj.length > 0) {
String defCode = obj[0];
String field = obj[1];
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String objKey = next.getKey();
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (objKey.equals(defCode) && BeanUtils.isNotEmpty(ywdxObj)) {
if (BeanUtils.isNotEmpty(ywdxObj.get(field))) {
objectNode.set("value", ywdxObj.get(field));
}
}
}
}
} else {
if (BeanUtils.isNotEmpty(vars.get(value))) {
objectNode.set("value", JsonUtil.toJsonNode(vars.get(value)));
}
}
}
}
//调用接口
String paramData = JsonUtil.toJsonString(inputAry);
String type = item.get("type").asText();
Object result = null;
if ("interface".equals(type)) {
//接口管理
result = portalFeignService.executeIntefaceJob(alias, null, null, paramData);
} else if ("service".equals(type)) {
//服务编排
result = portalFeignService.executeServiceJob(alias, paramData);
}
if (BeanUtils.isNotEmpty(result)) {
JsonNode resultNode = JsonUtil.toJsonNode(result);
ArrayNode outputAry = (ArrayNode) item.get("outputs");
for (JsonNode output : outputAry) {
String key = output.get("key").asText();
if (BeanUtils.isNotEmpty(output.get("value"))) {
Object keyData = null;
if (resultNode.isArray()) {
ArrayNode resultAry = (ArrayNode) resultNode;
for (JsonNode execute : resultAry) {
if (BeanUtils.isNotEmpty(execute.get(key))) {
keyData = execute.get(key);
break;
}
}
} else {
if (BeanUtils.isNotEmpty(resultNode.get(key))) {
keyData = resultNode.get(key);
}
}
String value = output.get("value").asText();
if (value.contains(".")) {
//表单变量
String[] obj = value.split("\\.");
if (obj.length > 0) {
String defCode = obj[0];
String field = obj[1];
Iterator<Entry<String, JsonNode>> iterator = jsonObject.fields();
while (iterator.hasNext()) {
Entry<String, JsonNode> next = iterator.next();
String objKey = next.getKey();
ObjectNode ywdxObj = (ObjectNode) next.getValue();
if (objKey.equals(defCode) && BeanUtils.isNotEmpty(ywdxObj)) {
if (BeanUtils.isNotEmpty(ywdxObj.get(field))) {
if (BeanUtils.isNotEmpty(keyData)) {
ywdxObj.set(field, JsonUtil.toJsonNode(keyData));
}
}
}
}
}
} else {
//流程变量
if (vars.containsKey(value) && BeanUtils.isNotEmpty(keyData)) {
if (BeanUtils.isNotEmpty(delegateTask)) {
delegateTask.setVariable(value, JsonUtil.toJsonNode(keyData));
}
}
}
}
}
//更新表单数据
BusDataUtil.updateBoData(instance, "", JsonUtil.toJson(jsonObject));
cmd.setBusData(JsonUtil.toJson(jsonObject));
buildServiceLog(isSuccess, item, instance, bpmTask, JsonUtil.toJsonString(result));
} else {
//保存调用日志
isSuccess = false;
buildServiceLog(isSuccess, item, instance, bpmTask, null);
}
} catch (Exception e) {
//保存调用日志
isSuccess = false;
String response = ExceptionUtils.getRootCauseMessage(e);
buildServiceLog(isSuccess, item, instance, bpmTask, response);
}
}
}
} else {
//没有获取到流程实例id,代表流程已经启动但是表单节点的数据还没有保存到实例表和表单数据表中,此时可以操作cmd修改开始节点下一个节点的数据
JsonNode jsonNode = JsonUtil.toJsonNode(data);
if (jsonNode.isArray()) {
ArrayNode excutorAry = (ArrayNode) jsonNode;
for (JsonNode item : excutorAry) {
Boolean isSuccess = true;
try {
//别名
String alias = item.get("alias").asText();
ArrayNode inputAry = (ArrayNode) item.get("inputs");
JsonNode busDataNode = JsonUtil.toJsonNode(cmd.getBusData());
for (JsonNode input : inputAry) {
ObjectNode objectNode = (ObjectNode) input;
if (BeanUtils.isNotEmpty(objectNode.get("value"))) {
String value = objectNode.get("value").asText();
if (value.contains(".")) {
//表单变量
String[] obj = value.split("\\.");
if (obj.length > 0) {
String defCode = obj[0];
String field = obj[1];
objectNode.set("value", busDataNode.get(defCode).get(field));
}
} else {
if (BeanUtils.isNotEmpty(vars.get(value))) {
objectNode.set("value", JsonUtil.toJsonNode(vars.get(value)));
}
}
}
}
//调用接口
String paramData = JsonUtil.toJsonString(inputAry);
String type = item.get("type").asText();
Object result = null;
if ("interface".equals(type)) {
//接口管理
result = portalFeignService.executeIntefaceJob(alias, null, null, paramData);
} else if ("service".equals(type)) {
//服务编排
result = portalFeignService.executeServiceJob(alias, paramData);
}
if (BeanUtils.isNotEmpty(result)) {
JsonNode resultNode = JsonUtil.toJsonNode(result);
ArrayNode outputAry = (ArrayNode) item.get("outputs");
for (JsonNode output : outputAry) {
String key = output.get("key").asText();
if (BeanUtils.isNotEmpty(output.get("value"))) {
Object keyData = null;
if (resultNode.isArray()) {
ArrayNode resultAry = (ArrayNode) resultNode;
for (JsonNode execute : resultAry) {
if (BeanUtils.isNotEmpty(execute.get(key))) {
keyData = execute.get(key);
break;
}
}
} else {
if (BeanUtils.isNotEmpty(resultNode.get(key))) {
keyData = resultNode.get(key);
}
}
String value = output.get("value").asText();
if (value.contains(".")) {
//表单变量
String[] obj = value.split("\\.");
if (obj.length > 0) {
String defCode = obj[0];
String field = obj[1];
ObjectNode node = (ObjectNode) busDataNode.get(defCode);
node.set(field, JsonUtil.toJsonNode(keyData));
}
} else {
//流程变量
if (vars.containsKey(value) && BeanUtils.isNotEmpty(keyData)) {
if (BeanUtils.isNotEmpty(vars)) {
vars.put(value, JsonUtil.toJsonNode(keyData));
}
}
}
}
}
//更新表单数据
cmd.setBusData(JsonUtil.toJson(busDataNode));
} else {
//保存调用日志
isSuccess = false;
buildServiceLog(isSuccess, item, instance, null, null);
}
} catch (Exception e) {
//保存调用日志
isSuccess = false;
String response = ExceptionUtils.getRootCauseMessage(e);
buildServiceLog(isSuccess, item, instance, null, response);
}
}
}
}
}
}
/**
* 保存调用日志
*
* @param isSuccess
* @param item
* @param instance
* @param bpmTask
* @param response
*/
private void buildServiceLog(Boolean isSuccess, JsonNode item, DefaultBpmProcessInstance instance, DefaultBpmTask bpmTask, String response) throws Exception {
IUser user = ContextUtil.getCurrentUser();
String alias = item.get("alias").asText();
String type = item.get("type").asText();
//构建日志参数
ObjectNode objectNode = JsonUtil.getMapper().createObjectNode();
objectNode.put("isSuccess", isSuccess ? "1" : "0");
objectNode.put("alias", alias);
objectNode.put("type", type);
if (instance != null) {
objectNode.put("subject", instance.getSubject());
objectNode.put("procDefId", instance.getProcDefId());
objectNode.put("procDefKey", instance.getProcDefKey());
objectNode.put("procInstId", instance.getId());
//流程定义
DefaultBpmDefinition bpmDefinition = bpmDefinitionManager.getById(instance.getProcDefId());
if (BeanUtils.isNotEmpty(bpmDefinition)) {
objectNode.put("procDefName", bpmDefinition.getName());
}
}
//任务相关参数
if (BeanUtils.isNotEmpty(bpmTask)) {
objectNode.put("taskId", bpmTask.getId());
objectNode.put("nodeId", bpmTask.getNodeId());
}
//调用人
objectNode.put("userId", user.getUserId());
objectNode.put("userAccount", user.getAccount());
objectNode.put("userName", user.getFullname());
//调用时间
objectNode.putPOJO("callTime", DateUtil.getCurrentDate());
//调用结果
objectNode.put("response", response);
portalFeignService.saveServiceLog(objectNode);
}
@Cacheable(value = CacheKeyConst.EIP_UC_CURRENT_USER_GROUP_ID, key = "#userId", firstCache = @FirstCache(expireTime = 100, timeUnit = TimeUnit.DAYS))
public String getCurrentGroupIdFromCache(String userId) {
return null;
}
/**
* 判断子表中某一行满足某个条件, 默认为false
*/
public boolean subFieldContain(JsonNode subArray, String field, String op, Object value, String dataType) {
return SubCalcUtils.subFieldContain(subArray, field, op, value, dataType);
}
/**
* 判断子表中是否存在某一行不满足条件的
*/
public boolean subFieldNotContain(JsonNode subArray, String field, String op, Object value, String dateType) {
return SubCalcUtils.subFieldNotContain(subArray, field, op, value, dateType);
}
/**
* 转换数据拼接sql
*
* @return
* @throws Exception
*/
public String getSql(String names) throws Exception {
StringBuilder sb = new StringBuilder("(");
if (StringUtils.isNotBlank(names)) {
String[] split = names.split(",");
for (int i = 0; i < split.length; i++) {
String s = split[i];
sb.append("'").append(s).append("'");
if (i != split.length - 1) {
sb.append(",");
}
}
sb.append(")");
return sb.toString();
}
return "";
}
//获取指定用户当前所属组织
public ArrayList<String> getCurrentOrg(String account){
ArrayList<String> orgIds = new ArrayList<String>();
ObjectNode listOrgs = uCFeignService.getUserParamByCode(account, UserParamsEnums.dqzz.getCode());
if (BeanUtils.isNotEmpty(listOrgs)) {
orgIds.add(listOrgs.get("value").asText());
}
return orgIds;
}
//当前登陆用户的ID
private static final String LOGIN_USER = "loginUser";
//当前登陆用户所属组织的ID
private static final String LOGIN_USER_ORGS = "loginUserOrgs";
//当前登陆用户所属组织及下属组织的ID
private static final String LOGIN_USER_SUB_ORGS = "loginUserSubOrgs";
//当前登陆用户所属组织及所有下属组织的ID
private static final String LOGIN_USER_ALL_SUB_ORGS = "loginUserAllSubOrgs";
//当前登录用户所在组织 所有上下 组织id
private static final String LOGIN_USER_ALL_ORGS = "loginUserAllOrgs";
//当前登陆用户 当前所在组织
private static final String LOGIN_USER_CURORGS = "loginUserCurOrgs";
//当前登陆用户 当前所在组织及下属组织的ID
private static final String LOGIN_USER_SUB_CURORGS = "loginUserSubCurOrgs";
public ArrayList<String> getDataPermission(String type) {
ArrayList<String> orgIds = new ArrayList<String>();
IUser currentUser = ContextUtil.getCurrentUser();
if (BeanUtils.isNotEmpty(type)) {
if (LOGIN_USER.equals(type)) {
orgIds.add(currentUser.getUserId());
} else if (LOGIN_USER_ORGS.equals(type)) {
String currentUserOrgIds = currentUser.getAttrbuite("CURRENT_USER_ORGIDS");
if (StringUtil.isNotEmpty(currentUserOrgIds)) {
String[] oids = currentUserOrgIds.split(",");
Set<String> oidSet = new HashSet<String>(Arrays.asList(oids));
orgIds.addAll(oidSet);
}
} else if (LOGIN_USER_SUB_ORGS.equals(type)) {
String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : "";
String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : "";
currentUserSubOrgIds += "," + currentUserOrgIds;
String[] oids = new String[]{};
if (StringUtil.isNotEmpty(currentUserSubOrgIds)) {
oids = currentUserSubOrgIds.split(",");
}
if (oids.length == 0) {
oids = new String[]{"-1"};
}
Set<String> oidSet = new HashSet<String>(Arrays.asList(oids));
orgIds.addAll(oidSet);
} else if (LOGIN_USER_ALL_SUB_ORGS.equals(type)) {
String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : "";
String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : "";
currentUserSubOrgIds += "," + currentUserOrgIds;
String[] oids = new String[]{};
if (StringUtil.isNotEmpty(currentUserSubOrgIds)) {
oids = currentUserSubOrgIds.split(",");
}
if (oids.length == 0) {
oids = new String[]{"-1"};
}
Set<String> oidSet = new HashSet<>(Arrays.asList(oids));
orgIds.addAll(oidSet);
} else if (LOGIN_USER_ALL_ORGS.equals(type)) {
ArrayNode department = uCFeignService.getOrgListByUserId(getCurrentUserId());
for (JsonNode node : department) {
//所有上级组织
ObjectNode dept = (ObjectNode) node;
String id = dept.get("id").asText();
String path = dept.get("path").asText();
String[] pathlist = path.split("\\.");
Set<String> oidSet1 = new HashSet<>(Arrays.asList(pathlist));
orgIds.addAll(oidSet1);
//所有下级组织
// String currentUserSubOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserSubOrgIds()) ? AuthenticationUtil.getCurrentUserSubOrgIds() : "";
// String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : "";
// currentUserSubOrgIds += "," + currentUserOrgIds;
// String[] oids = new String[]{};
// if (StringUtil.isNotEmpty(currentUserSubOrgIds)) {
// oids = currentUserSubOrgIds.split(",");
// }
// if (oids.length == 0) {
// oids = new String[]{"-1"};
// }
// Set<String> oidSet = new HashSet<>(Arrays.asList(oids));
Set<String> oidSet = new HashSet<>();
List<ObjectNode> orgsByparentId = uCFeignService.getChildOrg(id);//从数据库取下属组织数据,解决缓存中的组织不全问题
if (ObjectUtil.isNotEmpty(orgsByparentId)) {
for (ObjectNode jsonNodes : orgsByparentId) {
oidSet.add(jsonNodes.get("id").asText());
}
}
String currentUserOrgIds = StringUtil.isNotEmpty(AuthenticationUtil.getCurrentUserOrgIds()) ? AuthenticationUtil.getCurrentUserOrgIds() : "";
if (ObjectUtil.isNotEmpty(currentUserOrgIds)) {
oidSet.add(currentUserOrgIds);
}
orgIds.addAll(oidSet);
}
} else if (LOGIN_USER_CURORGS.equals(type)) {
//当前登陆用户 当前所在组织
ObjectNode listOrgs = uCFeignService.getUserParamByCode(currentUser.getAccount(), UserParamsEnums.dqzz.getCode());
if (BeanUtils.isNotEmpty(listOrgs)) {
orgIds.add(listOrgs.get("value").asText());
}
}else if (LOGIN_USER_SUB_CURORGS.equals(type)){
ObjectNode listOrgs = uCFeignService.getUserParamByCode(currentUser.getAccount(), UserParamsEnums.dqzz.getCode());
if (BeanUtils.isNotEmpty(listOrgs)) {
orgIds.add(listOrgs.get("value").asText());
List<ObjectNode> value = uCFeignService.getChildOrg(listOrgs.get("value").asText());
if (BeanUtils.isNotEmpty(value)) {
for (ObjectNode org : value) {
orgIds.add(org.get("id").asText());
}
}
}
}
}
return orgIds;
}
}