ludc
2024-10-09 69f6865e4744094d657a538e9c013cb9d97df01a
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
package com.vci.web.service.impl;
 
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
import com.vci.corba.omd.btm.BTMServicePrx;
import com.vci.corba.omd.btm.BizType;
import com.vci.corba.omd.etm.EnumItem;
import com.vci.corba.omd.etm.EnumType;
import com.vci.corba.omd.lcm.Bound;
import com.vci.corba.omd.lcm.LifeCycle;
import com.vci.corba.omd.lcm.TransitionVO;
import com.vci.corba.omd.lcm.TransitionVOEvent;
import com.vci.corba.omd.ltm.LinkType;
import com.vci.corba.omd.stm.StatePool;
import com.vci.dto.*;
import com.vci.pagemodel.*;
import com.vci.starter.poi.bo.WriteExcelData;
import com.vci.starter.poi.bo.WriteExcelOption;
import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.annotation.VciBtmType;
import com.vci.starter.web.constant.FrameWorkLcStatusConstant;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.util.BeanUtil;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.VciDateUtil;
import com.vci.starter.word.bo.WordMergeStartTableDataBO;
import com.vci.starter.word.util.WordUtil;
import com.vci.web.properties.OsDDLExportWordFieldProperties;
import com.vci.web.service.*;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
 
import static com.vci.omd.constants.AttributeConstants.*;
 
 
/**
 * 对象建模等相关的内容导入
 * @author weidy
 * @date 2021/8/13
 */
@Service
public class WebBtmIOServiceImpl implements WebBtmIOServiceI {
 
    /**
     * 平台的调用客户端
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 生命周期的服务
     */
    @Autowired
    private OsLifeCycleServiceI lifeCycleService;
 
    /**
     * 状态的服务
     */
    @Autowired
    private OsStatusServiceI statusService;
 
    /**
     * 属性的服务
     */
    @Autowired
    private OsAttributeServiceI attrService;
 
    /**
     * 枚举的服务
     */
    @Autowired
    private OsEnumServiceI enumService;
 
    /**
     * 业务类型的服务
     */
    @Autowired
    private OsBtmServiceI btmService;
 
    /**
     * 链接服务
     */
    @Autowired
    private OsLinkTypeServiceI linkTypeService;
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 获取消息的前缀
     * @return 消息前缀
     */
    private String getMsgPrefix(){
        return getClass().getPackage().getName();
    }
 
 
    /**
     * 业务类型
     */
    private Map<String, LinkType> allLink = new ConcurrentHashMap<String, LinkType>();
 
    /**
     * word里的字段域配置
     */
    @Autowired
    private OsDDLExportWordFieldProperties wordFieldProperties;
 
    /**
     * 导入业务类型和链接类型,包含属性,枚举,状态,生命周期,版本规则等全套内容
     *
     * @param importBtmTypeDTO 需要导入的业务类型,链接类型等内容
     * @throws VciBaseException
     */
    @Override
    public void importBtmTypes(OsBtmTypeExportDTO importBtmTypeDTO) throws VciBaseException {
        VciBaseUtil.alertNotNull(importBtmTypeDTO, "要导入的业务类型等相关数据");
        String msgPrefix = getMsgPrefix();
        if(logger.isInfoEnabled()){
            logger.info("{}在{}调用了" + msgPrefix + ".importBtmTypes", WebUtil.getCurrentUserId(), VciDateUtil.getNow());
        }
        if(logger.isDebugEnabled()){
            logger.debug(importBtmTypeDTO.toString());
        }
        //因为ORACLE在DDL的时候就会提交一次事务,如果交给spring执行的话。可能抛出事务回滚异常
 
        //要调整的数据库表的内容
        try {
            if (CollectionUtils.isEmpty(importBtmTypeDTO.getAttributeDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getStatusDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getEnumDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getLifeCycleDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getRevisionRuleDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getBtmTypeDTOList())
                    && CollectionUtils.isEmpty(importBtmTypeDTO.getLinkTypeDTOList())) {
               logger.info("要导入的业务类型等相关数据为空");
               return ;
            }
            //先处理基础的,比如,状态,版本规则,枚举,枚举项
            //然后处理生命周期,业务类型,链接类型
            Collection<OsStatusDTO> statusDTOList = importBtmTypeDTO.getStatusDTOList();
            if (!CollectionUtils.isEmpty(statusDTOList)) {
                //说明有新的状态
                //我们需要先去查询已经存在的状态
                importStatus(statusDTOList);
            }
            //规则使用对象没办法声明出来
            Collection<OsLifeCycleDTO> lifeCycleDTOList = importBtmTypeDTO.getLifeCycleDTOList();
            if (!CollectionUtils.isEmpty(lifeCycleDTOList)) {
                //说明有生命周期状态
                importLifeCycles(lifeCycleDTOList);
            }
            Collection<OsAttributeDTO> attributeDTOList = importBtmTypeDTO.getAttributeDTOList();
            if (!CollectionUtils.isEmpty(attributeDTOList)) {
                //说明有属性需要导入
                importAttributes(attributeDTOList);
            }
            //因为老平台的地方的业务类型上面不需要枚举的主键,所以先处理枚举
            Collection<OsEnumDTO> enumDTOList = importBtmTypeDTO.getEnumDTOList();
            if (!CollectionUtils.isEmpty(enumDTOList)) {
                //说明有枚举需要导入
                importEnums(enumDTOList);
            }
            Collection<OsBtmTypeDTO> btmTypeDTOList = importBtmTypeDTO.getBtmTypeDTOList();
            if (!CollectionUtils.isEmpty(btmTypeDTOList)) {
                //说明有业务类型需要导入
 
                importBtmType(btmTypeDTOList);
            }
            Collection<OsLinkTypeDTO> linkTypeDTOList = importBtmTypeDTO.getLinkTypeDTOList();
            if(!CollectionUtils.isEmpty(linkTypeDTOList)){
                importLinkType(linkTypeDTOList);
            }
        }catch (Throwable e){
            if(logger.isErrorEnabled()){
                logger.error("导入业务类型相关数据错误",e);
            }
            throw new VciBaseException(e.getMessage(),new String[0],e);
        }
    }
 
    /**
     * 导入状态
     * @param statusDTOList 要导入的状态的数据传输对象列表
     * @throws VciBaseException 查询或者执行出错的时候会抛出异常
     */
    private void importStatus( Collection<OsStatusDTO> statusDTOList) throws Exception {
        //要导入的状态的所有英文名称
        List<String> statusIdList = new ArrayList<String>();
        Iterator<OsStatusDTO> iterator = statusDTOList.iterator();
        while(iterator.hasNext()){
            statusIdList.add(iterator.next().getId().toLowerCase());
        }
        Set<String> existStatusIdList = statusService.selectAllStatusMap().keySet();
        Set<String> statusNameSet = statusService.selectAllStatusMap().values().stream().map(OsStatusVO::getName).collect(Collectors.toSet());
        //这个地方的状态不是小写的,但是平台又区分小写
        List<String> existStatusLowIdList = existStatusIdList.stream().map(s->s.toLowerCase(Locale.ROOT).trim()).collect(Collectors.toList());
        //不存在状态对象(意思需要添加)
        List<StatePool> unExistStatusDTOList = new ArrayList<StatePool>();
        for(OsStatusDTO statusDTO: statusDTOList){
            String statusId = statusDTO.getId().toLowerCase().trim();
            StatePool statePool = null;
            if(!existStatusLowIdList.contains(statusId)){
                statusDTO.setOid(VciBaseUtil.getPk());
                statePool = statusService.statusDTO2DO(statusDTO);
                unExistStatusDTOList.add(statePool);
               logger.info("要添加的状态{}",statusId);
               //要看名字是不是也重复了
                if(statusNameSet.contains(statusDTO.getName())){
                    throw new VciBaseException("平台要求状态池的中文标签不能重复,平台中已经存在了中文标签为{0}的状态,但是英文名称确不是{1}",new String[]{statusDTO.getName(),statusDTO.getId()});
                }
            }else{
               //名称都不改
            }
        }
        //执行添加
        if(!CollectionUtils.isEmpty(unExistStatusDTOList)){
            statusService.batchAddStatus(unExistStatusDTOList);
        }
        statusService.clearCache();;
        statusService.selectAllStatus();
    }
 
    /**
     * 导入生命周期
     * @param lifeCycleDTOList 要导入的生命周期数据传输对象列表
     * @throws VciBaseException 查询或者保存出错的时候,会抛出异常
     */
    private void importLifeCycles(Collection<OsLifeCycleDTO> lifeCycleDTOList) throws VciBaseException, PLException {
        Set<String> existLifeCycleIds = lifeCycleService.selectAllLifeCycleMap().keySet();
        //生命周期的名称没有转为小写,但是平台又区分大小写
        List<String> existLifeCycleLowIds = existLifeCycleIds.stream().map(s->s.toLowerCase(Locale.ROOT)).collect(Collectors.toList());
        Map<String, OsLifeCycleVO> allLifeCycleMap = lifeCycleService.selectAllLifeCycleMap();
        Map<String,OsLifeCycleVO> allLifeCycleLowMap = new HashMap<>();
        allLifeCycleMap.forEach((id,lifeCycleVO)->{
            allLifeCycleLowMap.put(id.toLowerCase(Locale.ROOT),lifeCycleVO);
        });
        //不存在的生命周期对象
        List<LifeCycle> unExistLifeCycleList = new ArrayList<LifeCycle>();
        List<LifeCycle> editLifeCycleList = new ArrayList<LifeCycle>();
        String userId = WebUtil.getCurrentUserId();
        long now = VciDateUtil.getNowTime();
        //循环分析需要添加还是修改
        for(OsLifeCycleDTO lifeCycleDTO : lifeCycleDTOList){
            String lifeCycleId = lifeCycleDTO.getId().toLowerCase().trim();
            LifeCycle lifeCyle = null;
            boolean edit = false;
            if(!existLifeCycleLowIds.contains(lifeCycleId)) {
                lifeCyle = new LifeCycle();
                lifeCyle.oid = "";
                lifeCyle.id = "";
                lifeCyle.creator = userId;
                lifeCyle.createTime = now;
                lifeCyle.ts = VciDateUtil.getNowString(VciDateUtil.DateTimeMillFormat);
                lifeCyle.name = lifeCycleDTO.getId();
            }else {
                lifeCyle = lifeCycleService.lifeCycleVO2DO(allLifeCycleLowMap.get(lifeCycleId));
                edit = true;
            }
            lifeCyle.tag = lifeCycleDTO.getName();
            lifeCyle.description = lifeCycleDTO.getDescription() == null?"":lifeCycleDTO.getDescription();
            lifeCyle.startState = lifeCycleDTO.getStartStatus() == null?"":lifeCycleDTO.getStartStatus();
            lifeCyle.modifier = userId;
            lifeCyle.modifyTime = now;
            //找区域
            List<OsLifeCycleLineDTO> lineDTOList = lifeCycleDTO.getLineDTOList();
            if(CollectionUtils.isEmpty(lineDTOList)){
                //如果是只有空的时候,说明可能只有一个状态
                lifeCyle.bounds = new Bound[0];
                lifeCyle.routes = new TransitionVO[0];
            }else{
                //先查询所有的状态
                List<String> hasStatusList = new ArrayList<String>();
                for(int i = 0 ; i < lineDTOList.size() ; i++){
                    OsLifeCycleLineDTO lineDTO = lineDTOList.get(i);
                    if(!hasStatusList.contains(lineDTO.getSourceLifeStatus())){
                        hasStatusList.add(lineDTO.getSourceLifeStatus());
                    }
                    if(!hasStatusList.contains(lineDTO.getTargetLifeStatus())){
                        hasStatusList.add(lineDTO.getTargetLifeStatus());
                    }
                }
                //我们每个状态的宽度100,高度50,然后是连接的间距100.
                //起始状态的左边间距为20,顶部间距为100
                List<Bound> boundList = new ArrayList<Bound>();
 
                int w = 1 ;
                for(int i = 0 ; i < hasStatusList.size() ; i++){
                    String status = hasStatusList.get(i);
                    Bound bound = new Bound();
                    bound.id="";
                    bound.name = status;
                    bound.cellw = "75.0";
                    bound.cellh = "50.0";
                    bound.cellx = String.valueOf(80+100*w);
                    bound.celly = String.valueOf(100 + 80*w);
                    w++;
                    boundList.add(bound);
                }
                lifeCyle.bounds = boundList.toArray(new Bound[0]);
                //找关系
                List<TransitionVO> lineList = new ArrayList<TransitionVO>();
                for(int i = 0 ; i < lineDTOList.size() ; i++) {
                    OsLifeCycleLineDTO lineDTO = lineDTOList.get(i);
                    TransitionVO line = new TransitionVO();
                    line.id = "";
                    line.source = lineDTO.getSourceLifeStatus();
                    line.destination = lineDTO.getTargetLifeStatus();
                    if(StringUtils.isNotBlank(lineDTO.getName())) {
                        line.connect = lineDTO.getName();
                    }else{
                        line.connect = "line" + i;
                    }
                    List<String> eventDTOList = lineDTO.getEventDTOList();
                    if(!CollectionUtils.isEmpty(eventDTOList)){
                        List<TransitionVOEvent> eventList = new ArrayList<TransitionVOEvent>();
                        for(String event:eventDTOList){
                            if(StringUtils.isNotBlank(event)) {
                                String id = event.contains(".") ? event.substring(event.lastIndexOf(".") + 1) : event;
                                TransitionVOEvent eventVO = new TransitionVOEvent();
                                eventVO.id = id;
                                eventVO.name = event;
                                eventList.add(eventVO);
                            }
                        }
                        line.transitionVOEvents = eventList.toArray(new TransitionVOEvent[0]);
                    }else{
                        line.transitionVOEvents = new TransitionVOEvent[0];
                    }
                    lineList.add(line);
                }
                lifeCyle.routes = lineList.toArray(new TransitionVO[0]);
            }
            if(edit){
                editLifeCycleList.add(lifeCyle);
            }else{
                unExistLifeCycleList.add(lifeCyle);
            }
        }
        //执行添加
        if(!CollectionUtils.isEmpty(unExistLifeCycleList)){
            lifeCycleService.batchAddLifeCycle(unExistLifeCycleList);
        }
        if(!CollectionUtils.isEmpty(editLifeCycleList)){
            lifeCycleService.batchEditLifeCycle(editLifeCycleList);
        }
        lifeCycleService.clearCache();
        lifeCycleService.selectAllLifeCycle();
    }
 
    /**
     * 导入属性
     * @param attributeDTOList 要导入的属性的数据显示对象
     */
    private void importAttributes(Collection<OsAttributeDTO> attributeDTOList) throws VciBaseException {
        Set<String> existAttributeList = attrService.selectAllAttributeMap().keySet();
        Map<String, OsAttributeVO> allAttributeMap = attrService.selectAllAttributeMap();
        List<AttributeDef> unExistAttrList = new ArrayList<AttributeDef>();
        List<AttributeDef> editAttrList = new ArrayList<AttributeDef>();
        String userId = WebUtil.getCurrentUserId();
        long now = VciDateUtil.getNowTime();
        //循环分析需要添加还是修改
        for (OsAttributeDTO attributeDTO : attributeDTOList) {
            String attrId = attributeDTO.getId().toLowerCase().trim();
            AttributeDef attribItem = null;
            boolean edit = false;
            if (!existAttributeList.contains(attrId)) {
                attribItem = new AttributeDef();
                attribItem.oid = "";
                attribItem.ts = VciDateUtil.getNowString(VciDateUtil.DateTimeMillFormat);
                attribItem.creator = userId;
                attribItem.createTime = now;
            }else {
                OsAttributeVO attributeVO = allAttributeMap.get(attrId);
                attribItem =new AttributeDef();
                attribItem.oid = attributeVO.getOid();
                attribItem.ts = VciDateUtil.date2Str(attributeVO.getTs(),VciDateUtil.DateTimeMillFormat);
                attribItem.creator = attributeVO.getCreator();
                attribItem.createTime = VciDateUtil.getTime(attributeVO.getCreateTime());
                edit = true;
            }
            attribItem.modifier = userId;
            attribItem.modifyTime = now;
            attribItem.name = attributeDTO.getId().toLowerCase();
            attribItem.label = attributeDTO.getName();
            attribItem.description = attributeDTO.getDescription() == null ? "" : attributeDTO.getDescription();
            attribItem.vtDataType = attributeDTO.getAttributeDataType() == null ? VciFieldTypeEnum.VTString.name() : attributeDTO.getAttributeDataType();
            attribItem.defValue = attributeDTO.getDefaultValue() == null?"":attributeDTO.getDefaultValue();
            attribItem.rage = attributeDTO.getRange() == null ? "" : attributeDTO.getRange();
            //other需要自行处理
            StringBuffer sb = new StringBuffer();
            sb.append(ALLOWNULL).append(" = ").append(attributeDTO.isNullableFlag() ? "yes" : "no").append(";");
            VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(attributeDTO.getAttributeDataType());
            String[] otherInfos = attribItem.other.split(";");
            int length = 0;
            if(otherInfos!=null&& otherInfos.length > 0){
                for(String s : otherInfos){
                    if(s.contains(LENGTH+" =") || s.contains(LENGTH+"=")){
                        length = VciBaseUtil.getInt(s.split("=")[1]);
                        break;
                    }
                }
            }
            switch (fieldTypeEnum) {
                case VTDouble:
                    sb.append(ACCURACY).append(" = ").append(attributeDTO.getPrecisionLength()).append(";");
                    if(edit){
                        sb.append(LENGTH).append(" = ").append(length > attributeDTO.getAttrLength()?length:attributeDTO.getAttrLength()).append(";");
                    }else {
                        sb.append(LENGTH).append(" = ").append(attributeDTO.getAttrLength()).append(";");
                    }
                    break;
                case VTInteger:
                    if (StringUtils.isNotBlank(attributeDTO.getEnumId())) {
                        sb.append(ENUMNAME).append(" = ").append(attributeDTO.getEnumId()).append(";");
                    }
                    break;
                case VTString:
                    if (StringUtils.isNotBlank(attributeDTO.getBtmTypeId())) {
                        //参照
                        sb.append(BTM).append(" = ").append(attributeDTO.getBtmTypeId()).append(";");
                        //链接类型暂时不支持
                    }
                    if(edit){
                        sb.append(LENGTH).append(" = ").append(length > attributeDTO.getAttrLength()?length:attributeDTO.getAttrLength()).append(";");
                    }else {
                        sb.append(LENGTH).append(" = ").append(attributeDTO.getAttrLength()).append(";");
                    }
                    if (StringUtils.isNotBlank(attributeDTO.getEnumId())) {
                        sb.append(ENUMNAME).append(" = ").append(attributeDTO.getEnumId()).append(";");
                    }
                    break;
                default:
                    //不需要处理
                    break;
            }
            attribItem.other = sb.toString();
            if (attribItem.other.endsWith(";")) {
                attribItem.other = attribItem.other.substring(0, attribItem.other.length() - 1);
            }
            if(edit){
                editAttrList.add(attribItem);
            }else {
                unExistAttrList.add(attribItem);
            }
        }
        if (!CollectionUtils.isEmpty(unExistAttrList)) {
            attrService.batchAddAttribute(unExistAttrList);
        }
        if(!CollectionUtils.isEmpty(editAttrList)){
            attrService.batchEditAttribute(editAttrList);
        }
        //刷新属性,因为后面需要
        attrService.clearCache();
        attrService.selectAllAttribute();
    }
 
    /**
     * 导入枚举
     * @param enumDTOList 要导入的枚举的数据传输对象列表
     * @throws VciBaseException 查询或执行出错的时候会抛出异常
     */
    private void importEnums(Collection<OsEnumDTO> enumDTOList) throws VciBaseException{
        Set<String> existEnumIdList = enumService.selectAllEnumMap().keySet();
        Map<String, OsEnumVO> allEnumMap = enumService.selectAllEnumMap();
        List<EnumType> unExistEnumList = new ArrayList<EnumType>();
        List<EnumType> editEnumList = new ArrayList<EnumType>();
 
        String userId = WebUtil.getCurrentUserId();
        String now = VciDateUtil.getNowString(VciDateUtil.DateTimeFormat);
        Long nowLong = System.currentTimeMillis();
        for(OsEnumDTO enumDTO : enumDTOList){
            String enumId = enumDTO.getId().toLowerCase().trim();
            if(!existEnumIdList.contains(enumId)){
                EnumType enumItem = new EnumType();
                enumItem.oid = "";
                enumItem.ts = now;
                enumItem.creator = userId;
                // enumItem.createTime = now;
                enumItem.createTime = nowLong;
                enumItem.modifier = userId;
                // enumItem.modifyTime = now;
                enumItem.modifyTime = nowLong;
                enumItem.name = enumDTO.getId();
                enumItem.label = enumDTO.getName();
                enumItem.type = "int".equalsIgnoreCase(enumDTO.getEnumValueDataType())?"Integer":"String";
                enumItem.length = enumDTO.getLength();
 
                List<EnumItem> childList = new ArrayList<EnumItem>();
                Map<String, String> itemMaps = enumDTO.getItemMaps();
                if(CollectionUtils.isEmpty(itemMaps)){
                    throw new VciBaseException("枚举{0}没有选项",new String[]{enumItem.name});
                }
                for(String key : itemMaps.keySet()){
                    String value = itemMaps.get(key);
                    EnumItem enumChild = new EnumItem();
                    enumChild.name = value;
                    enumChild.value = key;
                    enumChild.description = "";
                    childList.add(enumChild);
                }
                enumItem.items = childList.toArray(new EnumItem[0]);
                unExistEnumList.add(enumItem);
            }else{
                //修改内容
                EnumType enumItem = new EnumType();
                OsEnumVO enumVO = allEnumMap.get(enumId);
                enumItem.oid = enumVO.getOid();
                // enumItem.createTime = VciDateUtil.date2Str(enumVO.getCreateTime(),VciDateUtil.DateTimeFormat);
                enumItem.createTime = Func.toLong(enumVO.getCreateTime());
                enumItem.creator = enumVO.getCreator();
                enumItem.modifier = userId;
                // enumItem.modifyTime = now;
                enumItem.modifyTime = nowLong;
                enumItem.name = enumVO.getId();
                enumItem.ts =  VciDateUtil.date2Str(enumVO.getTs(),VciDateUtil.DateTimeMillFormat);
                enumItem.label = enumDTO.getName();
                enumItem.type = "int".equalsIgnoreCase(enumDTO.getEnumValueDataType())?"Integer":"String";
                enumItem.length = enumDTO.getLength();
 
                List<EnumItem> childList = new ArrayList<EnumItem>();
                Map<String, String> itemMaps = enumDTO.getItemMaps();
                if(CollectionUtils.isEmpty(itemMaps)){
                    throw new VciBaseException("枚举{0}没有选项",new String[]{enumItem.name});
                }
                for(String key : itemMaps.keySet()){
                    String value = itemMaps.get(key);
                    EnumItem enumChild = new EnumItem();
                    enumChild.name = value;
                    enumChild.value = key;
                    enumChild.description = "";
                    childList.add(enumChild);
                }
                enumItem.items = childList.toArray(new EnumItem[0]);
                editEnumList.add(enumItem);
            }
        }
        //执行添加
        if(!CollectionUtils.isEmpty(unExistEnumList)){
            enumService.batchAddEnum(unExistEnumList);
        }
        //执行修改
        if(!CollectionUtils.isEmpty(editEnumList)){
            enumService.batchEditEnum(editEnumList);
        }
        enumService.clearCache();
        enumService.selectAllEnum();
    }
 
    /**
     * 执行导入业务类型
     * @param btmTypeDTOList 需要导入的业务类型的数据传输对象列表
     */
    private void importBtmType(Collection<OsBtmTypeDTO> btmTypeDTOList) {
        //查询已经存在的业务类型
        Map<String, OsBtmTypeVO> allBtmMap = btmService.selectAllBtmMap();
        Set<String> exitBtmList = allBtmMap.keySet();
        List<BizType> unExistBtmList = new ArrayList<BizType>();
        List<BizType> editBtmList = new ArrayList<BizType>();
        String userId = WebUtil.getCurrentUserId();
        long now = VciDateUtil.getNowTime();
 
        for (OsBtmTypeDTO btmTypeDTO : btmTypeDTOList) {
            String btmId = btmTypeDTO.getId().toLowerCase().trim();
            if (!exitBtmList.contains(btmId)) {
                //老平台的内容中,实际不关心关联的数据是否真实存在,所以直接添加就行
                BizType btmItem = new BizType();
                btmItem.oid = "";
                btmItem.ts = now;
                btmItem.creator = userId;
                btmItem.createTime = now;
                btmItem.modifier = userId;
                btmItem.modifyTime = now;
                btmItem.name = btmTypeDTO.getId().toLowerCase();
                wrapperBtmItem(btmItem,btmTypeDTO);
                unExistBtmList.add(btmItem);
            } else {
                BizType btmItem = new BizType();
                OsBtmTypeVO btmTypeVO = allBtmMap.get(btmId);
                btmItem.name = btmTypeDTO.getId().toLowerCase();
                btmItem.oid = btmTypeVO.getOid();
                btmItem.creator = btmTypeVO.getCreator();
                btmItem.createTime = VciDateUtil.getTime(btmTypeVO.getCreateTime());
                //修改
                btmItem.modifier = userId;
                btmItem.modifyTime = now;
                btmItem.ts = VciDateUtil.getTime(btmTypeVO.getTs());
                wrapperBtmItem(btmItem,btmTypeDTO);
                editBtmList.add(btmItem);
            }
            if(logger.isInfoEnabled()){
                logger.info("业务类型[{}],对应的类路径是{}",btmId,btmTypeDTO.getClassFullName());
            }
        }
        batchAddBtm(unExistBtmList);
        batchEditBtm(editBtmList);
    }
 
    /**
     * 批量添加业务类型
     * @param btmItems 业务类型的对象
     */
    @Override
    public void batchAddBtm(Collection<BizType> btmItems){
        if(!CollectionUtils.isEmpty(btmItems)){
            Map<String, OsAttributeVO> attributeMap = attrService.selectAllAttributeMap();
            for(BizType btmItem : btmItems){
                try{
                    BTMServicePrx btmService = platformClientUtil.getBtmService();
                    btmService.addBizType(btmItem);
                    //执行完成了需要创建表
                    //获取的时候不一定刷新了缓存,这样就获取不到信息
                    //OmdHelper
                    //todo 此占无法引用,后续会进行调整,再进行引用
//                    String btmTableName = BtmProvider.getInstance().getBTTableName(btmItem.name);
                    String btmTableName = null;
                    String sql = "create Table " + btmTableName + "(" + "\n\tOID VARCHAR2(36) not null,\n\tREVISIONOID VARCHAR2(36),\n\tNAMEOID VARCHAR2(36),\n\tBtmName VARCHAR2(36),\n\tISLastR CHAR(1),\n\tISFirstR CHAR(1),\n\tISLastV CHAR(1),\n\tISFirstV CHAR(1),\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36),\n\tLastModifyTime TIMESTAMP,\n\tRevisionRule VARCHAR2(36),\n\tVersionRule VARCHAR2(36),\n\tRevisionSeq NUMBER,\n\tRevisionValue VARCHAR2(10),\n\tVersionSeq NUMBER,\n\tVersionValue VARCHAR2(10),\n\tLCTID VARCHAR2(36),\n\tLCStatus VARCHAR2(36),\n\tTS TIMESTAMP,\n\tID VARCHAR2(36),\n\tNAME VARCHAR2(128),\n\tDESCRIPTION VARCHAR2(255),\n\tOWNER VARCHAR2(36),\n\tCHECKINBY VARCHAR2(36),\n\tCHECKINTIME TIMESTAMP,\n\tCHECKOUTBY VARCHAR2(36),\n\tCHECKOUTTIME TIMESTAMP,\n\tCOPYFROMVERSION VARCHAR2(36),\n\t";
                    String[] apNameArray = btmItem.apNameArray;
                    if(apNameArray!=null && apNameArray.length>0){
                        for(String attrId : apNameArray){
                            OsAttributeVO attrVO = attributeMap.get(attrId.toLowerCase().trim());
                            if(attrVO!=null) {
                                //todo 此占无法引用,后续会进行调整,再进行引用
//                                String abSql = Tool.getInstance().getAbSql(attrService.attributeVO2DO(attrVO));
//                                sql = sql + abSql;
                            }else{
                                logger.info("业务类型{}里的属性{}没找到",btmTableName,attrId.toLowerCase().trim());
                            }
                        }
                    }
//                    String alterSql = BtmProvider.getInstance().getAddPKSql(btmItem.name);
                    sql = sql.substring(0, sql.lastIndexOf(","));
                    sql = sql + "\n)";
                    //TODO 暂时不清楚用何种方式创建表,此处先注释掉
//                    DDLToolClient.getService().executeUpdateOracle(sql);
//                    DDLToolClient.getService().executeUpdateOracle(alterSql);
                }catch (PLException vciError){
                    throw WebUtil.getVciBaseException(vciError);
                }
            }
        }
    }
 
    /**
     * 批量添加业务类型
     * @param btmItems 业务类型的对象
     */
    @Override
    public void batchEditBtm(Collection<BizType> btmItems){
        Map<String, OsBtmTypeVO> btmTypeVOMap = btmService.selectAllBtmMap();
        if(!CollectionUtils.isEmpty(btmItems)){
            for(BizType btmItem : btmItems){
                String btmId = btmItem.name;
                List<String> addAttrList = new ArrayList<String>();
                //修改这里判断不了,是靠属性整体调整的
                List<String> deleteAttrList = new ArrayList<String>();
 
                Set<String> newAttrSet = new HashSet<String>();
                Collections.addAll(newAttrSet,btmItem.apNameArray);
                //拿到以前的
                OsBtmTypeVO oldItem = btmTypeVOMap.get(btmId);
                Set<String> oldAttrSet = new HashSet<String>();
                Collections.addAll(oldAttrSet,oldItem.getAttributes().stream().map(OsBtmTypeAttributeVO::getId).collect(Collectors.toList()).toArray(new String[0]));
                for(String attr:newAttrSet){
                    if(!oldAttrSet.contains(attr)){
                        addAttrList.add(attr);
                    }
                }
                for(String attr:oldAttrSet){
                    if(!newAttrSet.contains(attr)){
                        deleteAttrList.add(attr);
                    }
                }
                try{
                    platformClientUtil.getBtmService().updateBizType(btmItem);
                }catch (PLException vciError){
                    throw WebUtil.getVciBaseException(vciError);
                }
                addAttrToDB(addAttrList,btmId,false);
                removeAttrToDB(deleteAttrList,btmId,false);
 
            }
        }
    }
 
    /**
     * 导出业务类型的信息到Word中
     *
     * @param btmTypeIdCollection 业务类型的编号集合
     * @return word的全路径
     */
    @Override
    public String exportBtmTypesToWord(Collection<String> btmTypeIdCollection) {
        if(CollectionUtils.isEmpty(btmTypeIdCollection)){
            btmTypeIdCollection = btmService.selectAllBtmMap().keySet();
        }
        List<OsBtmTypeVO> btmTypeVOList = btmService.listBtmByIds(btmTypeIdCollection);
        List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeIds(btmTypeIdCollection);
        if(CollectionUtils.isEmpty(btmTypeVOList) && CollectionUtils.isEmpty(linkTypeVOList)){
            throw new VciBaseException("要导出的业务类型或者链接类型都不存在");
        }
        WordMergeStartTableDataBO tableDataBO = new WordMergeStartTableDataBO();
        tableDataBO.setTableName(wordFieldProperties.getTableName());
        List<Map<String,Object>> dataList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(btmTypeVOList)){
            btmTypeVOList.stream().forEach( s -> {
                //保持顺序
                Map<String,Object> tableData = new HashMap<>();
                tableData.put(wordFieldProperties.getTitle(),(s.getName()==null?"":s.getName()) + " " + s.getId());
                //字段
                List<Map<String,Object>> columnDataList = new ArrayList<>();
                List<OsBtmTypeAttributeVO> attributes = s.getAttributes();
                String tableAreaDesc = "";
                if(CollectionUtils.isEmpty(attributes)){
                    attributes = new ArrayList<>();
                }
                //加三个默认的属性
                OsBtmTypeAttributeVO idAttrVO = new OsBtmTypeAttributeVO();
                idAttrVO.setId("id");
                idAttrVO.setName("编号");
                idAttrVO.setAttributeDataType(VciFieldTypeEnum.VTString.name());
                idAttrVO.setAttributeLength(50);
                idAttrVO.setNullableFlag(true);
                attributes.add(idAttrVO);
 
                OsBtmTypeAttributeVO nameAttrVO = new OsBtmTypeAttributeVO();
                nameAttrVO.setId("name");
                nameAttrVO.setName("名称");
                nameAttrVO.setAttributeDataType(VciFieldTypeEnum.VTString.name());
                nameAttrVO.setAttributeLength(50);
                nameAttrVO.setNullableFlag(true);
                attributes.add(nameAttrVO);
 
                OsBtmTypeAttributeVO descAttrVO = new OsBtmTypeAttributeVO();
                descAttrVO.setId("description");
                descAttrVO.setName("描述");
                descAttrVO.setAttributeDataType(VciFieldTypeEnum.VTString.name());
                descAttrVO.setAttributeLength(150);
                descAttrVO.setNullableFlag(true);
                attributes.add(descAttrVO);
                if(!CollectionUtils.isEmpty(attributes)){
                    Map<String,Integer> indexMap = new HashMap<>();
                    indexMap.put("index",1);
 
 
                    attributes.stream().forEach( t -> {
                        int index = indexMap.get("index");
                        Map<String,Object> columnData = attributeToWordMap(t,index);
                        indexMap.put("index",index+1);
                        columnDataList.add(columnData);
                    });
                    //看是否有枚举
                    String enumString = joinEnumInfoFromAttribute(attributes);
                    if(StringUtils.isNotBlank(enumString)) {
                        tableAreaDesc += enumString;
                    }
                }
                tableData.put(wordFieldProperties.getColumnTableName(),columnDataList);
                if(StringUtils.isNotBlank(s.getLifeCycleId()) && !FrameWorkLcStatusConstant.EMTYPE_LIFE_CYCLE.equalsIgnoreCase(s.getLifeCycleId())){
                    List<OsStatusVO> statusVOList = lifeCycleService.listStatusById(s.getLifeCycleId());
                    if(!CollectionUtils.isEmpty(statusVOList)){
                        tableAreaDesc += "生命周期:[" + statusVOList.stream().map(OsStatusVO::getName).collect(Collectors.joining(",")) + "]";
                    }
                }
                tableData.put(wordFieldProperties.getAreaDesc(),tableAreaDesc);
                dataList.add(tableData);
            });
        }
        if(!CollectionUtils.isEmpty(linkTypeVOList)){
            linkTypeVOList.stream().forEach( s -> {
                //保持顺序
                Map<String,Object> tableData = new HashMap<>();
                tableData.put(wordFieldProperties.getTitle(),(s.getName()==null?"":s.getName()) + " " + s.getId());
                //字段
                List<Map<String,Object>> columnDataList = new ArrayList<>();
                List<OsLinkTypeAttributeVO> linkAttributes = s.getAttributes();
                List<OsBtmTypeAttributeVO> attributes = new ArrayList<>();
                linkAttributes.stream().forEach(t -> {
                    OsBtmTypeAttributeVO attributeVO = new OsBtmTypeAttributeVO();
                    BeanUtil.convert(t,attributeVO);
                    attributeVO.setPkBtmType(t.getPkLinkType());
                    attributes.add(attributeVO);
                });
                String tableAreaDesc = "";
                if(!CollectionUtils.isEmpty(attributes)){
                    Map<String,Integer> indexMap = new HashMap<>();
                    indexMap.put("index",1);
                    attributes.stream().forEach( t -> {
                        int index = indexMap.get("index");
                        Map<String,Object> columnData = attributeToWordMap(t,index);
                        indexMap.put("index",index+1);
                        columnDataList.add(columnData);
                    });
                    //看是否有枚举
                    String enumString = joinEnumInfoFromAttribute(attributes);
                    if(StringUtils.isNotBlank(enumString)) {
                        tableAreaDesc += enumString ;
                    }
                }
                if(StringUtils.isNotBlank(s.getFromBtmTypeName()) ){
                    tableAreaDesc += "From端业务类型:" + s.getFromBtmTypeName() + "\n";
                }
                if(StringUtils.isNotBlank(s.getToBtmTypeName()) ){
                    tableAreaDesc += "To端业务类型:" + s.getToBtmTypeName() + "\n";
                }
                tableData.put(wordFieldProperties.getColumnTableName(),columnDataList);
                tableData.put(wordFieldProperties.getAreaDesc(),tableAreaDesc);
                dataList.add(tableData);
            });
        }
        tableDataBO.setTableDataList(dataList);
        //写入到文件
        return writeDataToWord(tableDataBO);
    }
 
    /**
     * 导出业务类型的信息到Excel中
     *
     * @param btmTypeIdCollection 业务类型的编号集合
     * @return excel的全路径
     */
    @Override
    public String exportBtmTypesToExcel(Collection<String> btmTypeIdCollection) {
        if(CollectionUtils.isEmpty(btmTypeIdCollection)){
            btmTypeIdCollection = btmService.selectAllBtmMap().keySet();
        }
        List<OsBtmTypeVO> btmTypeVOList = btmService.listBtmByIds(btmTypeIdCollection);
        List<OsLinkTypeVO> linkTypeVOList = linkTypeService.listLinkTypeIds(btmTypeIdCollection);
        if(CollectionUtils.isEmpty(btmTypeVOList) && CollectionUtils.isEmpty(linkTypeVOList)){
            throw new VciBaseException("要导出的业务类型或者链接类型都不存在");
        }
        List<WriteExcelData> rowDataList = new ArrayList<>();
        final int[] index = {0};
        if(!CollectionUtils.isEmpty(btmTypeVOList)) {
            btmTypeVOList.stream().forEach(btmTypeVO -> {
                String btmId = btmTypeVO.getId();
                List<OsBtmTypeAttributeVO> attributeVOS = null;
                try {
                    attributeVOS = btmService.listAttributeByBtmId(btmId);
                } catch (PLException e) {
                    e.printStackTrace();
                    throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
                }
                //先是名称
                int rowIndex = index[0];
                WriteExcelData idED = new WriteExcelData(rowIndex, 0, btmId);
                idED.setMerged(true);
                if (attributeVOS.size() > 0) {
                    idED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3);
                }
                rowDataList.add(idED);
 
                WriteExcelData nameED = new WriteExcelData(rowIndex, 1, btmTypeVO.getName());
                nameED.setMerged(true);
                if (attributeVOS.size() > 0) {
                    nameED.setRowTo(rowIndex + attributeVOS.size() - 1 + 3);
                }
                rowDataList.add(nameED);
 
                rowDataList.add(new WriteExcelData(rowIndex, 2, "id"));
                rowDataList.add(new WriteExcelData(rowIndex, 3, "编号"));
                rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串"));
                rowDataList.add(new WriteExcelData(rowIndex, 5, "是"));
                rowDataList.add(new WriteExcelData(rowIndex, 6, "50"));
                rowIndex++;
                rowDataList.add(new WriteExcelData(rowIndex, 2, "name"));
                rowDataList.add(new WriteExcelData(rowIndex, 3, "名称"));
                rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串"));
                rowDataList.add(new WriteExcelData(rowIndex, 5, "是"));
                rowDataList.add(new WriteExcelData(rowIndex, 6, "50"));
                rowIndex++;
                rowDataList.add(new WriteExcelData(rowIndex, 2, "description"));
                rowDataList.add(new WriteExcelData(rowIndex, 3, "描述"));
                rowDataList.add(new WriteExcelData(rowIndex, 4, "字符串"));
                rowDataList.add(new WriteExcelData(rowIndex, 5, "是"));
                rowDataList.add(new WriteExcelData(rowIndex, 6, "150"));
                //处理属性
                rowIndex++;
                for (int i = 0; i < attributeVOS.size(); i++) {
                    OsBtmTypeAttributeVO attributeVO = attributeVOS.get(i);
                    //先是属性的英文名称
                    rowDataList.add(new WriteExcelData(rowIndex, 2, attributeVO.getId()));
                    //然后属性的中文名称
                    rowDataList.add(new WriteExcelData(rowIndex, 3, attributeVO.getName()));
                    //属性的类型
                    rowDataList.add(new WriteExcelData(rowIndex, 4, VciFieldTypeEnum.getTextByValue(attributeVO.getAttributeDataType())));
                    //是否可以为空
                    rowDataList.add(new WriteExcelData(rowIndex, 5, attributeVO.isNullableFlag() ? "是" : "否"));
                    //属性长度
                    String length = attributeVO.getAttributeLength()==null?"":attributeVO.getAttributeLength() + "" ;
                    if (attributeVO.getPrecisionLength() != null) {
                        length = length + "(" + attributeVO.getPrecisionLength() + "," + attributeVO.getScaleLength() == null ? "2" : (attributeVO.getScaleLength() + "") + ")" ;
                    }
                    rowDataList.add(new WriteExcelData(rowIndex, 6, length));
                    //备注
                    rowDataList.add(new WriteExcelData(rowIndex, 7, attributeVO.getDescription() == null ? "" : attributeVO.getDescription()));
                    rowIndex++;
                }
 
                index[0] = rowIndex;
            });
        }
        if(!CollectionUtils.isEmpty(linkTypeVOList)){
            linkTypeVOList.stream().forEach(linkTypeVO->{
                String linkTypeId = linkTypeVO.getId();
                List<OsLinkTypeAttributeVO> attributeVOS = linkTypeService.listAttributeByLinkId(linkTypeId);
                //先是名称
                int rowIndex = index[0];
                WriteExcelData idED = new WriteExcelData(rowIndex, 0, linkTypeId);
                idED.setMerged(true);
                if (attributeVOS.size() > 0) {
                    idED.setRowTo(rowIndex + attributeVOS.size() - 1);
                }
                rowDataList.add(idED);
 
                WriteExcelData nameED = new WriteExcelData(rowIndex, 1, linkTypeVO.getName());
                nameED.setMerged(true);
                if (attributeVOS.size() > 0) {
                    nameED.setRowTo(rowIndex + attributeVOS.size() - 1);
                }
                rowDataList.add(nameED);
 
                //处理属性
                for (int i = 0; i < attributeVOS.size(); i++) {
                    OsLinkTypeAttributeVO attributeVO = attributeVOS.get(i);
                    //先是属性的英文名称
                    rowDataList.add(new WriteExcelData(rowIndex, 2, attributeVO.getId()));
                    //然后属性的中文名称
                    rowDataList.add(new WriteExcelData(rowIndex, 3, attributeVO.getName()));
                    //属性的类型
                    rowDataList.add(new WriteExcelData(rowIndex, 4, VciFieldTypeEnum.getTextByValue(attributeVO.getAttrDataType())));
                    //是否可以为空
                    rowDataList.add(new WriteExcelData(rowIndex, 5, attributeVO.isNullableFlag() ? "是" : "否"));
                    //属性长度
                    String length = attributeVO.getAttributeLength() + "" ;
                    if (attributeVO.getPrecisionLength() != null) {
                        length = length + "(" + attributeVO.getPrecisionLength() + "," + attributeVO.getScaleLength() == null ? "2" : (attributeVO.getScaleLength() + "") + ")" ;
                    }
                    rowDataList.add(new WriteExcelData(rowIndex, 6, length));
                    //备注
                    rowDataList.add(new WriteExcelData(rowIndex, 7, attributeVO.getDescription() == null ? "" : attributeVO.getDescription()));
                    rowIndex++;
                }
                if(attributeVOS.size()==0){
                    rowIndex ++;
                }
                index[0] = rowIndex ;
            });
        }
 
        String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + "数据库表信息.xls";
        File excelFile = new File(excelFileName);
        try {
            excelFile.createNewFile();
        }catch (Throwable e){
            String msg = "在创建excel文件的时候出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }
        String excelTemplateFileName = "/excelTemplate/dataBaseExport.xls";
        if(this.getClass().getResource(excelTemplateFileName) == null){
            throw new VciBaseException("请联系管理员,系统中缺少{0}这个模板文件",new String[]{excelTemplateFileName});
        }
        try {
            ExcelUtil.copyFileFromJar(excelTemplateFileName,excelFile);
            //这个方法会关闭文件流
        }catch (Throwable e){
            String msg = "从模板文件拷贝到目标文件出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }
        try{
            WriteExcelOption excelOption = new WriteExcelOption();
            excelOption.addSheetDataList("数据库表",rowDataList);
            ExcelUtil.writeDataToFile(excelFile,excelOption);
        }catch (Throwable e){
            String msg = "把数据写入到excel文件中出现错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{excelFileName},e);
        }
        //最后返回excel文件名称
        return excelFileName;
    }
 
    /**
     * 拷贝数据到word模板中
     * @param tableDataBO 要写入的数据
     * @return word 文件路径
     */
    public String writeDataToWord(WordMergeStartTableDataBO tableDataBO){
        String tempFolder = LocalFileUtil.getDefaultTempFolder();
        //拷贝文件
        String wordFileName = tempFolder + File.separator + "数据库逻辑设计.doc";
        File wordFile = new File(wordFileName);
        try {
            wordFile.createNewFile();
        }catch (Throwable e){
            String msg = "在创建word文件的时候出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{wordFileName},e);
        }
        String wordTemplateFileName = "/wordTemplate/dataBaseExport.doc";
        if(this.getClass().getResource(wordTemplateFileName) == null){
            throw new VciBaseException("请联系管理员,系统中缺少{0}这个模板文件",new String[]{wordTemplateFileName});
        }
        try {
            LocalFileUtil.copyFileInJar(wordTemplateFileName,wordFileName);
            //这个方法会关闭文件流
        }catch (Throwable e){
            String msg = "从模板文件拷贝到目标文件出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg+",{0}",new String[]{wordFileName},e);
        }
        //写入word文件
        List<WordMergeStartTableDataBO> tableDataBOList = new ArrayList<>();
        tableDataBOList.add(tableDataBO);
        try {
            WordUtil.setTableDataToWord(wordFile, tableDataBOList);
        }catch (FileNotFoundException e){
            String msg = "读取word文件的时候出现了错误";
            if(logger.isErrorEnabled()){
                logger.error(msg,e);
            }
            throw new VciBaseException(msg + ",{0}",new String[]{wordFileName},e);
        }catch (VciBaseException e){
            throw e;
        }catch (Throwable e){
            throw new VciBaseException("写入数据到word中出现",new String[0],e);
        }
        return wordFileName;
    }
 
    /**
     * 将属性对象拷贝到word数据对象中
     * @param btmTypeAttributeVO 属性对象
     * @param index 索引
     * @return 数据映射,key 是word里的域字段,value是对应的值
     */
    private  Map<String,Object> attributeToWordMap(OsBtmTypeAttributeVO btmTypeAttributeVO,int index){
        Map<String,Object> columnData = new HashMap<>();
        if(StringUtils.isNotBlank(wordFieldProperties.getColumnIndex())) {
            columnData.put(wordFieldProperties.getColumnIndex(), index);
        }
        columnData.put(wordFieldProperties.getColumnId(),btmTypeAttributeVO.getId().toLowerCase());
        columnData.put(wordFieldProperties.getColumnName(),btmTypeAttributeVO.getName());
        String attrDataType = btmTypeAttributeVO.getAttributeDataType();
        String columnType = VciFieldTypeEnum.getTextByValue(attrDataType);
        if(StringUtils.isBlank(columnType)){
            columnType = "字符串";
        }
        columnData.put(wordFieldProperties.getColumnType(),columnType);
        String area = "长度" + (btmTypeAttributeVO.getAttributeLength() ==null?" ":btmTypeAttributeVO.getAttributeLength())
                + ((VciFieldTypeEnum.VTDouble.name().equalsIgnoreCase(attrDataType)
                && btmTypeAttributeVO.getPrecisionLength() != null
                && btmTypeAttributeVO.getScaleLength() !=null)?("(" + btmTypeAttributeVO.getPrecisionLength()
                + "," + btmTypeAttributeVO.getScaleLength() + ")"):"");
        if(VciFieldTypeEnum.VTDate.name().equalsIgnoreCase(attrDataType)
                || VciFieldTypeEnum.VTDateTime.name().equalsIgnoreCase(attrDataType)
                || VciFieldTypeEnum.VTTime.name().equalsIgnoreCase(attrDataType)
                || VciFieldTypeEnum.VTClob.name().equalsIgnoreCase(attrDataType)){
            area = "";
        }
        if(btmTypeAttributeVO.isEnumFlag()){
            area = "枚举:" + enumService.getNameById(btmTypeAttributeVO.getEnumId());
        }
        if(btmTypeAttributeVO.isReferFlag()){
            area = "参照:" + btmService.getNameById(btmTypeAttributeVO.getReferBtmTypeId()) + "(" + btmTypeAttributeVO.getReferBtmTypeId() + ")";
        }
        if(!btmTypeAttributeVO.isNullableFlag()){
            if(StringUtils.isNotBlank(area)){
                area += ",";
            }
            area += "非空";
        }
        columnData.put(wordFieldProperties.getColumnArea(),area);
        columnData.put(wordFieldProperties.getColumnDesc(),"");
        return columnData;
    }
 
    /**
     * 从属性中获取枚举的信息
     * @param attributes 属性对象
     * @return 不存在枚举的属性的时候会返回空
     */
    private String joinEnumInfoFromAttribute(List<OsBtmTypeAttributeVO> attributes){
        List<OsBtmTypeAttributeVO> hasEnumAttributeVOList = attributes.stream().filter( t -> t.isEnumFlag() ).collect(Collectors.toList());
        if(!CollectionUtils.isEmpty(hasEnumAttributeVOList)){
            List<String> enumIdList = hasEnumAttributeVOList.stream().map(OsBtmTypeAttributeVO::getEnumId).collect(Collectors.toList());
            List<OsEnumVO> enumVOList = enumService.listEnumByIdCollection(enumIdList);
            return enumVOList.stream().map(t->{
                return t.getName() + "(" + t.getId() + "):[" + t.getItemMaps().values().stream().collect(Collectors.joining(",")) + "]";
            }).collect(Collectors.joining("\n")) + "\n";
        }
        return "";
    }
 
 
    /**
     * 添加属性到oracle
     * @param addedAbList 添加的属性
     * @param btmType 业务类型
     */
    private void addAttrToDB(Collection<String> addedAbList,String btmType,boolean linkType){
        if (!CollectionUtils.isEmpty(addedAbList)) {
            //todo 此暂无法引用,后续会进行调整,再进行引用
//            String tableName = linkType? LinkTypeProvider.getInstance().getLTTableName(btmType):BtmProvider.getInstance().getBTTableName(btmType);
            String tableName = null;
            String addSql = "alter table " + tableName + " add(";
            Map<String, OsAttributeVO> attributeMap = attrService.selectAllAttributeMap();
            for (String abName : addedAbList) {
                AttributeDef abItem = attrService.attributeVO2DO(attributeMap.get(abName));
                //todo 此暂无法引用,后续会进行调整,再进行引用
//                addSql = addSql + Tool.getInstance().getAbSql(abItem);
            }
            addSql = VciBaseUtil.removeComma(addSql.replace("\n\t",""));
            addSql = addSql + ")";
            //TODO 不清楚具体使用什么方法,暂时注释,但不要删除
//            DDLToolClient.getService().batchExecuteUpdateOracle(new String[]{addSql});
        }
    }
 
    /**
     * 移除属性
     * @param removeAbList 要移除的属性列表
     * @param btmType 业务类型的内容
     */
    private void removeAttrToDB(Collection<String> removeAbList,String btmType,boolean linkType){
        if (!CollectionUtils.isEmpty(removeAbList)) {
            //todo 此暂无法引用,后续会进行调整,再进行引用
//            String tableName = linkType?LinkTypeProvider.getInstance().getLTTableName(btmType):BtmProvider.getInstance().getBTTableName(btmType);
//            String removeSql = "alter table " + tableName + " drop(";
//            for (String abName : removeAbList) {
//                removeSql = removeSql + abName + ",";
//            }
//            removeSql = VciBaseUtil.removeComma(removeSql.replace("\n\t",""));
//            removeSql = removeSql + ")";
            //TODO 不清楚具体使用什么方法,暂时注释,但不要删除
//            DDLToolClient.getService().batchExecuteUpdateOracle(new String[]{removeSql});
        }
    }
 
 
 
 
 
    /**
     * 封装业务类型
     * @param btmItem 业务类型的对象
     * @param btmTypeDTO 业务类型的数据传输对象
     */
    private void wrapperBtmItem(BizType btmItem ,OsBtmTypeDTO btmTypeDTO){
        btmItem.label = btmTypeDTO.getName();
        btmItem.description = btmTypeDTO.getDescription() == null ? "" : btmTypeDTO.getDescription();
        btmItem.isAbstract = false;
        btmItem.fName = "";
        btmItem.implClass = "";
        btmItem.shape = "";
        btmItem.lifeCycle = btmTypeDTO.getLifeCycleId() == null ? "" : btmTypeDTO.getLifeCycleId();
        btmItem.lifeCycles = new String[0];
        btmItem.imageName = "";
        if (StringUtils.isBlank(btmTypeDTO.getRevisionRuleId())) {
            btmItem.revLevel = 0;
        } else {
            btmItem.revLevel = (StringUtils.isNotBlank(btmTypeDTO.getVersionRule()) && VciBtmType.VciBtmTypeVersionRule.NONE.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) ? (short) 1 : (short)2;
        }
        btmItem.revInput = btmTypeDTO.isInputRevisionFlag();
        btmItem.revRuleName = btmTypeDTO.getRevisionRuleId()==null?"":btmTypeDTO.getRevisionRuleId();
        btmItem.delimiter = "";
        if (VciBtmType.VciBtmTypeVersionRule.INTSTART0.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) {
            btmItem.verRuleName = 2;
        } else if (VciBtmType.VciBtmTypeVersionRule.LETTER.getValue().equalsIgnoreCase(btmTypeDTO.getVersionRule())) {
            btmItem.verRuleName = 1;
        } else {
            btmItem.verRuleName = 0;
        }
        //包含的属性名称
        btmItem.apNameArray = btmTypeDTO.getApNameArray().split(",");
    }
 
    /**
     * 导入链接类型
     * @param linkTypeDTOS 链接类型的数据传输对象
     */
    private void importLinkType(Collection<OsLinkTypeDTO> linkTypeDTOS){
        Map<String, OsLinkTypeVO> allLinkMap = linkTypeService.selectAllLinkMap();
        Set<String> existLinkIdList = allLinkMap.keySet();
        List<LinkType> addLinkTypeList = new ArrayList<LinkType>();
        List<LinkType> editLinkTypeList = new ArrayList<LinkType>();
        String userId = WebUtil.getCurrentUserId();
        long now = VciDateUtil.getNowTime();
        for(OsLinkTypeDTO linkTypeDTO : linkTypeDTOS){
            String linkId = linkTypeDTO.getId().toLowerCase().trim();
            LinkType linkType = null;
            boolean editFlag = false;
            if(!existLinkIdList.contains(linkId)) {
                linkType = new LinkType();
                linkType.oid = "";
                linkType.creator = userId;
                linkType.createTime = now;
                linkType.ts = now;
            }else {
                linkType = new LinkType();
                OsLinkTypeVO linkTypeVO = allLinkMap.get(linkId);
                linkType.oid = linkTypeVO.getOid();
                linkType.creator = linkTypeVO.getCreator();
                linkType.createTime = VciDateUtil.getTime(linkTypeVO.getCreateTime());
                linkType.ts = VciDateUtil.getTime(linkTypeVO.getTs());
                editFlag = true;
            }
            linkType.modifier = userId;
            linkType.modifyTime = now;
            linkType.id = "";
            linkType.name = linkId;
            linkType.tag = linkTypeDTO.getName();
            linkType.description = linkTypeDTO.getDescription() == null ?"":linkTypeDTO.getDescription();
            linkType.implClass = "";
            linkType.shape = "";
            linkType.btmItemsFrom = linkTypeDTO.getFromBtmType().split(",");
            linkType.btmItemsTo = linkTypeDTO.getToBtmType().split(",");
            linkType.primitivesFrom = linkType.btmItemsFrom[0];
            linkType.primitivesTo = linkType.btmItemsTo[0];
            linkType.relationFrom = "N:N";
            linkType.relationTo = "N:N";
            linkType.relation = "N:N";
            List<String> attrList = new ArrayList<String>();
            List<OsBtmTypeLinkAttributesDTO> attributesDTOList = linkTypeDTO.getAttributesDTOList();
            if(!CollectionUtils.isEmpty(attributesDTOList)){
                for(OsBtmTypeLinkAttributesDTO attr:attributesDTOList){
                    attrList.add(attr.getId().toLowerCase());
                }
            }
            linkType.attributes = attrList.toArray(new String[0]);
            if(editFlag){
                editLinkTypeList.add(linkType);
            }else{
                addLinkTypeList.add(linkType);
            }
        }
        batchAddLink(addLinkTypeList);
        batchEditLink(editLinkTypeList);
        linkTypeService.clearCache();
        linkTypeService.selectAllLink();
    }
 
    /**
     * 批量添加链接类型
     * @param linkTypes 链接类型的对象
     */
    public void batchAddLink(Collection<LinkType> linkTypes){
        if(!CollectionUtils.isEmpty(linkTypes)){
            Map<String, OsAttributeVO> attributeMap = attrService.selectAllAttributeMap();
            for(LinkType linkType : linkTypes){
                try{
                    platformClientUtil.getLinkTypeService().addLinkType(linkType);
                    //todo 此暂无法引用,后续会进行调整,再进行引用
//                    String tableName = LinkTypeProvider.getInstance().getLTTableName(linkType.name);
                    String tableName = null;
                    String sql = "create table " + tableName + "(" + "\n\tOID VARCHAR2(36) not null,\n\tCreator VARCHAR2(36),\n\tCreateTime TIMESTAMP,\n\tLastModifier VARCHAR2(36),\n\tLastModifyTime TIMESTAMP,\n\tTS TIMESTAMP,\n\t";
                    String[] apNameArray = linkType.attributes;
                    if(apNameArray!=null && apNameArray.length>0){
                        for(String attrId : apNameArray){
                            OsAttributeVO attrVO = attributeMap.get(attrId.toLowerCase().trim());
                            //todo 此暂无法引用,后续会进行调整,再进行引用
//                            String abSql = Tool.getInstance().getAbSql(attrService.attributeVO2DO(attrVO));
//                            sql = sql + abSql;
                        }
                    }
                    sql = sql.substring(0, sql.lastIndexOf(","));
                    sql = sql + "\n)";
                    //TODO 不清楚具体使用什么方法,暂时注释,但不要删除
//                    DDLToolClient.getService().executeUpdateOracle(sql);
//                    DDLToolClient.getService().executeUpdateOracle(LinkTypeProvider.getInstance().getAddPKSql(linkType.name));
                }catch (PLException vciError){
                    throw WebUtil.getVciBaseException(vciError);
                }
            }
        }
    }
 
    /**
     * 批量修改链接类型
     * @param linkTypes 链接类型的对象
     */
    public void batchEditLink(Collection<LinkType> linkTypes){
        Map<String, OsLinkTypeVO> linkTypeVOMap = linkTypeService.selectAllLinkMap();
        if(!CollectionUtils.isEmpty(linkTypes)){
            for(LinkType linkType : linkTypes){
                try{
                    platformClientUtil.getLinkTypeService().modifyLinkType(linkType);
                    String linkTypeId = linkType.name.toLowerCase(Locale.ROOT);
                    List<String> addAttrList = new ArrayList<String>();
                    //修改这里判断不了,是靠属性整体调整的
                    List<String> deleteAttrList = new ArrayList<String>();
 
                    Set<String> newAttrSet = new HashSet<String>();
                    Collections.addAll(newAttrSet,linkType.attributes);
 
                    OsLinkTypeVO oldItem = linkTypeVOMap.get(linkType.name.toLowerCase(Locale.ROOT));
                    Set<String> oldAttrSet = new HashSet<String>();
                    Collections.addAll(oldAttrSet,oldItem.getAttributes().stream().map(OsLinkTypeAttributeVO::getId).collect(Collectors.toList()).toArray(new String[0]));
                    for(String attr:newAttrSet){
                        if(!oldAttrSet.contains(attr)){
                            addAttrList.add(attr);
                        }
                    }
                    for(String attr:oldAttrSet){
                        if(!newAttrSet.contains(attr)){
                            deleteAttrList.add(attr);
                        }
                    }
                    addAttrToDB(addAttrList,linkTypeId,true);
                    removeAttrToDB(deleteAttrList,linkTypeId,true);
 
                }catch (PLException vciError){
                    throw WebUtil.getVciBaseException(vciError);
                }
            }
        }
    }
}