IdentityAuthController.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.izouma.nineth.web;
  2. import com.izouma.nineth.domain.IdentityAuth;
  3. import com.izouma.nineth.domain.User;
  4. import com.izouma.nineth.dto.PageQuery;
  5. import com.izouma.nineth.enums.AuthStatus;
  6. import com.izouma.nineth.exception.BusinessException;
  7. import com.izouma.nineth.repo.IdentityAuthRepo;
  8. import com.izouma.nineth.service.IdentityAuthService;
  9. import com.izouma.nineth.utils.SecurityUtils;
  10. import com.izouma.nineth.utils.excel.ExcelUtils;
  11. import io.swagger.annotations.ApiOperation;
  12. import lombok.AllArgsConstructor;
  13. import org.springframework.data.domain.Page;
  14. import org.springframework.security.access.prepost.PreAuthorize;
  15. import org.springframework.web.bind.annotation.*;
  16. import javax.servlet.http.HttpServletResponse;
  17. import java.io.IOException;
  18. import java.util.List;
  19. import java.util.Map;
  20. @RestController
  21. @RequestMapping("/identityAuth")
  22. @AllArgsConstructor
  23. public class IdentityAuthController extends BaseController {
  24. private IdentityAuthService identityAuthService;
  25. private IdentityAuthRepo identityAuthRepo;
  26. // @PreAuthorize("hasAnyRole('ADMIN','OPERATOR')")
  27. @PostMapping("/all")
  28. public Page<IdentityAuth> all(@RequestBody PageQuery pageQuery) {
  29. return identityAuthService.all(pageQuery);
  30. }
  31. @PreAuthorize("hasRole('ADMIN')")
  32. @GetMapping("/get/{id}")
  33. public IdentityAuth get(@PathVariable Long id) {
  34. return identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  35. }
  36. @PreAuthorize("hasRole('ADMIN')")
  37. @PostMapping("/del/{id}")
  38. public void del(@PathVariable Long id) {
  39. identityAuthRepo.softDelete(id);
  40. }
  41. @PreAuthorize("hasRole('ADMIN')")
  42. @GetMapping("/excel")
  43. @ResponseBody
  44. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  45. List<IdentityAuth> data = all(pageQuery).getContent();
  46. ExcelUtils.export(response, data);
  47. }
  48. @PostMapping("/apply")
  49. public void apply(IdentityAuth identityAuth) {
  50. identityAuth.setUserId(SecurityUtils.getAuthenticatedUser().getId());
  51. identityAuthService.apply(identityAuth);
  52. }
  53. @PreAuthorize("hasAnyRole('ADMIN', 'OPERATOR')")
  54. @PostMapping("/pass")
  55. public void audit(@RequestParam Long id) {
  56. identityAuthService.audit(id, AuthStatus.SUCCESS, null);
  57. }
  58. @PreAuthorize("hasAnyRole('ADMIN', 'OPERATOR')")
  59. @PostMapping("/deny")
  60. public void deny(@RequestParam Long id, @RequestParam(required = false) String reason) {
  61. identityAuthService.audit(id, AuthStatus.FAIL, reason);
  62. }
  63. @ApiOperation("查找重复身份证")
  64. @PostMapping("/repeat")
  65. public List<User> repeat(@RequestParam String idNo, @RequestParam Long userId) {
  66. return identityAuthService.repeat(idNo, userId);
  67. }
  68. @GetMapping("/removeDuplicated")
  69. public void removeDuplicated() {
  70. identityAuthService.removeDuplicated();
  71. }
  72. @PostMapping("/autoAuth")
  73. public Object authAuth(@RequestParam Long id) {
  74. IdentityAuth identityAuth = identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  75. Map<String, Object> map = identityAuthService.auth(identityAuth);
  76. identityAuthService.audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
  77. return map;
  78. }
  79. }