wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.uif.engine.common;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
 
import com.vci.client.bof.ClientBusinessObject;
import com.vci.client.bof.ClientLinkObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.ui.exception.VCIException;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
 
public class CBOHelper {
    /**
     * 根据传入的DataNode获取其上bo对象的OID
     * @return
     */
    public static String getBusinessObjectOid(IDataNode dataNode) {
        String boOid = "";
        if (dataNode.getMaterObject() instanceof ClientBusinessObject) {
            boOid = ((ClientBusinessObject)dataNode.getMaterObject()).getOid();
        } else if (dataNode.getMaterObject() instanceof ClientLinkObject) {
            if (dataNode.isForward()) {
                boOid = dataNode.getValueMap().get("t_oid");
            } else {
                boOid = dataNode.getValueMap().get("f_oid");
            }
        } else if (dataNode.getMaterObject() instanceof String) {
            return (String) dataNode.getMaterObject();
        }
        
        return boOid;
    }
    
    public static String getLinkObjectOid(IDataNode dataNode) {
        String loOid = "";
        if (dataNode.getMaterObject() instanceof ClientLinkObject) {
            loOid = dataNode.getValueMap().get("oid");
        }
        return loOid;
    }
    
    /**
     * 根据传入的DataNode获取其上bo对象的type
     * @return
     */
    public static String getBusinessObjectType(IDataNode dataNode) {
        String boType = "";
        if (dataNode.getMaterObject() instanceof ClientBusinessObject) {
            boType = ((ClientBusinessObject)dataNode.getMaterObject()).getBtmName();
        } else if (dataNode.getMaterObject() instanceof ClientLinkObject) {
            if (dataNode.isForward()) {
                boType = ((ClientLinkObject)dataNode.getMaterObject()).getToBTMName();
            } else {
                boType = ((ClientLinkObject)dataNode.getMaterObject()).getFromBTMName();
            }
        }
        
        return boType;
    }
    
 
    public static Map<String, String>[] getLOValueMap(LinkObject[] los){
        @SuppressWarnings("unchecked")
        Map<String, String>[] res = new LinkedHashMap[los.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = getLOValueMap(los[i]);
        }
        return res;
    }
    
    public static Map<String, String> getLOValueMap(LinkObject lo){
        Map<String, String> res = new LinkedHashMap<String, String>();
        for(AttributeValue av : lo.hisAttrValList){
            res.put(av.attrName.toLowerCase(), av.attrVal);
        }
        return res;
    }
    
    public static Map<String, String>[] getBOValueMap(BusinessObject[] bos){
        @SuppressWarnings("unchecked")
        Map<String, String>[] res = new LinkedHashMap[bos.length];
        for (int i = 0; i < res.length; i++) {
            res[i] = getBOValueMap(bos[i]);
        }
        return res;
    }
    
    public static Map<String, String> getBOValueMap(BusinessObject bo){
        Map<String, String> res = new LinkedHashMap<String, String>();
        for(AttributeValue av : bo.hisAttrValList){
            res.put(av.attrName.toLowerCase(), av.attrVal);
        }
        return res;
    }
 
    /**
     * 返回服务器端的日期 yyyy-MM-dd
     * @return
     */
    public static String getDBDateString(){
        return getDBDateTimeString("yyyy-MM-dd");
    }
 
    public static String getDBTimeString(String format){
        return getDBDateTimeString("hh:mm:ss");
    }
    /**
     * 返回服务器端时间字符串
     * @param dateFormat 日期&时间格式字符串 yyyy-MM-dd
     * @return
     */
    private static String getDBDateTimeString(String format){
        String res = "";
        try {
            long time = new RightManagementClientDelegate().getSystemTime();
            SimpleDateFormat sdf = new SimpleDateFormat(format);
            res = sdf.format(new Date(time));
        } catch (VCIException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return res;
    }
}