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
package com.vci.server.bof.histroy;
 
import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
 
import com.vci.common.log.ServerWithLog4j;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.data.AttributeValue;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.server.bof.delegate.BOFactoryServerBODelegate;
import com.vci.server.bof.delegate.BOFactoryServerDelegate;
 
/**
 * 操作业务对象历史数据
 * @author lmh
 *
 */
public class BOHistroyService {
    /**
     * 保存修改历史记录的业务类型
     */
    private static final String BTMNAME = "objecthistoryinfo";
    private static BOHistroyService service = null;
    
    private BOFactoryServerBODelegate bsb = BOFactoryServerBODelegate.getInstance();
    private BOFactoryServerDelegate bsd = BOFactoryServerDelegate.getInstance();
    
    public static BOHistroyService getInstance() {
        if(service == null) {
            service = new BOHistroyService();
        }
        return service;
    }
    
    /**
     * 保存对象的信息到objecthistoryinfo这个业务类型中
     * @param bo
     */
    public void saveHistroy(BusinessObject bo) {
        if(bo != null) {
            List<AttributeValue> list = new ArrayList<AttributeValue>();
            list.add(new AttributeValue("hoid",bo.oid));
            list.add(new AttributeValue("hrevisionoid",bo.revisionid));
            list.add(new AttributeValue("hnameoid",bo.nameoid));
            list.add(new AttributeValue("btmtype",bo.btName));
            String s = "";;
            try {
                s = getString(bo);
            } catch (Exception e) {
                //e.printStackTrace();
                ServerWithLog4j.logger.error(e);
            }
            list.add(new AttributeValue("plhistory", s));
            BusinessObject saveBo = null;
            try {
                saveBo = bsb.initBusinessObject(BTMNAME);
                saveBo.newAttrValList = list.toArray(new AttributeValue[0]);
                bsd.createBusinessObject(saveBo, false, false);
            } catch (VCIError e1) {
                e1.printStackTrace();
            }
        }
    }
    
    private String getString(BusinessObject bo) throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream ops = new ObjectOutputStream(baos);
        ops.writeObject(bo);
        String s = baos.toString("ISO-8859-1");
        ops.flush();
        ops.close();
        baos.close();
        return URLEncoder.encode(s,"UTF-8");
    }
}