package com.vci.client.portal.utility;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.Iterator;
|
import java.util.LinkedHashMap;
|
import java.util.LinkedList;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.dom4j.DocumentException;
|
import org.dom4j.DocumentHelper;
|
|
import com.vci.corba.query.data.RefPath;
|
import com.vci.omd.utils.ObjectTool;
|
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.client.portal.custom.ICustomDefine;
|
import com.vci.common.qt.object.Condition;
|
import com.vci.common.qt.object.Connector;
|
import com.vci.common.qt.object.OrderInfo;
|
import com.vci.common.qt.object.PageInfo;
|
import com.vci.common.qt.object.QueryTemplate;
|
import com.vci.corba.common.VCIError;
|
import com.vci.corba.omd.data.BusinessObject;
|
import com.vci.corba.omd.qtm.QTInfo;
|
|
public class TableDataUtilNew extends TableDataUtil {
|
|
/**
|
* 查询业务对象的详细信息
|
* @param qtName, 查询模版
|
* @param replaceMap, 替换map
|
* @param conditionMap, 附加条件
|
* @param pageInfo, 翻页信息
|
* @param orderInfos, 排序信息
|
* @param showType, 显示类型
|
* @param queryColumnsMap, 查询列, key为查询列名,value为显示名称
|
* @param customMap, 自定义列
|
* @return
|
* @throws VCIError
|
* @throws DocumentException
|
*/
|
public List<Map<String, String>> getNewObjectDataList(String qtName, Map<String, String> replaceMap,
|
Map<String, List<String>> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos, String showType,
|
Map<String, String> queryColumnsMap, Map<String, PRMItem> customMap, Map<String, PRMItem> fileMap) throws VCIError {
|
DataModelProcessor processor = new DataModelProcessor();
|
BusinessObject[] objs = getNewBusinessObjectByQueryTemplate(qtName, replaceMap, conditionMap, pageInfo, orderInfos);
|
List<Map<String, String>> datas = getObjectDataSecondList(processor, objs, showType, queryColumnsMap);
|
if (customMap != null && customMap.size() > 0) {
|
getCustomValue(customMap, datas);
|
}
|
if (fileMap != null && fileMap.size() > 0) {
|
getFileColValue(fileMap, datas);
|
}
|
return datas;
|
}
|
|
public BusinessObject[] getNewBusinessObjectByQueryTemplate(String queryTemplate, Map<String, String> replaceMap, Map<String, List<String>> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError {
|
BusinessObject[] v = null;
|
try
|
{
|
QueryTemplate qt_ = getNewCustomQt(queryTemplate, replaceMap, conditionMap, pageInfo, orderInfos);
|
v = QTClient.getService().findBTMObjects(qt_.getId(), OQTool.qtTOXMl(qt_).asXML());
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return v;
|
}
|
|
private QueryTemplate getNewCustomQt(String queryTemplate, Map<String, String> replaceMap, Map<String, List<String>> conditionMap, PageInfo pageInfo, List<OrderInfo> orderInfos) throws VCIError, DocumentException {
|
QueryTemplate qt_ = null;
|
try
|
{
|
QTInfo wrapper = ServiceProvider.getOMDService().getQTDService().getQT(queryTemplate);
|
QueryTemplate qt = OQTool.getQTByDoc(DocumentHelper.parseText(wrapper.qtText), queryTemplate);
|
qt_ = OQTool.replaceQTValues(qt, replaceMap);
|
if (conditionMap != null && conditionMap.size() > 0) {
|
Iterator<String> itor = conditionMap.keySet().iterator();
|
while (itor.hasNext()) {
|
String key = itor.next();
|
List<String> list = conditionMap.get(key);
|
for (int i = 0; i < list.size(); i++) {
|
Map<String, String> cMap = new HashMap<String, String>();
|
cMap.put(key, list.get(i));
|
Condition condition = OQTool.getCondition(cMap);
|
Condition mergeCondition = OQTool.mergeCondition(qt_.getCondition(), condition, Connector.AND);
|
qt_.setCondition(mergeCondition);
|
}
|
}
|
}
|
if(pageInfo != null){
|
qt_.setPageInfo(pageInfo);
|
}
|
if(orderInfos != null){
|
qt_.setOrderInfoList(orderInfos);
|
}
|
}
|
catch(VCIError vcie)
|
{
|
throw vcie;
|
}
|
catch(java.lang.Exception se)
|
{
|
VCIError vcierror = new VCIError("",new String[]{se.getMessage()});
|
throw vcierror;
|
}
|
return qt_;
|
}
|
|
/**
|
* 获取业务对象二次查询的结果
|
* @param processor
|
* @param objs, 业务对象
|
* @param showType, 显示类型
|
* @param formColumnsMap,key为内部主键,value为显示名称(在此过程中暂不使用,可以传入空值)
|
*/
|
private List<Map<String, String>> getObjectDataSecondList(
|
DataModelProcessor processor,
|
BusinessObject[] objs, String showType,
|
Map<String, String> queryColumnsMap){
|
@SuppressWarnings("unchecked")
|
Map<String, String>[] res = new LinkedHashMap[0];
|
res = CBOHelper.getBOValueMap(objs);
|
Map<String, List<String>> referenceKeyMap = processor.getReferenceCol(queryColumnsMap);
|
if (referenceKeyMap != null && referenceKeyMap.size() > 0) {
|
Iterator<String> referenceKey = referenceKeyMap.keySet().iterator();
|
List<String> referenceList = new LinkedList<String>();
|
while (referenceKey.hasNext()) {
|
referenceList.add(referenceKey.next());
|
}
|
Map<String, Map<String, String>> rowRefMap = new LinkedHashMap<String, Map<String, String>>();
|
Map<String, Boolean> emptyCheckMap = new LinkedHashMap<String, Boolean>();
|
for (BusinessObject obj : objs) {
|
String boOid = obj.oid;
|
Map<String, String> refMap = new LinkedHashMap<String, String>();
|
for (int j = 0; j < referenceList.size(); j++) {
|
String refKey = referenceList.get(j);
|
String refVal = ObjectTool.getBOAttributeValue(obj, refKey);
|
if (refVal == null) {
|
refVal = "";
|
emptyCheckMap.put(refVal, true);
|
} else {
|
emptyCheckMap.put(refKey, false);
|
}
|
refMap.put(refKey, refVal);
|
}
|
rowRefMap.put(boOid, refMap);
|
}
|
|
Map<String, String> emptyMap = new HashMap<String, String>();
|
Iterator<String> emptyCheckItor = emptyCheckMap.keySet().iterator();
|
List<String> delKeyList = new ArrayList<String>();
|
while (emptyCheckItor.hasNext()) {
|
String emptyCheckKey = emptyCheckItor.next();
|
boolean emptyCheckVal = emptyCheckMap.get(emptyCheckKey);
|
if (!emptyCheckVal) {
|
continue;
|
}
|
List<String> list = referenceKeyMap.get(emptyCheckKey);
|
emptyMap.put(emptyCheckKey, "");
|
for (int j = 0; j < list.size(); j++) {
|
emptyMap.put(list.get(j), "");
|
}
|
referenceKeyMap.remove(emptyCheckKey);
|
delKeyList.add(emptyCheckKey);
|
}
|
if (delKeyList.size() > 0) {
|
Iterator<String> itor = rowRefMap.keySet().iterator();
|
while (itor.hasNext()) {
|
Map<String, String> crowMap = rowRefMap.get(itor.next());
|
for (int i = 0; i < delKeyList.size(); i++) {
|
crowMap.remove(delKeyList.get(i));
|
}
|
}
|
}
|
|
Map<String, String> secQueryMap = processor.getQueryBusinessObjectCondition(showType, rowRefMap, referenceKeyMap);
|
RefPath[] refPaths = processor.queryReference(secQueryMap, showType);
|
connectSecondQueryResult(res, refPaths, secQueryMap, referenceKeyMap);
|
}
|
|
List<Map<String, String>> listRes = new LinkedList<Map<String, String>>();
|
for (Map<String, String> resMap : res) {
|
listRes.add(resMap);
|
}
|
return listRes;
|
}
|
|
/**
|
* 将二次查询结果拼接到一次查询结果中
|
* @param res
|
* @param refPaths
|
* @param secQueryMap
|
* @param referenceKeyMap
|
*/
|
private void connectSecondQueryResult(Map<String, String>[] res, RefPath[] refPaths, Map<String, String> secQueryMap, Map<String, List<String>> referenceKeyMap) {
|
if (refPaths != null) {
|
int colNum = secQueryMap.size();
|
for (int i = 0; i < res.length; i++) {
|
Map<String, String> rowVal = res[i];
|
for (int j = 0; j < colNum; j++) {
|
String key = secQueryMap.keySet().toArray(new String[colNum])[j];
|
if (referenceKeyMap.containsKey(key)) {
|
continue;
|
}
|
if (refPaths[j].values.length <= i) {
|
continue;
|
}
|
String cVal = refPaths[j].values[i].value;
|
rowVal.put(secQueryMap.keySet().toArray(new String[colNum])[j], cVal);
|
}
|
}
|
}
|
}
|
|
/**
|
* 获取自定义列的值
|
* @param customMap, 自定义查询列
|
* @param datas, 查询结果
|
* @throws VCIError
|
*/
|
private void getCustomValue(Map<String, PRMItem> customMap, List<Map<String, String>> datas) throws VCIError {
|
Iterator<String> itor = customMap.keySet().iterator();
|
while (itor.hasNext()) {
|
String key = itor.next();
|
PRMItem prm = customMap.get(key);
|
String customCls = prm.getItemCustomClass();
|
if(customCls == null || "".equals(customCls)){
|
continue;
|
}
|
executeSetCustomValue(customCls, key, customMap, datas);
|
}
|
}
|
|
/**
|
* 执行自定义列类获取具体的值
|
* @param customCls, 自定义类
|
* @param key, 自定义列主键
|
* @param customMap, 自定义列对应的Map
|
* @param datas, 数据
|
*/
|
private void executeSetCustomValue(String customCls, String key, Map<String, PRMItem> customMap, List<Map<String, String>> datas){
|
try {
|
int paramIndex = customCls.indexOf("?");
|
String param = "";
|
if(paramIndex > 0){
|
param = customCls.substring(paramIndex + 1);
|
customCls = customCls.substring(0, paramIndex);
|
}
|
Class<?> cls = Class.forName(customCls);
|
ICustomDefine custom = (ICustomDefine)cls.getConstructor().newInstance();
|
if(param != null && !"".equals(param)){
|
key = key + "?" + param;
|
}
|
custom.getCustomValue(key, customMap, datas);
|
} catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
private void getFileColValue(Map<String, PRMItem> fileMap, List<Map<String, String>> datas) throws VCIError {
|
try {
|
Iterator<String> itor = fileMap.keySet().iterator();
|
while (itor.hasNext()) {
|
String key = itor.next();
|
PRMItem prm = fileMap.get(key);
|
String customCls = prm.getItemCustomClass();
|
if(customCls == null || "".equals(customCls)){
|
customCls = "plm.portal.custom.CustomFileInterceptor";
|
}
|
executeSetCustomValue(customCls, key, fileMap, datas);
|
}
|
} catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
}
|