From fb71c959eb5d60460a0d78a6ea57d3985a83c3cb Mon Sep 17 00:00:00 2001 From: luojing Date: Mon, 4 Jan 2021 16:53:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=87=BA=E5=8B=A4=E7=8E=87=EF=BC=88=E4=B8=AA=E4=BA=BA=EF=BC=8C?= =?UTF-8?q?=E9=83=A8=E9=97=A8=EF=BC=8C=E5=85=AC=E5=8F=B8=EF=BC=89=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ActionExportPersonStatistic.java | 159 +++++++++++++++ .../ActionExportTopUnitStatistic.java | 168 ++++++++++++++++ .../ActionExportUnitSubNestedStatistic.java | 186 ++++++++++++++++++ .../control/jaxrs/attachment/BaseAction.java | 158 ++++++++++++++- .../ExceptionAttendanceStatisticProcess.java | 12 ++ .../attachment/ExceptionPersonNameEmpty.java | 12 ++ .../ExceptionQueryStatisticUnitNameEmpty.java | 12 ++ .../attachment/ExceptionTopUnitNameEmpty.java | 12 ++ .../attachment/FileImportExportAction.java | 63 ++++++ 9 files changed, 780 insertions(+), 2 deletions(-) create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportPersonStatistic.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportTopUnitStatistic.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportUnitSubNestedStatistic.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionAttendanceStatisticProcess.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionPersonNameEmpty.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionQueryStatisticUnitNameEmpty.java create mode 100644 o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionTopUnitNameEmpty.java diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportPersonStatistic.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportPersonStatistic.java new file mode 100644 index 0000000000..2eb1482f76 --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportPersonStatistic.java @@ -0,0 +1,159 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.attendance.entity.StatisticPersonForMonth; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoFile; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.base.core.project.tools.ListTools; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayOutputStream; +import java.util.List; + +public class ActionExportPersonStatistic extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionExportPersonStatistic.class); + + protected ActionResult execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception { + ActionResult result = new ActionResult<>(); + List ids = null; + List statisticPersonForMonth_list = null; + Workbook wb = null; + Wo wo = null; + String fileName = null; + String sheetName = null; + Boolean check = true; + + if ("(0)".equals(year)) { + year = null; + } + if ("(0)".equals(month)) { + month = null; + } + if( check ){ + if( name == null || name.isEmpty() ){ + check = false; + Exception exception = new ExceptionPersonNameEmpty(); + result.error( exception ); + } + } + + if( check ){ + try { + ids = attendanceStatisticServiceAdv.listPersonForMonthByUserYearAndMonth(name, year, month); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, + "系统根据人员姓名,年份和月份查询统计数据信息ID列表时发生异常.Name:"+name+", Year:"+year+", Month:" + month + ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + if( check ){ + if( ids != null && !ids.isEmpty() ){ + try { + statisticPersonForMonth_list = attendanceStatisticServiceAdv.listPersonForMonth(ids); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, "系统根据ID列表查询个人每月统计数据信息列表时发生异常." ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + } + + // 将结果组织成EXCEL + if( check ) { + fileName = "" + name + "的个人出勤率统计记录_"+year+"年"+month+"月.xls"; + sheetName = "个人出勤率统计记录"; + wb = composeDetail( fileName, sheetName, statisticPersonForMonth_list ); + } + + //输出数据信息 + if( check ) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + wb.write(bos); + wo = new Wo(bos.toByteArray(), + this.contentType(stream, fileName), + this.contentDisposition(stream, fileName)); + } finally { + bos.close(); + } + } + result.setData(wo); + return result; + } + + private Workbook composeDetail(String fileName, String sheetName, List statisticPersonForMonth_list) throws Exception { + Workbook wb = new HSSFWorkbook(); + Row row = null; + if (ListTools.isNotEmpty(statisticPersonForMonth_list)) { + // 创建新的表格 + Sheet sheet = wb.createSheet(sheetName); + // 先创建表头 + row = sheet.createRow(0); + row.createCell(0).setCellValue("顶层组织名称"); + row.createCell(1).setCellValue("组织名称"); + row.createCell(2).setCellValue("姓名"); + row.createCell(3).setCellValue("月份"); + row.createCell(4).setCellValue("上班打卡次数"); + row.createCell(5).setCellValue("下班打卡次数"); + row.createCell(6).setCellValue("出勤人天数"); + row.createCell(7).setCellValue("请假或外出报备人天数"); + row.createCell(8).setCellValue("缺勤人天数"); + row.createCell(9).setCellValue("迟到次数"); + row.createCell(10).setCellValue("工时不足人次"); + row.createCell(11).setCellValue("异常打卡人次"); + + logger.info("一共有"+statisticPersonForMonth_list.size()+"条请求记录可以输出。"); + for (int i = 0; i < statisticPersonForMonth_list.size(); i++) { + StatisticPersonForMonth statisticPersonForMonth = null; + statisticPersonForMonth = statisticPersonForMonth_list.get(i); + if( statisticPersonForMonth != null ){ + row = sheet.createRow(i + 1); + String topUnitName = statisticPersonForMonth.getTopUnitName(); + String unitName = statisticPersonForMonth.getUnitName(); + String empName = statisticPersonForMonth.getEmployeeName(); + if(StringUtils.isNotEmpty(topUnitName) && StringUtils.contains(topUnitName,"@")){ + topUnitName = topUnitName.split("@")[0]; + } + if(StringUtils.isNotEmpty(unitName) && StringUtils.contains(unitName,"@")){ + unitName = unitName.split("@")[0]; + } + if(StringUtils.isNotEmpty(empName) && StringUtils.contains(empName,"@")){ + empName = empName.split("@")[0]; + } + row.createCell(0).setCellValue(topUnitName); + row.createCell(1).setCellValue(unitName); + row.createCell(2).setCellValue(empName); + row.createCell(3).setCellValue(statisticPersonForMonth.getStatisticYear()+"-"+statisticPersonForMonth.getStatisticMonth()); + row.createCell(4).setCellValue(statisticPersonForMonth.getOnDutyTimes()); + row.createCell(5).setCellValue(statisticPersonForMonth.getOnDutyTimes()); + row.createCell(6).setCellValue(statisticPersonForMonth.getOnDutyDayCount()); + row.createCell(7).setCellValue(statisticPersonForMonth.getOnSelfHolidayCount()); + row.createCell(8).setCellValue(statisticPersonForMonth.getAbsenceDayCount()); + row.createCell(9).setCellValue(statisticPersonForMonth.getLateTimes()); + row.createCell(10).setCellValue(statisticPersonForMonth.getLackOfTimeCount()); + row.createCell(11).setCellValue(statisticPersonForMonth.getAbNormalDutyCount()); + } + } + + } + return wb; + } + + public static class Wo extends WoFile { + public Wo(byte[] bytes, String contentType, String contentDisposition) { + super(bytes, contentType, contentDisposition); + } + } + } diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportTopUnitStatistic.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportTopUnitStatistic.java new file mode 100644 index 0000000000..9625d5c1ec --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportTopUnitStatistic.java @@ -0,0 +1,168 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.attendance.entity.StatisticUnitForMonth; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoFile; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.base.core.project.tools.ListTools; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; + +public class ActionExportTopUnitStatistic extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionExportTopUnitStatistic.class); + + protected ActionResult execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception { + ActionResult result = new ActionResult<>(); + List ids = null; + List unitNames = new ArrayList(); + List statisticUnitForMonth_list = null; + Workbook wb = null; + Wo wo = null; + String fileName = null; + String sheetName = null; + Boolean check = true; + + if ("(0)".equals(year)) { + year = null; + } + if ("(0)".equals(month)) { + month = null; + } + if( check ){ + if( name == null || name.isEmpty() ){ + check = false; + Exception exception = new ExceptionTopUnitNameEmpty(); + result.error( exception ); + } + } + if( check ){ + try { + //根据顶层组织递归查询下级顶层组织经及顶层组织的顶级组织 + unitNames = getTopUnitNameList( name, unitNames, effectivePerson.getDebugger() ); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, + "根据顶层组织递归查询下级顶层组织经及顶层组织的顶级组织时发生异常!" + + "Name:" + name + + ", Units:" + unitNames ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + if( check ){ + if( unitNames == null ){ + unitNames = new ArrayList<>(); + } + unitNames.add( name ); + } + if( check ){ + try { + ids = attendanceStatisticServiceAdv.listUnitForMonthByUnitYearAndMonth( unitNames, year, month); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess(e, + "系统根据组织名称列表,年份和月份查询组织统计数据信息ID列表时发生异常.Name:"+unitNames+", Year:"+year+", Month:" + month + ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + if( check ){ + if( ids != null && !ids.isEmpty() ){ + try { + statisticUnitForMonth_list = attendanceStatisticServiceAdv.listUnitForMonth( ids ); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, "系统根据ID列表查询组织每月统计数据信息列表时发生异常." ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + } + + // 将结果组织成EXCEL + if( check ) { + fileName = "" + name + "的出勤率统计记录_"+year+"年"+month+"月.xls"; + sheetName = "公司出勤率统计记录"; + wb = composeDetail( fileName, sheetName, statisticUnitForMonth_list ); + } + + //输出数据信息 + if( check ) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + wb.write(bos); + wo = new Wo(bos.toByteArray(), + this.contentType(stream, fileName), + this.contentDisposition(stream, fileName)); + } finally { + bos.close(); + } + } + result.setData(wo); + return result; + } + + private Workbook composeDetail(String fileName, String sheetName, List statisticUnitForMonth_list) throws Exception { + Workbook wb = new HSSFWorkbook(); + Row row = null; + if (ListTools.isNotEmpty(statisticUnitForMonth_list)) { + // 创建新的表格 + Sheet sheet = wb.createSheet(sheetName); + // 先创建表头 + row = sheet.createRow(0); + row.createCell(0).setCellValue("公司"); + row.createCell(1).setCellValue("月份"); + row.createCell(2).setCellValue("上班打卡次数"); + row.createCell(3).setCellValue("下班打卡次数"); + row.createCell(4).setCellValue("出勤人天数"); + row.createCell(5).setCellValue("请假或外出报备人天数"); + row.createCell(6).setCellValue("缺勤人天数"); + row.createCell(7).setCellValue("迟到次数"); + row.createCell(8).setCellValue("工时不足人次"); + row.createCell(9).setCellValue("异常打卡人次"); + + logger.info("一共有"+statisticUnitForMonth_list.size()+"条请求记录可以输出。"); + for (int i = 0; i < statisticUnitForMonth_list.size(); i++) { + StatisticUnitForMonth statisticUnitForMonth = null; + statisticUnitForMonth = statisticUnitForMonth_list.get(i); + if( statisticUnitForMonth != null ){ + row = sheet.createRow(i + 1); + String topUnitName = statisticUnitForMonth.getTopUnitName(); + if(StringUtils.isNotEmpty(topUnitName) && StringUtils.contains(topUnitName,"@")){ + topUnitName = topUnitName.split("@")[0]; + } + row.createCell(0).setCellValue(topUnitName); + row.createCell(1).setCellValue(statisticUnitForMonth.getStatisticYear()+"-"+statisticUnitForMonth.getStatisticMonth()); + row.createCell(2).setCellValue(statisticUnitForMonth.getOnDutyCount()); + row.createCell(3).setCellValue(statisticUnitForMonth.getOffDutyCount()); + row.createCell(4).setCellValue(statisticUnitForMonth.getOnDutyEmployeeCount()); + row.createCell(5).setCellValue(statisticUnitForMonth.getOnSelfHolidayCount()); + row.createCell(6).setCellValue(statisticUnitForMonth.getAbsenceDayCount()); + row.createCell(7).setCellValue(statisticUnitForMonth.getLateCount()); + row.createCell(8).setCellValue(statisticUnitForMonth.getLackOfTimeCount()); + row.createCell(9).setCellValue(statisticUnitForMonth.getAbNormalDutyCount()); + } + } + } + return wb; + } + + + public static class Wo extends WoFile { + public Wo(byte[] bytes, String contentType, String contentDisposition) { + super(bytes, contentType, contentDisposition); + } + } + } diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportUnitSubNestedStatistic.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportUnitSubNestedStatistic.java new file mode 100644 index 0000000000..bc0826c259 --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ActionExportUnitSubNestedStatistic.java @@ -0,0 +1,186 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.attendance.entity.StatisticPersonForMonth; +import com.x.base.core.project.http.ActionResult; +import com.x.base.core.project.http.EffectivePerson; +import com.x.base.core.project.jaxrs.WoFile; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.base.core.project.tools.ListTools; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; + +import javax.servlet.http.HttpServletRequest; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.List; + +public class ActionExportUnitSubNestedStatistic extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(ActionExportUnitSubNestedStatistic.class); + + protected ActionResult execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception { + ActionResult result = new ActionResult<>(); + List ids = null; + List unitNameList = new ArrayList(); + List unUnitNameList = new ArrayList(); + List personNameList = new ArrayList(); + List statisticPersonForMonth_list = null; + Workbook wb = null; + Wo wo = null; + String fileName = null; + String sheetName = null; + Boolean check = true; + + if ("(0)".equals(year)) { + year = null; + } + if ("(0)".equals(month)) { + month = null; + } + if( check ){ + if( name == null || name.isEmpty() ){ + check = false; + Exception exception = new ExceptionQueryStatisticUnitNameEmpty(); + result.error( exception ); + } + } + if( check ){ + try { + unitNameList = userManagerService.listSubUnitNameWithParent( name ); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, "根据组织名称列示所有下级组织名称发生异常!Unit:" + name ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + if( check ){ + if( unitNameList == null ){ + unitNameList = new ArrayList<>(); + } + unitNameList.add( name ); + unUnitNameList = getUnUnitNameList(); + personNameList = getUnPersonNameList(); + logger.info("ActionShowStForPersonInUnitSubNested____unitNameList="+unitNameList); + logger.info("ActionShowStForPersonInUnitSubNested____unUnitNameList="+unUnitNameList); + logger.info("ActionShowStForPersonInUnitSubNested____personNameList="+personNameList); + } + if( check ){ + try { + //ids = attendanceStatisticServiceAdv.listPersonForMonthByUnitYearAndMonth( unitNameList, year, month); + ids = attendanceStatisticServiceAdv.listPersonForMonthByUnitYearMonthAndUn( unitNameList, unUnitNameList,personNameList,year, month); + logger.info("ActionShowStForPersonInUnitSubNested____ids="+ids.size()); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess(e, + "系统根据组织名称列表,年份和月份查询个人统计数据信息ID列表时发生异常.Name:"+unitNameList+", Year:"+year+", Month:" + month + ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + if( check ){ + if( ids != null && !ids.isEmpty() ){ + try { + statisticPersonForMonth_list = attendanceStatisticServiceAdv.listPersonForMonth( ids ); + } catch (Exception e) { + check = false; + Exception exception = new ExceptionAttendanceStatisticProcess( e, "系统根据ID列表查询个人每月统计数据信息列表时发生异常." ); + result.error( exception ); + logger.error( e, effectivePerson, request, null); + } + } + } + + // 将结果组织成EXCEL + if( check ) { + fileName = "" + name + "的部门出勤率统计记录_"+year+"年"+month+"月.xls"; + sheetName = "部门出勤率统计记录"; + wb = composeDetail( fileName, sheetName, statisticPersonForMonth_list ); + } + + //输出数据信息 + if( check ) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + try { + wb.write(bos); + wo = new Wo(bos.toByteArray(), + this.contentType(stream, fileName), + this.contentDisposition(stream, fileName)); + } finally { + bos.close(); + } + } + result.setData(wo); + return result; + } + + private Workbook composeDetail(String fileName, String sheetName, List statisticPersonForMonth_list) throws Exception { + Workbook wb = new HSSFWorkbook(); + Row row = null; + if (ListTools.isNotEmpty(statisticPersonForMonth_list)) { + // 创建新的表格 + Sheet sheet = wb.createSheet(sheetName); + // 先创建表头 + row = sheet.createRow(0); + row.createCell(0).setCellValue("顶层组织名称"); + row.createCell(1).setCellValue("组织名称"); + row.createCell(2).setCellValue("姓名"); + row.createCell(3).setCellValue("月份"); + row.createCell(4).setCellValue("上班打卡次数"); + row.createCell(5).setCellValue("下班打卡次数"); + row.createCell(6).setCellValue("出勤人天数"); + row.createCell(7).setCellValue("请假或外出报备人天数"); + row.createCell(8).setCellValue("缺勤人天数"); + row.createCell(9).setCellValue("迟到次数"); + row.createCell(10).setCellValue("工时不足人次"); + row.createCell(11).setCellValue("异常打卡人次"); + + logger.info("一共有"+statisticPersonForMonth_list.size()+"条请求记录可以输出。"); + for (int i = 0; i < statisticPersonForMonth_list.size(); i++) { + StatisticPersonForMonth statisticPersonForMonth = null; + statisticPersonForMonth = statisticPersonForMonth_list.get(i); + if( statisticPersonForMonth != null ){ + row = sheet.createRow(i + 1); + String topUnitName = statisticPersonForMonth.getTopUnitName(); + String unitName = statisticPersonForMonth.getUnitName(); + String empName = statisticPersonForMonth.getEmployeeName(); + if(StringUtils.isNotEmpty(topUnitName) && StringUtils.contains(topUnitName,"@")){ + topUnitName = topUnitName.split("@")[0]; + } + if(StringUtils.isNotEmpty(unitName) && StringUtils.contains(unitName,"@")){ + unitName = unitName.split("@")[0]; + } + if(StringUtils.isNotEmpty(empName) && StringUtils.contains(empName,"@")){ + empName = empName.split("@")[0]; + } + row.createCell(0).setCellValue(topUnitName); + row.createCell(1).setCellValue(unitName); + row.createCell(2).setCellValue(empName); + row.createCell(3).setCellValue(statisticPersonForMonth.getStatisticYear()+"-"+statisticPersonForMonth.getStatisticMonth()); + row.createCell(4).setCellValue(statisticPersonForMonth.getOnDutyTimes()); + row.createCell(5).setCellValue(statisticPersonForMonth.getOnDutyTimes()); + row.createCell(6).setCellValue(statisticPersonForMonth.getOnDutyDayCount()); + row.createCell(7).setCellValue(statisticPersonForMonth.getOnSelfHolidayCount()); + row.createCell(8).setCellValue(statisticPersonForMonth.getAbsenceDayCount()); + row.createCell(9).setCellValue(statisticPersonForMonth.getLateTimes()); + row.createCell(10).setCellValue(statisticPersonForMonth.getLackOfTimeCount()); + row.createCell(11).setCellValue(statisticPersonForMonth.getAbNormalDutyCount()); + } + } + + } + return wb; + } + + + public static class Wo extends WoFile { + public Wo(byte[] bytes, String contentType, String contentDisposition) { + super(bytes, contentType, contentDisposition); + } + } + } diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/BaseAction.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/BaseAction.java index 3295b5c566..8caa633855 100644 --- a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/BaseAction.java +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/BaseAction.java @@ -1,13 +1,167 @@ package com.x.attendance.assemble.control.jaxrs.attachment; import com.x.attendance.assemble.common.date.DateOperation; -import com.x.attendance.assemble.control.service.AttendanceImportFileInfoServiceAdv; -import com.x.attendance.assemble.control.service.AttendanceScheduleSettingServiceAdv; +import com.x.attendance.assemble.control.service.*; +import com.x.attendance.entity.AttendanceEmployeeConfig; +import com.x.base.core.container.EntityManagerContainer; +import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.project.jaxrs.StandardJaxrsAction; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.base.core.project.tools.ListTools; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; public class BaseAction extends StandardJaxrsAction { + protected Logger logger = LoggerFactory.getLogger(BaseAction.class ); protected AttendanceImportFileInfoServiceAdv importFileInfoServiceAdv = new AttendanceImportFileInfoServiceAdv(); + protected AttendanceStatisticServiceAdv attendanceStatisticServiceAdv = new AttendanceStatisticServiceAdv(); + protected UserManagerService userManagerService = new UserManagerService(); protected AttendanceScheduleSettingServiceAdv attendanceScheduleSettingServiceAdv = new AttendanceScheduleSettingServiceAdv(); + protected AttendanceEmployeeConfigServiceAdv attendanceEmployeeConfigServiceAdv = new AttendanceEmployeeConfigServiceAdv(); protected DateOperation dateOperation = new DateOperation(); + + // 根据组织递归查询下级组织 + protected List getUnitNameList(String unitName, List unitNameList ) throws Exception { + if (unitNameList == null) { + unitNameList = new ArrayList(); + } + if ( StringUtils.isNotEmpty( unitName ) && !unitNameList.contains(unitName.trim())) { + unitNameList.add(unitName.trim()); + + // 查询该组织的下级组织 + List unitList = null; + try { + // 对查询的unit进行解析,如果有下级组织的,全部解析出来 + unitList = userManagerService.listSubUnitNameWithParent( unitName ); + } catch (Exception e) { + throw e; + } + if (unitList != null && unitList.size() > 0) { + for (String unit : unitList) { + getUnitNameList( unit, unitNameList); + } + } + } + return unitNameList; + } + + // 根据顶层组织递归查询下级顶层组织经及顶层组织的顶级组织 + protected List getTopUnitNameList( String topUnitName, List unitNameList, Boolean debugger ) + throws Exception { + if (unitNameList == null) { + unitNameList = new ArrayList(); + } + if ( StringUtils.isNotEmpty( topUnitName ) && !unitNameList.contains(topUnitName.trim())) { + unitNameList.add( topUnitName.trim() ); + + // 查询该组织的下级组织 + List unitList = null; + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create();) { + // 查询所有的Top组织 + unitList = userManagerService.listSubUnitNameWithParent(topUnitName); + if ( unitList != null && unitList.size() > 0 ) { + logger.debug( debugger, ">>>>>>>>>>根据顶层组织名称["+topUnitName+"]查询到"+unitList.size()+"个顶级组织。"); + for ( String unit : unitList) { + if (unitNameList.contains( unit )) { + unitNameList.add( unit ); + } + getUnitNameList( unit, unitNameList ); + } + } else { + logger.debug( debugger, ">>>>>>>>>>根据顶层组织名称["+topUnitName+"]未查询到任何顶级组织。"); + } + } catch (Exception e) { + throw e; + } + } + return unitNameList; + } + + /** + * 根据List topUnitNameList, List unitNameList + * 查询所有符合查询范围所组织以及下级组织名称列表 + * + * @param topUnitNameList + * @param unitNameList + * @return + * @throws Exception + */ + protected List getUnitNameList(List topUnitNameList, List unitNameList, Boolean debugger ) + throws Exception { + + if (unitNameList == null) { + unitNameList = new ArrayList(); + } + // 先查询顶层组织所有的下属组织,全部加入List中 + // 对查询的unit进行解析,如果有下级组织的,全部解析出来 + if (topUnitNameList != null && topUnitNameList.size() > 0) { + for (String topUnitName : topUnitNameList) { + // 再递归查询所有的下级顶层组织以及所有组织 + getTopUnitNameList(topUnitName, unitNameList, debugger ); + } + } + // 对查询的unit进行解析,如果有下级组织的,全部解析出来 + if (unitNameList != null && unitNameList.size() > 0) { + for (String unitName : unitNameList) { + getUnitNameList(unitName, unitNameList); + } + } + return unitNameList; + } + + /** + * 获取不需要考勤的组织 + * @return + * @throws Exception + */ + protected List getUnUnitNameList() throws Exception { + List unUnitNameList = new ArrayList(); + + List attendanceEmployeeConfigs = attendanceEmployeeConfigServiceAdv.listByConfigType("NOTREQUIRED"); + + if(ListTools.isNotEmpty(attendanceEmployeeConfigs)){ + for (AttendanceEmployeeConfig attendanceEmployeeConfig : attendanceEmployeeConfigs) { + String unitName = attendanceEmployeeConfig.getUnitName(); + String employeeName = attendanceEmployeeConfig.getEmployeeName(); + + if(StringUtils.isEmpty(employeeName) && StringUtils.isNotEmpty(unitName)){ + unUnitNameList.add(unitName); + List tempUnitNameList = userManagerService.listSubUnitNameWithParent(unitName); + if(ListTools.isNotEmpty(tempUnitNameList)){ + for(String tempUnit:tempUnitNameList){ + if(!ListTools.contains(unUnitNameList, tempUnit)){ + unUnitNameList.add(tempUnit); + } + } + } + } + } + } + return unUnitNameList; + } + + /** + * 获取不需要考勤的人员 + * @return + * @throws Exception + */ + protected List getUnPersonNameList() throws Exception { + List personNameList = new ArrayList(); + List attendanceEmployeeConfigs = attendanceEmployeeConfigServiceAdv.listByConfigType("NOTREQUIRED"); + + if(ListTools.isNotEmpty(attendanceEmployeeConfigs)){ + for (AttendanceEmployeeConfig attendanceEmployeeConfig : attendanceEmployeeConfigs) { + String employeeName = attendanceEmployeeConfig.getEmployeeName(); + + if(StringUtils.isNotEmpty(employeeName) && !ListTools.contains(personNameList, employeeName)){ + personNameList.add(employeeName); + } + } + } + return personNameList; + } } diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionAttendanceStatisticProcess.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionAttendanceStatisticProcess.java new file mode 100644 index 0000000000..d1d47e0768 --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionAttendanceStatisticProcess.java @@ -0,0 +1,12 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.base.core.project.exception.PromptException; + +class ExceptionAttendanceStatisticProcess extends PromptException { + + private static final long serialVersionUID = 1859164370743532895L; + + public ExceptionAttendanceStatisticProcess(Throwable e, String message ) { + super("用户在进行考勤统计处理时发生异常!message:" + message, e ); + } +} diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionPersonNameEmpty.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionPersonNameEmpty.java new file mode 100644 index 0000000000..19c255b5d8 --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionPersonNameEmpty.java @@ -0,0 +1,12 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.base.core.project.exception.PromptException; + +class ExceptionPersonNameEmpty extends PromptException { + + private static final long serialVersionUID = 1859164370743532895L; + + public ExceptionPersonNameEmpty() { + super("系统未获取到查询参数员工姓名name,无法进行数据查询"); + } +} diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionQueryStatisticUnitNameEmpty.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionQueryStatisticUnitNameEmpty.java new file mode 100644 index 0000000000..f2c12972ea --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionQueryStatisticUnitNameEmpty.java @@ -0,0 +1,12 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.base.core.project.exception.PromptException; + +class ExceptionQueryStatisticUnitNameEmpty extends PromptException { + + private static final long serialVersionUID = 1859164370743532895L; + + public ExceptionQueryStatisticUnitNameEmpty() { + super("系统未获取到查询参数组织名称name,无法进行数据查询"); + } +} diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionTopUnitNameEmpty.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionTopUnitNameEmpty.java new file mode 100644 index 0000000000..0deda2e9a9 --- /dev/null +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/ExceptionTopUnitNameEmpty.java @@ -0,0 +1,12 @@ +package com.x.attendance.assemble.control.jaxrs.attachment; + +import com.x.base.core.project.exception.PromptException; + +class ExceptionTopUnitNameEmpty extends PromptException { + + private static final long serialVersionUID = 1859164370743532895L; + + public ExceptionTopUnitNameEmpty() { + super("系统未获取到查询参数顶层组织名称name,无法进行数据查询"); + } +} diff --git a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/FileImportExportAction.java b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/FileImportExportAction.java index 5bbce42315..97c44bbd11 100644 --- a/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/FileImportExportAction.java +++ b/o2server/x_attendance_assemble_control/src/main/java/com/x/attendance/assemble/control/jaxrs/attachment/FileImportExportAction.java @@ -135,4 +135,67 @@ public class FileImportExportAction extends StandardJaxrsAction { } asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); } + + @JaxrsMethodDescribe(value = "导出个人出勤率统计记录,设定是否使用stream输出", action = ActionExportPersonStatistic.class) + @GET + @Path("export/person/{name}/{year}/{month}/stream/{stream}") + @Consumes(MediaType.APPLICATION_JSON) + public void personStatisticExportStream(@Suspended final AsyncResponse asyncResponse, + @Context HttpServletRequest request, + @JaxrsParameterDescribe("统计员工姓名") @PathParam("name") String name, + @JaxrsParameterDescribe("统计周期年份") @PathParam("year") String year, + @JaxrsParameterDescribe("统计周期月份") @PathParam("month") String month, + @JaxrsParameterDescribe("用.APPLICATION_OCTET_STREAM头输出") @PathParam("stream") Boolean stream) { + ActionResult result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionExportPersonStatistic().execute(request, effectivePerson, name, year, month, stream); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + + @JaxrsMethodDescribe(value = "导出部门出勤率统计记录,设定是否使用stream输出", action = ActionExportUnitSubNestedStatistic.class) + @GET + @Path("export/unit/{name}/{year}/{month}/stream/{stream}") + @Consumes(MediaType.APPLICATION_JSON) + public void unitStatisticExportStream(@Suspended final AsyncResponse asyncResponse, + @Context HttpServletRequest request, + @JaxrsParameterDescribe("统计部门名称") @PathParam("name") String name, + @JaxrsParameterDescribe("统计周期年份") @PathParam("year") String year, + @JaxrsParameterDescribe("统计周期月份") @PathParam("month") String month, + @JaxrsParameterDescribe("用.APPLICATION_OCTET_STREAM头输出") @PathParam("stream") Boolean stream) { + ActionResult result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionExportUnitSubNestedStatistic().execute(request, effectivePerson, name, year, month, stream); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } + + @JaxrsMethodDescribe(value = "导出公司出勤率统计记录,设定是否使用stream输出", action = ActionExportTopUnitStatistic.class) + @GET + @Path("export/topunit/{name}/{year}/{month}/stream/{stream}") + @Consumes(MediaType.APPLICATION_JSON) + public void topunitStatisticExportStream(@Suspended final AsyncResponse asyncResponse, + @Context HttpServletRequest request, + @JaxrsParameterDescribe("统计公司名称") @PathParam("name") String name, + @JaxrsParameterDescribe("统计周期年份") @PathParam("year") String year, + @JaxrsParameterDescribe("统计周期月份") @PathParam("month") String month, + @JaxrsParameterDescribe("用.APPLICATION_OCTET_STREAM头输出") @PathParam("stream") Boolean stream) { + ActionResult result = new ActionResult<>(); + EffectivePerson effectivePerson = this.effectivePerson(request); + try { + result = new ActionExportTopUnitStatistic().execute(request, effectivePerson, name, year, month, stream); + } catch (Exception e) { + logger.error(e, effectivePerson, request, null); + result.error(e); + } + asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result)); + } } -- GitLab