| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package com.izouma.nineth.web;
- import com.izouma.nineth.domain.IdentityAuth;
- import com.izouma.nineth.domain.User;
- import com.izouma.nineth.dto.PageQuery;
- import com.izouma.nineth.enums.AuthStatus;
- import com.izouma.nineth.exception.BusinessException;
- import com.izouma.nineth.repo.IdentityAuthRepo;
- import com.izouma.nineth.service.IdentityAuthService;
- import com.izouma.nineth.utils.SecurityUtils;
- import com.izouma.nineth.utils.excel.ExcelUtils;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springframework.data.domain.Page;
- import org.springframework.security.access.prepost.PreAuthorize;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.util.List;
- import java.util.Map;
- @RestController
- @RequestMapping("/identityAuth")
- @AllArgsConstructor
- public class IdentityAuthController extends BaseController {
- private IdentityAuthService identityAuthService;
- private IdentityAuthRepo identityAuthRepo;
- // @PreAuthorize("hasAnyRole('ADMIN','OPERATOR')")
- @PostMapping("/all")
- public Page<IdentityAuth> all(@RequestBody PageQuery pageQuery) {
- return identityAuthService.all(pageQuery);
- }
- @PreAuthorize("hasRole('ADMIN')")
- @GetMapping("/get/{id}")
- public IdentityAuth get(@PathVariable Long id) {
- return identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- identityAuthRepo.softDelete(id);
- }
- @PreAuthorize("hasRole('ADMIN')")
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<IdentityAuth> data = all(pageQuery).getContent();
- ExcelUtils.export(response, data);
- }
- @PostMapping("/apply")
- public void apply(IdentityAuth identityAuth) {
- identityAuth.setUserId(SecurityUtils.getAuthenticatedUser().getId());
- identityAuthService.apply(identityAuth);
- }
- @PreAuthorize("hasAnyRole('ADMIN', 'OPERATOR')")
- @PostMapping("/pass")
- public void audit(@RequestParam Long id) {
- identityAuthService.audit(id, AuthStatus.SUCCESS, null);
- }
- @PreAuthorize("hasAnyRole('ADMIN', 'OPERATOR')")
- @PostMapping("/deny")
- public void deny(@RequestParam Long id, @RequestParam(required = false) String reason) {
- identityAuthService.audit(id, AuthStatus.FAIL, reason);
- }
- @ApiOperation("查找重复身份证")
- @PostMapping("/repeat")
- public List<User> repeat(@RequestParam String idNo, @RequestParam Long userId) {
- return identityAuthService.repeat(idNo, userId);
- }
- @GetMapping("/removeDuplicated")
- public void removeDuplicated() {
- identityAuthService.removeDuplicated();
- }
- @PostMapping("/autoAuth")
- public Object authAuth(@RequestParam Long id) {
- IdentityAuth identityAuth = identityAuthRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- Map<String, Object> map = identityAuthService.auth(identityAuth);
- identityAuthService.audit(identityAuth.getId(), (AuthStatus) map.get("status"), (String) map.get("reason"));
- return map;
- }
- }
|