郑永安
2023-09-04 bbb1b74f122affa814224dd2c9e5fb4ddcfcbe5a
src/main/java/com/gk/hotwork/Controller/SafetyFacilityInspectionController.java
@@ -253,7 +253,8 @@
         @ApiImplicitParam(name = "expert", value = "审查专家", required = false),
         @ApiImplicitParam(name = "contact", value = "联系人", required = false),
         @ApiImplicitParam(name = "telephone", value = "联系电话", required = false),
         @ApiImplicitParam(name = "company", value = "企业名称", required = false) })
         @ApiImplicitParam(name = "company", value = "企业名称", required = false),
         @ApiImplicitParam(name = "acceptpdf", value = "受理通知书PDF", required = false) })
   public Msg add(@RequestBody SafetyFacilityInspection param) {
      String genId = LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli() + "" + (int) (Math.random() * 900 + 100);
      param.setId(Long.valueOf(genId));
@@ -264,7 +265,7 @@
      flow.setCheckTime(date);
      flow.setProgressName("资料提交");
      flow.setResult("资料提交");
      flow.setResolution("开始");
      flow.setResolution(param.getAcceptpdf());
      flow.setLinkInspectionId(Long.valueOf(genId));
      flow.setProcessBy(this.getUser().getRealname());
      safetyFacilityProcessflowService.addOne(flow, this.getUser());
@@ -511,6 +512,71 @@
   }
   @ApiOperation("企业上传受理通知书")
   @PostMapping("/uploadAcceptpdf")
   @ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "企业上传受理通知书(PDF/图片)") })
   public Msg uploadAcceptpdf(HttpServletRequest request, @RequestParam("file") MultipartFile file) {
      if (file.getSize() > 1024 * 1024 * 10) {
         return failed("文件超过10M无法上传");
      }
      String path = filePathConfig.getModule().get("correctPDF");
      String dcPath = filePathConfig.getDcPath();
      String originalFilename = file.getOriginalFilename();
      LocalDateTime now = LocalDateTime.now();
      File newFile = null;
      try {
         String key = UUID.randomUUID().toString().replace("-", "");
         String suffix = originalFilename.substring(originalFilename.lastIndexOf(".")).toLowerCase();
         path = path.replace("/", File.separator);
         String modulePath = now.getYear() + path + now.format(DateTimeFormatter.ofPattern("MMdd"));
         String newFilePath = modulePath + File.separator + key + suffix;
         String localPath = dcPath + newFilePath;
         newFile = new File(localPath);
         if (!newFile.exists() && !newFile.mkdirs()) {
            return failed("文件上传路径不存在!");
         }
         file.transferTo(newFile);
         return success(newFilePath);
      } catch (IOException e) {
         if (newFile != null && newFile.exists()) {
            newFile.delete();
         }
         return failed("文件上传异常!");
      }
   }
   @ApiOperation("查看企业受理通知书")
   @PostMapping("/downAcceptpdf")
   @ApiImplicitParams({ @ApiImplicitParam(name = "filename", value = "企业受理通知书文件名", required = true)})
   public void downAcceptpdf(@RequestBody FilterObject filterObject, HttpServletResponse response) throws Exception {
      if (filterObject.getFilter().get("filename") == null)
         return;
      String filepath = filterObject.getFilter().get("filename").toString();
      String suffix = filepath.substring(filepath.lastIndexOf(".")).toLowerCase();
      response.reset();
      response.addHeader("Access-Control-Allow-Origin", "*");
      response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
      response.setContentType("application/octet-stream; charset=UTF-8");
      response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + URLEncoder.encode("企业受理通知书" + suffix, StandardCharsets.UTF_8.name()));
      response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
      String dcPath = filePathConfig.getDcPath();
      File file = new File(dcPath + filepath);
      if (!file.exists()) {
         throw new BusinessException(ResultCodes.FILE_NOT_EXISIST);
      }
      response.addHeader("Content-Length", "" + file.length());
      FileInputStream inputStream = new FileInputStream(file);
      byte[] b = new byte[inputStream.available()];
      inputStream.read(b);
      ServletOutputStream outputStream = response.getOutputStream();
      outputStream.write(b);
      outputStream.flush();
      inputStream.close();
   }
   @ApiOperation("专家审查上传补正告知书")
   @PostMapping("/uploadCorrectPDF")
   @ApiImplicitParams({ @ApiImplicitParam(name = "file", value = "上传补正告知书(PDF)文件") })