<%@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 oneClassify=(String)myAmarsoftUpload.getRequest().getParameter("ONE_CLASSIFY");//一级分类 oneClassify = oneClassify==null?"004001":oneClassify; String docId=(String)myAmarsoftUpload.getRequest().getParameter("DOC_NAME"); //二级分类 String sFileName = myAmarsoftUpload.getFiles().getFile(0).getFileName(); //文件名称 String Remark= (String)myAmarsoftUpload.getRequest().getParameter("REMARK"); //备注 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); //得到带相对路径的文件名 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"%>