MonthlySummaryController.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package com.chuanghai.attendance.controller;
  2. import com.chuanghai.attendance.common.exception.BizCodeEnume;
  3. import com.chuanghai.attendance.common.exception.RRException;
  4. import com.chuanghai.attendance.common.utils.CommonResult;
  5. import com.chuanghai.attendance.dto.MonthlyDto;
  6. import com.chuanghai.attendance.entity.DayDetails;
  7. import com.chuanghai.attendance.entity.DownLoadExcel;
  8. import com.chuanghai.attendance.entity.MonitorFoldLineTable;
  9. import com.chuanghai.attendance.entity.MonthlySummary;
  10. import com.chuanghai.attendance.service.*;
  11. import com.chuanghai.attendance.utils.FileExportUtil;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.springframework.beans.BeanUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.util.StringUtils;
  16. import org.springframework.web.bind.annotation.*;
  17. import org.springframework.web.multipart.MultipartFile;
  18. import javax.servlet.http.HttpServletResponse;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. /**
  22. * 月度汇总
  23. *
  24. * @Author: binguo
  25. * @Date: 2022/10/9 星期日 16:00
  26. * @Description: com.chuanghai.attendance.controller
  27. * @Version: 1.0
  28. */
  29. @RestController
  30. @RequestMapping("month")
  31. @Slf4j
  32. public class MonthlySummaryController {
  33. @Autowired
  34. private MonthlySummaryService monthlySummaryService;
  35. @Autowired
  36. private OriginalDataService originalDataService;
  37. @Autowired
  38. private WorkerIdentityService workerIdentityService;
  39. @Autowired
  40. private CampusTimeService campusTimeService;
  41. @Autowired
  42. private DayDetailsService dayDetailsService;
  43. private static Boolean analyseStatu = Boolean.FALSE;
  44. /**
  45. * 读取钉钉考勤excel原始数据,添加至数据库
  46. *
  47. * @param file
  48. * @throws Exception
  49. */
  50. @PostMapping("importExcel")
  51. public CommonResult importMonthExcel(@RequestParam("file") MultipartFile file) {
  52. Boolean aBoolean;
  53. Boolean oBoolean;
  54. Boolean wBoolean;
  55. String msg = "执行失败";
  56. try {
  57. aBoolean = monthlySummaryService.importMonthDataExcel(file);
  58. wBoolean = workerIdentityService.importWorkExcel(file);
  59. oBoolean = originalDataService.importOriginalDataExcel(file);
  60. if (aBoolean && oBoolean && wBoolean) {
  61. msg = "执行成功";
  62. }
  63. } catch (Exception e) {
  64. e.printStackTrace();
  65. throw new RRException(BizCodeEnume.FILE_IMPORT_ERROR);
  66. }
  67. return CommonResult.result("200", msg, aBoolean);
  68. }
  69. /**
  70. * 分析钉钉原始数据
  71. *
  72. * @return
  73. */
  74. @GetMapping("analyse")
  75. public CommonResult analyse() {
  76. List<MonthlyDto> monthlyDtoList = monthlySummaryService.analyse();
  77. MonthlyDto monthlyDto = monthlyDtoList.get(0);
  78. log.info("monthlyDtomonthlyDtomonthlyDtomonthlyDto",monthlyDto);
  79. if (monthlyDtoList.size() > 0) {
  80. analyseStatu = Boolean.TRUE;
  81. }
  82. return CommonResult.ok();
  83. }
  84. /**
  85. * 查询解析是否完成
  86. * @return
  87. */
  88. @GetMapping("queryAnalyseStatu")
  89. public CommonResult queryAnalyseStatu() {
  90. Boolean statu;
  91. statu = analyseStatu;
  92. if (statu) {
  93. analyseStatu = Boolean.FALSE;
  94. }
  95. return CommonResult.ok().setResult(statu);
  96. }
  97. /**
  98. * 下载excel数据
  99. * @return
  100. */
  101. @GetMapping("downLoad")
  102. public CommonResult<List<DownLoadExcel>> downLoad() {
  103. List<MonthlyDto> MonthlyDtoList = monthlySummaryService.analyse();
  104. List<MonthlySummary> monthlySummaryList = monthlySummaryService.queryAll();
  105. List<DayDetails> dayDetailsList = dayDetailsService.list();
  106. List<DownLoadExcel> downLoadExcelList = new ArrayList<>();
  107. for (int m = 0; m < MonthlyDtoList.size(); m++) {
  108. DownLoadExcel downLoadExcel = new DownLoadExcel();
  109. MonthlyDto monthlyDto = MonthlyDtoList.get(m);
  110. MonthlySummary monthlySummary = monthlySummaryList.get(m);
  111. DayDetails dayDetails = dayDetailsList.get(m + 1);
  112. BeanUtils.copyProperties(monthlyDto, downLoadExcel);
  113. BeanUtils.copyProperties(monthlySummary, downLoadExcel);
  114. BeanUtils.copyProperties(dayDetails, downLoadExcel);
  115. downLoadExcelList.add(downLoadExcel);
  116. }
  117. // downLoadExcelList.forEach(downLoadExcel -> {
  118. // System.out.println(downLoadExcel);
  119. // });
  120. return CommonResult.ok().setResult(downLoadExcelList);
  121. }
  122. @RequestMapping("te")
  123. public void test(HttpServletResponse response) {
  124. String[] titleStr = dayDetailsService.getTitleStr();
  125. //假设这是需要导出的数据
  126. List<DownLoadExcel> downLoadExcels = downLoad().getData();
  127. List<MonitorFoldLineTable> data = new ArrayList();
  128. //调用导出工具类
  129. FileExportUtil.testExcelDemo(downLoadExcels, response, titleStr);
  130. }
  131. /**
  132. * 获取月度 日标题
  133. *
  134. * @return
  135. */
  136. @GetMapping("title")
  137. public CommonResult<DayDetails> getTitle() {
  138. String[] titleStr = dayDetailsService.getTitleStr();
  139. for (int m = 0; m < titleStr.length; m++) {
  140. if (!StringUtils.hasText(titleStr[m])) {
  141. titleStr[m] = "";
  142. }
  143. }
  144. return CommonResult.ok().setResult(titleStr);
  145. }
  146. }