package com.vci.client.uif.engine.client.tableArea; import java.awt.Component; import java.sql.Time; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; 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 java.util.regex.Pattern; import javax.swing.ImageIcon; import org.apache.commons.lang3.StringUtils; import org.dom4j.DocumentException; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObject; import com.vci.client.common.FreeMarkerCommon; import com.vci.client.common.FreemarkerParamObject; import com.vci.client.common.providers.ServiceProvider; import com.vci.client.omd.attribpool.ui.APClient; import com.vci.client.omd.btm.ui.BtmClient; import com.vci.client.omd.linktype.LinkTypeStart; import com.vci.client.omd.statepool.StatePoolStart; import com.vci.client.portal.constants.QueryConditionConstants; import com.vci.client.portal.custom.ICustomDefine; import com.vci.client.portal.utility.DataModelFactory; import com.vci.client.portal.utility.DataModelProcessor; import com.vci.client.portal.utility.PLDefination; import com.vci.client.portal.utility.PRM; import com.vci.client.portal.utility.PRMItem; import com.vci.client.portal.utility.RowModel; import com.vci.client.portal.utility.UITools; import com.vci.client.ui.exception.VCIException; import com.vci.client.ui.swing.VCISwingUtil; import com.vci.client.ui.swing.components.VCIJOptionPane; import com.vci.client.ui.swing.components.table.AbstractVCIJTableDataProvider; import com.vci.client.ui.swing.components.table.VCIJTableNode; import com.vci.client.uif.actions.client.UIFCache; import com.vci.client.uif.actions.client.UIFUtils; import com.vci.client.uif.engine.client.IRegionPanel; import com.vci.client.uif.engine.client.UIHelper; import com.vci.client.uif.engine.client.controls.ControlFactory; import com.vci.client.uif.engine.client.controls.FileChooseControlPanel; import com.vci.client.uif.engine.client.controls.UserChooseControl; import com.vci.client.uif.engine.common.CBOHelper; import com.vci.client.uif.engine.common.DefaultTableNode; import com.vci.client.uif.engine.common.GlobalContextParam; import com.vci.client.uif.engine.common.IDataNode; import com.vci.common.portal.constants.PRMConstants; import com.vci.common.portal.enums.ControlType; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.ConditionItem; import com.vci.common.qt.object.LeafInfo; import com.vci.common.qt.object.QTConstants; import com.vci.common.qt.object.QueryTemplate; import com.vci.common.utility.ObjectUtility; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; import com.vci.corba.omd.btm.BtmAndApName; import com.vci.corba.omd.btm.BtmItem; import com.vci.corba.omd.data.AttributeValue; import com.vci.corba.omd.data.BusinessObject; import com.vci.corba.omd.data.LinkObject; import com.vci.corba.omd.etm.EnumChild; import com.vci.corba.omd.etm.EnumItem; import com.vci.corba.omd.ltm.LinkType; import com.vci.corba.omd.stm.StatePool; import com.vci.corba.portal.data.PortalVI; import com.vci.corba.query.data.RefPath; import com.vci.mw.ClientContextVariable; import com.vci.omd.dataType.VTDataType; import com.vci.omd.utils.ObjectTool; public class TablePanelDataProvider extends AbstractVCIJTableDataProvider { private IRegionPanel regionPanel = null; private DataModelFactory factory = null; private String type = ""; private String context = ""; private String[] headerColumns = new String[0]; private PLDefination defination; public final String T_OID = "t_oid"; public final String F_OID = "f_oid"; public final String OID = "oid"; public final String LCSTATUS = "lcstatus"; public final String TIME_STRING_EMPTY = "00:00:00.0"; private static Pattern ptnDateTimeString = null; private static Map statePoolsMap = new HashMap(); static{ ptnDateTimeString = Pattern.compile("[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]+"); try { StatePool[] statePools = StatePoolStart.getService().getStatePools(); for(StatePool sp:statePools){ statePoolsMap.put(sp.name, sp); } } catch (VCIError e) { e.printStackTrace(); } } /** * 查询条件Map */ private Map normalSearchFilterMap = new HashMap(); /** * 是否是按条件查询(仅指:点击查询、高级查询) */ private boolean loadByCondition = false; /** * 属性字段对应的索引 */ private Map fieldToColumnIndex = new HashMap(); private Map headerToFieldMap = new HashMap(); private Map> columnCustomClassMap = new HashMap>(); /** * 列索引对象的属性字段 */ private Map indexToFieldMap = new HashMap(); /** * 列索引对应属性列头 */ private Map indexToHeaderMap = new HashMap(); /** * href 列表 */ private LinkedList hrefFieldList = new LinkedList(); private LinkedList rowModelList = new LinkedList(); private String formId = ""; private QueryTemplate queryTemplate = null; private String queryTemplateName = null; /** * table 的定义信息 PortalVI对象 */ private PortalVI tableDef = null; /** * table 的定义信息 PRM对象 */ private PRM tableDefPRM = null; /** * table 的定义明细 PRMItem对象 */ private PRMItem tableDefPRMItem = null; protected Map allAttrItemMap = new HashMap(); private LinkedHashMap> dataTypeToClassMap = new LinkedHashMap>(); public TablePanelDataProvider(IRegionPanel regionPanel, DataModelFactory factory, String type, String context, PLDefination defination){ allAttrItemMap = UIFCache.getInstance().getAllAttributeMap(); initDataTypeToClassMap(); this.regionPanel = regionPanel; this.factory = factory; this.type = type; this.context = context; this.defination = defination; loadHeaderColumns(2); } private Map columnsMap = null; /** * table 使用的表单定义信息 PortalVI对象 */ private PortalVI tableFormDef = null; /** * table 使用的表单定义信息 PRM对象 */ private PRM tableFormDefPRM = null; /** * table 使用的Form PRMItem List */ private LinkedList tableFormPRMItemList = new LinkedList(); /** * table使用的Form PRMItem Map */ private Map tableFormPRMItemMap = new HashMap(); /** * 列宽映射map key:列索引 value:宽度 */ private HashMap columnWidthMap = new HashMap(); /** * 可编辑列的索引值 */ private List editableColumnList = new LinkedList(); public HashMap getColumnWidthMap() { return columnWidthMap; } public void setColumnWidthMaps(HashMap columnWidthMap) { this.columnWidthMap = columnWidthMap; } public List getEditableColumnList() { return editableColumnList; } public void setEditableColumnList(List editableColumnList) { this.editableColumnList = editableColumnList; } /** * Table 数据显示,使用的 LinkType */ private String linkType = ""; /** * Table 数据显示,主业务类型 */ private String showType = ""; /** * Table 使用的table表单模板名称 */ private String templateId = ""; /** * 业务类型名称 */ private String typeToLoad = ""; /** * 返回 Table 数据显示,使用的 LinkType * @return */ public String getLinkType() { return linkType; } /** * Table 数据显示,使用的 LinkType * @param linkType */ public void setLinkType(String linkType) { this.linkType = linkType; } /** * 返回 Table 数据显示,主业务类型 * @return */ public String getShowType() { return showType; } /** * 设置 Table 数据显示,主业务类型 * @param showType */ public void setShowType(String showType) { this.showType = showType; } /** * 返回 Table 使用的table表单模板名称 * @return */ public String getTemplateId() { return templateId; } /** * 设置 Table 使用的table表单模板名称 * @param templateId */ public void setTemplateId(String templateId) { this.templateId = templateId; } /** * 返回 业务类型名称 * @return */ public String getTypeToLoad() { return typeToLoad; } /** * 设置 业务类型名称 * @param typeToLoad */ public void setTypeToLoad(String typeToLoad) { this.typeToLoad = typeToLoad; } protected void loadHeaderColumns(int startColumnIndex){ DataModelProcessor processor = new DataModelProcessor(); try{ linkType = defination.getLinkType(); showType = defination.getShowType(); templateId = defination.getTemplateId(); if(linkType != null && !"".equals(linkType)){ typeToLoad = linkType; } else { typeToLoad = showType; } if(this.tableDef == null || this.tableDefPRM == null){ loadPortalVIAndPrm(typeToLoad, templateId); } // table 具体的定义明细信息结构 tableDefPRMItem = tableDefPRM.getPrmItemList().get(0); // 使用的form String formId = tableDefPRMItem.getItemInObj(); tableFormDef = UITools.getService().getPortalVIById(formId); tableFormDefPRM = UITools.getPRM(tableFormDef.prm); //获取自定义列的显示类型定义类 getCustomColClassType(tableFormDefPRM); // tableFormDefPRM. // table 定义的输出属性 String[] column = tableDefPRMItem.getItemOutFields().split(","); // 得到属性的名称与描述的映射map columnsMap = processor.getSheetColumnMap(tableFormDef, column); LinkedList listCols = new LinkedList(); // 计算 table 的属性列map calcFileColumnMap(tableFormDefPRM); int columnIndex = startColumnIndex; for(Iterator it = columnsMap.keySet().iterator();it.hasNext();){ String key = it.next(); String header = columnsMap.get(key); listCols.add(header); headerToFieldMap.put(header, key); if(key.equalsIgnoreCase("oid") || key.equalsIgnoreCase("nameid") || key.equalsIgnoreCase("revisionid")) continue; fieldToColumnIndex.put(key, columnIndex); indexToFieldMap.put(columnIndex, key); indexToHeaderMap.put(columnIndex, header); columnIndex += 1; } // 计算列宽 calcFieldColumnWidthMap(); // 计算哪些列可以编辑 calcEditableColumnList(); headerColumns = listCols.toArray(new String[]{}); queryTemplateName = tableDefPRMItem.getItemQtName(); // update by xchao 2017.07.03 begin // 如果组件上定义了查询模板,则以这个为准 if(StringUtils.isNotEmpty(getDefination().getQueryTemplateName())){ queryTemplateName = getDefination().getQueryTemplateName(); } // update by xchao 2017.07.03 end queryTemplate = this.getQueryTemplateByName(getQueryTemplateName()); }catch(VCIError e){ e.printStackTrace(); } } public void getCustomColClassType(PRM sheetPrm) { for (int i = 0; i < sheetPrm.getPrmItemList().size(); i++) { String key = sheetPrm.getPrmItemList().get(i).getItemField(); if (!sheetPrm.getPrmItemList().get(i).getItemType().equalsIgnoreCase(PRMConstants.CUSTOM)) { continue; } String style = sheetPrm.getPrmItemList().get(i).getItemStyle(); if (style == null || style.indexOf("tableClassType") < 0) { continue; } String[] styles = style.split(","); for (int j = 0; j < styles.length; j++) { if (styles[j].indexOf("tableClassType") < 0) { continue; } String[] classTypes = styles[j].split("="); if (classTypes.length < 2) { break; } String classType = classTypes[1]; if (classType.equalsIgnoreCase("image")) { columnCustomClassMap.put(key, ImageIcon.class); break; } } } } /** * 整数正则表达式 */ private Pattern ptnNumInteger = Pattern.compile("[0-9]+"); /** * 浮点数正则表达式 */ private Pattern ptnNumFloat = Pattern.compile("[0-9]+(\\.[0-9]+)?"); /** * 计算列宽map */ private void calcFieldColumnWidthMap(){ String columnWidthDef = tableDefPRMItem.getItemFieldWidth().trim(); if(columnWidthDef != null && !"".equals(columnWidthDef)){ String[] outFields = tableDefPRMItem.getItemOutFields().split(","); String[] widths = columnWidthDef.split(","); if(widths.length != outFields.length) return; // 设置列宽 for (int i = 0; i < outFields.length; i++) { String field = outFields[i]; if(!fieldToColumnIndex.containsKey(field)) continue; int fieldIndex = fieldToColumnIndex.get(field); String widthString = widths[i]; if(ptnNumInteger.matcher(widthString).matches()) { int columnWidth = Integer.valueOf(widthString); columnWidthMap.put(fieldIndex, columnWidth); } else if(ptnNumFloat.matcher(widthString).matches()){ float columnWidth = Float.valueOf(widthString); columnWidthMap.put(fieldIndex, (int)columnWidth); } } } } /** * 计算可编辑列的索引值 */ private void calcEditableColumnList(){ for(PRMItem item : tableFormDefPRM.getPrmItemList()){ String field = item.getItemField(); if(!fieldToColumnIndex.containsKey(field)) continue; int fieldIndex = fieldToColumnIndex.get(field); boolean editable = ControlFactory.isEditable(item); if(editable){ editableColumnList.add(fieldIndex); } } } @Override public Class[] getClasses(){ Class[] clazzes = super.getClasses(); String[] columns = super.getColumns(); for (int i = 0; i < columns.length; i++) { String column = columns[i]; if(column.equalsIgnoreCase("CheckBox")) clazzes[i] = Boolean.class; else if(column.equalsIgnoreCase("序号")) clazzes[i] = Integer.class; else if (columnCustomClassMap.get(column) != null) { clazzes[i] = columnCustomClassMap.get(column); } else { Class classze = String.class; if(headerToFieldMap.containsKey(column)){ String field = headerToFieldMap.get(column); if (columnCustomClassMap.get(field) != null) { clazzes[i] = columnCustomClassMap.get(field); } else { String[] fields = field.split("\\."); field = fields[fields.length - 1]; if(allAttrItemMap.containsKey(field)){ String dataType = allAttrItemMap.get(field).vtDataType; if(dataTypeToClassMap.containsKey(dataType)){ classze = dataTypeToClassMap.get(dataType); } } } } else clazzes[i] = classze; } } return clazzes; } private void initDataTypeToClassMap(){ dataTypeToClassMap.put(VTDataType.VTSTRING, String.class); dataTypeToClassMap.put(VTDataType.VTINTEGER, Integer.class); dataTypeToClassMap.put(VTDataType.VTLONG, Long.class); dataTypeToClassMap.put(VTDataType.VTDOUBLE, Double.class); dataTypeToClassMap.put(VTDataType.VTBOOLEAN, Boolean.class); dataTypeToClassMap.put(VTDataType.VTIMAGE, String.class); dataTypeToClassMap.put(VTDataType.VTDATE, Date.class); dataTypeToClassMap.put(VTDataType.VTTIME, Time.class); dataTypeToClassMap.put(VTDataType.VTDATETIME, Date.class); dataTypeToClassMap.put(VTDataType.VTNOTE, String.class); dataTypeToClassMap.put(VTDataType.VTFILEPATH, String.class); } private Map fileFieldMap = new HashMap(); private void calcFileColumnMap(PRM prm){ for(PRMItem item : prm.getPrmItemList()){ tableFormPRMItemList.add(item); tableFormPRMItemMap.put(item.getItemField(), item); if(item.getItemType().equalsIgnoreCase("file")){ fileFieldMap.put(item.getItemField(), item); } } } @Override public String[] getSpecialColumns() { return headerColumns; } /** * 计算出href字段数据结构 * @param prm */ private void calcHrefFieldDataStruct(PRM prm){ String hrefFields = prm.getPrmItemList().get(0).getItemHrefFields(); if(hrefFields != null && !hrefFields.equals("")){ //t_oid.id----> t_oidid if(hrefFields.contains(".")){ hrefFields = hrefFields.replace(".", ""); } // add href field to map if(hrefFields != null && !hrefFields.equals("")){ hrefFieldList.add(hrefFields); } } } @Override public IDataNode[] getDatas(int pageIndex, int pageSize) { // 标准Table使用 return this.getDatasByParentDataNode(pageIndex, pageSize, this.getRegionPanel().getSourceData()); } /** * 返回查询模板的方向 * @param queryTemplate * @return * @throws VCIError * @throws VCIException * @throws DocumentException */ public boolean getQueryTemplateDirectory(){ return getQueryTemplateDirectory(getQueryTemplateByName(getQueryTemplateName())); } /** * 返回查询模板的方向 * @param qt * @return true:正向 false:反向 */ private boolean getQueryTemplateDirectory(QueryTemplate qt) { boolean isForward = true; if(qt != null && qt.getDirection() != null){ if(qt.getDirection().equals(QTConstants.DIRECTION_POSITIVE)){ isForward = true; } else if(qt.getDirection().equals(QTConstants.DIRECTION_OPPOSITE)){ isForward = false; } } return isForward; } /** * 根据查询模板名称,返回查询模板 * @param queryTemplateName 查询模板 * @return */ private QueryTemplate getQueryTemplateByName(String queryTemplateName){ if(this.queryTemplate != null){ return this.queryTemplate; } QueryTemplate qt = UIFUtils.getQueryTemplateByName(queryTemplateName); this.queryTemplate = qt; return qt; } /** * 返回查询模板查询替换查询条件MAP * @param qt * @return */ private Map getQueryTemplateReplaceMap(QueryTemplate qt, IDataNode sourceData){ Map map = new HashMap(); Map valueMap = new HashMap(); Object masterObject = null; if(sourceData == null || sourceData.getMaterObject() instanceof String) { // add by xchao 2015.04.27 为保证能够返回一个正常(可以进行查询的 replacemap) // 当sourcedata为null时,为其创建 '非'null的结构 sourceData = new DefaultTableNode(); sourceData.setMasterObject(new ClientBusinessObject()); sourceData.setValueMap(new HashMap()); } else { masterObject = sourceData.getMaterObject(); valueMap = sourceData.getValueMap(); } if(qt == null) return map; Condition cond = qt.getCondition(); if(cond == null) return map; Map globalConditionMap = GlobalContextParam.getInstance().getDefaultConditionMap(); IRegionPanel regionPanel = getRegionPanel(); Map ciMap = cond.getCIMap(); Iterator it = ciMap.keySet().iterator(); while (it.hasNext()) { String key = it.next(); ConditionItem ci = ciMap.get(key); // add by xhao 2014.04.16 begin // 异常现象:查询模板显示,只定义了两个替换条件 // 但此时查询出的替换条件确有3三 // 第三个 ci对象不为空,但其leafInfo为空 // 因此针对此情况进行判空处理 if (ci == null) continue; LeafInfo li = ci.getLeafInfo(); if (li == null) continue; // add by xhao 2014.04.16 end // 替换值 String replaceField = li.getValue().getOrdinaryValue(); if (replaceField == null || replaceField.equals("")) { QueryTemplate innerQt = li.getValue().getQueryTemplate(); map.putAll(getQueryTemplateReplaceMap(innerQt, sourceData)); continue; } String replacedValue = ""; if (replaceField.equals(T_OID)) { replacedValue = this.getFromOid(sourceData); } else if (replaceField.equals(F_OID)) { replacedValue = this.getFromOid(sourceData); } else if (replaceField.equals("oid")) { if (masterObject instanceof ClientBusinessObject) { replacedValue = regionPanel .getBusinessObjectOid(sourceData); } else if (masterObject instanceof ClientLinkObject) { replacedValue = regionPanel.getLinkObjectOid(sourceData); } }else if (globalConditionMap.containsKey(replaceField)) { replacedValue = globalConditionMap.get(replaceField); } else if (replaceField.startsWith("#") && replaceField.endsWith("#")) { replaceField = replaceField.substring(1, replaceField.length() - 1); if (globalConditionMap.containsKey(replaceField)) { replacedValue = globalConditionMap.get(replaceField); } } // 替换值是 ${x}-${y} 形式的 变量 else if (isFreemarkTemplateContent(replaceField)) { valueMap = appendToValueMap(replaceField, valueMap); // update by xchao 2015.08.13 // 每次都重新 计算 rootMap Map rootMap = this.convertValueMapToFPOMap(valueMap); // if(isExistInMap(replaceField, valueMap)){ // replacedValue = FreeMarkerCommon.getValueByTempRule(rootMap, // replaceField.replace(".", "_")); replacedValue = FreeMarkerCommon.getValueByTempRule(rootMap, replaceFreemarkerField(replaceField)); // } else { // replacedValue = replaceField; // } }else if (sourceData.getValueMap().containsKey(replaceField)){ replacedValue = sourceData.getValueMap().get(replaceField); } // 固定值 else { replacedValue = replaceField; } map.put(replaceField, replacedValue); } return map; } private String replaceFreemarkerField(String replaceValue){ String src = replaceValue; String field = replaceValue; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; while(!"".equals(field) && begin >= 0 && end < len){ key = field.substring(begin + 2, end); src = src.replace(key, key.replace(".", "_")); field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); } return src; } private Map appendToValueMap(String replaceField, Map valueMap){ String field = replaceField; int begin = field.indexOf("${"); int end = field.indexOf("}"); int len = field.length(); String key = ""; while(!"".equals(field) && begin >= 0 && end < len){ key = field.substring(begin + 2, end); if(!valueMap.containsKey(key)){ valueMap.put(key, key); } field = field.substring(end + 1); begin = field.indexOf("${"); end = field.indexOf("}"); len = field.length(); } return valueMap; } // /** // * 检查要替换的字段KEY是否全部存在于valueMap中 // * @param replaceField 查询模板中替换值的查询属性值 // * @param valueMap dataSource.getValueMap() // * @return // */ // private boolean isExistInMap(String replaceField, Map valueMap){ // boolean res = true; // String field = replaceField; // int begin = field.indexOf("${"); // int end = field.indexOf("}"); // int len = field.length(); // String key = ""; // while(!"".equals(field) && begin >= 0 && end < len){ // key = field.substring(begin + 2, end); // if(!valueMap.containsKey(key)){ // System.out.println("变量:" + key + " 在 sourceData.getValueMap() 中不存在。"); // return false; // } // field = field.substring(end + 1); // begin = field.indexOf("${"); // end = field.indexOf("}"); // len = field.length(); // res = true; // } // return res; // } private void loadPortalVIAndPrm(String type, String tableName) throws VCIError{ PortalVI sheet = factory.getTableDefinationByTypeAndTableName(type, tableName); PRM prm = UITools.getPRM(sheet.prm); this.tableDef = sheet; this.tableDefPRM = prm; } /** * 根据sourceData及当前上下文,返回数据 * @param pageIndex * @param pageSize * @param parentDataNode * @return */ public IDataNode[] getDatasByParentDataNode(int pageIndex, int pageSize, IDataNode parentDataNode){ List dataNodeList = new LinkedList(); linkType = defination.getLinkType(); showType = defination.getShowType(); templateId = defination.getTemplateId(); boolean isShowLinkType = (linkType != null && !"".equals(linkType)); try { String typeToLoad = ""; if(isShowLinkType){ typeToLoad = linkType; } else { typeToLoad = showType; } if(this.tableDef == null || this.tableDefPRM == null){ loadPortalVIAndPrm(typeToLoad, templateId); } // 计算查出 Href 属性 calcHrefFieldDataStruct(tableDefPRM); // 获取标准过滤条件 Map conditionMap = getNormalConditionMap(tableDefPRM, showType, parentDataNode); // 传入分页参数 conditionMap.put(QueryConditionConstants.PAGESIZE, String.valueOf(pageSize)); conditionMap.put(QueryConditionConstants.PAGENO, String.valueOf(pageIndex)); DataModelProcessor processor = new DataModelProcessor(); // 返回查询模板 QueryTemplate qt = this.queryTemplate; // 计算查询方向 boolean isForward = getQueryTemplateDirectory(qt); // Map formColumnsMap = processor.getFormColumnMap(tableFormDef); // if(isShowLinkType){ dataNodeList = this.getLinkDataList(qt, tableDef, processor, pageSize, pageIndex, conditionMap, parentDataNode, isForward, formColumnsMap, linkType); } else { dataNodeList = this.getObjectDataList(qt, tableDef, processor, pageSize, pageIndex, conditionMap, parentDataNode, isForward, formColumnsMap, showType); } } catch (Exception e){ e.printStackTrace(); VCIJOptionPane.showError((Component) regionPanel, e.toString()); } catch (Throwable e) { e.printStackTrace(); VCIJOptionPane.showError((Component) regionPanel, e.toString()); } return dataNodeList.toArray(new IDataNode[]{}); } /** * 返回标准的公共查询条件 * @param prm * @param showType * @param parentDataNode * @return * @throws VCIError */ private Map getNormalConditionMap(PRM prm, String showType, IDataNode parentDataNode) throws VCIError{ String addFileter = prm.getPrmItemList().get(0).getItemAddFilter(); String[] addFileters = addFileter.split(","); //add by 2014.03.20 获得初始化条件Map Map conditionMap = GlobalContextParam.getInstance().getDefaultConditionMap(); conditionMap.put(UIHelper.TYPE, showType); boolean creatorFlag = false; boolean userSecretLevelFlag = false; for(int i = 0; i < addFileters.length; i++){ String filter = addFileters[i]; if(filter.contains("creator") && filter.contains("true")){ creatorFlag = true; } if(filter.contains("userSecretLevel") && filter.contains("true")){ userSecretLevelFlag = true; } if(creatorFlag && userSecretLevelFlag){ break; } } if (creatorFlag) { conditionMap.put(QueryConditionConstants.CREATOR, ClientContextVariable.getInvocationInfo().userName); } if (userSecretLevelFlag) { conditionMap .put(QueryConditionConstants.USER_SECRET_LEVEL_DB, ClientContextVariable.getInvocationInfo().secretGrade); } // 从源对象中取OID String oid = ""; IDataNode sourceData = parentDataNode; if(sourceData != null){ oid = this.getFromOid(sourceData); conditionMap.put("oid", this.getRegionPanel().getLinkObjectOid(sourceData)); //为什么不把oid值直接存储?如果当前RegionPanel不是LinkObject怎么办?看不懂的程序? by zgy 2015-02-15 } if(oid != null && !"".equals(oid)){ ClientBusinessObjectOperation operation = new ClientBusinessObjectOperation(); conditionMap.put(QueryConditionConstants.TRAINSITIONOID, oid); ClientBusinessObject ccbo = operation.readBusinessObjectById(oid, getDefination().getShowType()); //"getDefination().getShowType()"与源对象有什么关系??? by zgy 2015-02-15 conditionMap.put(QueryConditionConstants.NAME_OID, ccbo.getNameoid()); } conditionMap.put(QueryConditionConstants.FROM_OID, oid); //为什么要强制增加这种数据?内置了"f_oid"太多的解释?? by zgy 2015-02-15 return conditionMap; } /** * 返回dataSource上的F_OID *

当dataSource.getMasterObject() *

1、是BO时,此时返回此BO的oid

*

2、是LO时,此时根据此dataSource.isForward判断,当isForward是

*
    *
  • 2.1是true(正向)时,此时取此LO的TO端对象的oid,即此LINK上的T_OID


  • *
  • 2.2是false(反向)时,此时取此LO的FROM端对象的oid,即此LINK上的F_OID


  • *
  • 2.3此时返回的oid是TO端或FROM端对象最初始那个版本数据的OID


  • *
* @param sourceData * @return */ private String getFromOid(IDataNode sourceData){ String oid = ""; if(sourceData != null){ oid = this.getRegionPanel().getBusinessObjectOid(sourceData); } return oid; } /** * 返回LO查询结果 * @param qt * @param sheet * @param processor * @param pageSize * @param pageIndex * @param conditionMap * @param sourceData * @param isForward * @param formColumnsMap * @param linkType * @return * @throws VCIError * @throws DocumentException */ private LinkedList getLinkDataList( QueryTemplate qt, PortalVI sheet, DataModelProcessor processor, int pageSize, int pageIndex, Map conditionMap, IDataNode sourceData, boolean isForward, Map formColumnsMap, String linkType) throws VCIError, DocumentException{ Map searchFilterMap = new LinkedHashMap(); LinkedList dataNodeList = new LinkedList(); LinkObject[] los = new LinkObject[0]; Map replaceMap = new LinkedHashMap(); String toType = ""; @SuppressWarnings("unused") String fromOrToOid = ""; if(sourceData == null || sourceData.getMaterObject() instanceof String) { total = 0; return dataNodeList; } Object objData = sourceData.getMaterObject(); if(objData instanceof ClientBusinessObject){ fromOrToOid = ((ClientBusinessObject)objData).getBusinessObject().oid; toType = ((ClientBusinessObject)objData).getBusinessObject().btName; toType = getDefination().getShowType(); } else if(objData instanceof ClientLinkObject){ fromOrToOid = ((ClientLinkObject)objData).getLinkObject().toOid; toType = ((ClientLinkObject)objData).getLinkObject().toBTName; } // 获取输入的查询条件MAP searchFilterMap = getNormalSearchFilterMap(); // 获取替换掉枚举类型的查询MAP searchFilterMap = getReplaceEnumValueMap(searchFilterMap, toType); // 获取查询模板中定义的查询条件MAP replaceMap = this.getQueryTemplateReplaceMap(qt, sourceData); // 将通用的查询条件合并到replaceMap replaceMap.putAll(conditionMap); if (regionPanel.getFromDataMap() != null && regionPanel.getFromDataMap() .size() >0) { for (Map.Entry item : regionPanel.getFromDataMap().entrySet()) { if (!item.getKey().equals("oid") ) { // Add by zhonggy 2015-08 (计价系统需求,by xiejun) replaceMap.put(item.getKey(), item.getValue()); } } } long start = System.currentTimeMillis(); // 查询 los = processor.getLinkObjectByQueryTemplate(getQueryTemplateName(), replaceMap, searchFilterMap); long end = System.currentTimeMillis(); UIFUtils.writeClientLog("链接对象查询耗时:", start, end); start = System.currentTimeMillis(); // 返回二次查询结果 dataNodeList = this.getLinkDataSecondList(processor, los, isForward, linkType, formColumnsMap); end = System.currentTimeMillis(); UIFUtils.writeClientLog("链接对象二次查询耗时:", start, end); //计算自定义列 getCustomValue(dataNodeList, processor, sheet); // 计算总数 replaceMap.remove(QueryConditionConstants.PAGENO); replaceMap.remove(QueryConditionConstants.PAGESIZE); start = System.currentTimeMillis(); total = processor.getObjectCountByTemplate(getQueryTemplateName(), replaceMap, searchFilterMap); end = System.currentTimeMillis(); UIFUtils.writeClientLog("链接对象查询总数耗时:", start, end); return dataNodeList; } /** * 返回LO二次查询结果 * @param processor * @param los * @param isForward * @param linkType * @param formColumnsMap * @return */ private LinkedList getLinkDataSecondList( DataModelProcessor processor, LinkObject[] los, boolean isForward, String linkType, Map formColumnsMap){ return this.getLinkDataSecondList_v2(processor, los, isForward, linkType, formColumnsMap); } /** * 返回LO二次查询结果 * @param processor * @param los * @param isForward * @param linkType * @param formColumnsMap * @return */ @SuppressWarnings("unchecked") private LinkedList getLinkDataSecondList_v2( DataModelProcessor processor, LinkObject[] los, boolean isForward, String linkType, Map formColumnsMap){ if(los.length == 0) { return new LinkedList(); } Map> referenceKeyMap = processor.getReferenceCol(formColumnsMap); Iterator referenceKey = referenceKeyMap.keySet().iterator(); List referenceList = new LinkedList(); while (referenceKey.hasNext()) { referenceList.add(referenceKey.next()); } LinkedList dataNodeList = new LinkedList(); List typeNameList = new ArrayList(); List cLink = new LinkedList(); for (LinkObject lo : los) { String type = ""; if (isForward) { type = "t_btwname"; } else { type = "f_btwname"; } String cType = ObjectTool.getLOAttributeValue(lo, type); cLink.add(lo); typeNameList.add(cType); // 在LinkObject 加入 linkTypeName 属性 AttributeValue[] avs = Arrays.copyOfRange(lo.hisAttrValList, 0, lo.hisAttrValList.length+1); AttributeValue av = new AttributeValue("linkTypeName".toLowerCase(), linkType); avs[avs.length-1] = av; lo.hisAttrValList = avs; // 将数据对象加入到列表 IDataNode dataNode = new DefaultTableNode(); ClientLinkObject clo = new ClientLinkObject(); clo.setLinkObject(lo); dataNode.setMasterObject(clo); dataNode.setForward(isForward); dataNodeList.add(dataNode); } List> resMap = new LinkedList>(); Map rowRefMap = new LinkedHashMap(); Map rowKeyMap = new LinkedHashMap(); for (LinkObject lo : cLink.toArray(new LinkObject[]{})) { Map res = CBOHelper.getLOValueMap(lo); resMap.add(res); String loOid = lo.oid; String refKey = ""; if (referenceList.size() > 0) { refKey = referenceList.get(0); loOid = ObjectTool.getLOAttributeValue(lo, refKey); } if(!loOid.equals(lo.toOid)){ loOid = lo.toOid; } if(!isForward){ loOid = lo.fromOid; } rowRefMap.put(loOid, refKey); rowKeyMap.put(ObjectUtility.getNewObjectID36(), loOid); } Map secQueryMap = processor.getQueryLinkObjectCondition(linkType, rowKeyMap, rowRefMap, referenceKeyMap); RefPath[] refPaths = processor.queryReference(secQueryMap, typeNameList.toArray(new String[0])); connectSecondQueryResult(resMap.toArray(new LinkedHashMap[0]), refPaths, secQueryMap, referenceKeyMap); int curPos = 0; for (Map r : resMap) { dataNodeList.get(curPos).setValueMap(r); curPos++; } if(dataNodeList.size() > 0){ IDataNode dataNode = dataNodeList.get(0); ClientLinkObject clo = (ClientLinkObject) dataNode.getMaterObject(); String fromType = clo.getLinkObject().fromBTName; String toType = clo.getLinkObject().toBTName; calcAttrEnumMapForBtmType(new String[]{fromType, toType}); calcAttrEnumMapForLinkType(new String[]{clo.getLinkObject().ltName}); // TO端参照的枚举、TO端参照的参照的枚举、参照的参照的参照的枚举、.... Iterator its = dataNode.getValueMap().keySet().iterator(); while(its.hasNext()){ // e.g: //to:materialratio 材料定额对象 //t_oid.usedbypart 材料定额的所属零部件 //t_oid.usedbypart.name 所属零部件名称 //t_oid.usedbypart.parttype 所属零部件类型 //t_oid.usedbypart.usemat.name 所属零部件使用的材料名称 //t_oid.usedbypart.usemat.measurementunit 所属零部件使用材料的计量单位 String key = its.next(); String[] groups = key.split("\\."); if(groups.length <= 2) continue; int dotFirstIndex = key.indexOf("."); int dotLastIndex = key.lastIndexOf("."); if(dotLastIndex < 0 || dotFirstIndex == dotLastIndex) continue; try{ String loopToType = toType; for (int i = 1; i < groups.length; i++) { String refBtmName = getReferenceBtmName(loopToType, groups[i]).trim(); if(refBtmName != null && !"".equals(refBtmName) && !typeAttrEnumValueToNameMap.containsKey(refBtmName)){ calcAttrEnumMapForBtmType(new String[]{refBtmName}); if(typeAttrEnumValueToNameMap.containsKey(refBtmName)){ HashMap> map = typeAttrEnumValueToNameMap.get(refBtmName); String newKey = ""; for (int j = 0; j <= i; j++) { if(j != i){ newKey += groups[j] + "."; } else { newKey += groups[j]; } } typeAttrEnumValueToNameMap.put(newKey, map); } } loopToType = refBtmName; } }catch(Exception ex){ ex.printStackTrace(); } } } return dataNodeList; } // @Deprecated // private LinkedList getLinkDataSecondList_v1( // DataModelProcessor processor, // LinkObject[] los, boolean isForward, String linkType, // Map formColumnsMap){ // @SuppressWarnings("unchecked") // Map[] res = new LinkedHashMap[0]; // LinkedList dataNodeList = new LinkedList(); // Map> multiTypeLink = new LinkedHashMap>(); // for (LinkObject lo : los) { // String type = ""; // if (isForward) { // type = "t_btwname"; // } else { // type = "f_btwname"; // } // if (multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, type)) == null) { // List cLink = new LinkedList(); // cLink.add(lo); // multiTypeLink.put(ObjectTool.getLOAttributeValue(lo, type), cLink); // } else { // multiTypeLink.get(ObjectTool.getLOAttributeValue(lo, type)).add(lo); // } // // 在LinkObject 加入 linkTypeName 属性 // AttributeValue[] avs = Arrays.copyOfRange(lo.hisAttrValList, 0, lo.hisAttrValList.length+1); // AttributeValue av = new AttributeValue("linkTypeName".toLowerCase(), linkType); // avs[avs.length-1] = av; // lo.hisAttrValList = avs; // // // 将数据对象加入到列表 // IDataNode dataNode = new DefaultTableNode(); // ClientLinkObject clo = new ClientLinkObject(); // clo.setLinkObject(lo); // dataNode.setMasterObject(clo); // dataNode.setForward(isForward); // dataNodeList.add(dataNode); // } // // Map> referenceKeyMap = processor.getReferenceCol(formColumnsMap); // Iterator referenceKey = referenceKeyMap.keySet().iterator(); // List referenceList = new LinkedList(); // while (referenceKey.hasNext()) { // referenceList.add(referenceKey.next()); // } // List> listRes = new LinkedList>(); // Iterator itor = multiTypeLink.keySet().iterator(); // while (itor.hasNext()) { // String cType = itor.next(); // List cLinkList = multiTypeLink.get(cType); // res = CBOHelper.getLOValueMap(cLinkList.toArray(new LinkObject[]{})); // Map rowRefMap = new LinkedHashMap(); // Map rowKeyMap = new LinkedHashMap(); // for (LinkObject lo : cLinkList.toArray(new LinkObject[]{})) { // String loOid = lo.oid; // String refKey = ""; // if (referenceList.size() > 0) { // refKey = referenceList.get(0); // loOid = ObjectTool.getLOAttributeValue(lo, refKey); // } // if(!loOid.equals(lo.toOid)){ // loOid = lo.toOid; // } // if(!isForward){ // loOid = lo.fromOid; // } // rowRefMap.put(loOid, refKey); // rowKeyMap.put(ObjectUtility.getNewObjectID36(), loOid); // } // Map secQueryMap = processor.getQueryLinkObjectCondition(linkType, rowKeyMap, rowRefMap, referenceKeyMap); // RefPath[] refPaths = processor.queryReference(secQueryMap, cType); // connectSecondQueryResult(res, refPaths, secQueryMap, referenceKeyMap); // for (Map resMap : res) { // listRes.add(resMap); // } // } // for (int i = 0; i < listRes.size(); i++){ // IDataNode dataNode = dataNodeList.get(i); // dataNode.setValueMap(listRes.get(i)); // } // if(dataNodeList.size() > 0){ // IDataNode dataNode = dataNodeList.get(0); // ClientLinkObject clo = (ClientLinkObject) dataNode.getMaterObject(); // String fromType = clo.getLinkObject().fromBTMName; // String toType = clo.getLinkObject().toBTMName; // calcAttrEnumMapForBtmType(new String[]{fromType, toType}); // calcAttrEnumMapForLinkType(new String[]{clo.getLinkObject().linkTypeName}); // // // TO端参照的枚举、TO端参照的参照的枚举、参照的参照的参照的枚举、.... // Iterator its = dataNode.getValueMap().keySet().iterator(); // while(its.hasNext()){ // // e.g: // //to:materialratio 材料定额对象 // //t_oid.usedbypart 材料定额的所属零部件 // //t_oid.usedbypart.name 所属零部件名称 // //t_oid.usedbypart.parttype 所属零部件类型 // //t_oid.usedbypart.usemat.name 所属零部件使用的材料名称 // //t_oid.usedbypart.usemat.measurementunit 所属零部件使用材料的计量单位 // String key = its.next(); // String[] groups = key.split("\\."); // if(groups.length <= 2) continue; // int dotFirstIndex = key.indexOf("."); // int dotLastIndex = key.lastIndexOf("."); // if(dotLastIndex < 0 || dotFirstIndex == dotLastIndex) continue; // try{ // String loopToType = toType; // for (int i = 1; i < groups.length; i++) { // String refBtmName = getReferenceBtmName(loopToType, groups[i]).trim(); // if(refBtmName != null && !"".equals(refBtmName) // && !typeAttrEnumValueToNameMap.containsKey(refBtmName)){ // calcAttrEnumMapForBtmType(new String[]{refBtmName}); // if(typeAttrEnumValueToNameMap.containsKey(refBtmName)){ // HashMap> map = typeAttrEnumValueToNameMap.get(refBtmName); // String newKey = ""; // for (int j = 0; j <= i; j++) { // if(j != i){ // newKey += groups[j] + "."; // } else { // newKey += groups[j]; // } // } // typeAttrEnumValueToNameMap.put(newKey, map); // } // } // loopToType = refBtmName; // } // }catch(Exception ex){ // ex.printStackTrace(); // } // } // } // return dataNodeList; // } private String getReferenceBtmName(String type, String attrField){ String res = ""; try{ //BtmAndApName[] baans = BtmClient.getService().getBtmAndApNameArray(type); BtmItem bt = BtmClient.getService().getBtmItemByName(type); if(bt == null) return ""; BtmAndApName baan = new BtmAndApName(bt.name, bt.apNameArray); for(String apName : baan.apName){ if(apName.equals(attrField)){ AttribItem[] ais = APClient.getService().getAttribItemsByNames(new String[]{apName}); if(ais.length == 0) return ""; AttribItem ai = ais[0]; //btm = material;allowNull = yes;length = 64 String[] others = ai.other.split(";"); for(String other : others){ String[] cvs = other.split("="); if(cvs[0].trim().equalsIgnoreCase("btm")){ String btmName = cvs[1]; return btmName; } } } } }catch(Exception ex){ ex.printStackTrace(); } return res; } private void getCustomValue(LinkedList dataNodeList, DataModelProcessor processor, PortalVI sheet) throws VCIError { Map customMap = getHasCustomPRMItemMap(processor, sheet); List> datas = getDataNodeListValueMap(dataNodeList); Iterator itor = customMap.keySet().iterator(); while (itor.hasNext()) { String key = itor.next(); PRMItem prm = customMap.get(key); getCustomValue(prm, key, customMap, datas); } // 根据属性控件类型(显示类型)处理 if(tableFormPRMItemMap.containsKey("code")){ PRMItem prm = tableFormPRMItemMap.get("code"); getCustomValue(prm, prm.getItemField(), tableFormPRMItemMap, datas); } } private UserChooseControl ucc = null; private void getCustomValue(PRMItem prm, String key, Map customMap, List> datas) throws VCIError { String customCls = prm.getItemCustomClass(); if(customCls != null && !"".equals(customCls)){ executeSetCustomValue(customCls, key, customMap, datas); } else if(prm.getItemType().toLowerCase().equals(ControlType.UserChoose.name().toLowerCase())){ if(ucc == null){ ucc = new UserChooseControl(); } ucc.getCustomValue(key, customMap, datas); } } private Map getHasCustomPRMItemMap(DataModelProcessor processor, PortalVI sheet) throws VCIError{ Map map = new HashMap(); // PortalVI formView = factory.getFormViewById(tableDefPRMItem.getItemInObj()); // // 严格根据属性类型是否是'自定义' // map = processor.getCustomCol(formView); // update by xchao 2014.12.02 begin // 返回全部的定义属性 map = tableFormPRMItemMap; // update by xchao 2014.12.02 end return map; } private List> getDataNodeListValueMap(LinkedList dataNodeList){ List> datas = new LinkedList>(); for (int i = 0; i < dataNodeList.size(); i++) { datas.add(dataNodeList.get(i).getValueMap()); } return datas; } private void executeSetCustomValue(String customCls, String key, Map customMap, List> 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)){ param = "?" + param; } custom.getCustomValue(key + param, customMap, datas); } catch (Exception e){ e.printStackTrace(); } } /** * 返回BO查询结果 * @param qt * @param sheet * @param processor * @param pageSize * @param pageIndex * @param conditionMap * @param sourceData * @param isForward * @param formColumnsMap * @param showType * @return * @throws VCIError * @throws DocumentException */ private LinkedList getObjectDataList( QueryTemplate qt, PortalVI sheet, DataModelProcessor processor, int pageSize, int pageIndex, Map conditionMap, IDataNode sourceData, boolean isForward, Map formColumnsMap, String showType) throws VCIError, DocumentException{ Map searchFilterMap = new LinkedHashMap(); LinkedList dataNodeList = new LinkedList(); BusinessObject[] objs = new BusinessObject[0]; Map replaceMap = new LinkedHashMap(); boolean sourceDataIsFolder = this.checkSourceDataIsFolder(sourceData); Map folderConditionMap = this.getFolderConditionMap(sourceData); // 获取输入的查询条件MAP searchFilterMap = getNormalSearchFilterMap(); // 获取替换掉枚举类型的查询MAP searchFilterMap = getReplaceEnumValueMap(searchFilterMap, showType); // 获取查询模板中定义的查询条件MAP replaceMap = this.getQueryTemplateReplaceMap(qt, sourceData); Map newReplaceMap = new LinkedHashMap(); // 将通用的查询条件合并到replaceMap newReplaceMap.putAll(replaceMap); newReplaceMap.putAll(conditionMap); if (regionPanel.getFromDataMap() != null && regionPanel.getFromDataMap() .size() >0) { for (Map.Entry item : regionPanel.getFromDataMap().entrySet()) { if (!item.getKey().equals("oid") ) { // Add by zhonggy 2015-08 (计价系统需求,by xiejun) String itemVal = item.getValue() == null ? "" : item.getValue(); newReplaceMap.put(item.getKey(), itemVal); } } // newReplaceMap.remove("oid"); } // 如果sourceData是folder,且定义了查询条件,则此时查询时,也需要将FOLDER中定义的查询条件 if(sourceDataIsFolder && folderConditionMap != null){ searchFilterMap.putAll(folderConditionMap); } long start = System.currentTimeMillis(); // 查询 BusinessObject[] objss = processor.getBusinessObjectByQueryTemplate( getQueryTemplateName(), newReplaceMap, searchFilterMap); objs = objss; long end = System.currentTimeMillis(); UIFUtils.writeClientLog("业务对象查询耗时:", start, end); start = System.currentTimeMillis(); // 返回二次查询结果 dataNodeList = this.getObjectDataSecondList(processor, objs, isForward, showType, formColumnsMap); end = System.currentTimeMillis(); UIFUtils.writeClientLog("业务对象二次查询耗时:", start, end); //计算自定义列 getCustomValue(dataNodeList, processor, sheet); // 计算总数 newReplaceMap.remove(QueryConditionConstants.PAGENO); newReplaceMap.remove(QueryConditionConstants.PAGESIZE); start = System.currentTimeMillis(); total = processor.getObjectCountByTemplate(getQueryTemplateName(), newReplaceMap, searchFilterMap); end = System.currentTimeMillis(); UIFUtils.writeClientLog("业务对象查询总数耗时:", start, end); return dataNodeList; } /** * 返回BO二次查询结果 * @param processor * @param objs * @param isForward * @param showType * @param formColumnsMap * @return */ private LinkedList getObjectDataSecondList( DataModelProcessor processor, BusinessObject[] objs, boolean isForward, String showType, Map formColumnsMap){ @SuppressWarnings("unchecked") Map[] res = new LinkedHashMap[0]; LinkedList dataNodeList = new LinkedList(); Map> referenceKeyMap = processor.getReferenceCol(formColumnsMap); Iterator referenceKey = referenceKeyMap.keySet().iterator(); List referenceList = new LinkedList(); while (referenceKey.hasNext()) { referenceList.add(referenceKey.next()); } Map> rowRefMap = new LinkedHashMap>(); for (BusinessObject obj : objs) { String boOid = obj.oid; Map refMap = new LinkedHashMap(); for (int j = 0; j < referenceList.size(); j++) { String refKey = referenceList.get(j); String refVal = ObjectTool.getBOAttributeValue(obj, refKey); refMap.put(refKey, refVal); } rowRefMap.put(boOid, refMap); // 将数据对象加入到列表 IDataNode dataNode = new DefaultTableNode(); ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(obj); dataNode.setMasterObject(cbo); dataNode.setForward(isForward); dataNodeList.add(dataNode); } Map emptypMap = new HashMap(); Iterator itor = rowRefMap.keySet().iterator(); boolean isFirst = true; while (itor.hasNext()) { Map crowMap = rowRefMap.get(itor.next()); Iterator rowMap = crowMap.keySet().iterator(); List removeList = new ArrayList(); while (rowMap.hasNext()) { String ckey = rowMap.next(); String value = crowMap.get(ckey); //modify by songyf 2014.07.03 去掉移除部分代码 if(value == null) { crowMap.put(ckey, ""); } //if (value == null || value.trim().equals("")) { // removeList.add(ckey); //} // end by songyf } int len = removeList.size(); for (int i = 0; i < len; i++) { if (isFirst) { List list = referenceKeyMap.get(removeList.get(i)); emptypMap.put(removeList.get(i), ""); for (int j = 0; j < list.size(); j++) { emptypMap.put(list.get(j), ""); } referenceKeyMap.remove(removeList.get(i)); isFirst = false; } crowMap.remove(removeList.get(i)); } } Map secQueryMap = processor.getQueryBusinessObjectCondition(showType, rowRefMap, referenceKeyMap); RefPath[] refPaths = processor.queryReference(secQueryMap, showType); res = CBOHelper.getBOValueMap(objs); connectSecondQueryResult(res, refPaths, secQueryMap, referenceKeyMap); for (int i = 0; i < res.length; i++){ IDataNode dataNode = dataNodeList.get(i); res[i].putAll(emptypMap); dataNode.setValueMap(res[i]); } if(dataNodeList.size() > 0){ ClientBusinessObject cbo = (ClientBusinessObject) dataNodeList.get(0).getMaterObject(); String fromType = cbo.getBusinessObject().btName; calcAttrEnumMapForBtmType(new String[]{fromType}); } return dataNodeList; } private Map getReplaceEnumValueMap(Map searchFilterMap, String toType){ Map mapNew = new HashMap(); Iterator its = searchFilterMap.keySet().iterator(); while(its.hasNext()){ String key = its.next(); String value = searchFilterMap.get(key); if(value == null || value.equals("")) continue; String boField = key; if(key.lastIndexOf(".") >= 0){ boField = key.substring(key.lastIndexOf(".") + 1); } if(this.typeAttrEnumNameToValueMap.containsKey(toType)){ HashMap> fieldToEnumMap = typeAttrEnumNameToValueMap.get(toType); if(fieldToEnumMap.containsKey(boField)){ HashMap enumNameToValueMap = fieldToEnumMap.get(boField); String enumName = value; if(enumNameToValueMap.containsKey(enumName)){ value = enumNameToValueMap.get(enumName); } } } String keyNew = key; if(keyNew.contains(T_OID)){ keyNew = keyNew.replace(T_OID, T_OID.toUpperCase()); } if(keyNew.contains(F_OID)){ keyNew = keyNew.replace(F_OID, F_OID.toUpperCase()); } mapNew.put(keyNew, value); } return mapNew; } // /** // * 单次查询,全部的属性与其枚举项目名称之间的映射关系 // * key:attrField value:{key:枚举} // */ // private HashMap> allAttrEnumMap = new HashMap>(); /** * */ private HashMap>> typeAttrEnumValueToNameMap = new HashMap>>(); /** * */ private HashMap>> typeAttrEnumNameToValueMap = new HashMap>>(); /** * 计算指定链接类型 枚举属性的值map * @param types 业务类型名称集合 */ public void calcAttrEnumMapForLinkType(String[] linkTypes){ try { LinkType[] lts = LinkTypeStart.getService().getLinkTypes(); for(String type : linkTypes){ for(LinkType lt : lts){ if(type.equals(lt.name)){ calcAttrEnumMapCommonLogic(lt.name, lt.attributes); calcAttrEnumMapForBtmType(lt.btmItemsFrom); calcAttrEnumMapForBtmType(lt.btmItemsTo); } } } } catch (VCIError e) { e.printStackTrace(); } } /** * 计算指定业务类型 枚举属性的值map * @param types 业务类型名称集合 */ public void calcAttrEnumMapForBtmType(String[] btmTypes){ try { for(String type : btmTypes){ // BtmAndApName[] baans = BtmClient.getService().getBtmAndApNameArray(type); // for(BtmAndApName baan : baans) { BtmItem bt = BtmClient.getService().getBtmItemByName(type); calcAttrEnumMapCommonLogic(bt.name, bt.apNameArray); // } } } catch (VCIError e) { e.printStackTrace(); } } private void calcAttrEnumMapCommonLogic(String type, String[] attrNames) throws VCIError{ AttribItem[] arItems = APClient.getService().getAttribItemsByNames(attrNames); for(AttribItem ai : arItems){ //allowNull = yes;enumName = parttypeenum String[] others = ai.other.split(";"); for(String other : others){ String[] cvs = other.split("="); if(cvs[0].trim().equalsIgnoreCase("enumName")){ String enumName = cvs[1].trim(); HashMap enumValueToName = getEnumValueOrNameMap(enumName, true); HashMap> fieldToEnumValuetoNameMap = new HashMap>(); fieldToEnumValuetoNameMap.put(ai.name, enumValueToName); if(typeAttrEnumValueToNameMap.containsKey(type)){ HashMap> mapExist = typeAttrEnumValueToNameMap.get(type); fieldToEnumValuetoNameMap.putAll(mapExist); } typeAttrEnumValueToNameMap.put(type, fieldToEnumValuetoNameMap); HashMap enumNameToValue = getEnumValueOrNameMap(enumName, false); HashMap> fieldToEnumNameToValueMap = new HashMap>(); fieldToEnumNameToValueMap.put(ai.name, enumNameToValue); if(typeAttrEnumNameToValueMap.containsKey(type)){ HashMap> mapExist = typeAttrEnumNameToValueMap.get(type); fieldToEnumNameToValueMap.putAll(mapExist); } typeAttrEnumNameToValueMap.put(type, fieldToEnumNameToValueMap); } } } } private HashMap enumItemMap = new HashMap(); private HashMap getEnumValueOrNameMap(String enumName, boolean valueToName){ HashMap map = new HashMap(); try { if(enumItemMap.size() == 0){ EnumItem[] enumItems = ServiceProvider.getOMDService().getEnumService().getEmItems("", 1, 1); for(EnumItem ei : enumItems){ enumItemMap.put(ei.name, ei); } } if(enumItemMap.containsKey(enumName)){ EnumItem ei = enumItemMap.get(enumName); for(EnumChild ec : ei.children){ if(valueToName){ map.put(ec.value, ec.name); } else { map.put(ec.name, ec.value); } } } } catch (VCIError e) { e.printStackTrace(); } return map; } /** * 检查sourceData是否是文件夹 * @param sourceData * @return */ private boolean checkSourceDataIsFolder(IDataNode sourceData){ boolean res = false; if (sourceData != null && sourceData.getMaterObject() instanceof ClientBusinessObject) { ClientBusinessObject cbo = (ClientBusinessObject)sourceData.getMaterObject(); if (cbo.getBtmName().equalsIgnoreCase("folder")) { res = true; } } return res; } /** * 返回文件夹上定义的查询条件 * @param sourceData * @return */ private Map getFolderConditionMap(IDataNode sourceData){ if(!checkSourceDataIsFolder(sourceData)) return null; Map queryConditionMap = new HashMap(); ClientBusinessObject cbo = (ClientBusinessObject)sourceData.getMaterObject(); String condition = cbo.getAttributeValue("querycondition"); if (condition == null || condition.trim().length() == 0) { return null; } Map globalConditionMap = GlobalContextParam.getInstance().getDefaultConditionMap(); String[] conditions = condition.split(","); // 文件夹上定义的查询条件形式: // principal=#CURRENTUSER.NAME#,worktype=2,businesstype=3,folderoid=${folderoid} for (int i = 0; i < conditions.length; i++) { String key = conditions[i].split("=")[0]; String value = conditions[i].split("=")[1]; // 基础固有查询条件 if(globalConditionMap.containsKey(value)){ value = globalConditionMap.get(value); } else if(value.startsWith("#") && value.endsWith("#")){ value = value.substring(1, value.length() - 1); if(globalConditionMap.containsKey(value)){ value = globalConditionMap.get(value); } } // 变量 else if(isFreemarkTemplateContent(value)){ value = getRuleValue(value, sourceData); } // 指定的固定值 queryConditionMap.put(key, value); } return queryConditionMap; } private boolean isFreemarkTemplateContent(String itemValue){ return UIFUtils.isFreemarkTemplateContent(itemValue); } private String getRuleValue(String itemValue, IDataNode sourceData){ return UIFUtils.getRuleValue(itemValue, sourceData, getRegionPanel()); } private Map convertValueMapToFPOMap(Map map){ Map rootMap = new LinkedHashMap(); Iterator it = map.keySet().iterator(); while(it.hasNext()){ String key = it.next(); String value = map.get(key); String valueFromUILayout = this.getRegionPanel().getBaseLayoutPanel().getValue(key); if(!valueFromUILayout.equals(key)){ value = valueFromUILayout; } if(value == null){ value = ""; } String newKey = key.replace(".", "_"); FreemarkerParamObject fpo = new FreemarkerParamObject(newKey, value); rootMap.put(newKey, fpo); } return rootMap; } private void connectSecondQueryResult(Map[] res, RefPath[] refPaths, Map secQueryMap, Map> referenceKeyMap) { if (refPaths != null) { int colNum = secQueryMap.size(); for (int i = 0; i < res.length; i++) { Map 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); } } } } protected Map getMergedConditionMap(Map orignMap){ Map normalMap = getNormalSearchFilterMap(); if(normalMap != null && normalMap.size() > 0){ Iterator keys = normalMap.keySet().iterator(); while(keys.hasNext()){ String key = keys.next(); String value = normalMap.get(key); if(value != null && !"".equals(value)){ orignMap.put(key, value); } } } return orignMap; } @Override public VCIJTableNode getNewRowNode(IDataNode obj) { VCIJTableNode tableNode = new VCIJTableNode(obj); long start = System.currentTimeMillis(); for(String header : headerColumns){ tableNode.setPropertyValue(header, getPropertyValue(obj, header)); } long end = System.currentTimeMillis(); UIFUtils.writeClientLog("构建数据行耗时:", start, end); return tableNode; } public Object getPropertyValue(IDataNode obj, String header){ Map valueMap = obj.getValueMap(); String field = headerToFieldMap.get(header); String fieldReal = field; String value = valueMap.get(field); Object valueObject = value; String type = ""; ClientLinkObject clo = null; ClientBusinessObject cbo = null; boolean numberValue = true; if(obj.getMaterObject() instanceof ClientLinkObject){ clo = (ClientLinkObject) obj.getMaterObject(); String fromType = clo.getLinkObject().fromBTName; String toType = clo.getLinkObject().toBTName; if(field.contains(F_OID + ".")){ type = fromType; } else if(field.contains(T_OID + ".")){ type = toType; } else { type = clo.getLinkObject().ltName; } String[] splits = field.split("\\."); fieldReal = splits[splits.length - 1]; if(splits.length > 2){ type = ""; for (int i = 0; i <= splits.length - 2; i++) { if(i != splits.length - 2){ type += splits[i] + "."; } else { type += splits[i]; } } } } else if(obj.getMaterObject() instanceof ClientBusinessObject){ cbo = (ClientBusinessObject) obj.getMaterObject(); type = cbo.getBusinessObject().btName; } if(this.typeAttrEnumValueToNameMap.containsKey(type)){ HashMap> fieldToEnumMap = typeAttrEnumValueToNameMap.get(type); if(fieldToEnumMap.containsKey(fieldReal)){ HashMap enumValueToNameMap = fieldToEnumMap.get(fieldReal); String enumValue = obj.getValueMap().get(field); if(enumValueToNameMap.containsKey(enumValue)){ value = enumValueToNameMap.get(enumValue); } numberValue = false; valueObject = value; } } if(value == null){ value = ""; } valueObject = value; try{ if(fileFieldMap.containsKey(field)){ value = FileChooseControlPanel.getFileNameByFOId(value); valueObject = value; numberValue = false; } else if(ptnDateTimeString.matcher(value).matches()){ if(value.contains(TIME_STRING_EMPTY)){ value = value.replace(TIME_STRING_EMPTY, ""); } else { value = value.substring(0, value.lastIndexOf(".")); } numberValue = false; valueObject = value; } else if (columnCustomClassMap.containsKey(field)) { if (ImageIcon.class.equals(columnCustomClassMap.get(field))) { valueObject = VCISwingUtil.createImageIcon(value); } } }catch (Exception e) { e.printStackTrace(); } if(fieldReal.equalsIgnoreCase(LCSTATUS) && valueMap.containsKey(field)){ String lcStatus = valueMap.get(field); if(statePoolsMap.containsKey(lcStatus)){ value = statePoolsMap.get(lcStatus).tag; } valueObject = value; numberValue = false; } if(numberValue && value != null && !"".equals(value) && allAttrItemMap.containsKey(field)){ AttribItem attrItem = allAttrItemMap.get(fieldReal); if(attrItem.vtDataType.equals(VTDataType.VTINTEGER)){ valueObject = Integer.parseInt(valueObject.toString()); } else if(attrItem.vtDataType.equals(VTDataType.VTLONG)){ valueObject = Long.parseLong(valueObject.toString()); } else if(attrItem.vtDataType.equals(VTDataType.VTDOUBLE)){ double dou = Double.valueOf(valueObject.toString()); DecimalFormat df1 = (DecimalFormat)NumberFormat.getInstance(); df1.setGroupingUsed(false); valueObject = df1.format(dou); // valueObject = Double.parseDouble(valueObject.toString()); } } return valueObject; } @Override public int getTotal() { return super.total; } /********************************************************************/ public DataModelFactory getFactory() { return factory; } public void setFactory(DataModelFactory factory) { this.factory = factory; } public String getType() { return type; } public void setType(String type) { this.type = type; } public String getContext() { return context; } public void setContext(String context) { this.context = context; } public PLDefination getDefination() { return defination; } public void setDefination(PLDefination defination) { this.defination = defination; } public IRegionPanel getRegionPanel() { return regionPanel; } public void setRegionPanel(IRegionPanel regionPanel) { this.regionPanel = regionPanel; } public Map getNormalSearchFilterMap() { return normalSearchFilterMap; } public void setNormalSearchFilterMap( HashMap normalSearchFilterMap) { this.normalSearchFilterMap = normalSearchFilterMap; } public boolean isLoadByCondition() { return loadByCondition; } public void setLoadByCondition(boolean loadByCondition) { this.loadByCondition = loadByCondition; } public String getFormId() { return formId; } public void setFormId(String formId) { this.formId = formId; } public LinkedList getHrefFieldList() { return hrefFieldList; } public void setHrefFieldList(LinkedList hrefFieldList) { this.hrefFieldList = hrefFieldList; } public Map getFieldToColumnIndex() { return fieldToColumnIndex; } public Map getHeaderToFieldMap() { return headerToFieldMap; } public Map getIndexToFieldMap() { return indexToFieldMap; } public void setIndexToFieldMap(Map indexToFieldMap) { this.indexToFieldMap = indexToFieldMap; } public Map getIndexToHeaderMap() { return indexToHeaderMap; } public void setIndexToHeaderMap(Map indexToHeaderMap) { this.indexToHeaderMap = indexToHeaderMap; } public Map getFileFieldMap() { return fileFieldMap; } public void setFileFieldMap(Map fileFieldMap) { this.fileFieldMap = fileFieldMap; } public void setHeaderColumns(String[] headerColumns) { this.headerColumns = headerColumns; } public void setFieldToColumnIndex(Map fieldToColumnIndex) { this.fieldToColumnIndex = fieldToColumnIndex; } public void setHeaderToFieldMap(Map headerToFieldMap) { this.headerToFieldMap = headerToFieldMap; } public String[] getHeaderColumns() { return headerColumns; } public LinkedList getRowModelList() { return rowModelList; } private String getQueryTemplateName(){ return this.queryTemplateName; } public QueryTemplate getQueryTemplate(){ return this.queryTemplate; } public PortalVI getTableDef() { return tableDef; } public void setTableDef(PortalVI tableDef) { this.tableDef = tableDef; } public PRM getTableDefPRM() { return tableDefPRM; } public void setTableDefPRM(PRM tableDefPRM) { this.tableDefPRM = tableDefPRM; } public PRMItem getTableDefPRMItem() { return tableDefPRMItem; } public void setTableDefPRMItem(PRMItem tableDefPRMItem) { this.tableDefPRMItem = tableDefPRMItem; } public LinkedHashMap> getDataTypeToClassMap() { return dataTypeToClassMap; } public void setDataTypeToClassMap( LinkedHashMap> dataTypeToClassMap) { this.dataTypeToClassMap = dataTypeToClassMap; } public Map getColumnsMap() { return columnsMap; } public void setColumnsMap(Map columnsMap) { this.columnsMap = columnsMap; } public PortalVI getTableFormDef() { return tableFormDef; } public void setTableFormDef(PortalVI tableFormDef) { this.tableFormDef = tableFormDef; } public PRM getTableFormDefPRM() { return tableFormDefPRM; } public void setTableFormDefPRM(PRM tableFormDefPRM) { this.tableFormDefPRM = tableFormDefPRM; } public LinkedList getTableFormPRMItemList() { return tableFormPRMItemList; } public void setTableFormPRMItemList(LinkedList tableFormPRMItemList) { this.tableFormPRMItemList = tableFormPRMItemList; } public Map getTableFormPRMItemMap() { return tableFormPRMItemMap; } public void setTableFormPRMItemMap(Map tableFormPRMItemMap) { this.tableFormPRMItemMap = tableFormPRMItemMap; } public HashMap getEnumItemMap() { return enumItemMap; } public void setEnumItemMap(HashMap enumItemMap) { this.enumItemMap = enumItemMap; } public void setColumnWidthMap(HashMap columnWidthMap) { this.columnWidthMap = columnWidthMap; } }