| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.baomidou.mybatisplus.core.conditions.Wrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | |
| | | import com.google.common.util.concurrent.AtomicDouble; |
| | | import com.ruoyi.common.enums.ClockInState; |
| | | import com.ruoyi.common.enums.EnterOrExitType; |
| | | import com.ruoyi.common.enums.StaffAttendanceReportType; |
| | | import com.ruoyi.common.enums.SyncStatus; |
| | | import com.ruoyi.common.utils.api.icc.IccApiUtil; |
| | | import com.ruoyi.common.utils.api.icc.model.GetResultPageRequest; |
| | |
| | | private DateTimeFormatter HHmm = DateTimeFormatter.ofPattern("HH:mm"); |
| | | |
| | | private DateTimeFormatter yyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | private DateTimeFormatter yyyMMStr = DateTimeFormatter.ofPattern("yyyyå¹´MMæddæ¥"); |
| | | /** è´¨éé¨id */ |
| | | private final static String deptIds = "6"; |
| | | |
| | |
| | | for (int i = 0; i < userIdKeys.size(); i++) { |
| | | List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(userIdKeys.get(i)); |
| | | StaffAttendanceExcelData attendanceExcelData = new StaffAttendanceExcelData(); |
| | | attendanceExcelData.setExcelIndex(i+1); |
| | | List<String> shiftList = new ArrayList<>(); |
| | | attendanceExcelData.setPersonName(shiftMapDtos.get(0).getUserName()); |
| | | attendanceExcelData.setExcelIndex(i+1); |
| | | AtomicInteger holidayCount = new AtomicInteger(0);//伿¯å¤©æ° |
| | | AtomicInteger personalLeaveCount = new AtomicInteger(0);//äºåå¤©æ° |
| | | AtomicInteger annualLeaveCount = new AtomicInteger(0);//å¹´åå¤©æ° |
| | |
| | | } |
| | | } |
| | | } |
| | | //æåº¦ç»è®¡ææå
¥æ¹æ³¨æ°æ® |
| | | if(StringUtils.isNoneBlank(staffAttendanceDTO.getAttendanceReportType()) && StringUtils.equals(staffAttendanceDTO.getAttendanceReportType(), StaffAttendanceReportType.MONTH.name())){ |
| | | if(StringUtils.isNotBlank(shiftMapDto.getAnnotationText())){ |
| | | annotationTextList.add(new StaffAttendanceAnnotationTextExcelData(i,j,shiftMapDto.getAnnotationText())); |
| | | } |
| | | } |
| | | } |
| | | if(StringUtils.isNoneBlank(staffAttendanceDTO.getAttendanceReportType()) && StringUtils.equals(staffAttendanceDTO.getAttendanceReportType(), StaffAttendanceReportType.MONTH.name())){ |
| | | attendanceExcelData.setShiftList(shiftList); |
| | | } |
| | | attendanceExcelData.setAttendanceDayCount(attendanceDayCount.get()); |
| | | attendanceExcelData.setAttendanceWorkHourCount(attendanceWorkHourCount.get()); |
| | | //çæ¬¡èå¤å¤©æ° |
| | |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | InputStream resourceAsStream = buildAttendanceTemplate(attendanceDateList); |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .withTemplate(resourceAsStream) |
| | | .registerWriteHandler(new CommentWriteHandler(excelData, annotationTextList)) |
| | | .relativeHeadRowIndex(4) |
| | | .sheet() |
| | | .doFill(excelData); |
| | | InputStream resourceAsStream = buildAttendanceTemplate(attendanceDateList,staffAttendanceDTO.getAttendanceReportType()); |
| | | try (ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(resourceAsStream).registerWriteHandler(new CommentWriteHandler(excelData, annotationTextList)).relativeHeadRowIndex(4).build()) { |
| | | WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
| | | excelWriter.fill(excelData, writeSheet); |
| | | if(StringUtils.equals(staffAttendanceDTO.getAttendanceReportType(),StaffAttendanceReportType.YEAR.name())){ |
| | | String startDate = staffAttendanceDTO.getStartDate().format(yyyMMStr); |
| | | String endDate = staffAttendanceDTO.getEndDate().format(yyyMMStr); |
| | | Map<String, String> dateMap = new HashMap<>(); |
| | | dateMap.put("startDate",startDate); |
| | | dateMap.put("endDate",endDate); |
| | | excelWriter.fill(dateMap, writeSheet); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | |
| | | for (LocalDate currentDate = startDate; !currentDate.isAfter(endDate); currentDate = currentDate.plusDays(1)) { |
| | | attendanceDateList.add(currentDate); |
| | | } |
| | | if (attendanceDateList.size() > 31) { |
| | | if (attendanceDateList.size() > 31 && StringUtils.equals(staffAttendanceDTO.getAttendanceReportType(),StaffAttendanceReportType.MONTH.name())) { |
| | | throw new IllegalArgumentException("å¯¼åºæ¶é´èå´ä¸è½è¶
è¿31天"); |
| | | } |
| | | return attendanceDateList; |
| | | } |
| | | |
| | | private InputStream buildAttendanceTemplate(List<LocalDate> attendanceDateList) throws IOException { |
| | | try (InputStream templateStream = this.getClass().getResourceAsStream("/static/staff_attendance_template.xlsx"); |
| | | Workbook workbook = WorkbookFactory.create(templateStream); |
| | | private InputStream buildAttendanceTemplate(List<LocalDate> attendanceDateList,String attendanceReportType) throws IOException { |
| | | String templateName = "/static/staff_attendance_month_template.xlsx"; |
| | | if(StringUtils.equals(attendanceReportType,StaffAttendanceReportType.YEAR.name())){ |
| | | templateName = "/static/staff_attendance_year_template.xlsx"; |
| | | } |
| | | try (InputStream templateStream = this.getClass().getResourceAsStream(templateName)) { |
| | | assert templateStream != null; |
| | | try (Workbook workbook = WorkbookFactory.create(templateStream); |
| | | ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { |
| | | Sheet sheet = workbook.getSheetAt(0); |
| | | if(StringUtils.equals(attendanceReportType,StaffAttendanceReportType.MONTH.name())){ |
| | | fillAttendanceHeader(sheet, attendanceDateList); |
| | | } |
| | | workbook.write(outputStream); |
| | | return new ByteArrayInputStream(outputStream.toByteArray()); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new IOException("æå»ºèå¤å¯¼åºæ¨¡æ¿å¤±è´¥", e); |
| | | } |