85 lines
3.8 KiB
Plaintext
85 lines
3.8 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.awe.common.attachment.*"%>
|
|
<%@ page contentType="text/html; charset=GBK"%>
|
|
<%@ include file="/IncludeBegin.jsp"%><%
|
|
AmarsoftUpload myAmarsoftUpload = new AmarsoftUpload();
|
|
myAmarsoftUpload.initialize(pageContext);
|
|
myAmarsoftUpload.upload();
|
|
String id=CurPage.getParameter("id");
|
|
String sFileName = myAmarsoftUpload.getFiles().getFile(0).getFileName(); //文件名称
|
|
String InputTime= StringFunction.getTodayNow(); //附件编号上传时间
|
|
|
|
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");
|
|
|
|
BizObjectManager visBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.customer.CUSTOMER_VISIT_RECORD");
|
|
BizObject visit=visBm.createQuery("id=:id").setParameter("id", id).getSingleResult(true);
|
|
BizObject lib;
|
|
String relaid=visit.getAttribute("relativeid").getString();
|
|
if(relaid.length()>0){
|
|
lib=libBm.createQuery("RELATIVE_ID=:relaid").setParameter("relaid", relaid).getSingleResult(false);
|
|
}else{
|
|
BizObject rela=relaBm.newObject();
|
|
rela.setAttributeValue("ObjectType","CustomerVisit");
|
|
rela.setAttributeValue("cust_id",visit.getAttribute("customerid").getString());
|
|
relaBm.saveObject(rela);
|
|
relaid=rela.getAttribute("id").getString();
|
|
lib=libBm.newObject();
|
|
lib.setAttributeValue("RELATIVE_ID", relaid);
|
|
libBm.saveObject(lib);
|
|
visit.setAttributeValue("relativeid", relaid);
|
|
visBm.saveObject(visit);
|
|
}
|
|
String 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","CustomerVisit");
|
|
|
|
//得到不带路径的文件名
|
|
sFileName = StringFunction.getFileName(sFileName);
|
|
sFileName = URLDecoder.decode(URLDecoder.decode(sFileName,"UTF-8"),"UTF-8");
|
|
|
|
String sFileSavePath = CurConfig.getConfigure("FileSavePath");
|
|
|
|
|
|
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;
|
|
|
|
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.afterUpload(true);
|
|
</script>
|
|
<%
|
|
}
|
|
}
|
|
%>
|
|
<script type="text/javascript">
|
|
alert("上传成功");//上传文件成功!
|
|
parent.afterUpload(true);
|
|
</script>
|
|
<%@ include file="/IncludeEnd.jsp"%> |