2019-12-20 19:21:55 +08:00

231 lines
10 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@page import="java.io.File"%>
<%@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"%>
<%
// AmarsoftUpload myAmarsoftUpload = new AmarsoftUpload();
// myAmarsoftUpload.initialize(pageContext);
// myAmarsoftUpload.upload();
//1.创建DiskFileItemFactory对象配置缓存用
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
// 2. 创建 ServletFileUpload对象
ServletFileUpload servletFileUpload = new ServletFileUpload(diskFileItemFactory);
// 3. 设置文件名称编码
// servletFileUpload.setHeaderEncoding("UTF-8");
List<FileItem> items = servletFileUpload.parseRequest(request);
// String libraryId = "";//附件业务数据表编号
String inputTime = StringFunction.getTodayNow(); //附件编号上传时间
long fileSize = 0l; //文件大小
String contentType = ""; //文件类型
String sFileName = ""; //文件名称
String fileId = "";
String objectType = "";
String oneClassify = "";
String docId = "";
String Remark = "";
String cust_id = "";
String flowunid = "";
String ObjectType = "";
InputStream is = null;
for (FileItem fileItem : items) {
if (fileItem.isFormField()) { // >> 普通数据
String fieldValue = fileItem.getString("GB18030");
String fieldName = fileItem.getFieldName();
if("ONE_CLASSIFY".equals(fieldName)) {
oneClassify = fieldValue;
} else if("DOC_NAME".equals(fieldName)) {
docId = fieldValue;
} else if("REMARK".equals(fieldName)) {
Remark = fieldValue;
} else if("CUST_ID".equals(fieldName)) {
cust_id = fieldValue;
} else if("FLOWUNID".equals(fieldName)) {
flowunid = flowunid != null && !"".equals(flowunid) ? flowunid : fieldValue;
} else if("OBJECTTYPE".equals(fieldName)) {
ObjectType = fieldValue;
}
ARE.getLog().info(fieldName + ": " + fieldValue);
} else {
//获取文件的实际内容
is = fileItem.getInputStream();
contentType = fileItem.getContentType();
sFileName = fileItem.getName();
fileSize = fileItem.getSize();
}
}
// String oneClassify=(String)myAmarsoftUpload.getRequest().getParameter("ONE_CLASSIFY");//一级分类
oneClassify = oneClassify==null?"004001":oneClassify;
// String docId=(String)myAmarsoftUpload.getRequest().getParameter("DOC_NAME"); //二级分类
// String sFileName = fileName; //myAmarsoftUpload.getFiles().getFile(0).getFileName(); //文件名称
// System.out.println("文件名UTF-8" + new String(sFileName.getBytes(), "UTF-8"));
// System.out.println("文件名GBK" + new String(sFileName.getBytes(), "GBK"));
// System.out.println("文件名GB18030" + new String(sFileName.getBytes(), "GB18030"));
// String Remark= (String)myAmarsoftUpload.getRequest().getParameter("REMARK"); //备注
// System.out.println("备注UTF-8" + new String(Remark.getBytes(), "UTF-8"));
// System.out.println("备注GBK" + new String(Remark.getBytes(), "GBK"));
// System.out.println("备注GB18030" + new String(Remark.getBytes(), "GB18030"));
// String cust_id=(String)myAmarsoftUpload.getRequest().getParameter("CUST_ID"); //客户ID
BizObject docconfig=JBOFactory.createBizObjectQuery("jbo.app.tenwa.doc.LB_DOCCONFIG","id=:id").setParameter("id", docId).getSingleResult(false);
String docName=docconfig.getAttribute("DOC_NAME").getString();
String docType=docconfig.getAttribute("DOC_TYPE").getString();//资料类型
String doc_Class_Itemno=docconfig.getAttribute("DOC_CLASS_ITEMNO").getString();//资料类型
String libraryId=""; //附件编号
String InputTime= StringFunction.getTodayNow(); //附件上传时间
// String flowunid= (String)myAmarsoftUpload.getRequest().getParameter("FLOWUNID"); //流程号
// String ObjectType=(String)myAmarsoftUpload.getRequest().getParameter("OBJECTTYPE");//流程类型
String otherParamWhere="";
if(oneClassify==null){oneClassify="";}else if(oneClassify.length()>1){otherParamWhere=otherParamWhere+" and One_Classify=:oneClassify";}
if(docName==null){docName="";}else if(docName.length()>1){otherParamWhere=otherParamWhere+" and DOC_NAME=:docName";}
if(cust_id==null){cust_id="";}else if(cust_id.length()>1){otherParamWhere=otherParamWhere+" and rela.cust_id=:cust_id";}
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;
BizObject flow=GetFlowAction.getFlowBussinessObject(flowunid);//流程对象
String otherWhere=DocListInitAction.getFlowWhere(flow,"","rela");
String sql="select * from O left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on O.Relative_Id=rela.id where O.Doc_Type=:doc_type ";
sql+=otherWhere;
sql+=otherParamWhere;
BizObjectQuery query=libBm.createQuery(sql);
query.setParameter("doc_type",docType);
if(oneClassify.length()>0)query.setParameter("oneClassify", oneClassify);
if(docName.length()>0)query.setParameter("docName", docName);
if(cust_id.length()>0)query.setParameter("cust_id", cust_id);
lib=query.getSingleResult(true);
if(lib!=null){
lib.setAttributeValue("Remark", Remark);
libBm.saveObject(lib);
libraryId=lib.getAttribute("id").getString();
}else{
otherParamWhere="";
otherWhere=DocListInitAction.getFlowWhere(flow,"","O");
if(cust_id==null){cust_id="";}else if(cust_id.length()>1){otherParamWhere=otherParamWhere+" and O.cust_id=:cust_id";}
sql="select * from O left join jbo.app.tenwa.doc.LB_DOCLIBRARY lib on lib.Relative_Id=O.id where lib.Doc_Type=:doc_type ";
sql+=otherWhere;
sql+=otherParamWhere;
query=relaBm.createQuery(sql);
query.setParameter("doc_type",docType);
if(cust_id.length()>0)query.setParameter("cust_id", cust_id);
BizObject rela=query.getSingleResult(true);
String relativeid="";
if(rela==null){
//初始化附件关联对象
rela=relaBm.newObject();
rela.setAttributeValue("ObjectType", ObjectType);
rela.setAttributeValue("Flow_Unid", flowunid);
rela.setAttributeValue("proj_id", flow.getAttribute("proj_id").getString());
rela.setAttributeValue("contract_id", flow.getAttribute("contract_id").getString());
rela.setAttributeValue("cust_id",cust_id);
relaBm.saveObject(rela);
relativeid=rela.getAttribute("id").getString();
}else{
relativeid=rela.getAttribute("id").getString();
}
//初始化附件
lib=libBm.newObject();
lib.setAttributeValue("Doc_Type", docType);
lib.setAttributeValue("One_Classify", oneClassify);
lib.setAttributeValue("doc_Class_Itemno",doc_Class_Itemno);
lib.setAttributeValue("serial_num", docconfig.getAttribute("serial_num").getString());
lib.setAttributeValue("config_id", docId);
lib.setAttributeValue("doc_name", docName);
lib.setAttributeValue("Relative_Id", relativeid);
lib.setAttributeValue("BUSINESS_CHECK","DocCheck_2");
lib.setAttributeValue("REVIEW_CHECK","DocCheck_2");
lib.setAttributeValue("doc_nature","doc_nature");
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("Remark",Remark);
attr.setAttributeValue("ObjectType", ObjectType);
attr.setAttributeValue("FlowUnid", flowunid);
//得到不带路径的文件名
// 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);
//保存文件
File targetFile = new File(sFullPath);
;
FileUtils.copyInputStreamToFile(is, new File(sFullPath));
//得到带相对路径的文件名
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);
// 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"%>