From 376582f73c1b8ef8db17a281dd7a2319a7b663f8 Mon Sep 17 00:00:00 2001 From: fl <3098731433@qq.com> Date: Wed, 4 Dec 2024 17:14:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/poi/MultiSheetExcelExporter.java | 4 +- .../AttDetailByMonthController.java | 158 ++++++++++++++++-- .../system/att/entity/OrgChangeBean.java | 12 +- .../system/download/ExportFileController.java | 37 ++-- .../resources/mapper/att/OrgChangeMapper.xml | 8 +- 5 files changed, 182 insertions(+), 37 deletions(-) diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/poi/MultiSheetExcelExporter.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/poi/MultiSheetExcelExporter.java index 0e2fd08..8cbcc6e 100644 --- a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/poi/MultiSheetExcelExporter.java +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/utils/poi/MultiSheetExcelExporter.java @@ -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); } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/controller/AttDetailByMonthController.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/controller/AttDetailByMonthController.java index 4025175..8290d4a 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/controller/AttDetailByMonthController.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/controller/AttDetailByMonthController.java @@ -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 list = attDetailByMonthService.selectAttDetailList(data); - ExcelUtil util = new ExcelUtil(AttDetailByMonthBean.class); - util.exportExcel(response, list, "月异常报表"); - }catch (Exception e){ - log.error(e.toString(),e); + public void export(HttpServletResponse response, AttDetailByMonthBean bean) { +// try{ +// List list = attDetailByMonthService.selectAttDetailList(data); +// ExcelUtil util = new ExcelUtil(AttDetailByMonthBean.class); +// util.exportExcel(response, list, "月异常报表"); +// }catch (Exception e){ +// log.error(e.toString(),e); +// } + + try { + MultiSheetExcelExporter exporter = new MultiSheetExcelExporter(); + List attDayReportList = attDetailByMonthService.selectAttDetailList(bean); + Sheet departmentSheet1 = exporter.createSheet("月异常报表详情"); + List departmentHeaders1 = Arrays.asList("序号", "姓名", "所属部门", "考勤月", "应考勤天数", "正常打卡天数", + "迟到天数", "早退天数", "矿工天数", "打卡地异常天数", "出入异常天数"); + exporter.addHeaderRow(departmentSheet1, departmentHeaders1); + List> departmentData1 = new ArrayList<>(); + for (int i = 0; i < attDayReportList.size(); i++) { + Map 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 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 attStatus = getStringStringMap(); + if (StringHelper.isNotEmpty(bean.getAttCurrentMonth())) { + List 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 list = attDetailByMonthService.getDetailList(dayTable); + Sheet departmentSheet2 = exporter.createSheet(entry.getValue()); + List departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址"); + exporter.addHeaderRow(departmentSheet2, departmentHeaders2); + List> departmentData2 = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + Map 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 getMonthFirstAndLast(String monthString) { + List 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 getStringStringMap() { + Map 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; + } } diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/entity/OrgChangeBean.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/entity/OrgChangeBean.java index a008a39..e5365bb 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/entity/OrgChangeBean.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/att/entity/OrgChangeBean.java @@ -69,7 +69,17 @@ public class OrgChangeBean { /** * 变更后考勤组编号 */ - private String newAttGroup; + private Long newAttGroup; + + /** + * 变更前考勤组 + */ + private String oldAttGroupName; + + /** + * 变更后考勤组 + */ + private String newAttGroupName; /** * 生效日期 diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/download/ExportFileController.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/download/ExportFileController.java index 3ffb35a..ab073cb 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/download/ExportFileController.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/download/ExportFileController.java @@ -471,7 +471,7 @@ public class ExportFileController { dayTable.setAttStatus(entry.getKey()); List list = attendanceDetailsService.getAttDayReportDetailsList(dayTable); Sheet departmentSheet2 = exporter.createSheet(entry.getValue()); - List departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "打卡日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址"); + List departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址"); exporter.addHeaderRow(departmentSheet2, departmentHeaders2); List> 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 list = attDetailByMonthService.getDetailList(dayTable); Sheet departmentSheet2 = exporter.createSheet(entry.getValue()); - List departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "打卡日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址"); + List departmentHeaders2 = Arrays.asList("序号", "姓名", "所属部门", "考勤日期", "上班打卡时间", "上班状态", "打卡地址", "下班打卡时间", "下班状态", "打卡地址"); exporter.addHeaderRow(departmentSheet2, departmentHeaders2); List> departmentData2 = new ArrayList<>(); -// for (int i = 0; i < list.size(); i++) { -// Map 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 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) { diff --git a/bonus-modules/bonus-system/src/main/resources/mapper/att/OrgChangeMapper.xml b/bonus-modules/bonus-system/src/main/resources/mapper/att/OrgChangeMapper.xml index 8d8f586..32741e2 100644 --- a/bonus-modules/bonus-system/src/main/resources/mapper/att/OrgChangeMapper.xml +++ b/bonus-modules/bonus-system/src/main/resources/mapper/att/OrgChangeMapper.xml @@ -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