Commit 18079263 authored by shyWang's avatar shyWang

PDM前端改造

附件 主内容相关
parent 1bb01cf1
package com.yonde.basedata.controller;
import com.yonde.basedata.service.BaseSearchService;
import com.yonde.basedata.vo.ObjFileLinkVO;
import com.yonde.common.DxCommonUtils;
import com.yonde.common.ObjectsUtil;
import com.yonde.doc.vo.DxDocumentVO;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import wt.content.ApplicationData;
import wt.content.Streamed;
import wt.fc.ObjectReference;
import wt.util.WTProperties;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
@RestController
@RequestMapping({"/DxContentHolder"})
public class ContentHolderController {
@PostMapping({"/uploads"})
//@ApiOperation("获取工作副本")
public void uploadFiles(@RequestParam ObjFileLinkVO fileForm, @RequestParam("files") MultipartFile[] files) {
//DxDocumentVO dxDocumentVO = null;
try {
//dxDocumentVO = DxDocService.checkout(id, "Dex检出");
} catch (Exception e) {
e.printStackTrace();
}
return;
}
@PostMapping({"/uploadFile"})
public DxDocumentVO uploadFile(@RequestParam ObjFileLinkVO fileForm, @RequestParam("file") MultipartFile file) {
DxDocumentVO dxDocumentVO = null;
try {
System.out.println("fileForm====" + fileForm.getSourceId());
System.out.println("file====" + file);
} catch (Exception e) {
e.printStackTrace();
}
return dxDocumentVO;
}
/* @GetMapping({"/downLoadIO"})
//@ApiOperation("获取文件流")
public byte[] uploadFile(@RequestParam("appId") String appId) {
byte[] bytes = null;
try {
bytes = DxCommonUtils.getInputStreamById(appId);
System.out.println("====bytes===" + bytes);
} catch (Exception e) {
e.printStackTrace();
}
return bytes;
}*/
@GetMapping({"/downLoadIO"})
//@ApiOperation("获取文件流")
public void uploadFile(@RequestParam("appId") String appId, HttpServletResponse response) {
//InputStream inputStream = null;
String fileName = "fileName";
String filePath = null;
try {
filePath = DxCommonUtils.getFileById(appId, fileName);
File file = new File(filePath);
IOUtils.copy(new FileInputStream(file), response.getOutputStream());
/*BufferedOutputStream outputStream = new BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[1024];
int n;
while ((n=inputStream.read(buff))!=1) {
outputStream.write(buff, 0, n);
}
outputStream.flush();
outputStream.close();
inputStream.close();
System.out.println("====inputStream===" + inputStream);*/
} catch (Exception e) {
e.printStackTrace();
}
return;
}
@RequestMapping(value = "/upload", consumes = "multipart/form-data", method = RequestMethod.POST)
public DxDocumentVO createRelatedInformation(@RequestParam("file") CommonsMultipartFile file,
@RequestParam("sourceId") String sourceId,
@RequestParam("sourceType") String sourceType,
@RequestParam("targetId") String targetId,
@RequestParam("contentType") String contentType,
@RequestParam("operator") String operator) {
System.out.println("sourceId====" + sourceId);
System.out.println("contentType====" + contentType);
System.out.println("operator====" + operator);
System.out.println("file====" + file.isEmpty());
ObjFileLinkVO fileForm = new ObjFileLinkVO();
fileForm.setSourceId(Long.valueOf(sourceId));
fileForm.setOperator(operator);
fileForm.setContentType(contentType);
fileForm.setSourceIdType(sourceType);
fileForm.setTargetId(targetId);
try {
String importFiledirPath = WTProperties.getLocalProperties().getProperty("wt.content.temp") + File.separator + System.nanoTime();
File importFiledir = new File(importFiledirPath);
importFiledir.mkdir();
System.out.println(">>>>importFileDirPath=" + importFiledirPath);
File importFile = new File(importFiledirPath + File.separator + file.getOriginalFilename());
file.transferTo(importFile);
System.out.println(">>>>importFile=" + importFile);
BaseSearchService.uploadFile(importFile, fileForm);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
package com.yonde.basedata.search;
import com.yonde.basedata.entity.users.DxUserVO;
import com.yonde.basedata.vo.DxMasterVO;
import com.yonde.basedata.vo.DxOrganizationVO;
import com.yonde.basedata.vo.DxVersionVO;
import com.yonde.basedata.vo.*;
import com.yonde.context.vo.DxContextVO;
import com.yonde.doc.vo.DxDocumentVO;
import com.yonde.part.vo.*;
import com.yonde.plan.vo.DxProcessDocDescribeLinkVO;
import com.yonde.plan.vo.DxProcessDocReferenceLinkVO;
import wt.clients.beans.query.WTAttribute;
import wt.doc.WTDocument;
import wt.fc.ObjectIdentifier;
......@@ -48,7 +48,7 @@ public class SearchOperatorEnumUtil {
public static final Map<Class<?>, String> typeItemMap = new HashMap();// 类型映射
public static final Map<Long, String> viewMap = new HashMap();// 视图映射
public static final Map<String, String> viewMap = new HashMap();// 视图映射
public static final Map<Class<?>, String> typePrefixMap = new HashMap();// 类型映射
......@@ -62,9 +62,9 @@ public class SearchOperatorEnumUtil {
}
public static void initViewMap() {
viewMap.put(1L, "Design");
viewMap.put(2L, "Planning");
viewMap.put(3L, "Manufacture");
viewMap.put("1", "Design");
viewMap.put("2", "Planning");
viewMap.put("3", "Manufacture");
}
public static void initTypePrefixMap() {
......@@ -93,6 +93,11 @@ public class SearchOperatorEnumUtil {
typeItemMap.put(DxPartDescribeLinkVO.class, "com.yonde.dcs.xbom.common.entity.vo.DxPartDescribeLinkVO");
typeItemMap.put(DxPartReferenceLinkVO.class, "com.yonde.dcs.xbom.common.entity.vo.DxPartReferenceLinkVO");
typeItemMap.put(DxOrganizationVO.class, "com.yonde.dex.user.common.vo.DxOrganizationVO");
typeItemMap.put(ObjFileLinkVO.class, "com.yonde.dex.dfs.vo.ObjFileLinkVO");
typeItemMap.put(RepoFileVO.class, "com.yonde.dex.dfs.vo.RepoFileVO");
typeItemMap.put(DxProcessDocReferenceLinkVO.class, "com.yonde.dcs.process.common.entity.vo.DxProcessDocReferenceLinkVO");
typeItemMap.put(DxProcessDocDescribeLinkVO.class, "com.yonde.dcs.process.common.entity.vo.DxProcessDocDescribeLinkVO");
//TODO add
}
......
......@@ -5,22 +5,30 @@ import com.yonde.basedata.entity.api.ApiResult;
import com.yonde.basedata.search.SearchOperatorEnumUtil;
import com.yonde.basedata.search.SearchQueryCondition;
import com.yonde.basedata.vo.IdVO;
import com.yonde.common.DocUtil;
import com.yonde.common.DxCommonUtils;
import com.yonde.common.DxSearchUtil;
import com.yonde.common.RfUtil;
import com.yonde.basedata.vo.ObjFileLinkVO;
import com.yonde.common.*;
import com.yonde.doc.vo.DxDocumentVO;
import com.yonde.part.service.DxPartService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import wt.content.ApplicationData;
import wt.content.ContentHolder;
import wt.content.ContentRoleType;
import wt.doc.WTDocument;
import wt.fc.WTObject;
import wt.log4j.LogR;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.session.SessionContext;
import wt.session.SessionHelper;
import wt.util.WTProperties;
import java.io.File;
import java.util.List;
@Service
......@@ -77,4 +85,88 @@ public class BaseSearchService <V extends IdVO> implements RemoteAccess {
return false;
}
public static void uploadFile(CommonsMultipartFile file, ObjFileLinkVO fileForm) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("uploadFile", BaseSearchService.class.getName(), null,
new Class[] { CommonsMultipartFile.class, ObjFileLinkVO.class },
new Object[] { file, fileForm });
return;
}
SessionContext previous = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
String importFiledirPath = WTProperties.getLocalProperties().getProperty("wt.content.temp") + File.separator + System.nanoTime();
File importFiledir = new File(importFiledirPath);
importFiledir.mkdir();
logger.error(">>>>importFiledirPath=" + importFiledirPath);
File importFile = new File(importFiledirPath + File.separator + file.getOriginalFilename());
file.transferTo(importFile);
logger.error("====importFile =====" + importFile);
String contentType = fileForm.getContentType();
Long sourceId = fileForm.getSourceId();
String targetId = fileForm.getTargetId();
String operator = fileForm.getOperator();
String sourceIdType = fileForm.getSourceIdType();
ContentHolder holder = DxDocUtil.getDocById(sourceId);
if (StringUtils.isNotEmpty(sourceIdType) && sourceIdType.toLowerCase().contains("part")) {
holder = DxPartUtil.getPartById(sourceId);
}
if ("ADD".equalsIgnoreCase(operator)) {
ContentRoleType roleType = ContentRoleType.PRIMARY;
if (StringUtils.isNotEmpty(contentType) && contentType.equalsIgnoreCase("ATTACH_FILE")) {
roleType = ContentRoleType.SECONDARY;
}
DocUtil.uploadContentHolder(holder, file, roleType);
} else {
ApplicationData dataById = DxCommonUtils.getAppDataById(targetId);
if (ObjectsUtil.nonNull(dataById)) {
DocUtil.delContentItem(holder, dataById);
}
}
logger.error("===fileForm===" + fileForm);
} finally {
SessionContext.setContext(previous);
}
}
public static void uploadFile(File file, ObjFileLinkVO fileForm) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("uploadFile", BaseSearchService.class.getName(), null,
new Class[] { File.class, ObjFileLinkVO.class },
new Object[] { file, fileForm });
return;
}
SessionContext previous = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
logger.error("====importFile =====" + file);
String contentType = fileForm.getContentType();
Long sourceId = fileForm.getSourceId();
String targetId = fileForm.getTargetId();
String operator = fileForm.getOperator();
String sourceIdType = fileForm.getSourceIdType();
ContentHolder holder = DxDocUtil.getDocById(sourceId);
if (StringUtils.isNotEmpty(sourceIdType) && sourceIdType.toLowerCase().contains("part")) {
holder = DxPartUtil.getPartById(sourceId);
}
if ("ADD".equalsIgnoreCase(operator)) {
ContentRoleType roleType = ContentRoleType.PRIMARY;
if (StringUtils.isNotEmpty(contentType) && contentType.equalsIgnoreCase("ATTACH_FILE")) {
roleType = ContentRoleType.SECONDARY;
}
DocUtil.uploadContentHolder(holder, file, roleType);
} else {
ApplicationData dataById = DxCommonUtils.getAppDataById(targetId);
if (ObjectsUtil.nonNull(dataById)) {
DocUtil.delContentItem(holder, dataById);
}
}
logger.error("===fileForm===" + fileForm);
} finally {
SessionContext.setContext(previous);
}
}
}
package com.yonde.basedata.vo;
import wt.fc.WTObject;
import wt.util.WTException;
public class ObjFileLinkVO extends IdVO{
private RepoFileVO target;
private Long sourceId;//文档id
private String sourceIdType;//DxDocument
private String targetId;
private String targetIdType;//RepoFile
private String contentType;//MASTER_FILE,ATTACH_FILE
public ObjFileLinkVO() {
}
public ObjFileLinkVO(WTObject object, RepoFileVO target, String contentType) throws WTException {
super(object);
this.target = target;
this.sourceId = this.id;
this.contentType = contentType;
}
public RepoFileVO getTarget() {
return target;
}
public void setTarget(RepoFileVO target) {
this.target = target;
}
public Long getSourceId() {
return sourceId;
}
public void setSourceId(Long sourceId) {
this.sourceId = sourceId;
}
public String getSourceIdType() {
return sourceIdType;
}
public void setSourceIdType(String sourceIdType) {
this.sourceIdType = sourceIdType;
}
public String getTargetId() {
return targetId;
}
public void setTargetId(String targetId) {
this.targetId = targetId;
}
public String getTargetIdType() {
return targetIdType;
}
public void setTargetIdType(String targetIdType) {
this.targetIdType = targetIdType;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
}
package com.yonde.basedata.vo;
import wt.content.ApplicationData;
import wt.fc.PersistenceHelper;
import wt.util.WTException;
public class RepoFileVO extends IdVO{
private Long bucketId;
private String secretCode;
private Long originalSiteId;
private Long originalBucketId;
private Long originalDirId;
private String repoFileName;
private String fileMd5;
private String originalFileName;// fileName
private String fileSize;// fileSize
private Boolean isLink = true;
private String fileExtension;// 后缀
private String fileCode;// 下载用
private String fileStatus = "success";
public RepoFileVO() {
}
public RepoFileVO(ApplicationData applicationData) throws WTException {
super(applicationData);
this.bucketId = PersistenceHelper.getObjectIdentifier(applicationData).getId();
this.originalFileName = applicationData.getFileName();
this.fileSize = String.valueOf(applicationData.getFileSize());
this.fileExtension = this.originalFileName.substring(this.originalFileName.lastIndexOf(".") + 1);
this.fileCode = String.valueOf(this.bucketId);
}
public Long getBucketId() {
return bucketId;
}
public void setBucketId(Long bucketId) {
this.bucketId = bucketId;
}
public String getSecretCode() {
return secretCode;
}
public void setSecretCode(String secretCode) {
this.secretCode = secretCode;
}
public Long getOriginalSiteId() {
return originalSiteId;
}
public void setOriginalSiteId(Long originalSiteId) {
this.originalSiteId = originalSiteId;
}
public Long getOriginalBucketId() {
return originalBucketId;
}
public void setOriginalBucketId(Long originalBucketId) {
this.originalBucketId = originalBucketId;
}
public Long getOriginalDirId() {
return originalDirId;
}
public void setOriginalDirId(Long originalDirId) {
this.originalDirId = originalDirId;
}
public String getRepoFileName() {
return repoFileName;
}
public void setRepoFileName(String repoFileName) {
this.repoFileName = repoFileName;
}
public String getFileMd5() {
return fileMd5;
}
public void setFileMd5(String fileMd5) {
this.fileMd5 = fileMd5;
}
public String getOriginalFileName() {
return originalFileName;
}
public void setOriginalFileName(String originalFileName) {
this.originalFileName = originalFileName;
}
public String getFileSize() {
return fileSize;
}
public void setFileSize(String fileSize) {
this.fileSize = fileSize;
}
public Boolean getIsLink() {
return isLink;
}
public void setIsLink(Boolean isLink) {
isLink = isLink;
}
public String getFileExtension() {
return fileExtension;
}
public void setFileExtension(String fileExtension) {
this.fileExtension = fileExtension;
}
public String getFileCode() {
return fileCode;
}
public void setFileCode(String fileCode) {
this.fileCode = fileCode;
}
public String getFileStatus() {
return fileStatus;
}
public void setFileStatus(String fileStatus) {
this.fileStatus = fileStatus;
}
}
......@@ -5,6 +5,7 @@ import com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinition;
import com.ptc.core.meta.type.mgmt.server.impl.WTTypeDefinitionMaster;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.web.multipart.MultipartFile;
import wt.access.NotAuthorizedException;
import wt.content.*;
import wt.doc.*;
......@@ -23,7 +24,6 @@ import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.org.WTPrincipal;
import wt.org.WTPrincipalReference;
import wt.part.WTPart;
import wt.query.ClassAttribute;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
......@@ -43,6 +43,9 @@ import wt.vc.config.LatestConfigSpec;
import wt.vc.wip.CheckoutLink;
import wt.vc.wip.WorkInProgressHelper;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
......@@ -352,6 +355,55 @@ public class DocUtil implements RemoteAccess, Serializable {
return data;
}
/**
* 获取文档主内容
*
* @param holder
* 文档
* @param roleType
* 所属类型
* @return 结果
* @throws WTException
* 异常
*/
public static List<ApplicationData> getHolderContents(ContentHolder holder, ContentRoleType roleType)
throws WTException {
List<ApplicationData> dataList = new ArrayList<ApplicationData>();
QueryResult qr = ContentHelper.service.getContentsByRole(holder, roleType);
while (qr.hasMoreElements()) {
ContentItem item = (ContentItem)qr.nextElement();
if (item instanceof ApplicationData) {
dataList.add((ApplicationData)item);
}
}
return dataList;
}
/**
* 获取文档主内容
*
* @param holder
* 文档
* @param roleType
* 所属类型
* @return 结果
* @throws WTException
* 异常
*/
public static ApplicationData getHolderContent(ContentHolder holder, ContentRoleType roleType)
throws WTException {
ApplicationData data = null;
QueryResult qr = ContentHelper.service.getContentsByRole(holder, roleType);
if (qr.hasMoreElements()) {
ContentItem item = (ContentItem)qr.nextElement();
if (item instanceof ApplicationData) {
data = (ApplicationData)item;
}
}
return data;
}
/**
* 根据oid获取文档
*
......@@ -1282,4 +1334,44 @@ public class DocUtil implements RemoteAccess, Serializable {
}
return null;
}
public static void uploadContentHolder(ContentHolder holder, MultipartFile multipartFile, ContentRoleType roleType) throws Exception {
if (roleType.equals(ContentRoleType.PRIMARY)) {
QueryResult qr2 = ContentHelper.service.getContentsByRole(holder, roleType);
if (qr2.hasMoreElements()) {
ApplicationData appData = (ApplicationData) qr2.nextElement();
ContentServerHelper.service.deleteContent(holder, appData);
logger.debug("找到已存在的主内容,删除");
}
}
ApplicationData applicationData = ApplicationData.newApplicationData(holder);
applicationData.setRole(roleType);
InputStream ins = multipartFile.getInputStream();
ApplicationData applicationData1 = ContentServerHelper.service.updateContent(holder, applicationData, ins);
PersistenceHelper.manager.save(applicationData1);
PersistenceServerHelper.manager.restore(holder);
ins.close();
}
public static void uploadContentHolder(ContentHolder holder, File file, ContentRoleType roleType) throws Exception {
if (roleType.equals(ContentRoleType.PRIMARY)) {
QueryResult qr2 = ContentHelper.service.getContentsByRole(holder, roleType);
if (qr2.hasMoreElements()) {
ApplicationData appData = (ApplicationData) qr2.nextElement();
ContentServerHelper.service.deleteContent(holder, appData);
logger.debug("找到已存在的主内容,删除");
}
}
ApplicationData applicationData = ApplicationData.newApplicationData(holder);
applicationData.setRole(roleType);
//InputStream ins = new FileInputStream(file);
ApplicationData applicationData1 = ContentServerHelper.service.updateContent(holder, applicationData, file.getPath());
PersistenceHelper.manager.save(applicationData1);
PersistenceServerHelper.manager.restore(holder);
//ins.close();
}
public static void delContentItem(ContentHolder holder, ApplicationData data) throws WTException, WTPropertyVetoException {
ContentServerHelper.service.deleteContent(holder, data);
}
}
package com.yonde.common;
import com.ptc.windchill.enterprise.templateutil.ActionValidator;
import com.yonde.basedata.vo.ObjFileLinkVO;
import com.yonde.basedata.vo.RepoFileVO;
import com.yonde.part.vo.DxPartVO;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import wt.access.AccessControlHelper;
import wt.access.AccessPermission;
import wt.content.ApplicationData;
import wt.content.ContentHolder;
import wt.content.ContentRoleType;
import wt.content.Streamed;
import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.fc.PersistenceServerHelper;
......@@ -13,18 +26,26 @@ import wt.inf.container.WTContainerRef;
import wt.lifecycle.LifeCycleHelper;
import wt.lifecycle.LifeCycleManaged;
import wt.lifecycle.State;
import wt.log4j.LogR;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.part.WTPart;
import wt.session.SessionContext;
import wt.session.SessionHelper;
import wt.util.WTException;
import wt.util.WTProperties;
import wt.util.WTPropertyVetoException;
import wt.vc.wip.CheckoutLink;
import wt.vc.wip.WorkInProgressHelper;
import wt.vc.wip.Workable;
import java.io.Serializable;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class DxCommonUtils implements RemoteAccess, Serializable {
private static Logger logger = LogR.getLogger(DxCommonUtils.class.getName());
private static final long serialVersionUID = 1L;
/**
*
* 返回检出的工作副本,如果已经检出,则返回已经存在的工作副本
......@@ -162,4 +183,229 @@ public class DxCommonUtils implements RemoteAccess, Serializable {
return location;
}
public static List<ObjFileLinkVO> buildObjFileLinks(ContentHolder contentHolder) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (List) RemoteMethodServer.getDefault().invoke("buildObjFileLinks", DxCommonUtils.class.getName(), null,
new Class[] { ContentHolder.class },
new Object[] { contentHolder });
}
List<ObjFileLinkVO> resultList = new ArrayList<ObjFileLinkVO>();
WTObject wtObject = null;
if (contentHolder instanceof WTDocument) {
wtObject = (WTDocument)contentHolder;
} else if (contentHolder instanceof WTPart) {
wtObject = (WTPart)contentHolder;
}
ApplicationData holderContent = DocUtil.getHolderContent(contentHolder, ContentRoleType.PRIMARY);
if (ObjectsUtil.nonNull(holderContent)) {
ObjFileLinkVO master_file = new ObjFileLinkVO(wtObject, new RepoFileVO(holderContent), "MASTER_FILE");
resultList.add(master_file);
}
List<ApplicationData> docContents = DocUtil.getHolderContents(contentHolder, ContentRoleType.SECONDARY);
if (CollectionUtils.isNotEmpty(docContents)) {
for (ApplicationData docContent : docContents) {
ObjFileLinkVO attach_file = new ObjFileLinkVO(wtObject, new RepoFileVO(docContent), "ATTACH_FILE");
resultList.add(attach_file);
}
}
return resultList;
}
public static void uploadFile(CommonsMultipartFile file, ObjFileLinkVO fileForm) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("uploadFile", DxCommonUtils.class.getName(), null,
new Class[] { CommonsMultipartFile.class, ObjFileLinkVO.class },
new Object[] { file, fileForm });
return;
}
SessionContext previous = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
String importFiledirPath = WTProperties.getLocalProperties().getProperty("wt.content.temp") + File.separator + System.nanoTime();
File importFiledir = new File(importFiledirPath);
importFiledir.mkdir();
logger.error(">>>>importFiledirPath=" + importFiledirPath);
File importFile = new File(importFiledirPath + File.separator + file.getOriginalFilename());
file.transferTo(importFile);
logger.error("====importFile =====" + importFile);
String contentType = fileForm.getContentType();
Long sourceId = fileForm.getSourceId();
String targetId = fileForm.getTargetId();
String operator = fileForm.getOperator();
String sourceIdType = fileForm.getSourceIdType();
ContentHolder holder = DxDocUtil.getDocById(sourceId);
if (StringUtils.isNotEmpty(sourceIdType) && sourceIdType.toLowerCase().contains("part")) {
holder = DxPartUtil.getPartById(sourceId);
}
if ("ADD".equalsIgnoreCase(operator)) {
ContentRoleType roleType = ContentRoleType.PRIMARY;
if (StringUtils.isNotEmpty(contentType) && contentType.equalsIgnoreCase("ATTACH_FILE")) {
roleType = ContentRoleType.SECONDARY;
}
DocUtil.uploadContentHolder(holder, file, roleType);
} else {
ApplicationData dataById = getAppDataById(targetId);
if (ObjectsUtil.nonNull(dataById)) {
DocUtil.delContentItem(holder, dataById);
}
}
logger.error("===fileForm===" + fileForm);
} finally {
SessionContext.setContext(previous);
}
}
/**
* 根据id 查询DxApp
* @param id
* @return
*/
public static ApplicationData getAppDataById(String id) throws Exception {
String oid = "OR:wt.content.ApplicationData:" + id;
ApplicationData appData = (ApplicationData) RfUtil.getWTObjectByOid(oid);
return appData;
}
/**
* 根据id 查询InputStream
* @param id
* @return
*/
public static byte[] getDataByteById(String id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (byte[]) RemoteMethodServer.getDefault().invoke("getInputStreamById", DxCommonUtils.class.getName(), null,
new Class[] { String.class },
new Object[] { id });
}
SessionContext previous = SessionContext.newContext();
InputStream stream = null;
byte[] bytes = null;
try {
SessionHelper.manager.setAdministrator();
ApplicationData app = getAppDataById(id);
logger.error("=====app=====" + app);
if (ObjectsUtil.nonNull(app)) {
Streamed streamed = (Streamed) app.getStreamData().getObject();
if ((streamed != null) && (streamed.retrieveStream() != null)) {
stream = streamed.retrieveStream();
}
}
if (ObjectsUtil.nonNull(stream)) {
bytes = new byte[stream.available()];
stream.read(bytes, 0, stream.available());
}
} finally {
SessionContext.setContext(previous);
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bytes;
}
/**
* 根据id 查询InputStream
* @param id
* @return
*/
public static InputStream getInputStreamById(String id, String fileName) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (InputStream) RemoteMethodServer.getDefault().invoke("getInputStreamById", DxCommonUtils.class.getName(), null,
new Class[] { String.class, String.class },
new Object[] { id, fileName });
}
SessionContext previous = SessionContext.newContext();
InputStream stream = null;
try {
SessionHelper.manager.setAdministrator();
String folderStr = WTProperties.getLocalProperties().getProperty("wt.content.temp") + File.separator + System.nanoTime();
ApplicationData app = getAppDataById(id);
if (ObjectsUtil.nonNull(app)) {
logger.error("=====app=====" + app.getFileName());
fileName = app.getFileName();
Streamed streamed = (Streamed) app.getStreamData().getObject();
if ((streamed != null) && (streamed.retrieveStream() != null)) {
stream = streamed.retrieveStream();
InputStream is = streamed.retrieveStream();
FileOutputStream fos = new FileOutputStream(folderStr + File.separator + app.getFileName());
IOUtils.copy(is, fos);
is.close();
fos.close();
}
}
/* if (ObjectsUtil.nonNull(stream)) {
bytes = new byte[stream.available()];
stream.read(bytes, 0, stream.available());
}*/
} finally {
SessionContext.setContext(previous);
/* if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}*/
}
return stream;
}
/**
* 根据id 查询File
* @param id
* @return
*/
public static String getFileById(String id, String fileName) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (String) RemoteMethodServer.getDefault().invoke("getFileById", DxCommonUtils.class.getName(), null,
new Class[] { String.class, String.class },
new Object[] { id, fileName });
}
SessionContext previous = SessionContext.newContext();
InputStream stream = null;
String folderStr = WTProperties.getLocalProperties().getProperty("wt.content.temp") + File.separator + id;
File importFiledir = new File(folderStr);
importFiledir.mkdir();
try {
SessionHelper.manager.setAdministrator();
ApplicationData app = getAppDataById(id);
if (ObjectsUtil.nonNull(app)) {
logger.error("=====app=====" + app.getFileName());
fileName = app.getFileName();
Streamed streamed = (Streamed) app.getStreamData().getObject();
if ((streamed != null) && (streamed.retrieveStream() != null)) {
InputStream is = streamed.retrieveStream();
folderStr = folderStr + File.separator + fileName;
importFiledir = new File(folderStr);
FileOutputStream fos = new FileOutputStream(importFiledir);
IOUtils.copy(is, fos);
is.close();
fos.close();
}
}
/* if (ObjectsUtil.nonNull(stream)) {
bytes = new byte[stream.available()];
stream.read(bytes, 0, stream.available());
}*/
} finally {
SessionContext.setContext(previous);
/* if (stream != null) {
try {
stream.close();
} catch (IOException e) {
e.printStackTrace();
}
}*/
}
return folderStr;
}
}
......@@ -223,9 +223,14 @@ public class DxPartUtil implements RemoteAccess, Serializable {
}
}
DxViewVO dxView = dxPartVO.getDxView();
logger.error("dxView====" + dxView);
if (ObjectsUtil.nonNull(dxView)) {
logger.error("dxView id====" + dxView.getId());
if (ObjectsUtil.isNull(dxView.getName())) {
partView = SearchOperatorEnumUtil.viewMap.get(dxView.getId());
partView = SearchOperatorEnumUtil.viewMap.get(String.valueOf(dxView.getId()));
logger.error("dxView name====" + partView);
} else {
partView = dxView.getName();
}
}
String partType = "";
......@@ -285,11 +290,12 @@ public class DxPartUtil implements RemoteAccess, Serializable {
View part_view = null;
try {
if (partView == null || partView.trim().equals("")) {
if (StringUtils.isEmpty(partView)) {
part_view = ViewHelper.service.getView("Design");
} else {
part_view = ViewHelper.service.getView(partView);
}
logger.error("partView Name======" + partView);
} catch (Exception e) {
e.printStackTrace();
......
......@@ -206,12 +206,15 @@ public class DxSearchUtil implements RemoteAccess, Serializable {
//视图
if (fieldName.equals(SearchOperatorEnumUtil.DX_VIEWID)) {
addQuerySpecOp(querySpec, operator);
View view = ViewHelper.service.getView(SearchOperatorEnumUtil.viewMap.get(item.value));
String viewName = SearchOperatorEnumUtil.viewMap.get(String.valueOf(item.value));
logger.error("viewName=========" + viewName);
View view = ViewHelper.service.getView(viewName);
logger.error("view=========" + view);
if (view == null) {
continue;
}
SearchCondition sc = buildScd(clazz, typeSearchMap.get(fieldName), item.operator.name(), PersistenceHelper
.getObjectIdentifier(view));
.getObjectIdentifier(view).getId());
if (ObjectsUtil.nonNull(sc)) {
querySpec.appendWhere(sc, new int[]{0});
}
......
......@@ -14,17 +14,21 @@ import wt.inf.container.WTContainerRef;
import wt.log4j.LogR;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.org.WTUser;
import wt.part.*;
import wt.pds.StatementSpec;
import wt.query.ArrayExpression;
import wt.query.ClassAttribute;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.session.SessionHelper;
import wt.session.SessionServerHelper;
import wt.type.TypedUtility;
import wt.util.WTException;
import wt.vc.VersionControlHelper;
import wt.vc.config.ConfigSpec;
import wt.vc.config.IteratedOrderByPrimitive;
import wt.vc.config.LatestConfigSpec;
import wt.vc.config.VersionedOrderByPrimitive;
import wt.vc.views.View;
import wt.vc.views.ViewHelper;
......@@ -33,6 +37,7 @@ import wt.vc.views.ViewReference;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
......@@ -409,4 +414,137 @@ public class PartUtil implements RemoteAccess {
}
return latestPart;
}
/**
* @描述 获得所有的子件,不包括根节点
* @作者 Pengfei,Li
* @时间 2015-9-11上午11:13:19
*/
public static void getAllChildByView(WTPart parent, ConfigSpec configSpec, List<WTPart> childSet) throws Exception {
List<WTPart> childs = getChildByView(parent, configSpec);
childSet.addAll(childs);
for (WTPart wtPart : childs) {
getAllChildByView(wtPart, configSpec, childSet);
}
}
/**
* @描述 获取指定视图的子件,若子件无该视图则返回上游Design视图
* @作者 Pengfei,Li
* @时间 2015-9-11上午10:47:16
*/
@SuppressWarnings("unchecked")
public static List<WTPart> getChildByView(WTPart parent, String viewStr) throws WTException {
List<WTPart> childs = new ArrayList<WTPart>();
if (!RemoteMethodServer.ServerFlag) {
try {
childs = (List<WTPart>) RemoteMethodServer.getDefault().invoke("getChildByView", PartUtil.class.getName(), null,
new Class[] { WTPart.class, String.class }, new Object[] { parent, viewStr });
} catch (Exception e) {
throw new WTException(e);
}
} else {
SessionServerHelper.manager.setAccessEnforced(false);
try {
WTPartConfigSpec partConfigSpec = WTPartConfigSpec
.newWTPartConfigSpec(WTPartStandardConfigSpec.newWTPartStandardConfigSpec(ViewHelper.service.getView(viewStr), null));
for (QueryResult subNodes = WTPartHelper.service.getUsesWTParts(parent, partConfigSpec); subNodes.hasMoreElements();) {
wt.fc.Persistable aSubNodePair[] = (wt.fc.Persistable[]) subNodes.nextElement();
if (aSubNodePair[1] instanceof WTPart) {
WTPart tempPart = (WTPart) aSubNodePair[1];
if (tempPart != null) {
childs.add(tempPart);
}
} else if (aSubNodePair[1] instanceof WTPartMaster) {
String partNo = ((WTPartMaster) aSubNodePair[1]).getNumber();
WTPart tempPart = null;
try {
tempPart = getLatestViewPart(partNo, viewStr);
if (tempPart == null) {
tempPart = getLatestViewPart(partNo, "Design");
}
if (tempPart != null) {
childs.add(tempPart);
}
} catch (Exception e) {
throw new WTException(e);
}
}
}
} finally {
SessionServerHelper.manager.setAccessEnforced(true);
}
}
return childs;
}
/**
* @描述 获取指定视图的最新版
*/
public static WTPart getLatestViewPart(String number, String viewName) throws WTException {
try {
if (!RemoteMethodServer.ServerFlag) {
return (WTPart) RemoteMethodServer.getDefault().invoke("getLatestViewPart", PartUtil.class.getName(), null,
new Class[] { String.class, String.class }, new Object[] { number, viewName });
} else {
WTPart part = null;
if (!StringUtils.isEmpty(number) && !StringUtils.isEmpty(viewName)) {
QuerySpec qs = new QuerySpec(WTPart.class);
qs.setAdvancedQueryEnabled(true);
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.LATEST_ITERATION, SearchCondition.IS_TRUE), new int[] { 0 });
number = number == null ? null : number.toUpperCase();
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.NUMBER, SearchCondition.EQUAL, number), new int[] { 0 });
View view = ViewHelper.service.getView(viewName);
qs.appendAnd();
qs.appendWhere(new SearchCondition(WTPart.class, WTPart.VIEW + "." + ObjectReference.KEY, SearchCondition.EQUAL,
PersistenceHelper.getObjectIdentifier(view)), new int[] { 0 });
QueryResult queryResult = PersistenceHelper.manager.find((StatementSpec) qs);
queryResult = new LatestConfigSpec().process(queryResult);
if (queryResult.hasMoreElements()) {
part = (WTPart) queryResult.nextElement();
}
}
return part;
}
} catch (RemoteException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
/**
* @描述 返回指定配置的子件
*/
@SuppressWarnings("unchecked")
public static List<WTPart> getChildByView(WTPart parent, ConfigSpec configSpec) throws Exception {
List<WTPart> childs = new ArrayList<WTPart>();
if (!RemoteMethodServer.ServerFlag) {
childs = (List<WTPart>) RemoteMethodServer.getDefault().invoke("getChildByView", PartUtil.class.getName(), null,
new Class[] { WTPart.class, WTPartConfigSpec.class }, new Object[] { parent, configSpec });
} else {
WTUser currentUser = (WTUser) SessionHelper.manager.getPrincipal();
try {
SessionHelper.manager.setAdministrator();
for (QueryResult subNodes = WTPartHelper.service.getUsesWTParts(parent, configSpec); subNodes.hasMoreElements();) {
//for (QueryResult subNodes = StructHelper.service.navigateUsesToIteration(parent, false, configSpec); subNodes.hasMoreElements();) {
Object result = subNodes.nextElement();
if (!(result instanceof Persistable[]))
continue;
wt.fc.Persistable aSubNodePair[] = (wt.fc.Persistable[]) result;
if (aSubNodePair[1] instanceof WTPart) {
WTPartUsageLink link = (WTPartUsageLink) aSubNodePair[0];
WTPart tempPart = (WTPart) aSubNodePair[1];
if (tempPart != null) {
childs.add(tempPart);
}
}
}
} catch (Exception e) {
throw new WTException(e);
} finally {
SessionHelper.manager.setPrincipal(currentUser.getName());
}
}
return childs;
}
}
......@@ -192,7 +192,7 @@ public class DxDocService implements RemoteAccess {
}
public DxDocumentVO findByNumber(String var1) throws WTException, RemoteException, InvocationTargetException {
public DxDocumentVO findByNumber(String var1) throws Exception {
return new DxDocumentVO(DocUtil.getDoc(var1));
}
......
......@@ -17,7 +17,7 @@ public class DxDocServiceImpl {
}
public DxDocumentVO findByNumber(String var1) throws WTException, RemoteException, InvocationTargetException {
public DxDocumentVO findByNumber(String var1) throws Exception {
return new DxDocumentVO(DocUtil.getDoc(var1));
}
......
......@@ -107,15 +107,16 @@ public class DxDocUtil {
if (state != null && state.length() > 0) {
doc = (WTDocument) LifeCycleServerHelper.setState(doc, State.toState(state));
}
doc = (WTDocument) PersistenceHelper.manager.save(doc);
doc = (WTDocument) PersistenceHelper.manager.refresh(doc);
log.info(">>>>>>>>>refresh.doc=" + doc.getNumber());
//doc = (WTDocument) PersistenceHelper.manager.refresh(doc);
Object description = ibaMap.get("description");
if (ObjectsUtil.nonNull(description)) {
doc.setDescription(String.valueOf(description));
ibaMap.remove("description");
}
doc = (WTDocument) PersistenceHelper.manager.save(doc);
doc = (WTDocument) PersistenceHelper.manager.refresh(doc);
log.info(">>>>>>>>>refresh.doc=" + doc.getNumber());
//doc = (WTDocument) PersistenceHelper.manager.refresh(doc);
int ibaSize = ibaMap == null ? 0 : ibaMap.size();
log.debug("开始设置软属性,数:" + ibaSize);
if (ibaSize > 0) {
......
......@@ -4,8 +4,10 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.yonde.basedata.entity.users.DxUserVO;
import com.yonde.basedata.vo.*;
import com.yonde.common.DxCommonUtils;
import com.yonde.common.IBAHelper;
import com.yonde.context.vo.DxContextVO;
import org.apache.commons.lang.StringUtils;
import wt.doc.WTDocument;
import wt.fc.PersistenceHelper;
import wt.org.WTOrganization;
......@@ -18,6 +20,7 @@ import wt.vc.wip.WorkInProgressHelper;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Locale;
import java.util.Map;
......@@ -57,10 +60,12 @@ public class DxDocumentVO extends RevisionControlledVO implements Serializable {
private Long dxDocumentFolderId;
private String dxDocumentFolderIdType;
private List<ObjFileLinkVO> objFileLinks;
//TODO link
public DxDocumentVO(WTDocument wtDoc) throws WTException, RemoteException, InvocationTargetException {
public DxDocumentVO(WTDocument wtDoc) throws Exception {
super(wtDoc);
//TODO
//Team team = TeamHelper.service.getTeam("");
......@@ -91,8 +96,11 @@ public class DxDocumentVO extends RevisionControlledVO implements Serializable {
this.latest = wtDoc.isLatestIteration();
this.checkOuted = WorkInProgressHelper.isCheckedOut(wtDoc);
//this.setOperator("NO_CHANGE");
if (StringUtils.isNotEmpty(wtDoc.getDescription())) {
this.getDynamicAttrs().put("description", wtDoc.getDescription());
}
this.lifecycleTemplateId = PersistenceHelper.getObjectIdentifier(wtDoc.getLifeCycleTemplate().getObject()).getId();
this.setObjFileLinks(DxCommonUtils.buildObjFileLinks(wtDoc));
} finally {
SessionContext.setContext(previous);
}
......@@ -110,6 +118,14 @@ public class DxDocumentVO extends RevisionControlledVO implements Serializable {
}
}
public List<ObjFileLinkVO> getObjFileLinks() {
return objFileLinks;
}
public void setObjFileLinks(List<ObjFileLinkVO> objFileLinks) {
this.objFileLinks = objFileLinks;
}
public DxDocumentFolderVO getDxDocumentFolder() {
return dxDocumentFolder;
}
......
......@@ -183,4 +183,15 @@ public class DxPartController extends AbstractBaseController {
return parentDxPart;
}
}
@PostMapping({"/version/{id}/convertView"})
//@ApiOperation("转视图")
public ApiResult convertView(@PathVariable Long id) {
try {
DxPartService.convertViewAll(id);
} catch (Exception e) {
e.printStackTrace();
}
return ApiResult.ok("转视图成功");
}
}
......@@ -515,4 +515,76 @@ public class DxPartService implements RemoteAccess, Serializable {
return resultList;
}
/**
* 转视图
* @param id
* @return
* @throws Exception
*/
public static DxPartVO convertView(Long id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (DxPartVO) RemoteMethodServer.getDefault().invoke("convertView", DxPartService.class.getName(), null,
new Class[] { Long.class},
new Object[] { id});
}
WTPart partById = DxPartUtil.getPartById(id);
String viewName = partById.getViewName();
if(!viewName.equalsIgnoreCase("Planning")){
WTPart tmpPart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
tmpPart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), tmpPart);
tmpPart = (WTPart) PersistenceHelper.manager.save(tmpPart);
return new DxPartVO(tmpPart);
}else{
return new DxPartVO(partById);
}
}
/**
* 批量转视图
* @param id
* @return
* @throws Exception
*/
public static void convertViewAll(Long id) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
RemoteMethodServer.getDefault().invoke("convertViewAll", DxPartService.class.getName(), null,
new Class[] { Long.class},
new Object[] { id});
}
/* SessionContext previous = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
} finally {
SessionContext.setContext(previous);
}*/
WTPart partById = DxPartUtil.getPartById(id);
String viewName = partById.getViewName();
if(!viewName.equalsIgnoreCase("Planning")){
WTPart ppart = PartUtil.getLatestViewPart(partById.getNumber(),"Planning");
ArrayList<WTPart> list = new ArrayList<WTPart>();
if(ppart==null){
WTPartConfigSpec partConfigSpec = WTPartConfigSpec
.newWTPartConfigSpec(WTPartStandardConfigSpec.newWTPartStandardConfigSpec(ViewHelper.service.getView("Design"), null));
PartUtil.getAllChildByView(partById,partConfigSpec,list);
ppart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
ppart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), ppart);
PersistenceHelper.manager.save(ppart);
}
for(WTPart tempPart : list){
tempPart = (WTPart) ViewHelper.service.newBranchForView(partById, "Planning");
tempPart.setContainer(partById.getContainer());
CommonUtil.setFolder("/Default/PBOM/PBOM零部件", partById.getContainerReference(), tempPart);
PersistenceHelper.manager.save(tempPart);
}
}else{
throw new Exception("无需转视图");
}
}
}
......@@ -37,7 +37,7 @@ public class DxPartDescribeLinkVO extends IdVO implements Serializable{
public DxPartDescribeLinkVO() {
}
public DxPartDescribeLinkVO(WTPartDescribeLink describeLink) throws WTException, RemoteException, InvocationTargetException {
public DxPartDescribeLinkVO(WTPartDescribeLink describeLink) throws Exception {
super(describeLink);
SessionContext previous = SessionContext.newContext();
try {
......
......@@ -39,7 +39,7 @@ public class DxPartReferenceLinkVO extends IdVO implements Serializable{
public DxPartReferenceLinkVO() {
}
public DxPartReferenceLinkVO(WTPartReferenceLink referenceLink) throws WTException, RemoteException, InvocationTargetException {
public DxPartReferenceLinkVO(WTPartReferenceLink referenceLink) throws Exception {
super(referenceLink);
SessionContext previous = SessionContext.newContext();
try {
......
package com.yonde.plan.controller;
import com.yonde.plan.service.DxProcessLinkService;
import com.yonde.plan.vo.DxProcessDocDescribeLinkVO;
import com.yonde.plan.vo.DxProcessDocReferenceLinkVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping(value = "/DxProcessLink")
public class DxProcessLinkController {
//@ApiOperation("深度保存对象")
@PostMapping({"/ref/search"})
public List processRefDocLinks(@RequestBody Map entity) {
try {
List<DxProcessDocReferenceLinkVO> linkVOList = DxProcessLinkService.buildProcessDocRefLink(entity);
return linkVOList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
//@ApiOperation("深度保存对象")
@PostMapping({"/des/search"})
public List processDesDocLinks(@RequestBody Map entity) {
try {
List<DxProcessDocDescribeLinkVO> linkVOList = DxProcessLinkService.buildProcessDocDesLink(entity);
return linkVOList;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
package com.yonde.plan.service;
import com.yonde.doc.util.DxDocUtil;
import com.yonde.plan.vo.DxProcessDocDescribeLinkVO;
import com.yonde.plan.vo.DxProcessDocReferenceLinkVO;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import wt.doc.WTDocument;
import wt.log4j.LogR;
import wt.method.RemoteAccess;
import wt.method.RemoteMethodServer;
import wt.session.SessionContext;
import wt.session.SessionHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
@Service
public class DxProcessLinkService implements RemoteAccess {
private static Logger logger = LogR.getLogger(DxProcessLinkService.class.getName());
public static List<DxProcessDocReferenceLinkVO> buildProcessDocRefLink(Map entity) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (List) RemoteMethodServer.getDefault().invoke("buildProcessDocRefLink", DxProcessLinkService.class.getName(), null,
new Class[] { Map.class },
new Object[] { entity });
}
SessionContext previous = SessionContext.newContext();
List<DxProcessDocReferenceLinkVO> resultList = new ArrayList<DxProcessDocReferenceLinkVO>();
try {
SessionHelper.manager.setAdministrator();
String docIds = (String) entity.get("docIds");
//String sourceId = (String) entity.get("sourceId");
logger.error("docIds====" + docIds);
StringTokenizer tokenizer = new StringTokenizer(docIds, ",");
while (tokenizer.hasMoreElements()) {
String docId = tokenizer.nextToken();
WTDocument wtDocument = DxDocUtil.getDocById(Long.valueOf(docId));
DxProcessDocReferenceLinkVO linkVO = new DxProcessDocReferenceLinkVO(wtDocument);
resultList.add(linkVO);
}
} finally {
SessionContext.setContext(previous);
}
return resultList;
}
public static List<DxProcessDocDescribeLinkVO> buildProcessDocDesLink(Map entity) throws Exception {
if (!RemoteMethodServer.ServerFlag) {
return (List) RemoteMethodServer.getDefault().invoke("buildProcessDocDesLink", DxProcessLinkService.class.getName(), null,
new Class[] { Map.class },
new Object[] { entity });
}
List<DxProcessDocDescribeLinkVO> resultList = new ArrayList<DxProcessDocDescribeLinkVO>();
SessionContext previous = SessionContext.newContext();
try {
SessionHelper.manager.setAdministrator();
String docIds = (String) entity.get("docIds");
StringTokenizer tokenizer = new StringTokenizer(docIds, ",");
while (tokenizer.hasMoreElements()) {
String docId = tokenizer.nextToken();
WTDocument wtDocument = DxDocUtil.getDocById(Long.valueOf(docId));
DxProcessDocDescribeLinkVO linkVO = new DxProcessDocDescribeLinkVO(wtDocument);
resultList.add(linkVO);
}
} finally {
SessionContext.setContext(previous);
}
return resultList;
}
}
package com.yonde.plan.vo;
import com.yonde.basedata.vo.IdVO;
import com.yonde.doc.vo.DxDocumentVO;
import wt.doc.WTDocument;
public class DxProcessDocDescribeLinkVO extends IdVO {
private Object source;
private Long sourceId;
private String sourceIdType;
private DxDocumentVO target;
private Long targetId;
private String targetIdType;
public DxProcessDocDescribeLinkVO(WTDocument document) throws Exception {
super(document);
this.target = new DxDocumentVO(document);
this.targetId = target.getId();
this.sourceId = targetId;
this.sourceIdType = "DxProcessPlan";
this.targetIdType = "DxDocument";
this.setOperator("NO_CHANGE");
}
public Object getSource() {
return source;
}
public void setSource(Object source) {
this.source = source;
}
public Long getSourceId() {
return sourceId;
}
public void setSourceId(Long sourceId) {
this.sourceId = sourceId;
}
public String getSourceIdType() {
return sourceIdType;
}
public void setSourceIdType(String sourceIdType) {
this.sourceIdType = sourceIdType;
}
public DxDocumentVO getTarget() {
return target;
}
public void setTarget(DxDocumentVO target) {
this.target = target;
}
public Long getTargetId() {
return targetId;
}
public void setTargetId(Long targetId) {
this.targetId = targetId;
}
public String getTargetIdType() {
return targetIdType;
}
public void setTargetIdType(String targetIdType) {
this.targetIdType = targetIdType;
}
}
package com.yonde.plan.vo;
import com.yonde.basedata.vo.IdVO;
import com.yonde.doc.vo.DxDocumentVO;
import wt.doc.WTDocument;
public class DxProcessDocReferenceLinkVO extends IdVO {
private Object source;
private Long sourceId;
private String sourceIdType;
private DxDocumentVO target;
private Long targetId;
private String targetIdType;
public DxProcessDocReferenceLinkVO(WTDocument document) throws Exception {
super(document);
this.target = new DxDocumentVO(document);
this.targetId = target.getId();
this.sourceId = targetId;
this.sourceIdType = "DxProcessPlan";
this.targetIdType = "DxDocument";
this.setOperator("NO_CHANGE");
}
public Object getSource() {
return source;
}
public void setSource(Object source) {
this.source = source;
}
public Long getSourceId() {
return sourceId;
}
public void setSourceId(Long sourceId) {
this.sourceId = sourceId;
}
public String getSourceIdType() {
return sourceIdType;
}
public void setSourceIdType(String sourceIdType) {
this.sourceIdType = sourceIdType;
}
public DxDocumentVO getTarget() {
return target;
}
public void setTarget(DxDocumentVO target) {
this.target = target;
}
public Long getTargetId() {
return targetId;
}
public void setTargetId(Long targetId) {
this.targetId = targetId;
}
public String getTargetIdType() {
return targetIdType;
}
public void setTargetIdType(String targetIdType) {
this.targetIdType = targetIdType;
}
}
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