SmartAccessController.java 6.6 KB

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