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
package com.vci.test.oq;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
 
import com.vci.client.common.oq.OQTool;
import com.vci.client.common.providers.ServiceProvider;
import com.vci.client.oq.QTClient;
import com.vci.client.oq.QTDClient;
import com.vci.common.qt.object.ChildrenInfo;
import com.vci.common.qt.object.Condition;
import com.vci.common.qt.object.ConditionItem;
import com.vci.common.qt.object.Connector;
import com.vci.common.qt.object.LeafInfo;
import com.vci.common.qt.object.LeafValue;
import com.vci.common.qt.object.Operator;
import com.vci.common.qt.object.OrderInfo;
import com.vci.common.qt.object.PageInfo;
import com.vci.common.qt.object.QTConstants;
import com.vci.common.qt.object.QueryTemplate;
import com.vci.common.qt.object.Version;
import com.vci.corba.common.VCIError;
import com.vci.corba.omd.data.BusinessObject;
import com.vci.corba.omd.data.LinkObject;
import com.vci.corba.query.data.BOAndLO;
 
public class Test{
    
    @org.junit.Test
    public void getQT() throws VCIError{
        boolean qt = ServiceProvider.getOMDService().getQTDService().isExistsQT("GroupPRunitQueryAll");
        System.out.println();
    }
    @org.junit.Test
    public void buildWholeQT(){
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLink");
        qt.setType("link");
        qt.setLinkType("DocumentRelation");
        qt.setBtmType("Document");
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNO(1);
        pageInfo.setRowCount(100);
        qt.setPageInfo(pageInfo);
        qt.setVersion(Version.currentRevLastVer);
        qt.setDirection("positive");
        qt.setLevel(1);
        List<OrderInfo> orderInfoList = new ArrayList<OrderInfo>();
        OrderInfo e = new OrderInfo();
        e.setLevel(2);
        e.setOrderField("linkAttr1");
        e.setOrderMode(QTConstants.ORDERMODE_DESC);
        orderInfoList.add(e );
        OrderInfo e2 = new OrderInfo();
        e2.setLevel(5);
        e2.setOrderField("T_OID.btmAttr1");
        e2.setOrderMode(QTConstants.ORDERMODE_ASC);
        orderInfoList.add(e2 );
        qt.setOrderInfoList(orderInfoList );
        Condition condition = new Condition();
        condition.setRootCIName("ci3");
        Map<String, ConditionItem> cIMap = new HashMap<String, ConditionItem>();
        condition.setCIMap(cIMap );
        ConditionItem ci1 = new ConditionItem();
        ci1.setId("ci1");
        ci1.setLeafFlag(true);
        LeafInfo leafInfo = new LeafInfo();
        leafInfo.setClause("linkAttr2");
        leafInfo.setOperator(Operator.EQUAL);
        LeafValue value = new LeafValue();
        value.setOrdinaryValue("abc");
        leafInfo.setValue(value );
        ci1.setLeafInfo(leafInfo );
        ConditionItem ci2 = new ConditionItem();
        ci2.setId("ci2");
        ci2.setLeafFlag(true);
        LeafInfo leafInfo_ = new LeafInfo();
        leafInfo_.setClause("T_OID.btmAttr2");
        leafInfo_.setOperator(Operator.IN);
        LeafValue value_ = new LeafValue();
            QueryTemplate refQt = new QueryTemplate();
            refQt.setId("queryBtm");
            refQt.setType("btm");
            refQt.setBtmType("Document");
            refQt.setVersion(3);
            List<String> clauseList_ = new ArrayList<String>();
            clauseList_.add("btmAttr2");
            refQt.setClauseList(clauseList_);
            Condition condition_ = new Condition();
            condition_.setRootCIName("ci1_");
            Map<String, ConditionItem> cIMap_ = new HashMap<String, ConditionItem>();
            condition_.setCIMap(cIMap_ );
            ConditionItem ci1_ = new ConditionItem();
            cIMap_.put("ci1_", ci1_ );
            ci1_.setId("ci1_");
            ci1_.setLeafFlag(true);
            LeafInfo _leafInfo = new LeafInfo();
            _leafInfo.setClause("btmAttr3");
            _leafInfo.setOperator(Operator.LIKE);
            LeafValue _value = new LeafValue();
            _value.setOrdinaryValue("abc");
            _leafInfo.setValue(_value );
            ci1_.setLeafInfo(_leafInfo );
            refQt.setCondition(condition_);
        value_.setQueryTemplate(refQt );
        leafInfo_.setValue(value_ );
        ci2.setLeafInfo(leafInfo_ );
        cIMap.put("ci1", ci1);
        cIMap.put("ci2", ci2);
        ConditionItem ci3 = new ConditionItem();
        ci3.setId("ci3");
        ci3.setLeafFlag(false);
        ChildrenInfo childrenInfo = new ChildrenInfo();
        childrenInfo.setConnector(Connector.AND);
        childrenInfo.setLeftCIName("ci1");
        childrenInfo.setRightCIName("ci2");
        ci3.setChildrenInfo(childrenInfo );
        cIMap.put("ci3", ci3 );
        qt.setCondition(condition);
        
        String asXML = OQTool.qtTOXMl(qt).asXML();
        System.out.println();
    }
    
    public static void main(String[] args){
        int i;
        for(i = 0; i < 1; i++){
            Thread t = new Thread(new RunnableTest());
            t.setName("thread-" + i);
            t.start();
        }
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryBtm");
        qt.setType(QTConstants.TYPE_BTM);
        qt.setBtmType("part");
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        qt.setVersion(Version.lastReleasedRev);
        
        Map<String, String> map = new HashMap<String, String>();
        map.put("nameoid", "6AF73192-2B0C-FFF5-2B76-9819C44E566F");
        Condition condition = OQTool.getCondition(map );
        qt.setCondition(condition);
        
        BusinessObject[] bts = null;
        long ss = System.currentTimeMillis();
        try {
            bts = QTClient.getService().findBTMObjects(qt.getId(), OQTool.getQTTextByQT(qt));
        } catch (VCIError e) {
            e.printStackTrace();
        }
        long ss2 = System.currentTimeMillis();
        System.out.println("BusinessObject: " + (ss2 - ss) + "-----" + bts.length);
    }
    
//    public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException {
//        ExecutorService exec = Executors.newCachedThreadPool();
//        ExecutorCompletionService<BOAndLO[]> completionExec = new ExecutorCompletionService<BOAndLO[]>(exec);
//        List<Future<BOAndLO[]>> list1 = new ArrayList<Future<BOAndLO[]>>();
//        List<Future<BOAndLO[]>> list2 = new ArrayList<Future<BOAndLO[]>>();
//        int i;
//        for (i = 0; i < 10; i++) {
////            list1.add(exec.submit(new CallableTest()));
//            completionExec.submit(new CallableTest());
//        }
////        for(Future<BOAndLO[]> f1 : list1){
////            //如有必要,等待计算完成,然后获取其结果。
////            BOAndLO[] boAndLOs = f1.get(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
////            System.out.println(f1.toString() + ":" + boAndLOs.length);
////        }
//        
//        for(i = 0; i < 10; i++){
//            //completionExec.take():
//            //获取并移除表示下一个已完成任务的 Future,如果目前不存在这样的任务,则等待。
//            //任务完成后调用done(),将完成的任务加入队列;如果队列中没有已经完成的任务,则等待。
//            BOAndLO[] boAndLOs = completionExec.take().get(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
//            System.out.println(i + ":" + boAndLOs.length);
//        }
//        exec.shutdownNow();
//        exec.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
//    }
}
 
class RunnableTest implements Runnable{
 
    @Override
    public void run() {
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLink");
        qt.setType("link");
        qt.setLinkType("MBOM");
        qt.setBtmType("part");
        qt.setVersion(Version.lastReleasedRev);
        qt.setDirection("positive");
        qt.setRecReturnMode(QTConstants.RECRETURNMODE_FILTER);
        qt.setLevel(10);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        Condition condition = new Condition();
        qt.setCondition(condition);
        condition.setRootCIName("ci1");
        Map<String, ConditionItem> cIMap = new HashMap<String, ConditionItem>();
        condition.setCIMap(cIMap );
        ConditionItem ci1 = new ConditionItem();
        ci1.setId("ci1");
        ci1.setLeafFlag(true);
        LeafInfo leafInfo = new LeafInfo();
        leafInfo.setClause("f_oid");
        leafInfo.setOperator(Operator.EQUAL);
        LeafValue value = new LeafValue();
        value.setOrdinaryValue("E120EECE-733D-F0CE-0465-9DB3BBC7086B");
//        value.setOrdinaryValue("FC9F8F84-0C06-EC51-4089-4A5C60115B81");
        leafInfo.setValue(value );
        ci1.setLeafInfo(leafInfo );
        cIMap.put("ci1", ci1);
        
        ConditionItem ci2 = new ConditionItem();
        ci2.setId("ci2");
        ci2.setLeafFlag(true);
        LeafInfo leafInfo_ = new LeafInfo();
        leafInfo_.setClause("ownedmanuproduct");
        leafInfo_.setOperator(Operator.EQUAL);
        LeafValue value_ = new LeafValue();
        value_.setOrdinaryValue("5F460EF5-7EBE-0A9D-C32D-451C6D343AF1");
        leafInfo_.setValue(value_ );
        ci2.setLeafInfo(leafInfo_ );
        cIMap.put("ci1", ci1);
        cIMap.put("ci2", ci2);
        ConditionItem ci3 = new ConditionItem();
        ci3.setId("ci3");
        ci3.setLeafFlag(false);
        ChildrenInfo childrenInfo = new ChildrenInfo();
        childrenInfo.setConnector(Connector.AND);
        childrenInfo.setLeftCIName("ci1");
        childrenInfo.setRightCIName("ci2");
        ci3.setChildrenInfo(childrenInfo );
        cIMap.put("ci3", ci3 );
        
        long s1 = System.currentTimeMillis();
        LinkObject[] los = null;
        try {
            los = QTClient.getService().findLTObjects(qt.getId(), OQTool.getQTTextByQT(qt));
            System.out.println();
        } catch (VCIError e) {
            e.printStackTrace();
        }
        long s11 = System.currentTimeMillis();
        System.out.println(Thread.currentThread().getName() + "****findLTObjects:" + (s11 - s1) +"--"+ los.length);
//        BOAndLO[] boAndLOS = null;
//        long s2 = System.currentTimeMillis();
//        try {
//            boAndLOS = QTClient.getService().getBOAndLOS(qt.getId(), Tool.getQTTextByQT(qt), "");
//        } catch (VCIError e) {
//            e.printStackTrace();
//        }
//        long s3 = System.currentTimeMillis();
//        System.out.println(Thread.currentThread().getName() + "****BOAndLO:" + (s3 - s2) +"--"+ boAndLOS.length);
    }
}
 
 
class CallableTest implements Callable<BOAndLO[]>{
 
    @Override
    public BOAndLO[] call() throws Exception {
        QueryTemplate qt = new QueryTemplate();
        qt.setId("queryLink");
        qt.setType("link");
        qt.setLinkType("EBOM");
        qt.setBtmType("part,product");
        qt.setVersion(Version.lastReleasedRev);
        qt.setDirection("positive");
        qt.setLevel(10);
        List<String> clauseList = new ArrayList<String>();
        clauseList.add("*");
        qt.setClauseList(clauseList);
        Condition condition = new Condition();
        qt.setCondition(condition);
        condition.setRootCIName("ci1");
        Map<String, ConditionItem> cIMap = new HashMap<String, ConditionItem>();
        condition.setCIMap(cIMap );
        ConditionItem ci1 = new ConditionItem();
        ci1.setId("ci1");
        ci1.setLeafFlag(true);
        LeafInfo leafInfo = new LeafInfo();
        leafInfo.setClause("f_oid");
        leafInfo.setOperator(Operator.EQUAL);
        LeafValue value = new LeafValue();
        value.setOrdinaryValue("E120EECE-733D-F0CE-0465-9DB3BBC7086B");
        leafInfo.setValue(value );
        ci1.setLeafInfo(leafInfo );
        cIMap.put("ci1", ci1);
        
        long s2 = System.currentTimeMillis();
        BOAndLO[] boAndLOS = null;
        try {
            boAndLOS = QTClient.getService().getBOAndLOS(qt.getId(), OQTool.getQTTextByQT(qt), "");
        } catch (VCIError e) {
            e.printStackTrace();
        }
        long s3 = System.currentTimeMillis();
//        System.out.println(Thread.currentThread().getName() + "***BOAndLO:" + (s3 - s2));
        return boAndLOS;
    }
    
}