SmartAccessController.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.template.controller;
  2. import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
  3. import com.template.annotation.DESRespondSecret;
  4. import com.template.api.SmartAccessControllerAPI;
  5. import com.template.common.utils.ExcelUtils;
  6. import com.template.model.pojo.SmartAccess;
  7. import com.template.model.result.CommonResult;
  8. import com.template.model.result.PageUtils;
  9. import com.template.model.vo.SmartAccessVo;
  10. import com.template.model.vo.SmartAttendanceVo;
  11. import com.template.services.SmartAccessService;
  12. import org.apache.poi.ss.usermodel.Row;
  13. import org.apache.poi.ss.usermodel.Sheet;
  14. import org.apache.poi.ss.usermodel.Workbook;
  15. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.web.bind.annotation.RequestMapping;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import javax.servlet.http.HttpServletResponse;
  20. import java.time.LocalDateTime;
  21. import java.time.format.DateTimeFormatter;
  22. import java.util.List;
  23. /**
  24. * <p>
  25. * 前端控制器
  26. * </p>
  27. *
  28. * @author ceshi
  29. * @since 2024-05-31
  30. */
  31. @RestController
  32. @DESRespondSecret
  33. public class SmartAccessController implements SmartAccessControllerAPI {
  34. @Autowired
  35. SmartAccessService smartAccessService;
  36. @Override
  37. @DESRespondSecret(validated = true)
  38. public CommonResult getPage(Integer currentPage, Integer pageCount, String keyWord,Integer gradeId, Integer classId, Integer departmentId,String openType,String resultStatus,String startTime,String endTime) {
  39. PageUtils<SmartAccessVo> pageUtils=smartAccessService.getPage(currentPage,pageCount,keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
  40. return CommonResult.ok(pageUtils);
  41. }
  42. @Override
  43. public void getPageExport(HttpServletResponse response, String keyWord, Integer gradeId, Integer classId, Integer departmentId, String openType,String resultStatus, String startTime, String endTime) {
  44. //导出
  45. Workbook workbook = new XSSFWorkbook();
  46. Sheet sheet = workbook.createSheet("门禁通行记录");
  47. Row headerRow = sheet.createRow(0);
  48. headerRow.createCell(0).setCellValue("序号");
  49. headerRow.createCell(1).setCellValue("设备编号");
  50. headerRow.createCell(2).setCellValue("设备名称");
  51. headerRow.createCell(3).setCellValue("部门");
  52. headerRow.createCell(4).setCellValue("班级");
  53. headerRow.createCell(5).setCellValue("姓名");
  54. headerRow.createCell(6).setCellValue("人员编号");
  55. headerRow.createCell(7).setCellValue("图像");
  56. headerRow.createCell(8).setCellValue("识别分组");
  57. headerRow.createCell(9).setCellValue("记录时间");
  58. headerRow.createCell(10).setCellValue("出口类型");
  59. headerRow.createCell(11).setCellValue("通行状态");
  60. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  61. // 默认前一天的
  62. if (ObjectUtils.isEmpty(startTime)||ObjectUtils.isEmpty(endTime)) {
  63. LocalDateTime now = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
  64. LocalDateTime end = now.plusDays(1);
  65. startTime=now.format(dateTimeFormatter);
  66. endTime=end.format(dateTimeFormatter);
  67. }
  68. List<SmartAccessVo> vos=smartAccessService.getPageExport(keyWord,gradeId,classId,departmentId,openType,resultStatus,startTime,endTime);
  69. for (int i = 0; i < vos.size(); i++) {
  70. SmartAccessVo vo = vos.get(i);
  71. Row dataRow = sheet.createRow(i + 1);
  72. dataRow.createCell(0).setCellValue(i + 1);
  73. dataRow.createCell(1).setCellValue(vo.getSn());
  74. dataRow.createCell(2).setCellValue(vo.getType());
  75. dataRow.createCell(3).setCellValue(vo.getDepartmentName());
  76. dataRow.createCell(4).setCellValue(vo.getClassName());
  77. dataRow.createCell(5).setCellValue(vo.getName());
  78. dataRow.createCell(6).setCellValue(vo.getCardNo());
  79. dataRow.createCell(7).setCellValue(vo.getImage());
  80. Integer openType1 = vo.getOpenType();
  81. String type="";
  82. if (0==openType1) {
  83. type="白名单比对";
  84. }else if (1==openType1){
  85. type="人证比对";
  86. }else if (2==openType1){
  87. type="IC卡比对";
  88. }else if (5==openType1){
  89. type="职工二维码比对";
  90. }
  91. dataRow.createCell(8).setCellValue(type);
  92. dataRow.createCell(9).setCellValue(vo.getDateTime());
  93. Integer access = vo.getAccess();
  94. String accessSting="";
  95. if (1==access) {
  96. accessSting="入口";
  97. }else if (0==openType1){
  98. accessSting="出口";
  99. }
  100. dataRow.createCell(10).setCellValue(accessSting);
  101. Integer resultStatus1 = vo.getResultStatus();
  102. String result="";
  103. if (1==resultStatus1) {
  104. result="正常通行";
  105. }else if (0==resultStatus1){
  106. result="禁止通行";
  107. }
  108. dataRow.createCell(11).setCellValue(result);
  109. }
  110. // 将工作簿写入文件
  111. ExcelUtils.excelDownload(workbook, "通行记录.xlsx", response);
  112. }
  113. @Override
  114. @DESRespondSecret(validated = true)
  115. public CommonResult getAccessPage(Integer currentPage, Integer pageCount, String keyWord, Integer gradeId, Integer classId, String resultStatus, String inOut, String startTime, String endTime) {
  116. PageUtils<SmartAccessVo> pageUtils=smartAccessService.getAccessPage(currentPage,pageCount,keyWord,gradeId,classId,resultStatus,inOut,startTime,endTime);
  117. return CommonResult.ok(pageUtils);
  118. }
  119. }