From bad72cf161b0568065320336b5616ad4fb763c2e Mon Sep 17 00:00:00 2001 From: wendongchao Date: Mon, 5 Aug 2019 16:59:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E5=90=88=E5=90=8C=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=96=87=E4=BB=B6=E4=B8=80=E9=94=AE=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebContent/Tenwa/Comm/DocList/PayDocList.jsp | 20 +++++++++ .../com/tenwa/doc/action/DocListAction.java | 41 +++++++++++++++++++ .../servlet/DocFlowDownloadZipServlet.java | 2 +- src_core/com/tenwa/util/ZipFileUtil.java | 26 ++++++++++-- 4 files changed, 84 insertions(+), 5 deletions(-) diff --git a/WebContent/Tenwa/Comm/DocList/PayDocList.jsp b/WebContent/Tenwa/Comm/DocList/PayDocList.jsp index db2436d86..d72778d6a 100644 --- a/WebContent/Tenwa/Comm/DocList/PayDocList.jsp +++ b/WebContent/Tenwa/Comm/DocList/PayDocList.jsp @@ -32,15 +32,20 @@ if(sTempletNo==null){ sTempletNo="FlowPayDocList"; } + + String type=CurPage.getParameter("type"); + if(type==null)type=""; String docClassItemno=CurPage.getParameter("docList"); String[] itemnos=docClassItemno.split(","); String s=""; + String classItemno =""; for(int i=0;i0){ s=s.substring(0, s.length()-1); + classItemno = s.replace(",", "@"); } if("ProjectCreditFlow".equals(sObjectType)){ sTempletNo = "FlowPayDocList" ; @@ -61,6 +66,8 @@ docParam.put("inputuserid", CurPage.getUserId()); docParam.put("inputorgid", CurPage.getUser().getOrgID()); + String projectId = flow.getAttribute("proj_id").getString(); + //判断是否存在,不存在就从配置表倒到临时表 DocListInitAction.initDocList(docParam,other,docClassItemno,CurConfig); ASObjectModel doTemp = new ASObjectModel(sTempletNo); @@ -91,6 +98,7 @@ sButtons=new String[][]{ {"true","","Button","保存","保存所有修改","saveRecord()","","","",""}, + {"true","","Button","批量下载","批量下载","downloadZipFile()","","","","btn_icon_down"}, }; %> @@ -228,6 +236,18 @@ function deleteFile(id){ reloadSelf(); heping(); } +function downloadZipFile(){ + var projectId="<%=projectId%>"; + var classItemnos="<%=classItemno%>"; + var sParams="projectId="+projectId+",classItemnos="+classItemnos; + var ids = RunJavaMethodTrans("com.tenwa.doc.action.DocListAction","getLibraryIds",sParams); + var filePath="<%=CurConfig.getConfigure("FileSavePath")%>"; + var param="&flowunid=<%=flowunid%>&type=<%=type%>&ids="+ids; + if(!frames["downloadTemplate"]) $("").appendTo("body"); + window.open(sWebRootPath+"/servlet/view/docFlowDownloadZipServlet?CompClientID=<%=sCompClientID%>&filePath="+filePath+param, "downloadTemplate"); +} + + <%@ include file="/Frame/resources/include/include_end.jspf"%> \ No newline at end of file diff --git a/src_core/com/tenwa/doc/action/DocListAction.java b/src_core/com/tenwa/doc/action/DocListAction.java index 8d207629c..df2b32c20 100644 --- a/src_core/com/tenwa/doc/action/DocListAction.java +++ b/src_core/com/tenwa/doc/action/DocListAction.java @@ -13,6 +13,8 @@ import javax.imageio.ImageIO; import jbo.app.tenwa.doc.LB_DOCATTRIBUTE; import jbo.app.tenwa.doc.LB_DOCCONFIG; +import jbo.app.tenwa.doc.LB_DOCLIBRARY; +import jbo.app.tenwa.doc.LB_DOCRELATIVE; import com.amarsoft.are.ARE; import com.amarsoft.are.jbo.BizObject; @@ -38,6 +40,10 @@ public class DocListAction { public String lids; + public String classItemnos; + + public String projectId; + public String deleteFile(JBOTransaction tx) throws Exception{ if(attId==null||attId==""){ @@ -188,9 +194,44 @@ public class DocListAction { jsonObject.appendElement("height",sourceImg.getHeight()); return JSONEncoder.encode(jsonObject); } + public String getLibraryIds(JBOTransaction tx) throws JBOException{ + String itemnos = classItemnos.replace("@", ","); + String sql = "SELECT O.ID from O " + + " left join jbo.app.tenwa.doc.LB_DOCRELATIVE rela on rela.id=O.relative_Id" + + " where rela.proj_id='"+projectId+"' and rela.objecttype='BusinessApplyFlow'" + + " and O.doc_Class_Itemno in ("+itemnos+")" + + " ORDER BY DOC_CLASS_ITEMNO,Serial_Num"; + BizObjectManager relaBm = JBOFactory + .getBizObjectManager(LB_DOCLIBRARY.CLASS_NAME); + List rela = relaBm.createQuery(sql).getResultList(false); + String libId = ""; + for(BizObject biz : rela){ + libId += biz.getAttribute("ID").toString()+"@"; + } + libId = libId.substring(0, libId.length()-1); + return libId; + } + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + + + public String getClassItemnos() { + return classItemnos; + } + + public void setClassItemnos(String classItemnos) { + this.classItemnos = classItemnos; + } + public String getConfigid() { return configid; } diff --git a/src_core/com/tenwa/doc/servlet/DocFlowDownloadZipServlet.java b/src_core/com/tenwa/doc/servlet/DocFlowDownloadZipServlet.java index 1f2ea43ba..a8622356d 100644 --- a/src_core/com/tenwa/doc/servlet/DocFlowDownloadZipServlet.java +++ b/src_core/com/tenwa/doc/servlet/DocFlowDownloadZipServlet.java @@ -77,7 +77,7 @@ import com.tenwa.util.ZipFileUtil; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); for(BizObject lib:libs){ @SuppressWarnings("unchecked") - List attrs=JBOFactory.createBizObjectQuery(LB_DOCATTRIBUTE.CLASS_NAME,"library_id=:id").setParameter("id",lib.getAttribute("id").getString()).getResultList(false); + List attrs=JBOFactory.createBizObjectQuery(LB_DOCATTRIBUTE.CLASS_NAME,"library_id=:id and DELETEED is null").setParameter("id",lib.getAttribute("id").getString()).getResultList(false); if(attrs.size()==0){ continue; } diff --git a/src_core/com/tenwa/util/ZipFileUtil.java b/src_core/com/tenwa/util/ZipFileUtil.java index d96523d87..6ae7ecd12 100644 --- a/src_core/com/tenwa/util/ZipFileUtil.java +++ b/src_core/com/tenwa/util/ZipFileUtil.java @@ -3,11 +3,14 @@ package com.tenwa.util; import java.io.File; import java.io.FileInputStream; import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.mozilla.javascript.edu.emory.mathcs.backport.java.util.Collections; +import org.springframework.security.core.authority.mapping.MappableAttributesRetriever; public class ZipFileUtil { /** @@ -21,6 +24,7 @@ public class ZipFileUtil { if(!path.endsWith("/")){ path+="/"; } + HashMap map = new HashMap(); byte[] buf = new byte[1024]; try { if(srcFiles.size()==0){ @@ -40,11 +44,25 @@ public class ZipFileUtil { zipFiles(out,path+srcPath,as,null); } else{ - FileInputStream in = new FileInputStream(srcFiles.get(i)); - String filename= srcFiles.get(i).getName(); - if(filenames!=null){ - filename=filenames.get(i); + /** + * 文件输出流写入相同的文件名到相同的地址时会出错。 + * 当遇到相同的文件名时放到map中,之后改变文件名 + * 第一次:放入key,1 + * 第二次:若相同,1++, + * 若不同,放入key,1 + */ + String filename= filenames.get(i); + if(map.get(filename)==null){ + map.put(filename, 1); + }else{ + int num = map.get(filename)+1; + map.put(filename,num); } + if(1!=map.get(filename)){ + String[] arr = filenames.get(i).split("\\."); + filename = arr[0]+"("+map.get(filename)+")."+arr[1]; + } + FileInputStream in = new FileInputStream(srcFiles.get(i)); out.putNextEntry(new ZipEntry(path + filename)); int len; while((len=in.read(buf))>0){