SealController.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.ymwk.icvp.signature.controller;
  2. import com.ymwk.icvp.component.PageResult;
  3. import com.ymwk.icvp.component.ResponseDTO;
  4. import com.ymwk.icvp.signature.entity.Picture;
  5. import com.ymwk.icvp.signature.entity.Seal;
  6. import com.ymwk.icvp.signature.model.*;
  7. import com.ymwk.icvp.signature.service.SealService;
  8. import lombok.RequiredArgsConstructor;
  9. import org.springframework.http.HttpStatus;
  10. import org.springframework.http.MediaType;
  11. import org.springframework.http.ResponseEntity;
  12. import org.springframework.validation.annotation.Validated;
  13. import org.springframework.web.bind.annotation.*;
  14. @RestController
  15. @RequestMapping("/api/v1/seal")
  16. @RequiredArgsConstructor
  17. public class SealController {
  18. private final SealService sealService;
  19. /**
  20. * 印章列表(条件查询)
  21. */
  22. @PostMapping("/list")
  23. public ResponseDTO<PageResult<Seal>> list(@RequestBody SealQueryDTO queryDTO) {
  24. return sealService.pageSeal(queryDTO);
  25. }
  26. /**
  27. * 印章详情
  28. */
  29. @GetMapping("/detail/{id}")
  30. public ResponseDTO<Seal> detail(@PathVariable Long id) {
  31. return sealService.getSealDetail(id);
  32. }
  33. /**
  34. * 生成印章
  35. */
  36. @PostMapping("/create")
  37. public ResponseDTO<Long> create(@Validated @RequestBody SealCreateDTO createDTO) {
  38. return sealService.createSeal(createDTO);
  39. }
  40. /**
  41. * 冻结印章
  42. */
  43. @PostMapping("/freeze/{id}")
  44. public ResponseDTO<Void> freeze(@PathVariable Long id) {
  45. return sealService.freeze(id);
  46. }
  47. /**
  48. * 解冻印章
  49. */
  50. @PostMapping("/unfreeze/{id}")
  51. public ResponseDTO<Void> unfreeze(@PathVariable Long id) {
  52. return sealService.unfreeze(id);
  53. }
  54. /**
  55. * 销毁印章
  56. */
  57. @PostMapping("/destroy/{id}")
  58. public ResponseDTO<Void> destroy(@PathVariable Long id) {
  59. return sealService.destroy(id);
  60. }
  61. /**
  62. * 印章延期
  63. */
  64. @PostMapping("/extend")
  65. public ResponseDTO<Void> extend(@Validated @RequestBody SealExtendDTO extendDTO) {
  66. return sealService.extend(extendDTO);
  67. }
  68. /**
  69. * 绑定/换绑证书
  70. */
  71. @PostMapping("/bindCert")
  72. public ResponseDTO<Void> bindCert(@Validated @RequestBody SealBindCertDTO bindCertDTO) {
  73. return sealService.bindCert(bindCertDTO);
  74. }
  75. /**
  76. * 印章有效性验证
  77. */
  78. @PostMapping("/verify/{id}")
  79. public ResponseDTO<Boolean> verify(@PathVariable Long id) {
  80. return sealService.verify(id);
  81. }
  82. /**
  83. * 下载印章文件:SM2 返回 ESL,RSA 返回包含印模和证书的 ZIP
  84. */
  85. @GetMapping("/download/{id}")
  86. public ResponseEntity<?> download(@PathVariable Long id) {
  87. ResponseDTO<SealDownload> result = sealService.download(id);
  88. if (!Integer.valueOf(ResponseDTO.OK_CODE).equals(result.getCode())
  89. || result.getData() == null) {
  90. return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(result);
  91. }
  92. SealDownload download = result.getData();
  93. return ResponseEntity.ok()
  94. .header("Content-Disposition", "attachment; filename=\"" + download.getFileName() + "\"")
  95. .contentType(MediaType.parseMediaType(download.getContentType()))
  96. .body(download.getData());
  97. }
  98. }