PatentInstructionController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package cn.cslg.pas.controller;
  2. import cn.cslg.pas.common.AAA;
  3. import cn.cslg.pas.common.core.annotation.Permission;
  4. import cn.cslg.pas.common.core.base.Constants;
  5. import cn.cslg.pas.common.model.vo.PatentInstructionVO;
  6. import cn.cslg.pas.common.utils.FileUtils;
  7. import cn.cslg.pas.common.utils.Response;
  8. import cn.cslg.pas.common.utils.SecurityUtils.LoginUtils;
  9. import cn.cslg.pas.common.utils.auth.checkAuth;
  10. import cn.cslg.pas.domain.PatentInstruction;
  11. import cn.cslg.pas.service.PatentInstructionService;
  12. import cn.cslg.pas.service.patentPDF.PatentPDFService;
  13. import cn.hutool.core.io.FileUtil;
  14. import cn.hutool.core.io.IoUtil;
  15. import io.swagger.v3.oas.annotations.Operation;
  16. import io.swagger.v3.oas.annotations.tags.Tag;
  17. import lombok.RequiredArgsConstructor;
  18. import org.springframework.context.annotation.Lazy;
  19. import org.springframework.web.bind.annotation.*;
  20. import org.springframework.web.multipart.MultipartFile;
  21. import javax.servlet.ServletOutputStream;
  22. import javax.servlet.http.HttpServletResponse;
  23. import java.io.IOException;
  24. import java.util.List;
  25. /**
  26. * <p>
  27. * 专利说明书 前端控制器
  28. * </p>
  29. *
  30. * @author 王岩
  31. * @since 2022-03-02
  32. */
  33. @Tag(name = "专利说明书")
  34. @RestController
  35. @RequestMapping(Constants.API_VERSION_V2 + "/patent/instruction")
  36. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  37. public class PatentInstructionController {
  38. private final PatentInstructionService patentInstructionService;
  39. private final PatentPDFService patentPDFService;
  40. private final FileUtils fileUtils;
  41. private final LoginUtils loginUtils;
  42. @GetMapping("list")
  43. @Operation(summary = "说明书列表")
  44. public String getPageList(PatentInstructionVO params) {
  45. return Response.success(patentInstructionService.getPageList(params));
  46. }
  47. @checkAuth(FunId = "/workspace/folder/batchUploadSpecification")
  48. @PostMapping("/batch/upload")
  49. @Operation(summary = "批量上传说明书")
  50. public String batchUpload(String url, Integer type, String remark) throws IOException {
  51. patentInstructionService.batchUpload(url, type, remark, loginUtils.getId());
  52. return Response.success(true);
  53. }
  54. @Permission(roles = {1, 2})
  55. @PostMapping("add")
  56. @Operation(summary = "新增说明书")
  57. public String add(MultipartFile file, PatentInstruction patentInstruction) {
  58. return patentInstructionService.add(file, patentInstruction);
  59. }
  60. @checkAuth(FunId = "/workspace/details/updataInstruction")
  61. @PostMapping("edit")
  62. @Operation(summary = "编辑说明书")
  63. public String edit(MultipartFile file, PatentInstruction patentInstruction) {
  64. return patentInstructionService.edit(file, patentInstruction);
  65. }
  66. @Permission(roles = {1, 2})
  67. @PostMapping("delete")
  68. @Operation(summary = "删除说明书")
  69. public String delete(Integer id) {
  70. return patentInstructionService.delete(id);
  71. }
  72. @PostMapping("file")
  73. @Operation(summary = "获取说明书文件流")
  74. public void pdfFile(String patentNo, Integer type, HttpServletResponse response) {
  75. try {
  76. PatentInstruction patentInstruction = patentInstructionService.getPatentInstructionByPatentNoAndType(patentNo, type);
  77. if (patentInstruction != null) {
  78. response.setHeader("Content-Disposition", "attachment;filename=" + patentInstruction.getFileName());
  79. ServletOutputStream out = response.getOutputStream();
  80. // out.write(FileUtil.readBytes(fileUtils.getSystemPath(patentInstruction.getUrl())));
  81. String fil = fileUtils.getSystemPath() + patentInstruction.getUrl();
  82. out.write(FileUtil.readBytes(fil));
  83. IoUtil.close(out);
  84. }
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. }
  89. @PostMapping("/pdfFirstPage")
  90. @Operation(summary = "获取说明书首页")
  91. public void pdfFileFirstPage(@RequestBody AAA aaa) throws IOException {
  92. patentPDFService.queryPatentPdfFirstPages(aaa.getPatentNos());
  93. }
  94. }