wangting
2024-12-03 a53ab71161c5a546c70fa22ec5530cc4b2c7a672
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
package com.vci.web.service.impl;
 
import com.vci.client.common.datatype.VTDouble;
import com.vci.client.common.datatype.VTInteger;
import com.vci.client.common.datatype.VTLong;
import com.vci.client.common.datatype.VTString;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.PLException;
import com.vci.corba.omd.atm.AttributeDef;
import com.vci.dto.OsAttributeDTO;
import com.vci.enumpck.UI.ItemTypeEnum;
import com.vci.model.OsAttributeDO;
import com.vci.omd.dataType.VTDataType;
import com.vci.omd.objects.OtherInfo;
import com.vci.pagemodel.OsAttributeVO;
import com.vci.pagemodel.OsEnumVO;
import com.vci.po.OsAttributePO;
import com.vci.starter.poi.bo.ReadExcelOption;
import com.vci.starter.poi.bo.WriteExcelData;
import com.vci.starter.poi.bo.WriteExcelOption;
import com.vci.starter.poi.constant.ExcelLangCodeConstant;
import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.annotation.log.VciUnLog;
import com.vci.starter.web.enumpck.VciFieldTypeEnum;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.*;
import com.vci.starter.web.util.*;
import com.vci.web.enumpck.PortalVITypeFlag;
import com.vci.web.properties.UsedNames;
import com.vci.web.service.OsAttributeServiceI;
import com.vci.web.service.OsEnumServiceI;
import com.vci.web.service.OsLinkTypeServiceI;
import com.vci.starter.web.util.Lcm.Func;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.util.HSSFColor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
 
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
 
import static com.vci.omd.constants.AttributeConstants.*;
 
/**
 * 属性池服务  --已经调用了平台的服务,因此不在提供Dao层
 * @author weidy
 * @date 2021-2-15
 */
@Service
public class OsAttributeServiceImpl implements OsAttributeServiceI {
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 平台的调用工具类
     */
    @Autowired
    private PlatformClientUtil platformClientUtil;
 
    /**
     * 加载自身
     */
    @Autowired(required = false)
    @Lazy
    private OsAttributeServiceI self;
 
    /**
     * 属性名称最大长度
     */
    private Integer NAME_MAX_LENGTH = 28;
 
    /**
     * 系统中变量配置文件中配置的key
     */
    private final String SYSUSEDNAMES = "sysUsedNames";
 
    /**
     * 数据库中关键字配置文件中配置的key
     */
    private final String DATABASEUSEDNAMES = "dataBaseUsedNames";
 
    /**
     * 链接类型服务
     */
    @Autowired(required = false)
    @Lazy
    private OsLinkTypeServiceI osLinkTypeServiceI;
 
    /**
     * 业务类型服务
     */
    @Autowired(required = false)
    @Lazy
    private OsBtmServiceImpl osBtmService;
 
    /**
     * 枚举的服务
     */
    @Autowired
    @Lazy
    private OsEnumServiceI  enumService;
 
    /**
     *  必填列
     */
    private List<Integer> ColumnNameisRed = new ArrayList<Integer>();
 
    /**
     * 默认的属性
     */
    private static List<OsAttributeVO> defaultAttributeVOs = new ArrayList<>();
 
    /**
     * 默认属性的映射,key是小写
     */
    private static Map<String,OsAttributeVO> defaultAttributeVOMap = new HashMap<>();
 
    @Override
    public List<Tree> getTreeAttributesByBtmName(TreeQueryObject treeQueryObject) {
        List<Tree> rootTreeList=new ArrayList<>();
 
        Map<String, String> conditionMap = treeQueryObject.getConditionMap();
        if (conditionMap == null) {
            conditionMap = new HashMap<>();
        }
        String typeName = StringUtils.isBlank(conditionMap.get("typeName")) ? "" : conditionMap.get("typeName");
        if (StringUtils.isBlank(typeName)) {
            VciBaseUtil.alertNotNull(typeName,"业务类型名称");
        }
        try {
            String typeFlag=StringUtils.isBlank(conditionMap.get("typeFlag"))?"":conditionMap.get("typeFlag");
            PortalVITypeFlag portalVITypeFlag= PortalVITypeFlag.getByName(typeFlag);
            Short viTypeFlag=-1;
            if(portalVITypeFlag!=null){
                viTypeFlag=portalVITypeFlag.getIntVal();
            }
            boolean isDefault =Boolean.parseBoolean(conditionMap.get("isDefault"));
            Tree tree = new Tree("root", "【" + typeName + "】属性信息", "root");
            tree.setLevel(0);
            rootTreeList.add(tree);
            getChildTree(rootTreeList,typeName, viTypeFlag,isDefault);
        }catch (Throwable e){
         e.printStackTrace();
        }
        return rootTreeList;
    }
 
    /**
     * 构造属性树节点
     * @param parentTreeList
     * @param refTypeName
     * @param refFlag
     * @param isDefault
     * @throws Exception
     */
    private void getChildTree(List<Tree> parentTreeList,String refTypeName,int refFlag,boolean isDefault) throws Exception {
        for (Tree pTree : parentTreeList) {
            if (pTree.getLevel()>= 3) {
                continue;
            }
            Object o= pTree.getData();
            String pName=pTree.getText();
            boolean isOsAttributeVO=false;
            if(o instanceof OsAttributeVO){
                isOsAttributeVO=true;
                OsAttributeVO osAttributeVO=(OsAttributeVO)o;
                String other = osAttributeVO.getOther();
                OtherInfo otherInfo = OtherInfo.getOtherInfoByText(other);
                refFlag = otherInfo.getRefFlag();
                refTypeName = otherInfo.getRefTypeName();
            }
            List<OsAttributeVO> childOsAttributeVOList=new ArrayList<>();
            if (refFlag != -1) {
                // pName: 为参照属性名加上路径
                childOsAttributeVOList=getOsAttributeVOSByBtName(refTypeName,refFlag,isDefault);
                if(!CollectionUtils.isEmpty(childOsAttributeVOList)) {
                    List<Tree> childTreeList= new ArrayList<>();
                    boolean finalIsOsAttributeVO = isOsAttributeVO;
                    childOsAttributeVOList.stream().forEach(childOsAttributeVO->{
                        Tree childTree = new Tree(childOsAttributeVO.getOid(), childOsAttributeVO.getId(), childOsAttributeVO);
                        childTree.setOid(childOsAttributeVO.getOid());
                        childTree.setParentName(pTree.getText());
                        childTree.setParentId(pTree.getOid());
                        childTree.setLevel(pTree.getLevel()+1);
                        childTree.setLeaf(true);
                        if(finalIsOsAttributeVO) {
                            childTree.setText(pName + "." + childOsAttributeVO.getId());
                        }else{
                            childTree.setText(childOsAttributeVO.getId());
                        }
                        if (childTree.getLevel()>= 3) {
                            childTree.setLeaf(true);
                        }
                        childTreeList.add(childTree);
                    });
                    if(childTreeList.size()>0){
                        pTree.setChildren(childTreeList);
                        pTree.setExpanded(false);
                        getChildTree(childTreeList,refTypeName,refFlag,isDefault);
                    }else{
                        pTree.setLeaf(true);
                        pTree.setExpanded(true);
                    }
 
                }
            }else{
                pTree.setExpanded(true);
            }
        }
    }
 
    /**
     * 获取默认的属性
     * @return 默认的属性列表
     */
    @Override
    public List<OsAttributeVO> getDefaultAttributeVOs() {
        return OsAttributeServiceImpl.defaultAttributeVOs;
    }
 
    /**
     * 设置默认的属性
     * @param defaultAttributeVOs 默认的属性列表
     */
    @Override
    public void setDefaultAttributeVOs(List<OsAttributeVO> defaultAttributeVOs) {
        OsAttributeServiceImpl.defaultAttributeVOs = defaultAttributeVOs;
    }
 
    /**
     * 获取的默认属性的映射
     * @return 默认的属性映射
     */
    @Override
    public Map<String, OsAttributeVO> getDefaultAttributeVOMap() {
        return OsAttributeServiceImpl.defaultAttributeVOMap;
    }
 
    /**
     * 设置默认的属性的映射
     * @param defaultAttributeVOMap 默认的属性映射
     */
    @Override
    public void setDefaultAttributeVOMap(Map<String, OsAttributeVO> defaultAttributeVOMap) {
        OsAttributeServiceImpl.defaultAttributeVOMap = defaultAttributeVOMap;
    }
 
    /**
     * 查询所有的属性
     *
     * @return 属性的显示对象
     */
    @Override
    public List<OsAttributeVO> selectAllAttribute() {
        //后面两个分页数,完全没有用
        try {
            return attributeDO2VOs(Arrays.stream(platformClientUtil.getAttributeService().getAttributeDefs("",1,1)).collect(Collectors.toList()));
        } catch (PLException vciError) {
            throw WebUtil.getVciBaseException(vciError);
        }
    }
 
    /**
     * 查询所有的属性映射
     *
     * @return key是属性的英文名称小写,value是属性的显示对象
     */
    @Override
    @VciUnLog
    public Map<String, OsAttributeVO> selectAllAttributeMap() {
        return Optional.ofNullable(self.selectAllAttribute()).orElseGet(()->new ArrayList<>()).stream().collect(Collectors.toMap(s->s.getId().toLowerCase(),t->t,(o1,o2)->o1));
    }
 
    /**
     * 根据多个属性名称查询属性
     * @param attrNames
     * @return
     */
    @Override
    public List<OsAttributeVO> getByAttributeNames(String[] attrNames) throws PLException {
        VciBaseUtil.alertNotNull(attrNames,"属性名");
        List<OsAttributeVO> osAttributeVOS = new ArrayList<>();
        AttributeDef[] attributeDefs = platformClientUtil.getAttributeService().getAttributeDefsByNames(attrNames);
        Arrays.stream(attributeDefs).forEach(attr->{
            osAttributeVOS.add(attributeDO2VO(attr));
        });
        return osAttributeVOS;
    }
 
    /**
     * 属性的数据对象转换为显示对象
     *
     * @param attribItems 数据对象
     * @return 显示对象
     */
    @Override
    public List<OsAttributeVO> attributeDO2VOs(Collection<AttributeDef> attribItems) {
        List<OsAttributeVO> vos = new ArrayList<>();
        Optional.ofNullable(attribItems).orElseGet(()->new ArrayList<>()).stream().forEach(attribItem -> {
            vos.add(attributeDO2VO(attribItem));
        });
        return vos;
    }
 
    /**
     * 属性的数据对象转换为显示对象
     *
     * @param attribItem 数据对象
     * @return 显示对象
     */
    @Override
    public OsAttributeVO attributeDO2VO(AttributeDef attribItem) {
        OsAttributeVO attributeVO = new OsAttributeVO();
        if(attribItem!=null){
            attributeVO.setOid(attribItem.oid);
            attributeVO.setId(attribItem.name);
            attributeVO.setCreator(attribItem.creator);
            try {
                attributeVO.setCreateTime(new Date(attribItem.createTime));
                attributeVO.setLastModifyTime(new Date(attribItem.modifyTime));
                attributeVO.setTs(VciDateUtil.str2Date(attribItem.ts,VciDateUtil.DateTimeMillFormat));
            }catch (Throwable e){
                e.printStackTrace();
                String errorLog = "属性DO转VO时出错,原因:"+VciBaseUtil.getExceptionMessage(e);
                logger.error(errorLog);
                throw new VciBaseException(errorLog);
            }
            attributeVO.setLastModifier(attribItem.modifier);
            attributeVO.setName(attribItem.label);
            attributeVO.setDescription(attribItem.description);
            attributeVO.setAttributeDataType(attribItem.vtDataType);
            attributeVO.setAttributeDataTypeText(VciFieldTypeEnum.getTextByValue(attribItem.vtDataType));
            //获取UI属性类型
            attributeVO.setAttributeUIType(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,false));
            //获取UI属性类型文本
            attributeVO.setAttributeUITypeText(ItemTypeEnum.convertAttributeTypeTOUITypeTextByValue(attribItem.vtDataType,true));
            attributeVO.setDefaultValue(attribItem.defValue);
            if(Func.isNotBlank(attribItem.rage)){
                attributeVO.setRange(attribItem.rage.replace("&lt;","<"));
            }else{
                attributeVO.setRange(attribItem.rage);
            }
            attributeVO.setOther(attribItem.other);
            //处理参照相关属性
            if(StringUtils.isNotBlank(attribItem.other)) {
                if (isReferAttr(attribItem.other)) {
                    //说明这个的确是参照字段
                    String[] others = attribItem.other.split(";");
                    for (String s : others) {
                        if (s.toLowerCase().contains("btm") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                            attributeVO.setBtmTypeId(s.split("=")[1].trim());
                        }
                        //链接类型不支持
                        if (s.toLowerCase().contains("link") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                            attributeVO.setLinkTypeName(s.split("=")[1].trim());
                        }
                        if (s.toLowerCase().contains("version") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                            attributeVO.setVersion(WebUtil.getInt(s.split("=")[1].trim()));
                        }
                    }
                }
                //必输和长度
                String[] others = attribItem.other.split(";");
                for (String s : others) {
                    if (s.toLowerCase().contains("allownull") && s.split("=").length > 1) {//必须要判断长度,因为枚举的时候也是包含这个btm的
                        boolean allownull = false;
                        if (s.split("=")[1].trim().toLowerCase().equals("yes")) {
                            allownull = true;
                        }
                        attributeVO.setNullableFlag(allownull);
                    }
                    if (s.toLowerCase().indexOf("length") > -1 && s.split("=").length > 1) {
                        int length = WebUtil.getInt(s.split("=")[1].trim());
                        if (length > 0) {
                            attributeVO.setAttrLength(length);
                        }
                    }
                }
                //枚举
                if(isEnumAttr(attribItem.other)){
                    for (String s : others) {
                        if(s.contains("enumName") && s.split("=").length>1) {
                            attributeVO.setEnumId(s.split("=")[1].trim());
                        }
                    }
                }
            }
        }
        return attributeVO;
    }
 
    /**
     * 属性的显示对象转换为数据对象
     *
     * @param attributeVO 显示对象
     * @return 数据对象
     */
    @Override
    public AttributeDef attributeVO2DO(OsAttributeVO attributeVO) {
        AttributeDef attribItem = new AttributeDef();
        attribItem.oid = attributeVO.getOid();
        attribItem.ts = VciDateUtil.date2Str(attributeVO.getTs(),VciDateUtil.DateTimeFormat);
        attribItem.creator = attributeVO.getCreator();
        attribItem.createTime = attributeVO.getCreateTime() != null?attributeVO.getCreateTime().getTime():null;
        attribItem.modifier = attributeVO.getLastModifier();
        attribItem.modifyTime = attributeVO.getLastModifyTime() != null ? attributeVO.getLastModifyTime().getTime():null;
        attribItem.name = attributeVO.getId();
        attribItem.label = attributeVO.getName();
        attribItem.description = attributeVO.getDescription() == null ?"":attributeVO.getDescription();
        attribItem.vtDataType = attributeVO.getAttributeDataType() == null ? VciFieldTypeEnum.VTString.name() : attributeVO.getAttributeDataType();
        attribItem.defValue = attributeVO.getDefaultValue() == null?"":attributeVO.getDefaultValue();
        attribItem.rage = attributeVO.getRange() == null ? "" : attributeVO.getRange();
        //other需要自行处理
        StringBuffer sb = new StringBuffer();
        sb.append(ALLOWNULL).append(" = ").append(attributeVO.isNullableFlag() ? "yes" : "no").append(";");
        VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(attributeVO.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:
                if(attributeVO.getAttrLength() == null){
                    attributeVO.setAttrLength(20);
                }
                if(attributeVO.getPrecisionLength() == null){
                    attributeVO.setPrecisionLength(2);
                }
                sb.append(ACCURACY).append(" = ").append(attributeVO.getPrecisionLength()).append(";");
                sb.append(LENGTH).append(" = ").append(length > attributeVO.getAttrLength()?length:attributeVO.getAttrLength()).append(";");
 
                break;
            case VTInteger:
                if (StringUtils.isNotBlank(attributeVO.getEnumId())) {
                    sb.append(ENUMNAME).append(" = ").append(attributeVO.getEnumId()).append(";");
                }
                break;
            case VTString:
                if (StringUtils.isNotBlank(attributeVO.getBtmTypeId())) {
                    //参照
                    sb.append(BTM).append(" = ").append(attributeVO.getBtmTypeId()).append(";");
                    //链接类型暂时不支持
                }
                sb.append(LENGTH).append(" = ").append(length > attributeVO.getAttrLength()?length:attributeVO.getAttrLength()).append(";");
                if (StringUtils.isNotBlank(attributeVO.getEnumId())) {
                    sb.append(ENUMNAME).append(" = ").append(attributeVO.getEnumId()).append(";");
                }
                break;
            default:
                //不需要处理
                break;
        }
        attribItem.other = sb.toString();
        if (attribItem.other.endsWith(";")) {
            attribItem.other = attribItem.other.substring(0, attribItem.other.length() - 1);
        }
        return attribItem;
    }
 
    /**
     * 根据属性的名称获取属性对象
     * @param attrCode 属性英文名称
     * @return 属性的基本信息
     */
    @Override
    public OsAttributeVO getAttr(String attrCode) {
        if(StringUtils.isBlank(attrCode)){
            return null;
        }
        return self.selectAllAttributeMap().getOrDefault(attrCode.toLowerCase(),null);
    }
 
    /**
     * 使用属性编号获取对象--批量
     *
     * @param attrCodes 属性的英文名称
     * @return 属性的显示对象
     */
    @Override
    public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes) {
        if(CollectionUtils.isEmpty(attrCodes)){
            return null;
        }
        Map<String, OsAttributeVO> attributeVOMap = self.selectAllAttributeMap();
        List<OsAttributeVO> attributeVOS = new ArrayList<>();
        attrCodes.stream().forEach(attrCode->{
            OsAttributeVO attributeVO = attributeVOMap.getOrDefault(attrCode.toLowerCase(),null);
            if(attributeVO!=null){
                attributeVOS.add(attributeVO);
            }
        });
        return attributeVOS;
    }
 
    /**
     * 使用属性编号获取对象--批量
     *
     * @param attrCodes 属性的英文名称
     * @param attributeVOMap 属性对象
     * @return 属性的显示对象
     */
    @Override
    public List<OsAttributeVO> listAttrByIds(Collection<String> attrCodes,Map<String, OsAttributeVO> attributeVOMap) {
        if(CollectionUtils.isEmpty(attrCodes)){
            return null;
        }
        if(attributeVOMap == null){
            attributeVOMap = self.selectAllAttributeMap();
        }
        List<OsAttributeVO> attributeVOS = new ArrayList<>();
        Map<String, OsAttributeVO> finalAttributeVOMap = attributeVOMap;
        attrCodes.stream().forEach(attrCode->{
            OsAttributeVO attributeVO = finalAttributeVOMap.getOrDefault(attrCode.toLowerCase(),null);
            if(attributeVO!=null){
                attributeVOS.add(attributeVO);
            }
        });
        return attributeVOS;
    }
 
    /**
     * 批量添加属性
     *
     * @param attribItemList 属性的列表
     */
    @Override
    public void batchAddAttribute(List<AttributeDef> attribItemList) {
        if(!CollectionUtils.isEmpty(attribItemList)){
            attribItemList.stream().forEach(attribItem -> {
                try {
                    platformClientUtil.getAttributeService().addAttributeDef(attribItem);
                } catch (PLException e) {
                    throw WebUtil.getVciBaseException(e);
                }
            });
        }
    }
 
    /**
     * 批量编辑属性
     * @param editAttrList 属性的列表
     */
    @Override
    public void batchEditAttribute(List<AttributeDef> editAttrList) {
        if(!CollectionUtils.isEmpty(editAttrList)){
            editAttrList.stream().forEach(attribItem -> {
                try {
                    platformClientUtil.getAttributeService().modifyAttributeDef(attribItem);
                } catch (PLException e) {
                    throw WebUtil.getVciBaseException(e);
                }
            });
        }
    }
 
    /**
     * 属性列表
     *
     * @param baseQueryObject 查询对象
     * @return 属性的显示对象
     */
    @Override
    public DataGrid<OsAttributeVO> gridAttribute(BaseQueryObject baseQueryObject) {
        return gridObject(baseQueryObject, OsAttributeDO.class,self.selectAllAttributeMap(),OsAttributeVO.class);
    }
 
    /**
     * 添加单条属性
     * @param osAttributeDTO
     * @return true成功,false失败
     */
    @Override
    public boolean addAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
        //判空
        VciBaseUtil.alertNotNull(
        osAttributeDTO,"创建的属性对象",
            osAttributeDTO.getId(),"属性名称",
            osAttributeDTO.getAttributeDataType(),"属性类型"
        );
        //属性英文名称校验(判空、系统中判重、是否关键字、是否合规等)
        checkName(osAttributeDTO.getId());
        //检查属性名是否已存在与系统中
        if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributeDTO.getId())){
            throw new PLException("500",new String[]{"属性名称【" + osAttributeDTO.getId() + "】在系统中已存在!"});
        }
        //检查默认值与属性类型是否匹配
        checkDefValue(osAttributeDTO);
        //osAttributeDTO.setOid(VciBaseUtil.getPk().toUpperCase(Locale.ROOT));
        AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
        return platformClientUtil.getAttributeService().addAttributeDef(attributeDef);
    }
 
    /**
     * 修改单条属性
     * @param osAttributeDTO
     * @return true成功,false失败
     */
    @Override
    public boolean updateAttribute(OsAttributeDTO osAttributeDTO) throws PLException {
        //判空
        VciBaseUtil.alertNotNull(
                osAttributeDTO,"修改的属性对象",
                osAttributeDTO.getId(),"属性名称",
                osAttributeDTO.getTs(),"事务TS",
                osAttributeDTO.getAttributeDataType(),"属性类型"
        );
 
        //名称不允许修改所以不用查重
        //但是需要检查属性是否存在
        OsAttributeVO osAttributeVO = getByAttributeNames(new String[]{osAttributeDTO.getId()}).get(0);
        if(Func.isEmpty(osAttributeVO) || Func.isBlank(osAttributeVO.getOid())){
            throw new PLException("500",new String[]{"属性在系统中不存在,请刷新后重试!"});
        }
        //检查默认值与属性类型是否匹配
        checkDefValue(osAttributeDTO);
        boolean compatible = isCompatible(osAttributeVO,osAttributeDTO);
        //boolean hasInstance = hasInstance(osAttributeDTO.getId()); //不判断是否产生数据只要被引用就需要进一步判断类型是否兼容
        boolean checkAttrIsUse = this.checkAttrIsUse(osAttributeDTO.getId());
        //TODO:按照以前操作配置文档中的逻辑应该是:不论是否产生数据只要被引用就需要要判断类型是否兼容(如VTString不能转为VTIntger或VTLong)
        if(checkAttrIsUse/*hasInstance*/ && !compatible){
            throw new PLException("500",new String[]{"无效变更, 不兼容已产生的数据!"});
        }
        String userId = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId();
        osAttributeDTO.setLastModifier(userId);
        osAttributeDTO.setCreator(osAttributeVO.getCreator());
        osAttributeDTO.setCreateTime(osAttributeVO.getCreateTime());
        osAttributeDTO.setLastModifyTime(new Date());
 
        try {
            AttributeDef attributeDef = this.osAttributeDTO2AttributeDef(osAttributeDTO);
            boolean mdSuccess = platformClientUtil.getAttributeService().modifyAttributeDef(attributeDef);
            if(!mdSuccess){
                return false;
            }
 
            //属性修改成功,修改业务类型, 链接类型中该属性字段
            boolean alterApBoolean = this.alterAp(attributeDef.name);
            if(!alterApBoolean){
                logger.error("属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!");
                throw new PLException("500",new String[]{"属性修改完成,但在调整业务类型或链接类型中对应属性名的属性时出现错误!"});
            }
            return true;
        } catch (PLException e1) {
            e1.printStackTrace();
        }
        return false;
    }
 
    /**
     * DTO对象转实际存储所需的AttributeDef对象
     * @param osAttributeDTO
     * @return
     */
    private AttributeDef osAttributeDTO2AttributeDef(OsAttributeDTO osAttributeDTO) {
        AttributeDef attributeDef = new AttributeDef();
        attributeDef.oid = osAttributeDTO.getOid();
        attributeDef.name = osAttributeDTO.getId().toLowerCase().replaceAll(" ", "");
        attributeDef.label = osAttributeDTO.getName();
        attributeDef.description = osAttributeDTO.getDescription();
        attributeDef.vtDataType = (String)osAttributeDTO.getAttributeDataType();
        attributeDef.defValue = Func.isBlank(osAttributeDTO.getDefaultValue()) ? "" : osAttributeDTO.getDefaultValue();
        if(Func.isBlank(osAttributeDTO.getRange())){
            attributeDef.rage = "";
        }else{
            //特殊字符处理,直接存储<会报错
            attributeDef.rage = osAttributeDTO.getRange().replace("<","&lt;");
        }
        attributeDef.ts = Func.format((Func.isNotEmpty(osAttributeDTO.getTs()) ? osAttributeDTO.getTs():new Date()),VciDateUtil.DateTimeMillFormat);
        attributeDef.creator = Func.isBlank(osAttributeDTO.getCreator()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getCreator();
        attributeDef.createTime = Func.isEmpty(osAttributeDTO.getCreateTime()) ? System.currentTimeMillis():osAttributeDTO.getCreateTime().getTime();
        attributeDef.modifier = Func.isBlank(osAttributeDTO.getLastModifier()) ? WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId():osAttributeDTO.getLastModifier();
        attributeDef.modifyTime = System.currentTimeMillis();
        //other需要自行处理
        StringBuffer sb = new StringBuffer();
        sb.append(ALLOWNULL).append(" = ").append(osAttributeDTO.isNullableFlag() ? "yes" : "no").append(";");
        VciFieldTypeEnum fieldTypeEnum = VciFieldTypeEnum.valueOf(osAttributeDTO.getAttributeDataType());
        String[] otherInfos = attributeDef.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:
                if(osAttributeDTO.getAttrLength() == null){
                    osAttributeDTO.setAttrLength(20);
                }
                if(osAttributeDTO.getPrecisionLength() == null){
                    osAttributeDTO.setPrecisionLength(2);
                }
                sb.append(ACCURACY).append(" = ").append(osAttributeDTO.getPrecisionLength()).append(";");
                sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
 
                break;
            case VTInteger:
                if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
                    sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
                }
                break;
            case VTString:
                if (StringUtils.isNotBlank(osAttributeDTO.getBtmTypeId())) {
                    //参照业务类型
                    sb.append(BTM).append(" = ").append(osAttributeDTO.getBtmTypeId()).append(";");
                }
                if(StringUtils.isNotBlank(osAttributeDTO.getLinkTypeName())){
                    //参照链接类型
                    sb.append(LINKTYPENAME).append(" = ").append(osAttributeDTO.getLinkTypeName()).append(";");
                    sb.append(VERSION).append(" = ").append(osAttributeDTO.getVersion()).append(";");
                }
                sb.append(LENGTH).append(" = ").append(length > osAttributeDTO.getAttrLength()?length:osAttributeDTO.getAttrLength()).append(";");
                if (StringUtils.isNotBlank(osAttributeDTO.getEnumId())) {
                    sb.append(ENUMNAME).append(" = ").append(osAttributeDTO.getEnumId()).append(";");
                }
                break;
            default:
                //不需要处理
                break;
        }
        attributeDef.other = sb.toString();
        if (attributeDef.other.endsWith(";")) {
            attributeDef.other = attributeDef.other.substring(0, attributeDef.other.length() - 1);
        }
        return attributeDef;
    }
 
    /**
     * 修改属性时, 判断当前输入的属性是否能兼容之前的属性
     * @param osAttributeVO 数据库中存储的
     * @param osAttributeDTO 修改后的内容
     * @return
     */
    private boolean isCompatible(OsAttributeVO osAttributeVO/*数据库中存储的*/,OsAttributeDTO osAttributeDTO/*修改后的内容*/){
        String dataType = osAttributeVO.getAttributeDataType();
        //String other = osAttributeVO.getOther();
        //String newOther = abItem.other == null ? "" : abItem.other;
        String newType = osAttributeDTO.getAttributeDataType();
        if(newType.equals(VTDataType.VTSTRING)){
            if(dataType.equals(VTDataType.VTINTEGER) || dataType.equals(VTDataType.VTLONG)){
                return true;
            }
            if(dataType.equals(VTDataType.VTSTRING)){
                int length = osAttributeVO.getAttrLength();//Integer.valueOf(getOtherValueByType(other, "length"));
                int newLen = osAttributeDTO.getAttrLength();//Integer.valueOf(getOtherValueByType(newOther, "length"));
                if(length <= newLen){
                    return true;
                }else{
                    return false;
                }
            }
        }
 
        if(newType.equals(dataType)){
            return true;
        }
 
        return false;
    }
 
    /**
     * 判断该属性是否已经在业务类型中, 或者链接类型中产生了数据
     * @param abName
     * @return
     */
    private boolean hasInstance(String abName) throws PLException {
        return osBtmService.hasInstance(abName) && osLinkTypeServiceI.hasInstance(abName);
    }
 
    /**
     * 查看属性是否被引用
     * @param abName
     * @return false未被引用 true被引用
     */
    private boolean checkAttrIsUse(String abName) throws PLException {
        if(Func.isBlank(abName)){
            return false;
        }
        String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(abName);
        if(Func.isNotEmpty(btNames)){
            return true;
        }
        String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(abName);
        if(Func.isNotEmpty(ltNames)){
            return true;
        }
        return false;
    }
 
    /**
     * 检查属性名称是否符合规范
     * @param attributeName
     * @return 没有返回值,存在问题直接抛出错误
     */
    private void checkName(String attributeName) throws PLException {
        if(attributeName.equals("")){
            throw new PLException("500",new String[]{"注意,属性名不能为空!"});
        }
 
        if(!attributeName.matches("[a-z A-Z]*")){
            throw new PLException("500",new String[]{"注意:属性名只能为英文字母!"});
        }
 
        int length = attributeName.length();
        if(length > NAME_MAX_LENGTH){
            throw new PLException("500",new String[]{"属性名过长,属性名长度不能超过"+ NAME_MAX_LENGTH});
        }
 
        String abName = attributeName.toLowerCase();
        //检查属性名是否是为系统基础属性,如createTime,ts,oid等
        if(usedBySystem(abName)){
            throw new PLException("500",new String[]{"属性名无效,原因:属性名已被系统属性使用!"});
        }
        //检查属性名是否是关键字
        if(usedByDataBase(abName)){
            throw new PLException("500",new String[]{"属性名无效,原因:属性名是数据库关键字!"});
        }
        //检查属性名是否已存在与系统中
        /*if(platformClientUtil.getAttributeService().checkRowIsExists(abName)){
            throw new PLException("500",new String[]{"属性名称【" + abName + "】在系统中已存在!"});
        }*/
    }
 
    /**
     * 检查默认值与属性类型是否匹配
     * @param osAttributeDTO
     * @return
     */
    private void checkDefValue(OsAttributeDTO osAttributeDTO) throws PLException {
        String defValue = osAttributeDTO.getDefaultValue();
        String vtType = osAttributeDTO.getAttributeDataType();
        String rages = osAttributeDTO.getRange();
        if(defValue != null && !defValue.equals("")){
            if(vtType.equals(VTDataType.VTSTRING)){
                try{
                    String.valueOf(defValue);
                }catch(Exception e){
                    throw new PLException("500",new String[]{"请输入String类型的默认值!"});
                }
                if(rages == null || rages.equals("")){
                    return;
                }
                VTString obj = new VTString(String.valueOf(defValue));
                boolean flag = obj.checkRageValueByRage(rages);
                if(!flag){
                    throw new PLException("500",new String[]{"默认值与值域冲突!"});
                }
            }else if(vtType.equals(VTDataType.VTINTEGER)){
                try{
                    Integer.valueOf(defValue);
                }catch(Exception e){
                    throw new PLException("500",new String[]{"请输入Integer类型的默认值!"});
                }
                if(rages == null || rages.equals("")){
                    return;
                }
                VTInteger obj = new VTInteger(Integer.valueOf(defValue));
                boolean flag = obj.checkRageValueByRage(rages);
                if(!flag){
                    throw new PLException("500",new String[]{"默认值与值域冲突!"});
                }
            }else if(vtType.equals(VTDataType.VTLONG)){
                try{
                    Long.valueOf(defValue);
                }catch(Exception e){
                    throw new PLException("500",new String[]{"请输入Long类型的默认值!"});
                }
                if(rages == null || rages.equals("")){
                    return;
                }
                VTLong obj = new VTLong(Long.valueOf(defValue));
                boolean flag = obj.checkRageValueByRage(rages);
                if(!flag){
                    throw new PLException("500",new String[]{"默认值与值域冲突!"});
                }
            }else if(vtType.equals(VTDataType.VTDOUBLE)){
                try{
                    Double.valueOf(defValue);
                }catch(Exception e){
                    throw new PLException("500",new String[]{"请输入Double类型的默认值!"});
                }
                if(rages == null || rages.equals("")){
                    return;
                }
                VTDouble obj = new VTDouble(Double.valueOf(defValue));
                boolean flag = obj.checkRageValueByRage(rages);
                if(!flag){
                    throw new PLException("500",new String[]{"默认值与值域冲突!"});
                }
            }
        }
    }
 
    /**
     * 检查该属性名是否被系统属性使用
     * @param abName
     * @return
     */
    private boolean usedBySystem(String abName) {
        boolean flag = false;
        String[] names = UsedNames.getProperty(SYSUSEDNAMES).toUpperCase().split(",");
        List<String> nameList = Arrays.asList(names);
        if(nameList.contains(abName.toUpperCase())){
            flag = true;
        }
        return flag;
    }
 
    /**
     * 检查该属性名是否属于数据库关键字
     * @param abName
     * @return
     */
    private boolean usedByDataBase(String abName){
        boolean flag = false;
        String[] names = UsedNames.getProperty(DATABASEUSEDNAMES).toUpperCase().split(",");
        List<String> nameList = Arrays.asList(names);
        if(nameList.contains(abName.toUpperCase())){
            flag = true;
        }
        return flag;
    }
 
    /**
     * 删除属性
     * @param osAttributeDTOS
     * @return true成功,false失败
     */
    @Override
    public boolean deleteAttributes(List<OsAttributeDTO> osAttributeDTOS) throws PLException {
        VciBaseUtil.alertNotNull(osAttributeDTOS,"待删除的属性列表");
        //平台的deleteEnumTypes方法必传三个参数,oid、name和ts
        List<AttributeDef> attributeDefs = new ArrayList<>();
        for(OsAttributeDTO osAttributeDTO : osAttributeDTOS){
            //oid和ts判空
            String oid = osAttributeDTO.getOid();
            //name主要用来对缓存数据删除
            String name = osAttributeDTO.getName();
            Date ts = osAttributeDTO.getTs();
            if(Func.isBlank(oid) || Func.isBlank(name) || Func.isEmpty(ts)){
                throw new PLException("500",new String[]{"待删除的属性列表中主键【oid】、调整时间【ts】、属性名【name】不能为空!"});
            }
            //判断属性是否有被引用
            List<Map<String, String>> usedAttrList = this.getUsedAttributeList(name);
            if(Func.isNotEmpty(usedAttrList)){
                throw new PLException("500",new String[]{"删除的属性中,属性名称为:【" + name + "】,已被引用!"});
            }
            AttributeDef attributeDef = new AttributeDef();
            attributeDef.oid = oid;
            attributeDef.name = name;
            attributeDef.ts = Func.format(ts,VciDateUtil.DateTimeMillFormat);
            attributeDefs.add(attributeDef);
        }
        if(Func.isEmpty(attributeDefs)){
            return false;
        }
        return platformClientUtil.getAttributeService().deleteAttributeDefs(attributeDefs.toArray(new AttributeDef[attributeDefs.size()]));
    }
 
    /**
     * 查看属性的使用范围
     * @param attributeName
     * @return key:属性 ,value使用该属性的业务类型
     */
    @Override
    public List<Map<String, String>> getUsedAttributeList(String attributeName) throws PLException {
        if(Func.isBlank(attributeName)){
            throw new PLException("500",new String[]{"请选择要查询应用范围的属性!"});
        }
        String[] btNames = platformClientUtil.getBtmService().getBTNamesByAPName(attributeName);
        String[] ltNames = platformClientUtil.getLinkTypeService().getLTNamesByAPName(attributeName);
        String[] mergedArray = Stream.concat(Stream.of(btNames), Stream.of(ltNames)).toArray(String[]::new);
 
        if(Func.isEmpty(mergedArray)){
            return new ArrayList<>();
        }
        List<Map<String,String>> btmNameMapList = new ArrayList<>();
        Arrays.stream(mergedArray).forEach(btName->{
            Map<String, String> itemMap = new HashMap<>();
            itemMap.put("attributeName",attributeName);
            itemMap.put("source",btName);
            btmNameMapList.add(itemMap);
        });
        return btmNameMapList;
    }
 
    /**
     * 导出选中的属性
     * @param exportFileName 导出的文件名
     * @param attrNames 需要导出的属性名称
     * @param flag 控制导出的列名是否和导入模板一致
     * @return
     */
    @Override
    public String exportAttributes(String exportFileName, String attrNames,boolean flag/*控制导出的列名是否和导入模板一致*/) throws PLException {
        if(Func.isBlank(attrNames)){
            throw new PLException("500",new String[]{"请勾选要导出的属性!"});
        }
        //界面没传名称,使用默认导出名称
        exportFileName = Func.isBlank(exportFileName) ?  "属性池中属性导出_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
        //设置列名
        List<String> columns = this.getCloumns(flag);
 
        //写excel
        String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName +  ".xls";
        try {
            new File(excelPath).createNewFile();
        } catch (Throwable e) {
            throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
        }
        //设置列
        List<WriteExcelData> excelDataList = new ArrayList<>();
        //设置列头
        for (int index = 0; index < columns.size(); index++) {
            excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
        }
        //按照属性名查询属性,然后处理属性导出
        List<String> attrameList = Func.toStrList(attrNames);
        List<OsAttributeVO> osAttributeVOS = this.listAttrByIds(attrameList);
        if(Func.isEmpty(osAttributeVOS)){
            excelDataList.add(new WriteExcelData(1,1, "根据属性名称未查询到属性信息,请刷新后尝试重新导出!"));
        }else{
            //先按照属性类型排序,不同属性类型导出的数据乱的效果
            osAttributeVOS.sort(Comparator.comparing(OsAttributeVO::getAttributeDataType));
            for (int i = 0; i < osAttributeVOS.size(); i++) {
                OsAttributeVO osAttributeVO = osAttributeVOS.get(i);
                excelDataList.add(new WriteExcelData(i+1,0, osAttributeVO.getId()));
                excelDataList.add(new WriteExcelData(i+1,1, osAttributeVO.getName()));
                excelDataList.add(new WriteExcelData(i+1,2, osAttributeVO.getDescription()));
                if(flag){
                    excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()));
                }else{
                    excelDataList.add(new WriteExcelData(i+1,3, osAttributeVO.getAttributeDataType()+"("+osAttributeVO.getAttributeDataTypeText()+")"));
                }
                excelDataList.add(new WriteExcelData(i+1,4, osAttributeVO.isNullableFlag()));
                excelDataList.add(new WriteExcelData(i+1,5, osAttributeVO.getDefaultValue()));
                excelDataList.add(new WriteExcelData(i+1,6, osAttributeVO.getEnumId()));
                //excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getEnumName()));
                excelDataList.add(new WriteExcelData(i+1,7, osAttributeVO.getBtmTypeId()));
                //excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getBtmTypeName()));
                excelDataList.add(new WriteExcelData(i+1,8, osAttributeVO.getAttrLength()));
                excelDataList.add(new WriteExcelData(i+1,9, osAttributeVO.getLinkTypeName()));
                excelDataList.add(new WriteExcelData(i+1,10, osAttributeVO.getVersion()));
                excelDataList.add(new WriteExcelData(i+1,11, osAttributeVO.getPrecisionLength()));
                excelDataList.add(new WriteExcelData(i+1,12, osAttributeVO.getScaleLength()));
                excelDataList.add(new WriteExcelData(i+1,13, osAttributeVO.getRange()));
                if(!flag){
                    excelDataList.add(new WriteExcelData(i+1,14, Func.format(osAttributeVO.getCreateTime(),"yyyy年MM月dd日 hh:mm:ss")));
                }
            }
        }
        WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
        ExcelUtil.writeDataToFile(excelPath, excelOption);
        return excelPath;
    }
 
    /**
     * 获取导出或导入模板的列名
     * @param flag 是否获取导入模板列名
     * @return
     */
    private List<String> getCloumns(boolean flag){
        if(flag){
            return new ArrayList<>(
                    Arrays.asList("属性名", "标签", "描述",
                            "属性类型(参照新增界面的属性类型如VTString)", "允许为空(是/否)", "默认值", "使用的枚举英文名称"
                            , "参照的业务类型编号","参照的链接类型编号","版本版次","属性长度", "小数精度位数","小数刻度位数"
                            ,"取值范围"
                    )
            );
        }
        return new ArrayList<>(
                Arrays.asList("属性名", "标签", "描述",
                        "属性类型", "允许为空", "默认值", "使用的枚举英文名称(枚举名)",
                        "参照的业务类型编号", "参照的链接类型编号","版本版次","属性长度",
                        "小数精度位数","小数刻度位数","取值范围","创建时间")
        );
    }
 
    /**
     * 下载属性导入模板
     * @param exportFileName
     * @return
     * @throws PLException
     */
    @Override
    public String downloadAttributeTemplate(String exportFileName) throws Exception {
        //界面没传名称,使用默认导出名称
        exportFileName = Func.isBlank(exportFileName) ?  "属性池导入模板_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss"):exportFileName;
        //设置列名
        List<String> columns = this.getCloumns(true);
        //设置必填列
        ColumnNameisRed.clear();
        ColumnNameisRed.add(0);
        ColumnNameisRed.add(3);
        ColumnNameisRed.add(10);
 
        //写excel
        String excelPath = LocalFileUtil.getDefaultTempFolder() + File.separator + exportFileName +  ".xls";
        try {
            new File(excelPath).createNewFile();
        } catch (Throwable e) {
            throw new VciBaseException(LangBaseUtil.getErrorMsg(e), new String[]{excelPath}, e);
        }
        //设置列
        List<WriteExcelData> excelDataList = new ArrayList<>();
        //设置列头
        for (int index = 0; index < columns.size(); index++) {
            //判断是否为必填列,给必填列设置颜色
            if(ColumnNameisRed.contains(index)){
                WriteExcelData excelData = new WriteExcelData(0, index, columns.get(index));
                excelData.setFontColor(String.valueOf(HSSFColor.HSSFColorPredefined.RED.getIndex()));
                excelDataList.add(excelData);
            }else{
                excelDataList.add(new WriteExcelData(0,index, columns.get(index)));
            }
        }
        WriteExcelOption excelOption = new WriteExcelOption(excelDataList);
        ExcelUtil.writeDataToFile(excelPath, excelOption);
        return excelPath;
    }
 
    /**
     * 导入属性
     * @param file
     * @param isContinue 系统中出现重复是否跳过报错继续执行
     * @return
     * @throws Exception
     */
    @Override
    public BaseResult importAttributes(File file, boolean isContinue) throws Exception{
        VciBaseUtil.alertNotNull(file,"excel文件");
        if(!file.exists()){
            throw new VciBaseException("导入的excel文件不存在,{0}",new String[]{file.getPath()});
        }
        try{
            //1、读取excel中的数据,组成对象
            ReadExcelOption excelOption = new ReadExcelOption();
            List<OsAttributePO> poList = ExcelUtil.readDataObjectFromExcel(file, OsAttributePO.class,excelOption,(value, po, fieldName)->{});
            //去除都是空的情况
            if(CollectionUtils.isEmpty(poList)){
                return BaseResult.fail(ExcelLangCodeConstant.IMPORT_CONTENT_NULL,new String[]{});
            }
            //excel判重,数据校验,dto对象转换,存储对象转换,执行保存
            List<OsAttributeDTO> dtoList = new ArrayList<>();
            //当前excel中是否重复用的判重Map:(key:判重属性,value:行号)
            Map<String, String> excelReapeat = new HashMap<>();
            for (int i = 0; i < poList.size(); i++) {
                OsAttributePO osAttributePO = poList.get(i);
                if(Func.isBlank(osAttributePO.getId())){//属性名判空
                    throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,attrnameerror");
                }else if(Func.isBlank(osAttributePO.getAttributeDataType())){
                    throw new VciBaseException("第【"+osAttributePO.getRowIndex()+"】行,typeerror");
                }else if(excelReapeat.containsKey(osAttributePO.getId())){//属性名表格中判重
                    throw new VciBaseException("第【"+excelReapeat.get(osAttributePO.getId())+"】行和第【"+osAttributePO.getRowIndex()+"】行数据,属性名重复");
                }else {
                    try {
                        if(platformClientUtil.getAttributeService().checkRowIsExists(osAttributePO.getId())){
                            throw new PLException("500",new String[]{"属性名称【" + osAttributePO.getId() + "】在系统中已存在!"});
                        }
                    } catch (PLException e) {
                        e.printStackTrace();
                        String errorMsg = "与系统中属性名查重时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
                        logger.error(errorMsg);
                        //是否跳过当期重复数据
                        if(isContinue){
                            continue;
                        }
                        throw new VciBaseException(errorMsg);
                    }
                }
                //属性名校验
                try {
                    checkName(osAttributePO.getId());
                } catch (PLException e) {
                    e.printStackTrace();
                    throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
                }
                //属性名excel中判重处理
                excelReapeat.put(osAttributePO.getId(),osAttributePO.getRowIndex());
                OsAttributeDTO osAttributeDTO = new OsAttributeDTO();
                //查询属性是否存在,填写了枚举但没填写取值范围,这时候直接使用枚举项值作为默认的range
                if(Func.isNotBlank(osAttributePO.getEnumId()) && Func.isBlank(osAttributePO.getRange())){
                    try {
                        OsEnumVO enumVO = enumService.getEnumTypeById(osAttributePO.getEnumId());
                        if(Func.isEmpty(enumVO)){
                            throw new VciBaseException("第【" + osAttributePO.getRowIndex() + "】行数据,通过枚举名称【" + osAttributePO.getEnumId()
                                    + "】未获取到枚举信息!");
                        }
                        String itemValues = enumVO.getItemMaps().values().stream().collect(Collectors.joining(";"));
                        osAttributeDTO.setRange(itemValues);
                    } catch (PLException e) {
                        e.printStackTrace();
                        throw new VciBaseException("枚举查询失败,原因:"+e.getMessage());
                    }
                    osAttributeDTO.setBtmTypeId(osAttributePO.getEnumId());
                }
                osAttributeDTO.setOid(ObjectUtility.getNewObjectID36());
                osAttributeDTO.setId(osAttributePO.getId());
                osAttributeDTO.setName(osAttributePO.getName());
                osAttributeDTO.setDescription(osAttributePO.getDescription());
                osAttributeDTO.setDefaultValue(osAttributePO.getDefaultValue());
                osAttributeDTO.setAttrLength(osAttributePO.getAttrLength());
                osAttributeDTO.setAttributeDataType(osAttributePO.getAttributeDataType());
                osAttributeDTO.setBtmTypeId(osAttributePO.getBtmTypeId());
                //osAttributeDTO.setBtmTypeName(osAttributePO.getBtmname());
                osAttributeDTO.setLinkTypeName(osAttributePO.getLinkTypeName());
                osAttributeDTO.setVersion(osAttributePO.getVersion());
                osAttributeDTO.setEnumId(osAttributePO.getEnumId());
                //osAttributeDTO.setEnumName(osAttributePO.getEnumId());
                osAttributeDTO.setPrecisionLength(osAttributePO.getPrecisionLength());
                osAttributeDTO.setScaleLength(osAttributePO.getScaleLength());
                osAttributeDTO.setRange(osAttributePO.getRange());
                osAttributeDTO.setNullableFlag("是".equals(osAttributePO.getNullableFlag()) ? true:false);
                try {
                    //检查默认值与属性类型是否匹配
                    checkDefValue(osAttributeDTO);
                } catch (PLException e) {
                    e.printStackTrace();
                    throw new VciBaseException(VciBaseUtil.getExceptionMessage(e));
                }
                dtoList.add(osAttributeDTO);
            }
            //执行保存操作
            dtoList.stream().forEach(dto->{
                try {
                    boolean b = platformClientUtil.getAttributeService().addAttributeDef(osAttributeDTO2AttributeDef(dto));
                    if(!b){
                        throw new VciBaseException("save and return false");
                    }
                } catch (PLException e) {
                    e.printStackTrace();
                    throw new VciBaseException("执行保存时出现错误,错误属性对象名为:【" + dto.getId() + "】,原因:"+VciBaseUtil.getExceptionMessage(e));
                }
            });
        }catch (Exception e){
            if(logger.isErrorEnabled()){
                logger.error("读取excel内容时或保存属性时出现了错误,具体原因:",VciBaseUtil.getExceptionMessage(e));
            }
            e.printStackTrace();
            return BaseResult.fail(VciBaseUtil.getExceptionMessage(e),new String[]{},e);
        }
        return BaseResult.success("属性导入成功!");
    }
 
    /**
     * 是否默认的属性
     *
     * @param attr 属性编号
     * @return true表示是默认属性
     */
    @Override
    public boolean isDefaultAttr(String attr) {
        if(StringUtils.isBlank(attr)){
            return  false;
        }
        return getDefaultAttributeVOMap().containsKey(attr.toLowerCase(Locale.ROOT));
    }
 
    /**
     * 根据业务类型获取属性信息
     * @param btName 业务类型/链接类型
     * @param typeFlag 0:业务类型,1:链接类型
     * @return
     */
    @Override
    public List<OsAttributeVO> getOsAttributeVOSByBtName(String btName, int typeFlag,boolean isDefault) throws Exception{
        VciBaseUtil.alertNotNull(btName,"参数不允许为空",typeFlag,"参数不允许为空");
        List<OsAttributeVO> attributeVOS=new ArrayList<>();
 
        try {
            List<AttributeDef> attributeDefList=new ArrayList<>();
            if(typeFlag==0){
                AttributeDef [] attributeDefs=    platformClientUtil.getBtmService().getAttributeDefs(btName);
                if(attributeDefs!=null){
                    attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList()));
                }
                if(isDefault){
                    AttributeDef [] sysAttributeDefs=platformClientUtil.getBtmService().getSysAttributeDefs();
                    if(sysAttributeDefs!=null){
                        attributeDefList.addAll(Arrays.stream(sysAttributeDefs).collect(Collectors.toList()));
                    }
                }
            }else{
                AttributeDef []    attributeDefs=platformClientUtil.getLinkTypeService().getAttributes(btName);
                if(attributeDefs!=null){
                    attributeDefList.addAll(Arrays.stream(attributeDefs).collect(Collectors.toList()));
                }
                if(isDefault){
                    AttributeDef[] sysAbItems = platformClientUtil.getLinkTypeService().getSysAttributeDefs();
                    if(sysAbItems!=null){
                        attributeDefList.addAll(Arrays.stream(sysAbItems).collect(Collectors.toList()));
                    }
                }
            }
            attributeVOS=attributeDO2VOs(attributeDefList);
        }catch (PLException e){
            throw new Exception("根据业务类型获取属性异常"+e.getMessage());
        }
 
        return attributeVOS;
    }
 
    /**
     * 是否为参照属性
     * @param other 配置的其他
     * @return true 是参照
     */
    private boolean isReferAttr(String other){
        if(StringUtils.isNotBlank(other)
                && (other.toLowerCase().contains("btm") || other.toLowerCase().contains("link"))){
            //还不能确定,因为枚举的时候也会设置btm
            String[] temp = other.split(";");
            for(String s : temp){
                if((s.contains("btm") || s.contains("link")) && s.split("=").length>1){
                    return true;
                }
            }
        }
        return false;
    }
 
    /**
     * 是否为枚举的属性
     * @param other 配置的内容
     * @return true 是枚举
     */
    private boolean isEnumAttr(String other){
        if(StringUtils.isNotBlank(other)
                && other.contains("enumName")){
            //还不能确定,因为枚举的时候也会设置btm
            String[] temp = other.split(";");
            for(String s : temp){
                if(s.contains("enumName")&& s.split("=").length>1){
                    return true;
                }
            }
        }
        return false;
    }
 
    /**
     * 清除缓存
     */
    @Override
    public void clearCache() {
 
    }
 
    /**
     * 调用修改业务类型和连接类型中对应属性名的属性
     * @param apName
     * @return
     * @throws PLException
     */
    private boolean alterAp(String apName) throws PLException {
        return osBtmService.alterAp(apName) && osLinkTypeServiceI.alterAp(apName);
    }
 
}