田源
2024-03-07 4b4083fd73dc27ece42f4835483565eef0e4f608
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
package com.vci.server.base.utility;
 
import com.vci.corba.omd.atm.AttribItem;
import com.vci.omd.dataType.VTDataType;
import com.vci.server.cache.OMCacheProvider;
 
public class AttributeHelper {
 
    
    private AttributeHelper(){
        
    }
    
    /**
     * 获取属性的数据类型
     * @param abName
     * @return
     */
    public static String getAbItemDataType(String abName){
        String dataType = "VTString";
        
        if (abName == null || abName.equals("")) {
            return dataType;
        }
        if (abName.contains(".")) {
            abName = abName.substring(abName.lastIndexOf(".") + 1);
        }
        
        String abUpperName = abName.toUpperCase();
        //系统属性
        if(abUpperName.equals("OID") || abUpperName.equals("REVISIONOID") || abUpperName.equals("NAMEOID") || abUpperName.equals("BTMNAME")
                || abUpperName.equals("CREATOR") || abUpperName.equals("LASTMODIFIER") || abUpperName.equals("REVISIONRULE")
                || abUpperName.equals("VERSIONRULE") || abUpperName.equals("REVISIONVALUE") || abUpperName.equals("VERSIONVALUE")
                || abUpperName.equals("LCTID") || abUpperName.equals("LCSTATUS")
                || abUpperName.equals("ID") || abUpperName.equals("NAME") || abUpperName.equals("DESCRIPTION") 
                || abUpperName.equals("OWNER") || abUpperName.equals("CHECKINBY") 
                || abUpperName.equals("CHECKOUTBY") || abUpperName.equals("COPYFROMVERSION")
                || abUpperName.equals("F_OID") || abUpperName.equals("F_REVISIONOID") 
                || abUpperName.equals("F_NAMEOID") || abUpperName.equals("F_BTWNAME")
                || abUpperName.equals("T_OID") || abUpperName.equals("T_REVISIONOID") 
                || abUpperName.equals("T_NAMEOID") || abUpperName.equals("T_BTWNAME")){
            dataType = "VTString";
        } else if (abUpperName.equals("ISLASTR") || abUpperName.equals("ISFIRSTR")
                || abUpperName.equals("ISLASTV") || abUpperName.equals("ISFIRSTV")) {
            dataType = "VTBoolean";
        }else if(abUpperName.equals("REVISIONSEQ") || abUpperName.equals("VERSIONSEQ")){
            dataType = "VTInteger";
        }else if(abUpperName.equals("CREATETIME") || abUpperName.equals("LASTMODIFYTIME")
                || abUpperName.equals("TS") || abUpperName.equals("CHECKINTIME") || abUpperName.equals("CHECKOUTTIME")){
            dataType = "VTDateTime";
        //属性池中属性
        }else{        
            AttribItem attr = OMCacheProvider.getAttribute(abName);
            if (attr == null)
                return dataType;
            
            dataType = attr.vtDataType;
//            dataType = getService().getAttribItemDataType(abName, null);
        }
        return dataType;
    }
    
 
 
    /**
     * 获取other中指定项目的值
     * @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;
    }
    
    /**
     * 检查属性类型与属性值是否匹配
     * @param vtType
     * @param value
     * @return
     */
    public static boolean checkDataType(String vtType, String value){
        
        if(vtType.equals(VTDataType.VTSTRING)){
            try{
                String.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTINTEGER)){
            try{
                Integer.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTLONG)){
            try{
                Long.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }else if(vtType.equals(VTDataType.VTDOUBLE)){
            try{
                Double.valueOf(value);
            }catch(Exception e){
                return false;
            }
        }
    
        return true;
    }
 
//    
    /**
     * 将att转化成xmltext
     * @param bt
     * @return
     */
    public static String getXmlText(AttribItem att) {
        StringBuilder stb = new StringBuilder("<attribute>");
        stb.append("<name>" + att.name + "</name>");
        stb.append("<label>" + att.label + "</label>");
        stb.append("<description>" + att.description + "</description>");
        stb.append("<vtDataType>" + att.vtDataType + "</vtDataType>");
        stb.append("<defValue>" + att.defValue + "</defValue>");
        stb.append("<rage>" + att.rage + "</rage>");
        stb.append("<other>" + att.other + "</other>");
        stb.append("</attribute>");
        return stb.toString();
    }
 
}