导出页面

This commit is contained in:
fl 2024-12-04 17:14:58 +08:00
parent e7b8c0872c
commit 376582f73c
5 changed files with 182 additions and 37 deletions

View File

@ -6,6 +6,7 @@ import org.apache.commons.io.IOUtils;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@ -69,8 +70,7 @@ public class MultiSheetExcelExporter {
public void exportToResponse(HttpServletResponse response, String fileName) throws IOException {
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName + ".xlsx");
response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(fileName + ".xlsx", "UTF-8"));
workbook.write(response.getOutputStream());
IOUtils.closeQuietly(workbook);
}

View File

@ -1,6 +1,8 @@
package com.bonus.system.att.controller;
import com.bonus.common.core.utils.StringHelper;
import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.utils.poi.MultiSheetExcelExporter;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
@ -9,18 +11,21 @@ import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.BusinessType;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.system.att.entity.AttDetailBean;
import com.bonus.system.att.entity.AttDetailByMonthBean;
import com.bonus.system.att.entity.AttDetailLeaveBean;
import com.bonus.system.att.entity.AttGroupBean;
import com.bonus.system.att.entity.*;
import com.bonus.system.att.service.AttDetailByMonthService;
import com.bonus.system.att.service.AttGroupService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.io.IOException;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.*;
/**
* 月异常报表
@ -68,15 +73,144 @@ public class AttDetailByMonthController extends BaseController {
@RequiresPermissions("att:detail:export")
@GetMapping("/export")
public void export(HttpServletResponse response, AttDetailByMonthBean data) {
try{
List<AttDetailByMonthBean> list = attDetailByMonthService.selectAttDetailList(data);
ExcelUtil<AttDetailByMonthBean> util = new ExcelUtil<AttDetailByMonthBean>(AttDetailByMonthBean.class);
util.exportExcel(response, list, "月异常报表");
}catch (Exception e){
log.error(e.toString(),e);
public void export(HttpServletResponse response, AttDetailByMonthBean bean) {
// try{
// List<AttDetailByMonthBean> list = attDetailByMonthService.selectAttDetailList(data);
// ExcelUtil<AttDetailByMonthBean> util = new ExcelUtil<AttDetailByMonthBean>(AttDetailByMonthBean.class);
// util.exportExcel(response, list, "月异常报表");
// }catch (Exception e){
// log.error(e.toString(),e);
// }
try {
MultiSheetExcelExporter exporter = new MultiSheetExcelExporter();
List<AttDetailByMonthBean> attDayReportList = attDetailByMonthService.selectAttDetailList(bean);
Sheet departmentSheet1 = exporter.createSheet("月异常报表详情");
List<String> departmentHeaders1 = Arrays.asList("序号", "姓名", "所属部门", "考勤月", "应考勤天数", "正常打卡天数",
"迟到天数", "早退天数", "矿工天数", "打卡地异常天数", "出入异常天数");
exporter.addHeaderRow(departmentSheet1, departmentHeaders1);
List<Map<String, Object>> departmentData1 = new ArrayList<>();
for (int i = 0; i < attDayReportList.size(); i++) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("序号", i + 1);
map.put("姓名", attDayReportList.get(i).getName());
map.put("所属部门", attDayReportList.get(i).getOrgName());
map.put("考勤月", attDayReportList.get(i).getAttCurrentMonth());
map.put("应考勤天数", attDayReportList.get(i).getRequiredDays());
map.put("正常打卡天数", attDayReportList.get(i).getNormalNum());
map.put("迟到天数", attDayReportList.get(i).getLateNum());
map.put("早退天数", attDayReportList.get(i).getEarlyNum());
map.put("矿工天数", attDayReportList.get(i).getSkippingNum());
map.put("打卡地异常天数", attDayReportList.get(i).getAddressErrorNum());
map.put("出入异常天数", attDayReportList.get(i).getEinErrorNum());
departmentData1.add(map);
}
exporter.addDataRows(departmentSheet1, departmentData1, departmentHeaders1);
//详情的数据导出
Map<String, String> headers = new HashMap<>();
headers.put("1", "正常打卡");
headers.put("2", "迟到详情");
headers.put("3", "旷工详情");
headers.put("4", "早退详情");
headers.put("5", "轮休详情");
headers.put("6", "请假详情");
headers.put("7", "外出办事");
headers.put("8", "出入异常");
headers.put("9", "打卡地异常");
Map<String, String> attStatus = getStringStringMap();
if (StringHelper.isNotEmpty(bean.getAttCurrentMonth())) {
List<String> monthFirstAndLast = getMonthFirstAndLast(bean.getAttCurrentMonth());
AttDetailBean dayTable = new AttDetailBean();
dayTable.setStartDate(monthFirstAndLast.get(0));
dayTable.setEndDate(monthFirstAndLast.get(1));
headers.entrySet()
.forEach(entry -> {
dayTable.setAttStatis(Integer.parseInt(entry.getKey()));
List<AttDetailBean> list = attDetailByMonthService.getDetailList(dayTable);
Sheet departmentSheet2 = exporter.createSheet(entry.getValue());
List<String> departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址");
exporter.addHeaderRow(departmentSheet2, departmentHeaders2);
List<Map<String, Object>> departmentData2 = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("序号", i + 1);
map.put("姓名", list.get(i).getName());
map.put("所属部门", list.get(i).getOrgName());
map.put("考勤日期", list.get(i).getAttCurrent());
map.put("上班打卡时间", list.get(i).getGoWorkTime());
map.put("上班状态", attStatus.get(String.valueOf(list.get(i).getGoWorkStatus())));
map.put("上班打卡地址", list.get(i).getOffWorkAddress());
map.put("下班打卡时间", list.get(i).getOffWorkTime());
map.put("下班状态", attStatus.get(String.valueOf(list.get(i).getOffWorkStatus())));
map.put("下班打卡地址", list.get(i).getOffWorkAddress());
departmentData2.add(map);
}
exporter.addDataRows(departmentSheet2, departmentData2, departmentHeaders2);
});
// 导出Excel文件
exporter.exportToResponse(response, "月报表导出");
}
} catch (IOException e) {
e.printStackTrace();
}
}
private List<String> getMonthFirstAndLast(String monthString) {
List<String> months = new ArrayList<>();
// 定义日期格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
YearMonth yearMonth;
// 使用预定义的 ISO_LOCAL_DATE 格式 (yyyy-MM-dd)
DateTimeFormatter isoFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
try {
// 判空及默认为当月
if (monthString == null || monthString.trim().isEmpty()) {
// 如果字符串为空或仅包含空白字符取当前月份
yearMonth = YearMonth.from(LocalDate.now());
} else {
// 尝试将字符串解析为 YearMonth 对象
yearMonth = YearMonth.parse(monthString, formatter);
}
// 获取该月的第一天
LocalDate firstDayOfMonth = yearMonth.atDay(1);
// 获取该月的最后一天
LocalDate lastDayOfMonth = yearMonth.atEndOfMonth();
months.add(firstDayOfMonth.format(isoFormatter));
months.add(lastDayOfMonth.format(isoFormatter));
} catch (DateTimeParseException e) {
// 如果解析失败打印错误信息并使用当前月份
YearMonth currentYearMonth = YearMonth.from(LocalDate.now());
LocalDate firstDayOfCurrentMonth = currentYearMonth.atDay(1);
LocalDate lastDayOfCurrentMonth = currentYearMonth.atEndOfMonth();
months.add(firstDayOfCurrentMonth.format(isoFormatter));
months.add(lastDayOfCurrentMonth.format(isoFormatter));
}
return months;
}
private Map<String, String> getStringStringMap() {
Map<String, String> attStatus = new HashMap<>();
attStatus.put("1", "正常");
attStatus.put("2", "迟到");
attStatus.put("3", "旷工");
attStatus.put("4", "早退");
attStatus.put("5", "轮休");
attStatus.put("6", "请假");
attStatus.put("7", "外出");
attStatus.put("8", "出入异常");
attStatus.put("9", "打卡地异常");
attStatus.put("10", "出差");
attStatus.put("11", "法定节假日");
attStatus.put("12", "年休假");
attStatus.put("13", "探亲假");
attStatus.put("14", "事假");
attStatus.put("15", "病假");
attStatus.put("16", "产假");
attStatus.put("17", "婚假");
attStatus.put("18", "丧假");
return attStatus;
}
}

View File

@ -69,7 +69,17 @@ public class OrgChangeBean {
/**
* 变更后考勤组编号
*/
private String newAttGroup;
private Long newAttGroup;
/**
* 变更前考勤组
*/
private String oldAttGroupName;
/**
* 变更后考勤组
*/
private String newAttGroupName;
/**
* 生效日期

View File

@ -471,7 +471,7 @@ public class ExportFileController {
dayTable.setAttStatus(entry.getKey());
List<AttDataDetailsBean> list = attendanceDetailsService.getAttDayReportDetailsList(dayTable);
Sheet departmentSheet2 = exporter.createSheet(entry.getValue());
List<String> departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "打卡日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址");
List<String> departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址");
exporter.addHeaderRow(departmentSheet2, departmentHeaders2);
List<Map<String, Object>> departmentData2 = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
@ -479,7 +479,7 @@ public class ExportFileController {
map.put("序号", i + 1);
map.put("姓名", list.get(i).getUserName());
map.put("所属部门", list.get(i).getOrgName());
map.put("打卡日期", list.get(i).getAttCurrentDay());
map.put("考勤日期", list.get(i).getAttCurrentDay());
map.put("上班打卡时间", list.get(i).getToWorkAttCurrentTime());
map.put("上班状态", attStatus.get(list.get(i).getToWorkAttStatus()));
map.put("上班打卡地址", list.get(i).getToWorkAttAddress());
@ -594,29 +594,30 @@ public class ExportFileController {
dayTable.setEndDate(monthFirstAndLast.get(1));
headers.entrySet()
.forEach(entry -> {
dayTable.setAttStatis(Integer.parseInt(entry.getKey()));
List<AttDetailBean> list = attDetailByMonthService.getDetailList(dayTable);
Sheet departmentSheet2 = exporter.createSheet(entry.getValue());
List<String> departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "打卡日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址");
List<String> departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址");
exporter.addHeaderRow(departmentSheet2, departmentHeaders2);
List<Map<String, Object>> departmentData2 = new ArrayList<>();
// for (int i = 0; i < list.size(); i++) {
// Map<String, Object> map = new LinkedHashMap<>();
// map.put("序号", i + 1);
// map.put("姓名", list.get(i).getUserName());
// map.put("所属部门", list.get(i).getOrgName());
// map.put("打卡日期", list.get(i).getAttCurrentDay());
// map.put("上班打卡时间", list.get(i).getToWorkAttCurrentTime());
// map.put("上班状态", attStatus.get(list.get(i).getToWorkAttStatus()));
// map.put("上班打卡地址", list.get(i).getToWorkAttAddress());
// map.put("下班打卡时间", list.get(i).getOffWorkAttCurrentTime());
// map.put("下班状态", attStatus.get(list.get(i).getOffWorkAttStatus()));
// map.put("下班打卡地址", list.get(i).getOffWorkAttAddress());
// departmentData2.add(map);
// }
for (int i = 0; i < list.size(); i++) {
Map<String, Object> map = new LinkedHashMap<>();
map.put("序号", i + 1);
map.put("姓名", list.get(i).getName());
map.put("所属部门", list.get(i).getOrgName());
map.put("考勤日期", list.get(i).getAttCurrent());
map.put("上班打卡时间", list.get(i).getGoWorkTime());
map.put("上班状态", attStatus.get(String.valueOf(list.get(i).getGoWorkStatus())));
map.put("上班打卡地址", list.get(i).getOffWorkAddress());
map.put("下班打卡时间", list.get(i).getOffWorkTime());
map.put("下班状态", attStatus.get(String.valueOf(list.get(i).getOffWorkStatus())));
map.put("下班打卡地址", list.get(i).getOffWorkAddress());
departmentData2.add(map);
}
exporter.addDataRows(departmentSheet2, departmentData2, departmentHeaders2);
});
// 导出Excel文件
exporter.exportToResponse(response, "报表导出");
exporter.exportToResponse(response, "报表导出");
}
} catch (IOException e) {

View File

@ -9,8 +9,8 @@
su.user_name,
so.org_name AS oldOrgName,
so2.org_name AS newOrgName,
ag.group_name AS oldAttGroup,
ag2.group_name AS newAttGroup,
ag.group_name AS oldAttGroupName,
ag2.group_name AS newAttGroupName,
oc.*
FROM
org_change oc
@ -48,8 +48,8 @@
su.user_name,
so.org_name AS oldOrgName,
so2.org_name AS newOrgName,
ag.group_name AS oldAttGroup,
ag2.group_name AS newAttGroup,
ag.group_name AS oldAttGroupName,
ag2.group_name AS newAttGroupName,
oc.*
FROM
org_change oc