田源
2025-01-16 39269c81905457378a73dc83050349d7a364a1f8
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.client.common.datatype;
 
import com.vci.client.common.providers.ServiceProvider;
import com.vci.common.log.ServerWithLog4j;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.atm.AttribItem;
import com.vci.omd.constants.AttributeConstants;
import com.vci.omd.dataType.VTDataType;
 
public class VTDouble extends VTDataType{
    //精度
    private int accuracy;
    //0: 手动输入; 1: 下拉框选择
    public static int accInMode;
    public static int accDefault;
    public static int accMax;
    
    //长度
    private int length;
    public static int lenInMode;
    public static int lenDefault;
    public static int lenMax;
    
    //默认值
    public static double defaultValue;
    public static int defVInMode;
    
    private double value;
    
    public double getValue(){
        return this.value;
    }
    
    public VTDouble(double value){
        this.value = value;
    }
    
    public boolean checkRageValueByAbName(String abName){
        AttribItem ab = null;
        try {
            ab = ServiceProvider.getOMDService().getAttributeService().getAttribItemByName(abName);
        } catch (VCIError e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        if(ab == null){
            return false;
        }
        String rage = ab.rage;
        return checkRageValueByRage(rage);
    }
    
    public boolean checkRageValueByRage(String rage){
        if(rage == null || rage.equals("")){
            return true;
        }
        String[] rages = rage.split(";");
        boolean rageFlag = false;
        //当该值等于 用!= 所限制的值时,不满足值域
        for(int i = 0; i < rages.length; i++){
            String rage_ = rages[i];
            if(rage_.contains("!=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf("=") + 1));
                if(rageUne == this.value){
                    return false;
                }
            }
        }
        //当满足!= 以外的任一条件时,既满足值域
        for(int i = 0; i < rages.length; i++){
            String rage_ = rages[i];
            if(rage_.contains("=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf("=") + 1));
                if(rageUne == this.value){
                    rageFlag = true;
                    break;
                }
            }
            if(rage_.contains(">") && !rage_.contains(">=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf(">") + 1));
                if(this.value > rageUne){
                    rageFlag = true;
                    break;
                }
            }
            if(rage_.contains(">=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf("=") + 1));
                if(this.value >= rageUne){
                    rageFlag = true;
                    break;
                }
            }
            if(rage_.contains("<") && !rage_.contains("<=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf("<") + 1));
                if(this.value < rageUne){
                    rageFlag = true;
                    break;
                }
            }
            if(rage_.contains("<=")){
                double rageUne = Double.valueOf(rage_.substring(rage_.indexOf("<") + 1));
                if(this.value <= rageUne){
                    rageFlag = true;
                    break;
                }
            }
        }
        
        return rageFlag;
    }
    
    /**
     * 检查value是否超过了 属性abName的最大长度
     * @return
     */
    public boolean beyondMaxLength(String abName){
        AttribItem ab = null;
        try {
            ab = ServiceProvider.getOMDService().getAttributeService().getAttribItemByName(abName);
        } catch (VCIError e) {
            //e.printStackTrace();
            ServerWithLog4j.logger.error(e);
        }
        if(ab == null){
            return false;
        }
        
        String other = ab.other;
        int maxLength = Integer.valueOf(AttributeConstants.getOtherValueByType(other, AttributeConstants.LENGTH));
        int length = String.valueOf(this.value).length() - 1;
        if(length >= maxLength){
            return true;
        }
        return false;
    }
}