Pārlūkot izejas kodu

试验检测文件下载

lvy 1 dienu atpakaļ
vecāks
revīzija
90de6343d0

+ 7 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/TrialSelfInspectionRecord.java

@@ -92,4 +92,11 @@ public class TrialSelfInspectionRecord extends BaseEntity {
     @ApiModelProperty("基础信息")
     private String baseInfo;
 
+    @ApiModelProperty("记录表pdf")
+    private String recordPdfUrl;
+
+    @ApiModelProperty("报告表pdf")
+    private String reportPdfUrl;
+
+
 }

+ 15 - 0
blade-service/blade-business/src/main/java/org/springblade/business/controller/TrialDetectionController.java

@@ -45,6 +45,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -850,4 +851,18 @@ public class TrialDetectionController extends BladeController {
         iTrialSelfInspectionRecordService.updateSort(dto);
         return R.success("成功");
     }
+
+    /**
+     * pdf文件下载
+     * @param ids 试验记录ids
+     * @param classify 1 施工、2 监理、3业主
+     * @param type 1 整份下载,2 报告表下载,3 记录表下载,4 委托单下载
+     * @param response 响应
+     */
+    @PostMapping("/self/download")
+    @ApiOperationSupport(order = 31)
+    @ApiOperation(value = "pdf文件下载", notes = "传入记录ids,classify:1 施工、2 监理、3业主, type:1 整份下载、2 报告表下载、3 记录表下载、4 委托单下载")
+    public void download(@RequestParam String ids, @RequestParam Integer classify, @RequestParam Integer type, HttpServletResponse response) {
+        iTrialSelfInspectionRecordService.download(ids, classify, type, response);
+    }
 }

+ 3 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/ITrialSelfInspectionRecordService.java

@@ -9,6 +9,7 @@ import org.springblade.core.secure.BladeUser;
 import org.springblade.core.tool.api.R;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.FileNotFoundException;
 import java.util.List;
 
@@ -50,4 +51,6 @@ public interface ITrialSelfInspectionRecordService extends BaseService<TrialSelf
     Long saveBaseInfo(TrialSeleInspectionRecordInfoDTO vo);
 
     void updateSort(TrialSelfInspectionRecordPageDTO dto);
+
+    void download(String ids, Integer classify, Integer type, HttpServletResponse response);
 }

+ 67 - 0
blade-service/blade-business/src/main/java/org/springblade/business/service/impl/TrialSelfInspectionRecordServiceImpl.java

@@ -68,6 +68,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.InputStream;
@@ -2569,4 +2570,70 @@ public class TrialSelfInspectionRecordServiceImpl extends BaseServiceImpl<TrialS
         }
         return result;
     }
+    @Override
+    public void download(String ids, Integer classify, Integer type, HttpServletResponse response) {
+        List<TrialSelfInspectionRecord> recordList = baseMapper.selectList(Wrappers.<TrialSelfInspectionRecord>lambdaQuery().in(TrialSelfInspectionRecord::getId, Func.toLongList(ids)));
+//                .eq(TrialSelfInspectionRecord::getTaskStatus, "已审批"));
+        if (recordList.isEmpty()) {
+            throw new ServiceException("请选择已审批的记录");
+        }
+        List<String> pdfList = null;
+        List<String> deletedFileUrls = new ArrayList<>();
+        //打包下载
+        try {
+            if (type == 1) {
+                // 整份下载
+                List<String> tempUrls = new ArrayList<>();
+                recordList.forEach(record -> {
+                    //合并的pdfUrl
+                    try {
+                        String pdf = this.getMergePdfToTrialNew(record.getContractId(), record.getId(), classify);
+                        if (StringUtil.hasText(pdf)) {
+                            tempUrls.add(pdf + "@@@" + record.getRecordNo().replaceAll("\\\\", "_").replaceAll("/", "_"));
+                            deletedFileUrls.add(pdf);
+                        }
+                    } catch (FileNotFoundException e) {
+                        e.printStackTrace();
+                    }
+                });
+                pdfList = tempUrls;
+            } else if (type == 2) {
+                // 报告表下载
+                pdfList = recordList.stream().filter(item -> StringUtil.hasText(item.getReportPdfUrl())).map(item -> item.getReportPdfUrl() + "@@@" + item.getReportNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
+            } else if (type == 3) {
+                // 记录表下载
+                pdfList = recordList.stream().filter(item -> StringUtil.hasText(item.getRecordPdfUrl())).map(item -> item.getRecordPdfUrl() + "@@@" + item.getRecordNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
+            } else if (type == 4) {
+                // 委托单下载
+                Set<Long> entrustIds = recordList.stream().filter(record -> record.getEntrustId() != null && record.getEntrustId() > 0).map(TrialSelfInspectionRecord::getEntrustId).collect(Collectors.toSet());
+                if (entrustIds.isEmpty()) {
+                    throw new ServiceException("未找到委托单记录");
+                }
+                List<EntrustInfo> entrustInfoList = entrustInfoService.listByIds(entrustIds);
+                pdfList = entrustInfoList.stream().filter(item -> item.getEntrustEPdf() != null && StringUtil.hasText(item.getEntrustEPdf()))
+                        .map(item -> item.getEntrustEPdf() + "@@@" + item.getEntrustNo().replaceAll("\\\\", "_").replaceAll("/", "_")).collect(Collectors.toList());
+            }
+            if (pdfList == null || pdfList.isEmpty()) {
+                if (type == 1) {
+                    throw new ServiceException("未找到试验自检记录的pdf");
+                } else if (type == 2) {
+                    throw new ServiceException("未找到报告表pdf");
+                } else if (type == 3) {
+                    throw new ServiceException("未找到记录表pdf");
+                } else if (type == 4) {
+                    throw new ServiceException("未找到委托单pdf");
+                } else {
+                    throw new ServiceException("未找到pdf");
+                }
+            }
+            FileUtils.batchDownloadFileToZip(pdfList, response);
+        } catch (Exception e)  {
+            e.printStackTrace();
+        } finally {
+            if (!deletedFileUrls.isEmpty()) {
+                newIOSSClient.removeFiles(deletedFileUrls);
+            }
+        }
+    }
+
 }