| performance-server/src/main/java/com/ruoyi/performance/excel/PerformanceShiftAnnotationTextExcelData.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| performance-server/src/main/java/com/ruoyi/performance/excel/PerformanceShiftExcelData.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| performance-server/src/main/java/com/ruoyi/performance/excel/handler/performance/CommentWriteHandler.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| performance-server/src/main/java/com/ruoyi/performance/excel/handler/performance/PerformanceShiftHeaderWriteHandler.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| performance-server/src/main/resources/static/performance_shift_month_template.xlsx | 补丁 | 查看 | 原始文档 | blame | 历史 | |
| performance-server/src/main/resources/static/performance_shift_year_template.xlsx | 补丁 | 查看 | 原始文档 | blame | 历史 |
performance-server/src/main/java/com/ruoyi/performance/excel/PerformanceShiftAnnotationTextExcelData.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,34 @@ package com.ruoyi.performance.excel; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; /** * çæ¬¡å¯¼åºï¼æ¹æ³¨ä¸æ 对象 */ @Data @AllArgsConstructor @NoArgsConstructor public class PerformanceShiftAnnotationTextExcelData { /** * å䏿 */ @ApiModelProperty("å䏿 ") private int rowIndex; /** * å䏿 */ @ApiModelProperty("å䏿 ") private int cellIndex; /** * æ¹æ³¨ææ¬ */ @ApiModelProperty("æ¹æ³¨ææ¬") private String annotationText; } performance-server/src/main/java/com/ruoyi/performance/excel/PerformanceShiftExcelData.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,107 @@ package com.ruoyi.performance.excel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import java.util.List; @Data public class PerformanceShiftExcelData { /** * 导åºåºå· */ @ApiModelProperty("导åºåºå·") private Integer excelIndex; /** * å§å */ @ApiModelProperty("å§å") private String personName; /** * çæ¬¡å表 */ @ApiModelProperty("çæ¬¡å表") private List<String> shiftNameList; /** * æ©çå¤©æ° */ @ApiModelProperty("æ©ç天æ°") private Integer morningShiftCount; /** * ä¸çå¤©æ° */ @ApiModelProperty("ä¸ç天æ°") private Integer dayShiftCount; /** * å¤çå¤©æ° */ @ApiModelProperty("å¤ç天æ°") private Integer nightShiftCount; /** * 伿¯å¤©æ° */ @ApiModelProperty("伿¯å¤©æ°") private Integer holidayLeaveCount; /** * å ¬å·®å¤©æ° */ @ApiModelProperty("å ¬å·®å¤©æ°") private Integer officialTripCount; /** * äºåå¤©æ° */ @ApiModelProperty("äºå天æ°") private Integer personalLeaveCount; /** * ç åå¤©æ° */ @ApiModelProperty("ç å天æ°") private Integer sickLeaveCount; /** * å¹´åå¤©æ° */ @ApiModelProperty("å¹´å天æ°") private Integer annualLeaveCount; /** * å©åå¤©æ° */ @ApiModelProperty("å©å天æ°") private Integer marriageLeaveCount; /** * 产åå¤©æ° */ @ApiModelProperty("产å天æ°") private Integer maternityLeaveCount; /** * 丧åå¤©æ° */ @ApiModelProperty("丧å天æ°") private Integer bereavementLeaveCount; /** * åºå¤æ»å¤©æ° */ @ApiModelProperty("åºå¤æ»å¤©æ°") private Integer totalCount; /** * åºå¤æ»æ¶é´ */ @ApiModelProperty("åºå¤æ»æ¶é´") private Double totalWorkHourCount; } performance-server/src/main/java/com/ruoyi/performance/excel/handler/performance/CommentWriteHandler.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,107 @@ package com.ruoyi.performance.excel.handler.performance; import com.alibaba.excel.util.BooleanUtils; import com.alibaba.excel.write.handler.RowWriteHandler; import com.alibaba.excel.write.handler.context.RowWriteHandlerContext; import com.ruoyi.performance.excel.PerformanceShiftAnnotationTextExcelData; import com.ruoyi.performance.excel.PerformanceShiftExcelData; import org.apache.commons.lang3.StringUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFClientAnchor; import org.apache.poi.xssf.usermodel.XSSFRichTextString; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; /** * çæ¬¡å¯¼åºåå ¥å¤çå¨ * 1. è¡¥é½æ¨¡æ¿ä¸ä¸åå¨ççæ¬¡æç»åå æ ¼ * 2. å¨å¯¹åºåå æ ¼ä¸åå ¥æ¹æ³¨ */ public class CommentWriteHandler implements RowWriteHandler { /** * æ¨¡æ¿æ°æ®èµ·å§è¡ä¸ºç¬¬ 5 è¡ */ private static final int DATA_START_ROW_INDEX = 4; /** * 模æ¿ç次起å§å为 C å */ private static final int DATA_START_COLUMN_INDEX = 2; private final List<PerformanceShiftExcelData> excelDataList; private final Map<String, String> annotationTextMap = new HashMap<>(); public CommentWriteHandler(List<PerformanceShiftExcelData> excelDataList, List<PerformanceShiftAnnotationTextExcelData> annotationTextList) { this.excelDataList = excelDataList == null ? Collections.emptyList() : excelDataList; if (annotationTextList == null) { return; } annotationTextList.stream() .filter(item -> item != null && StringUtils.isNotBlank(item.getAnnotationText())) .forEach(item -> annotationTextMap.put(buildKey(item.getRowIndex(), item.getCellIndex()), item.getAnnotationText())); } @Override public void afterRowDispose(RowWriteHandlerContext context) { if (BooleanUtils.isTrue(context.getHead())) { return; } Row row = context.getRow(); if (row == null || row.getRowNum() < DATA_START_ROW_INDEX) { return; } int dataIndex = row.getRowNum() - DATA_START_ROW_INDEX; if (dataIndex < 0 || dataIndex >= excelDataList.size()) { return; } PerformanceShiftExcelData excelData = excelDataList.get(dataIndex); if (excelData == null || excelData.getShiftNameList() == null) { return; } Sheet sheet = row.getSheet(); CellStyle cellStyle = sheet.getColumnStyle(DATA_START_COLUMN_INDEX); Drawing<?> drawingPatriarch = null; List<String> shiftList = excelData.getShiftNameList(); for (int i = 0; i < shiftList.size(); i++) { int cellIndex = DATA_START_COLUMN_INDEX + i; Cell cell = row.getCell(cellIndex); if (cell == null) { cell = row.createCell(cellIndex); } if (cellStyle != null) { cell.setCellStyle(cellStyle); } String cellValue = shiftList.get(i); if (StringUtils.isNotBlank(cellValue)) { cell.setCellValue(cellValue); } String annotationText = annotationTextMap.get(buildKey(dataIndex, i)); if (StringUtils.isBlank(annotationText) || cell.getCellComment() != null) { continue; } if (drawingPatriarch == null) { drawingPatriarch = sheet.createDrawingPatriarch(); } Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor( 0, 0, 0, 0, cellIndex, row.getRowNum(), cellIndex + 2, row.getRowNum() + 3)); comment.setString(new XSSFRichTextString(annotationText)); comment.setAuthor("NS-LIMS"); cell.setCellComment(comment); } } private String buildKey(int rowIndex, int cellIndex) { return rowIndex + "_" + cellIndex; } } performance-server/src/main/java/com/ruoyi/performance/excel/handler/performance/PerformanceShiftHeaderWriteHandler.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,105 @@ package com.ruoyi.performance.excel.handler.performance; import com.alibaba.excel.write.handler.SheetWriteHandler; import com.alibaba.excel.write.handler.context.SheetWriteHandlerContext; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.util.Collections; import java.util.List; /** * çæ¬¡å¯¼åºå¨æè¡¨å¤´å¤çå¨ */ public class PerformanceShiftHeaderWriteHandler implements SheetWriteHandler { private static final int TITLE_ROW_INDEX = 1; private static final int WEEK_ROW_INDEX = 2; private static final int DAY_ROW_INDEX = 3; private static final int START_COLUMN_INDEX = 2; private static final int MAX_DATE_COLUMN_COUNT = 31; private static final DateTimeFormatter TITLE_FORMATTER = DateTimeFormatter.ofPattern("yyyyå¹´Mæ"); private final List<LocalDate> attendanceDateList; public PerformanceShiftHeaderWriteHandler(List<LocalDate> attendanceDateList) { this.attendanceDateList = attendanceDateList == null ? Collections.emptyList() : attendanceDateList; } @Override public void afterSheetCreate(SheetWriteHandlerContext context) { Sheet sheet = context.getWriteSheetHolder().getSheet(); if (sheet == null || attendanceDateList.isEmpty()) { return; } Row titleRow = sheet.getRow(TITLE_ROW_INDEX); if (titleRow != null) { Cell titleCell = titleRow.getCell(0); if (titleCell != null) { titleCell.setCellValue(attendanceDateList.get(attendanceDateList.size() - 1).format(TITLE_FORMATTER)); } } Row weekRow = sheet.getRow(WEEK_ROW_INDEX); Row dayRow = sheet.getRow(DAY_ROW_INDEX); if (weekRow == null || dayRow == null) { return; } for (int i = 0; i < MAX_DATE_COLUMN_COUNT; i++) { Cell weekCell = getOrCreateCell(weekRow, START_COLUMN_INDEX + i); Cell dayCell = getOrCreateCell(dayRow, START_COLUMN_INDEX + i); if (i < attendanceDateList.size()) { LocalDate currentDate = attendanceDateList.get(i); weekCell.setCellValue(resolveWeekOfYear(currentDate)); dayCell.setCellValue(currentDate.getDayOfMonth()); } else { weekCell.setBlank(); dayCell.setBlank(); } } } private Cell getOrCreateCell(Row row, int cellIndex) { Cell cell = row.getCell(cellIndex); if (cell != null) { return cell; } Cell templateCell = row.getCell(START_COLUMN_INDEX); cell = row.createCell(cellIndex); if (templateCell != null && templateCell.getCellStyle() != null) { cell.setCellStyle(templateCell.getCellStyle()); } return cell; } private String resolveWeekOfYear(LocalDate date) { switch (date.getDayOfWeek()) { case MONDAY: return "ä¸"; case TUESDAY: return "äº"; case WEDNESDAY: return "ä¸"; case THURSDAY: return "å"; case FRIDAY: return "äº"; case SATURDAY: return "å "; case SUNDAY: return "æ¥"; default: return ""; } } } performance-server/src/main/resources/static/performance_shift_month_template.xlsxBinary files differ
performance-server/src/main/resources/static/performance_shift_year_template.xlsxBinary files differ