diff --git a/src/com/engine/kq/biz/KQFormatData.java b/src/com/engine/kq/biz/KQFormatData.java index 2ab25a5..f5b4ae1 100644 --- a/src/com/engine/kq/biz/KQFormatData.java +++ b/src/com/engine/kq/biz/KQFormatData.java @@ -968,52 +968,117 @@ public class KQFormatData extends BaseBean { } //增加功能--如果上班卡和下班卡相差十分钟,旷工计一天 - String inTemp = ""; - String outTemp = ""; - for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { - Map checkInfo = (Map) lsCheckInfo.get(j); - String signType = Util.null2String(checkInfo.get("signType")); - String signTime = Util.null2String(checkInfo.get("signTime")); - String signDate = Util.null2String(checkInfo.get("signDate")); - if (signType.equals("1")) { - inTemp = signDate + " " + signTime; - } - if (signType.equals("2")) { - outTemp = signDate + " " + signTime; + //优化:休息班次不计算旷工 + String serialidTemp = Util.null2String(workTime.getSerialId()); + if(StringUtils.isNotBlank(serialidTemp)){ + List restSerialids = new ArrayList(); + String acqRestShiftSql = "select id from kq_shiftmanagement where rest_shift = 1 and (isdelete = 0 or isdelete is null)"; + rs.executeQuery(acqRestShiftSql); + while (rs.next()) { + String id = Util.null2String(rs.getString("id")); + restSerialids.add(id); } + if ( restSerialids != null && restSerialids.size() > 0) { + if( !restSerialids.contains(serialidTemp)){ + String inTemp = ""; + String outTemp = ""; + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signType = Util.null2String(checkInfo.get("signType")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String signDate = Util.null2String(checkInfo.get("signDate")); + + if (signType.equals("1")) { + inTemp = signDate + " " + signTime; + } + if (signType.equals("2")) { + outTemp = signDate + " " + signTime; + } - } + } - bb.writeLog("inTemp:" + inTemp); - bb.writeLog("outTemp:" + outTemp); + bb.writeLog("inTemp:" + inTemp); + bb.writeLog("outTemp:" + outTemp); - if(StringUtils.isNotBlank(inTemp) && StringUtils.isNotBlank(outTemp)){ + if(StringUtils.isNotBlank(inTemp) && StringUtils.isNotBlank(outTemp)){ - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime startTime = LocalDateTime.parse(inTemp, formatter); - LocalDateTime endTime = LocalDateTime.parse(outTemp, formatter); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse(inTemp, formatter); + LocalDateTime endTime = LocalDateTime.parse(outTemp, formatter); - // 计算两个LocalDateTime对象之间的Duration - Duration duration = Duration.between(startTime, endTime); + // 计算两个LocalDateTime对象之间的Duration + Duration duration = Duration.between(startTime, endTime); - // 将Duration转换为分钟 - long minutesLong = duration.toMinutes(); - int minutes = (int) minutesLong; - if(minutes<=10){ - //优化:考虑请假公出出差的时长 - if (evectionMins == 0 && leaveMins == 0 && outMins == 0) { - absenteeismMins = 480; - } else { - absenteeismMins = 480 - leaveMins - evectionMins - outMins; + // 将Duration转换为分钟 + long minutesLong = duration.toMinutes(); + int minutes = (int) minutesLong; + if(minutes<=10){ + //优化:考虑请假公出出差的时长 + if (evectionMins == 0 && leaveMins == 0 && outMins == 0) { + absenteeismMins = 480; + } else { + absenteeismMins = 480 - leaveMins - evectionMins - outMins; + } + beLateMins = 0; + graveBeLateMins = 0; + leaveEarlyMins = 0; + graveLeaveEarlyMins = 0; + } + } + } + } else { + String inTemp = ""; + String outTemp = ""; + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signType = Util.null2String(checkInfo.get("signType")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String signDate = Util.null2String(checkInfo.get("signDate")); + + if (signType.equals("1")) { + inTemp = signDate + " " + signTime; + } + if (signType.equals("2")) { + outTemp = signDate + " " + signTime; + } + + } + + bb.writeLog("inTemp:" + inTemp); + bb.writeLog("outTemp:" + outTemp); + + if(StringUtils.isNotBlank(inTemp) && StringUtils.isNotBlank(outTemp)){ + + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + LocalDateTime startTime = LocalDateTime.parse(inTemp, formatter); + LocalDateTime endTime = LocalDateTime.parse(outTemp, formatter); + + // 计算两个LocalDateTime对象之间的Duration + Duration duration = Duration.between(startTime, endTime); + + // 将Duration转换为分钟 + long minutesLong = duration.toMinutes(); + int minutes = (int) minutesLong; + if(minutes<=10){ + //优化:考虑请假公出出差的时长 + if (evectionMins == 0 && leaveMins == 0 && outMins == 0) { + absenteeismMins = 480; + } else { + absenteeismMins = 480 - leaveMins - evectionMins - outMins; + } + beLateMins = 0; + graveBeLateMins = 0; + leaveEarlyMins = 0; + graveLeaveEarlyMins = 0; + } } - beLateMins = 0; - graveBeLateMins = 0; - leaveEarlyMins = 0; - graveLeaveEarlyMins = 0; } + } + + //计算实际出勤时间(出差公出算出勤)=应出勤-旷工-请假-迟到-早退 bb.writeLog("workMins: " + workMins); bb.writeLog("absenteeismMins: " + absenteeismMins); diff --git a/src/com/engine/kq/biz/KQReportBiz.java b/src/com/engine/kq/biz/KQReportBiz.java index 7599e43..959191f 100644 --- a/src/com/engine/kq/biz/KQReportBiz.java +++ b/src/com/engine/kq/biz/KQReportBiz.java @@ -654,7 +654,7 @@ public class KQReportBiz extends BaseBean { sql = " select a.resourceid, count(*) as number from kq_format_total a left join hrmresource b on b.id = a. resourceid" + " where a.serialid = " + offdutyId + " " + sqlWhere; - + basebean.writeLog("getHoliDurationData sql:" + sql); rs.executeQuery(sql); while (rs.next()) { int number = Util.getIntValue(Util.null2String(rs.getString("number"))); diff --git a/src/com/engine/kq/cmd/report/ExportExcelCmd.java b/src/com/engine/kq/cmd/report/ExportExcelCmd.java index 4ea0210..3ec7804 100644 --- a/src/com/engine/kq/cmd/report/ExportExcelCmd.java +++ b/src/com/engine/kq/cmd/report/ExportExcelCmd.java @@ -26,6 +26,9 @@ import weaver.systeminfo.SystemEnv; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import java.util.*; public class ExportExcelCmd extends AbstractCommonCommand> { @@ -571,6 +574,56 @@ public class ExportExcelCmd extends AbstractCommonCommand> { } data.add(fieldValue); continue; + }else if(fieldName.equals("thisRemOt")){//当月加班剩余 + if ("3".equals(typeselect) || "7".equals(typeselect)) { + Map allTiaoxius = getAllTiaoxius(id, fromDate, toDate); + + double max2 = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("1"))), 0.00); + + fieldValue = String.valueOf(max2); + data.add(fieldValue); + + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("2"))), 0.00); + + fieldValue = String.valueOf(max); + data.add(fieldValue); + + double max1 = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("3"))), 0.00); + + fieldValue = String.valueOf(max1); + data.add(fieldValue); + + } else { + data.add("0"); + data.add("0"); + data.add("0"); + } + continue; + + } else if(fieldName.equals("lastRemOt")){//上月加班剩余 + if ("3".equals(typeselect) || "7".equals(typeselect)) { + Map allTiaoxius = getLastAllTiaoxius(id, fromDate, toDate); + double max2 = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("1"))), 0.00); + + fieldValue = String.valueOf(max2); + data.add(fieldValue); + + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("2"))), 0.00); + + fieldValue = String.valueOf(max); + data.add(fieldValue); + + double max1 = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("3"))), 0.00); + + fieldValue = String.valueOf(max1); + data.add(fieldValue); + + } else { + data.add("0"); + data.add("0"); + data.add("0"); + } + continue; } else if(fieldName.equals("overtime")){ // fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave"))); // data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave")))); @@ -929,6 +982,129 @@ public class ExportExcelCmd extends AbstractCommonCommand> { } return fieldValue; } + + /** + * 获取各种类型的调休时长 + * @return + */ + public Map getAllTiaoxius(String resourceid ,String fromdate, String todate) { + Map result = new HashMap(); + String acqSql = "SELECT " + + " a.resourceid, " + + " SUM(tiaoxiuamount) AS tiaoxiuamounts, " + + " SUM(usedamount) AS usedamounts, " + + " GREATEST( sum(extraamount) + SUM(tiaoxiuamount) - SUM(usedamount), 0.00000) AS difference_amounts, " + + " COALESCE(datetype, b.changetype) AS grouping_date, " + + " CASE " + + " WHEN datetype IS NOT NULL THEN datetype " + + " ELSE b.changetype " + + " END AS displayed_date " + + "FROM " + + " kq_balanceofleave a " + + "LEFT JOIN " + + " kq_flow_overtime b ON b.tiaoxiuid = a.id " + + "WHERE " + + " a.leaverulesid = 5 " + + " AND a.effectiveDate >= '"+fromdate+"' " + + " AND a.effectiveDate <= '"+todate+"' " + + " AND a.expirationDate >= '"+todate+"' " + + " AND a.resourceid = "+resourceid+" " + + "GROUP BY " + + " a.resourceid, " + + " COALESCE(datetype, b.changetype) " + + "ORDER BY " + + " grouping_date;"; + + + RecordSet rs = new RecordSet(); + rs.executeQuery(acqSql); + while (rs.next()){ + String differenceAmounts = Util.null2String(rs.getString("difference_amounts")); + String displayedDate = Util.null2String(rs.getString("displayed_date")); + if (StringUtils.isNotBlank(differenceAmounts) && StringUtils.isNotBlank(displayedDate)) { + result.put(displayedDate, differenceAmounts); + } + } + + return result; + } + + /** + * 获取上月各种类型的调休时长 + * @return + */ + public Map getLastAllTiaoxius(String resourceid ,String fromdate, String todate) { + Map result = new HashMap(); + Map lastMonthFirstAndLastDay = getLastMonthFirstAndLastDay(fromdate); + if (lastMonthFirstAndLastDay != null && lastMonthFirstAndLastDay.size() > 0) { + String firstDay = Util.null2String(lastMonthFirstAndLastDay.get("firstDay")); + String lastDay = Util.null2String(lastMonthFirstAndLastDay.get("lastDay")); + if (StringUtils.isNotBlank(firstDay)) { + fromdate = firstDay; + } + if (StringUtils.isNotBlank(lastDay)) { + todate = lastDay; + } + } + + String acqSql = "SELECT " + + " a.resourceid, " + + " SUM(tiaoxiuamount) AS tiaoxiuamounts, " + + " SUM(usedamount) AS usedamounts, " + + " GREATEST( sum(extraamount) + SUM(tiaoxiuamount) - SUM(usedamount), 0.00000) AS difference_amounts, " + + " COALESCE(datetype, b.changetype) AS grouping_date, " + + " CASE " + + " WHEN datetype IS NOT NULL THEN datetype " + + " ELSE b.changetype " + + " END AS displayed_date " + + "FROM " + + " kq_balanceofleave a " + + "LEFT JOIN " + + " kq_flow_overtime b ON b.tiaoxiuid = a.id " + + "WHERE " + + " a.leaverulesid = 5 " + + " AND a.effectiveDate >= '"+fromdate+"' " + + " AND a.effectiveDate <= '"+todate+"' " + + " AND a.expirationDate >= '"+todate+"' " + + " AND a.resourceid = "+resourceid+" " + + "GROUP BY " + + " a.resourceid, " + + " COALESCE(datetype, b.changetype) " + + "ORDER BY " + + " grouping_date;"; + + + RecordSet rs = new RecordSet(); + rs.executeQuery(acqSql); + while (rs.next()){ + String differenceAmounts = Util.null2String(rs.getString("difference_amounts")); + String displayedDate = Util.null2String(rs.getString("displayed_date")); + if (StringUtils.isNotBlank(differenceAmounts) && StringUtils.isNotBlank(displayedDate)) { + result.put(displayedDate, differenceAmounts); + } + } + + return result; + } + + public Map getLastMonthFirstAndLastDay(String dateString) { + + Map result = new HashMap(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + // 解析给定的日期字符串 + LocalDate date = LocalDate.parse(dateString, formatter); + + // 获取上个月的第一天 + LocalDate firstDayOfLastMonth = date.with(TemporalAdjusters.firstDayOfMonth()).minusMonths(1); + + // 获取上个月的最后一天 + LocalDate lastDayOfLastMonth = date.with(TemporalAdjusters.lastDayOfMonth()).minusMonths(1); + + // 格式化日期为字符串并返回 + result.put("firstDay", firstDayOfLastMonth.format(formatter)); + result.put("lastDay", lastDayOfLastMonth.format(formatter)); + return result; + } @Override public BizLogContext getLogContext() { return null; diff --git a/src/com/engine/kq/cmd/report/GetKQReportCmd.java b/src/com/engine/kq/cmd/report/GetKQReportCmd.java index d778cd9..7245f1c 100644 --- a/src/com/engine/kq/cmd/report/GetKQReportCmd.java +++ b/src/com/engine/kq/cmd/report/GetKQReportCmd.java @@ -24,10 +24,12 @@ import weaver.interfaces.sskj.comInfo.PropBean; import weaver.systeminfo.SystemEnv; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.time.temporal.TemporalAdjusters; import java.util.*; import static com.api.formmode.cache.ModeExpandPageComInfo.groupid; @@ -331,6 +333,10 @@ public class GetKQReportCmd extends AbstractCommonCommand> { params.put("uintType",uintType); params.put("hoursToDay",hoursToDay); Map flowData = kqReportBiz.getFlowData(params,user); + + //考勤二开--请假时长 + Map leaveInfos = getLeaveInfos(fromDate, toDate); + /*考勤二开--转事假start*/ String calLeaveId = bb.getPropValue("project_sskj", "calLeaveId"); /*考勤二开--转事假end*/ @@ -513,109 +519,55 @@ public class GetKQReportCmd extends AbstractCommonCommand> { fieldValue = String.valueOf(intValue); } - }else if(fieldName.equals("thisRemOt")){//当月加班剩余 - double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leave"))); - workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave; - double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leave"))); - restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave; - double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leave"))); - holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave; - - double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleave"))); - workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave; - double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleave"))); - restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave; - double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleave"))); - holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave; - - double overtimeDuration = workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+ - workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave; - - //请假时长统计 - String leaveData = Util.null2String(flowData.get(id+"|leaveType_5")); - String leavebackData = Util.null2s(Util.null2String(flowData.get(id+"|leavebackType_5")),"0.0"); - String b_flowLeaveData = ""; - String flowLeaveData = ""; - try{ - //以防止出现精度问题 - if(leaveData.length() == 0){ - leaveData = "0.0"; + }else if(kqReportFieldComInfo.getParentid().equals("thisRemOt")){//当月加班剩余 + if ("3".equals(typeselect) || "7".equals(typeselect)) { + Map allTiaoxius = getAllTiaoxius(id, fromDate, toDate); + if("workRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("2"))), 0.00); + + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); } - if(leavebackData.length() == 0){ - leavebackData = "0.0"; + if("restRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("3"))), 0.00); + + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); } - BigDecimal b_leaveData = new BigDecimal(leaveData); - BigDecimal b_leavebackData = new BigDecimal(leavebackData); - b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); - if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ - b_flowLeaveData = "0.0"; + if("holiRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("1"))), 0.00); + + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); } - }catch (Exception e){ - writeLog("GetKQReportCmd:leaveData"+leaveData+":leavebackData:"+leavebackData+":"+e); } - //考虑下冻结的数据 - if(b_flowLeaveData.length() > 0){ - flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); - }else{ - flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData,0.0)-Util.getDoubleValue(leavebackData,0.0))); - } - double leaveDuration = Math.max(Util.getDoubleValue(Util.null2String(flowLeaveData)),0.00); - - double temp = overtimeDuration - leaveDuration; - fieldValue = String.valueOf(temp); - - } else if(fieldName.equals("lastRemOt")){//上月加班剩余 - double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_4leavelast"))); - workingDayOvertime_4leave = workingDayOvertime_4leave<0?0:workingDayOvertime_4leave; - double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_4leavelast"))); - restDayOvertime_4leave = restDayOvertime_4leave<0?0:restDayOvertime_4leave; - double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_4leavelast"))); - holidayOvertime_4leave = holidayOvertime_4leave<0?0:holidayOvertime_4leave; - - double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|workingDayOvertime_nonleavelast"))); - workingDayOvertime_nonleave = workingDayOvertime_nonleave<0?0:workingDayOvertime_nonleave; - double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|restDayOvertime_nonleavelast"))); - restDayOvertime_nonleave = restDayOvertime_nonleave<0?0:restDayOvertime_nonleave; - double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id+"|holidayOvertime_nonleavelast"))); - holidayOvertime_nonleave = holidayOvertime_nonleave<0?0:holidayOvertime_nonleave; - - double overtimeDuration = workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+ - workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave; - - //请假时长统计 - String leaveData = Util.null2String(flowData.get(id+"|lastleaveType_5")); - String leavebackData = Util.null2s(Util.null2String(flowData.get(id+"|lastleavebackType_5")),"0.0"); - String b_flowLeaveData = ""; - String flowLeaveData = ""; - try{ - //以防止出现精度问题 - if(leaveData.length() == 0){ - leaveData = "0.0"; - } - if(leavebackData.length() == 0){ - leavebackData = "0.0"; + + } else if(kqReportFieldComInfo.getParentid().equals("lastRemOt")){//上月加班剩余 + if ("3".equals(typeselect) || "7".equals(typeselect)) { + Map allTiaoxius = getLastAllTiaoxius(id, fromDate, toDate); + if("lastWorkRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("2"))), 0.00); + + bb.writeLog("lastWorkRemot max: " + max); + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); } - BigDecimal b_leaveData = new BigDecimal(leaveData); - BigDecimal b_leavebackData = new BigDecimal(leavebackData); - b_flowLeaveData = b_leaveData.subtract(b_leavebackData).toString(); - if(Util.getDoubleValue(b_flowLeaveData, -1) < 0){ - b_flowLeaveData = "0.0"; + if("lastRestRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("3"))), 0.00); + + bb.writeLog("lastRestRemot max: " + max); + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); } - }catch (Exception e){ - writeLog("GetKQReportCmd:leaveData"+leaveData+":leavebackData:"+leavebackData+":"+e); - } + if("lastHoliRemot".equals(fieldName)){ + double max = Math.max(Util.getDoubleValue(Util.null2String(allTiaoxius.get("1"))), 0.00); - //考虑下冻结的数据 - if(b_flowLeaveData.length() > 0){ - flowLeaveData = KQDurationCalculatorUtil.getDurationRound(b_flowLeaveData); - }else{ - flowLeaveData = KQDurationCalculatorUtil.getDurationRound(Util.null2String(Util.getDoubleValue(leaveData,0.0)-Util.getDoubleValue(leavebackData,0.0))); + bb.writeLog("lastHoliRemot max: " + max); + fieldValue = String.valueOf(max); + data.put(fieldName,fieldValue); + } } - double leaveDuration = Math.max(Util.getDoubleValue(Util.null2String(flowLeaveData)),0.00); - - double temp = overtimeDuration - leaveDuration; - fieldValue = String.valueOf(temp); } else if(kqReportFieldComInfo.getParentid().equals("overtime")||kqReportFieldComInfo.getParentid().equals("overtime_nonleave") ||kqReportFieldComInfo.getParentid().equals("overtime_4leave")||fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")){ @@ -662,14 +614,36 @@ public class GetKQReportCmd extends AbstractCommonCommand> { }else{ fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id+"|"+fieldName))); } - } else if("holiDuration".equals(fieldName)){ + } else if("holiDuration".equals(fieldName)){//考勤二开--公休工时 int intValue = Util.getIntValue(Util.null2String(flowData.get("HoliDurationData|" + id))); if (intValue >= 0) { data.put(fieldName,intValue); } else { data.put(fieldName,"0"); } - } else if ("resourceType".equals(fieldName)) {//考勤二开--员工类型显示 + } else if("absenceDuration".equals(fieldName)){//考勤二开--缺勤工时 + //缺勤工时 = 请假+公休+入离职工时 + bb.writeLog("absenceDuration start "); + //请假 + double leaveMins = Math.max(Util.getDoubleValue(Util.null2String(leaveInfos.get(id))), 0.00); + bb.writeLog("absenceDuration leaveMins: " + leaveMins); + BigDecimal leaveHours = new BigDecimal(leaveMins).divide(new BigDecimal(60), 2, RoundingMode.HALF_UP); + + //公休 + int hodHours = Math.max(Util.getIntValue(Util.null2String(flowData.get("HoliDurationData|" + id))),0) * 8; + bb.writeLog("absenceDuration hodHours: " + hodHours); + + //入离职工时 + int absenceDays = 0; + absenceDays = getStartOrEndDays(id, fromDate, toDate, typeselect); + bb.writeLog("absenceDuration absenceDays: " + absenceDays); + + fieldValue = new BigDecimal(hodHours).add(new BigDecimal(absenceDays).multiply(new BigDecimal(8))).add(leaveHours) + .divide(new BigDecimal(8),2,RoundingMode.HALF_UP).toString(); + bb.writeLog("absenceDuration fieldValue: " + fieldValue); + + data.put(fieldName,fieldValue); + } else if ("resourceType".equals(fieldName)) {//考勤二开--员工类型显示 int emp = Util.getIntValue(Util.null2String(empTypes.get(id))); @@ -691,55 +665,7 @@ public class GetKQReportCmd extends AbstractCommonCommand> { data.put(fieldName, fieldValue); } else if ("startOrEndDays".equals(fieldName)) {//考勤二开--入离职工时 int absenceDays = 0; - if ("3".equals(typeselect) || "7".equals(typeselect)) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - Map employAndResignDates = getEmployAndResignDateById(id); - - String companystartdate = Util.null2String(employAndResignDates.get("companystartdate")); - String resignDate = Util.null2String(employAndResignDates.get("resignDate")); - - if (StringUtils.isNotBlank(companystartdate) && StringUtils.isBlank(resignDate)) { - String substring1 = companystartdate.substring(0, 7); - String substring2 = fromDate.substring(0, 7); - if (substring1.equals(substring2)) { - LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); - LocalDate localDate = companystartdateL.plusDays(1); - companystartdate = localDate.format(formatter); - absenceDays = getAbsenceDays(id, fromDate, companystartdate, toDate); - } - } else if (StringUtils.isBlank(companystartdate) && StringUtils.isNotBlank(resignDate)) { - String substring1 = resignDate.substring(0, 7); - String substring2 = toDate.substring(0, 7); - if (substring1.equals(substring2)) { - absenceDays = getAbsenceDays(id, resignDate, toDate, fromDate); - } - - } else if (StringUtils.isNotBlank(companystartdate) && StringUtils.isNotBlank(resignDate)) { - String substring1 = companystartdate.substring(0, 7); - String substring2 = resignDate.substring(0, 7); - String substring3 = fromDate.substring(0, 7); - String substring4 = toDate.substring(0, 7); - if ( substring1.equals(substring2) && substring2.equals(substring3) - && substring3.equals(substring4) ) {//考勤月入职且离职 - LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); - LocalDate localDate = companystartdateL.plusDays(1); - companystartdate = localDate.format(formatter); - - int temp1 = getAbsenceDays(id, fromDate, companystartdate, toDate); - int temp2 = getAbsenceDays(id, resignDate, toDate, fromDate); - absenceDays = temp1 + temp2; - } else if (substring1.equals(substring3) && !substring2.equals(substring3)) {//考勤月入职,非考勤月离职 - LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); - LocalDate localDate = companystartdateL.plusDays(1); - companystartdate = localDate.format(formatter); - - absenceDays = getAbsenceDays(id, fromDate, companystartdate, toDate); - } else if ( !substring1.equals(substring3) && !substring2.equals(substring3)){//非考勤月入职,考勤月离职 - absenceDays = getAbsenceDays(id, resignDate, toDate, fromDate); - } - } - - } + absenceDays = getStartOrEndDays(id, fromDate, toDate, typeselect); fieldValue = String.valueOf(absenceDays); data.put(fieldName, fieldValue); @@ -1204,6 +1130,7 @@ public class GetKQReportCmd extends AbstractCommonCommand> { "where belongdate >='"+startDate+"' and belongdate <='"+endDate+"' " + "group by resourceid " + "order by resourceid "; + bb.writeLog("getLeaveInfos acqLeaveSql: " + acqLeaveSql); rs.executeQuery(acqLeaveSql); while (rs.next()) { String resourceid = Util.null2String(rs.getString("resourceid")); @@ -1215,6 +1142,7 @@ public class GetKQReportCmd extends AbstractCommonCommand> { "where belongdate >='"+startDate+"' and belongdate <='"+endDate+"' " + "group by resourceid " + "order by resourceid "; + bb.writeLog("getLeaveInfos acqLeaveBackSql: " + acqLeaveBackSql); rs.executeQuery(acqLeaveBackSql); while (rs.next()) { String resourceid = Util.null2String(rs.getString("resourceid")); @@ -1226,7 +1154,192 @@ public class GetKQReportCmd extends AbstractCommonCommand> { } } + bb.writeLog("getLeaveInfos result: " + result); + return result; + } + + /** + * 入离职工时 + * @return + */ + public int getStartOrEndDays(String id, String fromDate, String toDate, String typeselect){ + int absenceDays = 0; + if ("3".equals(typeselect) || "7".equals(typeselect)) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map employAndResignDates = getEmployAndResignDateById(id); + + String companystartdate = Util.null2String(employAndResignDates.get("companystartdate")); + String resignDate = Util.null2String(employAndResignDates.get("resignDate")); + + if (StringUtils.isNotBlank(companystartdate) && StringUtils.isBlank(resignDate)) { + String substring1 = companystartdate.substring(0, 7); + String substring2 = fromDate.substring(0, 7); + if (substring1.equals(substring2)) { + LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); + LocalDate localDate = companystartdateL.minusDays(1); + companystartdate = localDate.format(formatter); + + absenceDays = getAbsenceDays(id, fromDate, companystartdate, toDate); + } + } else if (StringUtils.isBlank(companystartdate) && StringUtils.isNotBlank(resignDate)) { + String substring1 = resignDate.substring(0, 7); + String substring2 = toDate.substring(0, 7); + if (substring1.equals(substring2)) { + absenceDays = getAbsenceDays(id, resignDate, toDate, fromDate); + } + + } else if (StringUtils.isNotBlank(companystartdate) && StringUtils.isNotBlank(resignDate)) { + String substring1 = companystartdate.substring(0, 7); + String substring2 = resignDate.substring(0, 7); + String substring3 = fromDate.substring(0, 7); + String substring4 = toDate.substring(0, 7); + if ( substring1.equals(substring2) && substring2.equals(substring3) + && substring3.equals(substring4) ) {//考勤月入职且离职 + LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); + LocalDate localDate = companystartdateL.minusDays(1); + companystartdate = localDate.format(formatter); + + int temp1 = getAbsenceDays(id, fromDate, companystartdate, toDate); + int temp2 = getAbsenceDays(id, resignDate, toDate, fromDate); + absenceDays = temp1 + temp2; + } else if (substring1.equals(substring3) && !substring2.equals(substring3)) {//考勤月入职,非考勤月离职 + LocalDate companystartdateL = LocalDate.parse(companystartdate, formatter); + LocalDate localDate = companystartdateL.minusDays(1); + companystartdate = localDate.format(formatter); + + absenceDays = getAbsenceDays(id, fromDate, companystartdate, toDate); + } else if ( !substring1.equals(substring3) && !substring2.equals(substring3)){//非考勤月入职,考勤月离职 + absenceDays = getAbsenceDays(id, resignDate, toDate, fromDate); + } + } + + } + return absenceDays; + } + + /** + * 获取各种类型的调休时长 + * @return + */ + public Map getAllTiaoxius(String resourceid ,String fromdate, String todate) { + Map result = new HashMap(); + String acqSql = "SELECT " + + " a.resourceid, " + + " SUM(tiaoxiuamount) AS tiaoxiuamounts, " + + " SUM(usedamount) AS usedamounts, " + + " GREATEST( sum(extraamount) + SUM(tiaoxiuamount) - SUM(usedamount), 0.00000) AS difference_amounts, " + + " COALESCE(datetype, b.changetype) AS grouping_date, " + + " CASE " + + " WHEN datetype IS NOT NULL THEN datetype " + + " ELSE b.changetype " + + " END AS displayed_date " + + "FROM " + + " kq_balanceofleave a " + + "LEFT JOIN " + + " kq_flow_overtime b ON b.tiaoxiuid = a.id " + + "WHERE " + + " a.leaverulesid = 5 " + + " AND a.effectiveDate >= '"+fromdate+"' " + + " AND a.effectiveDate <= '"+todate+"' " + + " AND a.expirationDate >= '"+todate+"' " + + " AND a.resourceid = "+resourceid+" " + + "GROUP BY " + + " a.resourceid, " + + " COALESCE(datetype, b.changetype) " + + "ORDER BY " + + " grouping_date;"; + + + RecordSet rs = new RecordSet(); + rs.executeQuery(acqSql); + while (rs.next()){ + String differenceAmounts = Util.null2String(rs.getString("difference_amounts")); + String displayedDate = Util.null2String(rs.getString("displayed_date")); + if (StringUtils.isNotBlank(differenceAmounts) && StringUtils.isNotBlank(displayedDate)) { + result.put(displayedDate, differenceAmounts); + } + } + + return result; + } + + /** + * 获取上月各种类型的调休时长 + * @return + */ + public Map getLastAllTiaoxius(String resourceid ,String fromdate, String todate) { + Map result = new HashMap(); + Map lastMonthFirstAndLastDay = getLastMonthFirstAndLastDay(fromdate); + bb.writeLog("lastMonthFirstAndLastDay: " + lastMonthFirstAndLastDay); + + if (lastMonthFirstAndLastDay != null && lastMonthFirstAndLastDay.size() > 0) { + String firstDay = Util.null2String(lastMonthFirstAndLastDay.get("firstDay")); + String lastDay = Util.null2String(lastMonthFirstAndLastDay.get("lastDay")); + if (StringUtils.isNotBlank(firstDay)) { + fromdate = firstDay; + } + if (StringUtils.isNotBlank(lastDay)) { + todate = lastDay; + } + } + + + String acqSql = "SELECT " + + " a.resourceid, " + + " SUM(tiaoxiuamount) AS tiaoxiuamounts, " + + " SUM(usedamount) AS usedamounts, " + + " GREATEST( sum(extraamount) + SUM(tiaoxiuamount) - SUM(usedamount), 0.00000) AS difference_amounts, " + + " COALESCE(datetype, b.changetype) AS grouping_date, " + + " CASE " + + " WHEN datetype IS NOT NULL THEN datetype " + + " ELSE b.changetype " + + " END AS displayed_date " + + "FROM " + + " kq_balanceofleave a " + + "LEFT JOIN " + + " kq_flow_overtime b ON b.tiaoxiuid = a.id " + + "WHERE " + + " a.leaverulesid = 5 " + + " AND a.effectiveDate >= '"+fromdate+"' " + + " AND a.effectiveDate <= '"+todate+"' " + + " AND a.expirationDate >= '"+todate+"' " + + " AND a.resourceid = "+resourceid+" " + + "GROUP BY " + + " a.resourceid, " + + " COALESCE(datetype, b.changetype) " + + "ORDER BY " + + " grouping_date;"; + bb.writeLog("acqSql: " + acqSql); + + RecordSet rs = new RecordSet(); + rs.executeQuery(acqSql); + while (rs.next()){ + String differenceAmounts = Util.null2String(rs.getString("difference_amounts")); + String displayedDate = Util.null2String(rs.getString("displayed_date")); + if (StringUtils.isNotBlank(differenceAmounts) && StringUtils.isNotBlank(displayedDate)) { + result.put(displayedDate, differenceAmounts); + } + } + bb.writeLog("result: " + result); + return result; + } + + public Map getLastMonthFirstAndLastDay(String dateString) { + + Map result = new HashMap(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + // 解析给定的日期字符串 + LocalDate date = LocalDate.parse(dateString, formatter); + + // 获取上个月的第一天 + LocalDate firstDayOfLastMonth = date.with(TemporalAdjusters.firstDayOfMonth()).minusMonths(1); + + // 获取上个月的最后一天 + LocalDate lastDayOfLastMonth = date.with(TemporalAdjusters.lastDayOfMonth()).minusMonths(1); + // 格式化日期为字符串并返回 + result.put("firstDay", firstDayOfLastMonth.format(formatter)); + result.put("lastDay", lastDayOfLastMonth.format(formatter)); return result; }