wangting
2025-01-16 18c43123b51a1688ab4ae01fe3d171c7d92e619b
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
package com.vci.client.bof;
 
import java.util.HashMap;
 
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.omd.attribpool.toOutside.Tool;
import com.vci.client.omd.provider.ApProvider;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.omd.constants.BusinessConstants;
import com.vci.omd.constants.LinkConstants;
 
public class AttributeChecker {
 
    public static HashMap<String, AttribItem> attrItemMap = new HashMap<String, AttribItem>();
    public static AttribItem[] attrItems = null;
    
    public void getAllAttribute() {
        if (attrItems == null) {
            attrItems = ApProvider.getInstance().getAllAbItems();
            for (AttribItem attrItem : attrItems) {
                attrItemMap.put(attrItem.name, attrItem);
            }
        }
    }
    
    /**
     * 判断传入的属性值是否符合值域要求
     * @param attrName
     * @param attrVal
     * @return 0:代表符合;1代表长度不符合要求;2代表值不符合要求;3代表值和长度均不符合要求
     */
    public int isAttrValValid(String attrName, String attrVal) {
        if (BusinessConstants.BO_CONSTANTS.containsKey(attrName.toUpperCase())
                || LinkConstants.LO_CONSTANTS.containsKey(attrName.toUpperCase())) {
            return 0;
        } else if (attrVal == null || attrVal.trim().equals("")) {
            return 0;
        }
        getAllAttribute();
        
        int rs = 0;
        AttribItem attrItem = attrItemMap.get(attrName);
        if (attrItem == null) {
            return 0;
        }
        String attrType = attrItem.vtDataType;
        if (attrType.equals("VTString")){
            rs = checkVTStringValValid(attrItem, attrName, attrVal);
        } else if (attrType.equals("VTInteger")){
            rs = checkVTIntegerValValid(attrItem, attrName, attrVal);
        } else if (attrType.equals("VTLong")){
            rs = checkVTLongValValid(attrItem, attrName, attrVal);
        } else if (attrType.equals("VTDouble")){
            rs = checkVTDoubleValValid(attrItem, attrName, attrVal);
        } else if (attrType.equals("VTBoolean")){
            rs = 0;
        } else if (attrType.equals("VTImage")){
            rs = 0;
        } else if (attrType.equals("VTDate")){
            rs = 0;
        } else if (attrType.equals("VTTime")){
            rs = 0;
        } else if (attrType.equals("VTDateTime")) {
            rs = 0;
        } else if (attrType.equals("VTNote")){
            rs = 0;
        } else if (attrType.equals("VTFilePath")) {
            rs = 0;
        } else {
            rs = 0;
        }
        
        return rs;
    }
    
    /**
     * 判断VTString类型的属性值是否符合校验要求
     * @param attrName
     * @param attrVal
     * @return
     */
    private int checkVTStringValValid(AttribItem attrItem, String attrName, String attrVal) {
        String other = attrItem.other;
        int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")).intValue();
        int length = attrVal.length();
        if (length > maxLength) {
            return 1;
        } else {
            return 0;
        }
    }
    
    /**
     * 判断VTInteger类型的属性值是否符合校验要求
     * @param attrName
     * @param attrVal
     * @return
     */
    private int checkVTIntegerValValid(AttribItem attrItem, String attrName, String attrVal) {
        VTInteger obj = new VTInteger(Integer.valueOf(attrVal).intValue());
        if (!obj.checkRageValueByRage(attrItem.rage)) {
            return 2;
        } else {
            return 0;
        }
    }
    
    /**
     * 判断VTLong类型的属性值是否符合校验要求
     * @param attrName
     * @param attrVal
     * @return
     */
    private int checkVTLongValValid(AttribItem attrItem, String attrName, String attrVal) {
        VTLong obj = new VTLong(Long.valueOf(attrVal).longValue());
        if (!obj.checkRageValueByRage(attrItem.rage)) {
            return 2;
        } else {
            return 0;
        }
    }
    
    /**
     * 判断VTDouble类型的属性值是否符合校验要求
     * @param attrName
     * @param attrVal
     * @return
     */
    private int checkVTDoubleValValid(AttribItem attrItem, String attrName, String attrVal) {
        VTDouble obj = new VTDouble(Double.valueOf(attrVal));
        String other = attrItem.other;
        int maxLength = Integer.valueOf(Tool.getOtherValueByType(other, "length")).intValue();
        int length = String.valueOf(attrVal).length() - 1;
        
        if (length >= maxLength && !obj.checkRageValueByRage(attrItem.rage)) {
            return 3;
        } else if (!obj.checkRageValueByRage(attrItem.rage)) {
            return 2;
        } else if (length >= maxLength) {
            return 1;
        } else {
            return 0;
        }
    }
}