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
package com.vci.server.bof.utils;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.sql.Clob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
 
import com.vci.corba.omd.atm.AttribItem;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
 
public class ServerObjectUtil {
    
    private static ServerObjectUtil instance = null;
 
    private ServerObjectUtil() {
 
    }
 
    public static synchronized ServerObjectUtil getInstance() {
        if (instance == null) {
            instance = new ServerObjectUtil();
        }
 
        return instance;
    }
    
 
    public static BusinessObject createBOByRS(AttribItem[] attrItems, ResultSet rs) throws SQLException {
        BusinessObject bo = new BusinessObject();
        
        int index = 1;
 
        bo.oid = rs.getString(index++);
        bo.revisionid = rs.getString(index++);
        bo.nameoid = rs.getString(index++);
        bo.btName = rs.getString(index++);
        bo.isLastR = rs.getInt(index++) != 0;
        bo.isFirstR = rs.getInt(index++) != 0;
        bo.isLastV = rs.getInt(index++) != 0;
        bo.isFirstV = rs.getInt(index++) != 0;
        bo.creator = rs.getString(index++);
        bo.createTime = rs.getTimestamp(index++).getTime();
        bo.modifier = rs.getString(index++);
        bo.modifyTime = rs.getTimestamp(index++).getTime();
        bo.revisionRule = rs.getString(index++);
        bo.versionRule = rs.getString(index++);
        bo.revisionSeq = rs.getShort(index++);
        bo.revisionValue = rs.getString(index++);
        bo.versionSeq = rs.getShort(index++);
        bo.versionValue = rs.getString(index++);
        bo.lctId = rs.getString(index++);
        bo.lcStatus = rs.getString(index++);
        bo.ts = rs.getTimestamp(index++).getTime();
        bo.id = rs.getString(index++);
        bo.name = rs.getString(index++);
        bo.description = rs.getString(index++);
        bo.owner = rs.getString(index++);
        bo.fromVersion = rs.getString(index++);
 
        ArrayList<AttributeValue> list = new ArrayList<AttributeValue>();
        for (int i = 0; i < attrItems.length; i++) {
            AttributeValue attrVal = new AttributeValue();
            attrVal.attrName = attrItems[i].name;
            attrVal.attrVal = rs.getString(index++);
            list.add(attrVal);
        }
        bo.newAttrValList = new AttributeValue[0];
        bo.hisAttrValList = list.toArray(new AttributeValue[list.size()]);
        
        return bo;
    }
    
    
 
    public String tansferSystemDBDateToString(Map<String, String> attrType, String attributeName, Object value) {
        if (value == null) {
            return "";
        }
        String rsValue = "";
        String dType = attrType.get(attributeName);
        try {
            if (dType.equals("VTString")){
                rsValue = value.toString();
            } else if (dType.equals("VTInteger")){
                rsValue = ((BigDecimal)value).toString();
            } else if (dType.equals("VTLong")){
                rsValue = ((BigDecimal)value).toString();
            } else if (dType.equals("VTDouble")){
                rsValue = ((BigDecimal)value).toString();
            } else if (dType.equals("VTBoolean")){
                rsValue = (String)value;
            } else if (dType.equals("VTImage")){
                rsValue = (String)value;
            } else if (dType.equals("VTDate")){
//                rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
                if (value instanceof java.sql.Date) {
                    long time = ((java.sql.Date)value).getTime();
                    rsValue = ((Long)time).toString();
                } else if (value instanceof java.sql.Timestamp){
                    long time = ((java.sql.Timestamp)value).getTime();
                    rsValue = ((Long)time).toString();
                }
            } else if (dType.equals("VTTime")){
//                rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
                rsValue = ((java.sql.Timestamp)value).toString();
            } else if (dType.equals("VTDateTime")) {
//                rsValue = String.valueOf(((java.sql.Timestamp)value).getTime());
                if (value instanceof java.sql.Date) {
                    long time = ((java.sql.Date)value).getTime();
                    rsValue = ((Long)time).toString();
                } else if (value instanceof java.sql.Timestamp){
                    long time = ((java.sql.Timestamp)value).getTime();
                    rsValue = ((Long)time).toString();
                }
            } else if (dType.equals("VTNote")){
                rsValue = (String)value;
            } else if (dType.equals("VTFilePath")) {
                rsValue = (String)value;
            }  else if (dType.equals("VTClob")) {
                rsValue = clobToString((java.sql.Clob)value);
            } else {
                rsValue = (String)value;
            }
        } catch (Exception e) {
            rsValue = "";
            e.printStackTrace();
        }
        
        return rsValue;
    }
    
    public String tansferTypeDBDateToString(String attrType, Object value) {
        if (value == null) {
            return "";
        } else if (value.equals("")) {
            return "";
        }
        String rsValue = "";
        
        if (attrType.equals("VTString")){
            rsValue = String.valueOf(value);
        } else if (attrType.equals("VTInteger")){
            rsValue = ((BigDecimal)value).toString();
        } else if (attrType.equals("VTLong")){
            rsValue = ((BigDecimal)value).toString();
        } else if (attrType.equals("VTDouble")){
            rsValue = ((BigDecimal)value).toString();
        } else if (attrType.equals("VTBoolean")){
            rsValue = (String)value;
        } else if (attrType.equals("VTImage")){
            rsValue = (String)value;
        } else if (attrType.equals("VTDate")){
            if (value instanceof java.sql.Date) {
                rsValue = ((java.sql.Date)value).toString();
            } else if (value instanceof java.sql.Timestamp){
                rsValue = ((java.sql.Timestamp)value).toString();
            }
        } else if (attrType.equals("VTTime")){
            rsValue = ((java.sql.Timestamp)value).toString();
        } else if (attrType.equals("VTDateTime")) {
            if (value instanceof java.sql.Date) {
                rsValue = ((java.sql.Date)value).toString();
            } else if (value instanceof java.sql.Timestamp){
                rsValue = ((java.sql.Timestamp)value).toString();
            }
        } else if (attrType.equals("VTNote")){
            rsValue = (String)value;
        } else if (attrType.equals("VTFilePath")) {
            rsValue = (String)value;
        } else if (attrType.equals("VTClob")) {
            rsValue = clobToString((java.sql.Clob)value);
        } else {
            rsValue = (String)value;
        }
        return rsValue;
    }
    
    /**
     * clob转String
     * @param value
     * @return
     */
    private String clobToString(Clob value) {
        // TODO Auto-generated method stub
        String clobValue = "";
        try {
            Reader is = value.getCharacterStream();
            BufferedReader br = new BufferedReader(is);
            String s = br.readLine();
            StringBuffer sb = new StringBuffer();
            while(s!=null){
                sb.append(s);
                s=br.readLine();
            }
            clobValue = sb.toString();
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        
        return clobValue;
    }
 
    public String tansferTypeDBDateToString(
            HashMap<String, String> bO_CONSTANTS, String attrType,
            Object attributeValue) {
        // TODO Auto-generated method stub
        return null;
    }
}