| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package com.x1ongzhu.wisFactory.web;
- import com.x1ongzhu.wisFactory.domain.EventUploadReq;
- import com.x1ongzhu.wisFactory.domain.StaffAccess;
- import com.x1ongzhu.wisFactory.dto.PageQuery;
- import com.x1ongzhu.wisFactory.dto.StaffAccessDTO;
- import com.x1ongzhu.wisFactory.exception.BusinessException;
- import com.x1ongzhu.wisFactory.repo.StaffAccessRepo;
- import com.x1ongzhu.wisFactory.service.StaffAccessService;
- import com.x1ongzhu.wisFactory.utils.ObjUtils;
- import com.x1ongzhu.wisFactory.utils.excel.ExcelUtils;
- import lombok.AllArgsConstructor;
- import org.springframework.beans.BeanUtils;
- import org.springframework.data.domain.Page;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletResponse;
- import java.io.IOException;
- import java.time.LocalDateTime;
- import java.util.List;
- import java.util.Optional;
- import java.util.stream.Collectors;
- @RestController
- @RequestMapping("/staffAccess")
- @AllArgsConstructor
- public class StaffAccessController extends BaseController {
- private StaffAccessService staffAccessService;
- private StaffAccessRepo staffAccessRepo;
- //@PreAuthorize("hasRole('ADMIN')")
- @PostMapping("/save")
- public StaffAccess save(@RequestBody StaffAccess record) {
- if (record.getId() != null) {
- StaffAccess orig = staffAccessRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
- ObjUtils.merge(orig, record);
- return staffAccessRepo.save(orig);
- }
- return staffAccessRepo.save(record);
- }
- //@PreAuthorize("hasRole('ADMIN')")
- @GetMapping("/all")
- public Page<StaffAccess> all(PageQuery pageQuery) {
- return staffAccessRepo.findAll(toSpecification(pageQuery, StaffAccess.class), toPageRequest(pageQuery));
- }
- @GetMapping("/get/{id}")
- public StaffAccess get(@PathVariable Long id) {
- return staffAccessRepo.findById(id).orElseThrow(new BusinessException("无记录"));
- }
- @PostMapping("/del/{id}")
- public void del(@PathVariable Long id) {
- staffAccessRepo.deleteById(id);
- }
- @GetMapping("/excel")
- @ResponseBody
- public void excel(HttpServletResponse response, PageQuery pageQuery) throws IOException {
- List<StaffAccess> data = all(pageQuery).getContent();
- List<StaffAccessDTO> list = data.stream().map(staffAccess -> {
- StaffAccessDTO dto = new StaffAccessDTO();
- BeanUtils.copyProperties(staffAccess, dto);
- dto.setPass(Optional.ofNullable(staffAccess.getPass()).orElse(false) ? "通过" : "失败");
- return dto;
- }).collect(Collectors.toList());
- ExcelUtils.export(response, list);
- }
- @PostMapping("/access")
- public void access(@RequestParam Boolean pass,
- @RequestParam(required = false) String direction,
- @RequestParam(required = false) String ip,
- @RequestParam(required = false) String cardNo,
- @RequestParam(required = false) String employNo,
- @RequestParam(required = false) String doorNo,
- @RequestParam(required = false) String readerNo,
- @RequestParam(required = false) String channel,
- @RequestParam(required = false) String pic,
- @RequestParam LocalDateTime time) {
- staffAccessService.access(pass, direction, ip, cardNo, employNo, doorNo, readerNo, channel, pic, time);
- }
- @PostMapping("/uploadEvent")
- public void uploadEvent(@RequestBody EventUploadReq req) {
- staffAccessService.uploadEvent(req);
- }
- @PostMapping("/retroactive")
- public void retroactive(@RequestParam String employNo, @RequestParam String direction, @RequestParam LocalDateTime accessTime, @RequestParam String remark) {
- staffAccessService.retroactive(employNo, direction, accessTime, remark);
- }
- @GetMapping("/setInfo")
- public String setInfo() {
- staffAccessService.setInfo();
- return "ok";
- }
- }
|