矿工统计调整/考勤excel导出 不分
This commit is contained in:
parent
edf7945f61
commit
2c02ee738d
@ -33,6 +33,7 @@ import cn.iocoder.yudao.module.system.service.attendance.punch.PunchService;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.punch.dto.AttendanceOnTheDayDTO;
|
||||
import cn.iocoder.yudao.module.system.service.attendance.punchrecord.AttendancePunchRecordService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -682,7 +683,7 @@ public class AttendanceServiceImpl implements AttendanceService {
|
||||
// -- 缺卡
|
||||
this.calculateMissingCardsList(workMap, calculateNum);
|
||||
// -- 旷工
|
||||
this.calculateMiner(entry.getValue(), calculateNum);
|
||||
this.calculateMiner(dayEntry.getValue(), calculateNum);
|
||||
// -- 外勤
|
||||
this.calculateFieldService(workMap, calculateNum);
|
||||
}
|
||||
@ -810,10 +811,111 @@ public class AttendanceServiceImpl implements AttendanceService {
|
||||
.in(AttendancePunchRecordDO::getUserId, userList)
|
||||
.in(AttendancePunchRecordDO::getDayTime, dateList));
|
||||
// -- 根据部门分组 - 根据考勤组分组
|
||||
|
||||
Map<Long, Map<Long, List<AttendancePunchRecordDO>>> map = list.stream().collect(Collectors.groupingBy(AttendancePunchRecordDO::getDeptId, Collectors.groupingBy(AttendancePunchRecordDO::getAttendanceGroupId)));
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String fileName = "/Users/aikai/Downloads/" + System.currentTimeMillis() + ".xlsx";
|
||||
// 这里 需要指定写用哪个class去写,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
|
||||
EasyExcel.write(fileName)
|
||||
.head(generateHead())
|
||||
.registerWriteHandler(new CustomCellStyleHandler())
|
||||
// .registerWriteHandler(new LoopMergeStrategy())
|
||||
// .registerWriteHandler(loopMergeStrategy)
|
||||
.sheet("模板")
|
||||
.doWrite(generateData());
|
||||
}
|
||||
|
||||
public static List<List<String>> generateHead() {
|
||||
List<List<String>> head = new ArrayList<>();
|
||||
String headTitle = "月度汇总 统计日期:2024-06-01 至 2024-06-13";
|
||||
String detailedHead = "月度汇总 统计日期:2024-06-01 至 2024-06-13 10:48";
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "姓名", "姓名"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤组", "考勤组"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "部门", "部门"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "工号", "工号"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "职位", "职位"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "出勤天数", "出勤天数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "休息天数", "休息天数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "工作时长", "工作时长"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "迟到次数", "迟到次数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "迟到时长", "迟到时长"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "早退次数", "早退次数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "早退时长", "早退时长"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "上班缺卡次数", "上班缺卡次数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "下班缺卡次数", "下班缺卡次数"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "旷工天数", "旷工天数"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "出差时长", "出差时长"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "外出时长", "外出时长"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "加班-审批单统计", "加班-审批单统计"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "加班时长-按加班规则计算", "工作日加班"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "加班时长-按加班规则计算", "休息日加班"));
|
||||
// head.add(Arrays.asList(headTitle, detailedHead, "加班时长-按加班规则计算", "节假日加班"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "六"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "日"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "1"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "2"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "3"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "4"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "5"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "六"));
|
||||
head.add(Arrays.asList(headTitle, detailedHead, "考勤结果", "日"));
|
||||
// 添加更多表头
|
||||
return head;
|
||||
}
|
||||
|
||||
public static List<List<Object>> generateData() {
|
||||
List<List<Object>> data = new ArrayList<>();
|
||||
|
||||
List<Object> row1 = new ArrayList<>();
|
||||
row1.add("艾楷");
|
||||
row1.add("测试考勤");
|
||||
row1.add("");
|
||||
row1.add("");
|
||||
row1.add("");
|
||||
row1.add("22026829221062585");
|
||||
row1.add(1);
|
||||
row1.add(2);
|
||||
row1.add(3);
|
||||
row1.add(4);
|
||||
row1.add(5);
|
||||
row1.add(6);
|
||||
row1.add(7);
|
||||
row1.add(8);
|
||||
row1.add(9);
|
||||
row1.add(10);
|
||||
row1.add(10);
|
||||
row1.add(12);
|
||||
// 添加更多数据
|
||||
|
||||
List<Object> row2 = new ArrayList<>();
|
||||
row2.add("谢鸿飞");
|
||||
row2.add("测试考勤");
|
||||
row2.add("");
|
||||
row2.add("");
|
||||
row2.add("");
|
||||
row2.add("066557433135769889");
|
||||
row2.add(1);
|
||||
row2.add(2);
|
||||
row2.add(3);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
row2.add(4);
|
||||
// 添加更多数据
|
||||
|
||||
data.add(row1);
|
||||
data.add(row2);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,57 @@
|
||||
package cn.iocoder.yudao.module.system.service.attendance;
|
||||
|
||||
import com.alibaba.excel.metadata.Head;
|
||||
import com.alibaba.excel.metadata.data.WriteCellData;
|
||||
import com.alibaba.excel.write.handler.CellWriteHandler;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
|
||||
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
|
||||
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
||||
import com.alibaba.excel.write.metadata.style.WriteFont;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CustomCellStyleHandler implements CellWriteHandler {
|
||||
|
||||
@Override
|
||||
public void afterCellDispose(
|
||||
WriteSheetHolder writeSheetHolder,
|
||||
WriteTableHolder writeTableHolder,
|
||||
List<WriteCellData<?>> cellDataList,
|
||||
Cell cell,
|
||||
Head head,
|
||||
Integer relativeRowIndex,
|
||||
Boolean isHead) {
|
||||
|
||||
Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
|
||||
CellStyle cellStyle = workbook.createCellStyle();
|
||||
writeSheetHolder.getSheet().setColumnWidth(cell.getColumnIndex(), 5120);
|
||||
// 设置水平和垂直居中对齐
|
||||
cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
||||
cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
// 设置不同行的样式
|
||||
if (isHead) {
|
||||
if (relativeRowIndex == 0 || relativeRowIndex == 1) {
|
||||
// 头的策略
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
// 背景设置为红色
|
||||
headWriteCellStyle.setFillForegroundColor(IndexedColors.TURQUOISE.getIndex());
|
||||
WriteFont headWriteFont = new WriteFont();
|
||||
headWriteFont.setFontHeightInPoints((short) 20);
|
||||
headWriteCellStyle.setWriteFont(headWriteFont);
|
||||
WriteCellStyle.merge(headWriteCellStyle, cellDataList.get(0).getOrCreateStyle());
|
||||
} else if (relativeRowIndex == 2 || relativeRowIndex == 3) {
|
||||
// 头的策略
|
||||
WriteCellStyle headWriteCellStyle = new WriteCellStyle();
|
||||
// 背景设置为红色
|
||||
headWriteCellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
|
||||
WriteFont headWriteFont = new WriteFont();
|
||||
headWriteFont.setFontHeightInPoints((short) 20);
|
||||
headWriteCellStyle.setWriteFont(headWriteFont);
|
||||
WriteCellStyle.merge(headWriteCellStyle, cellDataList.get(0).getOrCreateStyle());
|
||||
}
|
||||
}
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user