Răsfoiți Sursa

考勤,新增出勤率(个人,部门,公司)统计导出

luojing 5 ani în urmă
părinte
comite
669ed54af9

+ 159 - 0
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<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception {
+			ActionResult<Wo> result = new ActionResult<>();
+			List<String> ids = null;
+			List<StatisticPersonForMonth> 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> 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);
+			}
+		}
+	}

+ 168 - 0
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<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception {
+			ActionResult<Wo> result = new ActionResult<>();
+			List<String> ids = null;
+			List<String> unitNames = new ArrayList<String>();
+			List<StatisticUnitForMonth> 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> 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);
+			}
+		}
+	}

+ 186 - 0
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<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, String name, String year, String month ,Boolean stream ) throws Exception {
+			ActionResult<Wo> result = new ActionResult<>();
+			List<String> ids = null;
+			List<String> unitNameList = new ArrayList<String>();
+			List<String> unUnitNameList = new ArrayList<String>();
+			List<String> personNameList = new ArrayList<String>();
+			List<StatisticPersonForMonth> 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> 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);
+			}
+		}
+	}

+ 156 - 2
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;
 package com.x.attendance.assemble.control.jaxrs.attachment;
 
 
 import com.x.attendance.assemble.common.date.DateOperation;
 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.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 {
 public class BaseAction extends StandardJaxrsAction {
+	protected Logger logger = LoggerFactory.getLogger(BaseAction.class );
 	protected AttendanceImportFileInfoServiceAdv importFileInfoServiceAdv = new AttendanceImportFileInfoServiceAdv();
 	protected AttendanceImportFileInfoServiceAdv importFileInfoServiceAdv = new AttendanceImportFileInfoServiceAdv();
+	protected AttendanceStatisticServiceAdv attendanceStatisticServiceAdv = new AttendanceStatisticServiceAdv();
+	protected UserManagerService userManagerService = new UserManagerService();
 	protected AttendanceScheduleSettingServiceAdv attendanceScheduleSettingServiceAdv = new AttendanceScheduleSettingServiceAdv();
 	protected AttendanceScheduleSettingServiceAdv attendanceScheduleSettingServiceAdv = new AttendanceScheduleSettingServiceAdv();
+	protected AttendanceEmployeeConfigServiceAdv attendanceEmployeeConfigServiceAdv = new AttendanceEmployeeConfigServiceAdv();
 	protected DateOperation dateOperation = new DateOperation();
 	protected DateOperation dateOperation = new DateOperation();
+
+	// 根据组织递归查询下级组织
+	protected List<String> getUnitNameList(String unitName, List<String> unitNameList ) throws Exception {
+		if (unitNameList == null) {
+			unitNameList = new ArrayList<String>();
+		}
+		if ( StringUtils.isNotEmpty( unitName ) && !unitNameList.contains(unitName.trim())) {
+			unitNameList.add(unitName.trim());
+
+			// 查询该组织的下级组织
+			List<String> 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<String> getTopUnitNameList( String topUnitName, List<String> unitNameList, Boolean debugger )
+			throws Exception {
+		if (unitNameList == null) {
+			unitNameList = new ArrayList<String>();
+		}
+		if ( StringUtils.isNotEmpty( topUnitName ) && !unitNameList.contains(topUnitName.trim())) {
+			unitNameList.add( topUnitName.trim() );
+
+			// 查询该组织的下级组织
+			List<String> 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<String> topUnitNameList, List<String> unitNameList
+	 * 查询所有符合查询范围所组织以及下级组织名称列表
+	 *
+	 * @param topUnitNameList
+	 * @param unitNameList
+	 * @return
+	 * @throws Exception
+	 */
+	protected List<String> getUnitNameList(List<String> topUnitNameList, List<String> unitNameList, Boolean debugger )
+			throws Exception {
+
+		if (unitNameList == null) {
+			unitNameList = new ArrayList<String>();
+		}
+		// 先查询顶层组织所有的下属组织,全部加入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<String> getUnUnitNameList() throws Exception {
+		List<String> unUnitNameList = new ArrayList<String>();
+
+		List<AttendanceEmployeeConfig> 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<String> 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<String> getUnPersonNameList() throws Exception {
+		List<String> personNameList = new ArrayList<String>();
+		List<AttendanceEmployeeConfig> 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;
+	}
 }
 }
 
 

+ 12 - 0
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 );
+	}
+}

+ 12 - 0
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,无法进行数据查询");
+	}
+}

+ 12 - 0
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,无法进行数据查询");
+	}
+}

+ 12 - 0
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,无法进行数据查询");
+	}
+}

+ 63 - 0
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));
 		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<ActionExportPersonStatistic.Wo> 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<ActionExportUnitSubNestedStatistic.Wo> 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<ActionExportTopUnitStatistic.Wo> 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));
+	}
 }
 }