121 lines
4.5 KiB
Plaintext
121 lines
4.5 KiB
Plaintext
<%@page import="java.io.File"%>
|
||
<%@page import="java.util.List"%>
|
||
<%@page import="java.net.URLDecoder"%>
|
||
<%@page import="org.apache.commons.io.FileUtils"%>
|
||
<%@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 import="org.apache.commons.fileupload.FileItem"%>
|
||
<%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
|
||
<%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
|
||
<%@ page contentType="text/html; charset=GBK"%>
|
||
<%@ include file="/IncludeBegin.jsp"%>
|
||
|
||
<%
|
||
//1.创建DiskFileItemFactory对象,配置缓存用
|
||
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
|
||
|
||
// 2. 创建 ServletFileUpload对象
|
||
ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
|
||
|
||
List<FileItem> items = servletFileUpload.parseRequest(request);
|
||
|
||
String libraryIds = "";//附件关联id集合
|
||
String libraryId = "";//附件关联id
|
||
String InputTime = StringFunction.getTodayNow(); //附件编号上传时间
|
||
long fileSize = 0l; //文件大小
|
||
String contentType = ""; //文件类型
|
||
String sFileName = ""; //文件名称
|
||
String fileId = "";
|
||
String Remark = "";
|
||
|
||
String ObjectType = "";
|
||
|
||
InputStream is = null;
|
||
|
||
for (FileItem fileItem : items) {
|
||
if (fileItem.isFormField()) { // >> 普通数据
|
||
String fieldValue = fileItem.getString("GB18030");
|
||
String fieldName = fileItem.getFieldName();
|
||
|
||
if("REMARK".equals(fieldName)) {
|
||
Remark = fieldValue;
|
||
} else if("OBJECTTYPE".equals(fieldName)) {
|
||
ObjectType = fieldValue;
|
||
} else if ("libraryId".equals(fieldName)){
|
||
libraryIds = fieldValue;
|
||
}
|
||
ARE.getLog().info(fieldName + ": " + fieldValue);
|
||
} else {
|
||
//获取文件的实际内容
|
||
is = fileItem.getInputStream();
|
||
contentType = fileItem.getContentType();
|
||
sFileName = fileItem.getName();
|
||
fileSize = fileItem.getSize();
|
||
}
|
||
}
|
||
BizObjectManager attrBm=JBOFactory.getBizObjectManager("jbo.app.tenwa.doc.LB_DOCATTRIBUTE");
|
||
//定义数据库操作变量
|
||
String sFileSavePath = CurConfig.getConfigure("FileSavePath");
|
||
|
||
String trueTable = ((BizObjectTableMapper)attrBm).getTable(); //取得真实的表名
|
||
String sAttachmentNo = DBKeyHelp.getSerialNo(trueTable,"Id");
|
||
String uuid=java.util.UUID.randomUUID().toString().replaceAll("-", "");
|
||
|
||
String sFullPath =com.tenwa.officetempalte.util.FileOperatorUtil.getuploadFileDir(sFileSavePath) +uuid+"_"+sFileName;
|
||
try {
|
||
|
||
String[] libList = libraryIds.split(",");
|
||
if(libList != null && libList.length>0){
|
||
for(int i =0; i<libList.length;i++){
|
||
libraryId = libList[i];
|
||
//删除原来的;
|
||
List<BizObject> attList = attrBm.createQuery(" Library_Id=:library_id and ObjectType=:objecttype ").setParameter("library_id", libraryId)
|
||
.setParameter("objecttype", ObjectType).getResultList(true);
|
||
if(attList != null && attList.size()>0){
|
||
for(int j =0; j<attList.size();j++){
|
||
BizObject att = attList.get(j);
|
||
att.setAttributeValue("DELETEED", "Y");
|
||
attrBm.saveObject(att);
|
||
}
|
||
}
|
||
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("Remark",Remark);
|
||
attr.setAttributeValue("ObjectType", ObjectType);
|
||
//得到带相对路径的文件名
|
||
String sFilePath = sFullPath.replace(sFileSavePath, "");
|
||
attr.setAttributeValue("FilePath",sFilePath);
|
||
attr.setAttributeValue("FullPath",sFullPath);
|
||
attr.setAttributeValue("Content_Type",contentType);
|
||
attr.setAttributeValue("FileSize",fileSize);
|
||
attrBm.saveObject(attr);
|
||
}
|
||
}
|
||
//保存文件
|
||
File targetFile = new File(sFullPath);
|
||
FileUtils.copyInputStreamToFile(is, new File(sFullPath));
|
||
}catch(Exception e){
|
||
e.printStackTrace();
|
||
out.println("An error occurs : " + e.toString());
|
||
%>
|
||
<script type="text/javascript">
|
||
alert("上传失败");//上传文件失败!
|
||
parent.AsDialog.ClosePage();
|
||
</script>
|
||
<%
|
||
}
|
||
// }
|
||
%>
|
||
<script type="text/javascript">
|
||
alert("上传成功");//上传文件成功!
|
||
parent.AsDialog.ClosePage("success");
|
||
</script>
|
||
<%@ include file="/IncludeEnd.jsp"%> |