Merge remote-tracking branch 'origin/main'
# Conflicts: # bonus-modules/bonus-bmw/src/main/java/com/bonus/bmw/controller/PmProjectController.java
This commit is contained in:
commit
dc88146175
|
|
@ -1,5 +1,32 @@
|
||||||
package com.bonus.common.core.utils.poi;
|
package com.bonus.common.core.utils.poi;
|
||||||
|
|
||||||
|
import com.bonus.common.core.annotation.Excel;
|
||||||
|
import com.bonus.common.core.annotation.Excel.ColumnType;
|
||||||
|
import com.bonus.common.core.annotation.Excel.Type;
|
||||||
|
import com.bonus.common.core.annotation.Excels;
|
||||||
|
import com.bonus.common.core.constant.Constants;
|
||||||
|
import com.bonus.common.core.exception.UtilException;
|
||||||
|
import com.bonus.common.core.text.Convert;
|
||||||
|
import com.bonus.common.core.utils.DateUtils;
|
||||||
|
import com.bonus.common.core.utils.StringUtils;
|
||||||
|
import com.bonus.common.core.utils.file.FileTypeUtils;
|
||||||
|
import com.bonus.common.core.utils.file.ImageUtils;
|
||||||
|
import com.bonus.common.core.utils.reflect.ReflectUtils;
|
||||||
|
import com.bonus.common.core.web.domain.AjaxResult;
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.RegExUtils;
|
||||||
|
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||||
|
import org.apache.poi.ss.usermodel.*;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||||
|
import org.apache.poi.util.IOUtils;
|
||||||
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||||
|
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
@ -11,63 +38,8 @@ import java.math.BigDecimal;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import com.bonus.common.core.web.domain.AjaxResult;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
import org.apache.commons.lang3.RegExUtils;
|
|
||||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
|
||||||
import org.apache.poi.ss.usermodel.BorderStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.CellType;
|
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
||||||
import org.apache.poi.ss.usermodel.DataFormat;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidation;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationConstraint;
|
|
||||||
import org.apache.poi.ss.usermodel.DataValidationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.DateUtil;
|
|
||||||
import org.apache.poi.ss.usermodel.Drawing;
|
|
||||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
||||||
import org.apache.poi.ss.usermodel.Name;
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
|
||||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
|
||||||
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
|
||||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
|
||||||
import org.apache.poi.util.IOUtils;
|
|
||||||
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
|
||||||
import org.apache.poi.xssf.usermodel.XSSFDataValidation;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import com.bonus.common.core.annotation.Excel;
|
|
||||||
import com.bonus.common.core.annotation.Excel.ColumnType;
|
|
||||||
import com.bonus.common.core.annotation.Excel.Type;
|
|
||||||
import com.bonus.common.core.annotation.Excels;
|
|
||||||
import com.bonus.common.core.exception.UtilException;
|
|
||||||
import com.bonus.common.core.text.Convert;
|
|
||||||
import com.bonus.common.core.utils.DateUtils;
|
|
||||||
import com.bonus.common.core.utils.StringUtils;
|
|
||||||
import com.bonus.common.core.utils.file.FileTypeUtils;
|
|
||||||
import com.bonus.common.core.utils.file.ImageUtils;
|
|
||||||
import com.bonus.common.core.utils.reflect.ReflectUtils;
|
|
||||||
import com.bonus.common.core.constant.Constants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel相关处理
|
* Excel相关处理
|
||||||
|
|
@ -1654,4 +1626,31 @@ public class ExcelUtil<T>
|
||||||
// 如果遍历完所有行都没有找到非空单元格,则返回true
|
// 如果遍历完所有行都没有找到非空单元格,则返回true
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展:为已有Workbook添加新Sheet(用于多Sheet导出)
|
||||||
|
* @param wb 已存在的Workbook
|
||||||
|
* @param list 新Sheet的数据
|
||||||
|
* @param sheetName 新Sheet名称
|
||||||
|
* @param title 新Sheet标题(可为空)
|
||||||
|
*/
|
||||||
|
public void addSheet(Workbook wb, List<T> list, String sheetName, String title) {
|
||||||
|
this.wb = wb; // 复用已有Workbook
|
||||||
|
this.list = list;
|
||||||
|
this.sheetName = sheetName;
|
||||||
|
this.title = title;
|
||||||
|
this.type = Type.EXPORT;
|
||||||
|
|
||||||
|
// 创建新Sheet
|
||||||
|
this.sheet = wb.createSheet(sheetName);
|
||||||
|
// 重新初始化字段和样式
|
||||||
|
createExcelField();
|
||||||
|
this.styles = createStyles(wb); // 基于已有Workbook创建样式
|
||||||
|
|
||||||
|
// 写入新Sheet的标题、表头和数据
|
||||||
|
createTitle();
|
||||||
|
createSubHead();
|
||||||
|
writeSheet(); // 写入表头和数据
|
||||||
|
addStatisticsRow(); // 写入合计行(若配置了isStatistics=true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
package com.bonus.bmw.controller;
|
package com.bonus.bmw.controller;
|
||||||
|
|
||||||
import com.alibaba.excel.EasyExcel;
|
|
||||||
import com.alibaba.excel.ExcelWriter;
|
|
||||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
||||||
import com.bonus.bmw.domain.dto.FileBasicMsgDto;
|
import com.bonus.bmw.domain.dto.FileBasicMsgDto;
|
||||||
import com.bonus.bmw.domain.dto.WebFileDto;
|
import com.bonus.bmw.domain.dto.WebFileDto;
|
||||||
|
import com.bonus.bmw.domain.dto.WorkerAttDayVo;
|
||||||
import com.bonus.bmw.domain.po.BmSubContract;
|
import com.bonus.bmw.domain.po.BmSubContract;
|
||||||
import com.bonus.bmw.domain.po.MapBeanPo;
|
import com.bonus.bmw.domain.po.MapBeanPo;
|
||||||
import com.bonus.bmw.domain.po.PmProject;
|
import com.bonus.bmw.domain.po.PmProject;
|
||||||
|
|
@ -48,6 +46,8 @@ public class PmProjectController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private PmProjectService pmProjectService;
|
private PmProjectService pmProjectService;
|
||||||
|
|
||||||
|
private List<Object[]> fields;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标段工程列表
|
* 标段工程列表
|
||||||
*/
|
*/
|
||||||
|
|
@ -451,8 +451,65 @@ public class PmProjectController extends BaseController {
|
||||||
public void exportUserAttendance(HttpServletResponse response, UserAttendanceVo userAttendanceVo) {
|
public void exportUserAttendance(HttpServletResponse response, UserAttendanceVo userAttendanceVo) {
|
||||||
try {
|
try {
|
||||||
List<UserAttendanceVo> res = pmProjectService.getUserAttendanceList(userAttendanceVo);
|
List<UserAttendanceVo> res = pmProjectService.getUserAttendanceList(userAttendanceVo);
|
||||||
ExcelUtil<UserAttendanceVo> util = new ExcelUtil<UserAttendanceVo>(UserAttendanceVo.class);
|
if (res.size()>0){
|
||||||
util.exportExcel(response, res, "分包人员考勤明细");
|
// 1. 设置响应头:告诉浏览器这是下载文件,而非直接打开
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); // Excel 2007+ 格式
|
||||||
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
// 文件名编码(解决中文乱码问题)
|
||||||
|
String fileName = URLEncoder.encode("分包人员考勤表.xlsx", "UTF-8");
|
||||||
|
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + fileName);
|
||||||
|
// 创建工作簿
|
||||||
|
Workbook workbook = new SXSSFWorkbook();
|
||||||
|
// 创建工作表
|
||||||
|
Sheet sheet = workbook.createSheet("分包人员考勤明细表");
|
||||||
|
String attendanceDay = res.get(0).getAttendanceDay();
|
||||||
|
List<WorkerAttDayVo> WorkerAttDayVoList = FastJsonHelper.jsonArrStrToBeanList(attendanceDay, WorkerAttDayVo.class);
|
||||||
|
// 构建表头
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
ArrayList<Object> headers = new ArrayList<>();
|
||||||
|
headers.add("项目名称");
|
||||||
|
headers.add("分包队伍全称");
|
||||||
|
headers.add("姓名");
|
||||||
|
headers.add("身份证号");
|
||||||
|
headers.add("职务/工种");
|
||||||
|
for (WorkerAttDayVo workerAttDayVo:WorkerAttDayVoList) {
|
||||||
|
headers.add(workerAttDayVo.getDay());
|
||||||
|
}
|
||||||
|
headers.add("出勤天数");
|
||||||
|
headers.add("签字");
|
||||||
|
headers.add("其他备注");
|
||||||
|
CellStyle headerCellStyle = createExcelUtilHeaderStyle(workbook);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
Cell cell = headerRow.createCell(i);
|
||||||
|
cell.setCellValue(headers.get(i).toString());
|
||||||
|
cell.setCellStyle(headerCellStyle); // 应用标准表头样式
|
||||||
|
}
|
||||||
|
CellStyle dataCellStyle = createExcelUtilDataStyle(workbook);
|
||||||
|
// 填充数据行
|
||||||
|
for (int i = 0; i < res.size(); i++) {
|
||||||
|
UserAttendanceVo userAttendanceVoNew = res.get(i);
|
||||||
|
Row dataRow = sheet.createRow(i + 1);
|
||||||
|
String attendanceDayNew = res.get(i).getAttendanceDay();
|
||||||
|
List<WorkerAttDayVo> WorkerAttDayVoNewList = FastJsonHelper.jsonArrStrToBeanList(attendanceDayNew, WorkerAttDayVo.class);
|
||||||
|
dataRow.createCell(0).setCellValue(userAttendanceVoNew.getProName());
|
||||||
|
dataRow.createCell(1).setCellValue(userAttendanceVoNew.getSubName());
|
||||||
|
dataRow.createCell(2).setCellValue(userAttendanceVoNew.getUserName());
|
||||||
|
dataRow.createCell(3).setCellValue(userAttendanceVoNew.getIdCard());
|
||||||
|
dataRow.createCell(4).setCellValue(userAttendanceVoNew.getWorkName());
|
||||||
|
|
||||||
|
// 填充出勤天数
|
||||||
|
for (int j = 0; j < WorkerAttDayVoNewList.size(); j++) {
|
||||||
|
dataRow.createCell(5 + j).setCellValue((WorkerAttDayVoNewList.get(j).getIsAtt()));
|
||||||
|
}
|
||||||
|
dataRow.createCell(5+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getAttendanceNum());
|
||||||
|
dataRow.createCell(6+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getSignature());
|
||||||
|
dataRow.createCell(7+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getRemark());
|
||||||
|
}
|
||||||
|
OutputStream outputStream = response.getOutputStream();
|
||||||
|
workbook.write(outputStream);
|
||||||
|
// 刷新流,确保数据完全输出
|
||||||
|
outputStream.flush();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.toString(), e);
|
logger.error(e.toString(), e);
|
||||||
}
|
}
|
||||||
|
|
@ -478,50 +535,217 @@ public class PmProjectController extends BaseController {
|
||||||
*/
|
*/
|
||||||
@PostMapping("/exportThreeAndOne")
|
@PostMapping("/exportThreeAndOne")
|
||||||
@SysLog(title = "三表一册", businessType = OperaType.EXPORT, module = "三表一册->导出三表一册")
|
@SysLog(title = "三表一册", businessType = OperaType.EXPORT, module = "三表一册->导出三表一册")
|
||||||
public void exportThreeAndOne(HttpServletResponse response, UserWagePayVo userWagePayVo) {
|
public void exportThreeAndOne(HttpServletResponse response, UserWagePayVo userWagePayVo) throws IOException {
|
||||||
|
//农民工工资支付表
|
||||||
|
List<UserWagePayVo> userWagePayList = pmProjectService.getUserWagePayList(userWagePayVo);
|
||||||
|
//农民工实名制工资信息报审
|
||||||
|
UserSalaryApprovalVo userSalaryApprovalVo = new UserSalaryApprovalVo();
|
||||||
|
userSalaryApprovalVo.setMonthId(Long.valueOf(userWagePayVo.getMonthId()));
|
||||||
|
List<UserSalaryApprovalVo> userSalaryApprovalList = pmProjectService.getUserSalaryApprovalList(userSalaryApprovalVo);
|
||||||
|
//分包人员考勤明细
|
||||||
|
UserAttendanceVo userAttendanceVo = new UserAttendanceVo();
|
||||||
|
userAttendanceVo.setMonthId(Long.valueOf(userWagePayVo.getMonthId()));
|
||||||
|
List<UserAttendanceVo> userAttendanceList = pmProjectService.getUserAttendanceList(userAttendanceVo);
|
||||||
|
//农民工花名册
|
||||||
|
ProMonthTableRosterVo proMonthTableRosterVo = new ProMonthTableRosterVo();
|
||||||
|
proMonthTableRosterVo.setMonthId(Long.valueOf(userWagePayVo.getMonthId()));
|
||||||
|
List<ProMonthTableRosterVo> proMonthTableRosterList = pmProjectService.getProMonthTableRosterList(proMonthTableRosterVo);
|
||||||
|
// 2. 设置响应头(下载Excel)
|
||||||
|
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
|
response.setCharacterEncoding("utf-8");
|
||||||
|
// 文件名编码(避免中文乱码)
|
||||||
|
String fileName = URLEncoder.encode("三表一册", "UTF-8").replaceAll("\\+", "%20");
|
||||||
|
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||||
|
|
||||||
|
// 3. 创建全局Workbook(复用,用于多Sheet)
|
||||||
|
Workbook wb = new SXSSFWorkbook(); // SXSSFWorkbook:大数据量导出(避免OOM)
|
||||||
try {
|
try {
|
||||||
// 设置响应头
|
// 4. 为每个Sheet创建ExcelUtil并添加到Workbook
|
||||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
// 4.1 Sheet1:农民工工资支付表
|
||||||
response.setCharacterEncoding("utf-8");
|
ExcelUtil<UserWagePayVo> wagePayExcel = new ExcelUtil<>(UserWagePayVo.class);
|
||||||
String fileName = URLEncoder.encode("三表一册", "UTF-8").replaceAll("\\+", "%20");
|
wagePayExcel.addSheet(wb, userWagePayList, "农民工工资支付", null);
|
||||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
|
||||||
//农民工工资支付表
|
// 4.2 Sheet2:农民工实名制工资信息报审
|
||||||
List<UserWagePayVo> userWagePayList = pmProjectService.getUserWagePayList(userWagePayVo);
|
ExcelUtil<UserSalaryApprovalVo> salaryApprovalExcel = new ExcelUtil<>(UserSalaryApprovalVo.class);
|
||||||
//农民工实名制工资信息报审
|
salaryApprovalExcel.addSheet(wb, userSalaryApprovalList, "农民工实名制工资信息报审", null);
|
||||||
UserSalaryApprovalVo userSalaryApprovalVo = new UserSalaryApprovalVo();
|
|
||||||
List<UserSalaryApprovalVo> userSalaryApprovalList = pmProjectService.getUserSalaryApprovalList(userSalaryApprovalVo);
|
// 4.3 Sheet3:分包人员考勤明细
|
||||||
//分包人员考勤明细
|
/*ExcelUtil<UserAttendanceVo> attendanceExcel = new ExcelUtil<>(UserAttendanceVo.class);
|
||||||
UserAttendanceVo userAttendanceVo = new UserAttendanceVo();
|
attendanceExcel.addSheet(wb, userAttendanceList, "分包人员考勤明细", null);*/
|
||||||
List<UserAttendanceVo> userAttendanceList = pmProjectService.getUserAttendanceList(userAttendanceVo);
|
addSheet(wb, userAttendanceList, "分包人员考勤明细", response);
|
||||||
//农民工花名册
|
// 4.4 Sheet4:农民工花名册
|
||||||
ProMonthTableRosterVo proMonthTableRosterVo = new ProMonthTableRosterVo();
|
ExcelUtil<ProMonthTableRosterVo> rosterExcel = new ExcelUtil<>(ProMonthTableRosterVo.class);
|
||||||
List<ProMonthTableRosterVo> proMonthTableRosterList = pmProjectService.getProMonthTableRosterList(proMonthTableRosterVo);
|
rosterExcel.addSheet(wb, proMonthTableRosterList, "农民工花名册", null);
|
||||||
// 获取ExcelWriter对象
|
|
||||||
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
|
// 5. 将Workbook写入响应流
|
||||||
// 第一个sheet
|
wb.write(response.getOutputStream());
|
||||||
WriteSheet writeSheet1 = EasyExcel.writerSheet(0, "农民工工资支付")
|
response.flushBuffer(); // 强制刷新流
|
||||||
.head(UserWagePayVo.class)
|
|
||||||
.build();
|
|
||||||
excelWriter.write(userWagePayList, writeSheet1);
|
|
||||||
// 第二个sheet
|
|
||||||
WriteSheet writeSheet2 = EasyExcel.writerSheet(1, "农民工实名制工资信息报审")
|
|
||||||
.head(UserSalaryApprovalVo.class)
|
|
||||||
.build();
|
|
||||||
excelWriter.write(userSalaryApprovalList, writeSheet2);
|
|
||||||
// 第三个sheet
|
|
||||||
WriteSheet writeSheet3 = EasyExcel.writerSheet(2, "分包人员考勤明细")
|
|
||||||
.head(UserAttendanceVo.class)
|
|
||||||
.build();
|
|
||||||
excelWriter.write(userAttendanceList, writeSheet3);
|
|
||||||
// 第四个sheet
|
|
||||||
WriteSheet writeSheet4 = EasyExcel.writerSheet(3, "农民工花名册")
|
|
||||||
.head(ProMonthTableRosterVo.class)
|
|
||||||
.build();
|
|
||||||
excelWriter.write(proMonthTableRosterList, writeSheet4);
|
|
||||||
// 关闭流
|
|
||||||
excelWriter.finish();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error(e.toString(), e);
|
e.printStackTrace();
|
||||||
|
// 异常处理:返回错误信息
|
||||||
|
response.reset();
|
||||||
|
response.setContentType("text/plain;charset=utf-8");
|
||||||
|
response.getWriter().write("Excel导出失败:" + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
// 关闭流(SXSSFWorkbook需手动清理临时文件)
|
||||||
|
if (wb != null) {
|
||||||
|
wb.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扩展:为已有Workbook添加新Sheet(用于多Sheet导出)
|
||||||
|
* @param wb 已存在的Workbook
|
||||||
|
* @param list 新Sheet的数据
|
||||||
|
* @param sheetName 新Sheet名称
|
||||||
|
*/
|
||||||
|
public void addSheet(Workbook wb, List<UserAttendanceVo> list, String sheetName, HttpServletResponse response) throws IOException {
|
||||||
|
// 创建工作表
|
||||||
|
|
||||||
|
Sheet sheet = wb.createSheet(sheetName);
|
||||||
|
String attendanceDay = list.get(0).getAttendanceDay();
|
||||||
|
List<WorkerAttDayVo> WorkerAttDayVoList = FastJsonHelper.jsonArrStrToBeanList(attendanceDay, WorkerAttDayVo.class);
|
||||||
|
// 构建表头
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
ArrayList<Object> headers = new ArrayList<>();
|
||||||
|
headers.add("项目名称");
|
||||||
|
headers.add("分包队伍全称");
|
||||||
|
headers.add("姓名");
|
||||||
|
headers.add("身份证号");
|
||||||
|
headers.add("职务/工种");
|
||||||
|
for (WorkerAttDayVo workerAttDayVo:WorkerAttDayVoList) {
|
||||||
|
headers.add(workerAttDayVo.getDay());
|
||||||
|
}
|
||||||
|
headers.add("出勤天数");
|
||||||
|
headers.add("签字");
|
||||||
|
headers.add("其他备注");
|
||||||
|
CellStyle headerCellStyle = createExcelUtilHeaderStyle(wb);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
Cell cell = headerRow.createCell(i);
|
||||||
|
cell.setCellValue(headers.get(i).toString());
|
||||||
|
cell.setCellStyle(headerCellStyle); // 应用标准表头样式
|
||||||
|
}
|
||||||
|
CellStyle dataCellStyle = createExcelUtilDataStyle(wb);
|
||||||
|
// 填充数据行
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
UserAttendanceVo userAttendanceVoNew = list.get(i);
|
||||||
|
Row dataRow = sheet.createRow(i + 1);
|
||||||
|
String attendanceDayNew = list.get(i).getAttendanceDay();
|
||||||
|
List<WorkerAttDayVo> WorkerAttDayVoNewList = FastJsonHelper.jsonArrStrToBeanList(attendanceDayNew, WorkerAttDayVo.class);
|
||||||
|
dataRow.setRowStyle(dataCellStyle);
|
||||||
|
dataRow.createCell(0).setCellValue(userAttendanceVoNew.getProName());
|
||||||
|
dataRow.createCell(1).setCellValue(userAttendanceVoNew.getSubName());
|
||||||
|
dataRow.createCell(2).setCellValue(userAttendanceVoNew.getUserName());
|
||||||
|
dataRow.createCell(3).setCellValue(userAttendanceVoNew.getIdCard());
|
||||||
|
dataRow.createCell(4).setCellValue(userAttendanceVoNew.getWorkName());
|
||||||
|
|
||||||
|
// 填充出勤天数
|
||||||
|
for (int j = 0; j < WorkerAttDayVoNewList.size(); j++) {
|
||||||
|
dataRow.createCell(5 + j).setCellValue((WorkerAttDayVoNewList.get(j).getIsAtt()));
|
||||||
|
}
|
||||||
|
dataRow.createCell(5+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getAttendanceNum());
|
||||||
|
dataRow.createCell(6+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getSignature());
|
||||||
|
dataRow.createCell(7+WorkerAttDayVoNewList.size()).setCellValue(userAttendanceVoNew.getRemark());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 预定义颜色索引(与Excel内置颜色对应)
|
||||||
|
private static final short GREY_BORDER_INDEX = IndexedColors.GREY_50_PERCENT.getIndex();
|
||||||
|
private static final short BLACK_FONT_INDEX = IndexedColors.WHITE.getIndex();
|
||||||
|
private static final short GREY_HEADER_BACKGROUND_INDEX = IndexedColors.GREY_25_PERCENT.getIndex();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复用ExcelUtil的表头样式:边框+居中对齐+灰色背景+加粗字体
|
||||||
|
* @param workbook 工作簿对象
|
||||||
|
* @return 标准表头样式
|
||||||
|
*/
|
||||||
|
public static CellStyle createExcelUtilHeaderStyle(Workbook workbook) {
|
||||||
|
CellStyle style = workbook.createCellStyle();
|
||||||
|
|
||||||
|
// 1. 边框配置(使用short类型的颜色索引)
|
||||||
|
style.setBorderRight(BorderStyle.THIN);
|
||||||
|
style.setRightBorderColor(GREY_BORDER_INDEX); // 灰色边框
|
||||||
|
style.setBorderLeft(BorderStyle.THIN);
|
||||||
|
style.setLeftBorderColor(GREY_BORDER_INDEX);
|
||||||
|
style.setBorderTop(BorderStyle.THIN);
|
||||||
|
style.setTopBorderColor(GREY_BORDER_INDEX);
|
||||||
|
style.setBorderBottom(BorderStyle.THIN);
|
||||||
|
style.setBottomBorderColor(GREY_BORDER_INDEX);
|
||||||
|
|
||||||
|
// 2. 对齐配置
|
||||||
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
|
// 3. 背景色配置(使用Excel内置颜色索引)
|
||||||
|
style.setFillForegroundColor(GREY_BORDER_INDEX);
|
||||||
|
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||||
|
|
||||||
|
// 4. 字体配置(字体颜色使用short类型索引)
|
||||||
|
Font font = workbook.createFont();
|
||||||
|
font.setFontName("Arial");
|
||||||
|
font.setFontHeightInPoints((short) 10);
|
||||||
|
font.setBold(true);
|
||||||
|
font.setColor(BLACK_FONT_INDEX); // 黑色字体
|
||||||
|
style.setFont(font);
|
||||||
|
|
||||||
|
// 5. 文本格式
|
||||||
|
DataFormat dataFormat = workbook.createDataFormat();
|
||||||
|
style.setDataFormat(dataFormat.getFormat("@"));
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 复用ExcelUtil的数据行样式:边框+居中对齐+默认背景
|
||||||
|
* @param workbook 工作簿对象
|
||||||
|
* @return 标准数据行样式
|
||||||
|
*/
|
||||||
|
public static CellStyle createExcelUtilDataStyle(Workbook workbook) {
|
||||||
|
CellStyle style = workbook.createCellStyle();
|
||||||
|
|
||||||
|
// 1. 边框配置(使用相同的灰色边框索引)
|
||||||
|
style.setBorderRight(BorderStyle.THIN);
|
||||||
|
style.setRightBorderColor(GREY_BORDER_INDEX);
|
||||||
|
style.setBorderLeft(BorderStyle.THIN);
|
||||||
|
style.setLeftBorderColor(GREY_BORDER_INDEX);
|
||||||
|
style.setBorderTop(BorderStyle.THIN);
|
||||||
|
style.setTopBorderColor(GREY_BORDER_INDEX);
|
||||||
|
style.setBorderBottom(BorderStyle.THIN);
|
||||||
|
style.setBottomBorderColor(GREY_BORDER_INDEX);
|
||||||
|
|
||||||
|
// 2. 对齐配置
|
||||||
|
style.setAlignment(HorizontalAlignment.CENTER);
|
||||||
|
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||||
|
|
||||||
|
// 3. 字体配置
|
||||||
|
Font font = workbook.createFont();
|
||||||
|
font.setFontName("Arial");
|
||||||
|
font.setFontHeightInPoints((short) 10);
|
||||||
|
font.setBold(false);
|
||||||
|
font.setColor(BLACK_FONT_INDEX);
|
||||||
|
style.setFont(font);
|
||||||
|
|
||||||
|
// 4. 文本格式
|
||||||
|
DataFormat dataFormat = workbook.createDataFormat();
|
||||||
|
style.setDataFormat(dataFormat.getFormat("@"));
|
||||||
|
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 封装数据单元格赋值逻辑
|
||||||
|
* @param row 数据行
|
||||||
|
* @param column 列索引
|
||||||
|
* @param value 单元格值
|
||||||
|
* @param style 单元格样式
|
||||||
|
*/
|
||||||
|
public static void setDataCell(Row row, int column, Object value, CellStyle style) {
|
||||||
|
Cell cell = row.createCell(column);
|
||||||
|
cell.setCellStyle(style);
|
||||||
|
|
||||||
|
// 处理null值
|
||||||
|
String cellValue = value == null ? "" : value.toString();
|
||||||
|
cell.setCellValue(cellValue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.bonus.bmw.domain.dto;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class WorkerAttDayVo {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日期
|
||||||
|
*/
|
||||||
|
private String day;
|
||||||
|
/**
|
||||||
|
* 是否在场
|
||||||
|
*/
|
||||||
|
private String isEin;
|
||||||
|
/**
|
||||||
|
* 是否打卡
|
||||||
|
*/
|
||||||
|
private String isAtt;
|
||||||
|
/**
|
||||||
|
* 是否为补卡
|
||||||
|
*/
|
||||||
|
private String isRepair;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -99,4 +99,16 @@ public class UserAttendanceVo {
|
||||||
* 考勤天数=打卡+补卡天数
|
* 考勤天数=打卡+补卡天数
|
||||||
*/
|
*/
|
||||||
private int attendanceNum;
|
private int attendanceNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本人签字
|
||||||
|
*/
|
||||||
|
private String signature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 考备注
|
||||||
|
*/
|
||||||
|
private String remark;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -275,7 +275,7 @@
|
||||||
</select>
|
</select>
|
||||||
<select id="getUserAttendanceList" resultType="com.bonus.bmw.domain.vo.UserAttendanceVo">
|
<select id="getUserAttendanceList" resultType="com.bonus.bmw.domain.vo.UserAttendanceVo">
|
||||||
select id,pro_id,`month`,pro_name,month_day,sub_id,sub_name,user_name,
|
select id,pro_id,`month`,pro_name,month_day,sub_id,sub_name,user_name,
|
||||||
id_card,work_name,work_id,attendance_day,check_day,repair_num,attendance_num
|
id_card,work_name,work_id,attendance_day,check_day,repair_num,attendance_num,signature,remark
|
||||||
from tb_pro_month_table_roster where month_id = #{monthId}
|
from tb_pro_month_table_roster where month_id = #{monthId}
|
||||||
<if test="subName != null">
|
<if test="subName != null">
|
||||||
and sub_name LIKE CONCAT('%', #{subName}, '%')
|
and sub_name LIKE CONCAT('%', #{subName}, '%')
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue