%@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 FileSizejs=(String)myAmarsoftUpload.getRequest().getParameter("FileSize2");
String docType=(String)myAmarsoftUpload.getRequest().getParameter("DOC_TYPE");
String oneClassfiy=(String)myAmarsoftUpload.getRequest().getParameter("ONE_CLASSIFY");
String twoClassfiy=(String)myAmarsoftUpload.getRequest().getParameter("TWO_CLASSIFY");
String objectType=(String)myAmarsoftUpload.getRequest().getParameter("OBJECTTYPE");
String sFileName =URLDecoder.decode((String)myAmarsoftUpload.getRequest().getParameter("FILENAMEX"),"UTF-8"); //文件名称
System.out.println("文件名"+sFileName);
// System.out.println("文件名==="+ URLDecoder.decode((String)myAmarsoftUpload.getRequest().getParameter("FILENAMEX"),"UTF-8"));
String Remark=URLDecoder.decode((String)myAmarsoftUpload.getRequest().getParameter("REMARK2"),"UTF-8"); //备注InputTime
String libraryId= (String)myAmarsoftUpload.getRequest().getParameter("ID"); //附件编号
String InputTime= StringFunction.getTodayNow(); //附件编号上传时间
BizObjectManager libBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCLIBRARY");
BizObjectManager attrBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCATTRIBUTE");
BizObject lib=libBm.createQuery("id=:id").setParameter("id", libraryId).getSingleResult(true);
lib.setAttributeValue("Remark", Remark);
libBm.saveObject(lib);
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 {
//System.out.println("sDocNo="+libraryId+"--sAttachmentNo="+sAttachmentNo+"--sFileName="+sFileName+"--sFileSavePath="+sFileSavePath);
//System.out.println("sFileNameType="+sFileNameType+"--application="+application);
//String sFullPath = com.amarsoft.awe.common.attachment.FileNameHelper.getFullPath(libraryId, sAttachmentNo,sFileName, sFileSavePath, sFileNameType, application);
String uuid=java.util.UUID.randomUUID().toString().replaceAll("-", "");
String sFullPath =com.tenwa.officetempalte.util.FileOperatorUtil.getuploadFileDir(sFileSavePath) +uuid+"_"+sFileName;
if(myAmarsoftUpload.getFiles().getFile(0).getSize()!=Integer.parseInt(FileSizejs)){
throw new Exception("上传文件失败,请联系管理员!");
}
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;
%>
<%
}
}
%>
<%@ include file="/IncludeEnd.jsp"%>