ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.server.omd.biztype.service;
 
import org.dom4j.Element;
import com.vci.corba.omd.btm.BTMService;
import com.vci.corba.omd.btm.BtmItem;
import com.vci.corba.omd.attribpool.AttribItem;
import com.vci.common.log.ServerWithLog4j;
import com.vci.corba.common.VCIError;
import com.vci.omd.utils.OmdTools;
import com.vci.server.cache.OMCacheProvider;
import com.vci.server.omd.btm.BTMServiceImpl;
import com.vci.server.omd.btm.resource.BtmTool;
 
 
/**
 * 对外部提供业务类型的属性列表
 * 获取属性的数据类型, 属性: 系统属性, 属性池属性
 * 
 */
public class BtmHelper {
    private static BTMService btmService = null;
 
    
    /**
     * 业务类型的系统属性
     */
    private static String otherFieldBt = "\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";
 
    
    
    private BtmHelper(){
    }
    
    
    private static BTMService getService(){
        try {
            if (btmService == null) {
                btmService = new BTMServiceImpl();
            }
 
            if (btmService == null)
            {
                ServerWithLog4j.logger.error("BtmProvider.getService, 获取【btmService】失败");
            }
 
            return btmService;
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return btmService;
    }
    
 
 
 
 
    /**
     * 获取属性other中type的值
     * @param other
     * @param type
     * @return
     */
//    public static String getOtherValueByType(String other, String type){
//        String[] otherArray = other.split(";");
//        for(int i = 0; i < otherArray.length; i++){
//            String otherValue = otherArray[i];
//            if(otherValue.contains(type)){
//                return otherValue.substring(otherValue.indexOf("=") + 2, otherValue.length());
//            }
//        }
//        return null;
//        
//    }
    
    /**
     * 获取属性字段的sql语句
     * @param array
     * @return
     */
//    public static String getAbSql(AttribItem abItem){
//        String sql = "";
//        if(abItem == null){
//            return sql;
//        }
//        String abName = abItem.name;
//        String vtType = abItem.vtDataType;
//        String other = abItem.other;
//        String defValue = abItem.defValue;
//        
//        if(vtType.equals("VTString")){
//            int length = 50;
//            String lengthStr = AttributeHelper.getOtherValueByType(other, "length");
//            if(lengthStr != null && !lengthStr.equals("")){
//                length = Integer.valueOf(lengthStr);
//            }
//            sql += abName.toUpperCase() + " VARCHAR2(" + length + ")";
//            if(!defValue.equals("")){
//                sql += " default '" + defValue + "'";
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTInteger") || vtType.equals("VTLong")){
//            sql += abName.toUpperCase() + " NUMBER";
//            if(!defValue.equals("")){
//                sql += " default " + defValue;
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDouble")){
//            int length = 20;
//            String lengthStr = AttributeHelper.getOtherValueByType(other, "length");
//            if(lengthStr != null && !lengthStr.equals("")){
//                length = Integer.valueOf(lengthStr);
//            }
//            
//            int accuracy = 2;
//            String accuracyStr = AttributeHelper.getOtherValueByType(other, "accuracy");
//            if(accuracyStr != null && !accuracyStr.equals("")){
//                accuracy = Integer.valueOf(accuracyStr);
//            }
//            sql += abName.toUpperCase() + " NUMBER(" + length + ", " + accuracy +")";
//            if(!defValue.equals("")){
//                sql += " default " + defValue;
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTBoolean")){
//            sql += abName.toUpperCase() + " VARCHAR2(8)";
//            if(!defValue.equals("")){
//                sql += " default '" + defValue + "'";
//            }
//            sql += ",\n\t";
//        }else if(vtType.equals("VTImage")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDate")){
//            sql += abName.toUpperCase() + " DATE";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTTime")){
//            sql += abName.toUpperCase() + " TIMESTAMP";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTDateTime")){
//            sql += abName.toUpperCase() + " TIMESTAMP";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTNote")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTFilePath")){
//            sql += abName.toUpperCase() + " VARCHAR2(255)";
//            sql += ",\n\t";
//        }else if(vtType.equals("VTClob")){
//            sql += abName.toUpperCase() + " CLOB";
//            sql += ",\n\t";
//        }
//        
//        return sql;
//    }
    
    /**
     * 生成创建业务类型的DDL
     * @param btm
     * @return
     */
    public static String getCreateBTMTableSql(BtmItem btm){
        String btmName = btm.name;
        String btmTableName = OmdTools.getBTMTableName(btmName);
        String sql = "create Table " + btmTableName + "(" + otherFieldBt;
        String[] apNames = null;
        try {
            apNames = getService().getBtmApNameArray(btmName, null);
        } catch (VCIError e) {
            e.printStackTrace();
        }
        if(apNames != null && apNames.length != 0){
            for(int k = 0; k < apNames.length; k++){
                String abName = apNames[k];
                AttribItem abItem = null;
 
                abItem = OMCacheProvider.getAttribute(abName);
 
                String abSql = BtmTool.getInstance().getAbSql(abItem);
                sql += abSql;
            }
        }
        
        sql = sql.substring(0, sql.lastIndexOf(","));
        sql += "\n)";
        return sql;
    }
    /**
     * 将业务类型树导出为.sql文件
     * add by caill 2015.12.21
     * */
//    public boolean expBtmDataSql(String dir, BtmItem[] allBtmItems) throws VCIError {
//        new File(dir).mkdir();
//        File file = new File(dir + "/platformBtm.sql");
//        FileWriter w = null;;
//        BufferedWriter bw = null;
//        try {
//            w = new FileWriter(file);
//            bw = new BufferedWriter(w);
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        
//        for(int i = 0; i < allBtmItems.length; i++){
//            String sql = getBTMTableSqlByName(allBtmItems[i]);
//            try {
//                bw.write(sql);
//                bw.write("\r\n");
//            } catch (IOException e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }    
//        }
//        try {
//            bw.flush();
//            bw.close();
//            return true;
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
//        
//        
//        return false;
//    }
 
    /**
     * 生成业务类型导出为.sql文件的sql语句 add by caill 2015.12.21
     * @param btm
     * @return
     */
//    public String getBTMTableSqlByName(BtmItem allBtmItem){
//        String btmTableName = OmdTools.getBTMTableName(allBtmItem.name);
//        String sql = "create Table " + btmTableName + "(" + otherFieldBt;
//        String[] apNames = null;
//        try {
//            apNames = getService().getBtmApNameArray(allBtmItem.name, null);
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
//        if(apNames != null && apNames.length != 0){
//            for(int k = 0; k < apNames.length; k++){
//                String abName = apNames[k];
//                AttribItem abItem = null;
//
//                abItem = OMCacheProvider.getAttribute(abName);
//
//                String abSql = BtmTool.getInstance().getAbSql(abItem);
//                sql += abSql;
//            }
//        }
//        
//        sql = sql.substring(0, sql.lastIndexOf(","));
//        sql += "\n);";
//        sql += "\r\ncomment on table "+btmTableName+" is '"+allBtmItem.label +"';";    //添加表注释
//        if(apNames != null && apNames.length != 0){
//            for(int k = 0; k < apNames.length; k++){
//                String abName = apNames[k];
//                AttribItem abItem = null;
//
//                abItem = OMCacheProvider.getAttribute(abName);
//
//                sql += "\r\ncomment on column "+btmTableName+"."+abItem.name+" is '"+ abItem.label +"';";
//            }
//        }
//        return sql;
//    }
    
    /**
     * 获取增加主键sql
     * @param typeName
     * @return
     */
    public static String getAddPKSql(String typeName){
        return "alter table " + OmdTools.getBTMTableName(typeName) + " add constraint PKBTM_" + typeName + " primary key (OID)\n";
    }
    
    /**
     * Array-->List
     * @param array
     * @return
     */
//    public List<String> parseArrayToList(String[] array){
//        List<String> list = new ArrayList<String>();
//        for(int i = 0; i < array.length; i++){
//            list.add(array[i]);
//        }
//        return list;
//    }
    
    /**
     * Array-->List
     * @param array
     * @return
     */
//    public List<Integer> parseArrayToList(int[] array){
//        List<Integer> list = new ArrayList<Integer>();
//        for(int i = 0; i < array.length; i++){
//            list.add(array[i]);
//        }
//        return list;
//    }
    
    /**
     * Array-->String
     * @param array
     * @return
     */
    public static String arrayTOString(String[] array){
        String str = "";
        if(array != null && array.length > 0){
            for(int i = 0; i < array.length; i++){
                str += array[i];
                str += ",";
            }
            str = str.substring(0, str.lastIndexOf(","));
        }
        return str;
    }
 
    /**
     * 将bt转化成xmltext
     * @param o
     * @return
     */
    public static String getXmlText(BtmItem o){
        String apNameArray = arrayTOString(o.apNameArray);
        String lifeCycles = arrayTOString(o.lifeCycles);
        StringBuilder stb = new StringBuilder("<btm>");
        stb.append("<name>" + o.name + "</name>");
        stb.append("<label>" + o.label + "</label>");
        stb.append("<description>" + o.description + "</description>");
        stb.append("<isAbstract>" + o.isAbstract + "</isAbstract>");
        stb.append("<shape>" + o.shape + "</shape>");
        stb.append("<implClass>" + o.implClass + "</implClass>");
        stb.append("<fName>" + o.fName + "</fName>");
        stb.append("<lifeCycle>" + o.lifeCycle + "</lifeCycle>");
        stb.append("<imageName>" + o.imageName + "</imageName>");
        stb.append("<revLevel>" + o.revLevel + "</revLevel>");
        stb.append("<revRuleName>" + o.revRuleName + "</revRuleName>");
        stb.append("<revInput>" + o.revInput + "</revInput>");
        stb.append("<delimiter>" + o.delimiter + "</delimiter>");
        stb.append("<verRuleName>" + o.verRuleName + "</verRuleName>");
        stb.append("<apNameArray>" + apNameArray + "</apNameArray>");
        stb.append("<lifeCycles>" + lifeCycles + "</lifeCycles>");
        stb.append("</btm>");
        return stb.toString();
    }
 
    /**
     * 设置EnumItem存在
     * @param att
     * @param element
     */
    public static void setBTValueFormDoc(BtmItem bt, Element element){
        String value = element.elementText("isAbstract");
        bt.isAbstract = (value == null ? false : Boolean.valueOf(value));
        value = element.elementText("fName");
        bt.fName = (value == null ? "" : value);
        value = element.elementText("implClass");
        bt.implClass = (value == null ? "" : value);
        value = element.elementText("shape");
        bt.shape = (value == null ? "" : value);
        value = element.elementText("lifeCycle");
        bt.lifeCycle = (value == null ? "" : value);
        value = element.elementText("lifeCycles");
        if(value != null && !value.equals("")){
            bt.lifeCycles = value.trim().split(",");
        }else{
            bt.lifeCycles = new String[0];
        }
        value = element.elementText("imageName");
        bt.imageName = (value == null ? "" : value);
        value = element.elementText("revLevel");
        bt.revLevel = (value == null ? 0 : Short.valueOf(value));
        value = element.elementText("revRuleName");
        bt.revRuleName = (value == null ? "" : value);
        value = element.elementText("revInput");
        bt.revInput = (value == null ? false : Boolean.valueOf(value));
        value = element.elementText("delimiter");
        bt.delimiter = (value == null ? "" : value);
        value = element.elementText("verRuleName");
        bt.verRuleName = (value == null ? 0 : Short.valueOf(value));
        value = element.elementText("apNameArray");
        if(value != null && !value.equals("")){
            bt.apNameArray = value.trim().split(",");
        }else{
            bt.apNameArray = new String[0];
        }
    }
 
    
    /**
     * 设置索引
     * @param typeName
     * @param indexAttr
     * @return
     */
    public String getAddIndex(String typeName,String[] indexAttr){
        String sql = "create unique INDEX "+indexAttr[0]+" on " + OmdTools.getBTMTableName(typeName) + "(" + indexAttr[1] + ")\n";
        return sql;
    }
    /**
     * 修改索引
     * @param typeName
     * @param indexAttr
     * @return
     */
    public String getDropIndex(String typeName,String[] indexAttr){
        String sql = "drop INDEX "+indexAttr[0]+" \n";
        return sql;
    }
}