package com.vci.client.utils.excel; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import com.vci.client.bof.ClientBusinessObject; import com.vci.client.bof.ClientBusinessObjectOperation; import com.vci.client.bof.ClientLinkObject; import com.vci.client.bof.ClientLinkObjectOperation; import com.vci.client.common.oq.OQTool; import com.vci.client.fm.ClientFileObjectOperation; import com.vci.client.fm.FileObject; import com.vci.client.fm.FileTypeConstants; import com.vci.client.omd.provider.ApProvider; import com.vci.client.omd.provider.EnumProvider; import com.vci.client.oq.QTClient; import com.vci.common.qt.object.Condition; import com.vci.common.qt.object.Connector; import com.vci.common.qt.object.QTConstants; import com.vci.common.qt.object.QueryTemplate; import com.vci.corba.common.VCIError; import com.vci.corba.omd.atm.AttribItem; 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.omd.constants.AttributeConstants; public class ImportDataTool { public static final String ERROR = "error"; public static final String RESULT = "result"; public static final String TRUE = "true"; public static final String FALSE = "false"; private final int PARTIONSIZE = 500; private static ImportDataTool instance = null; private static ImportDataTool getInstance(){ if (instance == null) { instance = new ImportDataTool(); } return instance; } private ClientLinkObjectOperation instanceLo; private ClientLinkObjectOperation getInstanceLo() { if (instanceLo == null) { instanceLo = new ClientLinkObjectOperation(); } return instanceLo; } private ClientBusinessObjectOperation instanceBo; private ClientBusinessObjectOperation getInstanceBo() { if (instanceBo == null) { instanceBo = new ClientBusinessObjectOperation(); } return instanceBo; } public static Map importLOData(File file, String fileName, String type, String linkType, String f_type, String f_oid, String f_revisionOid, String f_nameoid, int updateFlag) throws VCIError, IOException{ Map infoMap = new HashMap(); //压缩文件中的excel数据文件 InputStream dataInputStream = null; Map files = new HashMap(); boolean zipFlag = false; if(fileName.endsWith(".zip")){ zipFlag = true; ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); String tempFolder = file.getParent(); while(entries.hasMoreElements()){ ZipEntry zipEntry = entries.nextElement(); if(!zipEntry.isDirectory()){ String fileName_ = zipEntry.getName(); InputStream inputStream_ = zipFile.getInputStream(zipEntry); if(fileName_.endsWith(".xlsx") || fileName_.endsWith(".xls")){ fileName = fileName_; dataInputStream = inputStream_; }else{ String filePath = tempFolder + "\\" + fileName_; File tempFile = new File(filePath); File folder = tempFile.getParentFile(); if(!folder.exists()){ folder.mkdirs(); } if(!tempFile.exists()){ tempFile.createNewFile(); } BufferedInputStream inBuff = new BufferedInputStream(inputStream_); BufferedOutputStream outBuff = new BufferedOutputStream(new FileOutputStream(tempFile)); byte[] b = new byte[1024 * 512]; int len; while((len = inBuff.read(b)) != -1){ outBuff.write(b, 0, len); } files.put(fileName_, tempFile); inBuff.close(); outBuff.close(); } } } } BufferedInputStream bs; if(zipFlag){ bs = new BufferedInputStream(dataInputStream); }else{ bs = new BufferedInputStream(new FileInputStream(file)); } List sheetDataSets = ExcelDocumentUtils .readExcelDocument(fileName, bs); List dataSets = sheetDataSets.get(0).getDataSet(); String[] dataSet = dataSets.get(0); Set typeSet = new HashSet(); Map typeAttMap = new HashMap(); //判重列 List uniqueCols = new ArrayList(); //文件列 List fileCols = new ArrayList(); for(int i = 0; i < dataSet.length; i++){ String data = dataSet[i]; String[] data_ = data.split("\\."); typeSet.add(data_[0]); //判重列标识 if(data_[1].endsWith("*")){ uniqueCols.add(data_[1].substring(0, data_[1].indexOf("*")).toUpperCase()); data = data.substring(0, data.indexOf("*")); //文件列标识 }else if(data_[1].endsWith("+")){ fileCols.add(data_[1].substring(0, data_[1].indexOf("+")).toUpperCase()); data = data.substring(0, data.indexOf("+")); } typeAttMap.put(i, data); } if(!typeSet.contains(type)){ infoMap.put(ERROR, "文件中无该类型数据"); return infoMap; } if(typeSet.size() > 2){ infoMap.put(ERROR, "文件中含有其他类型数据"); return infoMap; } boolean flag = false; if(zipFlag){ flag = getInstance().saveBOAndLOsWithFile(dataSets, typeAttMap, type, linkType, f_type, f_oid, f_revisionOid, f_nameoid, uniqueCols, updateFlag, fileCols, files); }else{ flag = getInstance().saveBOAndLOs(dataSets, typeAttMap, type, linkType, f_type, f_oid, f_revisionOid, f_nameoid, uniqueCols, updateFlag); } //删除临时文件 for(Iterator ite = files.keySet().iterator(); ite.hasNext();){ String fileName_ = ite.next(); File file_ = files.get(fileName_); file_.delete(); } file.delete(); if(flag){ infoMap.put(RESULT, TRUE); }else{ infoMap.put(RESULT, FALSE); } return infoMap; } /** * 保存业务对象 和 链接对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSets * @param typeAttMap * @param type * @param linkType * @param f_nameoid * @param f_revisionOid * @return * @throws PLMError */ private boolean saveBOAndLOs(List dataSets, Map typeAttMap, String type, String linkType, String f_type, String f_oid, String f_revisionOid, String f_nameoid, List uniqueCols, int updateFlag) throws VCIError { List createListBo = new ArrayList(); List updateListBo = new ArrayList(); List createListLo = new ArrayList(); List updateListLo = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); List allLoList = new ArrayList(); Map loMap = new HashMap(); ClientBusinessObject cboSource = getInstanceBo().createBusinessObject(type); ClientLinkObject cloSource = getInstanceLo().createLinkObject(linkType); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = BOTool.cloneClientBusinessObject(cboSource, true); ClientLinkObject clo = LOTool.cloneClientLinkObject(cloSource, true); String[] data = dataSets.get(i); Map map = new HashMap(); for(int k = 0; k < data.length; k++){ String[] data_ = typeAttMap.get(k).split("\\."); String type_ = data_[0]; String attName = data_[1]; String value = data[k]; value = checkEnum(attName, value); //业务类型属性 if(type_.equalsIgnoreCase(type)){ if(attName.equalsIgnoreCase("ID") || attName.equalsIgnoreCase("NAME") || attName.equalsIgnoreCase("DESCRIPTION")){ map.put(attName.toLowerCase(), value); } cbo.setAttributeValue(attName.toLowerCase(), value, true); //链接类型属性 }else{ clo.setAttributeValue(attName.toLowerCase(), value); } } clo.setFromBTMName(f_type); clo.setFromOid(f_oid); clo.setFromRevisionOid(f_revisionOid); clo.setFromNameOid(f_nameoid); clo.setToBTMName(cbo.getBtmName()); clo.setToOid(cbo.getOid()); clo.setToRevisionOid(cbo.getRevisionid()); clo.setToNameOid(cbo.getNameoid()); map_.put(cbo.getOid(), map); allBoList.add(cbo); allLoList.add(clo); loMap.put(cbo.getOid(), clo); } if (uniqueCols.size() > 0 && allBoList.size() > 0) { List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); ClientLinkObject clo = loMap.get(cbo.getOid()); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateListBo.add(cbo); } // 当bo存在, lo不存在时, 不论bo是覆盖还是跳过 , 都需要创建lo clo.setToOid(bo.oid); clo.setToRevisionOid(bo.revisionid); clo.setToNameOid(bo.nameoid); } else { createListBo.add(cbo); } } if(allLoList.size() > 0){ List queryLO = queryLO(allLoList); for(ClientLinkObject clo : allLoList){ LinkObject lo = isExistLo(clo, queryLO); if(lo != null){ if (updateFlag == 1) { clo.setOid(lo.oid); clo.setTs(lo.ts); updateListLo.add(clo); } }else{ createListLo.add(clo); } } } }else { createListBo.addAll(allBoList); createListLo.addAll(allLoList); } boolean flag = true; if(createListBo.size() > 0 || createListLo.size() > 0){ flag &= getInstanceBo().batchSaveCreateBuinessObject( createListBo.toArray(new ClientBusinessObject[0]), createListLo.toArray(new ClientLinkObject[0])); }else{ flag &= true; } if(updateListBo.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateListBo.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } if(updateListLo.size() > 0){ flag &= getInstanceLo().batchUpdateLinkObject(updateListLo.toArray(new ClientLinkObject[0])); }else{ flag &= true; } return flag; } /** * 保存业务对象 和 链接对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSets * @param typeAttMap * @param type * @param linkType * @param f_nameoid * @param f_revisionOid * @param fileCols : 文件路径列 * @param files : Map * @return * @throws PLMError */ private boolean saveBOAndLOsWithFile(List dataSets,Map typeAttMap, String type, String linkType, String f_type, String f_oid, String f_revisionOid, String f_nameoid, List uniqueCols, int updateFlag, List fileCols, Map files) throws VCIError { List createListBo = new ArrayList(); List updateListBo = new ArrayList(); List createListLo = new ArrayList(); List updateListLo = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); Map> fileMap_ = new HashMap>(); List allLoList = new ArrayList(); Map loMap = new HashMap(); ClientFileObjectOperation operation = new ClientFileObjectOperation(); ClientBusinessObject cboSource = getInstanceBo().createBusinessObject(type); ClientLinkObject cloSource = getInstanceLo().createLinkObject(linkType); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = BOTool.cloneClientBusinessObject(cboSource, true); ClientLinkObject clo = LOTool.cloneClientLinkObject(cloSource, true); String[] data = dataSets.get(i); Map map = new HashMap(); Map fileMap = new HashMap(); for(int k = 0; k < data.length; k++){ String[] data_ = typeAttMap.get(k).split("\\."); String type_ = data_[0]; String attName = data_[1]; String value = data[k]; value = checkEnum(attName, value); //业务类型属性 if(type_.equalsIgnoreCase(type)){ if(attName.equalsIgnoreCase("ID") || attName.equalsIgnoreCase("NAME") || attName.equalsIgnoreCase("DESCRIPTION")){ map.put(attName.toLowerCase(), value); //上传文件 }else if(fileCols.contains(attName.toUpperCase())){ if(uniqueCols.size() > 0){ //文件信息在判重后再补充到对象 fileMap.put(attName, value); continue; }else{ //不需判重,文件信息直接在此处理 //文件以附件形式将对象作为外键(如Document) if(attName.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } continue; //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); } } } cbo.setAttributeValue(attName.toLowerCase(), value, true); //链接类型属性 }else{ clo.setAttributeValue(attName.toLowerCase(), value); } } clo.setFromBTMName(f_type); clo.setFromOid(f_oid); clo.setFromRevisionOid(f_revisionOid); clo.setFromNameOid(f_nameoid); clo.setToBTMName(cbo.getBtmName()); clo.setToOid(cbo.getOid()); clo.setToRevisionOid(cbo.getRevisionid()); clo.setToNameOid(cbo.getNameoid()); map_.put(cbo.getOid(), map); fileMap_.put(cbo.getOid(), fileMap); allBoList.add(cbo); allLoList.add(clo); loMap.put(cbo.getOid(), clo); } if (uniqueCols.size() > 0 && allBoList.size() > 0) { List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); ClientLinkObject clo = loMap.get(cbo.getOid()); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = bo.oid; // 删除对象关联的文档 ClientBusinessObject[] fObjs = getClientFileObjectByDocId(docId); if (fObjs != null && fObjs.length > 0) { getInstanceBo().batchDeleteBuinessObject(fObjs); } // 创建对象关联的文档 String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateListBo.add(cbo); } // 当bo存在, lo不存在时, 不论bo是覆盖还是跳过 , 都需要创建lo clo.setToOid(bo.oid); clo.setToRevisionOid(bo.revisionid); clo.setToNameOid(bo.nameoid); } else { //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } createListBo.add(cbo); } } if(allLoList.size() > 0){ List queryLO = queryLO(allLoList); for(ClientLinkObject clo : allLoList){ LinkObject lo = isExistLo(clo, queryLO); if(lo != null){ if (updateFlag == 1) { clo.setOid(lo.oid); clo.setTs(lo.ts); updateListLo.add(clo); } }else{ createListLo.add(clo); } } } }else { createListBo.addAll(allBoList); createListLo.addAll(allLoList); } boolean flag = true; if(createListBo.size() > 0 || createListLo.size() > 0){ flag &= getInstanceBo().batchSaveCreateBuinessObject( createListBo.toArray(new ClientBusinessObject[0]), createListLo.toArray(new ClientLinkObject[0])); }else{ flag &= true; } if(updateListBo.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateListBo.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } if(updateListLo.size() > 0){ flag &= getInstanceLo().batchUpdateLinkObject(updateListLo.toArray(new ClientLinkObject[0])); }else{ flag &= true; } return flag; } /** * 导入业务对象 * @param file * @param fileName * @param type * @param updateFlag: 当有重复记录时: 1:覆盖; 0:跳过 * @param folderId : 文件夹分类ID(PLCLASSIFY) * @return * @throws VCIError * @throws IOException */ public static Map importBOWithClassifyData(File file, String fileName, String type, int updateFlag, String folderId) throws VCIError, IOException{ Map infoMap = new HashMap(); //压缩文件中的excel数据文件 InputStream dataInputStream = null; Map files = new HashMap(); boolean zipFlag = false; if(fileName.endsWith(".zip")){ zipFlag = true; ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); String tempFolder = file.getParent(); while(entries.hasMoreElements()){ ZipEntry zipEntry = entries.nextElement(); if(!zipEntry.isDirectory()){ String fileName_ = zipEntry.getName(); InputStream inputStream_ = zipFile.getInputStream(zipEntry); if(fileName_.endsWith(".xlsx") || fileName_.endsWith(".xls")){ fileName = fileName_; dataInputStream = inputStream_; }else{ String filePath = tempFolder + "\\" + fileName_; File tempFile = new File(filePath); File folder = tempFile.getParentFile(); if(!folder.exists()){ folder.mkdirs(); } if(!tempFile.exists()){ tempFile.createNewFile(); } BufferedInputStream inBuff = new BufferedInputStream(inputStream_); BufferedOutputStream outBuff = new BufferedOutputStream(new FileOutputStream(tempFile)); byte[] b = new byte[1024 * 512]; int len; while((len = inBuff.read(b)) != -1){ outBuff.write(b, 0, len); } files.put(fileName_, tempFile); inBuff.close(); outBuff.close(); } } } } BufferedInputStream bs; if(zipFlag){ bs = new BufferedInputStream(dataInputStream); }else{ bs = new BufferedInputStream(new FileInputStream(file)); } List sheetDataSets = ExcelDocumentUtils .readExcelDocument(fileName, bs); List dataSets = sheetDataSets.get(0).getDataSet(); String[] dataSet = dataSets.get(0); Set typeSet = new HashSet(); Map typeAttMap = new HashMap(); //判重列 List uniqueCols = new ArrayList(); //文件列 List fileCols = new ArrayList(); for(int i = 0; i < dataSet.length; i++){ String data = dataSet[i]; String[] data_ = data.split("\\."); typeSet.add(data_[0]); //判重列标识 if(data_[1].endsWith("*")){ uniqueCols.add(data_[1].substring(0, data_[1].indexOf("*")).toUpperCase()); data = data.substring(0, data.indexOf("*")); //文件列标识 }else if(data_[1].endsWith("+")){ fileCols.add(data_[1].substring(0, data_[1].indexOf("+")).toUpperCase()); data = data.substring(0, data.indexOf("+")); } typeAttMap.put(i, data); } if(!typeSet.contains(type)){ infoMap.put(ERROR, "文件中无该类型数据"); return infoMap; } if(typeSet.size() > 1){ infoMap.put(ERROR, "文件中含有其他类型数据"); return infoMap; } boolean flag = false; if(zipFlag){ flag = getInstance().saveBOsWithClassifyAndFile(dataSets, typeAttMap, type, uniqueCols, updateFlag, folderId, fileCols, files); }else{ flag = getInstance().saveBOsWithClassify(dataSets, typeAttMap, type, uniqueCols, updateFlag, folderId); } //删除临时文件 for(Iterator ite = files.keySet().iterator(); ite.hasNext();){ String fileName_ = ite.next(); File file_ = files.get(fileName_); file_.delete(); } file.delete(); if(flag){ infoMap.put(RESULT, TRUE); }else{ infoMap.put(RESULT, FALSE); } return infoMap; } /** * 保存业务对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSet * @param typeAttMap * @param type * @param uniqueCols : 判重列 * @param folderId : 文件夹分类ID(PLCLASSIFY) * @return * @throws PLMError * @throws VciException */ private boolean saveBOsWithClassify(List dataSets, Map typeAttMap, String type, List uniqueCols, int updateFlag, String folderId) throws VCIError { List createList = new ArrayList(); List updateList = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); ClientBusinessObject source = getInstanceBo().createBusinessObject(type); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = BOTool.cloneClientBusinessObject(source, true); cbo.setBtmName(type); String[] data = dataSets.get(i); Map map = new HashMap(); for(int k = 0; k < data.length; k++){ String key = typeAttMap.get(k).split("\\.")[1]; String value = data[k]; value = checkEnum(key, value); if(key.equalsIgnoreCase("ID") || key.equalsIgnoreCase("NAME") || key.equalsIgnoreCase("DESCRIPTION")){ map.put(key.toLowerCase(), value); } cbo.setAttributeValue(key.toLowerCase(), value, true); } cbo.setAttributeValue("PLCLASSIFY".toLowerCase(), folderId, true); map_.put(cbo.getOid(), map); allBoList.add(cbo); } if(uniqueCols.size() > 0 && allBoList.size() > 0){ List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateList.add(cbo); } } else { createList.add(cbo); } } }else{ createList.addAll(allBoList); } boolean flag = false; if(createList.size() > 0){ ClientBusinessObject[] bos = getInstanceBo().batchSaveCreateBuinessObject(createList.toArray(new ClientBusinessObject[0])); if(bos.length == createList.size()){ flag = true; } }else{ flag = true; } if(updateList.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateList.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } return flag; } /** * 保存业务对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSet * @param typeAttMap * @param type * @param uniqueCols : 判重列 * @param folderId : 文件夹分类ID(PLCLASSIFY) * @param fileCols : 文件路径列 * @param files : Map * @return * @throws PLMError * @throws VciException */ private boolean saveBOsWithClassifyAndFile(List dataSets, Map typeAttMap, String type, List uniqueCols, int updateFlag, String folderId, List fileCols, Map files) throws VCIError { List createList = new ArrayList(); List updateList = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); Map> fileMap_ = new HashMap>(); ClientFileObjectOperation operation = new ClientFileObjectOperation(); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = getInstanceBo().createBusinessObject(type); cbo.setBtmName(type); String[] data = dataSets.get(i); Map map = new HashMap(); Map fileMap = new HashMap(); for(int k = 0; k < data.length; k++){ String key = typeAttMap.get(k).split("\\.")[1]; String value = data[k]; value = checkEnum(key, value); if(key.equalsIgnoreCase("ID") || key.equalsIgnoreCase("NAME") || key.equalsIgnoreCase("DESCRIPTION")){ map.put(key.toLowerCase(), value); //上传文件 }else if(fileCols.contains(key.toUpperCase())){ if(uniqueCols.size() > 0){ //文件信息在判重后再补充到对象 fileMap.put(key, value); continue; }else{ //不需判重,文件信息直接在此处理 //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } continue; //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); } } } cbo.setAttributeValue(key.toLowerCase(), value, true); } cbo.setAttributeValue("PLCLASSIFY".toLowerCase(), folderId, true); map_.put(cbo.getOid(), map); fileMap_.put(cbo.getOid(), fileMap); allBoList.add(cbo); } if(uniqueCols.size() > 0 && allBoList.size() > 0){ List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = bo.oid; // 删除对象关联的文档 ClientBusinessObject[] fObjs = getClientFileObjectByDocId(docId); if (fObjs != null && fObjs.length > 0) { getInstanceBo().batchDeleteBuinessObject(fObjs); } // 创建对象关联的文档 String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateList.add(cbo); } } else { //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } createList.add(cbo); } } }else{ createList.addAll(allBoList); } boolean flag = false; if(createList.size() > 0){ ClientBusinessObject[] bos = getInstanceBo().batchSaveCreateBuinessObject(createList.toArray(new ClientBusinessObject[0])); if(bos.length == createList.size()){ flag = true; } }else{ flag = true; } if(updateList.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateList.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } return flag; } /** * 导入业务对象 * @param file * @param fileName * @param type * @param updateFlag: 当有重复记录时: 1:覆盖; 0:跳过 * @return * @throws VCIError * @throws IOException */ public static Map importBOData(File file, String fileName, String type, int updateFlag) throws VCIError, IOException{ Map infoMap = new HashMap(); //压缩文件中的excel数据文件 InputStream dataInputStream = null; Map files = new HashMap(); boolean zipFlag = false; if(fileName.endsWith(".zip")){ zipFlag = true; ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); String tempFolder = file.getParent(); while(entries.hasMoreElements()){ ZipEntry zipEntry = entries.nextElement(); if(!zipEntry.isDirectory()){ String fileName_ = zipEntry.getName(); InputStream inputStream_ = zipFile.getInputStream(zipEntry); if(fileName_.endsWith(".xlsx") || fileName_.endsWith(".xls")){ fileName = fileName_; dataInputStream = inputStream_; }else{ String filePath = tempFolder + "\\" + fileName_; File tempFile = new File(filePath); File folder = tempFile.getParentFile(); if(!folder.exists()){ folder.mkdirs(); } if(!tempFile.exists()){ tempFile.createNewFile(); } BufferedInputStream inBuff = new BufferedInputStream(inputStream_); BufferedOutputStream outBuff = new BufferedOutputStream(new FileOutputStream(tempFile)); byte[] b = new byte[1024 * 512]; int len; while((len = inBuff.read(b)) != -1){ outBuff.write(b, 0, len); } files.put(fileName_, tempFile); inBuff.close(); outBuff.close(); } } } } BufferedInputStream bs; if(zipFlag){ bs = new BufferedInputStream(dataInputStream); }else{ bs = new BufferedInputStream(new FileInputStream(file)); } List sheetDataSets = ExcelDocumentUtils .readExcelDocument(fileName, bs); List dataSets = sheetDataSets.get(0).getDataSet(); String[] dataSet = dataSets.get(0); Set typeSet = new HashSet(); Map typeAttMap = new HashMap(); //判重列 List uniqueCols = new ArrayList(); //文件列 List fileCols = new ArrayList(); for(int i = 0; i < dataSet.length; i++){ String data = dataSet[i]; String[] data_ = data.split("\\."); typeSet.add(data_[0]); //判重列标识 if(data_[1].endsWith("*")){ uniqueCols.add(data_[1].substring(0, data_[1].indexOf("*")).toUpperCase()); data = data.substring(0, data.indexOf("*")); //文件列标识 }else if(data_[1].endsWith("+")){ fileCols.add(data_[1].substring(0, data_[1].indexOf("+")).toUpperCase()); data = data.substring(0, data.indexOf("+")); } typeAttMap.put(i, data); } if(!typeSet.contains(type)){ infoMap.put(ERROR, "文件中无该类型数据"); return infoMap; } if(typeSet.size() > 1){ infoMap.put(ERROR, "文件中含有其他类型数据"); return infoMap; } boolean flag = false; if(zipFlag){ flag = getInstance().saveBOsWithFile(dataSets, typeAttMap, type, uniqueCols, updateFlag, fileCols, files); }else{ flag = getInstance().saveBOs(dataSets, typeAttMap, type, uniqueCols, updateFlag); } //删除临时文件 for(Iterator ite = files.keySet().iterator(); ite.hasNext();){ String fileName_ = ite.next(); File file_ = files.get(fileName_); file_.delete(); } file.delete(); if(flag){ infoMap.put(RESULT, TRUE); }else{ infoMap.put(RESULT, FALSE); } return infoMap; } /** * 保存业务对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSet * @param typeAttMap * @param type * @param uniqueCols : 判重列 * @return * @throws PLMError * @throws VciException */ private boolean saveBOs(List dataSets, Map typeAttMap, String type, List uniqueCols, int updateFlag) throws VCIError { List createList = new ArrayList(); List updateList = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); ClientBusinessObject source = getInstanceBo().createBusinessObject(type); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = BOTool.cloneClientBusinessObject(source, true); String[] data = dataSets.get(i); Map map = new HashMap(); for(int k = 0; k < data.length; k++){ String key = typeAttMap.get(k).split("\\.")[1]; String value = data[k]; value = checkEnum(key, value); if(key.equalsIgnoreCase("ID") || key.equalsIgnoreCase("NAME") || key.equalsIgnoreCase("DESCRIPTION")){ map.put(key.toLowerCase(), value); } cbo.setAttributeValue(key.toLowerCase(), value, true); } map_.put(cbo.getOid(), map); allBoList.add(cbo); } if(uniqueCols.size() > 0 && allBoList.size() > 0){ List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateList.add(cbo); } } else { createList.add(cbo); } } }else{ createList.addAll(allBoList); } boolean flag = false; if(createList.size() > 0){ ClientBusinessObject[] bos = getInstanceBo().batchSaveCreateBuinessObject(createList.toArray(new ClientBusinessObject[0])); if(bos.length == createList.size()){ flag = true; } }else{ flag = true; } if(updateList.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateList.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } return flag; } /** * 保存业务对象 * 当对象不存在时, 创建对象; * 存在时(unique), 更新对象. * @param dataSet * @param typeAttMap * @param type * @param uniqueCols : 判重列 * @param updateFlag * @param fileCols : 文件路径列 * @param files : Map * @return * @throws PLMError * @throws VciException */ private boolean saveBOsWithFile(List dataSets, Map typeAttMap, String type, List uniqueCols, int updateFlag, List fileCols, Map files) throws VCIError { List createList = new ArrayList(); List updateList = new ArrayList(); List allBoList = new ArrayList(); Map> map_ = new HashMap>(); Map> fileMap_ = new HashMap>(); ClientBusinessObject source = getInstanceBo().createBusinessObject(type); ClientFileObjectOperation operation = new ClientFileObjectOperation(); for(int i = 1; i < dataSets.size(); i++){ ClientBusinessObject cbo = BOTool.cloneClientBusinessObject(source, true); String[] data = dataSets.get(i); Map map = new HashMap(); Map fileMap = new HashMap(); for(int k = 0; k < data.length; k++){ String key = typeAttMap.get(k).split("\\.")[1]; String value = data[k]; value = checkEnum(key, value); if(key.equalsIgnoreCase("ID") || key.equalsIgnoreCase("NAME") || key.equalsIgnoreCase("DESCRIPTION")){ map.put(key.toLowerCase(), value); //上传文件 }else if(fileCols.contains(key.toUpperCase())){ if(uniqueCols.size() > 0){ //文件信息在判重后再补充到对象 fileMap.put(key, value); continue; }else{ //不需判重,文件信息直接在此处理 //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } continue; //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); } } } cbo.setAttributeValue(key.toLowerCase(), value, true); } map_.put(cbo.getOid(), map); fileMap_.put(cbo.getOid(), fileMap); allBoList.add(cbo); } if(uniqueCols.size() > 0 && allBoList.size() > 0){ List queryBO = queryBO(allBoList, uniqueCols); for(ClientBusinessObject cbo : allBoList){ BusinessObject bo = isExistBo(cbo, uniqueCols, queryBO); if (bo != null) { if(updateFlag == 1){ Map map = map_.get(cbo.getOid()); if (map.get("id") != null) { cbo.setAttributeValue("id", map.get("id")); } if (map.get("name") != null) { cbo.setAttributeValue("name", map.get("name")); } if (map.get("description") != null) { cbo.setAttributeValue("description", map.get("description")); } //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = bo.oid; // 删除对象关联的文档 ClientBusinessObject[] fObjs = getClientFileObjectByDocId(docId); if (fObjs != null && fObjs.length > 0) { getInstanceBo().batchDeleteBuinessObject(fObjs); } // 创建对象关联的文档 String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } cbo.setOid(bo.oid); cbo.setTs(bo.ts); updateList.add(cbo); } } else { //处理cbo的文件信息 Map fileMap = fileMap_.get(cbo.getOid()); for(String key : fileMap.keySet()){ String value = fileMap.get(key); //文件以附件形式将对象作为外键(如Document) if(key.equalsIgnoreCase("_attach")){ //文件以附件形式将对象作为外键(如Document)时 , 文件的documentoid String docId = cbo.getOid(); String[] paths = value.split(";"); for (String path : paths) { File file = files.get(path); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject.setAttributeValue("documentoid", docId); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); } //文件是对象属性(如personallog) }else{ File file = files.get(value); String fileName = file.getName(); FileObject fileObject = operation.createNewFile(); fileObject.setFileType(fileName.substring(fileName.lastIndexOf(".") + 1)); fileObject.setRevisionLimit(7); fileObject.setName(fileName); fileObject = operation.createNewFile(file.getAbsolutePath(), fileObject); value = fileObject.getOid(); cbo.setAttributeValue(key.toLowerCase(), value, true); } } createList.add(cbo); } } }else{ createList.addAll(allBoList); } boolean flag = false; if(createList.size() > 0){ ClientBusinessObject[] bos = getInstanceBo().batchSaveCreateBuinessObject(createList.toArray(new ClientBusinessObject[0])); if(bos.length == createList.size()){ flag = true; } }else{ flag = true; } if(updateList.size() > 0){ flag &= getInstanceBo().batchUpdateBuinessObject(updateList.toArray(new ClientBusinessObject[0])); }else{ flag &= true; } return flag; } /** * 分段查询出满足判重条件(F_OID, T_OID)的LO * @param allLoList * @return */ private List queryLO(List allLoList) { List queryLoList = new ArrayList(); QueryTemplate qt = new QueryTemplate(); qt.setId("id"); qt.setType(QTConstants.TYPE_LINK); List clauseList = new ArrayList(); clauseList.add("*"); qt.setClauseList(clauseList); ClientLinkObject clo = allLoList.get(0); qt.setLinkType(clo.getLoName()); int size = allLoList.size(); for(int k = 0; k < size/PARTIONSIZE + 1; k++){ Condition cond = new Condition(); for(int m = k * PARTIONSIZE; m < (k + 1) * PARTIONSIZE && m < size; m++){ ClientLinkObject clo_ = allLoList.get(m); Map map_ = new HashMap(); map_.put("f_oid", clo_.getFromOid()); map_.put("t_oid", clo_.getToOid()); Condition cond_ = OQTool.getCondition(map_); cond = OQTool.mergeCondition(cond, cond_, Connector.OR); } qt.setCondition(cond); try { LinkObject[] los = QTClient.getService().findLTObjects(qt.getId(), OQTool.getQTTextByQT(qt)); queryLoList.addAll(LOTool.ArrayTOList(los)); } catch (VCIError e) { e.printStackTrace(); } } return queryLoList; } /** * 根据f_oid , t_oid在queryLO中判断对象是否已经存在 * @param clo * @param queryLO * @return */ private LinkObject isExistLo(ClientLinkObject clo, List queryLO) { for(LinkObject lo : queryLO){ if(lo.fromOid.equals(clo.getFromOid()) && lo.toOid.equals(clo.getToOid())){ return lo; } } return null; } /** * 分段查询出满足判重条件的BO * @param allBoList * @param uniqueCols * @return */ private List queryBO( List allBoList, List uniqueCols) { List queryBoList = new ArrayList(); int size = allBoList.size(); String type = allBoList.get(0).getBtmName(); QueryTemplate qt = new QueryTemplate(); qt.setId("qt"); qt.setBtmType(type); List clauseList = new ArrayList(); clauseList.add("*"); qt.setClauseList(clauseList); qt.setType(QTConstants.TYPE_BTM); for(int k = 0; k < size/PARTIONSIZE + 1; k++){ Condition cond = new Condition(); for(int m = k * PARTIONSIZE; m < (k + 1) * PARTIONSIZE && m < size; m++){ ClientBusinessObject cbo = allBoList.get(m); Map map = new HashMap(); for(String uniqueCol : uniqueCols){ if(uniqueCol.equalsIgnoreCase("ID")){ map.put("id", cbo.getId()); continue; } if(uniqueCol.equalsIgnoreCase("NAME")){ map.put("name", cbo.getName()); continue; } if(uniqueCol.equalsIgnoreCase("DESCRIPTION")){ map.put("description", cbo.getDescription()); continue; } String attributeValue = cbo.getAttributeValue(uniqueCol); if(attributeValue != null && !attributeValue.equals("")){ map.put(uniqueCol, attributeValue); } } Condition cond_ = OQTool.getCondition(map); cond = OQTool.mergeCondition(cond, cond_, Connector.OR); } qt.setCondition(cond); BusinessObject[] bos = null; try { bos = QTClient.getService().findBTMObjects(qt.getId(), OQTool.getQTTextByQT(qt)); queryBoList.addAll(BOTool.ArrayTOList(bos)); } catch (VCIError e) { e.printStackTrace(); } } return queryBoList; } /** * 根据uniqueCols在boList中判断cbo对象是否已经存在 * 处理系统属性:id/name/description (因仅此三个系统属性可用户设置) * 处理自定义属性:cbo.getAttributeValue(attrName) * @param uniqueCols * @param id * @param type * @return * @throws VciException * @throws PLMError */ private BusinessObject isExistBo(ClientBusinessObject cbo, List uniqueCols, List boList){ for(BusinessObject bo : boList){ boolean flag = true; for(String uniqueCol : uniqueCols){ if(uniqueCol.equalsIgnoreCase("ID")){ if(!cbo.getId().equals(bo.id)){ flag = false; break; } }else if(uniqueCol.equalsIgnoreCase("NAME")){ if(!cbo.getName().equals(bo.name)){ flag = false; break; } }else if(uniqueCol.equalsIgnoreCase("DESCRIPTION")){ if(!cbo.getDescription().equals(bo.description)){ flag = false; break; } }else{ String attributeValue = cbo.getAttributeValue(uniqueCol); if (attributeValue != null && !attributeValue.equals("")) { String boAttVal = BOTool.getBOAttVal(bo, uniqueCol); if (!attributeValue.equals(boAttVal)) { flag = false; break; } } } } if(flag){ return bo; } } return null; } /** * 若属性使用枚举, 将得到的枚举名转换为对应的枚举值 * @param key * @param value * @return */ private String checkEnum(String key, String value) { AttribItem att = ApProvider.getInstance().getAbItemByName(key.toLowerCase()); String enumName = OQTool.getOtherValueByType(att.other, AttributeConstants.ENUMNAME); if(enumName == null || enumName.equals("")){ return value; } EnumItem enumItem = EnumProvider.getInstance().getEnumByName(enumName); EnumChild[] children = enumItem.children; for(int i = 0; i < children.length; i++){ EnumChild child = children[i]; if(child.name.equalsIgnoreCase(value)){ return child.value; } } return value; } /** * 查询对象关联的文档 * @param docId * @return */ private BusinessObject[] getFileObjectByDocId(String docId){ QueryTemplate qt = new QueryTemplate(); qt.setId("id"); qt.setType(QTConstants.TYPE_BTM); qt.setBtmType(FileTypeConstants.FILE_DATA_TABLE); List clauseList = new ArrayList(); clauseList.add("*"); qt.setClauseList(clauseList); Map arg0 = new HashMap(); arg0.put("documentoid", docId); Condition condition = OQTool.getCondition(arg0 ); qt.setCondition(condition); try { return QTClient.getService().findBTMObjects(qt.getId(), OQTool.qtTOXMl(qt).asXML()); } catch (VCIError e) { e.printStackTrace(); } return null; } /** * 查询对象关联的文档 * @param docId * @return */ private ClientBusinessObject[] getClientFileObjectByDocId(String docId){ List cbos = new ArrayList(); BusinessObject[] bos = getFileObjectByDocId(docId); if(bos != null && bos.length > 0){ for(BusinessObject bo : bos){ ClientBusinessObject cbo = new ClientBusinessObject(); cbo.setBusinessObject(bo); cbos.add(cbo); } } return cbos.toArray(new ClientBusinessObject[0]); } }