数智-合同附件批量下载

shuzhi
dxfeng 2 years ago
parent dc31a6d9a8
commit e6cf968e0f

@ -10,5 +10,20 @@ import java.util.Map;
*/
public interface SzBatchExportService {
Map<String,Object> downloadResourceFile(List<Long> idList);
/**
*
*
* @param idList ID
* @return
*/
Map<String, Object> downloadResourceFile(List<Long> idList);
/**
*
*
* @param idList ID
* @return
*/
Map<String, Object> downloadContractFile(List<Long> idList);
}

@ -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<String, Object> downloadContractFile(List<Long> idList) {
Map<String, Object> 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 fileIdb.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);

@ -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<Long> 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<String, Object> 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();
}
}

Loading…
Cancel
Save