|
|
@@ -6,9 +6,7 @@ package com.jeeplus.modules.workinvoice.web;
|
|
|
import com.google.common.base.Strings;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
-import com.jeeplus.common.bos.BOSClientUtil;
|
|
|
import com.jeeplus.common.config.Global;
|
|
|
-import com.jeeplus.common.json.AjaxJson;
|
|
|
import com.jeeplus.common.mapper.JsonMapper;
|
|
|
import com.jeeplus.common.oss.OSSClientUtil;
|
|
|
import com.jeeplus.common.persistence.Page;
|
|
|
@@ -17,17 +15,13 @@ import com.jeeplus.common.utils.MyBeanUtils;
|
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
|
import com.jeeplus.common.utils.excel.ExportExcel;
|
|
|
import com.jeeplus.common.utils.excel.ImportExcel;
|
|
|
-import com.jeeplus.common.utils.excel.entity.CellModel;
|
|
|
-import com.jeeplus.common.utils.excel.utils.ExcelUtilInvoice;
|
|
|
import com.jeeplus.common.web.BaseController;
|
|
|
import com.jeeplus.modules.act.entity.Act;
|
|
|
import com.jeeplus.modules.act.service.ActTaskService;
|
|
|
import com.jeeplus.modules.act.utils.ActUtils;
|
|
|
-import com.jeeplus.modules.oa.entity.OaNotify;
|
|
|
import com.jeeplus.modules.projectrecord.entity.ProjectRecords;
|
|
|
import com.jeeplus.modules.projectrecord.enums.ProjectStatusEnum;
|
|
|
import com.jeeplus.modules.projectrecord.service.ProjectRecordsService;
|
|
|
-import com.jeeplus.modules.ruralprojectrecords.entity.RuralProjectRecords;
|
|
|
import com.jeeplus.modules.ruralprojectrecords.service.RuralProjectRecordsService;
|
|
|
import com.jeeplus.modules.sys.entity.MainDictDetail;
|
|
|
import com.jeeplus.modules.sys.entity.Office;
|
|
|
@@ -48,12 +42,12 @@ import com.jeeplus.modules.workclientinfo.entity.WorkClientLinkman;
|
|
|
import com.jeeplus.modules.workclientinfo.service.WorkClientInfoService;
|
|
|
import com.jeeplus.modules.workcontractinfo.entity.WorkContractInfo;
|
|
|
import com.jeeplus.modules.workcontractinfo.service.WorkContractInfoService;
|
|
|
+import com.jeeplus.modules.workfullmanage.utils.ZipUtils;
|
|
|
import com.jeeplus.modules.workinvoice.entity.WorkInvoice;
|
|
|
import com.jeeplus.modules.workinvoice.entity.WorkInvoiceProjectRelation;
|
|
|
import com.jeeplus.modules.workinvoice.service.WorkInvoiceService;
|
|
|
import com.jeeplus.modules.workinvoicealter.entity.WorkInvoiceAlter;
|
|
|
import com.jeeplus.modules.workinvoicealter.service.WorkInvoiceAlterService;
|
|
|
-import com.jeeplus.modules.workinvoicedetail.dao.WorkInvoiceDetailDao;
|
|
|
import com.jeeplus.modules.workinvoicedetail.service.WorkInvoiceDetailService;
|
|
|
import com.jeeplus.modules.workproject.service.WorkProjectService;
|
|
|
import com.jeeplus.modules.workprojectnotify.entity.WorkProjectNotify;
|
|
|
@@ -63,9 +57,6 @@ import org.activiti.engine.TaskService;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
|
import org.activiti.engine.task.Task;
|
|
|
import org.apache.commons.beanutils.BeanUtils;
|
|
|
-import org.apache.poi.ss.usermodel.Sheet;
|
|
|
-import org.apache.poi.ss.usermodel.Workbook;
|
|
|
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.apache.shiro.authz.annotation.Logical;
|
|
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -82,6 +73,8 @@ import java.io.*;
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
import java.net.URLDecoder;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
|
@@ -1755,4 +1748,102 @@ public class WorkInvoiceController extends BaseController {
|
|
|
String path = year+"/"+month+"/"+day + "/";
|
|
|
return path;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目相应文件批量下载并压缩
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "exportInvoiceAll", method = {RequestMethod.GET, RequestMethod.POST}) // 新增POST支持
|
|
|
+ public void exportAll(HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
|
|
|
+ String listIds = request.getParameter("listId");
|
|
|
+ String showFlag = request.getParameter("showFlag");
|
|
|
+ // 空值校验:避免listIds为空时split报错
|
|
|
+ if (listIds == null || listIds.trim().isEmpty()) {
|
|
|
+ writeErrorResponse(response, "请选择需要下载的发票!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> idList = Arrays.asList(listIds.split(","));
|
|
|
+ String zipFilePath = null;
|
|
|
+ InputStream is = null;
|
|
|
+ OutputStream os = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
+ String timeStamp = sdf.format(new Date());
|
|
|
+ String fileName = "数电发票批量下载_" + timeStamp;
|
|
|
+
|
|
|
+ // 1. 调用Service生成ZIP文件
|
|
|
+ zipFilePath = workInvoiceService.exportInvoiceAll(idList, fileName);
|
|
|
+
|
|
|
+ // 2. 校验ZIP文件
|
|
|
+ File zipFile = new File(zipFilePath);
|
|
|
+ if (!zipFile.exists() || zipFile.length() == 0) {
|
|
|
+ throw new Exception("批量下载生成的ZIP文件不存在或为空:" + zipFilePath);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 成功:输出文件流(原有逻辑不变)
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/zip");
|
|
|
+ String zipFileName = URLEncoder.encode(fileName + ".zip", StandardCharsets.UTF_8.name())
|
|
|
+ .replace("+", "%20");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + zipFileName);
|
|
|
+ response.setHeader("Download-Status", "success"); // 新增:标记成功状态
|
|
|
+
|
|
|
+ // 读取并输出文件
|
|
|
+ is = new BufferedInputStream(new FileInputStream(zipFile));
|
|
|
+ os = new BufferedOutputStream(response.getOutputStream());
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int len;
|
|
|
+ while ((len = is.read(buffer)) != -1) {
|
|
|
+ os.write(buffer, 0, len);
|
|
|
+ }
|
|
|
+ os.flush();
|
|
|
+ logger.info("批量下载ZIP文件已返回给前端:{}", zipFileName);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 失败:返回JSON格式错误信息
|
|
|
+ logger.error("批量下载数电发票异常:", e);
|
|
|
+ writeErrorResponse(response, "批量下载失败:" + e.getMessage());
|
|
|
+ } finally {
|
|
|
+ // 关闭流 + 清理临时文件(原有逻辑不变)
|
|
|
+ try {
|
|
|
+ if (os != null) os.close();
|
|
|
+ if (is != null) is.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("关闭流失败!", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (zipFilePath != null) {
|
|
|
+ File zipFile = new File(zipFilePath);
|
|
|
+ if (zipFile.isFile() && zipFile.exists()) {
|
|
|
+ boolean zipDeleted = zipFile.delete();
|
|
|
+ logger.info("ZIP文件删除{}:{}", zipDeleted ? "成功" : "失败", zipFile.getAbsolutePath());
|
|
|
+ }
|
|
|
+ String tempDirPath = zipFilePath.replace(".zip", "");
|
|
|
+ File tempDirFile = new File(tempDirPath);
|
|
|
+ if (tempDirFile.exists()) {
|
|
|
+ ZipUtils.deleteFolder(tempDirFile);
|
|
|
+ logger.info("批量下载临时文件夹已删除:{}", tempDirPath);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统一写入错误响应(JSON格式)
|
|
|
+ */
|
|
|
+ private void writeErrorResponse(HttpServletResponse response, String message) {
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/json;charset=UTF-8"); // 改为JSON格式
|
|
|
+ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
|
|
+ try {
|
|
|
+ // 输出标准JSON,方便前端解析
|
|
|
+ String errorJson = "{\"code\":500,\"msg\":\"" + message.replace("\"", "\\\"") + "\"}";
|
|
|
+ response.getWriter().write(errorJson);
|
|
|
+ } catch (IOException ioException) {
|
|
|
+ logger.error("响应错误信息失败!", ioException);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|