PatentInstructionController.java 3.9 KB

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