StaffAccessController.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package com.x1ongzhu.wisFactory.web;
  2. import com.x1ongzhu.wisFactory.domain.EventUploadReq;
  3. import com.x1ongzhu.wisFactory.domain.StaffAccess;
  4. import com.x1ongzhu.wisFactory.dto.PageQuery;
  5. import com.x1ongzhu.wisFactory.dto.StaffAccessDTO;
  6. import com.x1ongzhu.wisFactory.exception.BusinessException;
  7. import com.x1ongzhu.wisFactory.repo.StaffAccessRepo;
  8. import com.x1ongzhu.wisFactory.service.StaffAccessService;
  9. import com.x1ongzhu.wisFactory.utils.ObjUtils;
  10. import com.x1ongzhu.wisFactory.utils.excel.ExcelUtils;
  11. import lombok.AllArgsConstructor;
  12. import org.springframework.beans.BeanUtils;
  13. import org.springframework.data.domain.Page;
  14. import org.springframework.web.bind.annotation.*;
  15. import javax.servlet.http.HttpServletResponse;
  16. import java.io.IOException;
  17. import java.time.LocalDateTime;
  18. import java.util.List;
  19. import java.util.Optional;
  20. import java.util.stream.Collectors;
  21. @RestController
  22. @RequestMapping("/staffAccess")
  23. @AllArgsConstructor
  24. public class StaffAccessController extends BaseController {
  25. private StaffAccessService staffAccessService;
  26. private StaffAccessRepo staffAccessRepo;
  27. //@PreAuthorize("hasRole('ADMIN')")
  28. @PostMapping("/save")
  29. public StaffAccess save(@RequestBody StaffAccess record) {
  30. if (record.getId() != null) {
  31. StaffAccess orig = staffAccessRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
  32. ObjUtils.merge(orig, record);
  33. return staffAccessRepo.save(orig);
  34. }
  35. return staffAccessRepo.save(record);
  36. }
  37. //@PreAuthorize("hasRole('ADMIN')")
  38. @GetMapping("/all")
  39. public Page<StaffAccess> all(PageQuery pageQuery) {
  40. return staffAccessRepo.findAll(toSpecification(pageQuery, StaffAccess.class), toPageRequest(pageQuery));
  41. }
  42. @GetMapping("/get/{id}")
  43. public StaffAccess get(@PathVariable Long id) {
  44. return staffAccessRepo.findById(id).orElseThrow(new BusinessException("无记录"));
  45. }
  46. @PostMapping("/del/{id}")
  47. public void del(@PathVariable Long id) {
  48. staffAccessRepo.deleteById(id);
  49. }
  50. @GetMapping("/excel")
  51. @ResponseBody
  52. public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
  53. List<StaffAccess> data = all(pageQuery).getContent();
  54. List<StaffAccessDTO> list = data.stream().map(staffAccess -> {
  55. StaffAccessDTO dto = new StaffAccessDTO();
  56. BeanUtils.copyProperties(staffAccess, dto);
  57. dto.setPass(Optional.ofNullable(staffAccess.getPass()).orElse(false) ? "通过" : "失败");
  58. return dto;
  59. }).collect(Collectors.toList());
  60. ExcelUtils.export(response, list);
  61. }
  62. @PostMapping("/access")
  63. public void access(@RequestParam Boolean pass,
  64. @RequestParam(required = false) String direction,
  65. @RequestParam(required = false) String ip,
  66. @RequestParam(required = false) String cardNo,
  67. @RequestParam(required = false) String employNo,
  68. @RequestParam(required = false) String doorNo,
  69. @RequestParam(required = false) String readerNo,
  70. @RequestParam(required = false) String channel,
  71. @RequestParam(required = false) String pic,
  72. @RequestParam LocalDateTime time) {
  73. staffAccessService.access(pass, direction, ip, cardNo, employNo, doorNo, readerNo, channel, pic, time);
  74. }
  75. @PostMapping("/uploadEvent")
  76. public void uploadEvent(@RequestBody EventUploadReq req) {
  77. staffAccessService.uploadEvent(req);
  78. }
  79. @PostMapping("/retroactive")
  80. public void retroactive(@RequestParam String employNo, @RequestParam String direction, @RequestParam LocalDateTime accessTime, @RequestParam String remark) {
  81. staffAccessService.retroactive(employNo, direction, accessTime, remark);
  82. }
  83. @GetMapping("/setInfo")
  84. public String setInfo() {
  85. staffAccessService.setInfo();
  86. return "ok";
  87. }
  88. }