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
package com.vci.server.bof.objects;
 
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
 
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.omd.constants.BusinessConstants;
import com.vci.server.bof.utils.ServerObjectUtil;
 
public class ServerBusinessObject {
 
    public String oid = "";
    public String revisionOid = "";
    public String nameoid = "";
    public String btmName = "";
    public String isLastR;
    public String isFirstR;
    public String isLastV;
    public String isFirstV;
    public String creator = "";
    public long createTime = 0;
    public String lastModifier = "";
    public long lastModifyTime = 0;
    public String revisionRule = "";
    public String versionRule = "";
    public String revisionSeq;
    public String revisionValue = "";
    public String versionSeq;
    public String versionValue = "";
    public String lctId = "";
    public String lcStatus = "";
    public long ts = 0;
    public String id = "";
    public String name = "";
    public String description = "";
    public String owner = "";
//    public String checkinBy = "";
//    public String checkinTime = "";
//    public String checkoutBy = "";
//    public String checkoutTime = "";
    public String copyFromVersion = "";
    
    private BusinessObject businessObject;
    
    public BusinessObject getBusinessObject() {
        dealBusinessObjectNullValue();
        return businessObject;
    }
 
    public void setBusinessObject(BusinessObject businessObject) {
        this.businessObject = businessObject;
    }
 
    public ServerBusinessObject() {
        businessObject = new BusinessObject();
    }
    
    public String getOid() {
        return oid;
    }
    public String getRevisionOid() {
        return this.revisionOid;
    }
    public String getNameoid() {
        return nameoid;
    }
    public String getBtmName() {
        return btmName;
    }
    public String getIsLastR() {
        return isLastR;
    }
    public String getIsFirstR() {
        return isFirstR;
    }
    public String getIsLastV() {
        return isLastV;
    }
    public String getIsFirstV() {
        return isFirstV;
    }
    public String getCreator() {
        return creator;
    }
    public long getCreateTime() {
        return createTime;
    }
    public String getLastModifier() {
        return lastModifier;
    }
    public long getLastModifyTime() {
        return lastModifyTime;
    }
    public String getRevisionRule() {
        return revisionRule;
    }
    public String getVersionRule() {
        return versionRule;
    }
    public String getRevisionSeq() {
        return revisionSeq;
    }
    public String getRevisionValue() {
        return revisionValue;
    }
    public String getVersionSeq() {
        return versionSeq;
    }
    public String getVersionValue() {
        return versionValue;
    }
    public String getLctId() {
        return lctId;
    }
    public String getLcStatus() {
        return lcStatus;
    }
    public long getTs() {
        return ts;
    }
    public String getId() {
        return id;
    }
    public String getName() {
        return name;
    }
    public String getDescription() {
        return description;
    }
    public String getOwner() {
        return owner;
    }
//    public String getCheckinBy() {
//        return checkinBy;
//    }
//    public String getCheckinTime() {
//        return checkinTime;
//    }
//    public String getCheckoutBy() {
//        return checkoutBy;
//    }
//    public String getCheckoutTime() {
//        return checkoutTime;
//    }
    public String getCopyFromVersion() {
        return copyFromVersion;
    }
    public void setOid(String oid) {
        this.oid = oid;
        this.businessObject.oid = oid;
    }
    public void setRevisionOid(String revisionOid) {
        this.revisionOid = revisionOid;
        this.businessObject.revisionid = revisionOid;
    }
    public void setNameoid(String nameoid) {
        this.nameoid = nameoid;
        this.businessObject.nameoid = nameoid;
    }
    public void setBtmName(String btmName) {
        this.btmName = btmName;
        this.businessObject.btName = btmName;
    }
    public void setIsLastR(String isLastR) {
        this.isLastR = isLastR;
        this.businessObject.isLastR = Short.valueOf(isLastR) != 0;
    }
    public void setIsFirstR(String isFirstR) {
        this.isFirstR = isFirstR;
        this.businessObject.isFirstR = Short.valueOf(isFirstR) != 0;
    }
    public void setIsLastV(String isLastV) {
        this.isLastV = isLastV;
        this.businessObject.isLastV = Short.valueOf(isLastV) != 0;
    }
    public void setIsFirstV(String isFirstV) {
        this.isFirstV = isFirstV;
        this.businessObject.isFirstV = Short.valueOf(isFirstV) != 0;
    }
    public void setCreator(String creator) {
        this.creator = creator;
        this.businessObject.creator = creator;
    }
    public void setCreateTime(long createTime) {
        this.createTime = createTime;
        this.businessObject.createTime = createTime;
    }
    public void setLastModifier(String lastModifier) {
        this.lastModifier = lastModifier;
        this.businessObject.modifier = lastModifier;
    }
    public void setLastModifyTime(long lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
        this.businessObject.modifyTime = lastModifyTime;
    }
    public void setRevisionRule(String revisionRule) {
        this.revisionRule = revisionRule;
        this.businessObject.revisionRule = revisionRule;
    }
    public void setVersionRule(String versionRule) {
        this.versionRule = versionRule;
        this.businessObject.versionRule = versionRule;
    }
    public void setRevisionSeq(String revisionSeq) {
        this.revisionSeq = revisionSeq;
        this.businessObject.revisionSeq = Short.valueOf(revisionSeq);
    }
    public void setRevisionValue(String revisionValue) {
        this.revisionValue = revisionValue;
        this.businessObject.revisionValue = revisionValue;
    }
    public void setVersionSeq(String versionSeq) {
        this.versionSeq = versionSeq;
        this.businessObject.versionSeq = Short.valueOf(versionSeq);
    }
    public void setVersionValue(String versionValue) {
        this.versionValue = versionValue;
        this.businessObject.versionValue = versionValue;
    }
    public void setLctId(String lctId) {
        this.lctId = lctId;
        this.businessObject.lctId = lctId;
    }
    public void setLcStatus(String lcStatus) {
        this.lcStatus = lcStatus;
        this.businessObject.lcStatus = lcStatus;
    }
    public void setTs(long ts) {
        this.ts = ts;
        this.businessObject.ts = ts;
    }
    public void setId(String id) {
        this.id = id;
        this.businessObject.id = id;
    }
    public void setName(String name) {
        this.name = name;
        this.businessObject.name = name;
    }
    public void setDescription(String description) {
        this.description = description;
        this.businessObject.description = description;
    }
    public void setOwner(String owner) {
        this.owner = owner;
        this.businessObject.owner = owner;
    }
//    public void setCheckinBy(String checkinBy) {
//        this.checkinBy = checkinBy;
//        this.businessObject.checkinBy = checkinBy;
//    }
//    public void setCheckinTime(String checkinTime) {
//        this.checkinTime = checkinTime;
//        this.businessObject.checkinTime = checkinTime;
//    }
//    public void setCheckoutBy(String checkoutBy) {
//        this.checkoutBy = checkoutBy;
//        this.businessObject.checkoutBy = checkoutBy;
//    }
//    public void setCheckoutTime(String checkoutTime) {
//        this.checkoutTime = checkoutTime;
//        this.businessObject.checkoutTime = checkoutTime;
//    }
    public void setCopyFromVersion(String copyFromVersion) {
        this.copyFromVersion = copyFromVersion;
        this.businessObject.fromVersion = copyFromVersion;
    }
    
    public void setAttributeValue(String attributeName, String attrType, Object attributeValue) throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        if (BusinessConstants.BO_CONSTANTS.containsKey(attributeName)) {
            dealWithSystemAttributeValue(attributeName, attributeValue);
            attrType = BusinessConstants.BO_CONSTANTS.get(attributeName);
        } 
        dealWithBOAttributeValue(attributeName, attrType, attributeValue);
    }
    
    private void dealWithSystemAttributeValue(String attributeName, Object attributeValue) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
        String name = attributeName.toUpperCase();
        if (name.equals("CREATETIME") || name.equals("LASTMODIFYTIME") || name.equals("TS")) {
            long time = 0;
            if (attributeValue instanceof java.sql.Date) {
                time = ((java.sql.Date)attributeValue).getTime();
            } else if (attributeValue instanceof java.sql.Timestamp){
                time = ((java.sql.Timestamp)attributeValue).getTime();
            }
            
            if (name.equals("CREATETIME")) {
                this.setCreateTime(time);
            } else if (name.equals("LASTMODIFYTIME")) {
                this.setLastModifyTime(time);
            } else if (name.equals("TS")) {
                this.setTs(time);
            }
            return;
        }
        
        String changeValue = ServerObjectUtil.getInstance().tansferSystemDBDateToString(BusinessConstants.BO_CONSTANTS, attributeName, attributeValue);
        
        Field[] fields=ServerBusinessObject.class.getDeclaredFields();
        for (Field field : fields) {
            String fieldName = field.getName();
            if (!fieldName.toUpperCase().equals(attributeName.toUpperCase())) {
                continue;
            }
            //将属性名首字母转换成大写字母
            String firstLetter = fieldName.substring(0, 1).toUpperCase();
            String setMethodName = "set" + firstLetter + fieldName.substring(1);
            Method setMethod = ServerBusinessObject.class.getMethod(setMethodName, new Class[]{changeValue.getClass()});
            setMethod.invoke(this, new Object[]{changeValue});
            break;
        }
    }
    
    private void dealWithBOAttributeValue(String attributeName, String attrType, Object attributeValue) {
        String changeValue = ServerObjectUtil.getInstance().tansferTypeDBDateToString(attrType, attributeValue);
        AttributeValue[] attrValues = businessObject.hisAttrValList;
        ArrayList<AttributeValue> attrValList = new ArrayList<AttributeValue>();
        if (attrValues != null && attrValues.length > 0) {
            for (AttributeValue attrVal: attrValues) {
                attrValList.add(attrVal);
            }
        }
        AttributeValue attrVal = null;
        boolean isExist = false;
        for (int i = 0; i < attrValList.size(); i++) {
            attrVal = attrValList.get(i);
            if (attrVal.attrName.toUpperCase().equals(attributeName.toUpperCase())) {
                attrVal.attrVal = changeValue;
                isExist = true;
                break;
            }
        }
        if (!isExist) {
            attrVal = new AttributeValue();
            attrVal.attrName = attributeName.toUpperCase();
            attrVal.attrVal = changeValue;
            attrValList.add(attrVal);
        }
        businessObject.hisAttrValList = attrValList.toArray(new AttributeValue[attrValList.size()]);
    }
 
    public String[] getQueryColumnAccordingToSQL(String sql, String start, String end) {
        sql = sql.toUpperCase();
        sql = sql.substring(start.length());
        sql = sql.substring(0, sql.indexOf(end));
        sql = sql.replaceAll(" ", "");
        return sql.split(",");
    }
    
    public void dealBusinessObjectNullValue() {
        businessObject.newAttrValList = businessObject.newAttrValList == null ? new AttributeValue[0] : businessObject.newAttrValList;
        businessObject.hisAttrValList = businessObject.hisAttrValList == null ? new AttributeValue[0] : businessObject.hisAttrValList;
    }
}