From e6cf968e0f5a473ede38da9e977ac9ffac17556a Mon Sep 17 00:00:00 2001 From: dxfeng Date: Mon, 5 Jun 2023 14:52:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=99=BA-=E5=90=88=E5=90=8C=E9=99=84?= =?UTF-8?q?=E4=BB=B6=E6=89=B9=E9=87=8F=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shuzhi/service/SzBatchExportService.java | 17 ++++- .../impl/SzBatchExportServiceImpl.java | 72 ++++++++++++++++++- .../shuzhi/web/SzBatchExportController.java | 30 ++++++++ 3 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/com/engine/shuzhi/service/SzBatchExportService.java b/src/com/engine/shuzhi/service/SzBatchExportService.java index edd98c0..0290feb 100644 --- a/src/com/engine/shuzhi/service/SzBatchExportService.java +++ b/src/com/engine/shuzhi/service/SzBatchExportService.java @@ -10,5 +10,20 @@ import java.util.Map; */ public interface SzBatchExportService { - Map downloadResourceFile(List idList); + /** + * 下载人员附件 + * + * @param idList 所选人员ID + * @return 文件名称、文件路径 + */ + Map downloadResourceFile(List idList); + + /** + * 下载合同附件 + * + * @param idList 所选记录ID + * @return 文件名称、文件路径 + */ + Map downloadContractFile(List idList); + } diff --git a/src/com/engine/shuzhi/service/impl/SzBatchExportServiceImpl.java b/src/com/engine/shuzhi/service/impl/SzBatchExportServiceImpl.java index 4d5a678..0250f6a 100644 --- a/src/com/engine/shuzhi/service/impl/SzBatchExportServiceImpl.java +++ b/src/com/engine/shuzhi/service/impl/SzBatchExportServiceImpl.java @@ -12,9 +12,10 @@ import weaver.general.GCONST; import weaver.general.Util; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.time.LocalDate; import java.util.HashMap; import java.util.List; @@ -34,6 +35,7 @@ public class SzBatchExportServiceImpl extends Service implements SzBatchExportSe if (CollectionUtils.isEmpty(idList)) { throw new CustomizeRunTimeException("未选择需要下载的人员信息"); } + // 身份证复印件+日期 String zipFilename = "身份证复印件" + LocalDate.now() + ".zip"; String outPutPath = GCONST.getRootPath() + "filesystem" + File.separator + "downloadBatchTemp"; @@ -47,7 +49,7 @@ public class SzBatchExportServiceImpl extends Service implements SzBatchExportSe try { RecordSet rs = new RecordSet(); String sql = "select a.lastname ,a.workcode ,b.field0 as fileId from HrmResource a inner join cus_fielddata b on a.id =b.id and b.scopeid =3 and a.id = ? "; - ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(outPutPath)); + ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(Paths.get(outPutPath))); byte[] buffer = new byte[1024]; for (Long userId : idList) { String fileId = ""; @@ -65,7 +67,71 @@ public class SzBatchExportServiceImpl extends Service implements SzBatchExportSe manager.getImageFileInfoById(Util.getIntValue(file)); manager.getImageFileType(); InputStream inputStream = manager.getInputStream(); - zipOutputStream.putNextEntry(new ZipEntry(lastname + "-" + workcode + "(身份证)" + getFileSuffix(manager.getImageFileName()))); + // 姓名+工号(身份证) + zipOutputStream.putNextEntry(new ZipEntry(lastname + workcode + getFileSuffix(manager.getImageFileName()))); + int length; + while ((length = inputStream.read(buffer)) > 0) { + zipOutputStream.write(buffer, 0, length); + } + inputStream.close(); + zipOutputStream.closeEntry(); + } + + } + + } + zipOutputStream.close(); + returnMap.put("zipFilename", zipFilename); + returnMap.put("outPutPath", outPutPath); + } catch (IOException e) { + new BaseBean().writeLog(e); + throw new CustomizeRunTimeException(e); + } + return returnMap; + } + + @Override + public Map downloadContractFile(List idList) { + Map returnMap = new HashMap<>(2); + if (CollectionUtils.isEmpty(idList)) { + throw new CustomizeRunTimeException("未选择需要下载的人员信息"); + } + + // 合同附件+日期 + String zipFilename = "合同附件" + LocalDate.now() + ".zip"; + + String outPutPath = GCONST.getRootPath() + "filesystem" + File.separator + "downloadBatchTemp"; + File outPut = new File(outPutPath); + if (!outPut.exists() && !outPut.isDirectory()) { + outPut.mkdir(); + } + outPutPath += File.separator + zipFilename; + + try { + RecordSet rs = new RecordSet(); + String sql = "select a.lastname ,a.workcode ,b.fj as fileId,b.htksrq from HrmResource a inner join uf_ygqdhtbd b on a.id =b.xm where b.id = ?"; + ZipOutputStream zipOutputStream = new ZipOutputStream(Files.newOutputStream(Paths.get(outPutPath))); + byte[] buffer = new byte[1024]; + for (Long id : idList) { + String fileId = ""; + String lastname = ""; + String workcode = ""; + String htksrq = ""; + rs.executeQuery(sql, id); + if (rs.next()) { + fileId = rs.getString("fileId"); + lastname = rs.getString("lastname"); + workcode = rs.getString("workcode"); + htksrq = rs.getString("htksrq"); + } + if (StringUtils.isNotBlank(fileId)) { + for (String file : fileId.split(",")) { + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(file)); + manager.getImageFileType(); + InputStream inputStream = manager.getInputStream(); + // 姓名+工号+开始日期(合同) + zipOutputStream.putNextEntry(new ZipEntry(lastname + workcode + htksrq + getFileSuffix(manager.getImageFileName()))); int length; while ((length = inputStream.read(buffer)) > 0) { zipOutputStream.write(buffer, 0, length); diff --git a/src/com/engine/shuzhi/web/SzBatchExportController.java b/src/com/engine/shuzhi/web/SzBatchExportController.java index 30aba48..1d72364 100644 --- a/src/com/engine/shuzhi/web/SzBatchExportController.java +++ b/src/com/engine/shuzhi/web/SzBatchExportController.java @@ -69,5 +69,35 @@ public class SzBatchExportController { return Response.ok(output).header("Content-disposition", "attachment;filename=" + zipFilename).header("Cache-Control", "no-cache").build(); } + @GET + @Path("/contract/export") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response contractExport(@Context HttpServletRequest request, @Context HttpServletResponse response, + @QueryParam("ids") String ids) { + List idList = new ArrayList<>(); + if (StringUtils.isNotBlank(ids)) { + idList = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList()); + } + User user = HrmUserVarify.getUser(request, response); + + Map map = getService(user).downloadContractFile(idList); + String zipFilename = Util.null2String(map.get("zipFilename")); + String outPutPath = Util.null2String(map.get("outPutPath")); + try { + zipFilename = URLEncoder.encode(zipFilename, "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + + java.nio.file.Path path = Paths.get(outPutPath); + StreamingOutput output = outputStream -> { + byte[] data = Files.readAllBytes(path); + outputStream.write(data); + outputStream.flush(); + }; + response.setContentType("application/octet-stream"); + return Response.ok(output).header("Content-disposition", "attachment;filename=" + zipFilename).header("Cache-Control", "no-cache").build(); + } + }