119 lines
5.2 KiB
Plaintext

<%@page import="java.net.URLDecoder"%>
<%@page import="com.amarsoft.are.jbo.impl.BizObjectTableMapper"%>
<%@page import="com.amarsoft.awe.util.DBKeyHelp"%>
<%@ page import="com.amarsoft.app.lc.workflow.action.GetFlowAction" %>
<%@ page import="com.amarsoft.dict.als.manage.NameManager" %>
<%@page import="com.amarsoft.awe.common.attachment.*"%>
<%@ page import="com.tenwa.doc.action.DocListInitAction" %>
<%@ page contentType="text/html; charset=GBK"%>
<%@ include file="/IncludeBegin.jsp"%><%
AmarsoftUpload myAmarsoftUpload = new AmarsoftUpload();
myAmarsoftUpload.initialize(pageContext);
myAmarsoftUpload.upload();
String sFileName = myAmarsoftUpload.getFiles().getFile(0).getFileName(); //文件名称
String libraryId=""; //附件编号
String InputTime= StringFunction.getTodayNow(); //附件上传时间
String contract_id= (String)myAmarsoftUpload.getRequest().getParameter("contract_id"); //合同编号
String ObjectType=(String)myAmarsoftUpload.getRequest().getParameter("OBJECTTYPE");//附件类型
String otherParamWhere="";
BizObjectManager relaBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCRELATIVE");
BizObjectManager libBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCLIBRARY");
BizObjectManager attrBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCATTRIBUTE");
BizObject lib=null;
String sql="select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.Relative_Id=rela.id where rela.contract_id=:contract_id and rela.objecttype=:objecttype ";
BizObjectQuery query=libBm.createQuery(sql);
query.setParameter("contract_id",contract_id);
query.setParameter("objecttype",ObjectType);
lib=query.getSingleResult(true);
if(lib!=null){
libBm.saveObject(lib);
libraryId=lib.getAttribute("id").getString();
}else{
sql="select * from O left join jbo.app.tenwa.doc.LB_DOCLIBRARY lib on O.id=lib.Relative_Id where O.contract_id=:contract_id and O.objecttype=:objecttype ";
query=relaBm.createQuery(sql);
query.setParameter("contract_id",contract_id);
query.setParameter("objecttype",ObjectType);
BizObject rela=query.getSingleResult(true);
String relativeid="";
if(rela==null){
//初始化附件关联对象
rela=relaBm.newObject();
rela.setAttributeValue("ObjectType", ObjectType);
rela.setAttributeValue("contract_id", contract_id);
relaBm.saveObject(rela);
relativeid=rela.getAttribute("id").getString();
}else{
relativeid=rela.getAttribute("id").getString();
}
//初始化附件
lib=libBm.newObject();
lib.setAttributeValue("Relative_Id", relativeid);
libBm.saveObject(lib);
libraryId=lib.getAttribute("id").getString();
}
BizObject attr=attrBm.newObject();
attr.setAttributeValue("Library_Id", libraryId);
attr.setAttributeValue("FileName", sFileName);
attr.setAttributeValue("InputUserId", CurUser.getUserID());
attr.setAttributeValue("InputOrgId", CurUser.getOrgID());
attr.setAttributeValue("InputTime",InputTime);
attr.setAttributeValue("ObjectType", ObjectType);
//得到不带路径的文件名
sFileName = StringFunction.getFileName(sFileName);
sFileName = URLDecoder.decode(URLDecoder.decode(sFileName,"UTF-8"),"UTF-8");
//定义数据库操作变量
SqlObject so = null;
String sNewSql = "";
String sFileSaveMode = CurConfig.getConfigure("FileSaveMode");
String sFileSavePath = CurConfig.getConfigure("FileSavePath");
String sFileNameType = CurConfig.getConfigure("FileNameType");
String trueTable = ((BizObjectTableMapper)attrBm).getTable(); //取得真实的表名
String sAttachmentNo = DBKeyHelp.getSerialNo(trueTable,"Id");
if (!myAmarsoftUpload.getFiles().getFile(0).isMissing()){
try {
String uuid=java.util.UUID.randomUUID().toString().replaceAll("-", "");
String sFullPath =com.tenwa.officetempalte.util.FileOperatorUtil.getuploadFileDir(sFileSavePath) +uuid+"_"+sFileName;
//com.amarsoft.awe.common.attachment.FileNameHelper.getFullPath(libraryId, sAttachmentNo,sFileName, sFileSavePath, sFileNameType, application);
myAmarsoftUpload.getFiles().getFile(0).saveAs(sFullPath);
//得到带相对路径的文件名
String sFilePath = sFullPath.replace(sFileSavePath, "");
attr.setAttributeValue("FilePath",sFilePath);
attr.setAttributeValue("FullPath",sFullPath);
attr.setAttributeValue("Content_Type",DataConvert.toString(myAmarsoftUpload.getFiles().getFile(0).getContentType()));
attr.setAttributeValue("FileSize",DataConvert.toString(String.valueOf(myAmarsoftUpload.getFiles().getFile(0).getSize())));
attrBm.saveObject(attr);
myAmarsoftUpload = null;
}catch(Exception e){
e.printStackTrace();
out.println("An error occurs : " + e.toString());
attrBm.deleteObject(attr);
myAmarsoftUpload = null;
%>
<script type="text/javascript">
alert("上传失败");//上传文件失败!
parent.AsDialog.ClosePage();
</script>
<%
}
}
%>
<script type="text/javascript">
alert("上传成功");//上传文件成功!
parent.AsDialog.ClosePage("success");
</script>
<%@ include file="/IncludeEnd.jsp"%>