liuling hace 9 meses
padre
commit
6ba71e4334

+ 71 - 5
web/com/kingdee/custom/shengshen/handle/EntryRegistrationHandle.java

@@ -1,14 +1,80 @@
 package com.kingdee.eas.custom.shengshen.handle;
 
-import com.kingdee.shr.base.syssetting.web.handler.ListHandler;
+import com.kingdee.bos.BOSException;
+import com.kingdee.eas.custom.shengshen.utils.HttpClient3;
+import com.kingdee.eas.custom.shengshen.utils.PDFFillInformationUtil;
+import com.kingdee.shr.affair.web.handler.hrman.EmpEnrollBizBillHrManListHandler;
+import com.kingdee.shr.base.syssetting.exception.SHRWebException;
+import com.kingdee.shr.base.syssetting.web.dynamic.util.DynamicUtil;
+import com.kingdee.shr.base.syssetting.web.util.UserUtil;
+import org.apache.commons.io.FileUtils;
 import org.springframework.ui.ModelMap;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
+import java.util.zip.GZIPOutputStream;
 
-public class EntryRegistrationHandle extends ListHandler {
-    public String getRegisterFileAtion(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
-
-        return null;
+public class EntryRegistrationHandle extends EmpEnrollBizBillHrManListHandler {
+    public void getRegisterFileAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap)  throws SHRWebException{
+        //填充数据
+        List<Map<String,String>> dataList = new ArrayList<Map<String,String>>();
+        Map<String,String> dataMap = new HashMap<String,String>();
+        dataMap.put("topmostSubform[0].Page1[0].topmostSubform_0_\\.Page1_0_\\.TextField1_3_[0]", "Data1");
+        dataMap.put("topmostSubform[0].Page1[0].topmostSubform_0_\\.Page1_0_\\.TextField1_0_[0]", "Data2");
+        String url = "http://169.254.157.139:6888/easWebClient/download/DSF_Mod_373.pdf";
+        dataList.add(dataMap);
+        PDFFillInformationUtil pdfFillInformationUtil = new PDFFillInformationUtil();
+        //填充后的文件
+        List<File> list = new ArrayList<>();
+        long time = new Date().getTime();
+        //获取当前登入人的 临时存储地址
+        String userTempDirAbsolutePath = UserUtil.getUserTempDirAbsolutePath(request.getSession());
+        String tempFilePath = userTempDirAbsolutePath + File.separator + time + File.separator;
+        //压缩文件名
+        String zipName = time + File.separator + "personDocument.zip";
+        String zipPath = UserUtil.getUserTempDirAbsolutePath(request.getSession()) + File.separator + zipName;
+        //判断路径是否存在 如果没有创建
+        File userTempDirAbsolute = new File(userTempDirAbsolutePath);
+        if (!userTempDirAbsolute.exists()) {
+            userTempDirAbsolute.mkdir();
+        }
+        //判断路径是否存在 如果没有创建
+        File tempFile = new File(tempFilePath);
+        if (!tempFile.exists()) {
+            tempFile.mkdir();
+        }
+        String fileName = "刘颖";
+        try {
+            byte[] bytesByNetURL = HttpClient3.getBytesByNetURL(url);
+            for (int i = 0; i < dataList.size(); i++) {
+                File file = pdfFillInformationUtil.fillInformation(bytesByNetURL, dataList.get(i),tempFilePath,fileName+i+".pdf");
+                list.add(file);
+            }
+            //创建压缩文件
+            PDFFillInformationUtil.compress(zipPath, list);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        } catch (BOSException e) {
+            throw new RuntimeException(e);
+        }finally {
+            //删除源文件
+            for (int i = 0; i < list.size(); i++) {
+                FileUtils.deleteQuietly(list.get(i));
+            }
+        }
+        Map<String, String> param = new HashMap<String, String>();
+        param.put("method", "tmp");
+        param.put("file", zipName);
+        param.put("filename", "员工档案.zip");
+        String link = DynamicUtil.assembleUrl("/shr/downloadfile.do", param).replaceAll("\\+", "%20");
+        try {
+            this.writeSuccessData(link);
+        } catch (SHRWebException e) {
+            throw new RuntimeException(e);
+        }
     }
 }

+ 41 - 7
web/com/kingdee/custom/shengshen/utils/PDFFillInformationUtil.java

@@ -3,27 +3,31 @@ package com.kingdee.eas.custom.shengshen.utils;
 import com.itextpdf.text.pdf.AcroFields;
 import com.itextpdf.text.pdf.PdfReader;
 import com.itextpdf.text.pdf.PdfStamper;
+import com.kingdee.bos.BOSException;
+import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.exception.ZipException;
+import net.lingala.zip4j.model.ZipParameters;
 
 import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 public class PDFFillInformationUtil {
     /**
      * 给pdf填充数据
-     * @param fileName 原始文件
+     * @param file 原始文件
      * @param field map<String,String> key 为字段名,value 为填充值
      * @return 填充后的文件  文件类型为byte[]
      */
-    public byte[] fillInformation(String fileName, Map<String,String> field) throws IOException {
-        //http://169.254.157.139:6888/easWebClient/download/DSF_Mod_373.pdf
-        String url = "http://169.254.157.139:6888/easWebClient/download/"+fileName;
-        byte[] bytesByNetURL = HttpClient3.getBytesByNetURL(url);
+    public File fillInformation(byte[] file, Map<String,String> field,String tempFilePath,String fileName) throws IOException {
         try {
             System.setProperty("javax.xml.parsers.DocumentBuilderFactory","com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
             // 读取PDF模板
-            PdfReader pdfReader = new PdfReader(bytesByNetURL);
+            PdfReader pdfReader = new PdfReader(file);
             ByteArrayOutputStream baos = new ByteArrayOutputStream();
             // 创建需就改PDF文件
             PdfStamper pdfStamper = new PdfStamper(pdfReader, baos);
@@ -42,10 +46,40 @@ public class PDFFillInformationUtil {
             // 关闭修改器,并释放资源
             pdfStamper.close();
             pdfReader.close();
-            return  baos.toByteArray();
+            File outFile = new File(tempFilePath+"/"+fileName);
+            if (!outFile.createNewFile()) {
+                throw new RuntimeException("pdf 填充数据失败!!");
+            }
+            FileOutputStream fos = new FileOutputStream(outFile);
+            baos.writeTo(fos);
+            fos.close(); // 关闭流释放资源
+            return  outFile;
         } catch (Exception e) {
             e.printStackTrace();
             throw new RuntimeException("pdf 填充数据失败!!");
         }
     }
+    /**
+     * 创建压缩包
+     *
+     * @param destFileName
+     * @param files
+     * @return
+     */
+    public static String compress(String destFileName, List<File> files) throws BOSException {
+        ZipParameters parameters = new ZipParameters();
+        parameters.setCompressionMethod(8);
+        parameters.setCompressionLevel(5);
+        try {
+            ZipFile zipFile = new ZipFile(destFileName);
+            for (int i = 0; i < files.size(); ++i) {
+                File file = files.get(i);
+                zipFile.addFile(file, parameters);
+            }
+            return destFileName;
+        } catch (ZipException var9) {
+            var9.printStackTrace();
+            throw new BOSException(var9.getMessage());
+        }
+    }
 }