Commit 86f0cded authored by hanson.yao's avatar hanson.yao

可视化逻辑修改

parent e1ad43e1
package com.yonde.cadpro.controller; package com.yonde.cadpro.controller;
import com.yonde.cadpro.CADProConstants;
import com.yonde.cadpro.bean.DxCADBomVo;
import com.yonde.cadpro.service.PartVisService;
import com.yonde.cadpro.util.Base64Util;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.yonde.basedata.entity.api.ApiResult;
import com.yonde.cadpro.service.PartVisService;
import com.yonde.cadpro.util.Base64Util;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
/** /**
...@@ -17,13 +18,23 @@ import javax.servlet.http.HttpServletRequest; ...@@ -17,13 +18,23 @@ import javax.servlet.http.HttpServletRequest;
* @author * @author
*/ */
@RestController @RestController
@RequestMapping(value = "/cad") @RequestMapping(value = "/DxEPMDocument")
public class CADController { public class CADController {
private static String PORT_USER = "portUserName";
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
@RequestMapping(value = "/expandCADBom", method = RequestMethod.GET) @RequestMapping(value = "/expandBOM", method = RequestMethod.GET)
public ApiResult expandCADBom(@RequestParam String oid, HttpServletRequest request) throws Exception { public DxCADBomVo expandCADBom(@RequestParam String oid, HttpServletRequest request) throws Exception {
String userName = Base64Util.decodeForUserName(request); String authorization = request.getHeader(CADProConstants.AUTHORIZATION);
return ApiResult.ok(PartVisService.expandCADBom(oid,userName)); String userName = "";
if (StringUtils.isNotBlank(authorization)) {
userName = Base64Util.decodeForUserName(request);
}
String portUserName = request.getHeader(PORT_USER);
if (StringUtils.isNotBlank(portUserName)) {
userName = portUserName;
}
return PartVisService.expandCADBom(oid, userName);
} }
} }
...@@ -275,18 +275,18 @@ public class FtpUtil { ...@@ -275,18 +275,18 @@ public class FtpUtil {
/** /**
* 从ftp下载文件到本地 * 从ftp下载文件到本地
* *
* @param filename 服务器上的文件名 * @param fileName 服务器上的文件名
* @param newfilename 本地生成的文件名 * @param newFileName 本地生成的文件名
* @return * @return
* @throws Exception * @throws Exception
*/ */
public long downloadFile(String filename, String newfilename){ public long downloadFile(String fileName, String newFileName) throws IOException {
long result = 0; long result = 0;
TelnetInputStream is = null; TelnetInputStream is = null;
FileOutputStream os = null; FileOutputStream os = null;
try{ try{
is = ftpClient.get(filename); is = ftpClient.get(fileName);
File outfile = new File(newfilename); File outfile = new File(newFileName);
os = new FileOutputStream(outfile); os = new FileOutputStream(outfile);
byte[] bytes = new byte[1024]; byte[] bytes = new byte[1024];
int c; int c;
...@@ -296,6 +296,7 @@ public class FtpUtil { ...@@ -296,6 +296,7 @@ public class FtpUtil {
} }
}catch (IOException e){ }catch (IOException e){
e.printStackTrace(); e.printStackTrace();
throw new IOException("ftp download file failed... ",e);
}finally{ }finally{
try { try {
if(is != null){ if(is != null){
......
...@@ -11,6 +11,7 @@ import wt.util.WTException; ...@@ -11,6 +11,7 @@ import wt.util.WTException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID;
/** /**
...@@ -120,7 +121,7 @@ public class AssembleTransformUtil { ...@@ -120,7 +121,7 @@ public class AssembleTransformUtil {
StringBuffer insert = new StringBuffer(" insert into AssembleTransformInfo(SNAPSHOTID,ID,PARENTMODEL,CHILDMODEL,TRANSFORM,IDENTIFY) VALUES ("); StringBuffer insert = new StringBuffer(" insert into AssembleTransformInfo(SNAPSHOTID,ID,PARENTMODEL,CHILDMODEL,TRANSFORM,IDENTIFY) VALUES (");
insert.append("'" + snapshot.getId() + "',"); insert.append("'" + snapshot.getId() + "',");
insert.append("'" + System.currentTimeMillis() + "',"); insert.append("'" + UUID.randomUUID().toString() + "',");
insert.append("'" + EPMUtil.getOROid(rootCAD) + "',"); insert.append("'" + EPMUtil.getOROid(rootCAD) + "',");
insert.append("'" + EPMUtil.getOROid(linkedChildEPM) + "',"); insert.append("'" + EPMUtil.getOROid(linkedChildEPM) + "',");
insert.append("'" + EPMUtil.getOROid(epmMemberLink) + "',"); insert.append("'" + EPMUtil.getOROid(epmMemberLink) + "',");
...@@ -138,7 +139,7 @@ public class AssembleTransformUtil { ...@@ -138,7 +139,7 @@ public class AssembleTransformUtil {
*/ */
public static AssembleTransformSnapshot newAssembleTransformSnapshot(String parentId, String snapshotHash) throws WTException { public static AssembleTransformSnapshot newAssembleTransformSnapshot(String parentId, String snapshotHash) throws WTException {
System.out.println(">>>newAssembleTransformSnapshot start......"); System.out.println(">>>newAssembleTransformSnapshot start......");
String id = String.valueOf(System.currentTimeMillis()); String id = UUID.randomUUID().toString();
StringBuffer insert = new StringBuffer(" insert into ASSEMBLETRANSFORMSNAPSHOT(ID,PARENTID,SNAPSHOTHASH) VALUES ("); StringBuffer insert = new StringBuffer(" insert into ASSEMBLETRANSFORMSNAPSHOT(ID,PARENTID,SNAPSHOTHASH) VALUES (");
insert.append("'" + id + "',"); insert.append("'" + id + "',");
insert.append("'" + parentId + "',"); insert.append("'" + parentId + "',");
......
package com.yonde.cadpro.visualization.facade; package com.yonde.cadpro.visualization.facade;
import com.yonde.cadpro.CADProConstants; import com.yonde.cadpro.CADProConstants;
import com.yonde.cadpro.config.CatiaInteConfigPropertiesUtil;
import com.yonde.cadpro.util.*; import com.yonde.cadpro.util.*;
import com.yonde.cadpro.visualization.AssembleTransformUtil; import com.yonde.cadpro.visualization.AssembleTransformUtil;
import com.yonde.cadpro.visualization.catia.ConvertCatia2B3dUtil; import com.yonde.cadpro.visualization.catia.ConvertCatia2B3dUtil;
...@@ -121,31 +122,17 @@ public class VisualizationService { ...@@ -121,31 +122,17 @@ public class VisualizationService {
System.out.println("uploadFiles : " + uploadFiles); System.out.println("uploadFiles : " + uploadFiles);
//2. 上传至FTP目录 //2. 上传至FTP目录
FtpUtil ftpUtil = null; FtpUtil ftpUtil = new FtpUtil(catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_HOST),
if (!transferModel) { Integer.valueOf(catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PORT)),
ftpUtil = new FtpUtil( catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_USERNAME),
officeTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_OFFICE_FTP_HOST), catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PASSWORD));
Integer.valueOf(officeTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_OFFICE_FTP_PORT)),
officeTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_OFFICE_FTP_USERNAME),
officeTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_OFFICE_FTP_PASSWORD));
} else {
ftpUtil = new FtpUtil(
catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_HOST),
Integer.valueOf(catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PORT)),
catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_USERNAME),
catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PASSWORD));
}
if (!ftpUtil.connectServer()) { if (!ftpUtil.connectServer()) {
throw new WTException("FTP连接失败,请重试或联系系统管理员。"); throw new WTException("FTP连接失败,请重试或联系系统管理员。");
} }
String ftpRemoteFolder = ""; String ftpRemoteFolder = "";
if (!transferModel) { if (transferModel) {
ftpRemoteFolder = officeTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_OFFICE_TEMPFOLDERPATH) + uuidStr + "/";
} else {
ftpRemoteFolder = catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_TEMPFOLDERPATH) + uuidStr + "/"; ftpRemoteFolder = catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_TEMPFOLDERPATH) + uuidStr + "/";
} }
...@@ -203,11 +190,24 @@ public class VisualizationService { ...@@ -203,11 +190,24 @@ public class VisualizationService {
} }
System.out.println("transformedFtpPath :" + transformedFtpPath); System.out.println("transformedFtpPath :" + transformedFtpPath);
System.out.println("transformedFileName :" + transformedFileName); System.out.println("transformedFileName :" + transformedFileName);
//woker机b3d转换完成后将文件通过ftp下载到pdm codebase/tempDownload/时间戳/ 文件夹下
ftpUtil = new FtpUtil(
VisualizationFacade.catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_HOST),
Integer.valueOf(VisualizationFacade.catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PORT)),
VisualizationFacade.catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_USERNAME),
VisualizationFacade.catiaTransferConfig.getValueByKey(CADProConstants.CONFIG_KEY_CATIA_FTP_PASSWORD));
if (!ftpUtil.connectServer()) {
throw new WTException("FTP连接失败,请重试或联系系统管理员。");
}
String downloadFile = ContentUtil.getTempPath() + transformedFileName;
ftpUtil.downloadFile(transformedFtpPath + transformedFileName, downloadFile);
ftpUtil.closeServer();
//4. 上传转可视化之后文件至contentHolder //4. 上传转可视化之后文件至contentHolder
if (StringUtils.isNotBlank(transformedFtpPath) && StringUtils.isNotBlank(transformedFileName)) { if (StringUtils.isNotBlank(transformedFtpPath) && StringUtils.isNotBlank(transformedFileName)) {
if (transferModel) { if (transferModel) {
String xmlFile = transformedFileRemotePath; String xmlFile = downloadFile;
System.out.println("xmlFile : " + xmlFile); System.out.println("xmlFile : " + xmlFile);
//处理下载文件 //处理下载文件
Map<String, Set<String>> numberVisMap = new HashMap<String, Set<String>>(); Map<String, Set<String>> numberVisMap = new HashMap<String, Set<String>>();
...@@ -413,18 +413,13 @@ public class VisualizationService { ...@@ -413,18 +413,13 @@ public class VisualizationService {
Set<EPMMemberLink> allMembership = memberLinkWithTrasform Set<EPMMemberLink> allMembership = memberLinkWithTrasform
.keySet(); .keySet();
for (EPMMemberLink epmMemberLink : allMembership) { for (EPMMemberLink epmMemberLink : allMembership) {
Map<EPMDocument, String> epmTrans = memberLinkWithTrasform Map<EPMDocument, String> epmTrans = memberLinkWithTrasform.get(epmMemberLink);
.get(epmMemberLink);
if (epmTrans != null) { if (epmTrans != null) {
Set<Entry<EPMDocument, String>> epmKeyEnters = epmTrans Set<Entry<EPMDocument, String>> epmKeyEnters = epmTrans.entrySet();
.entrySet(); Iterator<Entry<EPMDocument, String>> itEntry = epmKeyEnters.iterator();
Iterator<Entry<EPMDocument, String>> itEntry = epmKeyEnters
.iterator();
if (itEntry.hasNext()) { if (itEntry.hasNext()) {
Entry<EPMDocument, String> epmKeyEntry = itEntry Entry<EPMDocument, String> epmKeyEntry = itEntry.next();
.next(); EPMDocument linkedChildEPM = epmKeyEntry.getKey();
EPMDocument linkedChildEPM = epmKeyEntry
.getKey();
String formatTransform = epmKeyEntry.getValue(); String formatTransform = epmKeyEntry.getValue();
System.out.println("process snapshot :" + snapshot System.out.println("process snapshot :" + snapshot
+ ", epm:" + rootCAD + ", epm:" + rootCAD
...@@ -495,13 +490,24 @@ public class VisualizationService { ...@@ -495,13 +490,24 @@ public class VisualizationService {
Set<String> b3dPaths = numberVisMap.get(cadNumber); Set<String> b3dPaths = numberVisMap.get(cadNumber);
if (b3dPaths != null) { if (b3dPaths != null) {
for (String b3dPath : b3dPaths) { for (String b3dPath : b3dPaths) {
System.out.println("b3dPath : " + b3dPath);
File file = new File(transformedFileRemotePath); File file = new File(transformedFileRemotePath);
String parent = file.getParent()+File.separator; String parent = file.getParent() + File.separator;
b3dPath = b3dPath.replace(tempFolderPath, parent); b3dPath = b3dPath.replace(tempFolderPath, parent);
if (!ftpUtil.connectServer()) {
throw new WTException("FTP连接失败,请重试或联系系统管理员。");
}
System.out.println("b3dPath2 : " + b3dPath);
File b3dFile = new File(b3dPath); File b3dFile = new File(b3dPath);
if (!b3dFile.exists() || b3dFile.isDirectory()) { if (!b3dFile.getParentFile().exists()){
b3dFile.getParentFile().mkdirs();
b3dFile.createNewFile();
}
//将worker机的b3d文件存储到pdm服务器临时目录中
String replace = b3dPath.replace(new File(CatiaInteConfigPropertiesUtil.getFtpRootPath()).getPath(), "");
ftpUtil.downloadFile(replace, b3dPath);
ftpUtil.closeServer();
if (!b3dFile.exists() || b3dFile.isDirectory() || b3dFile.length()<1) {
logger.error("b3dPath File [" + b3dPath + "] is not exist,continue..."); logger.error("b3dPath File [" + b3dPath + "] is not exist,continue...");
continue; continue;
} }
...@@ -512,7 +518,7 @@ public class VisualizationService { ...@@ -512,7 +518,7 @@ public class VisualizationService {
ContentRoleType.toContentRoleType("ADDITIONAL_FILES")); ContentRoleType.toContentRoleType("ADDITIONAL_FILES"));
epm = (EPMDocument) PersistenceHelper.manager.refresh(epm); epm = (EPMDocument) PersistenceHelper.manager.refresh(epm);
b3dFile.deleteOnExit();
//处理PMI 轻量化文件 //处理PMI 轻量化文件
//String fileName = FilenameUtils.getBaseName(b3dPath); //String fileName = FilenameUtils.getBaseName(b3dPath);
...@@ -616,13 +622,6 @@ public class VisualizationService { ...@@ -616,13 +622,6 @@ public class VisualizationService {
if (element instanceof EPMDocument) { if (element instanceof EPMDocument) {
child = (EPMDocument) element; child = (EPMDocument) element;
} else if (element instanceof EPMDocumentMaster) { } else if (element instanceof EPMDocumentMaster) {
/*
QueryResult versionQr = VersionControlHelper.service
.allVersionsOf((EPMDocumentMaster) element);
if (versionQr != null && versionQr.hasMoreElements()) {
child = (EPMDocument) versionQr.nextElement();
}
*/
child = EPMUtil.getEPM(((EPMDocumentMaster) element).getNumber(), "", ""); child = EPMUtil.getEPM(((EPMDocumentMaster) element).getNumber(), "", "");
} }
if (child != null) { if (child != null) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment