From 144e9a7f51a638247897367cc962f0f318744e33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E6=A0=8B?= Date: Thu, 14 Mar 2024 18:17:21 +0800 Subject: [PATCH] Lee --- src/WEB-INF/nbjh_ygdjblc.properties | 18 + src/WEB-INF/nbkq_main.properties | 40 + src/com/engine/kq/biz/KQFormatData.java | 1053 ++++++ src/com/engine/kq/biz/KQFormatShiftRule.java | 485 +++ src/com/engine/kq/biz/KQFormatSignData.java | 649 ++++ src/com/engine/kq/biz/KQHolidaySetBiz.java | 452 +++ .../engine/kq/biz/KQOverTimeRuleCalBiz.java | 3202 ++++++++++++++++ src/com/engine/kq/biz/KQReportBiz.java | 2312 ++++++++++++ .../kq/biz/KQShiftManagementComInfo.java | 759 ++++ src/com/engine/kq/biz/KQWorkTime.java | 413 +++ .../GetLeaveWorkDurationCmd.java | 78 + .../GetOverTimeWorkDurationCmd.java | 196 + .../engine/kq/cmd/report/ExportExcelCmd.java | 764 ++++ .../kq/cmd/report/GetKQDailyReportCmd.java | 745 ++++ .../engine/kq/cmd/report/GetKQReportCmd.java | 790 ++++ .../kq/cmd/reportdetial/GetBeLateInfoCmd.java | 167 + .../reportdetial/GetLeaveEearlyInfoCmd.java | 167 + .../cmd/reportdetial/GetWorkDayInfoCmd.java | 146 + src/com/engine/kq/entity/WorkTimeEntity.java | 136 + .../impl/KQReportDetailServiceImpl.java | 54 + .../kq/util/KQDurationCalculatorUtil.java | 652 ++++ .../engine/kq/util/TimeRangeCalculator.java | 21 + src/com/engine/kq/util/TransMethod.java | 929 +++++ .../engine/kq/web/KQReportDetailAction.java | 144 + .../engine/kq/wfset/action/KqSplitAction.java | 72 + .../engine/kq/wfset/util/SplitActionUtil.java | 3208 +++++++++++++++++ .../bnkq/action/GdJbUpdateAction.java | 707 ++++ .../bnkq/action/UpdateCcTimeAction.java | 189 + 28 files changed, 18548 insertions(+) create mode 100644 src/WEB-INF/nbjh_ygdjblc.properties create mode 100644 src/WEB-INF/nbkq_main.properties create mode 100644 src/com/engine/kq/biz/KQFormatData.java create mode 100644 src/com/engine/kq/biz/KQFormatShiftRule.java create mode 100644 src/com/engine/kq/biz/KQFormatSignData.java create mode 100644 src/com/engine/kq/biz/KQHolidaySetBiz.java create mode 100644 src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java create mode 100644 src/com/engine/kq/biz/KQReportBiz.java create mode 100644 src/com/engine/kq/biz/KQShiftManagementComInfo.java create mode 100644 src/com/engine/kq/biz/KQWorkTime.java create mode 100644 src/com/engine/kq/cmd/attendanceEvent/GetLeaveWorkDurationCmd.java create mode 100644 src/com/engine/kq/cmd/attendanceEvent/GetOverTimeWorkDurationCmd.java create mode 100644 src/com/engine/kq/cmd/report/ExportExcelCmd.java create mode 100644 src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java create mode 100644 src/com/engine/kq/cmd/report/GetKQReportCmd.java create mode 100644 src/com/engine/kq/cmd/reportdetial/GetBeLateInfoCmd.java create mode 100644 src/com/engine/kq/cmd/reportdetial/GetLeaveEearlyInfoCmd.java create mode 100644 src/com/engine/kq/cmd/reportdetial/GetWorkDayInfoCmd.java create mode 100644 src/com/engine/kq/entity/WorkTimeEntity.java create mode 100644 src/com/engine/kq/service/impl/KQReportDetailServiceImpl.java create mode 100644 src/com/engine/kq/util/KQDurationCalculatorUtil.java create mode 100644 src/com/engine/kq/util/TimeRangeCalculator.java create mode 100644 src/com/engine/kq/util/TransMethod.java create mode 100644 src/com/engine/kq/web/KQReportDetailAction.java create mode 100644 src/com/engine/kq/wfset/action/KqSplitAction.java create mode 100644 src/com/engine/kq/wfset/util/SplitActionUtil.java create mode 100644 src/weaver/interfaces/bnkq/action/GdJbUpdateAction.java create mode 100644 src/weaver/interfaces/bnkq/action/UpdateCcTimeAction.java diff --git a/src/WEB-INF/nbjh_ygdjblc.properties b/src/WEB-INF/nbjh_ygdjblc.properties new file mode 100644 index 0000000..a7124ed --- /dev/null +++ b/src/WEB-INF/nbjh_ygdjblc.properties @@ -0,0 +1,18 @@ +#员工登记表流程-EHR 表单id +billid=-379 + +#员工登记表流程-EHR 流程id +workflowid=501 + +#六夜 班次 id +sixnight_serialid=3 + +#12小时工作制夜班 班次 id +twelvehours_night_serialid=11 + +#补卡申请-EHR 流程表名 +fillcard_table=formtable_main_394 + +#加班台账 模块id +overtime_formmmodeid=60 + diff --git a/src/WEB-INF/nbkq_main.properties b/src/WEB-INF/nbkq_main.properties new file mode 100644 index 0000000..9f8322a --- /dev/null +++ b/src/WEB-INF/nbkq_main.properties @@ -0,0 +1,40 @@ +#瀹佹尝绮惧崕鑰冨嫟闇姹 +#绠$悊浜哄憳鎸囧畾浜哄憳鑰冨嫟缁刬d +glrygroupid=6 +#绠$悊浜哄憳鑰冨嫟缁刬d +glgroupid=3 +#浜嬪亣鐥呭亣浜у亣id +sjbjcjid=6,7,8 +#濠氬亣涓у亣id +hjsjid=10,11 +#棰勫叆鑱屾祦绋媔d +yrzWfid=518 +#鍥哄畾娴佺▼鍒涘缓浜篿d +lccjr=43 +#鐩綍id +secid=187 +#绠$悊浜哄憳12灏忔椂鐝埗鐧界彮id +searIdBb=3 +#绠$悊浜哄憳12灏忔椂鐝埗鐧界彮鏈澶у姞鐝椂闀 +bbMaxMins=150 +#绠$悊浜哄憳12灏忔椂鐝埗澶滅彮id +searIdYb=2 +#绠$悊浜哄憳12灏忔椂鐝埗澶滅彮鏈澶у姞鐝椂闀 +ybMaxMins=240 +#鍔犵彮鐢宠娴佺▼琛ㄥ悕 +lctableName=formtable_main_374 +#涓ゅ皬鏃惰捣姝ュ姞鐝紤鐝id +twoStartSerId=12 + + + + + + + + + + + + + diff --git a/src/com/engine/kq/biz/KQFormatData.java b/src/com/engine/kq/biz/KQFormatData.java new file mode 100644 index 0000000..0d71ddd --- /dev/null +++ b/src/com/engine/kq/biz/KQFormatData.java @@ -0,0 +1,1053 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.entity.KQShiftRuleEntity; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.log.KQLog; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.googlecode.aviator.AviatorEvaluator; +import com.googlecode.aviator.Expression; +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.BatchRecordSet; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * 鑰冨嫟鏁版嵁鏍煎紡鍖 + */ +public class KQFormatData extends BaseBean { + private String today = DateUtil.getCurrentDate(); + private KQLog kqLog = new KQLog(); + private boolean writeLog = false; + private LinkedHashMap logInfo = new LinkedHashMap<>(); + + /*** + * 璇ユ柟娉曚笉鍏佽鐩存帴璋冪敤 + * @param userId + * @param kqDate + * @return + */ + public Map formatKqDate(String userId, String kqDate) { + List> lsParam = new ArrayList<>(); + //闈炲伐浣滄棩澶勭悊 + List nonlsParam = null; + Map resultMap = new HashMap<>(); + BatchRecordSet bRs = new BatchRecordSet(); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + kqLog.info("formatKqDate in userId=" + userId + "kqDate==" + kqDate); + if (DateUtil.timeInterval(kqDate, today) < 0) {//浠婂ぉ涔嬪悗鐨勬棤闇澶勭悊 + kqLog.info("浠婂ぉ涔嬪悗鐨勬棤闇澶勭悊鐨勬暟鎹細resourceid==" + userId + "kqdate==" + kqDate + "today==" + today); + return resultMap; + } + String uuid = UUID.randomUUID().toString(); + KQFormatFreeData kqFormatFreeData = new KQFormatFreeData(); + KQWorkTime kqWorkTime = new KQWorkTime(); + kqWorkTime.setIsFormat(true); + String kqDateNext = DateUtil.addDate(kqDate, 1); + + KQFlowDataBiz kqFlowDataBiz = new KQFlowDataBiz.FlowDataParamBuilder().resourceidParam(userId).fromDateParam(kqDate).toDateParam(kqDateNext).build(); + Map workFlowInfo = new HashMap<>();//userid|date--宸ヤ綔娴佺▼ + kqFlowDataBiz.getAllFlowData(workFlowInfo, false); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqDate); + kqLog.info("userId:" + userId + ":kqDate:" + kqDate + ":formatKqDate workTime=" + JSONObject.toJSONString(workTime) + "::uuid::" + uuid); + kqLog.info("userId:" + userId + ":kqDate:" + kqDate + ":formatKqDate workFlowInfo=" + JSONObject.toJSONString(workFlowInfo) + "::uuid::" + uuid); + + if (this.writeLog) { + logInfo.put("userId", userId); + logInfo.put("kqDate", kqDate); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(16253, weaver.general.ThreadVarLanguage.getLang()) + "", workTime); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(126871, weaver.general.ThreadVarLanguage.getLang()) + "", workFlowInfo); + } + + new KQFormatBiz().delFormatData(userId, kqDate); + + String excludecount = Util.null2String(kqGroupComInfo.getExcludecount(workTime.getGroupId()));//鏄惁鍙備笌鑰冨嫟鎶ヨ〃缁熻 + if (workTime.getIsExclude()) {//鏃犻渶鑰冨嫟浜哄憳娌℃湁寮傚父鐘舵 + if (!excludecount.equals("1")) { + kqLog.info("鏃犻渶鑰冨嫟浜哄憳娌℃湁寮傚父鐘舵 workTime.getIsExclude()=" + workTime.getIsExclude() + "excludecount==" + excludecount); + return resultMap; + } + } + if (Util.null2String(workTime.getGroupId()).length() == 0) { + //娌℃湁鑰冨嫟缁勪笉闇鏍煎紡鍖 + return resultMap; + } + if (workTime == null || workTime.getWorkMins() == 0) { + kqLog.info("workTime == null || workTime.getWorkMins() == 0 鎻掑叆绌鸿褰"); + nonlsParam = new ArrayList<>(); + formatNonWork(userId, kqDate, nonlsParam, workTime, workFlowInfo); + + if (!nonlsParam.isEmpty()) { + sql = " insert into kq_format_detail(resourceid,kqdate,groupid,serialnumber,signindate,signintime,signinid,signoutdate,signouttime,signoutid,leaveMins,leaveinfo,evectionMins,outMins)values(?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + rs.executeUpdate(sql, nonlsParam); + + sql = " insert into kq_format_total(resourceid,kqdate,subcompanyid,departmentid,jobtitle,groupid,serialid,workdays," + + " workmins,attendancedays,attendancemins,signdays,signmins,belate,belatemins,gravebelate,gravebelatemins,leaveeearly,leaveearlymins," + + " graveleaveearly,graveleaveearlymins,absenteeism,absenteeismmins,forgotcheck, forgotcheckMins,leaveMins,evectionMins,outMins)" + + " select a.resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid," + + " case when sum(workmins)>0 then 1 end as workdays, sum(workmins) as workmins," + + " 0 as attendancedays, sum(attendanceMins) as attendanceMins," + + " 0 as signdays, sum(signmins) as signmins," + + " sum(case when belatemins> 0 then 1 else 0 end) as belate,sum(belatemins) as belatemins," + + " sum(case when graveBeLateMins> 0 then 1 else 0 end) as graveBeLate,sum(graveBeLateMins) as graveBeLateMins," + + " sum(case when leaveearlymins> 0 then 1 else 0 end) as leaveearly,sum(leaveearlymins) as leaveearlymins," + + " sum(case when graveLeaveEarlyMins> 0 then 1 else 0 end) as graveLeaveEarly,sum(graveLeaveEarlyMins) as graveLeaveEarlyMins," + + " sum(case when absenteeismmins> 0 then 1 else 0 end) as absenteeism,sum(absenteeismmins) as absenteeismmins," + + " sum(case when forgotcheckmins> 0 then 1 else 0 end) as forgotcheck,sum(forgotcheckmins) as forgotcheckmins, " + + " sum(leaveMins) as leaveMins, sum(evectionMins) as evectionMins, sum(outMins) as outMins" + + " from kq_format_detail a, hrmresource b" + + " where a.resourceid = b.id and resourceid =? and kqdate=?" + + " group by resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid,workmins"; + rs.executeUpdate(sql, userId, kqDate); + } + } else { + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String definedField = ""; + String definedParam = ""; + String definedParamSum = ""; + if (workTime.getKQType().equals("3")) {//鑷敱宸ユ椂 + lsParam.addAll(kqFormatFreeData.format(userId, kqDate, workFlowInfo)); + } else { + definedField = Util.null2String(definedFieldInfo.get("definedField")); + definedParam = Util.null2String(definedFieldInfo.get("definedParam")); + definedParamSum = Util.null2String(definedFieldInfo.get("definedParamSum")); + lsParam.addAll(format(userId, kqDate, workTime, workFlowInfo, uuid)); + } + + if (lsParam.size() > 0) { + sql = " insert into kq_format_detail( " + + " resourceid,kqdate,groupid,serialid,serialnumber,workbegindate,workbegintime,workenddate,workendtime,workmins," + + " signindate,signintime,signinid,signoutdate,signouttime,signoutid,signMins," + + " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins," + + " leaveMins,leaveinfo,evectionMins,outMins,forgotbeginworkcheckmins,otherinfo" + (definedField.length() > 0 ? "," + definedField + "" : "") + ") " + + " values(?,?,?,?,?,?,?,?,?,?, ?,?,?,?,?,?,?, ?,?,?,?,?,?,?,?,?,?,?,?,?" + (definedField.length() > 0 ? "," + definedParam + "" : "") + ")"; + for (int i = 0; i < lsParam.size(); i++) { + List param = lsParam.get(i); + boolean isok = rs.executeUpdate(sql, param); + kqLog.info("鎻掑叆璁板綍:userId:" + userId + ":kqDate:" + kqDate + ":param:" + JSON.toJSONString(param) + ":isok:" + isok + "::uuid::" + uuid); + } + + sql = " insert into kq_format_total(resourceid,kqdate,subcompanyid,departmentid,jobtitle,groupid,serialid,workdays,workmins," + + " attendancedays,attendancemins,signdays,signmins,belate,belatemins,gravebelate,gravebelatemins,leaveeearly,leaveearlymins,graveleaveearly," + + " graveleaveearlymins,absenteeism,absenteeismmins,forgotcheck,forgotcheckmins," + + " leaveMins,evectionMins,outMins,forgotbeginworkcheck,forgotbeginworkcheckmins" + (definedField.length() > 0 ? "," + definedField + "" : "") + ") " + + " select a.resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid," + + " case when sum(workmins)>0 then 1 end as workdays, sum(workmins) as workmins," + + " cast(sum(attendanceMins)AS decimal(10, 2))/sum(workmins) as attendancedays, sum(attendanceMins) as attendanceMins," + + " cast(sum(signmins)AS decimal(10, 2))/sum(workmins) as signdays, sum(signmins) as signmins," + + " sum(case when belatemins> 0 then 1 else 0 end) as belate,sum(belatemins) as belatemins," + + " sum(case when graveBeLateMins> 0 then 1 else 0 end) as graveBeLate,sum(graveBeLateMins) as graveBeLateMins," + + " sum(case when leaveearlymins> 0 then 1 else 0 end) as leaveearly,sum(leaveearlymins) as leaveearlymins," + + " sum(case when graveLeaveEarlyMins> 0 then 1 else 0 end) as graveLeaveEarly,sum(graveLeaveEarlyMins) as graveLeaveEarlyMins, " + + " sum(case when absenteeismmins> 0 then 1 else 0 end) as absenteeism,sum(absenteeismmins) as absenteeismmins," + + " sum(case when forgotcheckmins> 0 then 1 else 0 end) as forgotcheck,sum(forgotcheckmins) as forgotcheckmins,sum(leaveMins) as leaveMins," + + " sum(evectionMins) as evectionMins,sum(outMins) as outMins, " + + " sum(case when forgotbeginworkcheckmins> 0 then 1 else 0 end) as forgotbeginworkcheck,sum(forgotbeginworkcheckmins) as forgotbeginworkcheckmins " + + (definedField.length() > 0 ? "," + definedParamSum + "" : "") + + " from kq_format_detail a, hrmresource b" + + " where a.resourceid = b.id and resourceid = ? and kqdate=?" + + " group by resourceid,kqdate,b.subcompanyid1,b.departmentid,b.jobtitle,groupid,serialid"; + rs.executeUpdate(sql, userId, kqDate); + } + } + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + return resultMap; + } + + public List> format(String userId, String kqDate, WorkTimeEntity workTime, + Map workFlowInfo, String uuid) { + List> lsParam = new ArrayList<>(); + List params = null; + try { + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String nosign_is_absent = Util.null2String(kqSettingsComInfo.getMain_val("nosign_is_absent"), "1"); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + KQFormatShiftRule kqFormatShiftRule = new KQFormatShiftRule(); + String preDate = DateUtil.addDate(kqDate, -1);//涓婁竴澶╂棩鏈 + String nextDate = DateUtil.addDate(kqDate, 1);//涓嬩竴澶╂棩鏈 + String dateKey = userId + "|" + kqDate; + String nextDateKey = userId + "|" + nextDate; +// ArrayList hostIps = InitServer.getRealIp(); + ArrayList hostIps = new ArrayList<>(); + kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + boolean oneSign = false; + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + List lsRestTime = new ArrayList<>(); + List workFlow = null; + + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + lsRestTime = workTime.getRestTime();//浼戞伅鏃舵鏃堕棿 + oneSign = lsWorkTime != null && lsWorkTime.size() == 1; + } + + int[] dayMins = new int[2880];//涓澶╂墍鏈夊垎閽熸暟 + Arrays.fill(dayMins, -1); + // 涓澶4娆℃墦鍗″崟鐙仛鍒ゆ柇锛屽鏋滄槸涓婂崍涓嬬彮鎵撳崱鍜屼笅鍗堜笂鐝墦鍗℃椂闂撮噸鍙狅紝閭d箞涓婂崍鐨勪笅鐝崱鍙栨渶鏃╃殑锛屼笅鍗堢殑涓婄彮鍗″彇鏈鏅氱殑銆傜敤shiftCount鏄惁绛変簬-1鍒ゆ柇锛-1灏辫蛋鏍囧噯涓嶉噸鍙犮2灏辫〃绀洪噸鍙犺蛋鏂扮殑閫昏緫 + int shiftCount = lsWorkTime == null ? 0 : lsWorkTime.size(); + int shiftI = 0; + String signEndDateTimeZero = ""; + for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) { + shiftI = i; + TimeScopeEntity signTimeScope = lsSignTime.get(i); + TimeScopeEntity workTimeScope = lsWorkTime.get(i); + String signBeginDateTime = signTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + if (signTimeScope.isBeginTimePreAcross()) { + signBeginDateTime = preDate; + } + signBeginDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime()) + ":00"; + String signEndDateTime = signTimeScope.getEndTimeAcross() ? nextDate : kqDate; + signEndDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime()) + ":59"; + if (shiftCount == 2 && shiftI == 0) { + signEndDateTimeZero = signEndDateTime; + } + if (shiftCount == 2 && shiftI == 1) { + shiftCount = signBeginDateTime.compareTo(signEndDateTimeZero) <= 0 ? shiftCount : -1; + } + } + for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) { + shiftI = i; + params = new ArrayList<>(); + TimeScopeEntity signTimeScope = lsSignTime.get(i); + TimeScopeEntity workTimeScope = lsWorkTime.get(i); + //TimeScopeEntity restTimeScope = lsRestTime.isEmpty()?null:lsRestTime.get(i); + String workBeginTime = Util.null2String(workTimeScope.getBeginTime()); + String ori_workBeginTime = workBeginTime; + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + boolean workBenginTimeAcross = workTimeScope.getBeginTimeAcross(); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + String ori_workEndTime = workEndTime; + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + boolean workEndTimeAcross = workTimeScope.getEndTimeAcross(); + int workMins = workTimeScope.getWorkMins(); + + String workBeginDate = workBenginTimeAcross ? nextDate : kqDate; + String workEndDate = workEndTimeAcross ? nextDate : kqDate; + + Arrays.fill(dayMins, workBeginIdx, workEndIdx, 1);//宸ヤ綔鏃舵鏍囪瘑 1 + + int beginIdx = 0; + int endIdx = 0; + int checkIn = 0; + int checkOut = 0; + String signInId = ""; + String signInDate = ""; + String signInTime = ""; + String signOutId = ""; + String signOutDate = ""; + String signOutTime = ""; + int earlyInMins = 0;//鏃╁埌鍒嗛挓鏁 + int lateOutMins = 0;//鏅氳蛋鍒嗛挓鏁 + int signMins = 0;//绛惧埌绛鹃鏃堕暱 + int tmpAttendanceMins = 0;//鍑哄嫟鍒嗛挓鏁帮紙娴佺▼鎶垫墸鏉ョ殑锛 + int attendanceMins = 0; + int beLateMins = 0; + int graveBeLateMins = 0; + int leaveEarlyMins = 0; + int graveLeaveEarlyMins = 0; + int absenteeismMins = 0; + int leaveMins = 0;//璇峰亣鏃堕暱 + Map leaveInfo = new HashMap<>();//璇峰亣淇℃伅 + Map otherinfo = new HashMap<>();//瀛樹竴浜涚敤寰楀埌鐨勪俊鎭 + int evectionMins = 0;//鍑哄樊鏃堕暱 + int outMins = 0;//鍏嚭鏃堕暱 + int otherMins = 0;//寮傚父娴佺▼鏃堕暱 + int forgotCheckMins = 0; + int forgotBeginWorkCheckMins = 0;//涓婄彮婕忕 + int signInTimeIndx = -1; + int flowSignInTimeIndx = -1; + int signInTimeOutdx = -1; + //鐢ㄦ潵璁$畻瀹為檯鎵撳崱鏃堕暱鐢ㄧ殑 + int signInTimeIndx4Sign = -1; + int signInTimeOutdx4Sign = -1; + + String signBeginDateTime = signTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + if (signTimeScope.isBeginTimePreAcross()) { + signBeginDateTime = preDate; + } + signBeginDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime()) + ":00"; + String signEndDateTime = signTimeScope.getEndTimeAcross() ? nextDate : kqDate; + signEndDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime()) + ":59"; + String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + workBeginDateTime += " " + kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime()) + ":00"; + String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate; + workEndDateTime += " " + kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime()) + ":00"; + + kqLog.info("signBeginDateTime" + signBeginDateTime + "::userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + kqLog.info("signEndDateTime" + signEndDateTime + "::userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + kqLog.info("workBeginDateTime" + workBeginDateTime + "::userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + kqLog.info("workEndDateTime" + workEndDateTime + "::userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + + Map shifRuleMap = Maps.newHashMap(); + if (oneSign) { + //涓у寲璁剧疆鍙敮鎸佷竴澶╀竴娆′笂涓嬬彮 + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setSplitDate(kqDate); + shiftInfoBean.setShiftRuleMap(workTime.getShiftRuleInfo()); + shiftInfoBean.setSignTime(lsSignTime); + shiftInfoBean.setWorkTime(lsWorkTime); + List logList = Lists.newArrayList(); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, userId, shifRuleMap, logList); + if (!shifRuleMap.isEmpty()) { + if (!logList.isEmpty()) { + otherinfo.put("logList", logList); + } + otherinfo.put("shiftRule", shifRuleMap); + if (shifRuleMap.containsKey("shift_beginworktime")) { + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + if (shift_beginworktime.length() > 0) { + workBeginTime = Util.null2String(shift_beginworktime); + workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + workTimeScope.setBeginTime(workBeginTime); + workTimeScope.setBeginTimeAcross(workBeginIdx >= 1440 ? true : false); + } + } + if (shifRuleMap.containsKey("shift_endworktime")) { + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if (shift_endworktime.length() > 0) { + workEndTime = Util.null2String(shift_endworktime); + workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + workTimeScope.setEndTime(workEndTime); + workTimeScope.setEndTimeAcross(workEndIdx >= 1440 ? true : false); + } + } + } + kqLog.info("涓у寲涔嬪悗 signBeginDateTime" + signBeginDateTime); + kqLog.info("涓у寲涔嬪悗 signEndDateTime" + signEndDateTime); + kqLog.info("涓у寲涔嬪悗 workBeginDateTime" + workBeginDateTime); + kqLog.info("涓у寲涔嬪悗 workEndDateTime" + workEndDateTime); + } + + List lsCheckInfo = new KQFormatSignData().getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, hostIps, uuid, shiftCount, shiftI); + kqLog.info("lsCheckInfo" + JSONObject.toJSONString(lsCheckInfo) + "::userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + if (this.writeLog) { + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005297, weaver.general.ThreadVarLanguage.getLang()) + "", signBeginDateTime); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005298, weaver.general.ThreadVarLanguage.getLang()) + "", signEndDateTime); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(1940, weaver.general.ThreadVarLanguage.getLang()) + "", workBeginDateTime); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005299, weaver.general.ThreadVarLanguage.getLang()) + "", workEndDateTime); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005300, weaver.general.ThreadVarLanguage.getLang()) + "", lsCheckInfo); + } + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signStatus = Util.null2String(checkInfo.get("signStatus")); + String signId = Util.null2String(checkInfo.get("signId")); + String signDate = Util.null2String(checkInfo.get("signDate")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String deduct_signintime = Util.null2String(checkInfo.get("deduct_signintime")); + String deduct_signofftime = Util.null2String(checkInfo.get("deduct_signofftime")); + String flow_signInTime = ""; + String flow_signOutTime = ""; + if (kqDate.compareTo(signDate) < 0) endIdx += 1440; + if (signTime.length() > 8) { + signTime = signTime.substring(0, 8); + } + if (checkInfo.get("signType").equals("1")) {//绛惧埌 + checkIn++; + //濡傛灉娴佺▼鎶垫墸瀛樺湪锛屾墦鍗℃椂闀夸篃瀛樺湪锛岄偅涔堢浉浜掓瘮杈冨緱鍒板嚭鍕ゆ椂闀垮拰鎵撳崱鏃堕暱 鏆備笉杩欐牱澶勭悊锛岃繕鏄寜鐓ф紡绛剧殑閫昏緫鏉ュ鐞 + if (signTime.length() > 0) { + signInTimeIndx4Sign = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + } + signInId = signId; + signInDate = signDate; + signInTime = signTime; + signInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(signInTime); + if (deduct_signintime.length() > 0) { + if (signTime.length() > 0) { + if (deduct_signintime.compareTo(signTime) < 0) { + flow_signInTime = deduct_signintime; + } + } else { + flow_signInTime = deduct_signintime; + } + } + if (flow_signInTime.length() > 0) { + flowSignInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signInTime); + } + if (kqDate.compareTo(signDate) < 0) { + signInTimeIndx += 1440; + flowSignInTimeIndx += 1440; + } else if (kqDate.compareTo(signDate) > 0) { + signInTimeIndx -= 1440; + signInTimeIndx = signInTimeIndx < 0 ? 0 : signInTimeIndx; + flowSignInTimeIndx -= 1440; + flowSignInTimeIndx = flowSignInTimeIndx < 0 ? 0 : flowSignInTimeIndx; + } + if (oneSign) { + if (workBeginIdx > signInTimeIndx) { + earlyInMins = workBeginIdx - signInTimeIndx; + } + } + } else if (checkInfo.get("signType").equals("2")) {//绛鹃 + checkOut++; + //濡傛灉娴佺▼鎶垫墸瀛樺湪锛屾墦鍗℃椂闀夸篃瀛樺湪锛岄偅涔堢浉浜掓瘮杈冨緱鍒板嚭鍕ゆ椂闀垮拰鎵撳崱鏃堕暱 鏆備笉杩欐牱澶勭悊锛岃繕鏄寜鐓ф紡绛剧殑閫昏緫鏉ュ鐞 + if (signTime.length() > 0) { + signInTimeOutdx4Sign = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + } + signOutId = signId; + signOutDate = signDate; + signOutTime = signTime; + signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(signOutTime); + if (deduct_signofftime.length() > 0) { + if (signTime.length() > 0) { + if (deduct_signofftime.compareTo(signTime) > 0) { + flow_signOutTime = deduct_signofftime; + } + } else { + flow_signOutTime = deduct_signofftime; + } + } + if (flow_signOutTime.length() > 0) { + signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signOutTime); + } + if (kqDate.compareTo(signDate) < 0) { + signInTimeOutdx += 1440; + } else if (kqDate.compareTo(signDate) > 0) { + signInTimeOutdx -= 1440; + signInTimeOutdx = signInTimeOutdx < 0 ? 0 : signInTimeOutdx; + } + if (oneSign) { + if (signInTimeOutdx > workEndIdx) { + lateOutMins = signInTimeOutdx - workEndIdx; + } + } + } + if (checkInfo.get("signType").equals("1")) {//绛惧埌 + if (signTime.length() > 0) { + String signMinTime = signTime.substring(0, 5) + ":00"; + endIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + if (signTime.compareTo(signMinTime) > 0) { + //濡傛灉绛惧埌鏃堕棿鏄甫绉掔殑涓旀槸杩熷埌锛岄偅涔堢鍒版椂闂村涓绉掑拰澶氫竴鍒嗛挓鏄竴鏍风殑 + endIdx += 1; + signInTimeIndx = signInTimeIndx + 1;//濡傛灉鏄甫绉掔殑鎵撳崱鏁版嵁涓嶅簲璇ュ奖鍝嶆祦绋嬫姷鎵g殑鏁版嵁鐨勪笅鏍 + } + if (kqDate.compareTo(signDate) < 0) { + endIdx += 1440; + } else if (kqDate.compareTo(signDate) > 0) { + endIdx -= 1440; + endIdx = endIdx < 0 ? 0 : endIdx; + } + if (endIdx > workBeginIdx) { + if (flow_signInTime.length() > 0) { + if (flowSignInTimeIndx > workBeginIdx) { + //澧炲姞涓涓垽鏂紝娴佺▼鎶垫墸鎵撳崱濡傛灉寮鍚簡骞朵笖鏈夋姷鎵d笂鐝墦鍗★紝閭d箞涔熷氨涓嶆槸杩熷埌浜 + Arrays.fill(dayMins, workBeginIdx, endIdx, 2);//杩熷埌鏃舵鏍囪瘑 2 + } + } else { + Arrays.fill(dayMins, workBeginIdx, endIdx, 2);//杩熷埌鏃舵鏍囪瘑 2 + } + } + } + } else if (checkInfo.get("signType").equals("2")) {//绛鹃 + if (signTime.length() > 0) { + beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + if (StringUtils.isNotBlank(signDate) && signDate.compareTo(kqDate) > 0) { + beginIdx += 1440; + } else if (kqDate.compareTo(signDate) > 0) { + beginIdx -= 1440; + beginIdx = beginIdx < 0 ? 0 : beginIdx; + } + if (workEndIdx > beginIdx) { + if (flow_signOutTime.length() > 0) { + if (workEndIdx > signInTimeOutdx) { + //澧炲姞涓涓垽鏂紝娴佺▼鎶垫墸鎵撳崱濡傛灉寮鍚簡骞朵笖鏈夋姷鎵d笅鐝墦鍗★紝閭d箞涔熷氨涓嶆槸鏃╅浜 + Arrays.fill(dayMins, beginIdx, workEndIdx, 3);//鏃╅鏃舵鏍囪瘑 3 + } + } else { + + Arrays.fill(dayMins, beginIdx, workEndIdx, 3);//鏃╅鏃舵鏍囪瘑 3 + } + } + } + } + } + + //鎵撳崱鏃堕暱=绛鹃鏃堕棿-绛惧埌鏃堕棿(鏈夌鍒扮閫鎵嶈绠) + if (checkIn == 1 && checkOut == 1) { + if (signInTimeIndx4Sign > -1 && signInTimeOutdx4Sign > -1) { + if (DateUtil.dayDiff(signInDate, signOutDate) == 0) {//鍚屼竴澶╃鍒板拰绛鹃 + signMins = signInTimeOutdx4Sign - signInTimeIndx4Sign; + } else if (DateUtil.dayDiff(signInDate, signOutDate) == 1) {//绗竴澶╃鍒帮紝绗簩澶╃閫 + if (signInTimeOutdx4Sign < signInTimeIndx4Sign) { + signMins = 1440 + signInTimeOutdx4Sign - signInTimeIndx4Sign; + } else { + signMins = 1440 + signInTimeOutdx4Sign - signInTimeIndx4Sign; + } + } + } else { + signMins = 0; + } + if (signMins < 0) { + signMins = 0; + } + } + + if (checkIn == 0 && checkOut == 0) {//鏃峰伐(鏃犵鍒版棤绛鹃) + if (workEndIdx > workBeginIdx) { + Arrays.fill(dayMins, workBeginIdx, workEndIdx, 4);//鏃峰伐鏃舵鏍囪瘑 4 + } + } + + if (checkOut == 0 && checkIn > 0) {//婕忕(鏈夌鍒版棤绛鹃) + if (signInTimeIndx > -1) { + if (workEndIdx > signInTimeIndx) { + //婕忕灏辨槸浠庢湰娆℃椂娈靛唴鐨勬墦鍗″埌涓嬬彮鐐 + //涓婄彮婕忕搴旇鏄粠绛惧埌鍒扮鍒扮粨鏉熸椂闂达紝涓嶈繃杩欓噷鍙互涓嶇敤绠★紝鍙槸涓涓鏁 + Arrays.fill(dayMins, signInTimeIndx, workEndIdx, 6);//涓婄彮婕忕鏃舵鏍囪瘑 6 + } else { + //绛惧埌鏅氫簬鏈鏃舵缁撴潫鏃堕棿锛屼篃绠楁紡绛 + forgotCheckMins++; + } + } else if (flowSignInTimeIndx > -1) { + if (workEndIdx > flowSignInTimeIndx) { + //婕忕灏辨槸浠庢湰娆℃椂娈靛唴鐨勬墦鍗″埌涓嬬彮鐐 + //涓婄彮婕忕搴旇鏄粠绛惧埌鍒扮鍒扮粨鏉熸椂闂达紝涓嶈繃杩欓噷鍙互涓嶇敤绠★紝鍙槸涓涓鏁 + Arrays.fill(dayMins, flowSignInTimeIndx, workEndIdx, 6);//涓婄彮婕忕鏃舵鏍囪瘑 6 + } else { + //绛惧埌鏅氫簬鏈鏃舵缁撴潫鏃堕棿锛屼篃绠楁紡绛 + forgotCheckMins++; + } + } + } + + if (checkIn == 0 && checkOut > 0) {//婕忕(鏈夌閫鏃犵鍒) + if (signInTimeOutdx > 0) { + if (workBeginIdx < signInTimeOutdx) { + //涓嬬彮婕忕搴旇鏄粠绛鹃鍒扮閫寮濮嬫椂闂达紝涓嶈繃杩欓噷鍙互涓嶇敤绠★紝鍙槸涓涓鏁 + Arrays.fill(dayMins, workBeginIdx, signInTimeOutdx, 66);//涓嬬彮婕忕鏃舵鏍囪瘑 66锛66鍛煎簲鍓嶉潰鐨勬紡绛剧殑6 + } else { + //杩欑鏁版嵁鐞嗚涓婁笉浼氬瓨鍦紝涔熻涓嬪惂 + forgotBeginWorkCheckMins++; + } + } + } + + if (workFlowInfo.get(dateKey) != null) { + workFlow = (List) workFlowInfo.get(dateKey); + } + + for (int j = 0; workFlow != null && j < workFlow.size(); j++) { + Map data = (Map) workFlow.get(j); + String flowType = Util.null2String(data.get("flowtype")); + String newLeaveType = Util.null2String(data.get("newleavetype")); + String signtype = Util.null2String(data.get("signtype")); + String serial = Util.null2String(data.get("serial")); + String requestId = Util.null2String(data.get("requestId")); + beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime"))); + endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime"))); + if (beginIdx >= endIdx) { + continue; + } + + if (flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 7);//鍑哄樊鎶垫墸鏃舵鏍囪瘑 7 + } else if (flowType.equals(FlowReportTypeEnum.OUT.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 8);//鍏嚭鎶垫墸鏃舵鏍囪瘑 8 + } else if (flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 5);//娴佺▼鎶垫墸鏃舵鏍囪瘑 5 + int tmpBeginIdx = beginIdx; + int tmpEndIdx = endIdx; + Integer val = 0; + + if (beginIdx >= workEndIdx) { + continue; + } + if (endIdx <= workBeginIdx) { + continue; + } + + if (leaveInfo.get(newLeaveType) == null) { + leaveInfo.put(newLeaveType, val); + } else { + val = (Integer) leaveInfo.get(newLeaveType); + } + + if (beginIdx < workBeginIdx) tmpBeginIdx = workBeginIdx; + if (endIdx > workEndIdx) tmpEndIdx = endIdx; + if (tmpEndIdx > tmpBeginIdx) { + leaveInfo.put(newLeaveType, val + (tmpEndIdx - tmpBeginIdx)); + } + } + } else { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 99);//寮傚父娴佺▼鎶垫墸鏃舵鏍囪瘑99 + } + } + } + + + if (workEndTimeAcross && false) {//璺ㄥぉ闇瑕佸姞鍏ヤ竴澶╃殑娴佺▼ + workFlow = null; + if (workFlowInfo.get(nextDateKey) != null) { + workFlow = (List) workFlowInfo.get(nextDateKey); + } + + for (int j = 0; workFlow != null && j < workFlow.size(); j++) { + Map data = (Map) workFlow.get(j); + String flowType = Util.null2String(data.get("flowtype")); + beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime"))) + 1440; + endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime"))) + 1440; + if (endIdx >= 2880) { + endIdx = 2880; + } + if (flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 7);//鍑哄樊鎶垫墸鏃舵鏍囪瘑 7 + } else if (flowType.equals(FlowReportTypeEnum.OUT.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 8);//鍏嚭鎶垫墸鏃舵鏍囪瘑 8 + } else if (flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 5);//娴佺▼鎶垫墸鏃舵鏍囪瘑 5 + + } + } else { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 99);//寮傚父娴佺▼鎶垫墸鏃舵鏍囪瘑99 + } + } + } + } + + if (lsRestTime != null && !lsRestTime.isEmpty()) { + for (int k = 0; k < lsRestTime.size(); k++) { + TimeScopeEntity restTimeScope = lsRestTime.get(k); + if (restTimeScope != null) { + String restBeginTime = Util.null2String(restTimeScope.getBeginTime()); + String restEndTime = Util.null2String(restTimeScope.getEndTime()); + beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(restBeginTime); + endIdx = kqTimesArrayComInfo.getArrayindexByTimes(restEndTime); + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, -11);//浼戞伅鏃堕棿 + } + } + } + int all_rest_cnt = kqTimesArrayComInfo.getCnt(dayMins, workBeginIdx, workEndIdx, -11); + if (all_rest_cnt >= 0) { + workMins = workMins - (all_rest_cnt); + } + } + + for (int j = workBeginIdx; j < workEndIdx; j++) { + switch (dayMins[j]) { + case 1: + tmpAttendanceMins++; + break; + case 2: + beLateMins++; + break; + case 3: + leaveEarlyMins++; + break; + case 4: + absenteeismMins++; + break; + case 5: + leaveMins++; + break; + case 6: + forgotCheckMins++; + break; + case 7: + evectionMins++; + break; + case 8: + outMins++; + break; + case 66: + forgotBeginWorkCheckMins++; + break; + case 99: + otherMins++; + break; + default: + break; + } + } + + if (forgotCheckMins == 1 && beLateMins == 0 && tmpAttendanceMins == 0) {//forgotCheckMins==1琛ㄧず涓嬬彮鍚庢紡绛撅紝涓嶆槸杩熷埌锛屾祦绋嬪凡瀹屽叏鎶垫墸寮傚父 + forgotCheckMins = 0; + } + + KQShiftRuleEntity kqShiftRuleEntity = new KQShiftRuleEntity(); + kqShiftRuleEntity.setUserId(userId); + kqShiftRuleEntity.setKqDate(kqDate); + kqShiftRuleEntity.setBelatemins(beLateMins); + kqShiftRuleEntity.setLeaveearlymins(leaveEarlyMins); + kqShiftRuleEntity.setAbsenteeismmins(absenteeismMins); + kqShiftRuleEntity.setForgotcheckmins(forgotCheckMins); + kqShiftRuleEntity.setForgotBeginWorkCheckMins(forgotBeginWorkCheckMins); + kqShiftRuleEntity.setEarlyInMins(earlyInMins); + kqShiftRuleEntity.setLateOutMins(lateOutMins); + kqLog.info("浜烘у寲瑙勫垯澶勭悊鍓嶆暟鎹" + JSONObject.toJSONString(kqShiftRuleEntity)); + if (this.writeLog) { + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005301, weaver.general.ThreadVarLanguage.getLang()) + "", kqShiftRuleEntity); + } + //浜烘у寲瑙勫垯 + kqShiftRuleEntity = kqFormatShiftRule.doShiftRule(workTime, kqShiftRuleEntity); + kqLog.info("浜烘у寲瑙勫垯澶勭悊鍚庢暟鎹" + JSONObject.toJSONString(kqShiftRuleEntity)); + if (this.writeLog) { + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005302, weaver.general.ThreadVarLanguage.getLang()) + "", kqShiftRuleEntity); + } + beLateMins = kqShiftRuleEntity.getBelatemins(); + graveBeLateMins = kqShiftRuleEntity.getGravebelatemins(); + leaveEarlyMins = kqShiftRuleEntity.getLeaveearlymins(); + graveLeaveEarlyMins = kqShiftRuleEntity.getGraveleaveearlymins(); + absenteeismMins = kqShiftRuleEntity.getAbsenteeismmins(); + forgotCheckMins = kqShiftRuleEntity.getForgotcheckmins(); + forgotBeginWorkCheckMins = kqShiftRuleEntity.getForgotBeginWorkCheckMins(); + + boolean isondutyfreecheck = false; + boolean isoffdutyfreecheck = false; + Map model_ShiftRule = kqFormatShiftRule.getModel_ShiftRule(i, workTime.getSerialId()); + Iterator iter = model_ShiftRule.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = (Map.Entry) iter.next(); + String key = Util.null2String(entry.getKey()); + String value = Util.null2String(entry.getValue()); + if (key.equals("start") && value.equals("1")) { + isondutyfreecheck = true; + } + if (key.equals("end") && value.equals("1")) { + isoffdutyfreecheck = true; + } + } + boolean beforeBegin = !new KQFormatBiz().needCal(workBeginDate, workBeginTime); + if (beforeBegin) {//杩樻湭鍒颁笂鐝椂闂达紝涓嶇敤璁$畻浠讳綍鐘舵 + kqLog.writeLog("杩樻湭鍒颁笂鐝椂闂达紝涓嶇敤璁$畻浠讳綍鐘舵"); + beLateMins = 0; + graveBeLateMins = 0; + leaveEarlyMins = 0; + graveLeaveEarlyMins = 0; + absenteeismMins = 0; + forgotCheckMins = 0; + forgotBeginWorkCheckMins = 0; + } else if (!new KQFormatBiz().needCal(workEndDate, workEndTime)) {//杩樻湭鍒颁笅鐝椂闂 + kqLog.writeLog("杩樻湭鍒颁笂鐝椂闂"); + leaveEarlyMins = 0; + graveLeaveEarlyMins = 0; + forgotCheckMins = 0; + } + + if (workTime.getIsExclude()) {//鏃犻渶鑰冨嫟浜哄憳娌℃湁寮傚父鐘舵 + beLateMins = 0; + graveBeLateMins = 0; + leaveEarlyMins = 0; + graveLeaveEarlyMins = 0; + absenteeismMins = 0; + forgotCheckMins = 0; + forgotBeginWorkCheckMins = 0; + } + //鍏佽涓嬬彮涓嶆墦鍗 ,濡傛灉涓婄彮涔熸病鏈夋墦鍗★紝閭d箞绠椾笂鐝椃宸0.5澶 + if (isoffdutyfreecheck) { + if (checkIn == 0) {//(鏃犵鍒),灏变細鏈変笂鐝紡绛撅紝濡傛灉鏈変笅鐝崱锛岄偅涔堜笂鐝紡绛 + if (forgotBeginWorkCheckMins == 0 && absenteeismMins > 0) { + forgotBeginWorkCheckMins = absenteeismMins; + } + } + absenteeismMins = 0; + forgotCheckMins = 0; + } + //鍏佽涓婄彮涓嶆墦鍗★紝濡傛灉涓嬬彮涔熸病鏈夋墦鍗★紝閭d箞绠楁紡绛 + if (isondutyfreecheck) { + if (checkOut == 0) {//(鏃犵閫) + if (forgotCheckMins == 0 && absenteeismMins > 0) { + forgotCheckMins = absenteeismMins; + } + } + absenteeismMins = 0; + forgotBeginWorkCheckMins = 0; + } + if (isondutyfreecheck && isoffdutyfreecheck) { + absenteeismMins = 0; + forgotCheckMins = 0; + forgotBeginWorkCheckMins = 0; + } + //璁$畻瀹為檯鍑哄嫟鏃堕棿(鍑哄樊鍏嚭绠楀嚭鍕)=搴斿嚭鍕-鏃峰伐-璇峰亣-杩熷埌-鏃╅ + attendanceMins = workMins - absenteeismMins - leaveMins - beLateMins - graveBeLateMins - leaveEarlyMins - graveLeaveEarlyMins; + // 濡傛灉娌℃湁寮鍚"婕忕鏄惁绠楀疄闄呭嚭鍕"寮鍏筹紝鍒欐紡绛句笉绠楀疄闄呭嚭鍕ゆ椂闀 + if ("0".equals(nosign_is_absent)) { + attendanceMins = attendanceMins - forgotCheckMins - forgotBeginWorkCheckMins; + } + if (beforeBegin || attendanceMins < 0) {//杩樻湭鍒颁笂鐝椂闂达紝涓嶇敤璁$畻浠讳綍鐘朵綋 + attendanceMins = 0; + } + kqLog.info("瀹為檯鍑哄嫟璁$畻鍏紡" + "瀹為檯鍑哄嫟=搴斿嚭鍕- 鏃峰伐-璇峰亣-杩熷埌-鏃╅ userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + kqLog.info("瀹為檯鍑哄嫟璁$畻缁撴灉" + attendanceMins + "=" + workMins + "- " + absenteeismMins + "-" + leaveMins + "-" + (beLateMins + graveBeLateMins) + "-" + (leaveEarlyMins - graveLeaveEarlyMins) + " userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid); + if (this.writeLog) { + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005303, weaver.general.ThreadVarLanguage.getLang()) + "", "" + weaver.systeminfo.SystemEnv.getHtmlLabelName(130566, weaver.general.ThreadVarLanguage.getLang()) + "=" + weaver.systeminfo.SystemEnv.getHtmlLabelName(132056, weaver.general.ThreadVarLanguage.getLang()) + "- " + weaver.systeminfo.SystemEnv.getHtmlLabelName(20085, weaver.general.ThreadVarLanguage.getLang()) + "-" + weaver.systeminfo.SystemEnv.getHtmlLabelName(670, weaver.general.ThreadVarLanguage.getLang()) + "-" + weaver.systeminfo.SystemEnv.getHtmlLabelName(20081, weaver.general.ThreadVarLanguage.getLang()) + "-" + weaver.systeminfo.SystemEnv.getHtmlLabelName(20082, weaver.general.ThreadVarLanguage.getLang()) + ""); + logInfo.put("" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005304, weaver.general.ThreadVarLanguage.getLang()) + "", attendanceMins + "=" + workMins + "- " + absenteeismMins + "-" + leaveMins + "-" + (beLateMins + graveBeLateMins) + "-" + (leaveEarlyMins - graveLeaveEarlyMins)); + } + //鍒ゆ柇褰撳ぉ鑰冨嫟鐘舵 +// if (beLateMins > 0) { +// status = ButtonStatusEnum.BELATE.getStatusCode(); +// } else if (leaveEarlyMins > 0) { +// status = ButtonStatusEnum.LEAVEERALY.getStatusCode(); +// } else if (absenteeismMins > 0) { +// status = ButtonStatusEnum.ABSENT.getStatusCode(); +// } else if (forgotCheckMins > 0) { +// status = ButtonStatusEnum.NOSIGN.getStatusCode(); +// } else { +// status = ButtonStatusEnum.NORMAL.getStatusCode(); +// } + + String groupid = Util.null2String(workTime.getGroupId()); + String serialid = Util.null2String(workTime.getSerialId()); + + params.add(userId); + params.add(kqDate); + params.add(groupid.length() == 0 ? null : groupid); + params.add(serialid.length() == 0 ? null : serialid); + params.add(i); + params.add(workBeginDate); + params.add(kqTimesArrayComInfo.turn48to24Time(ori_workBeginTime)); + params.add(workEndDate); + params.add(kqTimesArrayComInfo.turn48to24Time(ori_workEndTime)); + params.add(workMins); + params.add(signInDate); + params.add(signInTime); + params.add(signInId.length() == 0 ? null : signInId); + params.add(signOutDate); + params.add(signOutTime); + params.add(signOutId.length() == 0 ? null : signOutId); + kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid + + ":signInDate:" + signInDate + ":signInTime::" + signInTime + ":signOutDate:" + signOutDate + ":signOutTime::" + signOutTime); + params.add(signMins); + params.add(attendanceMins); + params.add(beLateMins); + params.add(graveBeLateMins); + params.add(leaveEarlyMins); + params.add(graveLeaveEarlyMins); + //浜屽紑 浼戠彮娆′笉璁℃椃宸 + if (workTime.getRestShift() == 1 && absenteeismMins > 0) { + absenteeismMins = 0; + } + params.add(absenteeismMins); + params.add(forgotCheckMins); + params.add(leaveMins); + params.add(JSONObject.toJSONString(leaveInfo)); + params.add(evectionMins); + params.add(outMins); + params.add(forgotBeginWorkCheckMins); + params.add(JSONObject.toJSONString(otherinfo)); + + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String[] definedFields = Util.splitString(Util.null2String(definedFieldInfo.get("definedField")), ","); + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + for (int tmpIdx = 0; tmpIdx < definedFields.length; tmpIdx++) { + String fieldname = definedFields[tmpIdx]; +// System.out.println("fieldname=="+fieldname); + String fieldid = KQReportFieldComInfo.field2Id.get(fieldname); + String formula = kqReportFieldComInfo.getFormula(fieldid); + if (formula.length() == 0) continue; + String expression = formula; + Pattern pattern = Pattern.compile("\\$\\{[^}]+\\}"); + Matcher matcher = pattern.matcher(expression); + Map env = new HashMap<>(); + String keyname = ""; + while (matcher.find()) { + String key = matcher.group(0); + keyname = key.substring(2, key.length() - 1).trim(); + expression = matcher.replaceAll(keyname); + env.put(keyname, keyname.equals("beLateMins") ? beLateMins : leaveEarlyMins); + } + Expression compiledExp = AviatorEvaluator.compile(expression, true); + String value = Util.null2String(compiledExp.execute(env)); + params.add(value); + if (value.equals("1")) { + params.add(keyname.equals("beLateMins") ? beLateMins : leaveEarlyMins); + } else { + params.add("0"); + } + } + kqLog.info("format in >>>>>userId" + userId + "kqDate==" + kqDate + ":hostIps:" + hostIps + ":uuid::" + uuid + + ":params:" + JSON.toJSONString(params)); + lsParam.add(params); + } + } catch (Exception e) { + writeLog(e); + kqLog.info(e); + } + return lsParam; + } + + public void setWriteLog(boolean writeLog) { + this.writeLog = writeLog; + } + + public Map getLogInfo() { + return logInfo; + } + + public void formatDateByKQDate(String kqdate) { + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.formatDateByKQDate(kqdate); + } + + public void formatDateByGroupId(String groupid, String kqdate) { + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.formatDateByGroupId(groupid, kqdate); + } + + public void formatDate(String resourceid, String kqdate) { + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.formatDate(resourceid, kqdate); + } + + public void delFormatData(String resourceid, String kqdate) { + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.delFormatData(resourceid, kqdate); + } + + /** + * 闈炲伐浣滄棩鏍煎紡鍖栬冨嫟鎶ヨ〃 + * + * @param userId + * @param kqDate + * @param nonlsParam + * @param workTime + * @param workFlowInfo + */ + public void formatNonWork(String userId, String kqDate, List nonlsParam, WorkTimeEntity workTime, Map workFlowInfo) { + String signInId = ""; + String signInDate = ""; + String signInTime = ""; + String signOutId = ""; + String signOutDate = ""; + String signOutTime = ""; + int beginIdx = 0; + int endIdx = 0; + int leaveMins = 0;//璇峰亣鏃堕暱 + Map leaveInfo = new HashMap<>();//璇峰亣淇℃伅 + int evectionMins = 0;//鍑哄樊鏃堕暱 + int outMins = 0;//鍏嚭鏃堕暱 + int otherMins = 0;//寮傚父娴佺▼鏃堕暱 + int[] dayMins = new int[2880];//涓澶╂墍鏈夊垎閽熸暟 + List workFlow = null; + String dateKey = userId + "|" + kqDate; + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + String preDate = DateUtil.addDate(kqDate, -1);//涓婁竴澶╂棩鏈 + String nextDate = DateUtil.addDate(kqDate, 1);//涓嬩竴澶╂棩鏈 + WorkTimeEntity pre_workTime = new KQWorkTime().getWorkTime(userId, preDate); + List pre_lsSignTime = new ArrayList<>(); + + if (pre_workTime != null) { + pre_lsSignTime = pre_workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + pre_lsSignTime = pre_lsSignTime != null ? pre_lsSignTime : new ArrayList<>(); + } + WorkTimeEntity next_workTime = new KQWorkTime().getWorkTime(userId, nextDate); + List next_lsSignTime = new ArrayList<>(); + + if (next_workTime != null) { + next_lsSignTime = next_workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + next_lsSignTime = next_lsSignTime != null ? next_lsSignTime : new ArrayList<>(); + } + + List lsCheckInfo = new KQFormatSignData().getNonWorkSignInfo(userId, preDate, kqDate, pre_lsSignTime, next_lsSignTime); + + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signStatus = Util.null2String(checkInfo.get("signStatus")); + String signId = Util.null2String(checkInfo.get("signId")); + String signDate = Util.null2String(checkInfo.get("signDate")); + String signTime = Util.null2String(checkInfo.get("signTime")); + if (checkInfo.get("signType").equals("1")) {//绛惧埌 + signInId = signId; + signInDate = signDate; + signInTime = signTime; + } else if (checkInfo.get("signType").equals("2")) {//绛鹃 + signOutId = signId; + signOutDate = signDate; + signOutTime = signTime; + } + } + + if (workFlowInfo.get(dateKey) != null) { + workFlow = (List) workFlowInfo.get(dateKey); + } + + for (int j = 0; workFlow != null && j < workFlow.size(); j++) { + Map data = (Map) workFlow.get(j); + String flowType = Util.null2String(data.get("flowtype")); + String newLeaveType = Util.null2String(data.get("newleavetype")); + beginIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("begintime"))); + endIdx = kqTimesArrayComInfo.getArrayindexByTimes(Util.null2String(data.get("endtime"))); + if (flowType.equals(FlowReportTypeEnum.EVECTION.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 7);//鍑哄樊鎶垫墸鏃舵鏍囪瘑 7 + } else if (flowType.equals(FlowReportTypeEnum.OUT.getFlowType())) { + Arrays.fill(dayMins, beginIdx, endIdx, 8);//鍏嚭鎶垫墸鏃舵鏍囪瘑 8 + } else if (flowType.equalsIgnoreCase(FlowReportTypeEnum.LEAVE.getFlowType())) { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 5);//娴佺▼鎶垫墸鏃舵鏍囪瘑 5 + int tmpBeginIdx = beginIdx; + int tmpEndIdx = endIdx; + Integer val = 0; + if (leaveInfo.get(newLeaveType) == null) { + leaveInfo.put(newLeaveType, val); + } else { + val = (Integer) leaveInfo.get(newLeaveType); + } + if (tmpEndIdx > tmpBeginIdx) { + leaveInfo.put(newLeaveType, val + (tmpEndIdx - tmpBeginIdx)); + } + } + } else { + if (endIdx > beginIdx) { + Arrays.fill(dayMins, beginIdx, endIdx, 99);//寮傚父娴佺▼鎶垫墸鏃舵鏍囪瘑99 + } + } + } + + for (int j = 0; j < 2880; j++) { + switch (dayMins[j]) { + case 5: + leaveMins++; + break; + case 7: + evectionMins++; + break; + case 8: + outMins++; + break; + case 99: + otherMins++; + break; + default: + break; + } + } + + nonlsParam.add(userId); + nonlsParam.add(kqDate); + nonlsParam.add(workTime.getGroupId()); + nonlsParam.add(0); + nonlsParam.add(signInDate); + nonlsParam.add(signInTime); + nonlsParam.add(signInId.length() == 0 ? null : signInId); + nonlsParam.add(signOutDate); + nonlsParam.add(signOutTime); + nonlsParam.add(signOutId.length() == 0 ? null : signOutId); + nonlsParam.add(leaveMins); + nonlsParam.add(JSONObject.toJSONString(leaveInfo)); + nonlsParam.add(evectionMins); + nonlsParam.add(outMins); + } +} diff --git a/src/com/engine/kq/biz/KQFormatShiftRule.java b/src/com/engine/kq/biz/KQFormatShiftRule.java new file mode 100644 index 0000000..126cca5 --- /dev/null +++ b/src/com/engine/kq/biz/KQFormatShiftRule.java @@ -0,0 +1,485 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum; +import com.engine.kq.entity.KQShiftRuleEntity; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.TimeSignScopeEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +import java.util.*; + +/** + * 鏍煎紡鍖栨暟鎹 浜烘у寲瑙勫垯 + */ +public class KQFormatShiftRule extends BaseBean { + private KQLog kqLog = new KQLog(); + + public KQShiftRuleEntity doShiftRule(WorkTimeEntity workTime, KQShiftRuleEntity kqShiftRuleEntity) { + Map shiftRuleInfo = workTime.getShiftRuleInfo(); + //浜烘у寲澶勭悊 + if (shiftRuleInfo != null && shiftRuleInfo.size() > 0) { + Map ruleDetail = (Map) shiftRuleInfo.get("ruleDetail"); + //鍏佽杩熷埌鍒嗛挓鏁 + boolean usepermitlateminutes = Util.null2String(shiftRuleInfo.get("permitlatestatus")).equals("1"); + int permitlateminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("permitlateminutes")), 0); + boolean enableexcludelate = Util.null2String(shiftRuleInfo.get("enableexcludelate")).equals("1"); + //鍏佽鏃╅鍒嗛挓鏁 + boolean usepermitleaveearlyminutes = Util.null2String(shiftRuleInfo.get("permitleaveearlystatus")).equals("1"); + int permitleaveearlyminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("permitleaveearlyminutes")), 0); + boolean enableexcludeleaveearly = Util.null2String(shiftRuleInfo.get("enableexcludeleaveearly")).equals("1"); + + //涓ラ噸杩熷埌鍒嗛挓鏁 + boolean useseriouslateminutes = Util.null2String(shiftRuleInfo.get("seriouslatestatus")).equals("1"); + int seriouslateminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("seriouslateminutes")), 0); + //涓ラ噸鏃╅鍒嗛挓鏁 + boolean useseriousleaveearlyminutes = Util.null2String(shiftRuleInfo.get("seriousleaveearlystatus")).equals("1"); + int seriousleaveearlyminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("seriousleaveearlyminutes")), 0); + //杩熷埌澶氬皯閽熸暟绠楁椃宸 + boolean uselateabsentminutes = Util.null2String(shiftRuleInfo.get("lateabsentstatus")).equals("1"); + int lateabsentminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("lateabsentminutes")), 0); + //鏃╅澶氬皯閽熸暟绠楁椃宸 + boolean useleaveearlyabsentminutes = Util.null2String(shiftRuleInfo.get("leaveearlyabsentstatus")).equals("1"); + int leaveearlyabsentminutes = Util.getIntValue(Util.null2String(shiftRuleInfo.get("leaveearlyabsentminutes")), 0); + //鍏佽涓嬬彮涓嶆墦鍗 + boolean isoffdutyfreecheck = Util.null2String(shiftRuleInfo.get("isoffdutyfreecheck")).equals("1"); + + String userId = kqShiftRuleEntity.getUserId(); + String kqDate = kqShiftRuleEntity.getKqDate(); + int beLateMins = kqShiftRuleEntity.getBelatemins(); + int graveBeLateMins = 0; + int leaveEarlyMins = kqShiftRuleEntity.getLeaveearlymins(); + int graveLeaveEarlyMins = 0; + int absenteeismMins = kqShiftRuleEntity.getAbsenteeismmins(); + int forgotcheckMins = kqShiftRuleEntity.getForgotcheckmins(); + int forgotBeginWorkCheckMins = kqShiftRuleEntity.getForgotBeginWorkCheckMins(); + int earlyInMins = kqShiftRuleEntity.getEarlyInMins(); + int lateOutMins = kqShiftRuleEntity.getLateOutMins(); + + List earlyinearlyout = null;//鏃╁埌鏃╄蛋瑙勫垯 + List lateinlateout = null;//鏅氬埌鏅氳蛋瑙勫垯 + List lateoutlatein = null;//鏅氳蛋鏅氬埌瑙勫垯 + + //杩欓噷涓у寲娌℃硶澶勭悊娴佺▼鏁版嵁锛岄昏緫鏀逛负鍦ㄥ墠闈㈢洿鎺ヨ櫄鎷熸敼鎺変簡涓婁笅鐝椂闂 + if (ruleDetail != null && ruleDetail.size() > 0 && false) {//澶勭悊浜烘у寲璁剧疆鍏朵粬瑙勫垯 + earlyinearlyout = (List) ruleDetail.get("earlyinearlyout"); + lateinlateout = (List) ruleDetail.get("lateinlateout"); + lateoutlatein = (List) ruleDetail.get("lateoutlatein"); + + if (earlyinearlyout != null && earlyinearlyout.size() > 0 && leaveEarlyMins > 0) { + for (int i = 0; earlyInMins > 0 && i < earlyinearlyout.size(); i++) { + Map rule = (Map) earlyinearlyout.get(i); + if (Util.null2String(rule.get("enable")).equals("1")) { + int advancetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("advancetime"))))).intValue();//鏃╁埌鏃堕棿 + int postponetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("postponetime"))))).intValue();//鍏佽鏃╄蛋鏃堕棿 + if (Util.null2String(rule.get("enablesame")).equals("1")) { + if(earlyInMins>postponetime){ + leaveEarlyMins -= postponetime; + if (leaveEarlyMins < 0) leaveEarlyMins = 0; + }else{ + leaveEarlyMins -= earlyInMins; + if (leaveEarlyMins < 0) leaveEarlyMins = 0; + } + break; + }else{ + if (earlyInMins >= advancetime) { + leaveEarlyMins -= postponetime; + if (leaveEarlyMins < 0) leaveEarlyMins = 0; + break; + } + } + } + } + } + + if (lateinlateout != null && lateinlateout.size() > 0 && beLateMins > 0) { + for (int i = 0; lateOutMins > 0 && i < lateinlateout.size(); i++) { + Map rule = (Map) lateinlateout.get(i); + if (Util.null2String(rule.get("enable")).equals("1")) { + int advancetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("advancetime"))))).intValue();//鏅氬埌鏃堕棿 + int postponetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("postponetime"))))).intValue();//闇瑕佹櫄璧版椂闂 + if (Util.null2String(rule.get("enablesame")).equals("1")) { + if(lateOutMins>postponetime){ + beLateMins -= postponetime; + if (beLateMins < 0) beLateMins = 0; + }else{ + beLateMins -= lateOutMins; + if (beLateMins < 0) beLateMins = 0; + } + break; + }else{ + if (lateOutMins >= postponetime) { + beLateMins -= advancetime; + if (beLateMins < 0) beLateMins = 0; + break; + } + } + } + } + } + + if (lateoutlatein != null && lateoutlatein.size() > 0 && beLateMins > 0) { + int preDayLateOutMins = getPreDayLateOutMins(userId, kqDate); + for (int i = 0; preDayLateOutMins > 0 && i < lateoutlatein.size(); i++) { + Map rule = (Map) lateoutlatein.get(i); + if (Util.null2String(rule.get("enable")).equals("1")) { + int advancetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("advancetime"))))).intValue();//鏅氳蛋鏃堕棿 + int postponetime = new Double((Util.getDoubleValue(Util.null2String(rule.get("postponetime"))))).intValue();//鍏佽鏅氬埌鏃堕棿 + + if (Util.null2String(rule.get("enablesame")).equals("1")) { + if(preDayLateOutMins>postponetime){ + beLateMins -= postponetime; + if (beLateMins < 0) beLateMins = 0; + }else{ + beLateMins -= preDayLateOutMins; + if (beLateMins < 0) beLateMins = 0; + } + break; + }else{ + if (preDayLateOutMins >= advancetime) { + beLateMins -= postponetime; + if (beLateMins < 0) beLateMins = 0; + break; + } + } + } + } + } + } + + if (beLateMins > 0) {//杩熷埌浜烘у寲璁剧疆 + if (usepermitlateminutes) {//鍏佽杩熷埌鍒嗛挓鏁 + if(permitlateminutes >= beLateMins) { + beLateMins = 0; + }else if(enableexcludelate){ + beLateMins = beLateMins - permitlateminutes; + } + } + + if (uselateabsentminutes && beLateMins >= lateabsentminutes) {//鏃峰伐 + absenteeismMins += beLateMins; + beLateMins = 0; + //leaveEarlyMins = 0; + forgotcheckMins=0 ; + } else if (useseriouslateminutes && beLateMins >= seriouslateminutes) {//涓ラ噸杩熷埌 + graveBeLateMins += beLateMins; + //TODO 杩欐湁涓棶棰橈紝涓ラ噸杩熷埌浜嗭紝杩樿涓嶈绠楄繜鍒帮紵杩欎袱涓槸鍚屾椂瀛樺湪鐨勫悧锛 + beLateMins = 0; + } + } + + if (leaveEarlyMins > 0) {//鏃╅浜烘у寲璁剧疆 + if (usepermitleaveearlyminutes) {//鍏佽鏃╅鍒嗛挓鏁 + if(permitleaveearlyminutes >= leaveEarlyMins){ + leaveEarlyMins = 0; + }else if (enableexcludeleaveearly) { + leaveEarlyMins = leaveEarlyMins - permitleaveearlyminutes; + } + } + if (useleaveearlyabsentminutes && leaveEarlyMins >= leaveearlyabsentminutes) {//鏃峰伐 + absenteeismMins += leaveEarlyMins; + //beLateMins = 0; + leaveEarlyMins = 0; + forgotcheckMins=0 ; + forgotBeginWorkCheckMins = 0; + } else if (useseriousleaveearlyminutes && leaveEarlyMins >= seriousleaveearlyminutes) {//涓ラ噸鏃╅ + graveLeaveEarlyMins += leaveEarlyMins; + //TODO 杩欐湁涓棶棰橈紝涓ラ噸鏃╅浜嗭紝杩樿涓嶈绠楁棭閫锛熻繖涓や釜鏄悓鏃跺瓨鍦ㄧ殑鍚楋紵 + leaveEarlyMins = 0; + } + } + //鍏佽涓嬬彮涓嶆墦鍗 + if (isoffdutyfreecheck) { + forgotcheckMins = 0; + } + + kqShiftRuleEntity.setBelatemins(beLateMins); + kqShiftRuleEntity.setGravebelatemins(graveBeLateMins); + kqShiftRuleEntity.setLeaveearlymins(leaveEarlyMins); + kqShiftRuleEntity.setGraveleaveearlymins(graveLeaveEarlyMins); + kqShiftRuleEntity.setAbsenteeismmins(absenteeismMins); + kqShiftRuleEntity.setForgotcheckmins(forgotcheckMins); + kqShiftRuleEntity.setForgotBeginWorkCheckMins(forgotBeginWorkCheckMins); + } + return kqShiftRuleEntity; + } + + public int getEarlyInMins(String userId, String kqDate){ + int earlyInMins = 0; + boolean oneSign = false; + String preDate = DateUtil.addDate(kqDate, -1);//涓婁竴澶╂棩鏈 + String nextDate = DateUtil.addDate(kqDate, 1);//涓嬩竴澶╂棩鏈 + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqDate); + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + oneSign = lsWorkTime != null && lsWorkTime.size() == 1; + } + + if (oneSign) { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + TimeScopeEntity signTimeScope = lsSignTime.get(0); + TimeScopeEntity workTimeScope = lsWorkTime.get(0); + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workTimeScope.getBeginTime()); + + List lsCheckInfo = new KQFormatSignData().getSignInfo(userId,signTimeScope,workTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo); + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signDate = Util.null2String(checkInfo.get("signDate")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String deduct_signintime = Util.null2String(checkInfo.get("deduct_signintime")); + if (checkInfo.get("signType").equals("1")) {//绛惧埌 + //鏈夌鍒颁絾鏄病鏈塻ignTime鏄洜涓哄紑鍚簡娴佺▼鎶垫墸鎵撳崱 + if(null == signTime || signTime.length()<5){ + continue; + }else{ + writeLog("signDate:"+signDate+",signTime="+signTime+",checkInfo="+checkInfo.toString()); + } + String signMinTime = signTime.substring(0,5)+":00"; + boolean signInWorkBeginTime = false; + if(signTime.compareTo(signMinTime) > 0){ + //濡傛灉绛惧埌鏃堕棿鏄甫绉掔殑涓旀槸杩熷埌锛岄偅涔堢鍒版椂闂村涓绉掑拰澶氫竴鍒嗛挓鏄竴鏍风殑 + signInWorkBeginTime = true; + } + String signInTime = signTime; + int signInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(signInTime); + String flow_signInTime = ""; + if(deduct_signintime.length() > 0){ + if(signTime.length() > 0){ + if(deduct_signintime.compareTo(signTime) < 0){ + flow_signInTime = deduct_signintime; + } + }else{ + flow_signInTime = deduct_signintime; + } + } + if(flow_signInTime.length() > 0){ + signInTimeIndx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signInTime); + } + if(kqDate.compareTo(signDate) < 0)signInTimeIndx+=1440; + if(signInWorkBeginTime){ + signInTimeIndx = signInTimeIndx + 1; + } + if(workBeginIdx>signInTimeIndx) { + earlyInMins = workBeginIdx-signInTimeIndx; + } + } + } + } + return earlyInMins; + } + + public int getLateOutMins(String userId, String kqDate){ + int lateOutMins = 0; + boolean oneSign = false; + String preDate = DateUtil.addDate(kqDate, -1);//涓婁竴澶╂棩鏈 + String nextDate = DateUtil.addDate(kqDate, 1);//涓嬩竴澶╂棩鏈 + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqDate); + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + oneSign = lsWorkTime != null && lsWorkTime.size() == 1; + } + + if (oneSign) { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + TimeScopeEntity signTimeScope = lsSignTime.get(0); + TimeScopeEntity workTimeScope = lsWorkTime.get(0); + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workTimeScope.getEndTime()); + + List lsCheckInfo = new KQFormatSignData().getSignInfo(userId,signTimeScope,workTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo); + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfo = (Map) lsCheckInfo.get(j); + String signDate = Util.null2String(checkInfo.get("signDate")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String deduct_signofftime = Util.null2String(checkInfo.get("deduct_signofftime")); + if (checkInfo.get("signType").equals("2")) {//绛鹃 + String signOutTime = signTime; + int signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(signOutTime); + String flow_signOutTime = signOutTime; + if(deduct_signofftime.length() > 0){ + if(signTime.length() > 0){ + if(deduct_signofftime.compareTo(signTime) > 0){ + flow_signOutTime = deduct_signofftime; + } + }else{ + flow_signOutTime = deduct_signofftime; + } + } + if(flow_signOutTime.length() > 0){ + signInTimeOutdx = kqTimesArrayComInfo.getArrayindexByTimes(flow_signOutTime); + } + if(kqDate.compareTo(signDate) < 0)signInTimeOutdx+=1440; + if(signInTimeOutdx>workEndIdx) { + lateOutMins = signInTimeOutdx-workEndIdx; + } + } + } + } + return lateOutMins; + } + + public int getPreDayLateOutMins(String userId, String kqDate) { + return getPreDayLateOutMins(userId, kqDate, Lists.newArrayList()); + } + /** + * 鍓嶄竴澶╂櫄璧板垎閽熸暟 + */ + public int getPreDayLateOutMins(String userId, String kqDate,List logList) { + int preDayLateOutMins = 0; + + boolean oneSign = false; + KQWorkTime kqWorkTime = new KQWorkTime(); + //鍓嶄竴澶╂槸闈炲伐浣滄棩锛屽線鍓嶅彇鍒板伐浣滄棩 + String tmpKQPreDate = DateUtil.addDate(kqDate, -1); + for(int i=0;i<31;i++){ + WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, tmpKQPreDate); + if(workTime.getWorkMins()>0){ + kqDate = DateUtil.addDate(tmpKQPreDate, 1); + break; + } + tmpKQPreDate = DateUtil.addDate(tmpKQPreDate, -1); + } + String kqPreDate = DateUtil.addDate(kqDate, -1);; + String kqPrePreDate = DateUtil.addDate(kqDate, -2); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(userId, kqPreDate); + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + oneSign = lsWorkTime != null && lsWorkTime.size() == 1; + } + + if (oneSign) { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + TimeScopeEntity signTimeScope = lsSignTime.get(0); + TimeScopeEntity workTimeScope = lsWorkTime.get(0); + String signBeginDateTime = signTimeScope.getBeginTimeAcross() ? kqPrePreDate : kqPreDate; + signBeginDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime()) + ":00"; + String signEndDateTime = signTimeScope.getEndTimeAcross() ? kqDate : kqPreDate; + signEndDateTime += " " + kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime()) + ":00"; + String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? kqPrePreDate : kqPreDate; + workBeginDateTime += " " + kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime()) + ":00"; + String workEndDateTime = workTimeScope.getEndTimeAcross() ? kqDate : kqPreDate; + workEndDateTime += " " + kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime()) + ":00"; + + Map shifRuleMap = Maps.newHashMap(); + String shif_workEndTime = ""; + getPre_ShiftRuleInfo(kqPreDate,workTime,lsSignTime,lsWorkTime,userId,shifRuleMap,logList); + if(!shifRuleMap.isEmpty()){ + if(shifRuleMap.containsKey("shift_endworktime")){ + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if(shift_endworktime.length() > 0){ + shif_workEndTime = Util.null2String(shift_endworktime); + } + } + } + + List lsCheckInfo = new KQFormatSignData().getSignInfo(userId,signTimeScope,workTimeScope,kqPreDate,kqPrePreDate,kqDate,kqTimesArrayComInfo); + Map checkInfo = null; + if (lsCheckInfo.size() == 2) { + for(int i = 0 ;i < lsCheckInfo.size() ;i++){ + checkInfo = (Map) lsCheckInfo.get(i); + String signType = Util.null2String(checkInfo.get("signType")); + if("2".equalsIgnoreCase(signType)){ + break; + } + } + String signDate = Util.null2String(checkInfo.get("signDate")); + String signTime = Util.null2String(checkInfo.get("signTime")); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + if(shif_workEndTime.length() > 0){ + workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(shif_workEndTime); + } + if (!kqPreDate.equals(signDate)) { //璺ㄥぉ + signTime = kqTimesArrayComInfo.turn24to48Time(signTime); + } + int signOutTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + if (signOutTimeIdx > workEndIdx) { + preDayLateOutMins = signOutTimeIdx - workEndIdx; + logList.add("绛鹃鏃堕棿鏄:"+(signDate+" "+kqTimesArrayComInfo.turn48to24Time(signTime))+",鏅氳蛋浜"+preDayLateOutMins+"鍒嗛挓"); + } + }else if(!lsCheckInfo.isEmpty()){ + for(int i = 0 ;i < lsCheckInfo.size() ;i++){ + Map checkInfoMap = (Map) lsCheckInfo.get(i); + String signType = Util.null2String(checkInfoMap.get("signType")); + if("2".equalsIgnoreCase(signType)){ + String signDate = Util.null2String(checkInfoMap.get("signDate")); + String signTime = Util.null2String(checkInfoMap.get("signTime")); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + if(shif_workEndTime.length() > 0){ + workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(shif_workEndTime); + } + if (!kqPreDate.equals(signDate)) { //璺ㄥぉ + signTime = kqTimesArrayComInfo.turn24to48Time(signTime); + } + int signOutTimeIdx = kqTimesArrayComInfo.getArrayindexByTimes(signTime); + if (signOutTimeIdx > workEndIdx) { + preDayLateOutMins = signOutTimeIdx - workEndIdx; + logList.add(",绛鹃鏃堕棿鏄:"+(signDate+" "+signTime)+",鏅氳蛋浜"+preDayLateOutMins+"鍒嗛挓"); + } + } + } + } + } + return preDayLateOutMins; + } + + /** + * 鑾峰彇鍓嶄竴澶╃殑寮规ф椂闂 + * @param kqPreDate + * @param workTime + * @param lsSignTime + * @param lsWorkTime + * @param userId + * @param logList + */ + public void getPre_ShiftRuleInfo(String kqPreDate, WorkTimeEntity workTime, + List lsSignTime, List lsWorkTime, String userId, + Map shifRuleMap,List logList) { + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setSplitDate(kqPreDate); + shiftInfoBean.setShiftRuleMap(workTime.getShiftRuleInfo()); + shiftInfoBean.setSignTime(lsSignTime); + shiftInfoBean.setWorkTime(lsWorkTime); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, userId, shifRuleMap,false,logList); + } + + /** + * 鑾峰彇鐝璁剧疆閲岄潰鐨勪笂涓嬬彮涓嶆墦鍗℃暟鎹 + * @param i + * @param serialId + */ + public Map getModel_ShiftRule(int i,String serialId) { + RecordSet rs = new RecordSet(); + HashMap sectionMap = new HashMap<>(); + String getStartWorkSections = "select * from kq_ShiftOnOffWorkSections where SERIALID=? and record=? "; + rs.executeQuery(getStartWorkSections,serialId,i); + while (rs.next()) { + String onoffworktype = Util.null2String(rs.getString("onoffworktype")); + String clockinnot = Util.null2s(Util.null2String(rs.getString("clockinnot")), "0"); + sectionMap.put(onoffworktype, clockinnot); + } + return sectionMap; + } + +} \ No newline at end of file diff --git a/src/com/engine/kq/biz/KQFormatSignData.java b/src/com/engine/kq/biz/KQFormatSignData.java new file mode 100644 index 0000000..ed7e26c --- /dev/null +++ b/src/com/engine/kq/biz/KQFormatSignData.java @@ -0,0 +1,649 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.TimeSignScopeEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.UtilKQ; +import com.engine.kq.wfset.util.KQSignUtil; +import com.google.common.collect.Lists; +import java.io.PrintWriter; +import java.io.StringWriter; + +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import java.util.*; + +/** + * 鑾峰彇鐝鎵撳崱鏁版嵁 + */ +public class KQFormatSignData extends BaseBean { + private KQLog kqLog = new KQLog(); + + public List getSignInfo(String userId, TimeScopeEntity signTimeScope, + TimeScopeEntity workTimeScope, String kqDate, String preDate, + String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo) { + return getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, + Lists.newArrayList(), ""); + } + + public List getSignInfo(String userId, TimeScopeEntity signTimeScope, + TimeScopeEntity workTimeScope, String kqDate, String preDate, + String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,ArrayList hostIps,String uuid) { + return getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, hostIps, uuid, 0, 0); + + } + /*** + * 鑾峰彇鐝鎵撳崱鏁版嵁 + * @param userId + * @param signTimeScope + * @param workTimeScope + * @param kqDate + * @param preDate + * @param nextDate + * @param kqTimesArrayComInfo + * @return + */ + public List getSignInfo(String userId, TimeScopeEntity signTimeScope, + TimeScopeEntity workTimeScope, String kqDate, String preDate, + String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,ArrayList hostIps,String uuid, int shiftCount, int shiftI) { + kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+" in "); + List lsCheckInfo = new ArrayList<>(); + String count4NoonStartDateTime = ""; + String count4NoonEndDateTime = ""; + try{ + Map checkInfo = null; + String base_sql = ""; + RecordSet rs = new RecordSet(); + String dbtype = rs.getDBType(); + + //鑾峰彇宸ヤ綔涓婁笅鐝椂闂 + String workBeginDateTime = workTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + workBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime())+":00"; + kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::workBeginDateTime::"+workBeginDateTime); + + //鑾峰彇宸ヤ綔涓婁笅鐝椂闂 + String workEndDateTime = workTimeScope.getEndTimeAcross() ? nextDate : kqDate; + workEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(workTimeScope.getEndTime())+":00"; + kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::workEndDateTime::"+workEndDateTime); + + Map flow_deduct_card_map = getflowDeductCardSql(userId,kqDate,workTimeScope.getBeginTime(),workTimeScope.getEndTime()); + + kqLog.info("in getSignInfo ::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map); + + List> sqlConditions = getCanSignInfo(signTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,workTimeScope, shiftCount, shiftI); + base_sql = signSignSql(rs); + new KQLog().info("sqlConditions:(userId:"+userId+":base_sql"+base_sql+":::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map); + if(sqlConditions != null && !sqlConditions.isEmpty()){ + if(shiftCount == 2) { + String fieldName = ""; + if(shiftI == 0) { + fieldName = "signEndDateTime"; + } else if(shiftI == 1) { + fieldName = "signBeginDateTime"; + } + Map sqlMap = sqlConditions.get(0); + count4NoonStartDateTime = Util.null2String(sqlMap.get(fieldName)); + if (count4NoonStartDateTime.length() == 19) { + count4NoonStartDateTime = count4NoonStartDateTime.substring(0, 17) + "00"; + } + sqlMap = sqlConditions.get(0); + count4NoonEndDateTime = Util.null2String(sqlMap.get(fieldName)); + if (sqlConditions.size() >= 2) { + sqlMap = sqlConditions.get(1); + count4NoonEndDateTime = Util.null2String(sqlMap.get(fieldName)); + } + } + + for(Map sqlMap : sqlConditions){ + String sql = ""; + String orderSql = ""; + int idx = 0; + String signBeginDateTime = Util.null2String(sqlMap.get("signBeginDateTime")); + String signEndDateTime = Util.null2String(sqlMap.get("signEndDateTime")); + String type = Util.null2String(sqlMap.get("type")); + if(type.length() > 0){ + if("signoff".equalsIgnoreCase(type)){ + orderSql = " order by signdate desc, signtime desc "; + }else if("signin".equalsIgnoreCase(type)){ + orderSql = " order by signdate asc, signtime asc "; + } + if("oracle".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1"; + }else if("mysql".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a limit 0,1"; + } + else if("postgresql".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a limit 1 offset 0"; + } + else if("sqlserver".equalsIgnoreCase(dbtype)){ + sql = "select top 1 * from ("+base_sql+") a "+" "+orderSql; + }else{ + sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1"; + } + }else{ + orderSql = " order by signdate asc, signtime asc "; + sql = base_sql+" "+orderSql; + } + rs.executeQuery(sql, userId, signBeginDateTime, signEndDateTime); + new KQLog().info("getSignInfo:(userId:"+userId+":signBeginDateTime:"+ + signBeginDateTime+":signEndDateTime:"+signEndDateTime+"):sql"+sql+":counts:"+rs.getCounts()+":::userId" + userId + "kqDate==" + kqDate+":hostIps:"+hostIps+":uuid::"+uuid+"::flow_deduct_card_map::"+flow_deduct_card_map); + while (rs.next()) { + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + String signDateTime = signdate + " " + signtime; + idx++; + if(type.length() > 0){ + if("signin".equalsIgnoreCase(type)){ + checkInfo.put("signType", "1"); + if(workBeginDateTime.length()>0) { + checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime)); + } + if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){ + if(flow_deduct_card_map.containsKey("signin")){ + String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin")); + if(deduct_signintime.length() > 0){ + signDateTime = signdate + " " + deduct_signintime; + checkInfo.put("deduct_signintime", deduct_signintime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime)); + } + } + } + lsCheckInfo.add(checkInfo); + }else { + checkInfo.put("signType", "2"); + if(workEndDateTime.length()>0) { + checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime)); + } + if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){ + if(flow_deduct_card_map.containsKey("signoff")){ + String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff")); + if(deduct_signofftime.length() > 0){ + signDateTime = signdate + " " + deduct_signofftime; + checkInfo.put("deduct_signofftime", deduct_signofftime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime)); + } + } + } + lsCheckInfo.add(checkInfo); + } + }else{ + if(idx==1){//绗竴鏉$畻绛惧埌 + checkInfo.put("signType", "1"); + if(workBeginDateTime.length()>0) { + checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime)); + } + if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){ + if(flow_deduct_card_map.containsKey("signin")){ + String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin")); + if(deduct_signintime.length() > 0){ + signDateTime = signdate + " " + deduct_signintime; + checkInfo.put("deduct_signintime", deduct_signintime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", UtilKQ.getSignStatus("1", signDateTime, workBeginDateTime)); + } + } + } + lsCheckInfo.add(checkInfo); + }else if(idx==rs.getCounts()){//鏈鍚庝竴鏉$畻绛鹃 + checkInfo.put("signType", "2"); + if(workEndDateTime.length()>0) { + checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime)); + } + if(!Util.null2String(checkInfo.get("signStatus")).equalsIgnoreCase(ButtonStatusEnum.NORMAL.getStatusCode())){ + if(flow_deduct_card_map.containsKey("signoff")){ + String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff")); + if(deduct_signofftime.length() > 0){ + signDateTime = signdate + " " + deduct_signofftime; + checkInfo.put("deduct_signofftime", deduct_signofftime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", UtilKQ.getSignStatus("2", signDateTime, workEndDateTime)); + } + } + } + lsCheckInfo.add(checkInfo); + } + } + } + } + } + //濡傛灉绛惧埌锛岀閫涓嶆垚瀵癸紝娴佺▼鎶垫墸寮傚父瀛樺湪锛岄偅涔堥渶瑕佸垽鏂笅鏄笉鏄彲浠ヨˉ瓒 + if(lsCheckInfo.size() < 2 && !flow_deduct_card_map.isEmpty()){ + if(lsCheckInfo.isEmpty()){ + if(flow_deduct_card_map.containsKey("signin")){ + String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin")); + if(deduct_signintime.length() > 0){ + checkInfo = new HashMap<>(); + String[] workBeginDateTimes = workBeginDateTime.split(" "); + String tmp_workBeginDate = workBeginDateTimes[0]; + String tmp_workBeginTime = workBeginDateTimes[1]; + checkInfo.put("signType", "1"); + checkInfo.put("signDate", tmp_workBeginDate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", "");//绛惧埌绛鹃鏃堕棿 + checkInfo.put("deduct_signintime", tmp_workBeginTime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + lsCheckInfo.add(checkInfo); + } + } + if(flow_deduct_card_map.containsKey("signoff")){ + String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff")); + if(deduct_signofftime.length() > 0){ + checkInfo = new HashMap<>(); + String[] workEndDateTimes = workEndDateTime.split(" "); + String tmp_workEndDate = workEndDateTimes[0]; + String tmp_workEndTime = workEndDateTimes[1]; + checkInfo.put("signType", "2"); + checkInfo.put("signDate", tmp_workEndDate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", "");//绛惧埌绛鹃鏃堕棿 + checkInfo.put("deduct_signofftime", tmp_workEndTime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + lsCheckInfo.add(checkInfo); + } + } + }else{ + Map checkCardMap = (Map) lsCheckInfo.get(0); + if(!checkCardMap.isEmpty()){ + String signType = Util.null2String(checkCardMap.get("signType")); + if("1".equalsIgnoreCase(signType)){ + //濡傛灉绛惧埌鏁版嵁鏈変簡锛屾娴嬩笅鏄笉鏄湁绛鹃鐨勬祦绋嬫姷鎵f墦鍗 + if(flow_deduct_card_map.containsKey("signoff")){ + String deduct_signofftime = Util.null2String(flow_deduct_card_map.get("signoff")); + if(deduct_signofftime.length() > 0){ + checkInfo = new HashMap<>(); + String[] workEndDateTimes = workEndDateTime.split(" "); + String tmp_workEndDate = workEndDateTimes[0]; + String tmp_workEndTime = workEndDateTimes[1]; + checkInfo.put("signType", "2"); + checkInfo.put("signDate", tmp_workEndDate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", "");//绛惧埌绛鹃鏃堕棿 + checkInfo.put("deduct_signofftime", tmp_workEndTime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + lsCheckInfo.add(checkInfo); + } + } + }else{ + if(flow_deduct_card_map.containsKey("signin")){ + String deduct_signintime = Util.null2String(flow_deduct_card_map.get("signin")); + if(deduct_signintime.length() > 0){ + checkInfo = new HashMap<>(); + String[] workBeginDateTimes = workBeginDateTime.split(" "); + String tmp_workBeginDate = workBeginDateTimes[0]; + String tmp_workBeginTime = workBeginDateTimes[1]; + checkInfo.put("signType", "1"); + checkInfo.put("signDate", tmp_workBeginDate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", "");//绛惧埌绛鹃鏃堕棿 + checkInfo.put("deduct_signintime", tmp_workBeginTime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfo.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + lsCheckInfo.add(checkInfo); + } + } + } + } + } + } + // 涓婂崍鐨勭閫鍙栦腑闂存椂娈电殑绗竴娆℃墦鍗 + if(shiftCount == 2 && shiftI == 0) { + String noonSignTimeSql = KQSignUtil.buildSignSql(count4NoonStartDateTime,count4NoonEndDateTime); + String baseSql = "select * from hrmschedulesign where 1=1 and isInCom='1' and userid="+userId+" "; + String sql = baseSql; + sql += " and "+noonSignTimeSql + " order by signdate, signtime"; + rs.executeQuery(sql); + if(rs.next()) { + String signId = Util.null2String(rs.getString("id")); + String signDate = Util.null2String(rs.getString("signdate")); + String signTime = Util.null2String(rs.getString("signtime")); + String signDateTime = signDate+" "+signTime; + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfoInner = (Map) lsCheckInfo.get(j); + if (checkInfoInner.get("signType").equals("2")) {//绛鹃 + String signDateInner = Util.null2String(checkInfoInner.get("signDate")); + String signTimeInner = Util.null2String(checkInfoInner.get("signTime")); + String deduct_signofftime = Util.null2String(checkInfoInner.get("deduct_signofftime")); + if(!"".equals(signTimeInner)) { + String signDateTimeInner = signDateInner+" "+signTimeInner; + if(signDateTime.compareTo(signDateTimeInner) < 0) { + checkInfoInner.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfoInner.put("signType", "2"); + checkInfoInner.put("signDate", signDateInner);//绛惧埌绛鹃鏃ユ湡 + checkInfoInner.put("signTime", signTime);//绛惧埌绛鹃鏃堕棿 + checkInfoInner.put("deduct_signofftime", deduct_signofftime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfoInner.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + } + } + } + } + } + } else if(shiftCount == 2 && shiftI == 1) { // 涓嬪崍鐨勭鍒板彇涓棿鏃舵鐨勭浜屾鎵撳崱 + String noonSignTimeSql = KQSignUtil.buildSignSql(count4NoonStartDateTime,count4NoonEndDateTime); + String baseSql = "select * from hrmschedulesign where 1=1 and isInCom='1' and userid="+userId+" "; + String sql = baseSql; + sql += " and "+noonSignTimeSql + " order by signdate, signtime"; + rs.executeQuery(sql); + int count=0; + int counts=rs.getCounts(); + if(counts==1){ + lsCheckInfo.clear(); + } + while (rs.next()) { + if(count == 0) { + count++; + continue; + } + String signId = Util.null2String(rs.getString("id")); + String signTime = Util.null2String(rs.getString("signtime")); + for (int j = 0; lsCheckInfo != null && j < lsCheckInfo.size(); j++) { + Map checkInfoInner = (Map) lsCheckInfo.get(j); + if (checkInfoInner.get("signType").equals("1")) {//绛鹃 + String signDateInner = Util.null2String(checkInfoInner.get("signDate")); + String signTimeInner = Util.null2String(checkInfoInner.get("signTime")); + String deduct_signofftime = Util.null2String(checkInfoInner.get("deduct_signofftime")); + checkInfoInner.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfoInner.put("signType", "1"); + checkInfoInner.put("signDate", signDateInner);//绛惧埌绛鹃鏃ユ湡 + checkInfoInner.put("signTime", signTime);//绛惧埌绛鹃鏃堕棿 + checkInfoInner.put("deduct_signofftime", deduct_signofftime);//娴佺▼鎶垫墸浣滀负鎵撳崱鏃堕棿 + checkInfoInner.put("signStatus", ButtonStatusEnum.NORMAL.getStatusCode()); + } + } + break; + } + } + }catch (Exception e){ + + kqLog.info("鎶ヨ〃閿:getSignInfo:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + + //writeLog(sql,userId +"=="+ signBeginDateTime+"=="+signEndDateTime); + return lsCheckInfo; + } + + /** + * 鏍规嵁涓婁笅鐝椂闂磋幏鍙栧埌鏄惁鏈夋祦绋嬫姷鎵f墦鍗$殑鏁版嵁 + * @param userId + * @param kqDate + * @param workBeginDateTime + * @param workEndDateTime + */ + public Map getflowDeductCardSql(String userId, String kqDate, String workBeginDateTime, String workEndDateTime) { + Map flow_deduct_card_map = new HashMap<>(); + RecordSet rs = new RecordSet(); + String flow_deduct_card_sql = "select * from kq_flow_deduct_card where 1=1 and (isclear is null or isclear<>1) "; + if(userId.length() > 0){ + flow_deduct_card_sql += " and resourceid="+userId; + } + if(kqDate.length() > 0){ + flow_deduct_card_sql += " and belongDate='"+kqDate+"'"; + } + if(workBeginDateTime.length() > 0){ + flow_deduct_card_sql += " and workBeginTime='"+workBeginDateTime+"'"; + } + if(workEndDateTime.length() > 0){ + flow_deduct_card_sql += " and workEndTime='"+workEndDateTime+"'"; + } + rs.executeQuery(flow_deduct_card_sql); + while (rs.next()){ + String signtype = rs.getString("signtype"); + if("1".equalsIgnoreCase(signtype)){ + flow_deduct_card_map.put("signin",workBeginDateTime); + } + if("2".equalsIgnoreCase(signtype)){ + flow_deduct_card_map.put("signoff",workEndDateTime); + } + } + return flow_deduct_card_map; + } + + /** + * 鏍规嵁鎵撳崱鐨勮寖鍥寸敓鎴愪笂鐝紝涓嬬彮鏁版嵁鑾峰彇鐨剆ql + * @param signTimeScope + * @param kqDate + * @param preDate + * @param nextDate + * @param kqTimesArrayComInfo + * @return + */ + public List> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo) { + return getCanSignInfo(signTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo,null); + } + public List> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,TimeScopeEntity workTimeScope) { + return getCanSignInfo(signTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo,workTimeScope, 0, 0); + } + public List> getCanSignInfo(TimeScopeEntity signTimeScope, String kqDate, String preDate, String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,TimeScopeEntity workTimeScope, int shiftCount, int shiftI) { + + List> sqlConditions = new ArrayList<>(); + Map conditionMap = new HashMap<>(); + + TimeSignScopeEntity timeSignScopeEntity = signTimeScope.getTimeSignScopeEntity(); + + String signBeginDateTime = ""; + String signEndDateTime = ""; + signBeginDateTime = signTimeScope.getBeginTimeAcross() ? nextDate : kqDate; + if(signTimeScope.isBeginTimePreAcross()){ + signBeginDateTime = preDate; + } + signBeginDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getBeginTime())+":00"; + + signEndDateTime = signTimeScope.getEndTimeAcross() ? nextDate : kqDate; + +// if (workTimeScope != null && workTimeScope.getEndTimeAcross() && signTimeScope.getEndTimeAcross() ) { +// if(workTimeScope.getEndTime().compareTo(signTimeScope.getEndTime())>=0){ +// signEndDateTime = DateUtil.addDate(kqDate, 2);//涓嬩笅涓澶╂棩鏈; +// } +// } + signEndDateTime+=" "+kqTimesArrayComInfo.turn48to24Time(signTimeScope.getEndTime())+":59"; + + + + if(timeSignScopeEntity == null){ + //娌℃湁璁剧疆 绛惧埌鏈鏅氭椂闂村拰绛鹃鏈鏃╂椂闂 + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signBeginDateTime); + conditionMap.put("signEndDateTime", signEndDateTime); + sqlConditions.add(conditionMap); + }else{ + String beginTimeEnd = timeSignScopeEntity.getBeginTimeEnd(); + boolean beginTimeEndAcross = timeSignScopeEntity.isBeginTimeEndAcross(); + + String endTimeStart = timeSignScopeEntity.getEndTimeStart(); + boolean endTimeStartAcross = timeSignScopeEntity.isEndTimeStartAcross(); + + if(beginTimeEnd.length() > 0){ + //濡傛灉璁剧疆浜 涓婄彮缁撴潫鏃堕棿 + if(endTimeStart.length() > 0){ + //璁剧疆浜嗕笅鐝紑濮嬫椂闂 + String signBeginDateEndTime = ""; + String signEndDateStartTime = ""; + signBeginDateEndTime = beginTimeEndAcross ? nextDate : kqDate; + signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(beginTimeEnd)+":59"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signBeginDateTime); + conditionMap.put("signEndDateTime", signBeginDateEndTime); + conditionMap.put("type", "signin"); + sqlConditions.add(conditionMap); + + signEndDateStartTime = endTimeStartAcross ? nextDate : kqDate; + signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeStart)+":00"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signEndDateStartTime); + conditionMap.put("signEndDateTime", signEndDateTime); + conditionMap.put("type", "signoff"); + sqlConditions.add(conditionMap); + }else{ + //娌℃湁璁剧疆涓嬬彮寮濮嬫椂闂 + String signBeginDateEndTime = ""; + String signEndDateStartTime = ""; + signBeginDateEndTime = beginTimeEndAcross ? nextDate : kqDate; + signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(beginTimeEnd)+":59"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signBeginDateTime); + conditionMap.put("signEndDateTime", signBeginDateEndTime); + conditionMap.put("type", "signin"); + sqlConditions.add(conditionMap); + + //濡傛灉璁剧疆浜嗕笂鐝粨鏉熸椂闂达紝鐩稿綋浜庝笅鐝紑濮嬫椂闂翠篃琚檺瀹氫簡 + String endTimeByBeginTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(beginTimeEnd)+1); + signEndDateStartTime = beginTimeEndAcross ? nextDate : kqDate; + signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeByBeginTime)+":00"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signEndDateStartTime); + conditionMap.put("signEndDateTime", signEndDateTime); + conditionMap.put("type", "signoff"); + sqlConditions.add(conditionMap); + } + }else if(endTimeStart.length() > 0){ + //濡傛灉娌℃湁璁剧疆涓婄彮缁撴潫鏃堕棿锛岃缃簡涓嬬彮寮濮嬫椂闂 + String signBeginDateEndTime = ""; + String signEndDateStartTime = ""; + + //濡傛灉璁剧疆浜嗕笅鐝紑濮嬫椂闂达紝鐩稿綋浜庝笂鐝粨鏉熸椂闂翠篃琚檺瀹氫簡 + String BeginTimeByendTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(endTimeStart)-1); + signBeginDateEndTime = endTimeStartAcross ? nextDate : kqDate; + signBeginDateEndTime+=" "+kqTimesArrayComInfo.turn48to24Time(BeginTimeByendTime)+":59"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signBeginDateTime); + conditionMap.put("signEndDateTime", signBeginDateEndTime); + conditionMap.put("type", "signin"); + sqlConditions.add(conditionMap); + + signEndDateStartTime = endTimeStartAcross ? nextDate : kqDate; + signEndDateStartTime+=" "+kqTimesArrayComInfo.turn48to24Time(endTimeStart)+":00"; + + conditionMap = new HashMap<>(); + conditionMap.put("signBeginDateTime", signEndDateStartTime); + conditionMap.put("signEndDateTime", signEndDateTime); + conditionMap.put("type", "signoff"); + sqlConditions.add(conditionMap); + } + } + return sqlConditions; + } + + public String signSignSql(RecordSet rs){ + String sql = ""; + if(rs.getDBType().equals("oracle")){ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate||' '||signtime >= ? and signdate||' '||signtime <= ? " + + " "; + }else if("sqlserver".equals(rs.getDBType())){ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate + ' ' + signtime >= ? and signdate + ' ' + signtime <= ? " + + " "; + }else{ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and concat(signdate,' ',signtime) >= ? and concat(signdate,' ',signtime) <= ? " + + " "; + } + return sql; + } + + public List getSignInfoForAll(String userId, String signBeginDateTime, String signEndDateTime, String workBeginDateTime, String workEndDateTime) { + List lsCheckInfo = new ArrayList<>(); + Map checkInfo = null; + String sql = ""; + RecordSet rs = new RecordSet(); + + int idx = 0; + if(rs.getDBType().equals("oracle")){ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate||' '||signtime >= ? and signdate||' '||signtime <= ? " + + " order by signdate asc, signtime asc "; + }else if("sqlserver".equals(rs.getDBType())){ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and signdate + ' ' + signtime >= ? and signdate + ' ' + signtime <= ? " + + " order by signdate asc, signtime asc "; + }else{ + sql = " select id,signdate,signtime from hrmschedulesign where isincom=1 and userid = ? and concat(signdate,' ',signtime) >= ? and concat(signdate,' ',signtime) <= ? " + + " order by signdate asc, signtime asc "; + } + rs.executeQuery(sql, userId, signBeginDateTime, signEndDateTime); + //writeLog(sql,userId +"=="+ signBeginDateTime+"=="+signEndDateTime); + while (rs.next()) { + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + String signDateTime = signdate + " " + signtime; + + idx++; + if(idx%2==1){ + checkInfo.put("signType", "1"); + }else{ + checkInfo.put("signType", "2"); + } + lsCheckInfo.add(checkInfo); + } + return lsCheckInfo; + } + + public List getNonWorkSignInfo(String userId, String preDate, String kqDate, + List pre_lsSignTime, + List next_lsSignTime) { + List lsCheckInfo = new ArrayList<>(); + Map checkInfo = null; + RecordSet rs = new RecordSet(); + String pre_Worktime4Today = ""; + if(!pre_lsSignTime.isEmpty()){ + TimeScopeEntity pre_signTimeScope = pre_lsSignTime.get(pre_lsSignTime.size()-1); + if(pre_signTimeScope.getEndTimeAcross()){ + pre_Worktime4Today = pre_signTimeScope.getEndTime(); + } + } + String next_Worktime4Today = ""; + if(!next_lsSignTime.isEmpty()){ + TimeScopeEntity next_signTimeScope = next_lsSignTime.get(next_lsSignTime.size()-1); + if(next_signTimeScope.isBeginTimePreAcross()){ + next_Worktime4Today = next_signTimeScope.getBeginTime(); + } + } + String sql = "select * from hrmschedulesign where userid="+userId+" and signdate = '"+kqDate+"' "; + if(pre_Worktime4Today.length() > 0){ + if(pre_Worktime4Today.length() == 5){ + pre_Worktime4Today += ":59"; + } + sql += " and signtime > '"+pre_Worktime4Today+"'"; + } + if(next_Worktime4Today.length() > 0){ + if(next_Worktime4Today.length() == 5){ + next_Worktime4Today += ":00"; + } + sql += " and signtime < '"+next_Worktime4Today+"'"; + } + sql += " order by signdate asc,signtime asc "; + rs.executeQuery(sql); + int idx = 0; + while (rs.next()){ + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + idx++; + if(idx==1){//绗竴鏉$畻绛惧埌 + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + }else if(idx==rs.getCounts()){//鏈鍚庝竴鏉$畻绛鹃 + checkInfo.put("signType", "2"); + lsCheckInfo.add(checkInfo); + } + } + return lsCheckInfo; + } + +} \ No newline at end of file diff --git a/src/com/engine/kq/biz/KQHolidaySetBiz.java b/src/com/engine/kq/biz/KQHolidaySetBiz.java new file mode 100644 index 0000000..e008a79 --- /dev/null +++ b/src/com/engine/kq/biz/KQHolidaySetBiz.java @@ -0,0 +1,452 @@ +package com.engine.kq.biz; + +import com.engine.integration.util.MyX509TrustManager; +import com.engine.kq.log.KQLog; +import net.sf.json.JSONObject; +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.file.Prop; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.*; + +/** + * 鑺傚亣鏃ヨ缃浉鍏虫帴鍙f暟鎹 + */ +public class KQHolidaySetBiz { + + private static KQLog logger = new KQLog(); + private static BaseBean bb = new BaseBean(); + + /** + * 鑾峰彇鎸囧畾鑰冨嫟缁処D鑾峰彇鑺傚亣鏃ヨ缃暟鎹 + * + * @param resourceId 鎸囧畾浜哄憳鐨処D + * @param year 鎸囧畾骞翠唤 + * @param month 鎸囧畾鏈堜唤 鎸囧畾鏈堜唤涓虹┖鏃舵煡璇㈡寚瀹氬勾浠戒竴鏁村勾鐨勬暟鎹 + * @return + */ + public static List getGroupHolidaySetList(String groupId, String year, String month) { + List> valueList = new ArrayList>(); + Map valueMap = new HashMap(); + /*鎸囧畾骞存湀*/ + String startDate = year; + String endDate = month; + if (month.length() == 0) { + startDate = year + "-01" + "-01"; + endDate = year + "-12" + "-31"; + } else if (month.length() == 1) { + startDate = year + "-0" + month + "-01"; + endDate = year + "-0" + month + "-31"; + } else if (month.length() == 2) { + startDate = year + "-" + month + "-01"; + endDate = year + "-" + month + "-31"; + } + RecordSet recordSet = new RecordSet(); + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + boolean isEnd = false; + for (String date = startDate; !isEnd; ) { + if (date.compareTo(endDate) >= 0) { + isEnd = true; + } + + String changeType = holidaySetComInfo.getChangeType(groupId, date); + String holidayDesc = holidaySetComInfo.getHolidayDesc(groupId, date); + if (!changeType.equals("")) { + valueMap = new HashMap(); + valueMap.put("date", date); + valueMap.put("name", holidayDesc); + valueMap.put("type", changeType); + valueList.add(valueMap); + } + date = DateUtil.getDate(date, 1); + } + return valueList; + } + + /** + * 鑾峰彇鎸囧畾鑰冨嫟缁処D鑾峰彇鑺傚亣鏃ヨ缃暟鎹 + * + * @param resourceId 鎸囧畾浜哄憳鐨処D + * @param year 鎸囧畾骞翠唤 + * @param month 鎸囧畾鏈堜唤 鎸囧畾鏈堜唤涓虹┖鏃舵煡璇㈡寚瀹氬勾浠戒竴鏁村勾鐨勬暟鎹 + * @return + */ + public static List getKQHolidaySetList(String resourceId, String year, String month) { + Map valueMap = new HashMap(); + List> valueList = new ArrayList>(); + + /*鎸囧畾骞存湀*/ + String startDate = year; + String endDate = month; + if (month.length() == 0) { + startDate = year + "-01" + "-01"; + endDate = year + "-12" + "-31"; + } else if (month.length() == 1) { + startDate = year + "-0" + month + "-01"; + endDate = year + "-0" + month + "-31"; + } else if (month.length() == 2) { + startDate = year + "-" + month + "-01"; + endDate = year + "-" + month + "-31"; + } + valueList = getHolidaySetListByScope(resourceId, startDate, endDate); + return valueList; + } + + /** + * 鏍规嵁鏃ユ湡鑼冨洿鑾峰彇鑺傚亣鏃ユ暟鎹 + * + * @param resourceId 鎸囧畾浜哄憳鐨処D + * @param startDate 鎸囧畾鏃ユ湡鑼冨洿鐨勮捣鐐 + * @param endDate 鎸囧畾鏃ユ湡鑼冨洿鐨勭粓鐐 + * @return + */ + public static List getHolidaySetListByScope(String resourceId, String startDate, String endDate) { + Map valueMap = new HashMap(); + List> valueList = new ArrayList>(); + + RecordSet recordSet = new RecordSet(); + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + + boolean isEnd = false; + for (String date = startDate; !isEnd; ) { + if (date.compareTo(endDate) >= 0) { + isEnd = true; + } + + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date); + + String changeType = holidaySetComInfo.getChangeType(groupId, date); + String holidayDesc = holidaySetComInfo.getHolidayDesc(groupId, date); + if (!changeType.equals("")) { + valueMap = new HashMap(); + valueMap.put("date", date); + valueMap.put("name", holidayDesc); + valueMap.put("type", changeType); + valueList.add(valueMap); + } + date = DateUtil.getDate(date, 1); + } + return valueList; + } + + + /** + * 鍒ゆ柇鏌愬ぉ鏄惁鏄妭鍋囨棩锛堝叕浼楀亣鏃+璋冮厤浼戞伅鏃ワ級 + * + * @param resourceId 鎸囧畾浜哄憳ID + * @param date 鎸囧畾鏃ユ湡 + * @return true-鑺傚亣鏃ャ乫alse銆佷笉鏄妭鍋囨棩 + */ + public static boolean isHoliday(String resourceId, String date) { + return isHoliday(resourceId, date, false); + } + + /** + * 鍒ゆ柇鏌愬ぉ鏄惁鏄妭鍋囨棩锛堝叕浼楀亣鏃+璋冮厤浼戞伅鏃+鍛ㄦ湯锛 + * + * @param resourceId 鎸囧畾浜哄憳ID + * @param date 鎸囧畾鏃ユ湡 + * @param containWeekend 鏄惁鍖呭惈鍛ㄦ湯 涓簍rue鍖呭惈鍛ㄦ湯銆乫alse涓嶅寘鍚 + * @return true-鑺傚亣鏃ャ乫alse銆佷笉鏄妭鍋囨棩 + */ + public static boolean isHoliday(String resourceId, String date, boolean containWeekend) { + boolean flag = false; + + bb.writeLog("isHoliday-" + resourceId + "-" + date); + //褰撳ぉ鏈夋帓鐝殑涓嶇畻鑺傚亣鏃 + KQShiftScheduleComInfo scheduleComInfo = new KQShiftScheduleComInfo(); + String serialId = scheduleComInfo.getSerialId(resourceId, date); + if (StringUtils.isNotEmpty(serialId)) { + return false; + } + + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date); + int changeType = getChangeType(groupId, date); + /*濡傛灉闇瑕佸寘鍚懆鏈紝鍒ゆ柇浼犲叆鐨勬棩鏈熸槸涓嶆槸鍛ㄦ湯*/ + if (containWeekend && changeType != 2 && (DateUtil.getWeek(date) == 6 || DateUtil.getWeek(date) == 7)) { + flag = true; + } + if (changeType == 1 || changeType == 3) { + flag = true; + } + return flag; + } + + /** + * 鑾峰彇褰撳墠鏃ユ湡鏄綍绉嶇被鍨(杩欓噷鍙冭檻鑺傚亣鏃ヨ缃) + * + * @param groupId 鑰冨嫟缁処D + * @param date 鎸囧畾鏃ユ湡 + * @return 1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃ャ-1-娌℃湁璁剧疆杩囨暟鎹 + */ + public static int getChangeType(String groupId, String date) { + int changeType = -1;//榛樿娌℃湁璁剧疆杩囪妭鍋囨棩(鑺傚亣鏃ヨ缃殑绫诲瀷锛1-鍏紬鍋囨棩銆2-璋冮厤宸ヤ綔鏃ャ3-璋冮厤浼戞伅鏃) + KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo(); + changeType = Util.getIntValue(kqHolidaySetComInfo.getChangeType(groupId, date), -1); + return changeType; + } + + /** + * 鑾峰彇璋冮厤宸ヤ綔鏃ユ椂鐨勬寚瀹氬伐浣滄棩(褰撹冨嫟缁勪笉灞炰簬鎺掔彮鍒舵椂) + * + * @param resourceId 鎸囧畾浜哄憳鐨処D + * @param date 鎸囧畾鏃ユ湡 + * @return + */ + public static int getRelatedDay(String resourceId, String date) { + int relatedDay = -1; + + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date); + + /*鎺掔彮鍒朵笉鏀寔璋冮厤鑺傚亣鏃ユ暟鎹*/ + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + String KQType = kqGroupComInfo.getKqtype(groupId);//鑰冨嫟绫诲瀷锛1-鍥哄畾鐝埗銆2-鎺掔彮鍒躲3-鑷敱鐝埗 + if (KQType.equals("2")) { + return relatedDay; + } + + /*鍙湁褰撹皟閰嶅伐浣滄棩鏃舵墠鏈夊搴斿伐浣滄棩*/ + KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo(); + int changeType = Util.getIntValue(kqHolidaySetComInfo.getChangeType(groupId, date), -1); + if (changeType == 2) { + relatedDay = Util.getIntValue(kqHolidaySetComInfo.getRelatedDay(groupId, date), 0); + } + + return relatedDay; + } + + /** + * 鎸囧畾鐨勮冨嫟缁勫垵濮嬪寲鑺傚亣鏃ヨ缃暟鎹(鍙垵濮嬪寲鍥哄畾鐝埗鍜岃嚜鐢辩彮鍒) + * + * @param groupIds 鎸囧畾鑰冨嫟缁処D(澶氫釜ID涔嬮棿鐢,鍒嗛殧) + * @param year 鎸囧畾骞翠唤 + * @return + */ + public static Map initHolidaySet(String groupIds, String year, User user) { + Map resultMap = new HashMap(); + List errInfoList = new ArrayList();//閿欒淇℃伅闆嗗悎 + /** + * 璋冪敤缃戜笂鐨勮妭鍋囨棩API锛屾暟鎹牸寮忓涓(涓嶆槸JSON瀛楃涓)锛(姝ゅ悗濡傛灉鍘熸潵鐨勮妭鍋囨棩API涓嶈兘鐢ㄤ簡锛屽彧瑕佽皟鏁村皢鏂扮殑API鎺ュ彛璋冩暣鎴愬涓嬫牸寮忓嵆鍙) + * status锛1-鎴愬姛銆0-澶辫触 + * sketch锛'绠瑕佹弿杩伴敊璇師鍥' + * holidayList锛歔{holidayDate:'',changeType:'',holidayDesc:''},鈥︹,{holidayDate:'',changeType:'',holidayDesc:''}] + */ + String url = Prop.getInstance().getPropValue("kq_settings", "KQHolidaySetUrl"); + Map tempMap = httpRequest(url +"?year="+year+"&key="+Util.getEncrypt(Util.getRandom()), user); + if ("0".equals((String) tempMap.get("status"))) { + resultMap.put("status", "0"); + resultMap.put("sketch", (String) tempMap.get("sketch")); + return resultMap; + } + List holidayDateList = new ArrayList(); + try { + List groupIdList = Util.TokenizerString(groupIds, ",");//鑰冨嫟缁処D闆嗗悎 + for (int i = 0; i < groupIdList.size(); i++) { + String groupId = groupIdList.get(i); + /** + * 棰勫厛鍔犺浇姝よ冨嫟缁勫凡缁忚皟鏁翠簡鍝簺鏃ユ湡浜嗭紝濡傛灉鏌愭棩鏈熷湪鍒濆鍖栦箣鍓嶅凡缁忚皟鏁磋繃浜嗭紝鍒犻櫎鎺夊師鏉ョ殑鏁版嵁锛屾彃鍏ユ柊鐨勬暟鎹 + */ + List dateList = new ArrayList(); + KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo(); + kqHolidaySetComInfo.setTofirstRow(); + while (kqHolidaySetComInfo.next()) { + if (kqHolidaySetComInfo.getGroupId().equals(groupId)) { + dateList.add(kqHolidaySetComInfo.getHolidayDate()); + } + } + + /** + * 棰勫厛鍔犺浇鍥哄畾鐝埗鍛ㄤ竴~鍛ㄦ棩杩欎竴鍛ㄤ腑涓澶╁紑濮嬩笂鐝殑鏄懆鍑 + */ + int relatedDay = 0; + for (int x = 0; x < 7; x++) { + KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo(); + String serialId = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupId, x)); + if (!serialId.equals("")) { + relatedDay = x; + break; + } + } + + /** + * 鍒濆鍖栨敼鑰冨嫟缁勭殑鑺傚亣鏃ユ暟鎹(鍙垵濮嬪寲) + */ + boolean flag = true; + RecordSet recordSet = new RecordSet(); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + + List> holidayList = (List>) tempMap.get("holidayList"); + Map holidayMap = new HashMap(); + for (int j = 0; j < holidayList.size(); j++) { + holidayMap = holidayList.get(j); + + String holidayDate = year + "-" + (String) holidayMap.get("holidayDate"); + if (!holidayDateList.contains(holidayDate)) { + holidayDateList.add(holidayDate); + } + int changeType = (int) holidayMap.get("changeType"); + if (kqGroupComInfo.getKqtype(groupId).equals("2")&&changeType == 2 ) { + //鎺掔彮鍒剁殑鑰冨嫟缁勪笉鑳藉垵濮嬪寲璋冮厤宸ヤ綔鏃 + continue; + } + String holidayDesc = (String) holidayMap.get("holidayDesc"); + if (dateList.contains(holidayDate)) { + String deleteSql = "delete from kq_HolidaySet where groupId=? and holidayDate=?"; + recordSet.executeUpdate(deleteSql, groupId, holidayDate); + } + + String sql = "insert into kq_HolidaySet(groupId,holidayDate,changeType,holidayDesc,relatedDay) values(?,?,?,?,?)"; + flag = recordSet.executeUpdate(sql, groupId, holidayDate, changeType, holidayDesc, relatedDay); + if (!flag) { + errInfoList.add(SystemEnv.getHtmlLabelName(5056701, user.getLanguage()).replace("$groupName$", kqGroupComInfo.getGroupname(groupId)).replace("$holidayDate$", holidayDate)); + } + } + } + + /** + * 濡傛灉娌℃湁閿欒淇℃伅鍒欎唬琛ㄥ垵濮嬪寲鎴愬姛 + */ + if (errInfoList.size() > 0) { + resultMap.put("status", "0"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(125960, user.getLanguage())); + resultMap.put("description", errInfoList); + } else { + resultMap.put("status", "1"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(20196, user.getLanguage())); + } + } catch (Exception e) { + resultMap.put("status", "0"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(382661, user.getLanguage())); + resultMap.put("desscription", errInfoList); + } finally { + /*鍒锋柊缂撳瓨*/ + KQHolidaySetComInfo kqHolidaySetComInfo = new KQHolidaySetComInfo(); + kqHolidaySetComInfo.removeCache(); + + /*鍒锋柊鑰冨嫟鎶ヨ〃*/ + logger.info("鍒濆鍖栬妭鍋囨棩鏁版嵁锛屾牸寮忓寲鑰冨嫟鎶ヨ〃銆俫roupIdList=" + com.alibaba.fastjson.JSONObject.toJSONString(groupIds) + + "銆俬olidayDateList=" + com.alibaba.fastjson.JSONObject.toJSONString(holidayDateList)); + List groupIdList = Util.TokenizerString(groupIds, ",");//鑰冨嫟缁処D闆嗗悎 + new KQHolidaySetThread(groupIdList,holidayDateList).start(); + } + return resultMap; + } + + /** + * 璇锋眰缃戠粶涓婄殑鑺傚亣鏃PI鎺ュ彛锛岃幏鍙栬妭鍋囨棩璁剧疆鏁版嵁 + * + * @param requestUrl + * @return + */ + private static Map httpRequest(String requestUrl, User user) { + Map resultMap = new HashMap(); + //buffer鐢ㄤ簬鎺ュ彈杩斿洖鐨勫瓧绗 + StringBuffer buffer = new StringBuffer(); + try { + TrustManager[] tm = {new MyX509TrustManager()}; + SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); + sslContext.init(null, tm, new java.security.SecureRandom()); + SSLSocketFactory ssf = sslContext.getSocketFactory(); + + URL url= new URL(null, requestUrl, new sun.net.www.protocol.https.Handler()); + HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection(); + httpUrlConn.setSSLSocketFactory(ssf); + + httpUrlConn.setDoOutput(true); + httpUrlConn.setDoInput(true); + httpUrlConn.setUseCaches(false); + httpUrlConn.setRequestMethod("GET"); + httpUrlConn.connect(); + + //鑾峰緱杈撳叆 + InputStream inputStream = httpUrlConn.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8"); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + + //灏哹ufferReader鐨勫肩粰鏀惧埌buffer閲 + String str = null; + while ((str = bufferedReader.readLine()) != null) { + buffer.append(str); + } + //鍏抽棴bufferReader鍜岃緭鍏ユ祦 + bufferedReader.close(); + inputStreamReader.close(); + inputStream.close(); + inputStream = null; + //鏂紑杩炴帴 + httpUrlConn.disconnect(); + + /** + * 瑙f瀽JSON瀛楃涓 + */ + String jsonStr = buffer.toString(); + JSONObject jsonObject = JSONObject.fromObject(jsonStr).getJSONObject("data"); + int code = jsonObject.optInt("code");//0鏈嶅姟姝e父銆-1鏈嶅姟鍑洪敊 + if (code != 0) { + //鍒濆鍖栬妭鍋囨棩澶辫触锛岃幏鍙栫綉缁滄湇鍔″嚭閿 + resultMap.put("status", "0"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(520011, user.getLanguage())); + return resultMap; + } + JSONObject holiday = jsonObject.getJSONObject("holiday"); + if (holiday.size() == 0) { + //鍒濆鍖栬妭鍋囨棩澶辫触锛屾殏鏈幏鍙栧埌鎵閫夊勾浠界殑鑺傚亣鏃ユ暟鎹 + resultMap.put("status", "0"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(505673, user.getLanguage())); + return resultMap; + } + Map holidayMap = new HashMap(); + List> holidayList = new ArrayList>(); + Iterator iterator = holiday.keys(); + while (iterator.hasNext()) { + holidayMap = new HashMap(); + + String holidayDate = (String) iterator.next(); + holidayMap.put("holidayDate", holidayDate);//鏃ユ湡 + JSONObject detailInfo = holiday.getJSONObject(holidayDate); + int wage = detailInfo.optInt("wage"); + if (wage == 1) { + holidayMap.put("changeType", 2);//璋冮厤宸ヤ綔鏃 + } else if (wage == 2) { + holidayMap.put("changeType", 3);//璋冮厤浼戞伅鏃 + } else if (wage == 3) { + holidayMap.put("changeType", 1);//鍏紬鍋囨棩 + } + String holidayDesc = detailInfo.getString("name"); + holidayMap.put("holidayDesc", holidayDesc);//璇存槑 + + holidayList.add(holidayMap); + } + resultMap.put("status", "1"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(505674, user.getLanguage())); + resultMap.put("holidayList", holidayList); + } catch (Exception e) { + e.printStackTrace(); + resultMap.put("status", "0"); + resultMap.put("sketch", SystemEnv.getHtmlLabelName(520011, user.getLanguage())); + return resultMap; + } + return resultMap; + } + +} diff --git a/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java b/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java new file mode 100644 index 0000000..143f6e7 --- /dev/null +++ b/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java @@ -0,0 +1,3202 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.entity.KQOvertimeRulesDetailEntity; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.timer.KQOvertimeCardBean; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.TimeRangeCalculator; +import com.engine.kq.wfset.bean.OvertimeBalanceTimeBean; +import com.engine.kq.wfset.bean.SplitBean; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.resource.ResourceComInfo; + +/** + * 鏍规嵁鍔犵彮瑙勫垯璁$畻鍔犵彮鍜岃皟浼戞暟鎹 + * 涓昏鏄拡瀵 娴佺▼+鎵撳崱 鎵撳崱 杩欏嚑绉嶆柟寮 + */ +public class KQOverTimeRuleCalBiz { + private KQLog kqLog = new KQLog(); + + /** + * 鐢熸垚鍔犵彮鏁版嵁 + * @param resourceid + * @param fromDate + * @param toDate + * @param eventtype + */ + public void buildOvertime(String resourceid, String fromDate, String toDate, String eventtype){ + + try{ + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + RecordSet singleRs = new RecordSet(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + Map changeTypeMap = Maps.newHashMap(); + Map overRulesDetailMap = Maps.newHashMap(); + Map> restTimeMap = Maps.newHashMap(); + Map computingModeMap = Maps.newHashMap(); + //鍏堣幏鍙栦竴浜涘墠鎻愭暟鎹紝鍔犵彮瑕忓墖鍜屽亣鏈熻鍓 + getOverTimeDataMap(resourceid, fromDate, toDate, dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap); + Map eventLogMap = Maps.newHashMap(); + eventLogMap.put("fromDate", fromDate); + eventLogMap.put("toDate", toDate); + eventLogMap.put("eventtype", eventtype); + KQOvertimeLogBiz kqEventLogBiz = new KQOvertimeLogBiz(); + String logKey = "|key|"+resourceid+"_"+fromDate+"_"+toDate; + String uuid = kqEventLogBiz.logEvent(resourceid,eventLogMap,"buildOvertime|鐢熸垚鍔犵彮璋冧紤"+logKey); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + LocalDate preFromDate = localFromDate.minusDays(1); + LocalDate nextToDate = localToDate.plusDays(1); + //涔嬪墠鏄冭檻澶栭儴鑰冨嫟鏁版嵁瀵煎叆璺ㄥぉ鎵撳崱锛屽垽鏂綊灞炵殑闂锛屽悜鍓嶇畻涓澶╋紝鐜板湪涓嶇浜嗭紝閮芥槸榛樿鍙鐞嗗綋澶╃殑 + if(eventtype.indexOf("#flow,") > -1 || eventtype.indexOf("punchcard") > -1 || true){ + //濡傛灉鏄甯歌蛋鐨勫姞鐝祦绋嬶紝灏辨槸娴佺▼寮濮嬫棩鏈熷拰缁撴潫鏃ユ湡锛屽彧鏈夎ˉ鍗★紝鎵撳崱锛屽悓姝ョ殑鏃跺欐墠闇瑕佸鐞嗕竴涓嬪墠涓澶╁拰鍚庝竴澶╃殑鏁版嵁 + preFromDate = localFromDate; + nextToDate = localToDate; + } + long betweenDays = nextToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + LocalDate curLocalDate = preFromDate.plusDays(i); + String splitDate = curLocalDate.format(dateFormatter); + String key = resourceid + "_" + splitDate; + String change_key = splitDate + "_" + resourceid; + int changeType = Util.getIntValue("" + changeTypeMap.get(change_key), -1); + String changeType_key = splitDate + "_" + changeType; + int computingMode = Util.getIntValue(""+computingModeMap.get(changeType_key),-1); + if(computingMode == 2){ +// 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屼絾鏄笉鑳借秴杩囧鎵规椂闀 + doComputingMode2(resourceid,splitDate,dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap, + computingModeMap,kqTimesArrayComInfo,uuid,singleRs); + } + if(computingMode == 3){ +// 鏃犻渶瀹℃壒锛屾牴鎹墦鍗℃椂闂磋绠楀姞鐝椂闀 + doComputingMode3(resourceid,splitDate,dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap, + computingModeMap,kqTimesArrayComInfo,uuid,singleRs); + } + if(computingMode == 4){ +// 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屽彇娴佺▼鍜屾墦鍗$殑浜ら泦 + doComputingMode4(resourceid,splitDate,dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap, + computingModeMap,kqTimesArrayComInfo,uuid,singleRs); + } + } + }catch (Exception e){ + kqLog.info("鍔犵彮鐢熸垚鏁版嵁鎶ラ敊:KQOverTimeRuleCalBiz:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + } + + /** + * 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屽彇娴佺▼鍜屾墦鍗$殑浜ら泦 + * @param resourceid + * @param splitDate + * @param dateFormatter + * @param changeTypeMap + * @param overRulesDetailMap + * @param restTimeMap + * @param computingModeMap + * @param kqTimesArrayComInfo + * @param main_uuid + * @param singleRs + */ + private void doComputingMode4(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, RecordSet singleRs) throws Exception{ + String key = resourceid+"_"+splitDate; + //鍔犵彮鏃ュ織璁板綍绫 + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceid, splitDate); + Map workTimeEntityLogMap = Maps.newHashMap(); + workTimeEntityLogMap.put("resourceid", resourceid); + workTimeEntityLogMap.put("splitDate", splitDate); + workTimeEntityLogMap.put("workTimeEntity", workTimeEntity); + KQOvertimeLogBiz kqEventLogBiz = new KQOvertimeLogBiz(); + String uuid = kqEventLogBiz.logDetailWorkTimeEntity(resourceid,workTimeEntityLogMap,main_uuid,"doComputingMode4|鍔犵彮璁$畻,闇瀹℃壒,浠ユ墦鍗′负鍑,鍙栨祦绋嬪拰鎵撳崱鐨勪氦闆唡key|"+key); + Map overtimeLogMap = Maps.newLinkedHashMap(); + + Map eventMap = Maps.newLinkedHashMap(); + Map lsCheckInfoMaps = Maps.newLinkedHashMap(); + //鑾峰彇鍔犵彮鎵撳崱鏁版嵁 + getOverTimeCardDataMap(resourceid, splitDate, splitDate, dateFormatter,kqTimesArrayComInfo,overRulesDetailMap,changeTypeMap,lsCheckInfoMaps,eventMap); + + if(lsCheckInfoMaps.isEmpty()){ + logOvertimeMap(overtimeLogMap, "娌℃湁鎵撳崱鏁版嵁", "鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode4|瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹畖key|"+key); + return; + } + RecordSet rs = new RecordSet(); + + Iterator> iterator = lsCheckInfoMaps.entrySet().iterator(); + while (iterator.hasNext()) { + Entry next = iterator.next(); + String mapKey = next.getKey(); + KQOvertimeCardBean kqOvertimeCardBean = next.getValue(); + String[] mapKeys = mapKey.split("_"); + if (mapKeys.length != 2) { + continue; + } + String realSplitDate = mapKeys[1]; + + Map> splitBeanMaps = Maps.newHashMap(); + //鑾峰彇鍔犵彮娴佺▼鏁版嵁 + getOverTimeFlowData(resourceid,realSplitDate,realSplitDate,splitBeanMaps,dateFormatter); + + String change_key = realSplitDate+"_"+resourceid; + int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1); + String changeType_key = realSplitDate+"_"+changeType; + String changetypeName = 1==changeType ? "鑺傚亣鏃" : (2 == changeType ? "宸ヤ綔鏃" : (3 == changeType ? "浼戞伅鏃" : "寮傚父")); + String changetypeLogInfo = change_key+"|changeType|"+changeType+"|"+changetypeName; + logOvertimeMap(overtimeLogMap, changetypeLogInfo, mapKey+"|"+"鍔犵彮鏃ユ湡灞炴changetypeLogInfo"); + + clearOvertimeTX(resourceid, realSplitDate,overtimeLogMap,splitDate); + logOvertimeMap(overtimeLogMap, kqOvertimeCardBean, mapKey+"|"+"鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if(kqOvertimeRulesDetailEntity == null){ + String overRuleInfo = "changeType_key:"+changeType_key+":kqOvertimeRulesDetailEntity:"+kqOvertimeRulesDetailEntity; + logOvertimeMap(overtimeLogMap, overRuleInfo, mapKey+"|"+"鍔犵彮瑙勫垯涓簄ull|kqOvertimeRulesDetailEntity"); + continue; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if(overtimeEnable != 1){ + String overtimeEnableInfo = "overtimeEnable:"+overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey+"|"+"鏈紑鍚姞鐝鍒檤overtimeEnable"); + continue; + } + + if(kqOvertimeCardBean != null){ + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + List> hasOverTime4SignList = Lists.newArrayList(); + getHasOverTimeData(resourceid,realSplitDate,hasOverTime4SignList); + Map signinoffMap = buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key,initArrays,hasOverTime4SignList, + overRulesDetailMap,true,overtimeLogMap); + logOvertimeMap(overtimeLogMap, signinoffMap, mapKey+"|"+"鑾峰彇涓婁笅鐝墦鍗℃暟鎹畖signinoffMap"); + + String signinTime = Util.null2String(signinoffMap.get("signinTime")); + String signoutTime = Util.null2String(signinoffMap.get("signoutTime")); + String signinDate = Util.null2String(signinoffMap.get("signinDate")); + String signoutDate = Util.null2String(signinoffMap.get("signoutDate")); + int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime); + int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime); + + if(signinTimeIndex < signoutTimeIndex){ + //鍏堣鐩栨墦鍗 鎵撳崱鍖洪棿閮芥槸1 + int over_count = kqTimesArrayComInfo.getCnt(initArrays, signinTimeIndex, signoutTimeIndex, 1); + String overCountLogInfo = "signinTimeIndex:"+signinTimeIndex+":signoutTimeIndex:"+signoutTimeIndex+":over_count:"+over_count; + logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"鎵撳崱鍖洪棿锛屽緱鍒版墦鍗℃椂闀縷over_count"); + if(over_count > 0){ + int restTimeType = 1; + String kqOvertimeRulesDetailEntityLogInfo = kqOvertimeRulesDetailEntity==null ? "" :JSON.toJSONString(kqOvertimeRulesDetailEntity); + logOvertimeMap(overtimeLogMap, kqOvertimeRulesDetailEntityLogInfo, mapKey+"|鍏蜂綋杩欎釜浜鸿繖涓澶╁搴旂殑鍔犵彮瑙勫垯|KQOvertimeRulesDetailEntity"); + int minimumLen = -1; + if(kqOvertimeRulesDetailEntity != null){ + minimumLen = kqOvertimeRulesDetailEntity.getMinimumLen(); + if(over_count < minimumLen){ + String minInfo = "over_count:"+over_count+":minimumLen:"+minimumLen; + logOvertimeMap(overtimeLogMap, minInfo, mapKey+"|鎵撳崱鏃堕暱灏忎簬鏈灏忓姞鐝椂闀縷over_count splitBeans = splitBeanMaps.get(mapKey); + String flowinfo = ""; + if(splitBeans != null && !splitBeans.isEmpty()){ + flowinfo = JSON.toJSONString(splitBeans, SerializerFeature.DisableCheckSpecialChar,SerializerFeature.DisableCircularReferenceDetect); + } + eventMap.put(mapKey+"|"+"鍔犵彮娴佺▼鏁版嵁|flowinfo", flowinfo); + + if(splitBeans == null || splitBeans.isEmpty()){ + return; + } + + for (int m = 0; m < splitBeans.size(); m++) { + SplitBean splitBean = splitBeans.get(m); + String dataid = splitBean.getDataId(); + String detailid = splitBean.getDetailId(); + String flow_fromdate = splitBean.getFromDate(); + String flow_fromtime = splitBean.getFromTime(); + String flow_todate = splitBean.getToDate(); + String flow_totime = splitBean.getToTime(); + String fromdatedb = splitBean.getFromdatedb(); + String fromtimedb = splitBean.getFromtimedb(); + String todatedb = splitBean.getTodatedb(); + String totimedb = splitBean.getTotimedb(); + String requestid = splitBean.getRequestId(); + double d_mins = splitBean.getD_Mins(); + if(d_mins <= 0){ + continue; + } + String flow_key = mapKey+"|"+"flow_fromdate|"+flow_fromdate+"|flow_todate|"+flow_todate + +"|flow_fromtime|"+flow_fromtime+"|flow_totime|"+flow_totime; + //濡傛灉鎵撳崱鏁版嵁鏈変簡锛屽啀鎷挎祦绋嬫暟鎹幓瑕嗙洊锛屽緱鍒版湁鏁堢殑鎵撳崱鍖洪棿锛岃繖涓尯闂磋偗瀹氬凡缁忔槸鍘婚櫎浜嗕笂涓嬬彮鏃堕棿鍜屼紤鎭椂闂磋繕鏈夐噸澶嶆墦鍗$殑閮ㄥ垎 + List cross_time_list = Lists.newArrayList(); +// cross_time_list閲屽瓨鐨勬槸鎺掗櫎浜嗗伐浣滄椂闂寸殑鎵撳崱娈碉紝鎵惧埌1琛ㄧず鎵惧埌鎵撳崱寮濮嬬殑鐐逛簡锛屾壘鍒-2琛ㄧず鎵惧埌鎵撳崱缁撴潫鐨勭偣浜 + get_cross_time_list(cross_time_list,initArrays,signinTimeIndex,signoutTimeIndex,1,-2); + logOvertimeMap(overtimeLogMap, cross_time_list, flow_key+"|cross_time_list"); + int[] initArrays_flow = Arrays.copyOfRange(initArrays,0,initArrays.length); + if(flow_fromdate.compareTo(realSplitDate) > 0){ + flow_fromtime = kqTimesArrayComInfo.turn24to48Time(flow_fromtime); + } + if(flow_todate.compareTo(realSplitDate) > 0){ + flow_totime = kqTimesArrayComInfo.turn24to48Time(flow_totime); + } + int flow_fromIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_fromtime); + int flow_toIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_totime); + //鍦ㄥ凡缁忔墦鍗$殑鍖洪棿1涓婅鐩2锛岄偅涔堝湪鏈夋晥鎵撳崱鑼冨洿鍐呮槸2鐨勫氨鏄氦闆嗙殑閮ㄥ垎 + Arrays.fill(initArrays_flow, flow_fromIndex, flow_toIndex,2); +// 鏈潵涓嬮潰鐨勮繖涓湴鏂规槸澶勭悊閲嶅娴佺▼鐨勯棶棰橈紝姣斿鎻愪簡涓や釜娴佺▼19-20,19-21锛岄偅涔堣繖淇╂祦绋嬬浉浜掍氦鍙夌殑璇濅篃鍙兘鐢熸垚2涓皬鏃讹紝浣嗘槸鍚庢潵璁ㄨ +// 娴佺▼鐩存帴鐨勯噸澶嶆牎楠屽氨閫氳繃寮閭d釜鏍¢獙瑙勫垯浜嗭紝姣忎竴涓祦绋嬮兘鏄拰鎵撳崱鐨勬瘮杈冿紝鎵浠ヤ竴涓槸1涓涓槸2.鎬诲叡3 +// List> hasOverTimeList = Lists.newArrayList(); +// getHasOverTimeData(resourceid,realSplitDate,hasOverTimeList); +// logOvertimeMap(overtimeLogMap, hasOverTimeList, flow_key+"|鏄惁宸茬粡鐢熸垚杩囧姞鐝紝杩斿洖宸茬粡鐢熸垚杩囧姞鐝殑鍖洪棿|hasOverTimeList"); +// if(hasOverTimeList != null && !hasOverTimeList.isEmpty()){ +// for(int p = 0 ; p < hasOverTimeList.size(); p++){ +// Map hasOverTimeMap = hasOverTimeList.get(p); +// +// String fromdate_flow = Util.null2String(hasOverTimeMap.get("fromdate_flow")); +// String fromtime_flow = Util.null2String(hasOverTimeMap.get("fromtime_flow")); +// String todate_flow = Util.null2String(hasOverTimeMap.get("todate_flow")); +// String totime_flow = Util.null2String(hasOverTimeMap.get("totime_flow")); +// int has_flow_fromIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime_flow); +// int has_totime_flow = kqTimesArrayComInfo.getArrayindexByTimes(totime_flow); +// //鎶婇噸澶嶇殑娴佺▼缁欏幓鎺夛紝瑕嗙洊鎴-1 +// Arrays.fill(initArrays_flow, has_flow_fromIndex, has_totime_flow,-2); +// } +// } + + int across_mins = 0; + for(int i = 0 ; i < cross_time_list.size() ;) { + int cross_fromtime_index = cross_time_list.get(i); + int cross_totime_index = cross_time_list.get(i + 1); + //鍓嶉潰鎵撳崱鍖洪棿娈靛凡缁忛兘琚祦绋嬬粰瑕嗙洊浜嗭紝鎵浠ュ彇鑾峰彇鎵撳崱鍖洪棿娈靛唴鏈夊灏戞祦绋嬬殑鏍囪瘑2锛屽氨鏄氦鍙夐儴鍒嗕簡 + int flow_count = kqTimesArrayComInfo.getCnt(initArrays_flow, cross_fromtime_index, cross_totime_index, 2); + logOvertimeMap(overtimeLogMap, flow_count, flow_key+"|鍙栨墦鍗″拰娴佺▼鐩镐氦鐨勬椂闀縷flow_count"); + + if(flow_count > 0){ + List flow_cross_time_list = Lists.newArrayList(); + // 鎵惧埌2琛ㄧず鎵惧埌娴佺▼寮濮嬬殑鐐逛簡锛屾壘鍒1琛ㄧず鎵惧埌娴佺▼缁撴潫鐨勭偣浜 + get_cross_time_list(flow_cross_time_list,initArrays_flow,cross_fromtime_index,cross_totime_index,2,1); + + logOvertimeMap(overtimeLogMap, flow_cross_time_list, flow_key+"|鍙栨墦鍗″拰娴佺▼鐩镐氦鐨勫尯闂磡flow_cross_time_list"); + for(int j = 0 ; j < flow_cross_time_list.size() ;){ + int flow_cross_fromtime_index = flow_cross_time_list.get(j); + int flow_cross_totime_index = flow_cross_time_list.get(j+1); + + int mins = flow_cross_totime_index-flow_cross_fromtime_index; + if(mins <= 0){ + String crossInfo = "flow_cross_fromtime_index:"+flow_cross_fromtime_index+":flow_cross_totime_index:"+flow_cross_totime_index+":mins:"+mins; + logOvertimeMap(overtimeLogMap, crossInfo, flow_key+"|鎵撳崱鏃堕暱灏忎簬鏈灏忓姞鐝椂闀縷crossInfo"); + continue; + } + across_mins += mins; + + String flow_cross_key = "鍔犵彮璁$畻鍖洪棿|"+kqTimesArrayComInfo.getTimesByArrayindex(flow_cross_fromtime_index)+"-"+kqTimesArrayComInfo.getTimesByArrayindex(flow_cross_totime_index); + logOvertimeMap(overtimeLogMap, mins, flow_cross_key+"|鍘熷鍔犵彮鍖洪棿鐢熸垚鐨勫姞鐝椂闀縷mins"); + + String cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(flow_cross_fromtime_index); + String cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(flow_cross_totime_index); + String cross_fromdate = realSplitDate; + String cross_todate = realSplitDate; + + boolean needSplitByTime = false; + if(needSplitByTime){ + // 鎸夌収鍔犵彮鏃堕暱杞皟浼戠殑 鏃堕暱璁剧疆 杩欎釜閫昏緫濡傛灉鍚庨潰瑕佸紑鍚潵鍙互鐩存帴鐢ㄧ殑 + List timepointList = null; + if(kqOvertimeRulesDetailEntity != null){ + timepointList = get_timepointList(kqOvertimeRulesDetailEntity); + logOvertimeMap(overtimeLogMap, timepointList, flow_cross_key+"|濡傛灉瑕佺敓鎴愯皟浼戜笖鏄牴鎹椂闂村尯闂存潵杞皟浼戯紝杩斿洖瀵瑰簲鐨勬椂闂村尯闂磡timepointList"); + } + + List overtimeBalanceTimeBeans = Lists.newArrayList(); + if(timepointList != null && !timepointList.isEmpty()){ + int[] time_initArrays = kqTimesArrayComInfo.getInitArr(); + for(int t = flow_cross_fromtime_index;t < flow_cross_totime_index; t++){ + time_initArrays[t] = initArrays_flow[t]; + } + get_overtimeBalanceTimeBeans(timepointList,overtimeBalanceTimeBeans,kqTimesArrayComInfo,time_initArrays,flow_cross_totime_index,flow_cross_fromtime_index,2); + } + String overtimeBalanceTimeBeansLogInfo = ""; + if(overtimeBalanceTimeBeans == null || overtimeBalanceTimeBeans.isEmpty()){ + }else{ + overtimeBalanceTimeBeansLogInfo = JSON.toJSONString(overtimeBalanceTimeBeans); + } + logOvertimeMap(overtimeLogMap, overtimeBalanceTimeBeansLogInfo, flow_cross_key+"|濡傛灉瑕佺敓鎴愯皟浼戜笖鏄牴鎹椂闂村尯闂存潵杞皟浼戯紝杩斿洖瀵瑰簲鐨勬椂闂村尯闂村搴旂殑鏃堕暱|overtimeBalanceTimeBeans"); + + if(overtimeBalanceTimeBeans != null && !overtimeBalanceTimeBeans.isEmpty()){ + String bean_cross_fromtime = cross_fromtime; + String bean_cross_totime = cross_totime; + for(int timeIndex = 0 ; timeIndex < overtimeBalanceTimeBeans.size() ;timeIndex++){ + OvertimeBalanceTimeBean overtimeBalanceTimeBean = overtimeBalanceTimeBeans.get(timeIndex); + String timePointStart = overtimeBalanceTimeBean.getTimepoint_start(); + String timePointEnd = overtimeBalanceTimeBean.getTimepoint_end(); + boolean isNeedTX = overtimeBalanceTimeBean.isNeedTX(); + int timePointStart_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointStart); + int timePointEnd_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointEnd); + if(timePointStart_index > flow_cross_fromtime_index){ + bean_cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(timePointStart_index); + }else{ + bean_cross_fromtime = cross_fromtime; + } + if(timePointEnd_index < flow_cross_totime_index){ + bean_cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(timePointEnd_index); + }else{ + bean_cross_totime = cross_totime; + } + int timepoint_mins = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_mins == 0){ + continue; + } + mins = timepoint_mins; + } + } + }else{ + } + j =j + 2; + } }else{ + + } + i = i +2; + } + + if(kqOvertimeRulesDetailEntity != null){ + //鎴戣繖涓柟娉曟槸閽堝姣忔鐢熸垚鐨勫姞鐝暟鎹仛鎺掗櫎浼戞伅鏃堕暱鐨勫鐞 + restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType(); + if(restTimeType == 2){ + across_mins = new KQOverTimeFlowBiz().handle_restlength(across_mins,restTimeMap,changeType_key); + } + } + int card_mins = over_count; + double double_mins = getD_MinsByUnit((1.0*across_mins)); + across_mins = (int)double_mins; + if(across_mins <= 0){ + logOvertimeMap(overtimeLogMap, across_mins, flow_key+"|缁忚繃鍗曚綅鎹㈢畻涔嬪悗鏃堕暱涓0|across_mins"); + continue; + } + if(across_mins < minimumLen){ + String minInfo = "across_mins:"+across_mins+":minimumLen:"+minimumLen; + logOvertimeMap(overtimeLogMap, minInfo, flow_key+"|鎵撳崱鏃堕暱灏忎簬鏈灏忓姞鐝椂闀縷over_count otherParam = Maps.newHashMap(); + otherParam.put("overtime_type", overtime_type); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if(2 == paidLeaveEnableType){ + logOvertimeMap(overtimeLogMap, overtime_type, flow_key+"|鍏宠仈璋冧紤涓庡惁鏉ヨ嚜浜庢祦绋嬮夋嫨,鍔犵彮绫诲瀷涓嬫媺妗嗗紎overtime_type"); + } + + int paidLeaveEnable = getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type); + //鐩墠涓嶅鐞嗘寜鐓ф椂闂存鐢熸垚璋冧紤 + boolean needSplitByTime = false;//getNeedSplitByTime(kqOvertimeRulesDetailEntity, paidLeaveEnable); + if(needSplitByTime){ + + }else{ + otherParam.put("overtimeLogMap", overtimeLogMap); + logOvertimeMap(overtimeLogMap, across_mins, flow_key+"|鏈缁堢敓鎴愮殑鍔犵彮鍒嗛挓鏁皘overtime_mins"); + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceid, realSplitDate); + String tableNameFind = getTableNameByRequestid(requestid,"0"); + kqLog.info("鑾峰彇褰撳墠浜哄憳groupId:"+groupId+"tableNameFind:"+tableNameFind+"across_mins:"+across_mins); + BaseBean bb = new BaseBean(); + //绠$悊浜哄憳鑰冨嫟缁刬d + String glgroupid = bb.getPropValue("nbkq_main","glgroupid"); + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main","glrygroupid"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮id + String searIdBb = bb.getPropValue("nbkq_main","searIdBb"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮鏈澶у姞鐝椂闀 + Integer bbMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","bbMaxMins")); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮id + String searIdYb = bb.getPropValue("nbkq_main","searIdYb"); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮鏈澶у姞鐝椂闀 + Integer ybMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","ybMaxMins")); + //鍔犵彮鐢宠娴佺▼琛ㄥ悕 + String lctableName = bb.getPropValue("nbkq_main","lctableName"); + Integer bxszh = changeBxs(across_mins); + Integer yxszh = changeyxs(across_mins); + String searIdFrom = workTimeEntity.getSerialId(); + kqLog.info("鍗婂皬鏃惰鎻愭椂闀縝xszh:"+bxszh+"yxszh:"+yxszh+"searIdFrom:"+searIdFrom); + String jblx = ""; + String bxfs = ""; + String sqsy = ""; + if(lctableName.equals(tableNameFind)){ + jblx = findjbxz(requestid,tableNameFind); + bxfs = findbcfs(requestid,tableNameFind); + sqsy = findsqsy(requestid,tableNameFind); + kqLog.info("jblx:"+jblx); + if(groupId.equals(glgroupid)){ + kqLog.info("鏄鐞嗕汉鍛樺崟鍙屼紤"); + //鏄鐞嗕汉鍛樺崟鍙屼紤 + if("0".equals(jblx)){ + kqLog.info("涓存椂鍘讳竴绾"); + //涓存椂鍘讳竴绾 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(across_mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + across_mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + across_mins = bxszh; + } + }else{ + //绠$悊浜哄憳鐨勫崟鍙屼紤鐝鍔犵彮瑙勫垯鏄姞鐝渶灏忓崟浣嶆槸2灏忔椂锛屼互1灏忔椂涓洪掑璁$畻鍗曚綅,渚嬪2銆3銆4 + //鍒ゆ柇鏄惁灏忎簬2 + if(across_mins<120){ + kqLog.info("灏忎簬2灏忔椂璁0"); + across_mins = 0; + }else{ + kqLog.info("1灏忔椂璁℃彁"); + across_mins = yxszh; + } + } + }else if(groupId.equals(glrygroupid)){ + kqLog.info("鏄鐞嗕汉鍛12灏忔椂"); + //鏄鐞嗕汉鍛12灏忔椂鐝 + if("0".equals(jblx)){ + //涓存椂鍘讳竴绾 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(across_mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + across_mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + across_mins = bxszh; + } + }else{ + //绠$悊浜哄憳鐨12灏忔椂鐝埗鍔犵彮瑙勫垯鏄姞鐝渶灏忓崟浣嶆槸1灏忔椂锛屼互1灏忔椂涓洪掑璁$畻鍗曚綅,渚嬪1銆2銆3 + //鍒ゆ柇鏄惁灏忎簬1 + if(across_mins<60){ + kqLog.info("灏忎簬1灏忔椂璁0"); + across_mins = 0; + }else{ + kqLog.info("1灏忔椂璁℃彁"); + across_mins = yxszh; + } + } + }else{ + //涓嶆槸绠$悊浜哄憳 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(across_mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + across_mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + across_mins = bxszh; + } + } + }else{ + kqLog.info("鏈彁鍔犵彮娴佺▼"); + if(searIdBb.equals(searIdFrom)){ + kqLog.info("鐧界彮"); + if(across_mins>bbMaxMins){ + across_mins = bbMaxMins; + }else{ + across_mins = bxszh; + } + }else if(searIdYb.equals(searIdFrom)){ + kqLog.info("澶滅彮"); + if(across_mins>ybMaxMins){ + across_mins = ybMaxMins; + }else{ + across_mins = bxszh; + } + } + } + + + + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid,realSplitDate,across_mins+"","0",workingHours,requestid,"1",realSplitDate,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("doComputingMode4 鐢熸垚璋冧紤鎴愬姛锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + }else{ + kqLog.info("doComputingMode4 鐢熸垚璋冧紤澶辫触锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + } + logOvertimeMap(overtimeLogMap, tiaoxiuId, flow_key+"|鏈缁堢敓鎴愮殑璋冧紤id|tiaoxiuId"); + + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate," + + "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,card_mins,ori_belongdate,flow_dataid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + if(signinTime.length() == 5){ + signinTime = signinTime+":00"; + } + if(signoutTime.length() == 5){ + signoutTime = signoutTime+":00"; + } + + deleteJbtz(resourceid,"0",realSplitDate); + + insertJbtz(resourceid,String.valueOf(across_mins),resourceid,jblx,bxfs, + signinDate+" "+signinTime,signoutDate+" "+signoutTime,"0", + String.valueOf(changeType),fromdatedb,todatedb,sqsy,fromtimedb,totimedb,realSplitDate,searIdFrom,singleRs); + + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceid,signinDate,signinTime,signoutDate,signoutTime,across_mins,"",realSplitDate, + "",unit,changeType,paidLeaveEnable,computingMode,tiaoxiuId,overtime_uuid,fromdatedb,fromtimedb,todatedb,totimedb,d_mins,card_mins,splitDate,flow_dataid); + + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + } + }else{ + //鏈夋墦鍗℃病鏈夋祦绋 + logOvertimeMap(overtimeLogMap, mapKey, mapKey+"|"+"鍔犵彮娴佺▼涓虹┖"); + } + }else{ + logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"鎵撳崱鏁版嵁鏃堕暱涓0"); + } + }else{ + String overCountLogInfo = "signinTimeIndex:"+signinTimeIndex+":signoutTimeIndex:"+signoutTimeIndex; + logOvertimeMap(overtimeLogMap, overCountLogInfo, mapKey+"|"+"鎵撳崱鏁版嵁寮傚父"); + } + }else{ + logOvertimeMap(overtimeLogMap, "鎵撳崱鏁版嵁KQOvertimeCardBean涓簄ull", mapKey+"|"+"鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode4|瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹畖key|"+key); + + } + + /** + * 寰楀埌鏈夋晥鐨勬墦鍗″尯闂达紝杩欎釜鍖洪棿鑲畾宸茬粡鏄幓闄や簡涓婁笅鐝椂闂村拰浼戞伅鏃堕棿杩樻湁閲嶅鎵撳崱鐨勯儴鍒 + * @param cross_time_list + * @param initArrays + * @param fromIndex + * @param toIndex + * @param cross_from_index + * @param cross_to_index + */ + public void get_cross_time_list(List cross_time_list, int[] initArrays, + int fromIndex, int toIndex,int cross_from_index,int cross_to_index) { + for(int i = fromIndex ; i < toIndex+1 ; i++){ + if(cross_time_list.isEmpty()){ + if(initArrays[i] == cross_from_index){ + cross_time_list.add(i); + } + }else{ + if(cross_time_list.size() % 2 != 0){ + if(initArrays[i] == cross_to_index){ + cross_time_list.add(i); + } + }else{ + if(initArrays[i] == cross_from_index){ + cross_time_list.add(i); + } + } + } + } + if(cross_time_list.size() % 2 != 0){ + cross_time_list.add(toIndex); + } + } + + /** + * 澶勭悊鍔犵彮鏂瑰紡鏄 鏃犻渶瀹℃壒锛屾牴鎹墦鍗℃椂闂磋绠楀姞鐝椂闀 + * @param + * @param resourceid + * @param splitDate + * @param dateFormatter + * @param changeTypeMap + * @param overRulesDetailMap + * @param restTimeMap + * @param computingModeMap + * @param kqTimesArrayComInfo + * @param singleRs + */ + private void doComputingMode3(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, RecordSet singleRs) throws Exception{ + String key = resourceid+"_"+splitDate; + //鍔犵彮鏃ュ織璁板綍绫 + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceid, splitDate); + Map workTimeEntityLogMap = Maps.newHashMap(); + workTimeEntityLogMap.put("resourceid", resourceid); + workTimeEntityLogMap.put("splitDate", splitDate); + workTimeEntityLogMap.put("workTimeEntity", workTimeEntity); + KQOvertimeLogBiz kqEventLogBiz = new KQOvertimeLogBiz(); + String uuid = kqEventLogBiz.logDetailWorkTimeEntity(resourceid,workTimeEntityLogMap,main_uuid,"doComputingMode3|鍔犵彮璁$畻,鏃犻渶瀹℃壒,鏍规嵁鎵撳崱鏃堕棿璁$畻鍔犵彮鏃堕暱|key|"+key); + Map overtimeLogMap = Maps.newLinkedHashMap(); + + Map eventMap = Maps.newHashMap(); + Map lsCheckInfoMaps = Maps.newLinkedHashMap(); + //鑾峰彇鍔犵彮鎵撳崱鏁版嵁 + getOverTimeCardDataMap(resourceid, splitDate, splitDate, dateFormatter,kqTimesArrayComInfo,overRulesDetailMap,changeTypeMap,lsCheckInfoMaps, + eventMap); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode3|瀵瑰簲鐨勬墦鍗℃暟鎹畖key|"+key); + + if(lsCheckInfoMaps.isEmpty()){ + logOvertimeMap(overtimeLogMap, "娌℃湁鎵撳崱鏁版嵁", "鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + return; + } + + Iterator> iterator = lsCheckInfoMaps.entrySet().iterator(); + while (iterator.hasNext()) { + Entry next = iterator.next(); + String mapKey = next.getKey(); + KQOvertimeCardBean kqOvertimeCardBean = next.getValue(); + String[] mapKeys = mapKey.split("_"); + if (mapKeys.length != 2) { + continue; + } + String realSplitDate = mapKeys[1]; + String change_key = realSplitDate+"_"+resourceid; + int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1); + String changeType_key = realSplitDate+"_"+changeType; + String changetypeName = 1==changeType ? "鑺傚亣鏃" : (2 == changeType ? "宸ヤ綔鏃" : (3 == changeType ? "浼戞伅鏃" : "寮傚父")); + String changetypeLogInfo = change_key+"|changeType|"+changeType+"|"+changetypeName; + logOvertimeMap(overtimeLogMap, changetypeLogInfo, "鍔犵彮鏃ユ湡灞炴changetypeLogInfo"); + + clearOvertimeTX(resourceid, realSplitDate,overtimeLogMap, splitDate); + + logOvertimeMap(overtimeLogMap, kqOvertimeCardBean, "鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if(kqOvertimeRulesDetailEntity == null){ + String overRuleInfo = "changeType_key:"+changeType_key+":kqOvertimeRulesDetailEntity:"+kqOvertimeRulesDetailEntity; + logOvertimeMap(overtimeLogMap, overRuleInfo, mapKey+"|"+"鍔犵彮瑙勫垯涓簄ull|kqOvertimeRulesDetailEntity"); + continue; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if(overtimeEnable != 1){ + String overtimeEnableInfo = "overtimeEnable:"+overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey+"|"+"鏈紑鍚姞鐝鍒檤overtimeEnable"); + continue; + } + if(kqOvertimeCardBean != null){ + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + Map signinoffMap = buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key,initArrays,Lists.newArrayList(),overRulesDetailMap, + true, overtimeLogMap); + logOvertimeMap(overtimeLogMap, signinoffMap, "鑾峰彇涓婁笅鐝墦鍗℃暟鎹畖signinoffMap"); + + String signinTime = Util.null2String(signinoffMap.get("signinTime")); + String signoutTime = Util.null2String(signinoffMap.get("signoutTime")); + String signinDate = Util.null2String(signinoffMap.get("signinDate")); + String signoutDate = Util.null2String(signinoffMap.get("signoutDate")); + int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime); + int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime); + String flow_cross_key = mapKey+"|"+"鍔犵彮璁$畻鍖洪棿|"+signinTime+"-"+signoutTime; + + if(signinTimeIndex < signoutTimeIndex){ + int over_count = kqTimesArrayComInfo.getCnt(initArrays, signinTimeIndex, signoutTimeIndex, 1); + String countLogInfo = "signinTimeIndex:"+signinTimeIndex+":signoutTimeIndex:"+signoutTimeIndex+":over_count:"+over_count; + logOvertimeMap(overtimeLogMap, countLogInfo, mapKey+"|"+"鎵撳崱鍖洪棿锛屽緱鍒版墦鍗℃椂闀縷over_count"); + if(over_count > 0){ + //琛ㄧず鍔犵彮鎵撳崱鏄瓨鍦ㄧ殑 + int restTimeType = 1; + if(kqOvertimeRulesDetailEntity != null){ + int minimumLen = kqOvertimeRulesDetailEntity.getMinimumLen(); + if(over_count < minimumLen){ + continue; + } + logOvertimeMap(overtimeLogMap, JSON.toJSONString(kqOvertimeRulesDetailEntity), mapKey+"|"+"鍔犵彮瑙勫垯|KQOvertimeRulesDetailEntity"); + //鎴戣繖涓柟娉曟槸閽堝姣忔鐢熸垚鐨勫姞鐝暟鎹仛鎺掗櫎浼戞伅鏃堕暱鐨勫鐞 + restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType(); + if(restTimeType == 2){ + over_count = new KQOverTimeFlowBiz().handle_restlength(over_count,restTimeMap,changeType_key); + } + } + if(over_count <= 0){ + logOvertimeMap(overtimeLogMap, "娌℃湁鎵撳崱鏁版嵁", mapKey+"|"+"鎵撳崱鏃堕暱|over_count"); + continue; + } + logOvertimeMap(overtimeLogMap, over_count, mapKey+"|"+"缁忓巻杩囦紤鎭椂闂翠箣鍚庣殑鍔犵彮鏃堕暱|over_rest_count"); + + int mins = over_count; + double double_mins = getD_MinsByUnit((1.0*mins)); + mins = (int)double_mins; + + RecordSet rs = new RecordSet(); + String overtime_uuid = UUID.randomUUID().toString(); + String tiaoxiuId = ""; + String workingHours = ""; + int computingMode = 3; + + Map otherParam = Maps.newHashMap(); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + + int paidLeaveEnable = kqOvertimeRulesDetailEntity.getPaidLeaveEnable(); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + boolean needSplitByTime = false;//getNeedSplitByTime(kqOvertimeRulesDetailEntity, paidLeaveEnable); + if(needSplitByTime){ + // 鎸夌収鍔犵彮鏃堕暱杞皟浼戠殑 鏃堕暱璁剧疆 + List timepointList = null; + if(kqOvertimeRulesDetailEntity != null){ + timepointList = get_timepointList(kqOvertimeRulesDetailEntity); + logOvertimeMap(overtimeLogMap, timepointList, flow_cross_key+"|濡傛灉瑕佺敓鎴愯皟浼戜笖鏄牴鎹椂闂村尯闂存潵杞皟浼戯紝杩斿洖瀵瑰簲鐨勬椂闂村尯闂磡timepointList"); + } + + List overtimeBalanceTimeBeans = Lists.newArrayList(); + if(timepointList != null && !timepointList.isEmpty()){ + int[] time_initArrays = kqTimesArrayComInfo.getInitArr(); + for(int t = signinTimeIndex;t < signoutTimeIndex; t++){ + time_initArrays[t] = initArrays[t]; + } + get_overtimeBalanceTimeBeans(timepointList,overtimeBalanceTimeBeans,kqTimesArrayComInfo,time_initArrays,signoutTimeIndex,signinTimeIndex,1); + } + String overtimeBalanceTimeBeansLogInfo = ""; + if(overtimeBalanceTimeBeans == null || overtimeBalanceTimeBeans.isEmpty()){ + }else{ + overtimeBalanceTimeBeansLogInfo = JSON.toJSONString(overtimeBalanceTimeBeans); + } + logOvertimeMap(overtimeLogMap, overtimeBalanceTimeBeansLogInfo, flow_cross_key+"|濡傛灉瑕佺敓鎴愯皟浼戜笖鏄牴鎹椂闂村尯闂存潵杞皟浼戯紝杩斿洖瀵瑰簲鐨勬椂闂村尯闂村搴旂殑鏃堕暱|overtimeBalanceTimeBeans"); + + if(overtimeBalanceTimeBeans != null && !overtimeBalanceTimeBeans.isEmpty()){ + String bean_cross_fromtime = signinTime; + String bean_cross_totime = signoutTime; + for(int timeIndex = 0 ; timeIndex < overtimeBalanceTimeBeans.size() ;timeIndex++) { + OvertimeBalanceTimeBean overtimeBalanceTimeBean = overtimeBalanceTimeBeans.get(timeIndex); + String timePointStart = overtimeBalanceTimeBean.getTimepoint_start(); + String timePointEnd = overtimeBalanceTimeBean.getTimepoint_end(); + int timePointStart_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointStart); + int timePointEnd_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointEnd); + if(timePointStart_index > signinTimeIndex){ + bean_cross_fromtime = kqTimesArrayComInfo.getTimesByArrayindex(timePointStart_index); + }else{ + bean_cross_fromtime = signinTime; + } + if(timePointEnd_index < signoutTimeIndex){ + bean_cross_totime = kqTimesArrayComInfo.getTimesByArrayindex(timePointEnd_index); + }else{ + bean_cross_totime = signoutTime; + } + int timepoint_mins = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_mins == 0){ + continue; + } + mins = timepoint_mins; + otherParam.put("OvertimeBalanceTimeBean", overtimeBalanceTimeBean); + otherParam.put("overtimeLogMap", overtimeLogMap); + String timepoint_key = flow_cross_key+"|璋冧紤鎸夌収鍒嗘璁$畻鍔犵彮鏃堕棿("+signinTime+"-"+signoutTime+")"; + otherParam.put("timepoint_key", timepoint_key); + logOvertimeMap(overtimeLogMap, mins, timepoint_key+"鏈缁堢敓鎴愮殑鍔犵彮鍒嗛挓鏁皘overtime_mins"); + + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid,realSplitDate,mins+"","0",workingHours,"","",realSplitDate,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("doComputingMode3 鐢熸垚璋冧紤鎴愬姛锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + }else{ + kqLog.info("doComputingMode3 鐢熸垚璋冧紤澶辫触锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + } + overtime_uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate," + + "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,ori_belongdate)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + boolean isUp = rs.executeUpdate(flow_overtime_sql, "",resourceid,signinDate,signinTime,signoutDate,signoutTime,mins,"",realSplitDate, + "",unit,changeType,paidLeaveEnable,computingMode,tiaoxiuId,overtime_uuid,"","","","",0,splitDate); + + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + } + }else{ + + logOvertimeMap(overtimeLogMap, mins, flow_cross_key+"|鏈缁堢敓鎴愮殑鍔犵彮鍒嗛挓鏁皘overtime_mins"); + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceid, realSplitDate); + kqLog.info("鑾峰彇褰撳墠浜哄憳groupId:"+groupId+"across_mins:"+mins); + BaseBean bb = new BaseBean(); + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main","glrygroupid"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮id + String searIdBb = bb.getPropValue("nbkq_main","searIdBb"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮鏈澶у姞鐝椂闀 + Integer bbMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","bbMaxMins")); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮id + String searIdYb = bb.getPropValue("nbkq_main","searIdYb"); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮鏈澶у姞鐝椂闀 + Integer ybMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","ybMaxMins")); + Integer bxszh = changeBxs(mins); + String searIdFrom = workTimeEntity.getSerialId(); + kqLog.info("鍗婂皬鏃惰鎻愭椂闀縝xszh:"+bxszh+"searIdFrom:"+searIdFrom); + if(searIdBb.equals(searIdFrom)){ + kqLog.info("鐧界彮"); + if(mins>bbMaxMins){ + mins = bbMaxMins; + }else{ + mins = bxszh; + } + }else if(searIdYb.equals(searIdFrom)){ + kqLog.info("澶滅彮"); + if(mins>ybMaxMins){ + mins = ybMaxMins; + }else{ + mins = bxszh; + } + } + kqLog.info("鏈缁坢ins"+mins); + + + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid,realSplitDate,mins+"","0",workingHours,"","",realSplitDate,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("doComputingMode3 鐢熸垚璋冧紤鎴愬姛锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + }else{ + kqLog.info("doComputingMode3 鐢熸垚璋冧紤澶辫触锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate); + } + + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate," + + "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,ori_belongdate)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + + deleteJbtz(resourceid,"2",realSplitDate); + + insertJbtz(resourceid,String.valueOf(mins),resourceid,"1","1", + signinDate+" "+signinTime,signoutDate+" "+signoutTime,"2", + String.valueOf(changeType),signinDate,signoutDate,"鍥哄畾鍔犵彮鍐欏叆",signinTime,signoutTime,realSplitDate, searIdFrom,singleRs); + + boolean isUp = rs.executeUpdate(flow_overtime_sql, "",resourceid,signinDate,signinTime,signoutDate,signoutTime,mins,"",realSplitDate, + "",unit,changeType,paidLeaveEnable,computingMode,tiaoxiuId,overtime_uuid,"","","","",0,splitDate); + + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + + } + }else{ + logOvertimeMap(overtimeLogMap, "鎵撳崱鍖洪棿涓嶆纭畖"+flow_cross_key, mapKey+"|"+"鎵撳崱鍖洪棿锛屽緱鍒版墦鍗℃椂闀縷over_count"); + } + }else{ + logOvertimeMap(overtimeLogMap, "鎵撳崱鏁版嵁KQOvertimeCardBean涓簄ull", mapKey+"|"+"鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode3|瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹畖key|"+key); + + + } + + /** + * 鑾峰彇鐢熸垚鐨勫姞鐝璱d + * @param overtime_uuid + * @return + */ + public String get_overtime_uuid(String overtime_uuid) { + RecordSet rs = new RecordSet(); + String sql = "select * from kq_flow_overtime where uuid='"+overtime_uuid+"' "; + rs.executeQuery(sql); + if(rs.next()){ + return rs.getString("id"); + } + return ""; + } + + /** + * 鎸夊姞鐝殑鏃堕棿娈佃缃浆璋冧紤鏃堕暱 + * @param kqOvertimeRulesDetailEntity + * @return + */ + public List get_timepointList(KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity) { + List timepointList = Lists.newArrayList(); + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + int ruleDetailid = kqOvertimeRulesDetailEntity.getId(); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if(1 == paidLeaveEnableType){ + int paidLeaveEnableDefaultType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableDefaultType(); + + if(paidLeaveEnableDefaultType == 3){ + Map> balanceTimethDetailMap = kqOvertimeRulesBiz.getBalanceTimeDetailMap(ruleDetailid); + if(balanceTimethDetailMap != null && !balanceTimethDetailMap.isEmpty()){ + timepointList = balanceTimethDetailMap.get("timepointList"); + } + } + }else if(2 == paidLeaveEnableType){ + int paidLeaveEnableFlowType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableFlowType(); + + if(paidLeaveEnableFlowType == 3){ + Map> balanceTimethDetailMap = kqOvertimeRulesBiz.getBalanceTimeDetailMap(ruleDetailid); + if(balanceTimethDetailMap != null && !balanceTimethDetailMap.isEmpty()){ + timepointList = balanceTimethDetailMap.get("timepointList"); + } + } + } + return timepointList; + } + + /** + * 鍔犵彮琛ュ伩瑙勫垯閲岋紝鎸夌収鍔犵彮鏃舵琛ュ伩鏂瑰紡闇瑕佽幏鍙栨瘡涓涓椂闂村尯闂村唴鐨勫姞鐝椂闀 + * @param timepointList + * @param overtimeBalanceTimeBeans + * @param kqTimesArrayComInfo + * @param initArrays + * @param toTime_index + * @param fromTime_index + * @param arrayIndexValue + */ + public void get_overtimeBalanceTimeBeans(List timepointList, + List overtimeBalanceTimeBeans, + KQTimesArrayComInfo kqTimesArrayComInfo, int[] initArrays, + int toTime_index,int fromTime_index,int arrayIndexValue) { + //濡傛灉 [鎸夊姞鐝殑鏃堕棿娈佃缃浆璋冧紤鏃堕暱] 鏄繖绉嶆柟寮忥紝杩橀渶瑕佹牴鎹椂闂寸偣鏉ュ垽鏂椂闂村尯闂村唴鐨勫姞鐝椂闀匡紝鑹 + for(int k = 0 ; k < timepointList.size() ; k++){ + OvertimeBalanceTimeBean overtimeBalanceTimeBean = new OvertimeBalanceTimeBean(); + String start_pointtime = timepointList.get(k); + int start_pointtime_index = kqTimesArrayComInfo.getArrayindexByTimes(start_pointtime); + if(k == 0){ + if(start_pointtime_index > fromTime_index){ + int timepoint_curMins = kqTimesArrayComInfo.getCnt(initArrays, fromTime_index,start_pointtime_index,arrayIndexValue); + OvertimeBalanceTimeBean ori_overtimeBalanceTimeBean = new OvertimeBalanceTimeBean(); + ori_overtimeBalanceTimeBean.setTimepoint(kqTimesArrayComInfo.getTimesByArrayindex(start_pointtime_index)); + ori_overtimeBalanceTimeBean.setTimepoint_start(kqTimesArrayComInfo.getTimesByArrayindex(fromTime_index)); + ori_overtimeBalanceTimeBean.setTimepoint_end(kqTimesArrayComInfo.getTimesByArrayindex(start_pointtime_index)); + ori_overtimeBalanceTimeBean.setTimepoint_mins(timepoint_curMins); + ori_overtimeBalanceTimeBean.setNeedTX(false); + overtimeBalanceTimeBeans.add(ori_overtimeBalanceTimeBean); + } + } + if(start_pointtime_index > toTime_index){ + continue; + } + overtimeBalanceTimeBean.setList_index(k); + int start_index = -1; + int end_index = -1; + if(k == timepointList.size()-1){ + start_index = start_pointtime_index; + end_index = toTime_index; + }else{ + if(k+1 < timepointList.size()){ + String end_pointtime = timepointList.get(k+1); + start_index = start_pointtime_index; + end_index = kqTimesArrayComInfo.getArrayindexByTimes(end_pointtime); + } + } + if(start_index < end_index){ + int timepoint_curMins = kqTimesArrayComInfo.getCnt(initArrays, start_index,end_index,arrayIndexValue); + overtimeBalanceTimeBean.setTimepoint(kqTimesArrayComInfo.getTimesByArrayindex(start_index)); + overtimeBalanceTimeBean.setTimepoint_start(kqTimesArrayComInfo.getTimesByArrayindex(start_index)); + overtimeBalanceTimeBean.setTimepoint_end(kqTimesArrayComInfo.getTimesByArrayindex(end_index)); + overtimeBalanceTimeBean.setTimepoint_mins(timepoint_curMins); + overtimeBalanceTimeBean.setNeedTX(true); + overtimeBalanceTimeBeans.add(overtimeBalanceTimeBean); + } + } + } + + /** + * 澶勭悊鍔犵彮鏂瑰紡鏄 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屼絾鏄笉鑳借秴杩囧鎵规椂闀跨殑鍔犵彮鏃堕暱 + * @param + * @param resourceid + * @param splitDate + * @param dateFormatter + * @param changeTypeMap + * @param overRulesDetailMap + * @param restTimeMap + * @param computingModeMap + * @param kqTimesArrayComInfo + * @param singleRs + */ + private void doComputingMode2(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, RecordSet singleRs) throws Exception{ + String key = resourceid+"_"+splitDate; + //鍔犵彮鏃ュ織璁板綍绫 + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceid, splitDate); + Map workTimeEntityLogMap = Maps.newHashMap(); + workTimeEntityLogMap.put("resourceid", resourceid); + workTimeEntityLogMap.put("splitDate", splitDate); + workTimeEntityLogMap.put("workTimeEntity", workTimeEntity); + KQOvertimeLogBiz kqEventLogBiz = new KQOvertimeLogBiz(); + String uuid = kqEventLogBiz.logDetailWorkTimeEntity(resourceid,workTimeEntityLogMap,main_uuid,"doComputingMode2|鍔犵彮璁$畻,闇瀹℃壒,浠ユ墦鍗′负鍑,浣嗘槸涓嶈兘瓒呰繃瀹℃壒鏃堕暱鐨勫姞鐝椂闀縷key|"+key); + Map overtimeLogMap = Maps.newLinkedHashMap(); + + Map eventMap = Maps.newHashMap(); + Map lsCheckInfoMaps = Maps.newLinkedHashMap(); + //鑾峰彇鍔犵彮鎵撳崱鏁版嵁 + getOverTimeCardDataMap(resourceid, splitDate, splitDate, dateFormatter,kqTimesArrayComInfo,overRulesDetailMap,changeTypeMap,lsCheckInfoMaps, + eventMap); + + Map> splitBeanMaps = Maps.newHashMap(); + //鑾峰彇鍔犵彮娴佺▼鏁版嵁 + getOverTimeFlowData(resourceid,splitDate,splitDate,splitBeanMaps,dateFormatter); + + if(lsCheckInfoMaps.isEmpty()){ + logOvertimeMap(overtimeLogMap, "娌℃湁鎵撳崱鏁版嵁", "鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode2|瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹畖key|"+key); + return; + } + + Iterator> iterator = lsCheckInfoMaps.entrySet().iterator(); + while (iterator.hasNext()){ + Entry next = iterator.next(); + String mapKey = next.getKey(); + KQOvertimeCardBean kqOvertimeCardBean = next.getValue(); + String[] mapKeys = mapKey.split("_"); + if(mapKeys.length != 2){ + continue; + } + String realSplitDate = mapKeys[1]; + + String change_key = realSplitDate+"_"+resourceid; + int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1); + String changeType_key = realSplitDate+"_"+changeType; + String changetypeName = 1==changeType ? "鑺傚亣鏃" : (2 == changeType ? "宸ヤ綔鏃" : (3 == changeType ? "浼戞伅鏃" : "寮傚父")); + String changetypeLogInfo = change_key+"|changeType|"+changeType+"|"+changetypeName; + logOvertimeMap(overtimeLogMap, changetypeLogInfo, mapKey+"|"+"鍔犵彮鏃ユ湡灞炴changetypeLogInfo"); + + clearOvertimeTX(resourceid, realSplitDate,overtimeLogMap, splitDate); + logOvertimeMap(overtimeLogMap, kqOvertimeCardBean, mapKey+"|"+"鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if(kqOvertimeRulesDetailEntity == null){ + String overRuleInfo = "changeType_key:"+changeType_key+":kqOvertimeRulesDetailEntity:"+kqOvertimeRulesDetailEntity; + logOvertimeMap(overtimeLogMap, overRuleInfo, mapKey+"|"+"鍔犵彮瑙勫垯涓簄ull|kqOvertimeRulesDetailEntity"); + continue; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if(overtimeEnable != 1){ + String overtimeEnableInfo = "overtimeEnable:"+overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey+"|"+"鏈紑鍚姞鐝鍒檤overtimeEnable"); + continue; + } + + if(kqOvertimeCardBean != null){ + if(splitBeanMaps.containsKey(mapKey)) { + List splitBeans = splitBeanMaps.get(mapKey); + String flowinfo = ""; + if(splitBeans != null && !splitBeans.isEmpty()){ + flowinfo = JSON.toJSONString(splitBeans, SerializerFeature.DisableCheckSpecialChar,SerializerFeature.DisableCircularReferenceDetect); + }else{ + logOvertimeMap(overtimeLogMap, "鎵撳崱鏁版嵁KQOvertimeCardBean涓簄ull", mapKey+"|"+"鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + continue; + } + eventMap.put(mapKey+"|"+"鍔犵彮娴佺▼鏁版嵁|flowinfo", flowinfo); + for (int m = 0; m < splitBeans.size(); m++) { + int[] initArrays_flow = kqTimesArrayComInfo.getInitArr(); + SplitBean splitBean = splitBeans.get(m); + String dataid = splitBean.getDataId(); + String detailid = splitBean.getDetailId(); + String flow_fromdate = splitBean.getFromDate(); + String flow_fromtime = splitBean.getFromTime(); + String flow_todate = splitBean.getToDate(); + String flow_totime = splitBean.getToTime(); + String fromdatedb = splitBean.getFromdatedb(); + String fromtimedb = splitBean.getFromtimedb(); + String todatedb = splitBean.getTodatedb(); + String totimedb = splitBean.getTotimedb(); + String requestid = splitBean.getRequestId(); + double d_mins = splitBean.getD_Mins(); + if(d_mins <= 0){ + continue; + } + String flow_key = mapKey+"|"+"dataid|"+dataid+"|"+"detailid|"+detailid+"|"+"requestid|"+requestid+"|flow_fromdate|"+flow_fromdate + +"|flow_fromtime|"+flow_fromtime+"|flow_todate|"+flow_todate+"|flow_totime|"+flow_totime; + int flow_count = (int) d_mins; + String flowLogInfo = "flow_fromdate:"+flow_fromdate+":flow_fromtime:"+flow_fromtime + +":flow_todate:"+flow_todate+":flow_totime:"+flow_totime+":requestid:"+requestid + +":d_mins:"+d_mins; + logOvertimeMap(overtimeLogMap, flowLogInfo, flow_key+"|鍔犵彮娴佺▼淇℃伅|flowLogInfo"); + + List> hasOverTimeList = Lists.newArrayList(); + getHasOverTimeData(resourceid,realSplitDate,hasOverTimeList); + logOvertimeMap(overtimeLogMap, hasOverTimeList, flow_key+"|鏄惁宸茬粡鐢熸垚杩囧姞鐝紝杩斿洖宸茬粡鐢熸垚杩囧姞鐝殑鍖洪棿|hasOverTimeList"); + + if(flow_fromdate.compareTo(realSplitDate) > 0){ + flow_fromtime = kqTimesArrayComInfo.turn24to48Time(flow_fromtime); + } + if(flow_todate.compareTo(realSplitDate) > 0){ + flow_totime = kqTimesArrayComInfo.turn24to48Time(flow_totime); + } + int flow_fromIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_fromtime); + int flow_toIndex = kqTimesArrayComInfo.getArrayindexByTimes(flow_totime); + Arrays.fill(initArrays_flow, flow_fromIndex, flow_toIndex,1); + int all_has_duration_min = 0; + //鍥犱负瀛樺湪涓嬬彮鍚庣殑鎵撳崱鍜屼笂鐝墠鐨勬墦鍗°傝繖涓ゅ潡鐨勬墦鍗¢渶瑕佸悎鍦ㄤ竴璧锋潵鍜屽悎鍦ㄤ竴璧风殑娴佺▼姣旇緝鏃堕暱 + Map hasCardMap = Maps.newHashMap(); + if(hasOverTimeList != null && !hasOverTimeList.isEmpty()){ + for(int p = 0 ; p < hasOverTimeList.size(); p++){ + Map hasOverTimeMap = hasOverTimeList.get(p); + String duration_min = Util.null2String(hasOverTimeMap.get("duration_min")); + String flow_dataid = Util.null2String(hasOverTimeMap.get("flow_dataid")); + String ori_belongdate = Util.null2String(hasOverTimeMap.get("ori_belongdate")); + String has_requestid = Util.null2String(hasOverTimeMap.get("requestid")); + + String card_fromdate = Util.null2String(hasOverTimeMap.get("fromdate_flow")); + String card_fromtime = Util.null2String(hasOverTimeMap.get("fromtime_flow")); + String card_todate = Util.null2String(hasOverTimeMap.get("todate_flow")); + String card_totime = Util.null2String(hasOverTimeMap.get("totime_flow")); + String card_key = card_fromdate+"_"+card_fromtime+"_"+card_todate+"_"+card_totime; + + int int_duration_min = Util.getIntValue(duration_min,0); + String has_key = has_requestid; + String cur_key = requestid; + if(flow_dataid.length() > 0){ + has_key += "_"+dataid+"_"+detailid; + cur_key += "_"+flow_dataid; + } + //涓轰粈涔堣鍔犺繖涓垽鏂憿锛屽洜涓烘湁鍙兘鎴戣鍋3灏忔椂锛屾墦鍗1灏忔椂锛岀劧鍚庤繖涓椂鍊欑敓鎴1灏忔椂鍔犵彮锛岀劧鍚庢垜鍚庨潰鍙堣ˉ鍗′簡2灏忔椂锛岃繖鏃跺欙紝鍔犵彮娴佺▼铏界劧宸茬粡 +// 鐢熸垚杩囧姞鐝紝浣嗘槸鍏跺疄鍙敤浜1灏忔椂锛岃繕闇瑕佹嬁杩欎釜鍔犵彮娴佺▼鏉ワ紝鍑忓幓宸茬粡鐢ㄧ殑1灏忔椂锛宒_mins灏辨槸杩欎釜鍔犵彮娴佺▼瀹為檯鍙敤鐨勫姞鐝祦绋嬫椂闀 + if(has_key.equalsIgnoreCase(cur_key)){ + if(int_duration_min > 0){ + d_mins = d_mins-(int_duration_min*1.0); + } + } + all_has_duration_min += int_duration_min; + if(hasCardMap.containsKey(card_key)){ + int tmp_int_duration_min = Util.getIntValue(hasCardMap.get(card_key)); + hasCardMap.put(card_key, ""+(int_duration_min+tmp_int_duration_min)); + }else{ + hasCardMap.put(card_key, int_duration_min+""); + } + } + } + if(d_mins > 0){ + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + Map signinoffMap = buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key,initArrays,hasOverTimeList, + overRulesDetailMap, false, overtimeLogMap); + + String signinTime = Util.null2String(signinoffMap.get("signinTime")); + String signoutTime = Util.null2String(signinoffMap.get("signoutTime")); + String signinDate = Util.null2String(signinoffMap.get("signinDate")); + String signoutDate = Util.null2String(signinoffMap.get("signoutDate")); + int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime); + int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime); + + if(signinTimeIndex < signoutTimeIndex){ + String nowCardKey = signinDate+"_"+kqTimesArrayComInfo.turn48to24Time(signinTime) + +"_"+signoutDate+"_"+kqTimesArrayComInfo.turn48to24Time(signoutTime); + int over_count = kqTimesArrayComInfo.getCnt(initArrays, signinTimeIndex, signoutTimeIndex, 1); + int card_mins = over_count; + logOvertimeMap(overtimeLogMap, over_count, flow_key+"|鍔犵彮鎵撳崱鐢熸垚鐨勬椂闀縷over_count"); + if(over_count > 0){ + //琛ㄧず鍔犵彮鎵撳崱鏄瓨鍦ㄧ殑 + String flow_cross_key = flow_key+"|鍔犵彮璁$畻鍖洪棿|"+signinTime+"-"+signoutTime; + + int restTimeType = 1; + if(kqOvertimeRulesDetailEntity != null){ + int minimumLen = kqOvertimeRulesDetailEntity.getMinimumLen(); + if(card_mins < minimumLen){ + continue; + } + logOvertimeMap(overtimeLogMap, JSON.toJSONString(kqOvertimeRulesDetailEntity), flow_key+"|鍔犵彮瑙勫垯|KQOvertimeRulesDetailEntity"); + //鎴戣繖涓柟娉曟槸閽堝姣忔鐢熸垚鐨勫姞鐝暟鎹仛鎺掗櫎浼戞伅鏃堕暱鐨勫鐞 鎵撳崱鏁版嵁涔熻鍘绘帀浼戞伅鏃堕暱 + restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType(); + if(restTimeType == 2){ + over_count = new KQOverTimeFlowBiz().handle_restlength(over_count,restTimeMap,changeType_key); + } + } + if(all_has_duration_min > 0){ + for(Entry me : hasCardMap.entrySet()){ + String cardKey = me.getKey(); + String cardValue = me.getValue(); + if(cardKey.equalsIgnoreCase(nowCardKey)){ + }else{ + all_has_duration_min = all_has_duration_min - Util.getIntValue(cardValue); + } + } + over_count = over_count-all_has_duration_min; + } + if(over_count <= 0){ + continue; + } + int mins = over_count < d_mins ? over_count : (int)d_mins; + double double_mins = getD_MinsByUnit((1.0*mins)); + mins = (int)double_mins; + + RecordSet rs = new RecordSet(); + String overtime_uuid = UUID.randomUUID().toString(); + String flow_dataid = dataid+"_"+detailid; + String tiaoxiuId = ""; + int computingMode = 2; + + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + String workingHours = ""; + String overtime_type = splitBean.getOvertime_type(); + Map otherParam = Maps.newHashMap(); + otherParam.put("overtime_type", overtime_type); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if(2 == paidLeaveEnableType){ + logOvertimeMap(overtimeLogMap, overtime_type, flow_cross_key+"|鍏宠仈璋冧紤涓庡惁鏉ヨ嚜浜庢祦绋嬮夋嫨,鍔犵彮绫诲瀷涓嬫媺妗嗗紎overtime_type"); + } + + int paidLeaveEnable = getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type); + boolean needSplitByTime = false;//getNeedSplitByTime(kqOvertimeRulesDetailEntity, paidLeaveEnable); + if(needSplitByTime){ + // 鎸夌収鍔犵彮鏃堕暱杞皟浼戠殑 鏃堕暱璁剧疆 + List timepointList = null; + if(kqOvertimeRulesDetailEntity != null){ + timepointList = get_timepointList(kqOvertimeRulesDetailEntity); + logOvertimeMap(overtimeLogMap, timepointList, flow_cross_key+"|濡傛灉瑕佺敓鎴愯皟浼戜笖鏄牴鎹椂闂村尯闂存潵杞皟浼戯紝杩斿洖瀵瑰簲鐨勬椂闂村尯闂磡timepointList"); + } + + List overtimeBalanceTimeBeans = Lists.newArrayList(); + //闇瑕佸垎娈垫牴鎹缃殑鏃堕棿鍖洪棿鏉ヨ绠楀姞鐝紝杩欎釜绗簩绉嶅姞鐝柟寮忔湁鏈夌偣鍐茬獊锛屼笉鑳藉仛 +// if(timepointList != null && !timepointList.isEmpty()){ +// int[] time_initArrays = kqTimesArrayComInfo.getInitArr(); +// get_overtimeBalanceTimeBeans(timepointList,overtimeBalanceTimeBeans,kqTimesArrayComInfo,time_initArrays,flow_cross_totime_index,2); +// } + }else{ + logOvertimeMap(overtimeLogMap, mins, flow_cross_key+"|鏈缁堢敓鎴愮殑鍔犵彮鏃堕暱|mins"); + otherParam.put("overtimeLogMap", overtimeLogMap); + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceid, realSplitDate); + String tableNameFind = getTableNameByRequestid(requestid,"0"); + kqLog.info("鑾峰彇褰撳墠浜哄憳groupId:"+groupId+"tableNameFind:"+tableNameFind+"mins:"+mins); + BaseBean bb = new BaseBean(); + //绠$悊浜哄憳鑰冨嫟缁刬d + String glgroupid = bb.getPropValue("nbkq_main","glgroupid"); + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main","glrygroupid"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮id + String searIdBb = bb.getPropValue("nbkq_main","searIdBb"); + //绠$悊浜哄憳12灏忔椂鐝埗鐧界彮鏈澶у姞鐝椂闀 + Integer bbMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","bbMaxMins")); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮id + String searIdYb = bb.getPropValue("nbkq_main","searIdYb"); + //绠$悊浜哄憳12灏忔椂鐝埗澶滅彮鏈澶у姞鐝椂闀 + Integer ybMaxMins = Util.getIntValue(bb.getPropValue("nbkq_main","ybMaxMins")); + Integer bxszh = changeBxs(mins); + Integer yxszh = changeyxs(mins); + String searIdFrom = workTimeEntity.getSerialId(); + kqLog.info("鍗婂皬鏃惰鎻愭椂闀縝xszh:"+bxszh+"yxszh:"+yxszh+"searIdFrom:"+searIdFrom); + if("formtable_main_404".equals(tableNameFind)){ + String jblx = findjbxz(requestid,tableNameFind); + kqLog.info("jblx:"+jblx); + if(groupId.equals(glgroupid)){ + kqLog.info("鏄鐞嗕汉鍛樺崟鍙屼紤"); + //鏄鐞嗕汉鍛樺崟鍙屼紤 + if("0".equals(jblx)){ + kqLog.info("涓存椂鍘讳竴绾"); + //涓存椂鍘讳竴绾 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + mins = bxszh; + } + }else{ + //绠$悊浜哄憳鐨勫崟鍙屼紤鐝鍔犵彮瑙勫垯鏄姞鐝渶灏忓崟浣嶆槸2灏忔椂锛屼互1灏忔椂涓洪掑璁$畻鍗曚綅,渚嬪2銆3銆4 + //鍒ゆ柇鏄惁灏忎簬2 + if(mins<120){ + kqLog.info("灏忎簬2灏忔椂璁0"); + mins = 0; + }else{ + kqLog.info("1灏忔椂璁℃彁"); + mins = yxszh; + } + } + }else if(groupId.equals(glrygroupid)){ + kqLog.info("鏄鐞嗕汉鍛12灏忔椂"); + //鏄鐞嗕汉鍛12灏忔椂鐝 + if("0".equals(jblx)){ + //涓存椂鍘讳竴绾 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + mins = bxszh; + } + }else{ + //绠$悊浜哄憳鐨12灏忔椂鐝埗鍔犵彮瑙勫垯鏄姞鐝渶灏忓崟浣嶆槸1灏忔椂锛屼互1灏忔椂涓洪掑璁$畻鍗曚綅,渚嬪1銆2銆3 + //鍒ゆ柇鏄惁灏忎簬1 + if(mins<60){ + kqLog.info("灏忎簬1灏忔椂璁0"); + mins = 0; + }else{ + kqLog.info("1灏忔椂璁℃彁"); + mins = yxszh; + } + } + }else{ + //涓嶆槸绠$悊浜哄憳 + //鍒ゆ柇鏄惁灏忎簬0.5 + if(mins<30){ + kqLog.info("灏忎簬鍗婂皬鏃惰0"); + mins = 0; + }else{ + kqLog.info("鍗婂皬鏃惰鎻"); + mins = bxszh; + } + } + }else{ + kqLog.info("鏈彁娴佺▼"); + if(searIdBb.equals(searIdFrom)){ + kqLog.info("鐧界彮"); + if(mins>bbMaxMins){ + mins = bbMaxMins; + }else{ + mins = bxszh; + } + }else if(searIdYb.equals(searIdFrom)){ + kqLog.info("澶滅彮"); + if(mins>ybMaxMins){ + mins = ybMaxMins; + }else{ + mins = bxszh; + } + } + } + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid,realSplitDate,mins+"","0",workingHours,requestid,"1",flow_fromdate,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("doComputingMode2 鐢熸垚璋冧紤鎴愬姛锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate+":requestid:"+requestid); + }else{ + kqLog.info("doComputingMode2 鐢熸垚璋冧紤澶辫触锛岃皟浼慽d:"+tiaoxiuId+":resourceid:"+resourceid+":realSplitDate:"+realSplitDate+":requestid:"+requestid); + } + logOvertimeMap(overtimeLogMap, tiaoxiuId, flow_cross_key+"|鏈缁堢敓鎴愮殑璋冧紤id|tiaoxiuId"); + + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate," + + "workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid,fromdatedb,fromtimedb,todatedb,totimedb,flow_mins,card_mins,ori_belongdate,flow_dataid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + if(fromtimedb.length() == 5){ + fromtimedb = fromtimedb+":00"; + } + if(totimedb.length() == 5){ + totimedb = totimedb+":00"; + } + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceid,fromdatedb,fromtimedb,todatedb,totimedb,mins,"",realSplitDate, + "",unit,changeType,paidLeaveEnable,computingMode,tiaoxiuId,overtime_uuid,signinDate,signinTime,signoutDate,signoutTime,flow_count,card_mins,splitDate,flow_dataid); + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + + } + } + }else{ + logOvertimeMap(overtimeLogMap, "娴佺▼鏃堕暱d_mins涓0锛屼笉鐢熸垚鍔犵彮", flow_key+"|鍔犵彮娴佺▼淇℃伅|flowLogInfo"); + } + } + } + + }else{ + logOvertimeMap(overtimeLogMap, "鎵撳崱鏁版嵁KQOvertimeCardBean涓簄ull", "鎵撳崱鍜屼笂涓嬬彮鏁版嵁|KQOvertimeCardBean"); + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid,overtimeLogMap,uuid); + kqEventLogBiz.logDetailEvent(resourceid,eventMap,uuid,"doComputingMode2|瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹畖key|"+key); + + } + + /** + * 鎵撳崱鐨勬椂闀胯绠楋紝娴佺▼+鎵撳崱 鍜岀函鎵撳崱鐨勫彲浠ユ嬁鏉ュ叡鐢 + * needHasOverTime 鏄惁闇瑕佹寜鐓ф墦鍗″尯闂存帓闄ら噸澶嶆墦鍗$殑鏁版嵁锛岀浜岀娴佺▼鍜屾墦鍗℃瘮杈冩椂闀跨殑涓嶉渶瑕佽繖涓柟寮 + */ + public Map buildOvertimeCard(KQOvertimeCardBean kqOvertimeCardBean, + String resourceid, String splitDate, KQTimesArrayComInfo kqTimesArrayComInfo, + Map> restTimeMap, String changeType_key, int[] initArrays, + List> hasOverTimeList, + Map overRulesDetailMap, boolean needHasOverTime, + Map overtimeLogMap) throws Exception{ + Map signinoffMap = Maps.newHashMap(); + + String signinDate = kqOvertimeCardBean.getSigninDate(); + String signinTime = kqOvertimeCardBean.getSigninTime(); + String signoutDate = kqOvertimeCardBean.getSignoutDate(); + String signoutTime = kqOvertimeCardBean.getSignoutTime(); + + if(hasOverTimeList.isEmpty()){ + getHasOverTimeData(resourceid,splitDate,hasOverTimeList); + } + + if(signinDate.compareTo(splitDate) > 0){ + signinTime = kqTimesArrayComInfo.turn24to48Time(signinTime); + if(signinTime.length() > 0){ + signinTime = signinTime+ ":00"; + } + } + if(signoutDate.compareTo(splitDate) > 0){ + signoutTime = kqTimesArrayComInfo.turn24to48Time(signoutTime); + if(signoutTime.length() > 0){ + signoutTime = signoutTime+ ":00"; + } + } + if(signinTime.length() == 0 || signoutTime.length() == 0){ + return signinoffMap; + } + + int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime); + int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime); + + signinoffMap.put("signinTime", signinTime); + signinoffMap.put("signoutTime", signoutTime); + signinoffMap.put("signinDate", signinDate); + signinoffMap.put("signoutDate", signoutDate); + //鍏堟妸鎵撳崱鏁版嵁閮藉垪鍑烘潵 缃綅1 + if(signinTimeIndex < signoutTimeIndex){ + Arrays.fill(initArrays, signinTimeIndex, signoutTimeIndex,1); + } + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if(restTimeMap.containsKey(changeType_key)){ + List restTimeList = restTimeMap.get(changeType_key); + logOvertimeMap(overtimeLogMap, restTimeList, "闈炲伐浣滄椂闂磋缃殑鎺掗櫎浼戞伅鏃堕棿鍖洪棿|restTimeList"); + //鍐嶆妸浼戞伅鏃堕棿濉厖涓婂幓 + if(!restTimeList.isEmpty()){ + int restTimeType = 1; + if(kqOvertimeRulesDetailEntity != null){ + restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType(); + } + if(restTimeType == 1){ + for(int j =0 ; j < restTimeList.size() ; j++){ + String[] restTimes = restTimeList.get(j); + if(restTimes.length == 2){ + int restStart = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[0]); + int restEnd = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[1]); + if(restEnd == 1439){ + //閽堝璺ㄥぉ鐨勪紤鎭椂娈靛崟鐙鐞嗘帓闄ゆ帀23:59-00:00鐨勬椂闂 + restEnd = 1440; + } + int hasRestMins = kqTimesArrayComInfo.getCnt(initArrays, restStart,restEnd,1); + if(hasRestMins == 0) { + restStart = kqTimesArrayComInfo.turn24to48TimeIndex(restStart); + restEnd = kqTimesArrayComInfo.turn24to48TimeIndex(restEnd); + } + if(restStart < restEnd){ + Arrays.fill(initArrays, restStart, restEnd, -2); + } + } + } + }else{ + } + } + } + + boolean isNextDay = false; + clearWorkAndRestTime(resourceid,splitDate,isNextDay,kqTimesArrayComInfo,overtimeLogMap,kqOvertimeRulesDetailEntity,initArrays,signinTimeIndex); + isNextDay = true; + clearWorkAndRestTime(resourceid,DateUtil.addDate(splitDate, 1),isNextDay, kqTimesArrayComInfo, + overtimeLogMap, kqOvertimeRulesDetailEntity, initArrays, signinTimeIndex); + + if(!hasOverTimeList.isEmpty() && needHasOverTime){ + if(hasOverTimeList != null && !hasOverTimeList.isEmpty()){ + for(int p = 0 ; p < hasOverTimeList.size(); p++){ + Map hasOverTimeMap = hasOverTimeList.get(p); + String duration_min = Util.null2String(hasOverTimeMap.get("duration_min")); + String fromdate = Util.null2String(hasOverTimeMap.get("fromdate")); + String fromtime = Util.null2String(hasOverTimeMap.get("fromtime")); + String todate = Util.null2String(hasOverTimeMap.get("todate")); + String totime = Util.null2String(hasOverTimeMap.get("totime")); + if(fromdate.compareTo(splitDate) > 0){ + fromtime = kqTimesArrayComInfo.turn24to48Time(fromtime); + } + if(todate.compareTo(splitDate) > 0){ + totime = kqTimesArrayComInfo.turn24to48Time(totime); + } + int begintimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + int endtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime); + if(begintimeIndex < endtimeIndex){ + Arrays.fill(initArrays, begintimeIndex, endtimeIndex, -2); + } + } + } + } + return signinoffMap; + } + + /** + * 鎶婃寚瀹氱殑鎵撳崱鍖洪棿鍐呯殑涓婁笅鐝椂闂村拰浼戞伅鏃堕棿鍘婚櫎 + * @param resourceid + * @param splitDate + * @param isNextDay 鏄惁鏄鐞嗗鐞嗘槑鏃ョ殑锛屽鏋滄槸true鐨勮瘽锛屼笂涓嬬彮鏃堕棿鍜屼紤鎭椂闂撮兘瑕+1440 + * @param kqTimesArrayComInfo + * @param overtimeLogMap + * @param kqOvertimeRulesDetailEntity + * @param initArrays + * @param signinTimeIndex + */ + public void clearWorkAndRestTime(String resourceid, String splitDate, boolean isNextDay, + KQTimesArrayComInfo kqTimesArrayComInfo, + Map overtimeLogMap, + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, int[] initArrays, + int signinTimeIndex) { + + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(resourceid, splitDate); + if (workTime == null || workTime.getWorkMins() == 0) { + }else{ + if (workTime.getKQType().equals("3")) {//鑷敱宸ユ椂 + //鐩墠鑷敱宸ユ椂涓嶅姞鐝 + } else { + boolean oneSign = false; + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + List lsRestTime = new ArrayList<>(); + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + lsRestTime = workTime.getRestTime();//浼戞伅鏃舵鏃堕棿 + oneSign = lsWorkTime!=null&&lsWorkTime.size()==1; + + if(lsWorkTime != null && !lsWorkTime.isEmpty()){ + for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) { + TimeScopeEntity workTimeScope = lsWorkTime.get(i); + if(oneSign){ + boolean is_flow_humanized = KQSettingsBiz.is_flow_humanized(); + if(is_flow_humanized){ + String workBeginTime = Util.null2String(workTimeScope.getBeginTime()); + String ori_workBeginTime = workBeginTime; + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + boolean workBenginTimeAcross = workTimeScope.getBeginTimeAcross(); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + String ori_workEndTime = workEndTime; + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + boolean workEndTimeAcross = workTimeScope.getEndTimeAcross(); + + Map shifRuleMap = Maps.newHashMap(); + //涓у寲璁剧疆鍙敮鎸佷竴澶╀竴娆′笂涓嬬彮 + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setSplitDate(splitDate); + shiftInfoBean.setShiftRuleMap(workTime.getShiftRuleInfo()); + shiftInfoBean.setSignTime(lsSignTime); + shiftInfoBean.setWorkTime(lsWorkTime); + List logList = Lists.newArrayList(); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, resourceid, shifRuleMap,logList); + if(!shifRuleMap.isEmpty()){ + if(shifRuleMap.containsKey("shift_beginworktime")){ + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + if(shift_beginworktime.length() > 0){ + workBeginTime = Util.null2String(shift_beginworktime); + workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + workTimeScope.setBeginTime(workBeginTime); + workTimeScope.setBeginTimeAcross(workBeginIdx>=1440?true:false); + } + } + if(shifRuleMap.containsKey("shift_endworktime")){ + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if(shift_endworktime.length() > 0){ + workEndTime = Util.null2String(shift_endworktime); + workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + workTimeScope.setEndTime(workEndTime); + workTimeScope.setEndTimeAcross(workEndIdx>=1440?true:false); + } + } + } + } + } + } + //鐩墠鍙鐞嗕笂鐝墠鍜屼笅鐝悗鐨勫姞鐝暟鎹紝涓婄彮涓棿鐨勬暟鎹笉澶勭悊锛屾墍浠ヤ粠绗竴娆′笂鐝椂闂村埌鏈鍚庝笅鐝椂闂撮兘鏄棤鏁堢殑鍔犵彮鎵撳崱 + TimeScopeEntity first_TimeScopeEntity = lsWorkTime.get(0); + TimeScopeEntity last_TimeScopeEntity = lsWorkTime.get(lsWorkTime.size()-1); + + String begintime = first_TimeScopeEntity.getBeginTime(); + String endtime = last_TimeScopeEntity.getEndTime(); + int begintimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if(isNextDay){ + begintimeIndex = begintimeIndex + 1440; + endtimeIndex = endtimeIndex + 1440; + if(begintimeIndex >= initArrays.length){ + begintimeIndex = initArrays.length-1; + } + if(endtimeIndex >= initArrays.length){ + endtimeIndex = initArrays.length-1; + } + } + String workTimeLogInfo = "begintime:"+begintime+":endtime:"+endtime+":isNextDay:"+isNextDay; + logOvertimeMap(overtimeLogMap, workTimeLogInfo, "宸ヤ綔鏃ョ殑涓婁笅鐝椂闂磡workTimeLogInfo"); + if(begintimeIndex < endtimeIndex){ + Arrays.fill(initArrays, begintimeIndex, endtimeIndex, -2); + } + if(!isNextDay){ + if(kqOvertimeRulesDetailEntity != null){ + int startTime = kqOvertimeRulesDetailEntity.getStartTime(); + if(startTime > -1){ + int after_endtimeIndex = endtimeIndex + startTime; + if(after_endtimeIndex > endtimeIndex){ + Arrays.fill(initArrays, endtimeIndex, after_endtimeIndex, -2); + } + } + int has_cut_point = kqOvertimeRulesDetailEntity.getHas_cut_point(); + if(has_cut_point == 1){ + int before_startTime = kqOvertimeRulesDetailEntity.getBefore_startTime(); + if(before_startTime > -1){ + int before_begintimeIndex = begintimeIndex - before_startTime; + if(before_begintimeIndex > signinTimeIndex){ + Arrays.fill(initArrays, signinTimeIndex, before_begintimeIndex, -2); + } + } + } + } + } + } + if(lsRestTime != null && !lsRestTime.isEmpty()){ + String restTimeLogInfo = JSON.toJSONString(lsRestTime); + logOvertimeMap(overtimeLogMap, restTimeLogInfo, "宸ヤ綔鏃ョ殑浼戞伅鏃堕棿|restTimeLogInfo"); + for(int p = 0 ; p < lsRestTime.size(); p++){ + TimeScopeEntity rest_TimeScopeEntity = lsRestTime.get(p); + String begintime = rest_TimeScopeEntity.getBeginTime(); + String endtime = rest_TimeScopeEntity.getEndTime(); + int begintimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(begintime); + int endtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(endtime); + if(isNextDay){ + begintimeIndex = begintimeIndex + 1440; + endtimeIndex = endtimeIndex + 1440; + if(begintimeIndex >= initArrays.length){ + begintimeIndex = initArrays.length-1; + } + if(endtimeIndex >= initArrays.length){ + endtimeIndex = initArrays.length-1; + } + } + if(begintimeIndex < endtimeIndex){ + Arrays.fill(initArrays, begintimeIndex, endtimeIndex, -2); + } + } + } + + } + } + } + } + + /** + * 鏍规嵁鎵撳崱鏁版嵁鍜屽姞鐝綊灞 鎷嗗垎鍑烘潵闇瑕佽绠楀姞鐝殑鍖烘 + * @param resourceid + * @param fromDate + * @param toDate + * @param dateFormatter + * @param kqTimesArrayComInfo + * @param overRulesDetailMap + * @param changeTypeMap + * @param lsCheckInfoMaps + * @param eventMap + */ + public void getOverTimeCardDataMap(String resourceid, String fromDate, String toDate, + DateTimeFormatter dateFormatter, + KQTimesArrayComInfo kqTimesArrayComInfo, + Map overRulesDetailMap, + Map changeTypeMap, Map lsCheckInfoMaps, + Map eventMap) throws Exception{ + + KQOverTimeFlowBiz kqOverTimeFlowBiz = new KQOverTimeFlowBiz(); + + List lsCheckInfos = Lists.newArrayList(); + Map result = getSignData(resourceid, fromDate, dateFormatter,eventMap,lsCheckInfos,changeTypeMap,overRulesDetailMap); + + //鑾峰彇涓涓嬪綋澶╃殑涓婄彮鏃堕棿 + String firstworkDate = Util.null2String(result.get("firstworkDate")); + String firstworkTime = Util.null2String(result.get("firstworkTime")); + int pre_has_cut_point = Util.getIntValue(Util.null2String(result.get("pre_has_cut_point"))); + String pre_cut_point = Util.null2String(result.get("pre_cut_point")); + int has_cut_point = Util.getIntValue(Util.null2String(result.get("has_cut_point"))); + String cut_point = Util.null2String(result.get("cut_point")); + int before_startTime = Util.getIntValue(Util.null2String(result.get("before_startTime"))); + int preChangeType = Util.getIntValue(Util.null2String(result.get("preChangeType"))); + int changeType = Util.getIntValue(Util.null2String(result.get("changeType"))); + + LocalDate localbelongDate = LocalDate.parse(fromDate); + String splitDate = localbelongDate.format(dateFormatter); + LocalDate preLocalDate = localbelongDate.minusDays(1); + String preSplitDate = preLocalDate.format(dateFormatter); + String nextSplitDate = localbelongDate.plusDays(1).format(dateFormatter); + + String preKey = resourceid+"_"+preSplitDate; + String key = resourceid+"_"+splitDate; + String nextkey = resourceid+"_"+nextSplitDate; + + eventMap.put("lsCheckInfos", lsCheckInfos); + if(!lsCheckInfos.isEmpty()){ + Map signMap = (Map) lsCheckInfos.get(0); + String signindate = ""; + String signintime = ""; + String signoutdate = ""; + String signouttime = ""; + + if(signMap != null && !signMap.isEmpty()){ + signindate = Util.null2String(signMap.get("signindate")); + signintime = Util.null2String(signMap.get("signintime")); + signoutdate = Util.null2String(signMap.get("signoutdate")); + signouttime = Util.null2String(signMap.get("signouttime")); + if(lsCheckInfos.size() > 1){ + Map lastSignMap = (Map) lsCheckInfos.get(lsCheckInfos.size()-1); + signoutdate = Util.null2String(lastSignMap.get("signoutdate")); + signouttime = Util.null2String(lastSignMap.get("signouttime")); + } + } + KQOvertimeCardBean kqOvertimeBean = new KQOvertimeCardBean(); + kqOvertimeBean.setSigninDate(signindate); + kqOvertimeBean.setSigninTime(signintime); + kqOvertimeBean.setSignoutDate(signoutdate); + kqOvertimeBean.setSignoutTime(signouttime); + kqOvertimeBean.setBelongDate(splitDate); + eventMap.put("has_cut_point", has_cut_point); + if(pre_has_cut_point == 0){ + //鏈缃墦鍗″綊灞 + if(preChangeType == 2){ + eventMap.put("preChangeType", preChangeType); + //濡傛灉鍓嶄竴澶╂槸宸ヤ綔鏃 + String pre_overtime_cut_point = ""; + ShiftInfoBean pre_shiftInfoBean = KQDurationCalculatorUtil + .getWorkTime(resourceid, preSplitDate, false); + if(pre_shiftInfoBean != null){ + List workLongTimeIndex = pre_shiftInfoBean.getWorkLongTimeIndex(); + List real_workLongTimeIndex = Lists.newArrayList(); + SplitBean splitBean = new SplitBean(); + splitBean.setResourceId(resourceid); + kqOverTimeFlowBiz.get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,pre_shiftInfoBean,kqTimesArrayComInfo,splitBean); + + if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){ + pre_overtime_cut_point = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]); + } + eventMap.put("pre_overtime_cut_point", pre_overtime_cut_point); + if(pre_overtime_cut_point.length() >= 0){ + rePutCheckInfoMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, pre_overtime_cut_point, splitDate,eventMap); + } + }else{ + String errorMsg = "鍓嶄竴澶╂槸宸ヤ綔鏃ヤ絾鏄墠涓澶╃殑ShiftInfoBean鐝鑾峰彇涓嶅埌淇℃伅"; + eventMap.put("errorMsg", errorMsg); + } + }else { + eventMap.put("changeType", changeType); + if(changeType == 2){ + eventMap.put("firstworkTime", firstworkTime); + if(has_cut_point == 1 && before_startTime > 0){ + firstworkTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(firstworkTime)-before_startTime); + } + //濡傛灉鍓嶄竴澶╂槸闈炲伐浣滄棩锛屼粖澶╂槸宸ヤ綔鏃ョ殑璇 + rePutCheckInfoMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, firstworkTime, splitDate, + eventMap); + }else{ + //濡傛灉鍓嶄竴澶╂槸闈炲伐浣滄棩锛屼粖澶╂槸闈炲伐浣滄棩鐨勮瘽锛岄偅灏辨槸鎵撳崱鑾峰彇鐨勬槸鍟ュ氨鏄暐 + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + } + }else{ + String pre_splittime = ""; + List pre_lsCheckInfos = Lists.newArrayList(); + getSignData(resourceid, preSplitDate, dateFormatter, eventMap, pre_lsCheckInfos, changeTypeMap, overRulesDetailMap); + if(!pre_lsCheckInfos.isEmpty()){ + Map preSignMap = (Map) pre_lsCheckInfos.get(0); + String pre_signindate = ""; + String pre_signintime = ""; + String pre_signoutdate = ""; + String pre_signouttime = ""; + if(preSignMap != null && !preSignMap.isEmpty()){ + pre_signindate = Util.null2String(preSignMap.get("signindate")); + pre_signintime = Util.null2String(preSignMap.get("signintime")); + pre_signoutdate = Util.null2String(preSignMap.get("signoutdate")); + pre_signouttime = Util.null2String(preSignMap.get("signouttime")); + if(pre_signindate.length() > 0 && pre_signintime.length() > 0){ + pre_splittime = pre_signindate+" "+pre_signintime; + }else if(pre_signoutdate.length() > 0 && pre_signouttime.length() > 0){ + pre_splittime = pre_signoutdate+" "+pre_signouttime; + } + } + } + eventMap.put("pre_cut_point", pre_cut_point); + //璁剧疆浜嗘墦鍗″綊灞 閭d箞涓澶╃殑鎵撳崱灏卞彲鑳借鍓嶄竴澶╃粰鎷嗘垚涓ら儴鍒嗗拰鍚庝竴澶╃殑鎵撳崱褰掑睘缁欐媶鍒嗘垚涓ら儴鍒 + rePutCheckInfoCutPointMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, pre_cut_point, splitDate, + eventMap,cut_point,nextSplitDate,nextkey,has_cut_point,pre_splittime); + } + } + } + + /** + * 鑾峰彇鎵撳崱鏁版嵁 + * @param resourceid + * @param belongDate + * @param dateFormatter + * @param eventMap + * @param lsCheckInfos + * @param changeTypeMap + * @param overRulesDetailMap + */ + public Map getSignData(String resourceid, String belongDate, + DateTimeFormatter dateFormatter, Map eventMap, + List lsCheckInfos, Map changeTypeMap, + Map overRulesDetailMap) throws Exception{ + Map result = Maps.newHashMap(); + String firstworkDate = ""; + String firstworkTime = ""; + + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + LocalDate localbelongDate = LocalDate.parse(belongDate); + String splitDate = localbelongDate.format(dateFormatter); + LocalDate preLocalDate = localbelongDate.minusDays(1); + String preSplitDate = preLocalDate.format(dateFormatter); + String nextSplitDate = localbelongDate.plusDays(1).format(dateFormatter); + + String change_key = splitDate+"_"+resourceid; + String preChange_key = preSplitDate+"_"+resourceid; + String nextChange_key = nextSplitDate+"_"+resourceid; + int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1); + int preChangeType = Util.getIntValue(""+changeTypeMap.get(preChange_key),-1); + int nextChangeType = Util.getIntValue(""+changeTypeMap.get(nextChange_key),-1); + String changeType_key = splitDate+"_"+changeType; + String preChangeType_key = preSplitDate+"_"+preChangeType; + String nextChangeType_key = nextSplitDate+"_"+nextChangeType; + + KQOvertimeRulesDetailEntity curKqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity = overRulesDetailMap.get(preChangeType_key); + KQOvertimeRulesDetailEntity nextKqOvertimeRulesDetailEntity = overRulesDetailMap.get(preChangeType_key); + + int pre_has_cut_point = 0; + String pre_cut_point = ""; + if(preKqOvertimeRulesDetailEntity != null){ + pre_has_cut_point = preKqOvertimeRulesDetailEntity.getHas_cut_point(); + pre_cut_point = preKqOvertimeRulesDetailEntity.getCut_point(); + } + int has_cut_point = 0; + String cut_point = ""; + int before_startTime = -1; + if(curKqOvertimeRulesDetailEntity != null){ + has_cut_point = curKqOvertimeRulesDetailEntity.getHas_cut_point(); + cut_point = curKqOvertimeRulesDetailEntity.getCut_point(); + before_startTime =curKqOvertimeRulesDetailEntity.getBefore_startTime(); + } + + result.put("pre_has_cut_point", ""+pre_has_cut_point); + result.put("pre_cut_point", pre_cut_point); + result.put("has_cut_point", ""+has_cut_point); + result.put("cut_point", cut_point); + result.put("before_startTime", ""+before_startTime); + result.put("preChangeType", ""+preChangeType); + result.put("changeType", ""+changeType); + + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(resourceid, splitDate); + + LocalDate pre_curLocalDate = localbelongDate.minusDays(1); + String preDate = pre_curLocalDate.format(dateFormatter); + LocalDate next_curLocalDate = localbelongDate.plusDays(1); + String nextDate = next_curLocalDate.format(dateFormatter); + + if (workTime == null || (workTime.getWorkMins() == 0 && workTime.getRestShift() != 1)) { + Map signMap = getRestSignInfo(resourceid,splitDate,preDate,nextDate,curKqOvertimeRulesDetailEntity,eventMap,preKqOvertimeRulesDetailEntity); + if(signMap != null && !signMap.isEmpty()){ + lsCheckInfos.add(signMap); + } + }else{ + if (workTime.getKQType().equals("3")) {//鑷敱宸ユ椂 + //鐩墠鑷敱宸ユ椂涓嶅姞鐝 + } else { + boolean oneSign = false; + List lsSignTime = new ArrayList<>(); + List lsWorkTime = new ArrayList<>(); + List lsRestTime = new ArrayList<>(); + oneSign = lsWorkTime!=null&&lsWorkTime.size()==1; + boolean need_middle_time = false; + + if (workTime != null) { + lsSignTime = workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + lsWorkTime = workTime.getWorkTime();//宸ヤ綔鏃堕棿 + result.put("lsWorkTime_size", ""+lsWorkTime.size()); + lsRestTime = workTime.getRestTime();//浼戞伅鏃舵鏃堕棿 + oneSign = lsWorkTime!=null&&lsWorkTime.size()==1; + for (int i = 0; lsWorkTime != null && i < lsWorkTime.size(); i++) { + TimeScopeEntity signTimeScope = lsSignTime.get(i); + TimeScopeEntity workTimeScope = lsWorkTime.get(i); + if(i == 0){ + firstworkDate = splitDate; + firstworkTime = workTimeScope.getBeginTime(); + } + if(!oneSign){ + if(!need_middle_time){ + //澶氭鎵撳崱鐨勬椂鍊欙紝涓棿鎵撳崱涓嶇畻鍔犵彮 + if(i != 0 && i != lsWorkTime.size()-1){ + continue; + } + } + }else { + boolean is_flow_humanized = KQSettingsBiz.is_flow_humanized(); + if(is_flow_humanized){ + String workBeginTime = Util.null2String(workTimeScope.getBeginTime()); + String ori_workBeginTime = workBeginTime; + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + boolean workBenginTimeAcross = workTimeScope.getBeginTimeAcross(); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + String ori_workEndTime = workEndTime; + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + boolean workEndTimeAcross = workTimeScope.getEndTimeAcross(); + + Map shifRuleMap = Maps.newHashMap(); + //涓у寲璁剧疆鍙敮鎸佷竴澶╀竴娆′笂涓嬬彮 + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setSplitDate(splitDate); + shiftInfoBean.setShiftRuleMap(workTime.getShiftRuleInfo()); + shiftInfoBean.setSignTime(lsSignTime); + shiftInfoBean.setWorkTime(lsWorkTime); + List logList = Lists.newArrayList(); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, resourceid, shifRuleMap,logList); + if(!shifRuleMap.isEmpty()){ + if(shifRuleMap.containsKey("shift_beginworktime")){ + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + if(shift_beginworktime.length() > 0){ + workBeginTime = Util.null2String(shift_beginworktime); + workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + workTimeScope.setBeginTime(workBeginTime); + workTimeScope.setBeginTimeAcross(workBeginIdx>=1440?true:false); + if(i == 0){ + firstworkDate = workBeginIdx>=1440 ? nextDate : splitDate; + firstworkTime = workBeginTime; + } + } + } + if(shifRuleMap.containsKey("shift_endworktime")){ + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if(shift_endworktime.length() > 0){ + workEndTime = Util.null2String(shift_endworktime); + workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + workTimeScope.setEndTime(workEndTime); + workTimeScope.setEndTimeAcross(workEndIdx>=1440?true:false); + } + } + } + } + } + Map signMap = getSignInfo(resourceid,signTimeScope,workTimeScope,splitDate,preDate,nextDate,kqTimesArrayComInfo,eventMap,i,result); + if(signMap != null && !signMap.isEmpty()){ + //鐩墠涓澶╁娆℃墦鍗$殑璇濓紝鍙幏鍙栫涓娆″拰鏈鍚庝竴娆℃墦鍗 + lsCheckInfos.add(signMap); + } + } + } + } + } + + if(firstworkDate.length() > 0 && firstworkTime.length() > 0){ + result.put("firstworkDate", firstworkDate); + result.put("firstworkTime", firstworkTime); + } + return result; + } + + public void rePutCheckInfoCutPointMap(Map lsCheckInfoMaps, + KQOvertimeCardBean kqOvertimeBean, String preKey, String key, String pre_cut_point, + String splitDate, Map eventMap, String cut_point, String nextDate, + String nextkey, int has_cut_point, String pre_splitdatetime) { + String preDate = DateUtil.addDate(splitDate, -1); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + String pre_cut_points = pre_cut_point+":00"; + String pre_date_cut_point = splitDate+" "+pre_cut_points; + + String cut_points = cut_point+":00"; + String cur_date_cut_point = nextDate+" "+cut_points; + + String signindate = kqOvertimeBean.getSigninDate(); + String signoutdate = kqOvertimeBean.getSignoutDate(); + String signintime = kqOvertimeBean.getSigninTime(); + String signouttime = kqOvertimeBean.getSignoutTime(); + String signindatetime = kqOvertimeBean.getSigninDate()+" "+kqOvertimeBean.getSigninTime(); + String signoutdatetime = ""; + if(kqOvertimeBean.getSignoutDate().length() > 0 && kqOvertimeBean.getSignoutTime().length() > 0){ + //濡傛灉鏄紤鎭棩鐨勮瘽锛屽彲鑳藉瓨鍦ㄦ病鏈変笂鐝椂闂寸殑鎯呭喌 + signoutdatetime = kqOvertimeBean.getSignoutDate()+" "+kqOvertimeBean.getSignoutTime(); + } + String pre_splittime_date = ""; + String pre_splittime_time = ""; + if(pre_splitdatetime.length() > 0){ + String[] pre_splittimes = pre_splitdatetime.split(" "); + if(pre_splittimes.length == 2){ + pre_splittime_date = pre_splittimes[0]; + pre_splittime_time = pre_splittimes[1]; + } + } + + String timeInfo = "date_cut_point:"+pre_date_cut_point+":signoutdatetime:"+signoutdatetime+":signindatetime:"+signindatetime; + String timeCompare1 = "date_cut_point.compareTo(signoutdatetime):"+pre_date_cut_point.compareTo(signoutdatetime); + String timeCompare2 = "date_cut_point.compareTo(signindatetime):"+pre_date_cut_point.compareTo(signindatetime); + eventMap.put("timeInfo", timeInfo); + eventMap.put("timeCompare1", timeCompare1); + eventMap.put("timeCompare2", timeCompare2); + if(pre_date_cut_point.compareTo(signindatetime) > 0){ + //濡傛灉褰掑睘澶т簬绛惧埌鏃堕棿锛屽皬浜庣閫鏃堕棿锛岃〃绀哄綊灞炰箣鍓嶆槸灞炰簬鍓嶄竴澶╃殑锛屽綊灞炰箣鍚庣殑鏄睘浜庝粖澶╃殑 + //寮鍚簡褰掑睘涔嬪悗锛屽綊灞炵偣涔嬪墠鐨勬墦鍗″氨灞炰簬鍓嶄竴澶╃殑绛鹃鍗′簡锛岀浉褰撲簬鏄粠鍓嶄竴澶╃殑涓嬬彮鏃堕棿鍒拌繖涓崱閮界畻鏄墠涓澶╃殑鍔犵彮鍗★紝鍜屼笉寮褰掑睘鐨勬椂鍊欎笉涓鏍 + KQOvertimeCardBean preKqOvertimeBean = new KQOvertimeCardBean(); + if(pre_splittime_date.length() > 0 && pre_splittime_time.length() > 0){ + preKqOvertimeBean.setSigninDate(pre_splittime_date); + preKqOvertimeBean.setSigninTime(pre_splittime_time); + preKqOvertimeBean.setSignoutDate(signindate); + preKqOvertimeBean.setSignoutTime(signintime); + preKqOvertimeBean.setBelongDate(preDate); + lsCheckInfoMaps.put(preKey, preKqOvertimeBean); + } + if(signoutdatetime.length() > 0 && signoutdatetime.compareTo(pre_date_cut_point) > 0){ + KQOvertimeCardBean curOvertimeBean = new KQOvertimeCardBean(); + curOvertimeBean.setSigninDate(splitDate); + curOvertimeBean.setSigninTime(pre_cut_points); + curOvertimeBean.setSignoutDate(signoutdate); + curOvertimeBean.setSignoutTime(signouttime); + curOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(key, curOvertimeBean); + } + + }else if(signoutdatetime.length() > 0 && pre_date_cut_point.compareTo(signoutdatetime) > 0){ + //濡傛灉褰掑睘澶т簬绛鹃鏃堕棿 琛ㄧず杩欎釜鏃堕棿閮芥槸灞炰簬鍓嶄竴澶╃殑 + lsCheckInfoMaps.put(preKey, kqOvertimeBean); + }else { + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + if(signoutdate.length() > 0){ + if(signoutdate.compareTo(splitDate) > 0){ + if(1 == has_cut_point){ + //濡傛灉绛鹃澶т簬绛惧埌 琛ㄧず鎵撳崱璺ㄥぉ + if(cur_date_cut_point.compareTo(signoutdatetime) < 0){ + String hasSigninDate = signindate; + String hasSigninTime = signintime; + if(lsCheckInfoMaps.containsKey(key)){ + KQOvertimeCardBean hasOvertimeBean = lsCheckInfoMaps.get(key); + hasSigninDate = hasOvertimeBean.getSigninDate(); + hasSigninTime = hasOvertimeBean.getSigninTime(); + } + KQOvertimeCardBean curOvertimeBean = new KQOvertimeCardBean(); + curOvertimeBean.setSigninDate(hasSigninDate); + curOvertimeBean.setSigninTime(hasSigninTime); + curOvertimeBean.setSignoutDate(nextDate); + curOvertimeBean.setSignoutTime(cut_points); + curOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(key, curOvertimeBean); + + KQOvertimeCardBean nextOvertimeBean = new KQOvertimeCardBean(); + nextOvertimeBean.setSigninDate(nextDate); + nextOvertimeBean.setSigninTime(cut_points); + nextOvertimeBean.setSignoutDate(signoutdate); + nextOvertimeBean.setSignoutTime(signouttime); + nextOvertimeBean.setBelongDate(nextDate); + lsCheckInfoMaps.put(nextkey, nextOvertimeBean); + } + } + } + } + } + + + /** + * 閲嶆柊鎶婃墦鍗℃暟鎹寜鐓у綊灞炴潵璧嬪 + * @param lsCheckInfoMaps + * @param kqOvertimeBean + * @param preKey + * @param key + * @param overtime_cut_point + * @param splitDate + * @param eventMap + */ + public void rePutCheckInfoMap(Map lsCheckInfoMaps, + KQOvertimeCardBean kqOvertimeBean, + String preKey, String key, String overtime_cut_point, String splitDate, + Map eventMap){ + + String preDate = DateUtil.addDate(splitDate, -1); + String overtime_cut_points = overtime_cut_point+":00"; + String date_cut_point = splitDate+" "+overtime_cut_points; + String signindate = kqOvertimeBean.getSigninDate(); + String signoutdate = kqOvertimeBean.getSignoutDate(); + String signintime = kqOvertimeBean.getSigninTime(); + String signouttime = kqOvertimeBean.getSignoutTime(); + String signindatetime = kqOvertimeBean.getSigninDate()+" "+kqOvertimeBean.getSigninTime(); + String signoutdatetime = ""; + if(kqOvertimeBean.getSignoutDate().length() > 0 && kqOvertimeBean.getSignoutTime().length() > 0){ + //濡傛灉鏄紤鎭棩鐨勮瘽锛屽彲鑳藉瓨鍦ㄦ病鏈変笂鐝椂闂寸殑鎯呭喌 + signoutdatetime = kqOvertimeBean.getSignoutDate()+" "+kqOvertimeBean.getSignoutTime(); + } + + String timeInfo = "date_cut_point:"+date_cut_point+":signoutdatetime:"+signoutdatetime+":signindatetime:"+signindatetime; + String timeCompare1 = "date_cut_point.compareTo(signoutdatetime):"+date_cut_point.compareTo(signoutdatetime); + String timeCompare2 = "date_cut_point.compareTo(signindatetime):"+date_cut_point.compareTo(signindatetime); + eventMap.put("timeInfo", timeInfo); + eventMap.put("timeCompare1", timeCompare1); + eventMap.put("timeCompare2", timeCompare2); + if(date_cut_point.compareTo(signindatetime) > 0){ + //濡傛灉褰掑睘澶т簬绛惧埌鏃堕棿锛屽皬浜庣閫鏃堕棿锛岃〃绀哄綊灞炰箣鍓嶆槸灞炰簬鍓嶄竴澶╃殑锛屽綊灞炰箣鍚庣殑鏄睘浜庝粖澶╃殑 + //涓嶅紑鍚簡褰掑睘鐨勬椂鍊欙紝鏍规嵁鎵撳崱鐨勬ц川鏉ュ垽鏂紝濡傛灉鏄鍒板崱锛岄偅涔堢鍒版椂闂村埌鍓嶄竴澶╀笂鐝椂闂达紝杩欐鍖洪棿鍐呯畻鏄墠涓澶╃殑鍔犵彮鍗★紝鍜屽紑鍚簡褰掑睘涓嶄竴鏍 + KQOvertimeCardBean preKqOvertimeBean = new KQOvertimeCardBean(); + preKqOvertimeBean.setSigninDate(signindate); + preKqOvertimeBean.setSigninTime(signintime); + preKqOvertimeBean.setSignoutDate(splitDate); + preKqOvertimeBean.setSignoutTime(overtime_cut_points); + preKqOvertimeBean.setBelongDate(preDate); + preKqOvertimeBean.setHas_cut_point("0"); + lsCheckInfoMaps.put(preKey, preKqOvertimeBean); + + if(signoutdatetime.length() > 0 && signoutdatetime.compareTo(date_cut_point) > 0){ + KQOvertimeCardBean curOvertimeBean = new KQOvertimeCardBean(); + curOvertimeBean.setSigninDate(splitDate); + curOvertimeBean.setSigninTime(overtime_cut_points); + curOvertimeBean.setSignoutDate(signoutdate); + curOvertimeBean.setSignoutTime(signouttime); + curOvertimeBean.setBelongDate(splitDate); + curOvertimeBean.setHas_cut_point("0"); + lsCheckInfoMaps.put(key, curOvertimeBean); + } + }else if(signoutdatetime.length() > 0 && date_cut_point.compareTo(signoutdatetime) > 0){ + //濡傛灉褰掑睘澶т簬绛鹃鏃堕棿 琛ㄧず杩欎釜鏃堕棿閮芥槸灞炰簬鍓嶄竴澶╃殑 + lsCheckInfoMaps.put(preKey, kqOvertimeBean); + }else{ + //濡傛灉褰掑睘 灏忎簬绛惧埌鏃堕棿锛屽垯閮藉睘浜庝粖澶 + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + } + + + /** + * 鑾峰彇鍔犵彮娴佺▼鏁版嵁 + * @param resourceid + * @param fromDate + * @param toDate + * @param splitBeanMaps + * @param dateFormatter + */ + private void getOverTimeFlowData(String resourceid, String fromDate, String toDate, + Map> splitBeanMaps, + DateTimeFormatter dateFormatter) { + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate preFromDate = localFromDate.minusDays(1); + LocalDate localToDate = LocalDate.parse(toDate); + long betweenDays = localToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int k = 0; k <= betweenDays; k++) { + LocalDate curLocalDate = preFromDate.plusDays(k); + String splitDate = curLocalDate.format(dateFormatter); + String key = resourceid+"_"+splitDate; + String order_sql = " order by belongdate,fromtime "; + KQFlowDataBiz kqFlowDataBiz = new KQFlowDataBiz.FlowDataParamBuilder().belongDateParam(splitDate).resourceidParam(resourceid).orderby_sqlParam(order_sql).build(); + Map flowMaps = Maps.newHashMap(); + List splitBeans = kqFlowDataBiz.getOverTimeData(flowMaps); + if(!splitBeans.isEmpty()){ + splitBeanMaps.put(key, splitBeans); + } + } + } + + /** + * 鑾峰彇闈炲伐浣滄棩鐨勬墦鍗℃暟鎹 + * @param resourceid + * @param splitDate + * @param preDate + * @param nextDate + * @param curKqOvertimeRulesDetailEntity + * @param eventMap + * @param preKqOvertimeRulesDetailEntity + * @return + */ + private Map getRestSignInfo(String resourceid, String splitDate, String preDate, + String nextDate, + KQOvertimeRulesDetailEntity curKqOvertimeRulesDetailEntity, + Map eventMap, + KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity) { + Map signMap = Maps.newHashMap(); + WorkTimeEntity pre_workTime = new KQWorkTime().getWorkTime(resourceid, preDate); + List pre_lsSignTime = new ArrayList<>(); + + if (pre_workTime != null) { + pre_lsSignTime = pre_workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + pre_lsSignTime = pre_lsSignTime != null ? pre_lsSignTime : new ArrayList<>(); + } + WorkTimeEntity next_workTime = new KQWorkTime().getWorkTime(resourceid, nextDate); + List next_lsSignTime = new ArrayList<>(); + + if (next_workTime != null) { + next_lsSignTime = next_workTime.getSignTime();//鍏佽鎵撳崱鏃堕棿 + next_lsSignTime = next_lsSignTime != null ? next_lsSignTime : new ArrayList<>(); + } + + signMap = getNonWorkSignInfo(resourceid,nextDate,splitDate,pre_lsSignTime,next_lsSignTime,curKqOvertimeRulesDetailEntity,eventMap,preKqOvertimeRulesDetailEntity); + + return signMap; + } + + + /** + * 鑾峰彇闈炲伐浣滄棩鐨勬墦鍗℃暟鎹 灏佽澶勭悊涓 + * @param resourceid + * @param nextDate + * @param kqDate + * @param pre_lsSignTime + * @param next_lsSignTime + * @param curKqOvertimeRulesDetailEntity + * @param eventMap + * @param preKqOvertimeRulesDetailEntity + * @return + */ + public Map getNonWorkSignInfo(String resourceid, String nextDate, String kqDate, + List pre_lsSignTime, + List next_lsSignTime, + KQOvertimeRulesDetailEntity curKqOvertimeRulesDetailEntity, + Map eventMap, + KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity) { + Map signMap = Maps.newHashMap(); + KQFormatSignData kqFormatSignData = new KQFormatSignData(); + List lsCheckInfo = new ArrayList<>(); + Map checkInfo = null; + RecordSet rs = new RecordSet(); + String pre_Worktime4Today = ""; + if(!pre_lsSignTime.isEmpty()){ + TimeScopeEntity pre_signTimeScope = pre_lsSignTime.get(pre_lsSignTime.size()-1); + if(pre_signTimeScope.getEndTimeAcross()){ + pre_Worktime4Today = pre_signTimeScope.getEndTime(); + } + } + String next_Worktime4Today = ""; + if(!next_lsSignTime.isEmpty()){ + TimeScopeEntity next_signTimeScope = next_lsSignTime.get(next_lsSignTime.size()-1); + if(next_signTimeScope.isBeginTimePreAcross()){ + next_Worktime4Today = next_signTimeScope.getBeginTime(); + } + } + String signBeginDateTime = kqDate+" 00:00:00"; + String signEndDateTime = kqDate+" 23:59:59"; + //鏈夎繖涔堜竴绉嶆儏鍐碉紝姣斿鍓嶄竴澶╂槸宸ヤ綔鏃ワ紝鏈鏅氱閫鏄2鐐癸紝鐒跺悗宸ヤ綔鏃ョ殑褰掑睘鏄缃殑5鐐癸紝閭d箞濡傛灉4鐐规墦涓涓崱鐨勮瘽锛屽叾瀹炴槸闇瑕佺敓鎴愬姞鐝殑锛屽洜涓4甯︿綘杩欎釜鍗℃槸鏄ㄦ棩鐨勭閫 + String ore_signBeginDateTime = signBeginDateTime; + String base_sql = kqFormatSignData.signSignSql(rs); + + int pre_has_cut_point = preKqOvertimeRulesDetailEntity != null ? preKqOvertimeRulesDetailEntity.getHas_cut_point() : 0; + + if(pre_Worktime4Today.length() > 0){ + if(pre_has_cut_point == 1){ + String cut_point = Util.null2String(preKqOvertimeRulesDetailEntity.getCut_point()); + if(cut_point.length() > 0){ + if(cut_point.compareTo(pre_Worktime4Today) > 0){ + pre_Worktime4Today = cut_point; + }else{ + if(pre_Worktime4Today.length() == 5){ + pre_Worktime4Today += ":00"; + } + ore_signBeginDateTime = kqDate+" "+pre_Worktime4Today; + } + } + } + if(pre_Worktime4Today.length() == 5){ + pre_Worktime4Today += ":00"; + } + signBeginDateTime = kqDate+" "+pre_Worktime4Today; + }else{ + if(pre_has_cut_point == 1){ + String cut_point = Util.null2String(preKqOvertimeRulesDetailEntity.getCut_point()); + if(cut_point.length() > 0){ + String cut_point_time = kqDate+" "+cut_point+":00"; + signBeginDateTime = cut_point_time; + } + } + } + if(next_Worktime4Today.length() > 0){ + if(next_Worktime4Today.length() == 5){ + next_Worktime4Today += ":00"; + } + signEndDateTime = kqDate+" "+next_Worktime4Today; + }else{ + if(curKqOvertimeRulesDetailEntity != null){ + int cur_has_cut_point = curKqOvertimeRulesDetailEntity.getHas_cut_point(); + if(cur_has_cut_point == 1){ + String cut_point = Util.null2String(curKqOvertimeRulesDetailEntity.getCut_point()); + if(cut_point.length() > 0){ + String cut_point_time = nextDate+" "+cut_point+":00"; + signEndDateTime = cut_point_time; + } + } + } + } + String sql = "select * from ("+base_sql+") a "+" order by signdate asc,signtime asc "; + rs.executeQuery(sql,resourceid,signBeginDateTime,signEndDateTime); + String nonwork_card_sql = "sql:"+sql+"|resourceid|"+resourceid+"|signBeginDateTime|"+signBeginDateTime+"|signEndDateTime|"+signEndDateTime; + eventMap.put("闈炲伐浣滄棩鎵撳崱sql|nonwork_card_sql", nonwork_card_sql); + eventMap.put("闈炲伐浣滄棩鎵撳崱sql缁撴灉|nonwork_card_sql_getCounts", rs.getCounts()); + int idx = 0; + while (rs.next()){ + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + idx++; + if(idx==1){//绗竴鏉$畻绛惧埌 + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + }else if(idx==rs.getCounts()){//鏈鍚庝竴鏉$畻绛鹃 + checkInfo.put("signType", "2"); + lsCheckInfo.add(checkInfo); + } + } + if(lsCheckInfo != null && !lsCheckInfo.isEmpty()){ + if(lsCheckInfo.size() == 2){ + Map begin_signMap = (Map) lsCheckInfo.get(0); + Map end_signMap = (Map) lsCheckInfo.get(lsCheckInfo.size()-1); + signMap.put("signindate", begin_signMap.get("signDate")); + signMap.put("signintime", begin_signMap.get("signTime")); + signMap.put("signoutdate", end_signMap.get("signDate")); + signMap.put("signouttime", end_signMap.get("signTime")); + }else if(lsCheckInfo.size() == 1){ + Map begin_signMap = (Map) lsCheckInfo.get(0); + signMap.put("signindate", begin_signMap.get("signDate")); + signMap.put("signintime", begin_signMap.get("signTime")); + } + }else{ + if(pre_has_cut_point == 1){ + sql = "select * from ("+base_sql+") a "+" order by signdate asc,signtime asc "; + rs.executeQuery(sql,resourceid,ore_signBeginDateTime,signEndDateTime); + nonwork_card_sql = "sql:"+sql+"|resourceid|"+resourceid+"|ore_signBeginDateTime|"+ore_signBeginDateTime+"|signEndDateTime|"+signEndDateTime; + eventMap.put("鏄ㄦ棩寮鍚簡鎵撳崱褰掑睘锛岄潪宸ヤ綔鏃ユ墦鍗ql|nonwork_card_sql", nonwork_card_sql); + eventMap.put("鏄ㄦ棩寮鍚簡鎵撳崱褰掑睘锛岄潪宸ヤ綔鏃ユ墦鍗ql缁撴灉|nonwork_card_sql_getCounts", rs.getCounts()); + idx = 0; + while (rs.next()){ + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + idx++; + if(idx==1){//绗竴鏉$畻绛惧埌 + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + }else if(idx==rs.getCounts()){//鏈鍚庝竴鏉$畻绛鹃 + checkInfo.put("signType", "2"); + lsCheckInfo.add(checkInfo); + } + } + if(lsCheckInfo != null && !lsCheckInfo.isEmpty()){ + //杩欑鎯呭喌涓嬶紝灏卞彧鏄妸绛惧埌鍗′紶鍥炲幓浣滀负鍓嶄竴澶╃殑绛鹃浜 + Map begin_signMap = (Map) lsCheckInfo.get(0); + signMap.put("signindate", begin_signMap.get("signDate")); + signMap.put("signintime", begin_signMap.get("signTime")); + } + } + } + return signMap; + } + /** + * 鑾峰彇宸ヤ綔鏃ョ殑鎵撳崱鏁版嵁 + * @param userId + * @param signTimeScope + * @param workTimeScope + * @param kqDate + * @param preDate + * @param nextDate + * @param kqTimesArrayComInfo + * @param eventMap + * @param index + * @param result + * @return + */ + public Map getSignInfo(String userId, TimeScopeEntity signTimeScope, + TimeScopeEntity workTimeScope, String kqDate, String preDate, + String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo,Map eventMap, + int index,Map result) { + Map signMap = Maps.newHashMap(); + KQFormatSignData kqFormatSignData = new KQFormatSignData(); + List lsCheckInfo = new ArrayList<>(); + Map checkInfo = null; + String base_sql = ""; + RecordSet rs = new RecordSet(); + String dbtype = rs.getDBType(); + + int has_cut_point = Util.getIntValue(Util.null2String(result.get("has_cut_point"))); + String cut_point = Util.null2String(result.get("cut_point")); + + int pre_has_cut_point = Util.getIntValue(Util.null2String(result.get("pre_has_cut_point"))); + String pre_cut_point = Util.null2String(result.get("pre_cut_point")); + int lsWorkTime_size = Util.getIntValue(Util.null2String(result.get("lsWorkTime_size"))); + + //娴佺▼鎶垫墸鎵撳崱涓嶅鐞 + Map flow_deduct_card_map = Maps.newHashMap(); + + List> sqlConditions = kqFormatSignData.getCanSignInfo(signTimeScope,kqDate,preDate,nextDate,kqTimesArrayComInfo); + base_sql = kqFormatSignData.signSignSql(rs); + + if(sqlConditions != null && !sqlConditions.isEmpty()){ + for (int i = 0; i < sqlConditions.size(); i++) { + Map sqlMap = sqlConditions.get(i); + String sql = ""; + String orderSql = ""; + int idx = 0; + String signBeginDateTime = Util.null2String(sqlMap.get("signBeginDateTime")); + String signEndDateTime = Util.null2String(sqlMap.get("signEndDateTime")); + if(index == lsWorkTime_size-1 && i == sqlConditions.size()-1){ + //鏈鍚庝竴娆$殑鎵撳崱鑼冨洿浼氳鎵撳崱涓寸晫鐐圭粰淇敼 + if(has_cut_point == 1){ + String cut_point_datettime = nextDate+" "+cut_point+":59"; + signEndDateTime = cut_point_datettime; + } + } + if(index == 0 && i == 0){ + //绗竴娆$殑鎵撳崱鑼冨洿浼氳鎵撳崱涓寸晫鐐圭粰淇敼 + if(pre_has_cut_point == 1){ + String cut_point_datettime = kqDate+" "+pre_cut_point+":00"; + signBeginDateTime = cut_point_datettime; + } + } + String type = Util.null2String(sqlMap.get("type")); + if(type.length() > 0){ + if("signoff".equalsIgnoreCase(type)){ + orderSql = " order by signdate desc, signtime desc "; + }else if("signin".equalsIgnoreCase(type)){ + orderSql = " order by signdate asc, signtime asc "; + } + if("oracle".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1"; + }else if("mysql".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a limit 0,1"; + } + else if("postgresql".equalsIgnoreCase(dbtype)){ + sql = "select * from ("+base_sql+" "+orderSql+") a limit 1 offset 0"; + } + else if("sqlserver".equalsIgnoreCase(dbtype)){ + sql = "select top 1 * from ("+base_sql+") a "+" "+orderSql; + }else{ + sql = "select * from ("+base_sql+" "+orderSql+") a where rownum=1"; + } + }else{ + orderSql = " order by signdate asc, signtime asc "; + sql = base_sql+" "+orderSql; + } + rs.executeQuery(sql, userId, signBeginDateTime, signEndDateTime); + String work_card_sql = "index:"+index+":idx:"+idx+"|sql:"+sql+"|resourceid|"+userId+"|signBeginDateTime|"+signBeginDateTime+"|signEndDateTime|"+signEndDateTime; + + eventMap.put("宸ヤ綔鏃ユ墦鍗ql|work_card_sql_"+index, work_card_sql); + eventMap.put("宸ヤ綔鏃ユ墦鍗ql缁撴灉|work_card_sql_getCounts_"+index, rs.getCounts()); + while (rs.next()) { + String signId = Util.null2String(rs.getString("id")); + String signdate = Util.null2String(rs.getString("signdate")); + String signtime = Util.null2String(rs.getString("signtime")); + + checkInfo = new HashMap<>(); + checkInfo.put("signId", signId);//绛惧埌绛鹃鏍囪瘑 + checkInfo.put("signDate", signdate);//绛惧埌绛鹃鏃ユ湡 + checkInfo.put("signTime", signtime);//绛惧埌绛鹃鏃堕棿 + checkInfo.put("type", type);//鏄惁鏈夋墦鍗″綊灞,type鏈夊煎氨鏄湁鎵撳崱褰掑睘 + idx++; + if(type.length() > 0){ + if("signin".equalsIgnoreCase(type)){ + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + }else { + checkInfo.put("signType", "2"); + lsCheckInfo.add(checkInfo); + } + }else{ + if(idx==1){//绗竴鏉$畻绛惧埌 + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + }else if(idx==rs.getCounts()){//鏈鍚庝竴鏉$畻绛鹃 + checkInfo.put("signType", "2"); + lsCheckInfo.add(checkInfo); + } + } + } + } + } + if(lsCheckInfo != null && !lsCheckInfo.isEmpty()){ + if(lsCheckInfo.size() == 1){ + Map checkInfoMap = (Map) lsCheckInfo.get(0); + String type = Util.null2String(checkInfoMap.get("type")); + if("signin".equalsIgnoreCase(type)){ + signMap.put("signindate", checkInfoMap.get("signDate")); + signMap.put("signintime", checkInfoMap.get("signTime")); + signMap.put("signoutdate", workTimeScope.getBeginTimeAcross()?nextDate:kqDate); + signMap.put("signouttime", workTimeScope.getBeginTime()+":00"); + }else if("signoff".equalsIgnoreCase(type)){ + signMap.put("signindate", workTimeScope.getEndTimeAcross()?nextDate:kqDate); + signMap.put("signintime", workTimeScope.getEndTime()+":00"); + signMap.put("signoutdate", checkInfoMap.get("signDate")); + signMap.put("signouttime", checkInfoMap.get("signTime")); + }else{ + signMap.put("signindate", checkInfoMap.get("signDate")); + signMap.put("signintime", checkInfoMap.get("signTime")); + signMap.put("signoutdate", workTimeScope.getBeginTimeAcross()?nextDate:kqDate); + signMap.put("signouttime", workTimeScope.getBeginTime()+":00"); + } + }else{ + Map begin_signMap = (Map) lsCheckInfo.get(0); + Map end_signMap = (Map) lsCheckInfo.get(lsCheckInfo.size()-1); + signMap.put("signindate", begin_signMap.get("signDate")); + signMap.put("signintime", begin_signMap.get("signTime")); + signMap.put("signoutdate", end_signMap.get("signDate")); + signMap.put("signouttime", end_signMap.get("signTime")); + } + } + return signMap; + } + + /** + * 鑾峰彇宸茬粡鐢熸垚杩囩殑鍔犵彮鏁版嵁 + * @param resourceid + * @param belongdate + * @param hasOverTimeList + */ + private void getHasOverTimeData(String resourceid, String belongdate,List> hasOverTimeList) { + RecordSet rs = new RecordSet(); + + String sql = " select * from kq_flow_overtime where resourceid = ? and belongdate = ? "; + rs.executeQuery(sql,resourceid,belongdate); + while (rs.next()){ + String requestid =rs.getString("requestid"); + String fromdate =rs.getString("fromdate"); + String fromtime =rs.getString("fromtime"); + String todate =rs.getString("todate"); + String totime =rs.getString("totime"); + String duration_min =Util.null2String(rs.getString("duration_min")); + String flow_dataid =Util.null2String(rs.getString("flow_dataid")); + String ori_belongdate =Util.null2String(rs.getString("ori_belongdate")); + //娴佺▼+鎵撳崱鐨勬椂鍊欙紝瀛樼殑瀵瑰簲鐨勬祦绋嬫暟鎹 + String fromdate_flow =rs.getString("fromdatedb"); + String fromtime_flow =rs.getString("fromtimedb"); + String todate_flow =rs.getString("todatedb"); + String totime_flow =rs.getString("totimedb"); + Map hasOverTimeMap = Maps.newHashMap(); + hasOverTimeMap.put("resourceid", resourceid); + hasOverTimeMap.put("belongdate", belongdate); + hasOverTimeMap.put("requestid", requestid); + hasOverTimeMap.put("fromdate", fromdate); + hasOverTimeMap.put("fromtime", fromtime); + hasOverTimeMap.put("todate", todate); + hasOverTimeMap.put("totime", totime); + hasOverTimeMap.put("fromdate_flow", fromdate_flow); + hasOverTimeMap.put("fromtime_flow", fromtime_flow); + hasOverTimeMap.put("todate_flow", todate_flow); + hasOverTimeMap.put("totime_flow", totime_flow); + hasOverTimeMap.put("duration_min", duration_min); + hasOverTimeMap.put("flow_dataid", flow_dataid); + hasOverTimeMap.put("ori_belongdate", ori_belongdate); + + hasOverTimeList.add(hasOverTimeMap); + } + } + + /** + * 鏍规嵁浜哄拰鏃ユ湡鑾峰彇鍔犵彮瑙勫垯閲岀殑淇℃伅 + * @param resourceid + * @param fromDate + * @param toDate + * @param dateFormatter + * @param changeTypeMap + * @param overRulesDetailMap + * @param restTimeMap + * @param computingModeMap + */ + public void getOverTimeDataMap(String resourceid, String fromDate, String toDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap,Map> restTimeMap,Map computingModeMap){ + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + LocalDate preFromDate = localFromDate.minusDays(2); + LocalDate nextToDate = localToDate.plusDays(1); + long betweenDays = nextToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + LocalDate curLocalDate = preFromDate.plusDays(i); + String splitDate = curLocalDate.format(dateFormatter); + KQOvertimeRulesBiz.getOverTimeData(resourceid, splitDate,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap); + } + } + + public void logOvertimeMap(Map overtimeLogMap,Object params, String keys){ + if(overtimeLogMap != null){ + overtimeLogMap.put(keys, params); + } + } + + /** + * 鏍规嵁鍔犵彮瑙勫垯璁剧疆锛屽垎娈佃幏鍙栨瘡涓娈电殑鍔犵彮鏃堕暱 + * @param resourceId + * @param fromdate + * @param fromtime + * @param todate + * @param totime + * @param changeTypeMap + * @param kqOvertimeRulesDetailEntity + * @param splitBean + * @param restTimeMap + * @param overRulesDetailMap + */ + public List getOvertimeBalanceTimeBean(String resourceId, + String fromdate, String fromtime, String todate, String totime, + Map changeTypeMap, + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, SplitBean splitBean, + Map> restTimeMap, + Map overRulesDetailMap){ + KQOverTimeFlowBiz kqOverTimeFlowBiz = new KQOverTimeFlowBiz(); + KQTimesArrayComInfo kqTimesArrayComInfo= new KQTimesArrayComInfo(); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + boolean shouldAcross = false; + int before_startTime = -1; + int startTime = 0; + String change_key = fromdate+"_"+resourceId; + int changeType = Util.getIntValue(""+changeTypeMap.get(change_key),-1); + String changeType_key = fromdate+"_"+changeType; + + String nextSplitDate = DateUtil.addDate(fromdate,1); + String next_change_key = nextSplitDate+"_"+resourceId; + int next_changeType = Util.getIntValue(""+changeTypeMap.get(next_change_key),-1); + String nextChangeType_key = nextSplitDate+"_"+next_changeType; + + String next_beginwork_time = ""; + String serialid = ""; + //闇瑕佺煡閬撴槑鏃ョ殑绫诲瀷:濡傛灉浠婂ぉ鏄伐浣滄棩鐨勮瘽锛岄偅涔堜粖澶╃殑鍔犵彮涓寸晫鐐瑰彲鑳藉拰鏄庢棩鐨勪笂鐝椂闂村啿绐侊紝闇瑕佺煡閬撴槑鏃ョ殑涓婄彮鏃堕棿杩涜姣旇緝锛 + // 濡傛灉浠婂ぉ鏄紤鎭棩锛岄偅涔堟槑澶╁鏋滄槸宸ヤ綔鏃ョ殑璇濓紝榛樿瑙勫垯涓嬶紝鏄庡ぉ鐨勪笂鐝墠閮芥槸灞炰簬浠婂ぉ鐨勫姞鐝尯闂 + if(next_changeType == 2){ + ShiftInfoBean next_shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceId, nextSplitDate, false); + if(next_shiftInfoBean != null){ + List workLongTimeIndex = next_shiftInfoBean.getWorkLongTimeIndex(); + List real_workLongTimeIndex = Lists.newArrayList(); + kqOverTimeFlowBiz.get_real_workLongTimeIndex(workLongTimeIndex,real_workLongTimeIndex,next_shiftInfoBean,kqTimesArrayComInfo,splitBean); + + if(real_workLongTimeIndex != null && !real_workLongTimeIndex.isEmpty()){ + next_beginwork_time = kqTimesArrayComInfo.getTimesByArrayindex(real_workLongTimeIndex.get(0)[0]); + } + } + } + + int fromTime_index = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + int toTime_index = kqTimesArrayComInfo.getArrayindexByTimes(totime); + Arrays.fill(initArrays, fromTime_index, toTime_index, 0); + if(changeType == 1){ + kqOverTimeFlowBiz.handle_changeType_1(initArrays, overRulesDetailMap, nextChangeType_key, + next_changeType, next_beginwork_time); + }else if(changeType == 2){ + if(kqOvertimeRulesDetailEntity != null){ + before_startTime = kqOvertimeRulesDetailEntity.getBefore_startTime(); + int has_cut_point = kqOvertimeRulesDetailEntity.getHas_cut_point(); + if(has_cut_point != 1){ + before_startTime = -1; + } + startTime = kqOvertimeRulesDetailEntity.getStartTime(); + } + boolean isok = kqOverTimeFlowBiz.handle_changeType_2(initArrays, resourceId, fromdate, before_startTime, startTime, fromTime_index, + kqTimesArrayComInfo, splitBean,toTime_index); + }else if(changeType == 3){ + kqOverTimeFlowBiz.handle_changeType_3(initArrays, overRulesDetailMap, nextChangeType_key, + next_changeType, next_beginwork_time); + } + int restTimeType = -1; + if(kqOvertimeRulesDetailEntity != null){ + restTimeType = kqOvertimeRulesDetailEntity.getRestTimeType(); + } + if(restTimeType == 1){ + //濡傛灉鎺掗櫎璁剧疆鐨勪紤鎭椂闂 + kqOverTimeFlowBiz.handle_resttime(restTimeMap,changeType_key,kqTimesArrayComInfo,shouldAcross,initArrays); + } + // 鎸夌収鍔犵彮鏃堕暱杞皟浼戠殑 鏃堕暱璁剧疆 + List timepointList = null; + List overtimeBalanceTimeBeans = Lists.newArrayList(); + if(kqOvertimeRulesDetailEntity != null){ + timepointList = kqOverTimeRuleCalBiz.get_timepointList(kqOvertimeRulesDetailEntity); + } + + if(timepointList != null && !timepointList.isEmpty()){ + kqOverTimeRuleCalBiz.get_overtimeBalanceTimeBeans(timepointList,overtimeBalanceTimeBeans,kqTimesArrayComInfo,initArrays,toTime_index,fromTime_index,0); + } + + return overtimeBalanceTimeBeans; + } + + /** + * 鍒ゆ柇鏄惁寮鍚簡璋冧紤鐨 鎸夌収鏃堕棿鐐瑰垎娈电敓鎴愯皟浼 + * @param kqOvertimeRulesDetailEntity + * @param paidLeaveEnable + * @return + */ + public boolean getNeedSplitByTime(KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, + int paidLeaveEnable) { + //鍥犱负銆愭寜鍔犵彮鏃堕暱鑼冨洿璁剧疆杞皟浼戞椂闀块棶棰樸戣繖涓柟寮忓瓨鍦ㄩ棶棰橈紝鏆備笉浣跨敤 + if(true){ + return false; + } + boolean needSplitByTime = false; + if(paidLeaveEnable == 1){ + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + //濡傛灉寮鍚簡杞皟浼戯紝骞朵笖璋冧紤鏄垎娈垫姌绠楃殑锛屽彲浠ユ寜鐓у垎娈垫潵鏄剧ず鍔犵彮 + if(1 == paidLeaveEnableType){ + int paidLeaveEnableDefaultType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableDefaultType(); + if(paidLeaveEnableDefaultType == 3){ + needSplitByTime = true; + } + }else if(2 == paidLeaveEnableType){ + int paidLeaveEnableFlowType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableFlowType(); + if(paidLeaveEnableFlowType == 3){ + needSplitByTime = true; + } + } + } + return needSplitByTime; + } + + /** + * 鍒ゆ柇鏄惁寮鍚簡璋冧紤 + * @param kqOvertimeRulesDetailEntity + * @param overtime_type + * @return + */ + public int getPaidLeaveEnable(KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, + String overtime_type) { + int paidLeaveEnable = -1; + if (kqOvertimeRulesDetailEntity != null){ + paidLeaveEnable = kqOvertimeRulesDetailEntity.getPaidLeaveEnable(); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + } + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if(2 == paidLeaveEnableType){ +// logOvertimeMap(overtimeLogMap, overtime_type, flow_cross_key+"|鍏宠仈璋冧紤涓庡惁鏉ヨ嚜浜庢祦绋嬮夋嫨,鍔犵彮绫诲瀷涓嬫媺妗嗗紎overtime_type"); + if("0".equalsIgnoreCase(overtime_type)){ + paidLeaveEnable = 1; + }else if("1".equalsIgnoreCase(overtime_type)){ + paidLeaveEnable = 0; + }else{ + paidLeaveEnable = 0; + } + } + return paidLeaveEnable; + } + + + /** + * 娓呮帀涔嬪墠鐨勫姞鐝拰璋冧紤锛岄噸鏂扮敓鎴 + * @param resourceid + * @param belongdate + * @param overtimeLogMap + * @param splitDate + */ + public void clearOvertimeTX(String resourceid, String belongdate, + Map overtimeLogMap, String splitDate) { + List all_tiaoxiuidList = Lists.newArrayList(); + String all_tiaoxiuids = ""; + RecordSet rs = new RecordSet(); + String sql = "select * from kq_flow_overtime where resourceid = ? and belongdate=? and ori_belongdate=? "; + rs.executeQuery(sql,resourceid, belongdate,splitDate); + while (rs.next()){ + String tiaoxiuid = Util.null2String(rs.getString("tiaoxiuid"),""); + if(tiaoxiuid.length() > 0 && Util.getIntValue(tiaoxiuid) > 0){ + all_tiaoxiuids += ","+tiaoxiuid; + all_tiaoxiuidList.add(tiaoxiuid); + } + } + logOvertimeMap(overtimeLogMap, all_tiaoxiuids, "闇瑕侀噸鏂扮敓鎴愮殑璋冧紤|all_tiaoxiuids"); + if(all_tiaoxiuids.length() > 0){ + all_tiaoxiuids = all_tiaoxiuids.substring(1); + + Map tiaoxiuamountMap = Maps.newLinkedHashMap(); + String selSql = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in"); + rs.executeQuery(selSql); + while (rs.next()){ + String id = rs.getString("id"); + String tiaoxiuamount = rs.getString("tiaoxiuamount"); + tiaoxiuamountMap.put(id, tiaoxiuamount); + } + if(!tiaoxiuamountMap.isEmpty()){ + logOvertimeMap(overtimeLogMap, tiaoxiuamountMap, "鍏堣褰曚笅涔嬪墠鐨勫姞鐝敓鎴愮殑璋冧紤鏁版嵁|tiaoxiuamountMap"); + } + String tiaoxiuidis0 = ""; + String delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " baseamount =0 and extraamount=0 and usedamount=0 and baseamount2=0 and extraamount2=0 and usedamount2=0 "; + if(rs.getDBType().equalsIgnoreCase("oracle")) { + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " nvl(baseamount,0) =0 and nvl(extraamount,0)=0 and nvl(usedamount,0)=0 and nvl(baseamount2,0)=0 " + + " and nvl(extraamount2,0)=0 and nvl(usedamount2,0)=0 "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " ifnull(baseamount,0) =0 and ifnull(extraamount,0)=0 and ifnull(usedamount,0)=0 and ifnull(baseamount2,0)=0 " + + " and ifnull(extraamount2,0)=0 and ifnull(usedamount2,0)=0 "; + }else { + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " isnull(baseamount,0) =0 and isnull(extraamount,0)=0 and isnull(usedamount,0)=0 and isnull(baseamount2,0)=0 " + + " and isnull(extraamount2,0)=0 and isnull(usedamount2,0)=0 "; + } + rs.executeQuery(delSql0); + while (rs.next()){ + String tiaoxiuid = Util.null2String(rs.getString("id"),""); + if(tiaoxiuid.length() > 0 && Util.getIntValue(tiaoxiuid) > 0){ + tiaoxiuidis0 += ","+tiaoxiuid; + all_tiaoxiuidList.remove(tiaoxiuid); + } + } + String delSql = ""; + if(tiaoxiuidis0.length() > 0){ + delSql = "delete from kq_balanceofleave where "+Util.getSubINClause(tiaoxiuidis0, "id", "in"); + rs.executeUpdate(delSql); + } + String clearSql = ""; + boolean isclearOk = false; + if(!all_tiaoxiuidList.isEmpty()){ + String clear_tiaoxiuids = all_tiaoxiuidList.stream().collect(Collectors.joining(",")); + clearSql = "update kq_balanceofleave set tiaoxiuamount=0.0 where "+Util.getSubINClause(clear_tiaoxiuids, "id", "in"); + isclearOk = rs.executeUpdate(clearSql); + } + + String delUsageSql = "delete from kq_usagehistory where "+Util.getSubINClause(all_tiaoxiuids, "balanceofleaveid", "in"); + boolean isdelUsageOk = rs.executeUpdate(delUsageSql); + Map logSqlMap = Maps.newLinkedHashMap(); + logSqlMap.put("tiaoxiuidis0",tiaoxiuidis0); + logSqlMap.put("all_tiaoxiuidList",all_tiaoxiuidList); + logSqlMap.put("delSql",delSql); + logSqlMap.put("clearSql",clearSql); + logSqlMap.put("isclearOk",isclearOk); + logSqlMap.put("delUsageSql",delUsageSql); + logSqlMap.put("isdelUsageOk",isdelUsageOk); + logOvertimeMap(overtimeLogMap, logSqlMap, "闇瑕侀噸鏂扮敓鎴愮殑璋冧紤瀵瑰簲鐨勪俊鎭瘄logSqlMap"); + } + String delSql = "delete from kq_flow_overtime where resourceid = ? and belongdate=? and ori_belongdate=? "; + boolean isDelOk = rs.executeUpdate(delSql,resourceid, belongdate,splitDate); + String delSqlLog = delSql+":resourceid:"+resourceid+":belongdate:"+belongdate+":splitDate:"+splitDate+":isDelOk:"+isDelOk; + logOvertimeMap(overtimeLogMap, delSqlLog, "鍒犻櫎鍔犵彮涓棿琛ㄦ暟鎹畖delSql"); + + } + /** + * 鍔犵彮鍗曚綅 + * @param d_mins + * @return + */ + public double getD_MinsByUnit(double d_mins) { + Map map = KQOvertimeRulesBiz.getMinimumUnitAndConversion(); + if(!map.isEmpty()){ + double conversionMins = 0.0; + int minimumUnit = Util.getIntValue(Util.null2String(map.get("minimumUnit")),-1); + int overtimeConversion = Util.getIntValue(Util.null2String(map.get("overtimeConversion")),-1); + if(5 == minimumUnit || 6 == minimumUnit){ + int halfHourInt = 30; + int wholeHourInt = 60; + if(5 == minimumUnit){ + conversionMins = getConversionMins(halfHourInt,d_mins,overtimeConversion); + }else { + conversionMins = getConversionMins(wholeHourInt,d_mins,overtimeConversion); + } + return conversionMins; + } + } + return d_mins; + } + + /** + * 鏍规嵁杞崲瑙勫垯寰楀埌杞崲鍚庣殑鍔犵彮鏃堕暱 + * @param halfHourInt + * @param d_mins + * @param overtimeConversion + * @return + */ + public double getConversionMins(int halfHourInt, double d_mins, int overtimeConversion) { + double conversionMins = 0.0; + int step = (int) (d_mins/halfHourInt); + double leftMins = d_mins - halfHourInt*step; + //鍗婂皬鏃 + if(1 == overtimeConversion){ +// 鍥涜垗浜斿叆 + if(leftMins >= halfHourInt/2){ + conversionMins = halfHourInt*step+halfHourInt; + }else{ + conversionMins = halfHourInt*step; + } + }else if(2 == overtimeConversion){ +// 鍚戜笂鍙栨暣 + if(leftMins > 0){ + conversionMins = halfHourInt*step+halfHourInt; + }else{ + conversionMins = halfHourInt*step; + } + }else if(3 == overtimeConversion){ +// 鍚戜笅鍙栨暣 + if(leftMins < halfHourInt){ + conversionMins = halfHourInt*step; + }else{ + conversionMins = halfHourInt*step; + } + } + return conversionMins; + } + + /** + * 鏍规嵁 requestid 鑾峰彇琛ㄥ崟鍚 + * + * @param requestid 璇锋眰ID + * @param num 涓昏〃锛0 鏄庣粏锛1,2,3 + * @return 琛ㄥ悕 + */ + public String getTableNameByRequestid(String requestid, String num) { + String tableName = ""; + String table = ""; + RecordSet rs = new RecordSet(); + rs.execute( + "select t1.tablename from workflow_bill t1,workflow_base t2,workflow_requestbase t3 \n where t1.id =t2.formid and t2.id = t3.workflowid and t3.requestid = " + + + requestid); + if (rs.next()) { + table = com.weaver.general.Util.null2String(rs.getString("tablename")); + if (num.equals("0")) { + tableName = table; + } else { + tableName = table + "_dt" + num; + } + } + return tableName; + } + + /** + * 鑾峰彇鍔犵彮娴佺▼鍔犵彮鎬ц川 + * @param reqid + * @param tablename + * @return + */ + public String findjbxz(String reqid,String tablename){ + RecordSet rs = new RecordSet(); + String jbxz = ""; + String sql = "select jbxz from "+tablename+" where requestId = "+reqid; + rs.executeQuery(sql); + if(rs.next()){ + jbxz = Util.null2String(rs.getString("jbxz")); + } + return jbxz; + } + + + /** + * 鑾峰彇鍔犵彮娴佺▼琛ュ伩鏂瑰紡 + * @param reqid + * @param tablename + * @return + */ + public String findbcfs(String reqid,String tablename){ + RecordSet rs = new RecordSet(); + String bcfs = ""; + String sql = "select bcfs from "+tablename+" where requestId = "+reqid; + rs.executeQuery(sql); + if(rs.next()){ + bcfs = Util.null2String(rs.getString("bcfs")); + } + return bcfs; + } + + /** + * 鑾峰彇鍔犵彮娴佺▼浜嬬敱 + * @param reqid + * @param tablename + * @return + */ + public String findsqsy(String reqid,String tablename){ + RecordSet rs = new RecordSet(); + String sqsy = ""; + String sql = "select sqsy from "+tablename+" where requestId = "+reqid; + rs.executeQuery(sql); + if(rs.next()){ + sqsy = Util.null2String(rs.getString("sqsy")); + } + return sqsy; + } + + /** + * 鍗婂皬鏃惰浆鎹 + * @param value + * @return + */ + public static Integer changeBxs(Integer value){ + return (value / 30)*30 ; + } + + /** + * 1灏忔椂杞崲 + * @param value + * @return + */ + public static Integer changeyxs(Integer value){ + return (value / 60)*60 ; + } + + /** + * 鍔犵彮鍙拌处鏁版嵁鍐欏叆 + */ + public static void insertJbtz(String jbr, String gjsc, String sqr, String jbxz, String bcfs, String zzdksj, String zwdkrq, String ly, String jblx, String ksrq, String jsrq, String sqsy, String kssj, String jssj, String gsrq, String searIdFrom, RecordSet singleRs){ + RecordSet rs = new RecordSet(); + String idNew = "1"; + int modeid = getFormModeIdByCubeName("uf_jbtz"); + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss"); + String modedatacreatedate = sdfDate.format(new Date()); + String modedatacreatetime = sdfTime.format(new Date()); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String bm = resourceComInfo.getDepartmentID(jbr); + String szbm = resourceComInfo.getDepartmentID(sqr); + String sjh = resourceComInfo.getTelephone(jbr); + String gh = resourceComInfo.getWorkcode(jbr); + String zw = resourceComInfo.getJobActivityDesc(jbr); + Double sc = divide(gjsc,"60"); + String jblxNew = ""; + if("1".equals(jblx)){ + jblxNew = "2"; + }else if("2".equals(jblx)){ + jblxNew = "0"; + }else if("3".equals(jblx)){ + jblxNew = "1"; + } + int weekDay = TimeUtil.dateWeekday(ksrq); + if (weekDay == 0 || weekDay == 6) { + jblxNew = "1"; + } + //濡傛灉鏄紤鐝锛屽姞鐝被鍨嬩负浼戞伅鏃ュ姞鐝 + if (isRestSerial(searIdFrom,rs)) { + jblxNew = "1"; + sc = recalculateOverTime(sc,searIdFrom, ksrq, kssj, jsrq, jssj, rs, singleRs); + } + + String sqlMode = "insert into uf_jbtz (jbr,gjsc,bcfs,jbxz,sqr,szbm,sjh,zzdksj,zwdkrq,ly,gh,bm,zw,jblx,ksrq,jsrq,sqsy,kssj,jssj,gzrq,FORMMODEID,MODEDATACREATER,MODEDATACREATERTYPE,MODEDATACREATEDATE,MODEDATACREATETIME) \n" + + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + rs.executeUpdate(sqlMode, jbr,sc,bcfs,jbxz,sqr,szbm,sjh,zzdksj,zwdkrq,ly,gh,bm,zw,jblxNew,ksrq,jsrq,sqsy,kssj,jssj,gsrq,modeid, jbr, "0", modedatacreatedate, modedatacreatetime); + + RecordSet findNew = new RecordSet(); + String sqlFindnew ="select Id from uf_jbtz where jbr = '"+jbr+"' and zzdksj = '"+zzdksj+"' and zwdkrq = '"+zwdkrq+"' order by" + + " modedatacreatedate desc,modedatacreatetime desc"; + findNew.execute(sqlFindnew); + + if (findNew.next()){ + idNew = weaver.general.Util.null2String(findNew.getString("id")); + } + + // 鏉冮檺閲嶆瀯 + int dataId = Integer.valueOf(idNew); + ModeRightInfo modeRightInfo = new ModeRightInfo(); + modeRightInfo.editModeDataShare(Integer.valueOf(jbr), modeid, dataId); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static boolean isRestSerial(String serialId, RecordSet rs) { + try { + String querySql = "select rest_shift from kq_ShiftManagement where id=?"; + rs.executeQuery(querySql, serialId); + if (rs.next()) { + return rs.getInt("rest_shift") == 1; + } + } catch (Exception e) { + return false; + } + return false; + } + private static Double recalculateOverTime(Double sc, String serialId, String ksrq, String kssj, String jsrq, String jssj, RecordSet rs, RecordSet singleRs) { + BaseBean bb = new BaseBean(); + try { + boolean isAcross = false; + BigDecimal workTimeTotal = new BigDecimal(TimeUtil.timeInterval(ksrq + " " + kssj + ":00", jsrq + " " + jssj + ":00")); + BigDecimal restTimeCount = new BigDecimal(0); + if (ksrq.compareTo(jsrq) > 0) { + isAcross = true; + } + String restStartSql = "select * from kq_ShiftRestTimeSections where serialid=? and resttype='start'"; + rs.executeQuery(restStartSql, serialId); + while (rs.next()) { + //浼戞伅寮濮嬫椂闂 + String startTime = rs.getString("time"); + String record1 = rs.getString("record1"); + //浼戞伅缁撴潫鏃堕棿 + String restEndSql = "select * from kq_ShiftRestTimeSections where record1=? and resttype='end'"; + singleRs.executeQuery(restEndSql, record1); + singleRs.next(); + String endTime = singleRs.getString("time"); + if (isAcross) { + double restTime1 = TimeRangeCalculator.getRestTime(kssj, "23:59", startTime, endTime); + double restTime2 = TimeRangeCalculator.getRestTime("00:00", jssj, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime1)); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime2)); + + } else { + double restTime = TimeRangeCalculator.getRestTime(kssj, jssj, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime)); + } + } + sc = divideRoundModeDown(workTimeTotal.subtract(restTimeCount).toString(), "3600"); + //鍗曞弻浼戜紤鐝 鍔犵彮鏈灏忓崟浣嶆槸2灏忔椂 + String twoStartSerId = bb.getPropValue("nbkq_main", "twoStartSerId"); + if (Arrays.asList(twoStartSerId.split(",")).contains(serialId) && sc < 2) { + sc = 0.0; + } + return sc; + } catch (Exception e) { + bb.writeLog("biz-recalculateOverTime-e-" + e.getMessage()); + return sc; + } + } + + public static Double divideRoundModeDown(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + BigDecimal divide = b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP); + return divide.setScale(0, RoundingMode.DOWN).doubleValue(); + } + + /** + * 鎻愪緵绮剧‘鐨勯櫎娉曡繍绠椼 + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static Double divide(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + /** + * 鏍规嵁寤烘ā琛ㄥ悕鑾峰彇formModeId + * + * @param cubeName 寤烘ā琛ㄦ槑 + * @return int formModeId + */ + private static int getFormModeIdByCubeName(String cubeName) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select t1.id from modeinfo t1\n" + + " left join workflow_bill t2\n" + + " on t1.formid=t2.id\n" + + " where t2.tablename='" + cubeName + "'"); + rs.next(); + return rs.getInt("id"); + } + + + /** + * 鍏堝垹闄ゅ彴璐 + * @param jbr + * @param ly + * @param date + */ + public static void deleteJbtz(String jbr,String ly,String date) { + RecordSet rs = new RecordSet(); + String sql = "delete from uf_jbtz where jbr='"+jbr+"' and ly ="+ly+" and gzrq = '"+date+"' "; + rs.executeUpdate(sql); + } +} diff --git a/src/com/engine/kq/biz/KQReportBiz.java b/src/com/engine/kq/biz/KQReportBiz.java new file mode 100644 index 0000000..3fad2bf --- /dev/null +++ b/src/com/engine/kq/biz/KQReportBiz.java @@ -0,0 +1,2312 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum; +import com.engine.kq.enums.KqSplitFlowTypeEnum; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQDurationCalculatorUtil; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +public class KQReportBiz extends BaseBean { + + private static DecimalFormat df = new DecimalFormat("0.00"); + private KQLog kqLog = new KQLog(); + /** + * 鍒濆鍖栧綋澶╄冨嫟鏁版嵁 + */ + public void initKQReportData(){ + String date = DateUtil.getCurrentDate(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + boolean hasInit = false; + sql = "select 1 from kq_report_check where check_date = ? "; + rs.executeQuery(sql,date); + if(rs.next()) { + hasInit = true; + } + + String beforeyesterday = DateUtil.addDate(date,-2); + String yesterday = DateUtil.addDate(date,-1); + if(!hasInit){ + //杩欓噷鍋氳繃鍔熻兘鏄瘡澶╅兘鍒蜂笅鑰冨嫟缂撳瓨 鍥犱负杩欎釜缂撳瓨涔熸槸寮傛鐨勶紝涓鐐归兘涓嶇ǔ瀹 + kqLog.info("begin do KQOneStopUp refreshCominfo invoke ..."); + new KQOneStopUp().refreshCominfo(); + kqLog.info("end do KQOneStopUp refreshCominfo invoke ..."); + + KQFormatBiz kqFormatBiz = new KQFormatBiz(); + kqFormatBiz.clearFormatPool(); + //鏍煎紡鍖栦笂涓婂ぉ鏁版嵁 + kqFormatBiz.formatDateByKQDate(beforeyesterday); + //鏍煎紡鍖栦笂涓澶╂暟鎹 + kqFormatBiz.formatDateByKQDate(yesterday); + //鍒濆鍖栦粖澶╂暟鎹 + kqFormatBiz.formatDateByKQDate(date); + + sql = " insert into kq_report_check(check_date) values (?)"; + rs.executeUpdate(sql,date); + + writeLog(date+"鎵ц鑰冨嫟鎶ヨ〃鏁版嵁鏍煎紡鍖栨垚鍔燂紒"); + } + }catch (Exception e){ + writeLog(e); + } + } + + /*** + * 鑾峰彇鑰冨嫟鐘舵 + * @param resourceId + * @param fromdate + * @param todate + * @param isAll + * @return + */ + public List getKqDateInfo(String resourceId, String fromdate, String todate, boolean isAll) { + List kqdates = new ArrayList<>(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + Map kqdate = null; + List datas = null; + Map data = null; + sql = " select kqdate,serialid, workbegindate, workbegintime,workenddate, workendtime," + + " signintime,signouttime,beLateMins,graveBeLateMins,leaveEarlyMins,graveLeaveEarlyMins," + + " absenteeismMins, forgotCheckMins,forgotBeginWorkCheckMins,otherinfo "+ + " from kq_format_detail " + + " where resourceid=? and kqdate>=? and kqdate<=? "; + if(!isAll){ + if(rs.getDBType().equalsIgnoreCase("oracle") || Util.null2String(rs.getOrgindbtype()).equals("dm") || Util.null2String(rs.getOrgindbtype()).equals("st")) { + sql += " and beLateMins+graveBeLateMins+leaveEarlyMins+graveLeaveEarlyMins+absenteeismMins+forgotCheckMins+nvl(forgotBeginWorkCheckMins,0)>0 "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + sql += " and beLateMins+graveBeLateMins+leaveEarlyMins+graveLeaveEarlyMins+absenteeismMins+forgotCheckMins+ifnull(forgotBeginWorkCheckMins,0)>0 "; + }else { + sql += " and beLateMins+graveBeLateMins+leaveEarlyMins+graveLeaveEarlyMins+absenteeismMins+forgotCheckMins+isnull(forgotBeginWorkCheckMins,0)>0 "; + } + } + sql += " order by kqdate "; + + rs.executeQuery(sql,resourceId,fromdate, todate); + while(rs.next()){ + String workbegindate = Util.null2String(rs.getString("workbegindate")); + String workbegintime = Util.null2String(rs.getString("workbegintime")); + String workenddate = Util.null2String(rs.getString("workenddate")); + String workendtime = Util.null2String(rs.getString("workendtime")); + String signintime = Util.null2String(rs.getString("signintime")); + String signouttime = Util.null2String(rs.getString("signouttime")); + int beLateMins = rs.getInt("beLateMins"); + int graveBeLateMins = rs.getInt("graveBeLateMins"); + int leaveEarlyMins = rs.getInt("leaveEarlyMins"); + int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins"); + int absenteeismMins = rs.getInt("absenteeismMins"); + int forgotCheckMins = rs.getInt("forgotCheckMins"); + int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins"); + String otherinfo = Util.null2String(rs.getString("otherinfo")); + + String shift_begindate = ""; + String shift_beginworktime = ""; + String shift_enddate = ""; + String shift_endworktime = ""; + if(otherinfo.length() > 0){ + JSONObject otherinfo_object = JSONObject.parseObject(otherinfo); + if(otherinfo_object != null && !otherinfo_object.isEmpty()){ + JSONObject shiftRule = (JSONObject) otherinfo_object.get("shiftRule"); + if(shiftRule != null && !shiftRule.isEmpty()){ + shift_begindate = Util.null2String(shiftRule.get("shift_begindate")); + shift_beginworktime = Util.null2String(shiftRule.get("shift_beginworktime")); + shift_enddate = Util.null2String(shiftRule.get("shift_enddate")); + shift_endworktime = Util.null2String(shiftRule.get("shift_endworktime")); + if(shift_begindate.length() > 0){ + workbegindate = shift_begindate; + } + if(shift_beginworktime.length() > 0){ + workbegintime = shift_beginworktime; + } + if(shift_enddate.length() > 0){ + workenddate = shift_enddate; + } + if(shift_endworktime.length() > 0){ + workendtime = shift_endworktime; + } + } + } + } + + kqdate = new HashMap<>(); + datas = new ArrayList<>(); + kqdate.put("kqdate",Util.null2String(rs.getString("kqdate"))); + if(workbegindate.length()>0){ + data = new HashMap<>(); + data.put("workbegindate",workbegindate); + data.put("workbegintime",workbegintime); + data.put("signintime",signintime); + + data.put("workenddate",workenddate); + data.put("workendtime",workendtime); + data.put("signouttime",signouttime); + String status = ""; + if(beLateMins>0||graveBeLateMins>0){ + status = ButtonStatusEnum.BELATE.getStatusCode(); + } + if(forgotBeginWorkCheckMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.NOSIGN_ON.getStatusCode(); + } + if(leaveEarlyMins>0||graveLeaveEarlyMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.LEAVEERALY.getStatusCode(); + } + if(absenteeismMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.ABSENT.getStatusCode(); + } + if(forgotCheckMins>0){ + if(status.length()>0)status+=","; + status += ButtonStatusEnum.NOSIGN.getStatusCode(); + } + data.put("status",status); + datas.add(data); + } + + kqdate.put("checkInfo",datas); + kqdates.add(kqdate); + } + } catch (Exception e) { + writeLog(e); + } + return kqdates; + } + + /** + * 鑾峰彇鎶ヨ〃鏉冮檺 + * @param reportType 鎶ヨ〃绫诲瀷 + * @param userId 鐢ㄦ埛id + * @param tableExt 鍒悕 + * @return + */ + public String getReportRight(String reportType, String userId, String tableExt){ + String rightSql = ""; + String sql = ""; + RecordSet rs = new RecordSet(); + try{ + List userAllUserIds = new ArrayList<>(); + List userAllDeptIds = new ArrayList<>(); + List userAllSubCompanyIds = new ArrayList<>(); + List userAllJobtitleIds = new ArrayList<>(); + boolean forAllUser = false; + sql = " select sharelevel,subcomid, deptid,userid,jobtitleid,foralluser from kq_reportshare where resourceid=? "; + if(reportType.length()>0 ){ + sql += " and (reportname =0 or reportname =" + reportType+")"; + } + rs.executeQuery(sql,userId); + while(rs.next()){ + int sharelevel = rs.getInt("sharelevel"); + if(sharelevel==0){//鍒嗛儴 + if(Util.null2String(rs.getString("subcomid")).length()>0){ + userAllSubCompanyIds.add(rs.getString("subcomid")); + } + }else if(sharelevel==1){//閮ㄩ棬 + if(Util.null2String(rs.getString("deptid")).length()>0) { + userAllDeptIds.add(rs.getString("deptid")); + } + }else if(sharelevel==2){//浜哄憳 + if(Util.null2String(rs.getString("userid")).length()>0) { + userAllUserIds.add(rs.getString("userid")); + } + }else if(sharelevel==3){//宀椾綅 + if(Util.null2String(rs.getString("jobtitleid")).length()>0) { + userAllJobtitleIds.add(rs.getString("jobtitleid")); + } + }else if(sharelevel==4){//鎵鏈変汉 + forAllUser = true; + userAllUserIds.clear(); + userAllDeptIds.clear(); + userAllSubCompanyIds.clear(); + userAllJobtitleIds.clear(); + break; + } + } + + if(!forAllUser) { + for (int sharelevel = 0; sharelevel < 4; sharelevel++) { + if (sharelevel == 0) {//鍒嗛儴 + if (userAllSubCompanyIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".subcompanyid1 in(" + String.join(",", userAllSubCompanyIds) + ")"; + } + } else if (sharelevel == 1) {//閮ㄩ棬 + if (userAllDeptIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".departmentid in(" + String.join(",", userAllDeptIds) + ")"; + } + } else if (sharelevel == 2) {//浜哄憳 + if (userAllUserIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".id in(" + String.join(",", userAllUserIds) + ")"; + } + } else if (sharelevel == 3) {//宀椾綅 + if (userAllJobtitleIds.size() > 0) { + if(rightSql.length()>0)rightSql+= " or "; + rightSql += tableExt+".jobtitle in(" + String.join(",", userAllJobtitleIds) + ")"; + } + } + } + + //鍙互鐪嬭嚜宸卞拰涓嬪睘鐨勮冨嫟 + String selfSql = " ("+tableExt+".id = "+userId+" or "+tableExt+".managerstr like '%,"+userId+",%')"; + if(rightSql.length()>0){ + rightSql = " and ((" +rightSql+") or "+selfSql+" ) "; + }else{ + rightSql = " and "+selfSql; + } + + } + }catch (Exception e){ + writeLog(e); + } + return rightSql; + } + + public static String getUnitType(KQReportFieldComInfo kqReportFieldComInfo, User user){ + String unitTypeName = ""; + String unitType = Util.null2String(kqReportFieldComInfo.getUnittype()); + String parentid = Util.null2String( kqReportFieldComInfo.getParentid()); + String fieldName = Util.null2String(kqReportFieldComInfo.getFieldname()); + if(kqReportFieldComInfo.getIsLeaveType().equals("1")){ + if(fieldName.equals("businessLeave")){ + unitType = KQTravelRulesBiz.getMinimumUnit().equals("3")?"2":"1";//鍗曚綅绫诲瀷 + }else if(fieldName.equals("officialBusiness")){ + unitType = KQExitRulesBiz.getMinimumUnit().equals("3")?"2":"1";//鍗曚綅绫诲瀷 + }else if(parentid.equals("overtime") || parentid.equals("overtime_nonleave") || parentid.equals("overtime_4leave")){ + unitType = (KQOvertimeRulesBiz.getMinimumUnit()==3 || KQOvertimeRulesBiz.getMinimumUnit()==5 ||KQOvertimeRulesBiz.getMinimumUnit()==6)?"2":"1";//鍗曚綅绫诲瀷 + } + } + if(Util.null2String(unitType).length()>0){ + if(unitType.equals("1")){ + unitTypeName=SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + }else if(unitType.equals("2")){ + unitTypeName=SystemEnv.getHtmlLabelName(391, user.getLanguage()); + }else if(unitType.equals("3")){ + unitTypeName=SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + return unitTypeName; + } + + public Map getFlowData(Map params, User user){ + Map datas = new HashMap<>();; + try{ + datas.putAll(getFlowLeaveData(params,user)); + datas.putAll(getFlowEvectionOutData(params,user)); + datas.putAll(getFlowOverTimeDataNew(params,user)); + datas.putAll(getFlowOtherData(params,user)); + datas.putAll(getFlowLeaveBackData(params,user)); + datas.putAll(getFlowProcessChangeData(params,user)); + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇鍛ㄥ叚璇峰亣鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getSaturdayFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + try{ + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' and (DATEPART(dw, belongdate) = 7 or DATEPART(dw, belongdate) = 1) " +sqlWhere + + " group by resourceid, newleavetype, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype, kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇鍛ㄥ叚璇峰亣鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getDailySaturdayFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' and (DATEPART(dw, belongdate) = 7 or DATEPART(dw, belongdate) = 1) " +sqlWhere + + " group by resourceid, newleavetype, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 涓烘瘡鏃ョ粺璁℃姤琛ㄥ仛娴佺▼鏁版嵁鏌ヨ + * @param params + * @param user + * @return + */ + public Map getDailyFlowData(Map params, User user){ + Map datas = new HashMap<>();; + try{ + datas.putAll(getDailyFlowLeaveData(params,user)); + datas.putAll(getDailyFlowEvectionOutData(params,user)); + datas.putAll(getDailyFlowOverTimeData(params,user)); + datas.putAll(getDailyFlowLeaveBackData(params,user)); + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇鍑哄樊鍜屽叕鍑烘暟鎹 + * @param params + * @param user + * @return + */ + public Map getFlowEvectionOutData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String[] tables = new String[]{KqSplitFlowTypeEnum.EVECTION.getTablename(),//鍑哄樊 + KqSplitFlowTypeEnum.OUT.getTablename()};//鍏嚭 + + String minimumUnit = "";//鍗曚綅绫诲瀷 + double proportion = 0.00;//鎹㈢畻鍏崇郴 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + for(String table : tables){ + sql = " select resourceid, durationrule, sum(duration) as val from hrmresource a, "+table+" b "+ + " where a.id = b.resourceid and (b.status is null or b.status<>1) and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + double value = rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getTablename().equals(table)){ + flowType = "businessLeave"; + minimumUnit = KQTravelRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + + }else if(KqSplitFlowTypeEnum.OUT.getTablename().equals(table)){ + flowType = "officialBusiness"; + minimumUnit = KQExitRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + } + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key, df.format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇姣忔棩鐨勫嚭宸拰鍏嚭鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getDailyFlowEvectionOutData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String[] tables = new String[]{KqSplitFlowTypeEnum.EVECTION.getTablename(),//鍑哄樊 + KqSplitFlowTypeEnum.OUT.getTablename()};//鍏嚭 + + String minimumUnit = "";//鍗曚綅绫诲瀷 + double proportion = 0.00;//鎹㈢畻鍏崇郴 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + for(String table : tables){ + sql = " select resourceid, durationrule, sum(duration) as val,belongdate from hrmresource a, "+table+" b "+ + " where a.id = b.resourceid and (b.status is null or b.status<>1) and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + double value = rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getTablename().equals(table)){ + flowType = "businessLeave"; + minimumUnit = KQTravelRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + }else if(KqSplitFlowTypeEnum.OUT.getTablename().equals(table)){ + flowType = "officialBusiness"; + minimumUnit = KQExitRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + } + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key, df.format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇璇峰亣鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype, kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇閿鍋囨暟鎹 + * @param params + * @param user + * @return + */ + public Map getFlowLeaveBackData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leavebackType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇鑰冨嫟鍙樻洿娴佺▼鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getFlowProcessChangeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String minimumUnit = "";//鍗曚綅绫诲瀷 + double proportion = 0.00;//鎹㈢畻鍏崇郴 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, durationrule, changetype,sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.PROCESSCHANGE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule,changetype "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + int changetype = Util.getIntValue(rs.getString("changetype")); + + String flowType = ""; + if(KqSplitFlowTypeEnum.EVECTION.getFlowtype() == changetype){ + flowType = "businessLeave_back"; + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + minimumUnit = KQTravelRulesBiz.getMinimumUnit(); + }else if(KqSplitFlowTypeEnum.OUT.getFlowtype() == changetype){ + flowType = "officialBusiness_back"; + minimumUnit = KQExitRulesBiz.getMinimumUnit(); + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 + } + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+flowType; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key, df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇姣忔棩璇峰亣鏁版嵁 + * @param params + * @param user + * @return + */ + public Map getDailyFlowLeaveData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|leaveType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇姣忔棩閿鍋囨暟鎹 + * @param params + * @param user + * @return + */ + public Map getDailyFlowLeaveBackData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere + + " group by resourceid, newleavetype, durationrule,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String newleavetype = rs.getString("newleavetype"); + String durationrule = rs.getString("durationrule"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + + double proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newleavetype)); + if(KQUnitBiz.isLeaveHour(newleavetype,kqLeaveRulesComInfo)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|"+belongdate+"|leavebackType_"+newleavetype; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇瀹為檯鍔犵彮鏁版嵁锛屽寘鎷祦绋嬶紝鎵撳崱鐢熸垚鐨 + * @return + */ + public Map getFlowOverTimeDataNew(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//褰撳墠鍔犵彮鍗曚綅 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//褰撳墠澶╄窡灏忔椂璁$畻鍏崇郴 + + String valueField = ""; + + sql = " select resourceid,changeType, sum(cast(duration_min as decimal(18,4))) as val,paidLeaveEnable "+ + " from hrmresource a, kq_flow_overtime b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,paidLeaveEnable "; + rs.execute(sql); + kqLog.info("getFlowOverTimeDataNew:sql:"+sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String paidLeaveEnable = rs.getString("paidLeaveEnable"); + int changeType =rs.getInt("changeType");//1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + if(uintType==3 || uintType== 5 || uintType== 6){//鎸夊皬鏃惰绠 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0)+"")); + }else{//鎸夊ぉ璁$畻 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0*hoursToDay)+"")); + } + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + if("1".equalsIgnoreCase(paidLeaveEnable)){ + //1琛ㄧず鍏宠仈璋冧紤 + flowType += "_4leave"; + }else{ + //0琛ㄧず涓嶅叧鑱旇皟浼 + flowType += "_nonleave"; + } + String key = resourceid+"|"+flowType; + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + if(datas.containsKey(key)){ + double tmpVal = Util.getDoubleValue(Util.null2String(datas.get(key)),0.0); + tmpVal += value; + datas.put(key,df.format(tmpVal)); + }else{ + datas.put(key,df.format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + + /** + * 鑾峰彇鍔犵彮鏁版嵁 + * @return + */ + public Map getFlowOverTimeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and b.subcompanyid in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and b.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//褰撳墠鍔犵彮鍗曚綅 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//褰撳墠澶╄窡灏忔椂璁$畻鍏崇郴 + + String valueField = ""; + if(uintType==3 || uintType== 5 || uintType== 6){//鎸夊皬鏃惰绠 + valueField = "sum( case when durationrule='3' then duration else duration*"+hoursToDay+" end) as val"; + }else{//鎸夊ぉ璁$畻 + valueField = "sum( case when durationrule='3' then duration/"+hoursToDay+" else duration end) as val"; + } + + sql = " select resourceid,changeType, " +valueField+ + " from hrmresource a, "+KqSplitFlowTypeEnum.OVERTIME.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + int changeType =rs.getInt("changeType");//1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + String key = resourceid+"|"+flowType; + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + if(datas.containsKey(key)){ + double tmpVal = Util.getDoubleValue(Util.null2String(datas.get(key)),0.0); + tmpVal += value; + datas.put(key,df.format(tmpVal)); + }else{ + datas.put(key,df.format(value)); + } + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 鑾峰彇姣忔棩鍔犵彮鏁版嵁 + * @return + */ + public Map getDailyFlowOverTimeData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//褰撳墠鍔犵彮鍗曚綅 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//褰撳墠澶╄窡灏忔椂璁$畻鍏崇郴 + + String valueField = ""; + if(uintType==3 || uintType== 5 || uintType== 6){//鎸夊皬鏃惰绠 + valueField = "sum( case when durationrule='3' then duration else duration*"+hoursToDay+" end) as val"; + }else{//鎸夊ぉ璁$畻 + valueField = "sum( case when durationrule='3' then duration/"+hoursToDay+" else duration end) as val"; + } + + sql = " select resourceid,changeType,belongdate,paidLeaveEnable, sum(cast(duration_min as decimal(18,4))) as val "+ + " from hrmresource a, kq_flow_overtime b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' " +sqlWhere+ + " group by resourceid,changeType,paidLeaveEnable,belongdate "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + String belongdate = rs.getString("belongdate"); + String paidLeaveEnable = rs.getString("paidLeaveEnable"); + int changeType =rs.getInt("changeType");//1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃 + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + if(uintType==3 || uintType== 5 || uintType== 6){//鎸夊皬鏃惰绠 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0)+"")); + }else{//鎸夊ぉ璁$畻 + value = Util.getDoubleValue(KQDurationCalculatorUtil.getDurationRound(value/(60.0*hoursToDay)+"")); + } + String flowType = ""; + if(changeType==1){ + flowType = "holidayOvertime"; + }else if(changeType==2){ + flowType = "workingDayOvertime"; + }else if(changeType==3){ + flowType = "restDayOvertime"; + } + if("1".equalsIgnoreCase(paidLeaveEnable)){ + //1琛ㄧず鍏宠仈璋冧紤 + flowType += "_4leave"; + }else{ + //0琛ㄧず涓嶅叧鑱旇皟浼 + flowType += "_nonleave"; + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(resourceid+"|"+belongdate+"|"+flowType,df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + * 寮傚父鍐叉姷 + * @return + */ + public Map getFlowOtherData(Map params, User user){ + Map datas = new HashMap<>();; + RecordSet rs = new RecordSet(); + String sql = ""; + String sqlWhere = " "; + try{ + String minimumUnit = "";//鍗曚綅绫诲瀷 + double proportion = 0.00;//鎹㈢畻鍏崇郴 + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect =Util.null2String(jsonObj.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if(resourceId.length()>0){ + sqlWhere +=" and b.resourceid in("+resourceId+") "; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + sql = " select resourceid, durationrule, sum(duration) as val from hrmresource a, "+KqSplitFlowTypeEnum.OTHER.getTablename()+" b "+ + " where a.id = b.resourceid and belongdate >='"+fromDate+"' and belongdate <='"+toDate+"' "+sqlWhere+ + " group by resourceid, durationrule "; + rs.execute(sql); + while (rs.next()) { + String resourceid = rs.getString("resourceid"); + double value = rs.getDouble("val")<0?0:rs.getDouble("val"); + String durationrule = rs.getString("durationrule"); + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value*proportion; + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) value = value/proportion; + } + } + + String key = resourceid+"|leaveDeduction"; + if(datas.containsKey(key)){ + value += Util.getDoubleValue(Util.null2String(datas.get(key))); + } + //df.format 榛樿鏄笉鍥涜垗浜斿叆鐨 0.125杩欐牱鐨勫氨浼氱洿鎺ュ彉鎴0.12浜 + df.setMaximumFractionDigits(5); + datas.put(key, df.format(value)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + + /** + *鏃ユ姤琛ㄦ暟鎹 + * @param resourceId + * @param fromDate + * @param toDate + * @return + */ + public Map getDetialDatas(String resourceId,String fromDate, String toDate, User user){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + Map datas = new HashMap<>(); + Map data = null; + Map tmpdatas = new HashMap<>(); + Map tmpdata = null; + Map tmpmap = null; + RecordSet rs = new RecordSet(); + String sql = ""; + try { + sql = " select resourceid, kqdate, workMins, belatemins, graveBeLateMins, leaveearlymins, graveLeaveEarlyMins, absenteeismmins, forgotcheckMins, forgotBeginWorkCheckMins, "+ + " leaveMins,leaveInfo,evectionMins,outMins " + + " from kq_format_detail " + + " where resourceid = ? and kqdate>=? and kqdate<=? "+ + " order by resourceid, kqdate, serialnumber "; + rs.executeQuery(sql,resourceId, fromDate,toDate); + while (rs.next()) { + String key = rs.getString("resourceid") + "|" + rs.getString("kqdate"); + int workMins = rs.getInt("workMins"); + int beLateMins = rs.getInt("beLateMins"); + int leaveEarlyMins = rs.getInt("leaveEarlyMins"); + int graveBeLateMins = rs.getInt("graveBeLateMins"); + int absenteeismMins = rs.getInt("absenteeismMins"); + int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins"); + int forgotCheckMins = rs.getInt("forgotCheckMins"); + int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins"); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = rs.getString("leaveInfo"); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + String text = ""; + String tmptext =""; + String flag ="true"; + if(datas.get(key)==null){ + data = new HashMap<>(); + }else{ + data = (Map)datas.get(key); + tmptext = Util.null2String(data.get("text")); + } + tmpdata = new HashMap<>(); + if(tmpdatas.get(key)!=null){ + tmpmap = (Map)tmpdatas.get(key); + flag = Util.null2String(tmpmap.get("text")); + } + + if (workMins<=0) { + if(text.length()>0) text +=" "; + text += SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + } else { + if (absenteeismMins > 0) {//鏃峰伐 + if(text.length()>0) text+=" "; + text += SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + }else { + if (beLateMins > 0) {//杩熷埌 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + if (graveBeLateMins > 0) {//涓ラ噸杩熷埌 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//鏃╅ + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//涓ラ噸鏃╅ + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + if (forgotCheckMins > 0) {//婕忕 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if (forgotBeginWorkCheckMins > 0) {//婕忕 + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + if (leaveMins > 0) {//璇峰亣 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//鍑哄樊 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//鍏嚭 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + + if(text.length()==0) { + text = "鈭"; + }else{ + flag = "false";//鏈夊叾浠栫殑寮傚父鐘舵,鍒欒〃绀轰负false锛屼笉闇瑕佸鐞嗙洿鎺ュ叏閮ㄦ樉绀哄嵆鍙 + } + + text = tmptext.length()>0?tmptext+" "+text:text;//鏄剧ず鎵鏈夌殑鐘舵 + data.put("text", text); + datas.put(key, data); + + //add + tmpdata.put("text", flag); + tmpdatas.put(key, tmpdata); + //end + } + //鍏ㄩ儴鎼炰竴閬 + if(tmpdatas != null){ +// writeLog(n+">>>tmpdatas="+JSONObject.toJSONString(tmpdatas)); + Map data1 = null; + for(Entry entry : tmpdatas.entrySet()){ + String mapKey = Util.null2String(entry.getKey()); + Map mapValue = (Map)entry.getValue(); + String flag = Util.null2String(mapValue.get("text")); + if("true".equals(flag)){//闇瑕佸姞宸ョ殑鏁版嵁 + data1 = new HashMap<>(); + data1.put("text", "鈭"); + datas.put(mapKey, data1); + } + } +// writeLog("datas="+JSONObject.toJSONString(datas)); + } + }catch (Exception e){ + writeLog(e); + } + return datas; + } + +// public String getSignStatus(Map data, User user){ +// String result = ""; +// String signtype = Util.null2String(data.get("signtype"));//涓婄彮 涓嬬彮 +// String worktime = Util.null2String(data.get("worktime"));//宸ヤ綔鏃堕棿 +// String signtime = Util.null2String(data.get("signtime"));//绛惧埌鏃堕棿 +// String abnormalMins = Util.null2String(data.get("abnormalMins"));//寮傚父鍒嗛挓鏁 +// String forgotCheck = Util.null2String(data.get("forgotCheck"));//婕忕 +// if(worktime.length()>0){ +// if(signtime.length()>0){ +// if(Util.getDoubleValue(abnormalMins)>0){ +// result =SystemEnv.getHtmlLabelName(signtype.equals("1")?20081:20082, user.getLanguage())+abnormalMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage());//杩熷埌 鏃╅ +// }else{ +// result =SystemEnv.getHtmlLabelName(225, user.getLanguage());//姝e父 +// } +// }else if(forgotCheck.equals("1")){ +// result =SystemEnv.getHtmlLabelName(20086, user.getLanguage());//婕忕 +// } +// }else{ +// result = ""; +// } +// +// return result; +// } + + public int getSerialCount(String resourceId, String fromDate, String toDate, String serialId){ + RecordSet rs = new RecordSet(); + String sql = ""; + int serialCount = 0; + try{ + sql = "select count(1) from hrmresource a, kq_format_total b where a.id= b.resourceid and b.resourceid = ? and b.kqdate >=? and b.kqdate <=? and b.serialId = ? "; + rs.executeQuery(sql,resourceId,fromDate,toDate, serialId); + if(rs.next()){ + serialCount = rs.getInt(1); + } + }catch (Exception e){ + writeLog(e); + } + return serialCount; + } + + public static String getSignStatus(Map signInfo, User user){ + return getSignStatus(signInfo,user,""); + } + + public static String getSignStatus(Map signInfo, User user,String onOrOff){ + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String text = ""; + String workdate = Util.null2String(signInfo.get("workdate")); + String worktime = Util.null2String(signInfo.get("worktime")); + if(!new KQFormatBiz().needCal(workdate,worktime)) {//杩樻湭鍒版椂闂存棤闇璁$畻 + return text; + } + int absenteeismMins = Util.getIntValue(Util.null2String(signInfo.get("absenteeismMins"))); + int beLateMins = Util.getIntValue(Util.null2String(signInfo.get("beLateMins"))); + int graveBeLateMins = Util.getIntValue(Util.null2String(signInfo.get("graveBeLateMins"))); + int leaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("leaveEarlyMins"))); + int graveLeaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("graveLeaveEarlyMins"))); + int forgotCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotCheckMins"))); + int forgotBeginWorkCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotBeginWorkCheckMins"))); + int leaveMins = Util.getIntValue(Util.null2String(signInfo.get("leaveMins"))); + String leaveInfo = Util.null2String(signInfo.get("leaveInfo")); + int evectionMins = Util.getIntValue(Util.null2String(signInfo.get("evectionMins"))); + int outMins = Util.getIntValue(Util.null2String(signInfo.get("outMins"))); + + if(worktime.length()>0){ + if (absenteeismMins > 0) {//鏃峰伐 + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage())+absenteeismMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + }else { + if (beLateMins > 0) {//杩熷埌 + text = SystemEnv.getHtmlLabelName(20081, user.getLanguage())+beLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveBeLateMins > 0) {//涓ラ噸杩熷埌 + text = SystemEnv.getHtmlLabelName( 500546, user.getLanguage())+graveBeLateMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//鏃╅ + text = SystemEnv.getHtmlLabelName(20082, user.getLanguage())+leaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//涓ラ噸鏃╅ + text = SystemEnv.getHtmlLabelName(500547, user.getLanguage())+graveLeaveEarlyMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + } + if (forgotCheckMins > 0) {//婕忕 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if(onOrOff.length() > 0 && "on".equalsIgnoreCase(onOrOff)){ + if (forgotBeginWorkCheckMins > 0) {//婕忕 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + + if (leaveMins > 0) {//璇峰亣 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang(kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage()); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//鍑哄樊 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//鍏嚭 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + if(text.equals("")){ + boolean needCal = new KQFormatBiz().needCal(workdate,worktime); + text = needCal?SystemEnv.getHtmlLabelName(225, user.getLanguage()):""; + } + }else{ + if (leaveMins > 0) {//璇峰亣 + Map jsonObject = null; + if(leaveInfo.length()>0){ + jsonObject = JSON.parseObject(leaveInfo); + for (Entry entry : jsonObject.entrySet()) { + String newLeaveType = entry.getKey(); + String tmpLeaveMins = Util.null2String(entry.getValue()); + if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){ + if (text.length() > 0) text += " "; + //text += kqLeaveRulesComInfo.getLeaveName(newLeaveType)+tmpLeaveMins+SystemEnv.getHtmlLabelName(15049, user.getLanguage()); + text += Util.formatMultiLang(kqLeaveRulesComInfo.getLeaveName(newLeaveType)); + } + } + }else{ + if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(670, user.getLanguage()); + } + } + } + if (evectionMins > 0) {//鍑哄樊 + if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(20084, user.getLanguage()); + } + } + if (outMins > 0) {//鍏嚭 + if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) { + if (text.length() > 0) text += " "; + text += SystemEnv.getHtmlLabelName(24058, user.getLanguage()); + } + } + } + return text; + } + + /** + * 鑾峰彇鎵撳崱鐘舵(涓嶅寘鍚叿浣撳垎閽熸暟) + * @param signInfo + * @param user + * @param onOrOff + * @return + */ + public static String getSignStatus2(Map signInfo, User user, String onOrOff) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String text = ""; + String worktime = Util.null2String(signInfo.get("worktime")); + int absenteeismMins = Util.getIntValue(Util.null2String(signInfo.get("absenteeismMins"))); + int beLateMins = Util.getIntValue(Util.null2String(signInfo.get("beLateMins"))); + int graveBeLateMins = Util.getIntValue(Util.null2String(signInfo.get("graveBeLateMins"))); + int leaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("leaveEarlyMins"))); + int graveLeaveEarlyMins = Util.getIntValue(Util.null2String(signInfo.get("graveLeaveEarlyMins"))); + int forgotCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotCheckMins"))); + int forgotBeginWorkCheckMins = Util.getIntValue(Util.null2String(signInfo.get("forgotBeginWorkCheckMins"))); + int leaveMins = Util.getIntValue(Util.null2String(signInfo.get("leaveMins"))); + String leaveInfo = Util.null2String(signInfo.get("leaveInfo")); + int evectionMins = Util.getIntValue(Util.null2String(signInfo.get("evectionMins"))); + int outMins = Util.getIntValue(Util.null2String(signInfo.get("outMins"))); + + if (worktime.length() > 0) { + if (absenteeismMins > 0) {//鏃峰伐 + text = SystemEnv.getHtmlLabelName(20085, user.getLanguage()); + } else { + if (beLateMins > 0) {//杩熷埌 + text = SystemEnv.getHtmlLabelName(20081, user.getLanguage()); + } + if (graveBeLateMins > 0) {//涓ラ噸杩熷埌 + text = SystemEnv.getHtmlLabelName(500546, user.getLanguage()); + } + if (leaveEarlyMins > 0) {//鏃╅ + text = SystemEnv.getHtmlLabelName(20082, user.getLanguage()); + } + if (graveLeaveEarlyMins > 0) {//涓ラ噸鏃╅ + text = SystemEnv.getHtmlLabelName(500547, user.getLanguage()); + } + if (forgotCheckMins > 0) {//婕忕 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + if (onOrOff.length() > 0 && "on".equalsIgnoreCase(onOrOff)) { + if (forgotBeginWorkCheckMins > 0) {//婕忕 + text = SystemEnv.getHtmlLabelName(20086, user.getLanguage()); + } + } + } + if (text.equals("") && leaveMins <= 0 && evectionMins <= 0 && outMins <= 0) { + text = SystemEnv.getHtmlLabelName(225, user.getLanguage()); + } + } + return text; + } + + public static boolean getShowFlowText(String leaveInfo,String onOrOff){ + Map jsonObject = null; + jsonObject = JSON.parseObject(leaveInfo); + String flow_signtype = ""; + for (Entry entry : jsonObject.entrySet()) { + String tmpSignType = Util.null2String(entry.getValue()); + flow_signtype += ","+tmpSignType; + } + if(flow_signtype.length() == 0){ + return true; + } + return isShowFlowText(flow_signtype,onOrOff); + } + + public static boolean isShowFlowText(String flow_signtype,String onOrOff){ + boolean showFlowText = true; + + if(flow_signtype.length() > 0){ + flow_signtype = flow_signtype.substring(1); + if("on".equalsIgnoreCase(onOrOff)){ + if((","+flow_signtype+",").indexOf(",1,") > -1){ + //鎶垫墸浜嗕笂鐝崱 + }else{ + //涓婄彮鐘舵侊紝浣嗘槸娌℃湁涓婄彮鎶垫墸娴佺▼ + showFlowText = false; + } + } + if("off".equalsIgnoreCase(onOrOff)){ + if((","+flow_signtype+",").indexOf(",2,") > -1){ + //鎶垫墸浜嗕笅鐝崱 + }else{ + //涓嬬彮鐘舵侊紝浣嗘槸娌℃湁涓嬬彮鎶垫墸娴佺▼ + showFlowText = false; + } + } + } + return showFlowText; + } + + public static int getPageSize(String pageSize, String pageUid, int userid){ + String sql = ""; + RecordSet rs = new RecordSet(); + int iPageSize= Util.getIntValue(pageSize,10); + if(iPageSize<10)iPageSize=10; + try{ + if(pageSize.length()>0){ + boolean flag = false; + sql = "select count(1) from ecology_pagesize where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + flag = true; + } + } + if(flag){ + sql = "update ecology_pagesize set pagesize ="+pageSize+" where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeUpdate(sql); + }else{ + sql = "insert into ecology_pagesize (pageid,pagesize,userid) values ('"+pageUid+"',"+pageSize+","+userid+")"; + rs.executeUpdate(sql); + } + }else{ + sql = "select pageSize from ecology_pagesize where pageid = '"+pageUid+"' and userid ="+userid; + rs.executeQuery(sql); + if(rs.next()){ + iPageSize = rs.getInt("pageSize"); + } + } + }catch (Exception e){ + new BaseBean().writeLog("KQReportBiz.getPageSize"+e); + } + + return iPageSize; + } + + //缁忓父閬囧埌鐢宠鍙樻洿娴佺▼鎴栭攢鍋囨祦绋嬫彁绀烘湭褰掓。锛屼笉鑳滃叾鐑︼紝鎵浠ユ悶涓涓 + public void reflow(String requestid){ + try { + requestid = Util.null2String(requestid); + String workflowid = ""; + String currentnodetype = ""; + if(requestid.length() == 0){ + return; + } + RecordSet rs2 = new RecordSet(); + String sql = "select requestid,workflowid,currentnodetype from workflow_requestbase where requestid = '"+requestid+"'"; + rs2.executeQuery(sql); + if(rs2.next()){ + workflowid = Util.null2String(rs2.getString("workflowid")); + currentnodetype = Util.null2String(rs2.getString("currentnodetype")); + } + + boolean isForce1 = false; + boolean isUpgrade1 = false; + if(requestid.length() == 0){ + return ; + } + if(workflowid.length() == 0){ + return ; + } + if(!"3".equals(currentnodetype)){ + return ; + } + long start = System.currentTimeMillis(); + + KQFlowActiontBiz kqFlowActiontBiz = new KQFlowActiontBiz(); + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + String proc_set_sql = "select * from kq_att_proc_set where field001 = ? "; + rs.executeQuery(proc_set_sql, workflowid); + if(rs.next()){ + String proc_set_id = rs.getString("id"); + //寰楀埌杩欎釜鑰冨嫟娴佺▼璁剧疆鏄惁浣跨敤鏄庣粏 + String usedetails = rs.getString("usedetail"); + + int kqtype = Util.getIntValue(rs.getString("field006")); + + Map map = new HashMap(); + if(Util.getIntValue(requestid) > 0){ + map.put("requestId", "and t.requestId = " + requestid); + } + String tablename = ""; + if(kqtype == KqSplitFlowTypeEnum.LEAVE.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.LEAVE.getTablename(); + }else if(kqtype == KqSplitFlowTypeEnum.EVECTION.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.EVECTION.getTablename(); + }else if(kqtype == KqSplitFlowTypeEnum.OUT.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OUT.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.OVERTIME.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OVERTIME.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.SHIFT.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.SHIFT.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.OTHER.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.OTHER.getTablename();; + }else if(kqtype == KqSplitFlowTypeEnum.CARD.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.CARD.getTablename();; + return; + }else if(kqtype == KqSplitFlowTypeEnum.LEAVEBACK.getFlowtype()){ + tablename = KqSplitFlowTypeEnum.LEAVEBACK.getTablename();; + }else{ + return; + } + if(null != tablename && tablename.length() > 0){ + String tmpsql = "select * from "+tablename+" where requestId="+requestid; + rs1.executeQuery(tmpsql); + if(rs1.next()){ + return;//琛ㄧず宸茬粡浜х敓浜嗘媶鍒嗘暟鎹 + } + } + + //鍏堟牴鎹畆equestid鍒犻櫎涓棿琛ㄩ噷鐨勬暟鎹紝鍐嶅仛鍟ユ彃鍏ユ搷浣 + String delSql = "delete from "+tablename+" where requestid = "+requestid; + rs1.executeUpdate(delSql); + if(kqtype == KqSplitFlowTypeEnum.OVERTIME.getFlowtype()) { + delSql = "delete from kq_flow_overtime where requestid = "+requestid; + rs1.executeUpdate(delSql); + } + + Map result = kqFlowActiontBiz.handleKQFlowAction(proc_set_id, usedetails, Util.getIntValue(requestid), kqtype, Util.getIntValue(workflowid), isForce1,isUpgrade1,map); + + if(!result.isEmpty()){ + + } + } + long end = System.currentTimeMillis(); + }catch (Exception e){ + e.printStackTrace();; + } + } + + /** + * 鑾峰彇 鍔犵彮鎬绘暟 + * @param startdate + * @param enddate + * @param userid + * @param jblx + * @param bcfs + * @return + */ + public double getOverTimeCount(String startdate,String enddate,String userid,String jblx,String bcfs){ + double result = 0.00; + RecordSet rs = new RecordSet(); + rs.executeQuery("select sum(gjsc) as count from uf_jbtz where gzrq >= ? and gzrq <= ? and jbr=? and jblx=? and bcfs=?",startdate,enddate,userid,jblx,bcfs); + rs.writeLog("select sum(gjsc) as count from uf_jbtz where gzrq >= '"+ startdate +"' and gzrq <= '"+ enddate +"' and jbr="+ userid +" and jblx="+ jblx +" and bcfs="+ bcfs); + while(rs.next()){ + result = Util.getDoubleValue(rs.getString("count"),0.00); + } + return result; + } + + /** + * 鑾峰彇 姣忔棩 鍔犵彮鏁 + * @param kqdate + * @param userid + * @param jblx + * @param bcfs + * @return + */ + public double getOverTimeDailyCount(String kqdate,String userid,String jblx,String bcfs){ + double result = 0.00; + RecordSet rs = new RecordSet(); + rs.executeQuery("select sum(gjsc) as count from uf_jbtz where gzrq = ? and jbr=? and jblx=? and bcfs=?",kqdate,userid,jblx,bcfs); + rs.writeLog("select sum(gjsc) as count from uf_jbtz where gzrq = '"+ kqdate +"' and jbr="+ userid +" and jblx="+ jblx +" and bcfs="+ bcfs); + while(rs.next()){ + result = Util.getDoubleValue(rs.getString("count"),0.00); + } + return result; + } + + /** + * 鑾峰彇澶滅彮姣忔棩琛ヨ创娆℃暟 + * @param kqdate + * @param userid + * @return + */ + public double getNightSubsidyDaily(String kqdate,String userid){ + double result = 0.00; + RecordSet rs = new RecordSet(); + int sixnight_serialid = Integer.parseInt(rs.getPropValue("nbjh_ygdjblc","sixnight_serialid")); + int twelvehours_night_serialid = Integer.parseInt(rs.getPropValue("nbjh_ygdjblc","twelvehours_night_serialid")); + rs.executeQuery("select * from kq_format_total where kqdate = ? and resourceid=?",kqdate,userid); + rs.writeLog("select * from kq_format_total where kqdate = '"+ kqdate +"' and resourceid="+ userid); + while(rs.next()){ + int serialid = Util.getIntValue(rs.getString("serialid")); + double attendanceMins = Util.getDoubleValue(rs.getString("attendanceMins"),0.00); + double overTimeTotal = getOverTimeTotal(kqdate,userid); + double time = attendanceMins+overTimeTotal; + if(serialid == sixnight_serialid|| serialid == twelvehours_night_serialid){ + if(time >= 8){ + result = 1; + } + } + } + return result; + } + + /** + * 鑾峰彇澶滅彮琛ヨ创鎬绘鏁 + * @param fromDate + * @param toDate + * @param userid + * @return + */ + public double getNightSubsidyTotal(String fromDate,String toDate,String userid){ + double result = 0.00; + RecordSet rs = new RecordSet(); + int sixnight_serialid = Integer.parseInt(rs.getPropValue("nbjh_ygdjblc","sixnight_serialid")); + int twelvehours_night_serialid = Integer.parseInt(rs.getPropValue("nbjh_ygdjblc","twelvehours_night_serialid")); + rs.executeQuery("select * from kq_format_total where kqdate >= ? and kqdate <= ? and resourceid=?",fromDate,toDate,userid); + rs.writeLog("select * from kq_format_total where kqdate >= '"+ fromDate +"' and kqdate <= '"+ toDate +"' and resourceid="+ userid); + while(rs.next()){ + int serialid = Util.getIntValue(rs.getString("serialid")); + String kqdate = Util.null2String(rs.getString("kqdate")); + double attendanceMins = Util.getDoubleValue(rs.getString("attendanceMins"),0.00); + double overTimeTotal = getOverTimeTotal(kqdate,userid); + double time = attendanceMins+overTimeTotal; + if(serialid == sixnight_serialid|| serialid == twelvehours_night_serialid){ + if(time >= 8){ + result++; + } + } + } + return result; + } + + /** + * 鑾峰彇 鍔犵彮鍙拌处 鎬绘椂闀 + * @param kqdate + * @param userid + * @return + */ + public double getOverTimeTotal(String kqdate,String userid){ + double result = 0.00; + RecordSet rs = new RecordSet(); + rs.executeQuery("select sum(gjsc)as gjsc from uf_jbtz where gzrq=? and jbr=?",kqdate,userid); + while(rs.next()){ + result = Util.getDoubleValue(rs.getString("gjsc"),0.00); + } + return result; + } + + /** + * 鑾峰彇 琛ュ崱鐢宠娴佺▼ 鏄庣粏琛 鏁 + * @param fromDate + * @param toDate + * @param userid + * @return + */ + public int getFillCardCount(String fromDate,String toDate,String userid){ + int result = 0; + RecordSet rs = new RecordSet(); + String tablename = rs.getPropValue("nbjh_ygdjblc","fillcard_table"); + String tablename_dt = tablename+"_dt1"; + rs.executeQuery("select b.* from "+ tablename +" a,"+ tablename_dt +" b,workflow_requestbase c" + + "where a.requestid = c.requestid and a.id=b.mainid and c.currentnodetype=3" + + "and a.ksrq >=? and a.jsrq <=? and a.resourceId=?",fromDate,toDate,userid); + if(rs.next()){ + + } + result = rs.getCounts(); + return result; + } + + /** + * 鑾峰彇 琛ュ崱鐢宠娴佺▼ 鏄庣粏琛 鏁 + * @param kqdate + * @param userid + * @return + */ + public int getFillCardCountDaily(String kqdate,String userid){ + int result = 0; + RecordSet rs = new RecordSet(); + String tablename = rs.getPropValue("nbjh_ygdjblc","fillcard_table"); + String tablename_dt = tablename+"_dt1"; + rs.executeQuery("select b.* from "+ tablename +" a,"+ tablename_dt +" b,workflow_requestbase c" + + "where a.requestid = c.requestid and a.id=b.mainid and c.currentnodetype=3" + + "and b.detail_signdate =? and a.resourceId=?",kqdate,userid); + if(rs.next()){ + result = 1; + } + return result; + } + +} diff --git a/src/com/engine/kq/biz/KQShiftManagementComInfo.java b/src/com/engine/kq/biz/KQShiftManagementComInfo.java new file mode 100644 index 0000000..de64279 --- /dev/null +++ b/src/com/engine/kq/biz/KQShiftManagementComInfo.java @@ -0,0 +1,759 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.biz.chain.cominfo.HalfShiftComIndex; +import com.engine.kq.biz.chain.cominfo.RestShiftComIndex; +import com.engine.kq.biz.chain.cominfo.ShiftComIndex; +import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean; +import com.engine.kq.biz.chain.cominfo.WorkShiftComIndex; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.log.KQLog; +import java.io.PrintWriter; +import java.io.Serializable; +import java.io.StringWriter; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; +import org.apache.commons.lang.math.NumberUtils; +import weaver.cache.CacheBase; +import weaver.cache.CacheColumn; +import weaver.cache.CacheColumnType; +import weaver.cache.CacheItem; +import weaver.cache.CacheMap; +import weaver.cache.PKColumn; +import weaver.conn.RecordSet; +import weaver.general.Util; + +/** + * 鐝绠$悊缂撳瓨绫 + */ +public class KQShiftManagementComInfo extends CacheBase implements Serializable { + /* + * 闇瑕佸叧娉 : 濡傛灉瀹屽叏鍦 initCache 鑷繁瀹氫箟鏁版嵁鍒濆鍖栵紝 杩欎釜瀛楁鍙互涓嶅畾涔 + */ + protected static String TABLE_NAME = ""; + + /* + * 闇瑕佸叧娉 : 濡傛灉瀹屽叏鍦 initCache 鑷繁瀹氫箟鏁版嵁鍒濆鍖栵紝鎴栬呬笉闇瑕佹寚瀹氬浐瀹氱殑鏉′欢锛 杩欎釜瀛楁鍙互涓嶅畾涔 + * sql涓殑where淇℃伅锛屼笉瑕佷互where寮濮 + */ + protected static String TABLE_WHERE = null; + + /* + * 闇瑕佸叧娉 : 濡傛灉瀹屽叏鍦 initCache 鑷繁瀹氫箟鏁版嵁鍒濆鍖栵紝鎴栬呬笉闇瑕佹寚瀹氶『搴忥紝 杩欎釜瀛楁鍙互涓嶅畾涔 sql涓殑order + * by淇℃伅锛屼笉瑕佷互order by寮濮 + * + */ + protected static String TABLE_ORDER = null; + + @PKColumn(type = CacheColumnType.NUMBER) + protected static String PK_NAME = "id"; + + @CacheColumn + protected static int shiftbean; + + @CacheColumn + protected static int color; + + @CacheColumn + protected static int isoffdutyfreecheck; + + @CacheColumn + protected static int shiftonoffworkcount; + + @CacheColumn + protected static int serial; + + @CacheColumn + protected static int isresttimeopen; + + @CacheColumn + protected static int worktime; + + @CacheColumn + protected static int punchsetting; + + @CacheColumn + protected static int cardRemind; + + @CacheColumn + protected static int cardRemOfSignIn; + + @CacheColumn + protected static int minsBeforeSignIn; + + @CacheColumn + protected static int cardRemOfSignOut; + + @CacheColumn + protected static int minsAfterSignOut; + + @CacheColumn + protected static int remindMode; + + @CacheColumn + protected static int remindOnPC; + + @CacheColumn + protected static int rest_shift; + + private KQLog kqLog = new KQLog(); + + @Override + public CacheItem initCache(String key) { + if (key == null || "".equals(key.trim())) { + return null; + } + CacheMap localData = createCacheMap(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //鑰冨嫟缁勪紭鍏堢骇 + try { + + ConcurrentHashMap shiftInfoBeanMap = new ConcurrentHashMap<>(); + ConcurrentHashMap idMap = new ConcurrentHashMap<>(); + ConcurrentHashMap colorsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isoffdutyfreechecksMap = new ConcurrentHashMap<>(); + ConcurrentHashMap shiftonoffworkcountsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap serialsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isresttimeopensMap = new ConcurrentHashMap<>(); + ConcurrentHashMap worktimesMap = new ConcurrentHashMap<>(); + ConcurrentHashMap punchsettingsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemindMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsBeforeSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsAfterSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindModeMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindOnPCMap = new ConcurrentHashMap<>(); + ConcurrentHashMap restShiftMap = new ConcurrentHashMap<>(); + RecordSet rs = new RecordSet(); + String getShiftInfo = "select * from kq_ShiftManagement where 1=1 and id="+key+" order by id "; + rs.execute(getShiftInfo); + while(rs.next()){ + String serialid = rs.getString("id"); + String isresttimeopen = rs.getString("isresttimeopen"); + String color = rs.getString("color"); + String shiftonoffworkcount = rs.getString("shiftonoffworkcount"); + String worktime = rs.getString("worktime"); + String serial = rs.getString("serial"); + String punchsetting = "1"; + String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck"); + String cardRemind = rs.getString("cardRemind"); + String cardRemOfSignIn = rs.getString("cardRemOfSignIn"); + String minsBeforeSignIn = rs.getString("minsBeforeSignIn"); + String cardRemOfSignOut = rs.getString("cardRemOfSignOut"); + String minsAfterSignOut = rs.getString("minsAfterSignOut"); + String remindMode = rs.getString("remindMode"); + String remindOnPC = rs.getString("remindOnPC"); + String halfcalrule = rs.getString("halfcalrule"); + halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule; + String halfcalpoint = rs.getString("halfcalpoint"); + String halfcalpoint2cross = rs.getString("halfcalpoint2cross"); + String restShift = rs.getString("rest_shift"); + + getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,restShift); + + idMap.put(serialid, serialid); + colorsMap.put(serialid, color); + isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck); + shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount); + serialsMap.put(serialid, serial); + isresttimeopensMap.put(serialid, isresttimeopen); + worktimesMap.put(serialid, worktime); + punchsettingsMap.put(serialid, punchsetting); + cardRemindMap.put(serialid,cardRemind); + cardRemOfSignInMap.put(serialid,cardRemOfSignIn); + minsBeforeSignInMap.put(serialid,minsBeforeSignIn); + cardRemOfSignOutMap.put(serialid,cardRemOfSignOut); + minsAfterSignOutMap.put(serialid,minsAfterSignOut); + remindModeMap.put(serialid,remindMode); + remindOnPCMap.put(serialid,remindOnPC); + restShiftMap.put(serialid,restShift); + } + + + if(shiftInfoBeanMap.size()>0){ + CacheItem cacheItem = createCacheItem(); + Iterator> iterator = shiftInfoBeanMap.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + String id = entry.getKey(); + Object value = entry.getValue(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(shiftbean, value); + cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id)); + cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id)); + cacheItem.set(serial, serialsMap.get(id)); + cacheItem.set(isresttimeopen, isresttimeopensMap.get(id)); + cacheItem.set(worktime, worktimesMap.get(id)); + cacheItem.set(punchsetting, punchsettingsMap.get(id)); + cacheItem.set(cardRemind,cardRemindMap.get(id)); + cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id)); + cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id)); + cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id)); + cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id)); + cacheItem.set(remindMode,remindModeMap.get(id)); + cacheItem.set(remindOnPC,remindOnPCMap.get(id)); + cacheItem.set(rest_shift,restShiftMap.get(id)); + modifyCacheItem(id, cacheItem); + } + return cacheItem; + } + } catch (Exception e) { + kqLog.info(e); + } + return null; + } + + @Override + public CacheMap initCache() { + CacheMap localData = createCacheMap(); + String sql = ""; + kqLog = new KQLog(); + ConcurrentHashMap resourceKQGroups = new ConcurrentHashMap<>(); + //鑰冨嫟缁勪紭鍏堢骇 + try { + + ConcurrentHashMap shiftInfoBeanMap = new ConcurrentHashMap<>(); + ConcurrentHashMap idMap = new ConcurrentHashMap<>(); + ConcurrentHashMap colorsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isoffdutyfreechecksMap = new ConcurrentHashMap<>(); + ConcurrentHashMap shiftonoffworkcountsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap serialsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap isresttimeopensMap = new ConcurrentHashMap<>(); + ConcurrentHashMap worktimesMap = new ConcurrentHashMap<>(); + ConcurrentHashMap punchsettingsMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemindMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsBeforeSignInMap = new ConcurrentHashMap<>(); + ConcurrentHashMap cardRemOfSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap minsAfterSignOutMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindModeMap = new ConcurrentHashMap<>(); + ConcurrentHashMap remindOnPCMap = new ConcurrentHashMap<>(); + ConcurrentHashMap restShiftMap = new ConcurrentHashMap<>(); + RecordSet rs = new RecordSet(); + String getShiftInfo = "select * from kq_ShiftManagement where 1=1 order by id "; + rs.execute(getShiftInfo); + while(rs.next()){ + String serialid = rs.getString("id"); + String isresttimeopen = rs.getString("isresttimeopen"); + String color = rs.getString("color"); + String shiftonoffworkcount = rs.getString("shiftonoffworkcount"); + String worktime = rs.getString("worktime"); + String serial = rs.getString("serial"); + String punchsetting = "1"; + String isoffdutyfreecheck = rs.getString("isoffdutyfreecheck"); + String cardRemind = rs.getString("cardRemind"); + String cardRemOfSignIn = rs.getString("cardRemOfSignIn"); + String minsBeforeSignIn = rs.getString("minsBeforeSignIn"); + String cardRemOfSignOut = rs.getString("cardRemOfSignOut"); + String minsAfterSignOut = rs.getString("minsAfterSignOut"); + String remindMode = rs.getString("remindMode"); + String remindOnPC = rs.getString("remindOnPC"); + String halfcalrule = rs.getString("halfcalrule"); + halfcalrule = Util.null2String(halfcalrule).length() == 0 ? "0" : halfcalrule; + String halfcalpoint = rs.getString("halfcalpoint"); + String halfcalpoint2cross = rs.getString("halfcalpoint2cross"); + String restShift = rs.getString("rest_shift"); + + getShiftInfoBean(serialid,isresttimeopen,worktime,punchsetting,shiftInfoBeanMap,halfcalrule,halfcalpoint,halfcalpoint2cross,restShift); + + idMap.put(serialid, serialid); + colorsMap.put(serialid, color); + isoffdutyfreechecksMap.put(serialid, isoffdutyfreecheck); + shiftonoffworkcountsMap.put(serialid, shiftonoffworkcount); + serialsMap.put(serialid, serial); + isresttimeopensMap.put(serialid, isresttimeopen); + worktimesMap.put(serialid, worktime); + punchsettingsMap.put(serialid, punchsetting); + cardRemindMap.put(serialid,cardRemind); + cardRemOfSignInMap.put(serialid,cardRemOfSignIn); + minsBeforeSignInMap.put(serialid,minsBeforeSignIn); + cardRemOfSignOutMap.put(serialid,cardRemOfSignOut); + minsAfterSignOutMap.put(serialid,minsAfterSignOut); + remindModeMap.put(serialid,remindMode); + remindOnPCMap.put(serialid,remindOnPC); + restShiftMap.put(serialid,restShift); + } + + + if(shiftInfoBeanMap.size()>0){ + Iterator> iterator = shiftInfoBeanMap.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + String id = entry.getKey(); + Object value = entry.getValue(); + CacheItem cacheItem = createCacheItem(); + cacheItem.set(PK_INDEX, id); + cacheItem.set(shiftbean, value); + cacheItem.set(isoffdutyfreecheck, isoffdutyfreechecksMap.get(id)); + cacheItem.set(shiftonoffworkcount, shiftonoffworkcountsMap.get(id)); + cacheItem.set(serial, serialsMap.get(id)); + cacheItem.set(isresttimeopen, isresttimeopensMap.get(id)); + cacheItem.set(worktime, worktimesMap.get(id)); + cacheItem.set(punchsetting, punchsettingsMap.get(id)); + cacheItem.set(cardRemind,cardRemindMap.get(id)); + cacheItem.set(cardRemOfSignIn,cardRemOfSignInMap.get(id)); + cacheItem.set(minsBeforeSignIn,minsBeforeSignInMap.get(id)); + cacheItem.set(cardRemOfSignOut,cardRemOfSignOutMap.get(id)); + cacheItem.set(minsAfterSignOut,minsAfterSignOutMap.get(id)); + cacheItem.set(remindMode,remindModeMap.get(id)); + cacheItem.set(remindOnPC,remindOnPCMap.get(id)); + cacheItem.set(rest_shift,restShiftMap.get(id)); + modifyCacheItem(id, cacheItem); + localData.put(id, cacheItem); + } + } + } catch (Exception e) { + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + return localData; + } + + public String getId(){ + return (String)getRowValue(PK_INDEX); + } + + public String getColor() { return (String)getRowValue(color); } + + public String getColor(String key) + { + return (String)getValue(color,key); + } + + public String getIsoffdutyfreecheck() { return (String)getRowValue(isoffdutyfreecheck); } + + public String getIsoffdutyfreecheck(String key) + { + return (String)getValue(isoffdutyfreecheck,key); + } + + public String getShiftonoffworkcounts() { return (String)getRowValue(shiftonoffworkcount); } + + public String getShiftonoffworkcounts(String key) + { + return (String)getValue(shiftonoffworkcount,key); + } + + public String getSerial() { return (String)getRowValue(serial); } + + public String getSerial(String key) + { + return (String)getValue(serial,key); + } + + public String getIsresttimeopen() { return (String)getRowValue(isresttimeopen); } + + public String getIsresttimeopen(String key) + { + return (String)getValue(isresttimeopen,key); + } + + public String getWorktime() { return (String)getRowValue(worktime); } + + public String getWorktime(String key) + { + return (String)getValue(worktime,key); + } + + public String getPunchsetting() { + return (String) getRowValue(punchsetting); + } + + public String getPunchsetting(String key) { + return (String) getValue(punchsetting, key); + } + + public String getCardRemind() { + return (String) getRowValue(cardRemind); + } + + public String getCardRemind(String key) { + return (String) getValue(cardRemind,key); + } + + public String getCardRemOfSignIn() { + return (String) getRowValue(cardRemOfSignIn); + } + + public String getCardRemOfSignIn(String key) { + return (String) getValue(cardRemOfSignIn, key); + } + + public String getMinsBeforeSignIn() { + return (String) getRowValue(minsBeforeSignIn); + } + + public String getMinsBeforeSignIn(String key) { + return (String) getValue(minsBeforeSignIn, key); + } + + public String getCardRemOfSignOut() { + return (String) getRowValue(cardRemOfSignOut); + } + + public String getCardRemOfSignOut(String key) { + return (String) getValue(cardRemOfSignOut, key); + } + + public String getMinsAfterSignOut() { + return (String) getRowValue(minsAfterSignOut); + } + + public String getMinsAfterSignOut(String key) { + return (String) getValue(minsAfterSignOut, key); + } + + public String getRemindMode() { + return (String) getRowValue(remindMode); + } + + public String getRemindMode(String key) { + return (String) getValue(remindMode, key); + } + + public String getRemindOnPC() { + return (String) getRowValue(remindOnPC); + } + + public String getRemindOnPC(String key) { + return (String) getValue(remindOnPC, key); + } + + public String getRestShift() { + return (String) getRowValue(rest_shift); + } + + public String getRestShift(String key) { + return (String) getValue(rest_shift, key); + } + + private void getShiftInfoBean(String serialid, String isresttimeopen, String worktime, + String punchsettings, + ConcurrentHashMap serialMap, + String halfcalrule,String halfcalpoint,String halfcalpoint2cross, String restShift) throws Exception { + + Map workTimeMap = new HashMap<>(); + int workmins = 0; + List workTimes = Collections.synchronizedList(new ArrayList<>()); + List restTimes = Collections.synchronizedList(new ArrayList<>()); + KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo(); + KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo(); + + workTimes = kqShiftOnOffWorkSectionComInfo.getWorkSectionTimes(serialid); + if(workTimes != null && !workTimes.isEmpty()){ + if("1".equalsIgnoreCase(isresttimeopen)) { + //濡傛灉寮鍚簡鎵嶅幓鍒ゆ柇 + restTimes = kqShiftRestTimeSectionComInfo.getRestSectionTimes(serialid); + } + if(NumberUtils.isNumber(worktime)){ + if(worktime.indexOf('.') == -1){ + workmins = Util.getIntValue(worktime,0); + }else { + worktime = worktime.substring(0,worktime.indexOf('.')); + workmins = Util.getIntValue(worktime,0); + } + + }else{ + workmins = 0; + kqLog.info("鐝鏈夐棶棰橈紝serialid:"+serialid+"宸ヤ綔鏃堕暱涓:"+worktime); + } + workTimeMap.put("workTime", workTimes); + workTimeMap.put("restTime", restTimes); + workTimeMap.put("serialid", serialid); + //宸ヤ綔鏃堕暱鍒嗛挓鏁 + workTimeMap.put("workmins", workmins+""); + workTimeMap.put("punchsettings", punchsettings); + workTimeMap.put("isresttimeopen", isresttimeopen); + workTimeMap.put("halfcalrule", halfcalrule); + workTimeMap.put("halfcalpoint", halfcalpoint); + workTimeMap.put("halfcalpoint2cross", halfcalpoint2cross); + workTimeMap.put("restShift", restShift.equals("1") ? "1" : "0"); + + ShiftInfoCominfoBean shiftInfoCominfoBean = setShiftInfoBean(workTimeMap); + serialMap.put(serialid, shiftInfoCominfoBean); + } + + } + + private ShiftInfoCominfoBean setShiftInfoBean(Map workTimeMap) throws Exception { + + ShiftComIndex workComIndex = new WorkShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005306,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + ShiftComIndex restComIndex = new RestShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005307,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + ShiftComIndex halfComIndex = new HalfShiftComIndex(""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005308,weaver.general.ThreadVarLanguage.getLang())+"",workTimeMap); + //鍒涘缓鎵ц閾 + //鍓嶄竴澶╃殑閮芥墽琛屽畬浜嗭紝鍘昏幏鍙栧綋澶╁伐浣滄椂娈碉紝鍐嶆墽琛屽崐澶╃殑瑙勫垯 + workComIndex.setDuration(restComIndex); + //鎵ц瀹屼簡鍗婂ぉ鐨勮鍒欙紝鍐嶆渶鍚庡垽鏂紤鎭殑鏃舵 + restComIndex.setDuration(halfComIndex); + + ShiftInfoCominfoBean shiftInfoCominfoBean = new ShiftInfoCominfoBean(); + + workComIndex.handleDuration(shiftInfoCominfoBean); + return shiftInfoCominfoBean; + } + + /** + * 鑰冨嫟鎸夐挳 + * @param workdate + * @param serialidInfo + * @param containYesterday + * @return + */ + public Map getWorkButton(String workdate,Map serialidInfo, boolean containYesterday){ + Map shiftMap = new HashMap<>(); + + //鑰冨嫟鎸夐挳杩樻槸璧扮紦瀛 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + String serialid = Util.null2String(serialidInfo.get(workdate)); + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + if(containYesterday){ + if(Util.getIntValue(preSerialid) > 0){ + ShiftInfoCominfoBean pre_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(preSerialid); + List timelineList = pre_shiftInfoCominfoBean.getTimelineList(); + if(timelineList!=null && !timelineList.isEmpty()){ + shiftMap.put("pre_timelineList", timelineList); + } + shiftMap.put("pre_isAcross", pre_shiftInfoCominfoBean.getIsAcross()); + shiftMap.put("pre_allWorkTime", pre_shiftInfoCominfoBean.getAllWorkTime()); + shiftMap.put("pre_allAcrossWorkTime", pre_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftMap.put("pre_signTime", pre_shiftInfoCominfoBean.getSignWorkTime()); + shiftMap.put("pre_restTime", pre_shiftInfoCominfoBean.getRestAcrossLongTime()); + } + } + if(Util.getIntValue(serialid) > 0){ + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = kqShiftManagementRedis.getShiftInfoBean(serialid); + Map shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false); + List timelineList = cur_shiftInfoCominfoBean.getTimelineList(); + if(timelineList!=null && !timelineList.isEmpty()){ + shiftMap.put("timelineList", timelineList); + } + shiftMap.put("isAcross", cur_shiftInfoCominfoBean.getIsAcross()); + shiftMap.put("allWorkTime", cur_shiftInfoCominfoBean.getAllWorkTime()); + shiftMap.put("allAcrossWorkTime", cur_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime()); + shiftMap.put("restTime", cur_shiftInfoCominfoBean.getRestAcrossLongTime()); + if(shiftRuleMap != null && !shiftRuleMap.isEmpty()){ + shiftMap.put("shiftRuleMap", shiftRuleMap); + } + } + } + + return shiftMap; + } + + /** + * 娴佺▼璁$畻鐢ㄧ殑 + * @param workdate + * @param serialidInfo + * @param containYesterday + * @return + * shiftInfoBean 姣忎竴澶╁唴鍚湁鐨勭彮娆¢兘鎷嗗垎鍑烘潵,鍖呭惈鏄ㄥぉ鐝鍦ㄤ粖澶╃殑鏃舵0-24灏忔椂鍒剁殑 + * shiftLongInfoBean 褰撳ぉ鐨勭彮娆℃暟鎹紝0-48灏忔椂鍒跺害鐨 + */ + public Map getWorkDuration(String workdate,Map serialidInfo,boolean containYesterday){ + + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map dateWorkTimeMap = new HashMap<>(); + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + String serialid = Util.null2String(serialidInfo.get(workdate)); + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setPreSplitDate(preSplitDate); + shiftInfoBean.setSplitDate(workdate); + shiftInfoBean.setD_Mins(0.0); + shiftInfoBean.setPreSerialid(preSerialid); + shiftInfoBean.setSerialid(serialid); + if(containYesterday){ + if(Util.getIntValue(serialid) > 0 || Util.getIntValue(preSerialid) > 0){ + fillShiftInfoBean(shiftInfoBean, preSerialid, serialid); + dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean); + } + }else{ + if(Util.getIntValue(serialid) > 0){ + fillShiftInfoBean(shiftInfoBean, preSerialid, serialid); + dateWorkTimeMap.put("shiftInfoBean", shiftInfoBean); + } + } + } + + return dateWorkTimeMap; + } + + /** + * 鏍规嵁鐝id鑾峰彇瀵瑰簲鏃ユ湡鐨勪笂涓嬬彮鏃堕棿+浼戞伅鏃堕棿 + * @param workdate + * @param serialidInfo + * @return + */ + public Map getWorkTimeMap(String workdate,Map serialidInfo){ + + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + Map dateWorkTimeMap = new HashMap<>(); + LocalDate preLocalDate = LocalDate.parse(workdate); + String preSplitDate = ""; + preLocalDate = preLocalDate.minusDays(1); + preSplitDate = preLocalDate.format(dateFormatter); + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String preSerialid = Util.null2String(serialidInfo.get(preSplitDate)); + String serialid = Util.null2String(serialidInfo.get(workdate)); + getShiftInfoBeanMap(dateWorkTimeMap,preSerialid, serialid); + } + + return dateWorkTimeMap; + } + + /** + * 鏍规嵁鑰冨嫟鎶ヨ〃闇瑕佺殑 杩斿洖鐩稿簲鏍煎紡鐨勬暟鎹 + * @param dateWorkTimeMap + * @param preSerialid + * @param serialid + */ + private void getShiftInfoBeanMap(Map dateWorkTimeMap,String preSerialid, String serialid) { + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + + if(cur_shiftInfoCominfoBean != null){ + dateWorkTimeMap.put("restTime",cur_shiftInfoCominfoBean.getRestAcrossLongTime()); + dateWorkTimeMap.put("workTime",cur_shiftInfoCominfoBean.getWorkAcrossLongTime()); + dateWorkTimeMap.put("workMins",cur_shiftInfoCominfoBean.getWorkmins()); + dateWorkTimeMap.put("isAcross",cur_shiftInfoCominfoBean.getIsAcross()); + dateWorkTimeMap.put("signTime", cur_shiftInfoCominfoBean.getSignWorkTime()); + } + } + + /** + * 姣忔鑾峰彇鐨勮瘽閮介渶瑕佽幏鍙栨槰澶╁拰浠婂ぉ鐨勭彮娆℃暟鎹 + * @param shiftInfoBean + * @param preSerialid 鏄ㄥぉ鐨勭彮娆 + * @param serialid 浠婂ぉ鐨勭彮娆 + */ + private void fillShiftInfoBean(ShiftInfoBean shiftInfoBean,String preSerialid,String serialid){ + ShiftInfoCominfoBean pre_shiftInfoCominfoBean = getShiftInfoCominfoBean(preSerialid); + ShiftInfoCominfoBean cur_shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + Map pre_shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(preSerialid,false); + Map shiftRuleMap = ShiftManagementToolKit.getShiftRuleInfo(serialid,false); + + //鎶婂墠涓涓彮娆$殑濉厖濂 + if(pre_shiftInfoCominfoBean != null){ + shiftInfoBean.setPreWorkIndex(pre_shiftInfoCominfoBean.getPreWorkTimeIndex()); + shiftInfoBean.setPreWorkAcrossIndex(pre_shiftInfoCominfoBean.getWorkAcrossTimeIndex()); + shiftInfoBean.setPreWorkMinsAcrossIndex(pre_shiftInfoCominfoBean.getWorkPunchMins()); + shiftInfoBean.setPreRestIndex(pre_shiftInfoCominfoBean.getPreRestTimeIndex()); + shiftInfoBean.setPreHalfWorkIndex(pre_shiftInfoCominfoBean.getHalfWorkIndex()); + shiftInfoBean.setPreWorkmins(pre_shiftInfoCominfoBean.getWorkmins()); + shiftInfoBean.setPreAllWorkTime(pre_shiftInfoCominfoBean.getAllWorkTime()); + shiftInfoBean.setPreAllAcrossWorkTime(pre_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftInfoBean.setPreAllRestTime(pre_shiftInfoCominfoBean.getAllRestTime()); + shiftInfoBean.setPreAllAcrossRestTime(pre_shiftInfoCominfoBean.getAllAcrossRestTime()); + shiftInfoBean.setPreSerialid(preSerialid); + shiftInfoBean.setIsPreAcross(pre_shiftInfoCominfoBean.getIsAcross()); + shiftInfoBean.setShiftRuleMap(pre_shiftRuleMap); + } + + //鎶婂綋鍓嶇彮娆$殑濉厖濂 + if(cur_shiftInfoCominfoBean != null){ + shiftInfoBean.setWorkIndex(cur_shiftInfoCominfoBean.getWorkTimeIndex()); + shiftInfoBean.setWorkAcrossIndex(cur_shiftInfoCominfoBean.getWorkAcrossTimeIndex()); + shiftInfoBean.setWorkMinsAcrossIndex(cur_shiftInfoCominfoBean.getWorkPunchMins()); + shiftInfoBean.setRestIndex(cur_shiftInfoCominfoBean.getRestTimeIndex()); + shiftInfoBean.setHalfWorkIndex(cur_shiftInfoCominfoBean.getHalfWorkIndex()); + shiftInfoBean.setWorkmins(cur_shiftInfoCominfoBean.getWorkmins()); + shiftInfoBean.setAllWorkTime(cur_shiftInfoCominfoBean.getAllWorkTime()); + shiftInfoBean.setAllAcrossWorkTime(cur_shiftInfoCominfoBean.getAllAcrossWorkTime()); + shiftInfoBean.setAllRestTime(cur_shiftInfoCominfoBean.getAllRestTime()); + shiftInfoBean.setAllAcrossRestTime(cur_shiftInfoCominfoBean.getAllAcrossRestTime()); + shiftInfoBean.setAllLongWorkTime(cur_shiftInfoCominfoBean.getAllLongWorkTime()); + shiftInfoBean.setRestLongTimeIndex(cur_shiftInfoCominfoBean.getRestLongTimeIndex()); + shiftInfoBean.setWorkLongTimeIndex(cur_shiftInfoCominfoBean.getWorkLongTimeIndex()); + shiftInfoBean.setIsAcross(cur_shiftInfoCominfoBean.getIsAcross()); + shiftInfoBean.setSerialid(serialid); + shiftInfoBean.setShiftRuleMap(shiftRuleMap); + + if(cur_shiftInfoCominfoBean.getWorkAcrossLongTime() != null){ + List workTime1 = cur_shiftInfoCominfoBean.getWorkAcrossLongTime().stream().collect(Collectors.toList()); + List lsWorkTime = new KQWorkTime().formatTimeScope(workTime1, false); + shiftInfoBean.setWorkTime(lsWorkTime); + } + if(cur_shiftInfoCominfoBean.getSignWorkTime() != null){ + List signTime1 = cur_shiftInfoCominfoBean.getSignWorkTime().stream().collect(Collectors.toList()); + List lsSignTime = new KQWorkTime().formatTimeScope(signTime1, true); + shiftInfoBean.setSignTime(lsSignTime); + } + shiftInfoBean.setHalfcalrule(cur_shiftInfoCominfoBean.getHalfcalrule()); + shiftInfoBean.setHalfcalpoint(cur_shiftInfoCominfoBean.getHalfcalpoint()); + shiftInfoBean.setHalfcalpoint2cross(cur_shiftInfoCominfoBean.getHalfcalpoint2cross()); + shiftInfoBean.setWorkAcrossTime(cur_shiftInfoCominfoBean.getWorkAcrossTime()); + shiftInfoBean.setEachWorkMins(cur_shiftInfoCominfoBean.getEachWorkMins()); + } + } + + public void removeShiftManagementCache(){ + KQShiftRestTimeSectionComInfo kqShiftRestTimeSectionComInfo = new KQShiftRestTimeSectionComInfo(); + KQShiftOnOffWorkSectionComInfo kqShiftOnOffWorkSectionComInfo = new KQShiftOnOffWorkSectionComInfo(); + kqShiftRestTimeSectionComInfo.removeShiftRestTimeSectionCache(); + kqShiftOnOffWorkSectionComInfo.removeShiftWorkSectionCache(); + super.removeCache(); + //鏀圭敤redis鍜宻taticobj鐨勬柟寮 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + kqShiftManagementRedis.resetShiftValWithRedis(); + } + + /** + * 鏍规嵁鐝鑾峰彇shiftInfoCominfoBean + * @param serialid + * @return + */ + public ShiftInfoCominfoBean getShiftInfoCominfoBean(String serialid){ +// Object object = getObjValue(shiftbean, serialid); +// if(object != null){ +// return (ShiftInfoCominfoBean) object; +// }else{ +// return null; +// } + //鏀圭敤redis鍜宻taticobj鐨勬柟寮 + KQShiftManagementRedis kqShiftManagementRedis = new KQShiftManagementRedis(); + return kqShiftManagementRedis.getShiftInfoBeanMapBySql(serialid); + } + + /** + * 鏍规嵁浜哄憳鍜屾棩鏈熻幏鍙杝hiftInfoCominfoBean + * @param workdate + * @param serialidInfo + * @return + */ + public ShiftInfoCominfoBean getShiftInfoCominfoBean(String workdate,Map serialidInfo){ + ShiftInfoCominfoBean shiftInfoCominfoBean = null; + if(serialidInfo != null && !serialidInfo.isEmpty()){ + String serialid = Util.null2String(serialidInfo.get(workdate)); + if(Util.getIntValue(serialid) > 0){ + shiftInfoCominfoBean = getShiftInfoCominfoBean(serialid); + } + } + return shiftInfoCominfoBean; + } + +} diff --git a/src/com/engine/kq/biz/KQWorkTime.java b/src/com/engine/kq/biz/KQWorkTime.java new file mode 100644 index 0000000..9694bdb --- /dev/null +++ b/src/com/engine/kq/biz/KQWorkTime.java @@ -0,0 +1,413 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.entity.KQGroupEntity; +import com.engine.kq.entity.TimeScopeEntity; +import com.engine.kq.entity.TimeSignScopeEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.resource.ResourceComInfo; + +import java.util.*; + +public class KQWorkTime extends BaseBean { + private KQLog kqLog = new KQLog(); + private boolean isFormat = false; + + public WorkTimeEntity getWorkTime(String userId) { + return getWorkTime(userId, null); + } + + /** + * 鍒ゆ柇鏄惁鏄伐浣滄棩 + * @param userId + * @param workdate + * @return + */ + public boolean isWorkDay(String userId, String workdate) { + boolean isWorkDay = false; + if(!KQHolidaySetBiz.isHoliday(userId,workdate)) {//涓嶆槸鑺傚亣鏃ワ紝涓旀湁鐝 + Map serialInfo = getSerialInfo( userId, workdate, false); + if(!serialInfo.isEmpty()){ + if(Util.null2String(serialInfo.get("kqType")).equals("3")){ + Map result = (Map) serialInfo.get(workdate); + if(result!=null && result.size()>0 && Util.null2String(result.get("signStart")).length()>0 && Util.null2String(result.get("workMins")).length()>0){ + isWorkDay = true; + } + }else{ + int serialid = Util.getIntValue(Util.null2String(serialInfo.get(workdate)), 0); + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + int restShift = StringUtil.parseToInt(kQShiftManagementComInfo.getRestShift(String.valueOf(serialid)), 0); + isWorkDay = restShift == 1 ? false : serialid > 0; + } + } + } + return isWorkDay; + } + + public Map getWorkButton(String userId, String workdate, boolean containYesterday) { + Map result = new HashMap<>(); + try { + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + Map serialInfo = getSerialInfo(userId, workdate, containYesterday); + kqLog.info("鑰冨嫟缁勮幏鍙栨垚鍛樻墍鍦ㄧ殑鐝 getWorkButton:serialInfo:"+ serialInfo); + String kqType = Util.null2String(serialInfo.get("kqType")); + if(serialInfo!=null&&serialInfo.size()>0){ + if("3".equalsIgnoreCase(kqType)){ + //鑷敱鐝埗鐨勫崟鐙鐞 + result = (Map) serialInfo.get(workdate); + if(result != null && !result.isEmpty()){ + result.put("isfree", "1"); + }else{ + result = new HashMap<>(); + } + }else{ + result = kQShiftManagementComInfo.getWorkButton(workdate,serialInfo,containYesterday); + kqLog.info("鑰冨嫟缁勮幏鍙栨垚鍛樻墍鍦ㄧ殑鐝 getWorkButton:result:"+ JSON.toJSONString(result)); + } + } + } catch (Exception e) { + writeLog(e); + } + return result; + } + + /** + * + * 鑾峰彇浠婂ぉ鎵鍚彮娆$殑鑰冨嫟鏃堕棿锛堝寘鍚粖澶╁拰鏄ㄥぉ鐨勶級 + * @param userId + * @param workdate + * @param containYesterday + * @param isLog 鏄惁璁板綍鏃ュ織 + * @return + */ + public Map getWorkDuration(String userId, String workdate,boolean containYesterday,boolean isLog) { + Map result = new HashMap<>(); + try { + Map workTimeMap = null; + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + Map serialInfo = getSerialInfo(userId, workdate, true); + writeLog("getWorkDuration-serialInfo-" + userId + "-" + workdate + serialInfo); + if(isLog){ + kqLog.info("鑰冨嫟缁勮幏鍙栨垚鍛樻墍鍦ㄧ殑鐝 getWorkDuration:"+serialInfo); + } + if(serialInfo!=null&&serialInfo.size()>0){ + String kqType = Util.null2String(serialInfo.get("kqType")); + if("3".equalsIgnoreCase(kqType)){ + //鑷敱鐝埗鐨勫崟鐙鐞 + result = (Map) serialInfo.get(workdate); + if(result != null && !result.isEmpty()){ + result.put("isfree", "1"); + }else{ + result = new HashMap<>(); + } + }else{ + workTimeMap = kQShiftManagementComInfo.getWorkDuration(workdate,serialInfo,containYesterday); + if(workTimeMap!=null){ + if(isLog) { + kqLog.info( + "鑰冨嫟缁勮幏鍙栨垚鍛樻墍鍦ㄧ殑鐝 getWorkDuration:workTimeMap:" + JSON.toJSONString(workTimeMap)); + } + result.put("shiftInfoBean",workTimeMap.get("shiftInfoBean")); + } + } + } + } catch (Exception e) { + writeLog(e); + } + return result; + } + + /** + * 鑾峰彇浠婂ぉ鎵鍚彮娆$殑鑰冨嫟鏃堕棿锛堝寘鍚粖澶╁拰鏄ㄥぉ鐨勶級 + * @param userId + * @param workdate + * @param containYesterday + * @return + */ + public Map getWorkDuration(String userId, String workdate,boolean containYesterday) { + return getWorkDuration(userId,workdate,containYesterday,true); + } + + /** + * 鑾峰彇浠婂ぉ鎵鍚彮娆$殑鑰冨嫟鏃堕棿锛堜粖澶╃殑锛 + * @param userId + * @param workdate + * @return + */ + public ShiftInfoCominfoBean getShiftInfoCominfoBean(String userId, String workdate) { + ShiftInfoCominfoBean shiftInfoCominfoBean = null; + try { + Map workTimeMap = null; + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + Map serialInfo = getSerialInfo(userId, workdate, false); + + if(serialInfo!=null&&serialInfo.size()>0){ + shiftInfoCominfoBean = kQShiftManagementComInfo.getShiftInfoCominfoBean(workdate,serialInfo); + } + } catch (Exception e) { + writeLog(e); + } + return shiftInfoCominfoBean; + } + + /** + * 鑾峰彇鑰冨嫟鏃堕棿 + * @param userId + * @param workdate + * @return + */ + public WorkTimeEntity getWorkTime(String userId, String workdate) { + WorkTimeEntity workTimeEntity = new WorkTimeEntity(); + try { + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + Map serialInfo = getSerialInfo(userId, workdate, false); + workTimeEntity.setIsExclude(Util.null2String(serialInfo.get("isExclude")).equals("1")); + workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId"))); + if(serialInfo!=null&&serialInfo.size()>0) { + String kqType = Util.null2String(serialInfo.get("kqType")); + if(kqType.equals("3")){ + Map map = (Map)serialInfo.get(workdate); + workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId"))); + workTimeEntity.setGroupName(Util.null2String(serialInfo.get("groupName"))); + workTimeEntity.setKQType(Util.null2String(kqType)); + workTimeEntity.setIsExclude(Util.null2String(serialInfo.get("isExclude")).equals("1")); + if(map!=null) { + workTimeEntity.setSignStart(Util.null2String(map.get("signStart"))); + workTimeEntity.setWorkMins(Util.getIntValue(Util.null2String(map.get("workMins")))); + workTimeEntity.setCalmethod(Util.null2String(map.get("calmethod"))); + } + workTimeEntity.setRestShift(0); + }else{ + int serialid = Util.getIntValue(Util.null2String(serialInfo.get(workdate)), 0); + int restShift = StringUtil.parseToInt(kQShiftManagementComInfo.getRestShift(String.valueOf(serialid)), 0); + if(kqType.equals("1") && KQHolidaySetBiz.isHoliday(userId,workdate)) restShift = 1; + workTimeEntity.setRestShift(restShift); + if (serialid > 0){ + Map dateWorkTimeMap = kQShiftManagementComInfo.getWorkTimeMap(workdate, serialInfo); + workTimeEntity.setGroupId(Util.null2String(serialInfo.get("groupId"))); + workTimeEntity.setGroupName(Util.null2String(serialInfo.get("groupName"))); + workTimeEntity.setKQType(kqType); + workTimeEntity.setSerialId(""+serialid); + workTimeEntity.setRestTime(formatTimeScope((List)dateWorkTimeMap.get("restTime"),false)); + workTimeEntity.setShiftRuleInfo(ShiftManagementToolKit.getShiftRuleInfo(""+serialid,true)); + workTimeEntity.setSignTime(formatTimeScope((List)dateWorkTimeMap.get("signTime"),false)); + workTimeEntity.setWorkTime(formatTimeScope((List)dateWorkTimeMap.get("workTime"),true)); + if(restShift != 1) { + workTimeEntity.setWorkMins(Util.getIntValue(Util.null2String(dateWorkTimeMap.get("workMins")))); + } + workTimeEntity.setIsAcross(Util.null2String(dateWorkTimeMap.get("isAcross"))); + } + } + } + } catch (Exception e) { + writeLog(e); + } + return workTimeEntity; + } + + public List formatTimeScope(List timeScope, boolean needWorkMins){ + List timeScopes = new ArrayList<>(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + TimeScopeEntity timeScopeEntity = null; + for(int i=0;timeScope!=null && i obj = (Map)timeScope.get(i); + String bengintime_end = Util.null2String(obj.get("bengintime_end")); + String bengintime_end_across = Util.null2String(obj.get("bengintime_end_across")); + String endtime_start = Util.null2String(obj.get("endtime_start")); + String endtime_start_across = Util.null2String(obj.get("endtime_start_across")); + String bengintime_pre_across = Util.null2String(obj.get("bengintime_pre_across")); + timeScopeEntity = new TimeScopeEntity(); + timeScopeEntity.setBeginTime(Util.null2String(obj.get("bengintime"))); + timeScopeEntity.setBeginTimeAcross(Util.null2String(obj.get("bengintime_across")).equals("1"));//鏍囪鏄惁璺ㄥぉ + timeScopeEntity.setEndTime(Util.null2String(obj.get("endtime"))); + timeScopeEntity.setEndTimeAcross(Util.null2String(obj.get("endtime_across")).equals("1"));//鏍囪鏄惁璺ㄥぉ + timeScopeEntity.setBeginTimePreAcross("1".equalsIgnoreCase(bengintime_pre_across)); + + if(needWorkMins) { + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(timeScopeEntity.getBeginTime()); + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(timeScopeEntity.getEndTime()); + timeScopeEntity.setWorkMins(workEndIdx - workBeginIdx); + } + if((bengintime_end != null && bengintime_end.length() >0) || (endtime_start != null && endtime_start.length() > 0)){ + TimeSignScopeEntity timeSignScopeEntity = new TimeSignScopeEntity(); + timeSignScopeEntity.setBeginTimeEnd(bengintime_end); + timeSignScopeEntity.setBeginTimeEndAcross("1".equalsIgnoreCase(bengintime_end_across)); + timeSignScopeEntity.setEndTimeStart(endtime_start); + timeSignScopeEntity.setEndTimeStartAcross("1".equalsIgnoreCase(endtime_start_across)); + timeSignScopeEntity.setBeginTimePreAcross("1".equalsIgnoreCase(bengintime_pre_across)); + timeScopeEntity.setTimeSignScopeEntity(timeSignScopeEntity); + } + timeScopes.add(timeScopeEntity); + } + return timeScopes; + } + + /** + * 鑾峰彇褰撳ぉ鐝 + * @param userId + * @param workdate + * @return + */ + public String getSerialIds(String userId, String workdate) { + Map serialInfo = getSerialInfo( userId, workdate, false); + return serialInfo!=null?Util.null2String(serialInfo.get(workdate)):""; + } + + /** + * 鑾峰彇鐝淇℃伅 鑾峰彇椤哄簭 宸ヤ綔鏃ヨ皟鏁淬佹帓鐝佸浐瀹氱彮鍜屽懆鏈熺彮 + * @param userId + * @param workdate + * @param containYesterday + * @return + */ + public Map getSerialInfo(String userId, String workdate, boolean containYesterday) { + Map serialInfo = new HashMap<>(); + String preworkdate = ""; + try { + KQGroupMemberComInfo groupMemberComInfo = new KQGroupMemberComInfo(); + groupMemberComInfo.setIsFormat(this.isFormat); + KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo(); + kqFixedSchedulceComInfo.setFormat(this.isFormat); + KQShiftScheduleComInfo kqShiftScheduleComInfo = new KQShiftScheduleComInfo(); + kqShiftScheduleComInfo.setFormat(this.isFormat); + KQGroupEntity kqGroupEntity = groupMemberComInfo.getUserKQGroupInfo(userId,workdate); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + + preworkdate = DateUtil.addDate(workdate,-1); + if(containYesterday){ + Map pre_serialInfo = getSerialInfo(userId, preworkdate, false); + if(pre_serialInfo != null && !pre_serialInfo.isEmpty()){ + if(pre_serialInfo.containsKey(preworkdate)){ + serialInfo.put(preworkdate,pre_serialInfo.get(preworkdate));//鑾峰彇鍓嶄竴澶╃殑鐝 + } + } + } + + if(kqGroupEntity==null){//涓嶅湪鑰冨嫟缁勫唴 + return serialInfo; + } + + + //鏃犻渶鑰冨嫟浜哄憳闇瑕佽绠楄冨嫟鏃堕棿锛屼絾涓嶈绠楀紓甯哥姸鎬 +// if (("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + userId + ",")>-1) {//鎺掗櫎浜哄憳鏃犻渶璁$畻鑰冨嫟鏃堕棿 +// return serialInfo; +// } + + if (("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + userId + ",")>-1) {//鎺掗櫎浜哄憳鏃犻渶璁$畻鑰冨嫟鏃堕棿 + serialInfo.put("isExclude","1"); + } + + String begindate = Util.null2String(resourceComInfo.getCreatedate(userId)).trim(); + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(userId)).trim(); + if(companyStartDate.length()!=10){ + companyStartDate = ""; + } + if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){ + begindate=companyStartDate; + } + if(begindate.length()>0 && DateUtil.compDate(begindate,workdate)<0 ){//浜哄憳鍏ヨ亴鏃ユ湡鍓嶆棤闇璁$畻鑰冨嫟锛屽鏋滄病鏈夊叆鑱屾棩鏈燂紝宸插垱寤烘棩鏈熶负鍑 +// kqLog.writeLog("getSerialInfo 鍏ヨ亴鏃ユ湡涓嶆弧瓒虫潯浠:userId:"+userId+":workdate:"+workdate+":companyStartDate:"+companyStartDate+":begindate:"+begindate+":DateUtil.compDate(begindate,workdate):"+DateUtil.compDate(begindate,workdate)); + return serialInfo; + } + + String endDate = Util.null2String(resourceComInfo.getEndDate(userId)); + + String status = Util.null2String(resourceComInfo.getStatus(userId)); + if(status.equals("0")||status.equals("1")||status.equals("2")||status.equals("3")){ + //鍦ㄨ亴 + }else{ + //鍏朵粬鐘舵 + if(endDate.length()>0 && DateUtil.compDate(endDate,workdate)>0){//浜哄憳鍚堝悓缁撴潫鏃ユ湡鏃犻渶璁$畻鑰冨嫟 +// kqLog.writeLog("getSerialInfo 浜哄憳鍚堝悓缁撴潫鏃ユ湡涓嶆弧瓒虫潯浠:userId:"+userId+":workdate:"+workdate+":endDate:"+endDate+":status:"+status+":DateUtil.compDate(endDate,workdate):"+DateUtil.compDate(endDate,workdate)); + return serialInfo; + } + } + + String groupid = kqGroupEntity.getId(); + String groupname = kqGroupEntity.getGroupname(); + String kqtype = kqGroupEntity.getKqtype(); + int dayOfweek = DateUtil.getWeek(workdate)-1; + int preDayOfweek = DateUtil.getWeek(preworkdate)-1; + boolean preDayIsHoliday = KQHolidaySetBiz.isHoliday(userId,preworkdate); + boolean isHoliday = KQHolidaySetBiz.isHoliday(userId,workdate); + String serialid = ""; + + if(!kqtype.equals("2")){//澶勭悊璋冮厤宸ヤ綔鏃(闄ゆ帓鐝) + if(KQHolidaySetBiz.getChangeType(groupid,preworkdate)==2){ + preDayOfweek = KQHolidaySetBiz.getRelatedDay(userId,preworkdate); + } + + if(KQHolidaySetBiz.getChangeType(groupid,workdate)==2){ + dayOfweek = KQHolidaySetBiz.getRelatedDay(userId,workdate); + } + } + serialInfo.put("groupId",groupid); + serialInfo.put("groupName",groupname); + serialInfo.put("kqType",kqtype); + serialInfo.put("isHoliday",isHoliday); + if (kqtype.equals("1")) {//鍥哄畾鐝 +// if(containYesterday && !serialInfo.containsKey(preworkdate)) { +// serialid = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupid,preDayOfweek)); +// if(!preDayIsHoliday&&serialid.length()>0 && Util.getIntValue(serialid) > 0){ +// serialInfo.put(preworkdate,serialid);//鑾峰彇鍓嶄竴澶╃殑鐝 +// } +// } + if(!serialInfo.containsKey(workdate)){ + serialid = Util.null2String(kqFixedSchedulceComInfo.getSerialid(groupid,dayOfweek)); + if( !isHoliday&&serialid.length()>0 && Util.getIntValue(serialid) > 0){ + serialInfo.put(workdate, serialid);//鑾峰彇褰撳ぉ鐨勭彮娆 + } + } + } else if (kqtype.equals("2")) {//鎺掔彮 + //鍏堝彇鎺掔彮璁剧疆閲岀殑鐝 +// serialid = Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,preworkdate)); +// if(containYesterday && serialid.length()>0 && !preDayIsHoliday && Util.getIntValue(serialid) > 0){ +// serialInfo.put(preworkdate,Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,preworkdate)));//鑾峰彇鍓嶄竴澶╃殑鐝 +// } + serialid = Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,workdate)); + if(serialid.length()>0 && !isHoliday && Util.getIntValue(serialid) > 0){ + serialInfo.put(workdate,Util.null2String(kqShiftScheduleComInfo.getSerialId(userId,workdate)));//鑾峰彇褰撳ぉ鐨勭彮娆 + } + } else if (kqtype.equals("3")) {//鑷敱鐝 + List weekDay = Util.splitString2List(kqGroupEntity.getWeekday(), ","); + String signStart = Util.null2String(kqGroupEntity.getSignstart());//绛惧埌寮濮嬫椂闂 + int workMins = Util.getIntValue(Util.getIntValues(""+Util.getDoubleValue(Util.null2String(kqGroupEntity.getWorkhour()))*60));//宸ヤ綔鏃堕暱 + if(signStart.length()>0 && workMins>0) { + String calmethod = Util.null2s(kqGroupEntity.getCalmethod(),"2"); + Map map = null; + if (weekDay.contains(""+preDayOfweek) && !preDayIsHoliday) {//鍓嶄竴澶 + map = new HashMap<>(); + map.put("signStart", signStart); + map.put("workMins", workMins); + map.put("calmethod", calmethod); + serialInfo.put(preworkdate, map); + } + if (weekDay.contains(""+dayOfweek) && !isHoliday) {//褰撳墠澶 + map = new HashMap<>(); + map.put("signStart", signStart); + map.put("workMins", workMins); + map.put("calmethod", calmethod); + serialInfo.put(workdate, map); + } + } + } + } catch (Exception e) { + writeLog(e); + } + return serialInfo; + } + + + public void setIsFormat(boolean isFormat){ + this.isFormat = isFormat; + } +} \ No newline at end of file diff --git a/src/com/engine/kq/cmd/attendanceEvent/GetLeaveWorkDurationCmd.java b/src/com/engine/kq/cmd/attendanceEvent/GetLeaveWorkDurationCmd.java new file mode 100644 index 0000000..edb778f --- /dev/null +++ b/src/com/engine/kq/cmd/attendanceEvent/GetLeaveWorkDurationCmd.java @@ -0,0 +1,78 @@ +package com.engine.kq.cmd.attendanceEvent; + +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQGroupMemberComInfo; +import com.engine.kq.biz.KQLeaveRulesBiz; +import com.engine.kq.enums.DurationTypeEnum; +import com.engine.kq.util.KQDurationCalculatorUtil; +import java.util.HashMap; +import java.util.Map; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +/** + * 璇峰亣鐢ㄧ殑鏃堕暱璁$畻 + */ +public class GetLeaveWorkDurationCmd extends AbstractCommonCommand> { + + public GetLeaveWorkDurationCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String newLeaveType = Util.null2String(params.get("newLeaveType")); + String resourceId = Util.null2String(params.get("resourceId")); + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String fromTime = Util.null2String(params.get("fromTime")); + String toTime = Util.null2String(params.get("toTime")); + String timestamp = Util.null2String(params.get("timestamp")); + + ResourceComInfo rci = new ResourceComInfo(); + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupid = kqGroupMemberComInfo.getKQGroupId(resourceId,fromDate); + if(resourceId.length() > 0 && groupid.length() == 0){ + retmap.put("status", "-1"); + retmap.put("message", rci.getLastname(resourceId)+","+fromDate+""+ SystemEnv.getHtmlLabelName(10005329,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + + String durationrule = Util.null2String(KQLeaveRulesBiz.getMinimumUnit(newLeaveType)); + String computingMode = Util.null2String(KQLeaveRulesBiz.getComputingMode(newLeaveType)); + + KQDurationCalculatorUtil kqDurationCalculatorUtil =new KQDurationCalculatorUtil.DurationParamBuilder(resourceId). + fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime). + newLeaveTypeParam(newLeaveType).durationRuleParam(durationrule). + computingModeParam(computingMode).durationTypeEnumParam(DurationTypeEnum.LEAVE).build(); + + Map durationMap = kqDurationCalculatorUtil.getWorkDuration(); + + retmap.put("duration", Util.null2String(durationMap.get("duration"))); + retmap.put("min_duration", Util.null2String(durationMap.get("min_duration"))); + retmap.put("timestamp", timestamp); + retmap.put("status", "1"); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/attendanceEvent/GetOverTimeWorkDurationCmd.java b/src/com/engine/kq/cmd/attendanceEvent/GetOverTimeWorkDurationCmd.java new file mode 100644 index 0000000..fef8836 --- /dev/null +++ b/src/com/engine/kq/cmd/attendanceEvent/GetOverTimeWorkDurationCmd.java @@ -0,0 +1,196 @@ +package com.engine.kq.cmd.attendanceEvent; + +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQGroupMemberComInfo; +import com.engine.kq.biz.KQOvertimeRulesBiz; +import com.engine.kq.biz.KQWorkTime; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.enums.DurationTypeEnum; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.TimeRangeCalculator; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +/** + * 鍔犵彮鐢ㄧ殑鏃堕暱璁$畻 + */ +public class GetOverTimeWorkDurationCmd extends AbstractCommonCommand> { + + public GetOverTimeWorkDurationCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + BaseBean bb = new BaseBean(); + String resourceId = Util.null2String(params.get("resourceId")); + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String fromTime = Util.null2String(params.get("fromTime")); + String toTime = Util.null2String(params.get("toTime")); + String overtime_type = Util.null2String(params.get("overtime_type")); + String timestamp = Util.null2String(params.get("timestamp")); + bb.writeLog("璁$畻鏃堕暱"); + int minimumUnit = KQOvertimeRulesBiz.getMinimumUnit(); + // + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity kqWorkTimeEntity = kqWorkTime.getWorkTime(resourceId, fromDate); + if (kqWorkTimeEntity != null) { + String kqType = Util.null2String(kqWorkTimeEntity.getKQType()); + if ("3".equalsIgnoreCase(kqType)) { + writeLog("鑷敱鐝埗涓嶈绠楀姞鐝"); + retmap.put("status", "1"); + retmap.put("message", "" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005330, weaver.general.ThreadVarLanguage.getLang()) + ""); + return retmap; + } + } + + //浼戠彮娆$殑鍔犵彮鏃堕暱 + String restSerialValue = ""; + restSerialValue = isRestSerialCalculate(resourceId, kqWorkTime); + if (StringUtils.isNotEmpty(restSerialValue)) { + retmap.put("duration", restSerialValue); + retmap.put("timestamp", timestamp); + retmap.put("status", "1"); + return retmap; + } + + ResourceComInfo rci = new ResourceComInfo(); + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupid = kqGroupMemberComInfo.getKQGroupId(resourceId, fromDate); + bb.writeLog("璁$畻鏃堕暱groupid锛" + groupid); + if (resourceId.length() > 0 && groupid.length() == 0) { + retmap.put("status", "-1"); + retmap.put("message", rci.getLastname(resourceId) + "," + fromDate + "" + weaver.systeminfo.SystemEnv.getHtmlLabelName(10005329, weaver.general.ThreadVarLanguage.getLang()) + ""); + return retmap; + } + + bb.writeLog("璁$畻鏃堕暱fromDate锛" + fromDate + "toDate:" + toDate + "fromTime:" + fromTime + "toTime:" + toTime); + //鍔犵彮榛樿鏄伐浣滄棩鍔犵彮 + KQDurationCalculatorUtil kqDurationCalculatorUtil = new KQDurationCalculatorUtil.DurationParamBuilder(resourceId). + fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1"). + durationRuleParam(minimumUnit + "").durationTypeEnumParam(DurationTypeEnum.OVERTIME). + overtime_typeParam(overtime_type).build(); + + Map durationMap = kqDurationCalculatorUtil.getWorkDuration(); + + + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main", "glrygroupid"); + bb.writeLog("鑾峰彇褰撳墠浜哄憳groupId:" + groupid + "glrygroupid:" + glrygroupid); + String value = ""; + if (groupid.equals(glrygroupid)) { + bb.writeLog("鏄12灏忔椂鐝埗鐨勪汉"); + Double newValue = divide(String.valueOf(TimeUtil.timeInterval(fromDate + " " + fromTime + ":00", toDate + " " + toTime + ":00")), "3600"); + if (newValue > 0) { + value = String.valueOf(newValue); + } else { + value = "0.0"; + } + } else { + value = Util.null2String(durationMap.get("duration")); + } + + + bb.writeLog("璁$畻鏃堕暱timestamp锛" + timestamp); + bb.writeLog("璁$畻鏃堕暱durationMap锛" + JSONObject.toJSONString(durationMap)); + retmap.put("duration", value); + retmap.put("timestamp", timestamp); + retmap.put("status", "1"); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private String isRestSerialCalculate(String resourceId, KQWorkTime kqWorkTime) { + try { + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String fromTime = Util.null2String(params.get("fromTime")); + String toTime = Util.null2String(params.get("toTime")); + BigDecimal workTimeTotal = new BigDecimal(TimeUtil.timeInterval(fromDate + " " + fromTime + ":00", toDate + " " + toTime + ":00")); + BigDecimal restTimeCount = new BigDecimal(0); + //鍔犵彮鏄惁璺ㄥぉ + boolean isAcross = false; + if (toDate.compareTo(fromDate) > 0) { + isAcross = true; + } + Map serialInfo = kqWorkTime.getSerialInfo(resourceId, fromDate, false); + String serialId = (String) serialInfo.get(fromDate); + RecordSet rs = new RecordSet(); + RecordSet rs2 = new RecordSet(); + String querySql = "select rest_shift from kq_ShiftManagement where id=?"; + rs.executeQuery(querySql, serialId); + if (rs.next()) { + if (rs.getInt("rest_shift") == 1) { + String restStartSql = "select * from kq_ShiftRestTimeSections where serialid=? and resttype='start'"; + rs.executeQuery(restStartSql, serialId); + while (rs.next()) { + //浼戞伅寮濮嬫椂闂 + String startTime = rs.getString("time"); + String record1 = rs.getString("record1"); + //浼戞伅缁撴潫鏃堕棿 + String restEndSql = "select * from kq_ShiftRestTimeSections where record1=? and resttype='end'"; + rs2.executeQuery(restEndSql, record1); + rs2.next(); + String endTime = rs2.getString("time"); + if (isAcross) { + double restTime1 = TimeRangeCalculator.getRestTime(fromTime, "23:59", startTime, endTime); + double restTime2 = TimeRangeCalculator.getRestTime("00:00", toTime, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime1)); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime2)); + + } else { + double restTime = TimeRangeCalculator.getRestTime(fromTime, toTime, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime)); + } + } + } + } + Double workTotal = divide(workTimeTotal.subtract(restTimeCount).toString(), "3600"); + return workTotal.toString(); + } catch (Exception e) { + return null; + } + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + /** + * 鎻愪緵绮剧‘鐨勯櫎娉曡繍绠椼 + * + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static Double divide(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + +} diff --git a/src/com/engine/kq/cmd/report/ExportExcelCmd.java b/src/com/engine/kq/cmd/report/ExportExcelCmd.java new file mode 100644 index 0000000..00b989b --- /dev/null +++ b/src/com/engine/kq/cmd/report/ExportExcelCmd.java @@ -0,0 +1,764 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.util.ExcelUtil; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.UtilKQ; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class ExportExcelCmd extends AbstractCommonCommand> { + + private HttpServletRequest request; + private HttpServletResponse response; + private List lsFieldDataKey; + + public ExportExcelCmd(Map params, HttpServletRequest request, HttpServletResponse response, User user) { + this.user = user; + this.params = params; + this.request = request; + this.response = response; + this.lsFieldDataKey = new ArrayList<>(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQReportBiz kqReportBiz = new KQReportBiz(); + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial")); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect = Util.null2String(jsonObj.get("typeselect")); + if (typeselect.length() == 0) typeselect = "3"; + if (!typeselect.equals("") && !typeselect.equals("0") && !typeselect.equals("6")) { + if (typeselect.equals("1")) { + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + } else { + fromDate = TimeUtil.getDateByOption(typeselect, "0"); + toDate = TimeUtil.getDateByOption(typeselect, "1"); + } + } + //浜哄憳鐘舵 + String status = Util.null2String(jsonObj.get("status")); + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + List showColumns = Util.splitString2List(Util.null2String(jsonObj.get("showColumns")), ","); + showColumns.add("lastname"); + showColumns.removeIf(showColumn -> showColumn.trim().equals("")); + + List tmpShowColumns = new ArrayList<>(); + for (String showColumn : showColumns) { + tmpShowColumns.add(showColumn); + String cascadekey = ""; + if (showColumn.equals("beLate")) { + cascadekey = "beLateMins"; + } else if (showColumn.equals("leaveEearly")) { + cascadekey = "leaveEarlyMins"; + } else if (showColumn.equals("graveBeLate")) { + cascadekey = "graveBeLateMins"; + } else if (showColumn.equals("graveLeaveEarly")) { + cascadekey = "graveLeaveEarlyMins"; + } else if (showColumn.equals("absenteeism")) { + cascadekey = "absenteeismMins"; + } else if (showColumn.equals("overtime")) { + tmpShowColumns.add("overtime_4leave"); + tmpShowColumns.add("overtime_nonleave"); + tmpShowColumns.add("workingDayOvertime_nonleave"); + tmpShowColumns.add("workingDayOvertime_4leave"); + tmpShowColumns.add("restDayOvertime_nonleave"); + tmpShowColumns.add("restDayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_4leave"); + tmpShowColumns.add("holidayOvertime_nonleave"); + } + if (cascadekey.length() > 0) { + tmpShowColumns.add(cascadekey); + } + } + showColumns = tmpShowColumns; + + String rightSql = new KQReportBiz().getReportRight("1", "" + user.getUID(), "a"); + + LinkedHashMap workbook = new LinkedHashMap<>(); + List lsSheet = new ArrayList<>(); + Map sheet = null; + List titleList = new ArrayList<>(); + Map title = null; + List> dataList = new ArrayList<>(); + List data = null; + List> constraintList = null; + + sheet = new HashMap<>(); + sheet.put("sheetName", SystemEnv.getHtmlLabelName(390351, user.getLanguage())); + sheet.put("sheetTitle", SystemEnv.getHtmlLabelName(390351, user.getLanguage())); + boolean isEnd = false; + Calendar cal = DateUtil.getCalendar(); + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue; + if (kqReportFieldComInfo.getFieldname().equals("kqCalendar")) continue; + if (KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname())) + continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month")) + continue; + if (!showColumns.contains(kqReportFieldComInfo.getFieldname()) && !showColumns.contains(kqReportFieldComInfo.getParentid())) + continue; + if ("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname()) && leaveRules.size() == 0) { + continue; + } + title = new HashMap<>(); + String unitType = KQReportBiz.getUnitType(kqReportFieldComInfo, user); + if (unitType.length() > 0) { + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + unitType + ")"); + } else { + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + } + title.put("width", 30 * 256); + this.lsFieldDataKey.add(kqReportFieldComInfo.getFieldname()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user); + childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + title.put("children", childColumns); + title.put("colSpan", childColumns.size()); + } else { + title.put("rowSpan", 3); + } + titleList.add(title); + + titleList.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(), user)); + } + + String today = DateUtil.getCurrentDate(); +// if (DateUtil.compDate(today, toDate) > 0) {//缁撴潫濡傛湡涓嶅ぇ浜庝粖澶 +// toDate = today; +// } + + if (showColumns.contains("kqCalendar")) { + childColumns = new ArrayList<>(); + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + title = new HashMap<>(); + title.put("title", UtilKQ.getWeekDayShort(DateUtil.getWeek(date) - 1, user.getLanguage()) + "\r\n" + DateUtil.geDayOfMonth(date)); + title.put("width", 30 * 256); + childColumns.add(title); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + + title = new HashMap(); + title.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage())); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + title.put("children", childColumns); + title.put("colSpan", childColumns.size()); + } + titleList.add(title); + } + sheet.put("titleList", titleList); + + String forgotBeginWorkCheck_field = " sum(b.forgotBeginWorkCheck) "; + + if (rs.getDBType().equalsIgnoreCase("oracle")) { + forgotBeginWorkCheck_field = " sum(nvl(b.forgotBeginWorkCheck,0)) "; + } else if ((rs.getDBType()).equalsIgnoreCase("mysql")) { + forgotBeginWorkCheck_field = " sum(ifnull(b.forgotBeginWorkCheck,0)) "; + } else { + forgotBeginWorkCheck_field = " sum(isnull(b.forgotBeginWorkCheck,0)) "; + } + + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String definedFieldSum = Util.null2String(definedFieldInfo.get("definedFieldSum")); + //鏀彺鐝缁熻 + String supportSerId = new BaseBean().getPropValue("nbkq_main", "supportSerId"); + String backFields = " (select sum(zma.workdays) from kq_format_total zma where zma.resourceid = a.id and zma.kqdate >='" + fromDate + "' and zma.kqdate <='" + toDate + "' and (DATEPART(dw, zma.kqdate) = 7 or DATEPART(dw, zma.kqdate) = 1) AND zma.kqdate NOT IN (select holidayDate from KQ_HolidaySet where changeType = 3 AND zma.groupid = groupId)) as saturdayworkdays," + + " (select count(0) from kq_shiftschedule where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and serialid=" + supportSerId + " )as supportTotal," + + " (select sum(zma.attendancedays) from kq_format_total zma where zma.resourceid = a.id and zma.kqdate >='" + fromDate + "' and zma.kqdate <='" + toDate + "' and (DATEPART(dw, zma.kqdate) = 7 or DATEPART(dw, zma.kqdate) = 1) AND zma.kqdate NOT IN (select holidayDate from KQ_HolidaySet where changeType = 3 AND zma.groupid = groupId)) as saturdayattendancedays," + + " (select sum(zma.workdays) from kq_format_total zma where zma.resourceid = a.id and zma.kqdate >='" + fromDate + "' and zma.kqdate <='" + toDate + "' and ((DATEPART(dw, zma.kqdate) != 7 and DATEPART(dw, zma.kqdate) != 1) or ((DATEPART(dw, zma.kqdate) = 7 or DATEPART(dw, zma.kqdate) = 1) and zma.kqdate IN (select holidayDate from KQ_HolidaySet where changeType = 3 and zma.groupid = groupId)))) as weekdayworkdays," + + " (select sum(zma.attendancedays) from kq_format_total zma where zma.resourceid = a.id and zma.kqdate >='" + fromDate + "' and zma.kqdate <='" + toDate + "' and ((DATEPART(dw, zma.kqdate) != 7 and DATEPART(dw, zma.kqdate) != 1) or ((DATEPART(dw, zma.kqdate) = 7 or DATEPART(dw, zma.kqdate) = 1) and zma.kqdate IN (select holidayDate from KQ_HolidaySet where changeType = 3 and zma.groupid = groupId)))) as weekdayattendancedays," + + " a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," + + " sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," + + " sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " + + " sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," + + " sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " + + " sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " + + " sum(b.signdays) as signdays,sum(b.signmins) as signmins, " + + " sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+" + forgotBeginWorkCheck_field + " as forgotCheck " + (definedFieldSum.length() > 0 ? "," + definedFieldSum + "" : ""); + if (rs.getDBType().equals("oracle")) { + backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ " + backFields; + } + String sqlFrom = " from hrmresource a, kq_format_total b,kq_ShiftManagement c " + + "where a.id= b.resourceid and c.id=b.serialid and (c.rest_shift is null or c.rest_shift=0) " + + "and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'"; + String sqlWhere = rightSql; + String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle "; + if (subCompanyId.length() > 0) { + sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") "; + } + + if (departmentId.length() > 0) { + sqlWhere += " and a.departmentid in(" + departmentId + ") "; + } + + if (resourceId.length() > 0) { + sqlWhere += " and a.id in(" + resourceId + ") "; + } + + if (viewScope.equals("4")) {//鎴戠殑涓嬪睘 + if (allLevel.equals("1")) {//鎵鏈変笅灞 + sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'"; + } else { + sqlWhere += " and a.managerid=" + user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' "); + } + + if (status.length() > 0) { + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = " + status + ""; + } else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + String orderBy = " order by a.dsporder asc, a.lastname asc "; + String descOrderBy = " order by a.dsporder desc, a.lastname desc "; + sql = "select " + backFields + sqlFrom + sqlWhere + groupBy + orderBy; + + //System.out.println("start" + DateUtil.getFullDate()); + Map flowData = new KQReportBiz().getFlowData(params, user); + Map saturdayFlowLeaveData = kqReportBiz.getSaturdayFlowLeaveData(params, user); + //System.out.println("end" + DateUtil.getFullDate()); + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞 + String fullPathMainKey = "show_full_path"; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey), "0"); + + + rs.execute(sql); + rs.writeLog("========== ExportExcelCmd sql ========== " + sql); + while (rs.next()) { + data = new ArrayList<>(); + String id = rs.getString("id"); + for (int fieldDataKeyIdx = 0; fieldDataKeyIdx < lsFieldDataKey.size(); fieldDataKeyIdx++) { + String fieldName = lsFieldDataKey.get(fieldDataKeyIdx); + String fieldid = KQReportFieldComInfo.field2Id.get(fieldName); + String fieldValue = ""; + //琛ュ崱娆℃暟int + if (fieldName.equals("fillCard")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(kqReportBiz.getFillCardCount(fromDate, toDate, id))); + } else if (fieldName.equals("subcompany")) { + String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid")); + if (tmpSubcompanyId.length() == 0) { + tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id)); + } + + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") : + subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + + // fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + } else if (fieldName.equals("department")) { + String tmpDepartmentId = Util.null2String(rs.getString("departmentid")); + if (tmpDepartmentId.length() == 0) { + tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id)); + } + + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") : + departmentComInfo.getDepartmentname(tmpDepartmentId); + + // fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId); + } else if (fieldName.equals("jobtitle")) { + String tmpJobtitleId = Util.null2String(rs.getString("jobtitle")); + if (tmpJobtitleId.length() == 0) { + tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id)); + } + fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId); + } else if (fieldName.equals("attendanceSerial")) { + List serialIds = null; + if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) { + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ","); + for (int i = 0; serialIds != null && i < serialIds.size(); i++) { + data.add(kqReportBiz.getSerialCount(id, fromDate, toDate, serialIds.get(i))); + } + } else { + data.add(""); + } + continue; + } else if (fieldName.equals("leave")) {//璇峰亣 + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + leaveRule = allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + data.add(flowLeaveData); + } + continue; + } else if (fieldName.equals("overtime")) { + //鍔犵彮鏁版嵁 鈥 鍙栧姞鐝彴璐︾殑鏁版嵁 + //鍔犵彮涓嶅叧鑱旇皟浼戝伐浣滄棩鍔犵彮 + double workingDayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "0", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戜紤鎭棩鍔犵彮 + double restDayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "1", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戣妭鍋囨棩鍔犵彮 + double holidayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "2", "1"); + //鍔犵彮鍏宠仈璋冧紤宸ヤ綔鏃ュ姞鐝 + double workingDayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "0", "0"); + //鍔犵彮鍏宠仈璋冧紤浼戞伅鏃ュ姞鐝 + double restDayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "1", "0"); + //鍔犵彮鍏宠仈璋冧紤鑺傚亣鏃ュ姞鐝 + double holidayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "2", "0"); + + data.add(workingDayOvertime_nonleave); + data.add(restDayOvertime_nonleave); + data.add(holidayOvertime_nonleave); + data.add(workingDayOvertime_4leave); + data.add(restDayOvertime_4leave); + data.add(holidayOvertime_4leave); + + String overtimeTotal = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + data.add(overtimeTotal); + +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_nonleave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_nonleave")))); +// +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_nonleave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_nonleave")))); +// +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_nonleave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_nonleave")))); +// +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|workingDayOvertime_4leave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("workingDayOvertime_4leave")))); +// +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|restDayOvertime_4leave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("restDayOvertime_4leave")))); +// +// fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|holidayOvertime_4leave"))); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("holidayOvertime_4leave")))); +// +// 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; +// fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave+restDayOvertime_4leave+holidayOvertime_4leave+ +// workingDayOvertime_nonleave+restDayOvertime_nonleave+holidayOvertime_nonleave)); +// data.add(getFieldValueByUnitType(fieldValue,kqReportFieldComInfo.getUnittype(KQReportFieldComInfo.field2Id.get("overtimeTotal")))); + continue; + } else if (fieldName.equals("nightSubsidy")) { + //澶滅彮琛ヨ创娆℃暟 + double nightSubsidy = kqReportBiz.getNightSubsidyTotal(fromDate, toDate, id); + data.add(nightSubsidy); + continue; + } else if (fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) { + String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id + "|" + fieldName)), "0.0"); + String backType = fieldName + "_back"; + String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + backType)), "0.0"); + String businessLeave = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (businessLeaveData.length() == 0) { + businessLeaveData = "0.0"; + } + if (businessLeavebackData.length() == 0) { + businessLeavebackData = "0.0"; + } + BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData); + BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData); + businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString(); + if (Util.getDoubleValue(businessLeave, -1) < 0) { + businessLeave = "0.0"; + } + } catch (Exception e) { + } + fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave); + } else if (Util.null2String(kqReportFieldComInfo.getCascadekey(fieldid)).length() > 0) { + fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)), "" + user.getLanguage()); + data.add(fieldValue); + + List lsCascadekey = Util.splitString2List(kqReportFieldComInfo.getCascadekey(fieldid), ","); + for (int i = 0; i < lsCascadekey.size(); i++) { + if (Util.null2String(rs.getString(lsCascadekey.get(i))).length() > 0) { + fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i)); + //杩熷埌鏃╅浣跨敤鍒嗛挓 + if (lsCascadekey.get(i).contains("LateMins") || lsCascadekey.get(i).contains("EarlyMins")) { + fieldValue = rs.getString(lsCascadekey.get(i)); + } else { + fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)), kqReportFieldComInfo.getUnittype(fieldid)); + } + } else { + fieldValue = "0"; + } + data.add(fieldValue); + } + continue; + } else if (fieldName.equals("saturdaysbcjsc")) { + BaseBean baseBean = new BaseBean(); + String sjbjcjidStr = baseBean.getPropValue("nbkq_main", "sjbjcjid"); + String[] sjbjcjidArr = sjbjcjidStr.split(","); + List sjbjcjidList = new ArrayList<>(); + for (String idT : sjbjcjidArr) { + sjbjcjidList.add(Integer.valueOf(idT)); + } + String sjbjcjRes = "0.0"; + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + if (((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i))) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + if (StringUtils.isEmpty(flowLeaveData)) { + flowLeaveData = "0.0"; + } + if ((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i)) { + sjbjcjRes = new BigDecimal(sjbjcjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + } + } + fieldValue = sjbjcjRes; + } else if (fieldName.equals("saturdayshjsc")) { + BaseBean baseBean = new BaseBean(); + String hjsjidStr = baseBean.getPropValue("nbkq_main", "hjsjid"); + String[] hjsjidArr = hjsjidStr.split(","); + List hjsjidList = new ArrayList<>(); + for (String idT : hjsjidArr) { + hjsjidList.add(Integer.valueOf(idT)); + } + String hjsjRes = "0.0"; + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + if (((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i))) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + if (StringUtils.isEmpty(flowLeaveData)) { + flowLeaveData = "0.0"; + } + if ((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i)) { + hjsjRes = new BigDecimal(hjsjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + } + } + fieldValue = hjsjRes; + } else { + fieldValue = Util.formatMultiLang(Util.null2String(rs.getString(fieldName)), "" + user.getLanguage()); + fieldValue = getFieldValueByUnitType(fieldValue, kqReportFieldComInfo.getUnittype(fieldid)); + } + fieldValue = Util.formatMultiLang(fieldValue, "" + user.getLanguage()); + data.add(fieldValue); + } + if (showColumns.contains("kqCalendar")) { + Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user); + isEnd = false; + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + if (DateUtil.compDate(today, date) > 0) { + data.add(""); + } else { + if (detialDatas.get(id + "|" + date) != null) { + data.add(((Map) detialDatas.get(id + "|" + date)).get("text")); + } else { + data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + } + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + } + dataList.add(data); + } + sheet.put("dataList", dataList); + sheet.put("constraintList", constraintList); + sheet.put("createFile", "1"); + lsSheet.add(sheet); + + workbook.put("sheet", lsSheet); + String fileName = SystemEnv.getHtmlLabelName(390351, user.getLanguage()) + " " + fromDate + " " + toDate; + workbook.put("fileName", fileName); + ExcelUtil ExcelUtil = new ExcelUtil(); + Map exportMap = ExcelUtil.export(workbook, request, response); + retmap.putAll(exportMap); + retmap.put("status", "1"); + } catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661, user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private Map getChildColumnsInfo(String parentid, User user) { + Map returnMap = new HashMap<>(); + List titleList = new ArrayList<>(); + Map title = null; + if (parentid.equals("attendanceSerial")) {//鑰冨嫟鐝 + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + List serialIds = null; + if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) { + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ","); + } + for (int i = 0; serialIds != null && i < serialIds.size(); i++) { + title = new HashMap<>(); + title.put("title", Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialIds.get(i)), "" + user.getLanguage())); + title.put("width", 30 * 256); + titleList.add(title); + } + } else if (parentid.equals("leave")) { + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) { + Map leaveRule = leaveRules.get(i); + String name = Util.formatMultiLang(Util.null2String(leaveRule.get("name")), "" + user.getLanguage()); + String unitType = Util.null2String(leaveRule.get("unitType")); + String unitName = (KQUnitBiz.isLeaveHour(unitType)) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + title = new HashMap<>(); + title.put("title", name + "(" + unitName + ")"); + title.put("width", 30 * 256); + titleList.add(title); + } + } else if (parentid.equals("overtime")) { + String[] overtimeChild = {"overtime_nonleave", "overtime_4leave", "overtimeTotal"}; + for (int i = 0; i < overtimeChild.length; i++) { + String id = overtimeChild[i]; + title = new HashMap(); + String fieldlabel = ""; + if ("overtime_nonleave".equalsIgnoreCase(id)) { + fieldlabel = "125805"; + title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + title.put("rowSpan", "2"); + } else if ("overtime_4leave".equalsIgnoreCase(id)) { + fieldlabel = "125804"; + title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + title.put("rowSpan", "2"); + } else { + fieldlabel = "523"; + title.put("showDetial", "1"); + String unitType = (KQOvertimeRulesBiz.getMinimumUnit() == 3 || KQOvertimeRulesBiz.getMinimumUnit() == 5 || KQOvertimeRulesBiz.getMinimumUnit() == 6) ? "2" : "1"; + String unitTypeName = ""; + if (Util.null2String(unitType).length() > 0) { + if (unitType.equals("1")) { + unitTypeName = SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + } else if (unitType.equals("2")) { + unitTypeName = SystemEnv.getHtmlLabelName(391, user.getLanguage()); + } else if (unitType.equals("3")) { + unitTypeName = SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + title.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage()) + "(" + unitTypeName + ")"); + } + + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + title.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")), 65); + } + title.put("width", childWidth + ""); + titleList.add(title); + } + } else { + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (kqReportFieldComInfo.getParentid().equals(parentid)) { + if (!kqReportFieldComInfo.getReportType().equals("month")) continue; + title = new HashMap<>(); + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")"); + title.put("width", 30 * 256); + titleList.add(title); + } + } + } + returnMap.put("childColumns", titleList); + return returnMap; + } + + private List getCascadeKeyColumnsInfo(String cascadeKey, User user) { + List titleList = new ArrayList<>(); + Map title = null; + if (Util.null2String(cascadeKey).length() == 0) { + return titleList; + } + List lsCascadeKey = Util.splitString2List(cascadeKey, ","); + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + for (int i = 0; i < lsCascadeKey.size(); i++) { + kqReportFieldComInfo.setTofirstRow(); + while (kqReportFieldComInfo.next()) { + if (!kqReportFieldComInfo.getReportType().equals("month")) continue; + if (kqReportFieldComInfo.getFieldname().equals(lsCascadeKey.get(i))) { + title = new HashMap<>(); + //浜屽紑 杩熷埌浣跨敤鍒嗛挓 + if (kqReportFieldComInfo.getFieldname().contains("LateMins") || kqReportFieldComInfo.getFieldname().contains("EarlyMins")) { + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(鍒嗛挓)"); + } else { + title.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage()) + "(" + KQReportBiz.getUnitType(kqReportFieldComInfo, user) + ")"); + } + title.put("width", 30 * 256); + titleList.add(title); + } + } + } + return titleList; + } + + private String getFieldValueByUnitType(String fieldValue, String unittype) { + if (Util.null2String(unittype).length() > 0) { + if (fieldValue.length() == 0) { + fieldValue = "0"; + } else { + if (unittype.equals("2")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + return fieldValue; + } + + @Override + public BizLogContext getLogContext() { + return null; + } +} diff --git a/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java b/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java new file mode 100644 index 0000000..dba9add --- /dev/null +++ b/src/com/engine/kq/cmd/report/GetKQDailyReportCmd.java @@ -0,0 +1,745 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.PageUidFactory; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GetKQDailyReportCmd extends AbstractCommonCommand> { + + private KQLog kqLog = new KQLog(); + + public GetKQDailyReportCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + String pageUid = PageUidFactory.getHrmPageUid("KQDailyReport"); + + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQWorkTime kqWorkTime = new KQWorkTime(); + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + KQReportBiz kqReportBiz = new KQReportBiz(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + + String rightSql = new KQReportBiz().getReportRight("2", "" + user.getUID(), "a"); + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect = Util.null2String(jsonObj.get("typeselect")); + if (typeselect.length() == 0) typeselect = "3"; + if (!typeselect.equals("") && !typeselect.equals("0") && !typeselect.equals("6")) { + if (typeselect.equals("1")) { + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + } else { + fromDate = TimeUtil.getDateByOption(typeselect, "0"); + toDate = TimeUtil.getDateByOption(typeselect, "1"); + } + } + //浜哄憳鐘舵 + String status = Util.null2String(jsonObj.get("status")); + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + if (typeselect.length() == 0) typeselect = "3"; + int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1); + int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")), pageUid, user.getUID()); + int count = 0; + int pageCount = 0; + int isHavePre = 0; + int isHaveNext = 0; + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + List columns = new ArrayList(); + Map column = null; + List datas = new ArrayList(); + Map data = null; + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue; + boolean isDaily = kqReportFieldComInfo.getReportType().equals("daily"); + if (!kqReportFieldComInfo.getReportType().equals("all") && !isDaily) continue; + if ("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname()) && leaveRules.size() == 0) { + continue; + } + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user); + childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + column.put("rowSpan", 1); + column.put("width", mapChildColumnInfo.get("sumChildColumnWidth")); + column.put("children", childColumns); + } else { + column.put("rowSpan", 3); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + } + if (kqReportFieldComInfo.getReportType1().equals("daily")) { + column.put("isdaily", "1"); + } + column.put("showDetial", kqReportFieldComInfo.getShowDetial()); + //2024-01-31 浜屽紑 杩熷埌鏃堕暱浣跨敤鍒嗛挓 + String title = (String) column.get("title"); + if (title.contains("杩熷埌鏃堕暱") || title.contains("鏃╅鏃堕暱")) { + column.put("title", title + "(鍒嗛挓)"); + column.put("unit", ""); + } + if ("濮撳悕".equals(column.get("title"))) { + column.put("fixed", "left"); + } + columns.add(column); + } + +// String today = DateUtil.getCurrentDate(); +// if(DateUtil.compDate(today, toDate)>0){//缁撴潫濡傛湡涓嶅ぇ浜庝粖澶 +// toDate = today; +// if(DateUtil.compDate(today, fromDate)>0){ +// fromDate = today; +// } +// } + String forgotBeginWorkCheck_field = " b.forgotbeginworkcheck "; + + if (rs.getDBType().equalsIgnoreCase("oracle") && !Util.null2String(rs.getOrgindbtype()).equals("dm") && !Util.null2String(rs.getOrgindbtype()).equals("st") && !Util.null2String(rs.getOrgindbtype()).equals("jc")) { + forgotBeginWorkCheck_field = " nvl(b.forgotBeginWorkCheck,0) "; + } else if ((rs.getDBType()).equalsIgnoreCase("mysql")) { + forgotBeginWorkCheck_field = " ifnull(b.forgotBeginWorkCheck,0) "; + } else { + forgotBeginWorkCheck_field = " isnull(b.forgotBeginWorkCheck,0) "; + } + + String backFields = " (select workdays from kq_format_total where resourceid = a.id and kqdate = b.kqdate and (DATEPART(dw, kqdate) = 7 or DATEPART(dw, kqdate) = 1)) as saturdayworkdays," + + " (select attendancedays from kq_format_total where resourceid = a.id and kqdate = b.kqdate and (DATEPART(dw, kqdate) = 7 or DATEPART(dw, kqdate) = 1)) as saturdayattendancedays," + + " (select workdays from kq_format_total where resourceid = a.id and kqdate = b.kqdate and DATEPART(dw, kqdate) != 7 and DATEPART(dw, kqdate) != 1) as weekdayworkdays," + + " (select attendancedays from kq_format_total where resourceid = a.id and kqdate = b.kqdate and DATEPART(dw, kqdate) != 7 and DATEPART(dw, kqdate) != 1) as weekdayattendancedays," + + " a.id,a.lastname,a.subcompanyid1 as subcompanyid,a.departmentid, a.workcode,b.jobtitle,a.dsporder," + + " b.kqdate, b.workdays,b.workMins,b.serialid, b.attendancedays,b.attendanceMins," + + " b.beLate,b.beLateMins,b.graveBeLate,b.graveBeLateMins,b.leaveEearly,b.leaveEarlyMins," + + " b.signdays,b.signmins, " + + " b.graveLeaveEarly,b.graveLeaveEarlyMins,b.absenteeism ,b.absenteeismMins ,(b.forgotCheck+" + forgotBeginWorkCheck_field + ") forgotCheck "; + String sqlFrom = " from hrmresource a, kq_format_total b where a.id= b.resourceid and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'"; + String sqlWhere = rightSql; + if (subCompanyId.length() > 0) { + sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") "; + } + + if (departmentId.length() > 0) { + sqlWhere += " and a.departmentid in(" + departmentId + ") "; + } + + if (resourceId.length() > 0) { + sqlWhere += " and a.id in(" + resourceId + ") "; + } + + if (viewScope.equals("4")) {//鎴戠殑涓嬪睘 + if (allLevel.equals("1")) {//鎵鏈変笅灞 + sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'"; + } else { + sqlWhere += " and a.managerid=" + user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' "); + } + if (status.length() > 0) { + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = " + status + ""; + } else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + sql = " select count(*) as c from ( select 1 as c " + sqlFrom + sqlWhere + ") t"; + rs.execute(sql); + if (rs.next()) { + count = rs.getInt("c"); + } + + if (count <= 0) { + pageCount = 0; + } + + pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0); + + isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0; + + isHavePre = (pageIndex - 1 >= 1) ? 1 : 0; + + String orderBy = " order by a.dsporder asc, a.lastname asc, b.kqdate asc "; + String descOrderBy = " order by a.dsporder desc, a.lastname desc, b.kqdate desc "; + sql = backFields + sqlFrom + sqlWhere + orderBy; + + if (pageIndex > 0 && pageSize > 0) { + if (rs.getDBType().equals("oracle")) { + sql = " select " + sql; + sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= " + + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); + } else if (rs.getDBType().equals("mysql")) { + sql = " select " + sql; + sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize; + } else if (rs.getDBType().equals("postgresql")) { + sql = " select " + sql; + sql = "select t1.* from (" + sql + ") t1 limit " + pageSize + " offset " + ((pageIndex - 1) * pageSize); + } else { + orderBy = " order by dsporder asc, lastname asc, kqdate asc "; + descOrderBy = " order by dsporder desc, lastname desc, kqdate desc "; + if (pageIndex > 1) { + int topSize = pageSize; + if (pageSize * pageIndex > count) { + topSize = count - (pageSize * (pageIndex - 1)); + } + sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top " + + (pageIndex * pageSize) + sql + " ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy; + } else { + sql = " select top " + pageSize + sql; + } + } + } else { + sql = " select " + sql; + } + Map flowData = kqReportBiz.getDailyFlowData(params, user); + Map dailySaturdayFlowLeaveData = kqReportBiz.getDailySaturdayFlowLeaveData(params, user); + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞 + String fullPathMainKey = "show_full_path"; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey), "0"); + + new BaseBean().writeLog("kkkkkk:" + sql); + rs.execute(sql); + while (rs.next()) { + String id = rs.getString("id"); + String kqdate = rs.getString("kqdate"); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(id, kqdate); + data = new HashMap<>(); + kqReportFieldComInfo.setTofirstRow(); + while (kqReportFieldComInfo.next()) { + if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("daily")) + continue; + String fieldName = kqReportFieldComInfo.getFieldname(); + String fieldValue = ""; + if (fieldName.equals("subcompany")) { + String fieldValueID = rs.getString("subcompanyid"); + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") : + subCompanyComInfo.getSubCompanyname(fieldValueID); + + //fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID); + + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getSubCompanyID(id); + + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(fieldValueID, "/", "0") : + subCompanyComInfo.getSubCompanyname(fieldValueID); + + // fieldValue = subCompanyComInfo.getSubCompanyname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (fieldName.equals("department")) { + String fieldValueID = rs.getString("departmentid"); + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") : + departmentComInfo.getDepartmentname(fieldValueID); + //fieldValue = departmentComInfo.getDepartmentname(fieldValueID); + + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getDepartmentID(id); + + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(fieldValueID, "/", "0") : + departmentComInfo.getDepartmentname(fieldValueID); + + // fieldValue = departmentComInfo.getDepartmentname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (fieldName.equals("jobtitle")) { + String fieldValueID = rs.getString("jobtitle"); + fieldValue = jobTitlesComInfo.getJobTitlesname(rs.getString("jobtitle")); + if (fieldValue.length() == 0) { + fieldValueID = resourceComInfo.getJobTitle(id); + fieldValue = jobTitlesComInfo.getJobTitlesname(fieldValueID); + } + data.put(fieldName + "Id", fieldValueID); + data.put(fieldName, fieldValue); + } else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave") + || kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) { + if (fieldName.equals("overtimeTotal")) { + double workingDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_4leave"))); + workingDayOvertime_4leave = workingDayOvertime_4leave < 0 ? 0 : workingDayOvertime_4leave; + double restDayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_4leave"))); + restDayOvertime_4leave = restDayOvertime_4leave < 0 ? 0 : restDayOvertime_4leave; + double holidayOvertime_4leave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_4leave"))); + holidayOvertime_4leave = holidayOvertime_4leave < 0 ? 0 : holidayOvertime_4leave; + + double workingDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|workingDayOvertime_nonleave"))); + workingDayOvertime_nonleave = workingDayOvertime_nonleave < 0 ? 0 : workingDayOvertime_nonleave; + double restDayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|restDayOvertime_nonleave"))); + restDayOvertime_nonleave = restDayOvertime_nonleave < 0 ? 0 : restDayOvertime_nonleave; + double holidayOvertime_nonleave = Util.getDoubleValue(Util.null2String(flowData.get(id + "|" + kqdate + "|holidayOvertime_nonleave"))); + holidayOvertime_nonleave = holidayOvertime_nonleave < 0 ? 0 : holidayOvertime_nonleave; + + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + } else { + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + kqdate + "|" + fieldName))); + } + data.put(fieldName, fieldValue); + } else if (fieldName.equals("serialid")) { + fieldValue = Util.null2String(rs.getString(fieldName)); + if (fieldValue.length() > 0) {//寮规у伐浣滃埗娌℃湁鐝 + data.put("serialid", shiftManagementToolKit.getShiftOnOffWorkSections(fieldValue, user.getLanguage())); + } + } else { + fieldValue = Util.null2String(rs.getString(fieldName)); + //2024-01-31 浜屽紑 杩熷埌浣跨敤鍒嗛挓 + writeLog("testreport-" + fieldName + fieldValue); + if (kqReportFieldComInfo.getUnittype().equals("2") && fieldValue.length() > 0 + && !fieldName.contains("LateMins") && !fieldName.contains("EarlyMins")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + data.put(fieldName, fieldValue); + } + } + data.putAll(this.getSignDetailInfo(id, kqdate)); + + //璇峰亣 + List> allLeaveRules = KQLeaveRulesBiz.getAllLeaveRules(); + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + kqdate + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + + } catch (Exception e) { + kqLog.info("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))); + } + data.put(flowType, flowLeaveData); + } + + BaseBean baseBean = new BaseBean(); + String sjbjcjidStr = baseBean.getPropValue("nbkq_main", "sjbjcjid"); + String[] sjbjcjidArr = sjbjcjidStr.split(","); + List sjbjcjidList = new ArrayList<>(); + for (String idT : sjbjcjidArr) { + sjbjcjidList.add(Integer.valueOf(idT)); + } + String hjsjidStr = baseBean.getPropValue("nbkq_main", "hjsjid"); + String[] hjsjidArr = hjsjidStr.split(","); + List hjsjidList = new ArrayList<>(); + for (String idT : hjsjidArr) { + hjsjidList.add(Integer.valueOf(idT)); + } + String sjbjcjRes = "0.0"; + String hjsjRes = "0.0"; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + if (((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i)) || + ((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i))) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(dailySaturdayFlowLeaveData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(dailySaturdayFlowLeaveData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + if (StringUtils.isEmpty(flowLeaveData)) { + flowLeaveData = "0.0"; + } + if ((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i)) { + sjbjcjRes = new BigDecimal(sjbjcjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + if ((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i)) { + hjsjRes = new BigDecimal(hjsjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + } + } + data.put("saturdaysbcjsc", sjbjcjRes); // 鍛ㄥ叚浜嬪亣鐥呭亣浜у亣鏃堕暱 + data.put("saturdayshjsc", hjsjRes); // 鍛ㄥ叚涓у亣濠氬亣鏃堕暱 + + //鍔犵彮鏁版嵁 鈥 鍙栧姞鐝彴璐︾殑鏁版嵁 + //鍔犵彮涓嶅叧鑱旇皟浼戝伐浣滄棩鍔犵彮 + double workingDayOvertime_nonleave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "0", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戜紤鎭棩鍔犵彮 + double restDayOvertime_nonleave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "1", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戣妭鍋囨棩鍔犵彮 + double holidayOvertime_nonleave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "2", "1"); + //鍔犵彮鍏宠仈璋冧紤宸ヤ綔鏃ュ姞鐝 + double workingDayOvertime_4leave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "0", "0"); + //鍔犵彮鍏宠仈璋冧紤浼戞伅鏃ュ姞鐝 + double restDayOvertime_4leave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "1", "0"); + //鍔犵彮鍏宠仈璋冧紤鑺傚亣鏃ュ姞鐝 + double holidayOvertime_4leave = kqReportBiz.getOverTimeDailyCount(kqdate, id, "2", "0"); + + rs.writeLog("================ GetKQDailyReportCmd workingDayOvertime_nonleave ============" + workingDayOvertime_nonleave); + rs.writeLog("================ GetKQDailyReportCmd restDayOvertime_nonleave ============" + restDayOvertime_nonleave); + rs.writeLog("================ GetKQDailyReportCmd holidayOvertime_nonleave ============" + holidayOvertime_nonleave); + rs.writeLog("================ GetKQDailyReportCmd workingDayOvertime_4leave ============" + workingDayOvertime_4leave); + rs.writeLog("================ GetKQDailyReportCmd restDayOvertime_4leave ============" + restDayOvertime_4leave); + rs.writeLog("================ GetKQDailyReportCmd holidayOvertime_4leave ============" + holidayOvertime_4leave); + + data.put("workingDayOvertime_nonleave", workingDayOvertime_nonleave); + data.put("restDayOvertime_nonleave", restDayOvertime_nonleave); + data.put("holidayOvertime_nonleave", holidayOvertime_nonleave); + data.put("workingDayOvertime_4leave", workingDayOvertime_4leave); + data.put("restDayOvertime_4leave", restDayOvertime_4leave); + data.put("holidayOvertime_4leave", holidayOvertime_4leave); + + String totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + workingDayOvertime_nonleave)); + data.put("workdayovertotal", totalValue); + totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(restDayOvertime_4leave + restDayOvertime_nonleave)); + data.put("restdayovertotal", totalValue); + totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(holidayOvertime_4leave + holidayOvertime_nonleave)); + data.put("holidayovertotal", totalValue); + + String overtimeTotal = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + data.put("overtimeTotal", overtimeTotal); + + //澶滅彮琛ヨ创娆℃暟 + String nightSubsidy = KQDurationCalculatorUtil.getDurationRound(String.valueOf(kqReportBiz.getNightSubsidyDaily(kqdate, id))); + data.put("nightSubsidy", nightSubsidy); + + //琛ュ崱娆℃暟 + String fillCard = KQDurationCalculatorUtil.getDurationRound(String.valueOf(kqReportBiz.getFillCardCountDaily(kqdate, id))); + data.put("fillCard", fillCard); + + data.put("resourceId", id); + data.put("kqdate", kqdate); + datas.add(data); + } + + List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope("" + user.getUID(), fromDate, toDate); + retmap.put("holidays", lsHolidays); + retmap.put("columns", columns); + retmap.put("datas", datas); + retmap.put("pagesize", pageSize); + retmap.put("pageindex", pageIndex); + retmap.put("count", count); + retmap.put("pagecount", pageCount); + retmap.put("ishavepre", isHavePre); + retmap.put("ishavenext", isHaveNext); + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + + private String getUnitType(String unitType, User user) { + String unitTypeName = ""; + if (Util.null2String(unitType).length() > 0) { + if (unitType.equals("1")) { + unitTypeName = SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + } else if (unitType.equals("2")) { + unitTypeName = SystemEnv.getHtmlLabelName(391, user.getLanguage()); + } else if (unitType.equals("3")) { + unitTypeName = SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + return unitTypeName; + } + + private Map getChildColumnsInfo(String parentid, User user) { + Map returnMap = new HashMap<>(); + List lsChildColumns = new ArrayList<>(); + Map column = null; + int sumChildColumnWidth = 0; + if (parentid.equals("leave")) { + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) { + Map leaveRule = leaveRules.get(i); + String id = "leaveType_" + Util.null2String(leaveRule.get("id")); + String name = Util.null2String(leaveRule.get("name")); + String unitType = Util.null2String(leaveRule.get("unitType")); + column = new HashMap(); + column.put("title", name); + column.put("unit", KQUnitBiz.isLeaveHour(unitType) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage())); + column.put("width", 65); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("showDetial", "1"); + sumChildColumnWidth += 65; + lsChildColumns.add(column); + } + } else if (parentid.equals("overtime")) { + String[] overtimeChild = {"overtime_nonleave", "overtime_4leave", "overtimeTotal", "workdayovertotal", "restdayovertotal", "holidayovertotal"}; + for (int i = 0; i < overtimeChild.length; i++) { + String id = overtimeChild[i]; + column = new HashMap(); + String fieldlabel = ""; + column.put("unit", ""); + if ("overtime_nonleave".equalsIgnoreCase(id)) { + fieldlabel = "125805"; + } else if ("overtime_4leave".equalsIgnoreCase(id)) { + fieldlabel = "125804"; + } else if ("workdayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "1"; + } else if ("restdayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "2"; + } else if ("holidayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "3"; + }else { + fieldlabel = "523"; + column.put("showDetial", "1"); + String unitType = (KQOvertimeRulesBiz.getMinimumUnit() == 3 || KQOvertimeRulesBiz.getMinimumUnit() == 5 || KQOvertimeRulesBiz.getMinimumUnit() == 6) ? "2" : "1"; + String unitTypeName = ""; + if (Util.null2String(unitType).length() > 0) { + if (unitType.equals("1")) { + unitTypeName = SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + } else if (unitType.equals("2")) { + unitTypeName = SystemEnv.getHtmlLabelName(391, user.getLanguage()); + } else if (unitType.equals("3")) { + unitTypeName = SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + column.put("unit", unitTypeName); + } + column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 1); + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + column.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")), 65); + } + column.put("width", childWidth + ""); + sumChildColumnWidth += childWidth; + lsChildColumns.add(column); + } + } else { + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (kqReportFieldComInfo.getParentid().equals(parentid)) { + if (!kqReportFieldComInfo.getReportType().equals("daily")) continue; + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("isdaily", kqReportFieldComInfo.getReportType1().equals("daily") ? "1" : "0"); + sumChildColumnWidth += Util.getIntValue(kqReportFieldComInfo.getWidth()); + lsChildColumns.add(column); + } + } + } + returnMap.put("childColumns", lsChildColumns); + returnMap.put("sumChildColumnWidth", sumChildColumnWidth); + return returnMap; + } + + public Map getSignDetailInfo(String resourceId, String kqDate) { + Map data = new HashMap<>(); + Map signStatusInfo = null; + RecordSet rs = new RecordSet(); + String sql = ""; + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + try { + sql = " select kqdate,resourceid,serialid,serialnumber,workbegindate,workbegintime, " + + " workenddate,workendtime,workmins,signindate,signintime,signoutdate,signouttime, \n" + + " attendanceMins,belatemins,graveBeLateMins,leaveearlymins,graveLeaveEarlyMins,absenteeismmins,forgotcheckMins,forgotBeginWorkCheckMins," + + " leaveMins,leaveInfo,evectionMins,outMins,signinid,signoutid \n" + + " from kq_format_detail b \n" + + " where resourceid = " + resourceId + " and kqdate ='" + kqDate + "' \n" + + " order by serialnumber \n"; + rs.execute(sql); + while (rs.next()) { + String resourceid = Util.null2String(rs.getString("resourceid")); + String kqdate = Util.null2String(rs.getString("kqdate")); + String serialid = Util.null2String(rs.getString("serialid")); + int serialnumber = rs.getInt("serialnumber") + 1; + String workbegindate = Util.null2String(rs.getString("workbegindate")).trim(); + String workbegintime = Util.null2String(rs.getString("workbegintime")).trim(); + String workenddate = Util.null2String(rs.getString("workenddate")).trim(); + String workendtime = Util.null2String(rs.getString("workendtime")).trim(); + int workMins = rs.getInt("workMins"); + String signintime = Util.null2String(rs.getString("signintime")).trim(); + String signouttime = Util.null2String(rs.getString("signouttime")).trim(); + int attendanceMins = rs.getInt("attendanceMins"); + String beLateMins = Util.null2String(rs.getString("beLateMins")).trim(); + String graveBeLateMins = Util.null2String(rs.getString("graveBeLateMins")).trim(); + String leaveEarlyMins = Util.null2String(rs.getString("leaveEarlyMins")).trim(); + String graveLeaveEarlyMins = Util.null2String(rs.getString("graveLeaveEarlyMins")).trim(); + String absenteeismMins = Util.null2String(rs.getString("absenteeismMins")).trim(); + String forgotCheckMins = Util.null2String(rs.getString("forgotcheckMins")).trim(); + String forgotBeginWorkCheckMins = Util.null2String(rs.getString("forgotBeginWorkCheckMins")).trim(); + String signinid = Util.null2String(rs.getString("signinid")).trim(); + String signoutid = Util.null2String(rs.getString("signoutid")).trim(); + int leaveMins = rs.getInt("leaveMins"); + String leaveInfo = Util.null2String(rs.getString("leaveInfo")); + int evectionMins = rs.getInt("evectionMins"); + int outMins = rs.getInt("outMins"); + + + if (serialid.length() > 0) { + if (workbegintime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("workdate", workbegindate); + signStatusInfo.put("worktime", workbegintime); + signStatusInfo.put("beLateMins", beLateMins); + signStatusInfo.put("forgotBeginWorkCheckMins", forgotBeginWorkCheckMins); + signStatusInfo.put("graveBeLateMins", graveBeLateMins); + signStatusInfo.put("absenteeismMins", absenteeismMins); + signStatusInfo.put("leaveMins", leaveMins); + signStatusInfo.put("leaveInfo", leaveInfo); + signStatusInfo.put("evectionMins", evectionMins); + signStatusInfo.put("outMins", outMins); + + data.put("signintime" + serialnumber, signintime.length() == 0 ? SystemEnv.getHtmlLabelName(25994, user.getLanguage()) : signintime); + data.put("signinstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "on")); + } + + if (workendtime.length() > 0) { + signStatusInfo = new HashMap(); + signStatusInfo.put("workdate", workenddate); + signStatusInfo.put("worktime", kqTimesArrayComInfo.turn48to24Time(workendtime)); + signStatusInfo.put("leaveEarlyMins", leaveEarlyMins); + signStatusInfo.put("graveLeaveEarlyMins", graveLeaveEarlyMins); + signStatusInfo.put("forgotCheckMins", forgotCheckMins); + signStatusInfo.put("forgotBeginWorkCheckMins", forgotBeginWorkCheckMins); + signStatusInfo.put("absenteeismMins", absenteeismMins); + signStatusInfo.put("leaveMins", leaveMins); + signStatusInfo.put("leaveInfo", leaveInfo); + signStatusInfo.put("evectionMins", evectionMins); + signStatusInfo.put("outMins", outMins); + + data.put("signouttime" + serialnumber, signouttime.length() == 0 ? SystemEnv.getHtmlLabelName(25994, user.getLanguage()) : signouttime); + data.put("signoutstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "off")); + } + } else { + if (workMins > 0) { + //寮规у伐鏃舵墦鍗℃椂闂村彇鑷鍒扮閫鏁版嵁 + } + signStatusInfo = new HashMap(); + signStatusInfo.put("leaveMins", leaveMins); + signStatusInfo.put("leaveInfo", leaveInfo); + signStatusInfo.put("evectionMins", evectionMins); + signStatusInfo.put("outMins", outMins); + + if (signinid.length() > 0) { + data.put("signintime" + serialnumber, signintime.length() == 0 ? SystemEnv.getHtmlLabelName(25994, user.getLanguage()) : signintime); + data.put("signinstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "on")); + if (signoutid.length() > 0) { + data.put("signouttime" + serialnumber, signouttime.length() == 0 ? SystemEnv.getHtmlLabelName(25994, user.getLanguage()) : signouttime); + data.put("signoutstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "off")); + } + } else { + data.put("signinstatus" + serialnumber, KQReportBiz.getSignStatus(signStatusInfo, user, "on")); + } + } + } + } catch (Exception e) { + writeLog(e); + } + return data; + } + + @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 new file mode 100644 index 0000000..1d8d1e1 --- /dev/null +++ b/src/com/engine/kq/cmd/report/GetKQReportCmd.java @@ -0,0 +1,790 @@ +package com.engine.kq.cmd.report; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.*; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.PageUidFactory; +import org.apache.commons.lang3.StringUtils; +import org.springframework.util.CollectionUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.company.SubCompanyComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GetKQReportCmd extends AbstractCommonCommand> { + + public GetKQReportCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try { + String pageUid = PageUidFactory.getHrmPageUid("KQReport"); + + SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); + DepartmentComInfo departmentComInfo = new DepartmentComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + JobTitlesComInfo jobTitlesComInfo = new JobTitlesComInfo(); + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + KQReportBiz kqReportBiz = new KQReportBiz(); + + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String attendanceSerial = Util.null2String(jsonObj.get("attendanceSerial")); + String fromDate = Util.null2String(jsonObj.get("fromDate")); + String toDate = Util.null2String(jsonObj.get("toDate")); + String typeselect = Util.null2String(jsonObj.get("typeselect")); + if (typeselect.length() == 0) typeselect = "3"; + if (!typeselect.equals("") && !typeselect.equals("0") && !typeselect.equals("6")) { + if (typeselect.equals("1")) { + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + } else { + fromDate = TimeUtil.getDateByOption(typeselect, "0"); + toDate = TimeUtil.getDateByOption(typeselect, "1"); + } + } + //浜哄憳鐘舵 + String status = Util.null2String(jsonObj.get("status")); + String subCompanyId = Util.null2String(jsonObj.get("subCompanyId")); + String departmentId = Util.null2String(jsonObj.get("departmentId")); + String resourceId = Util.null2String(jsonObj.get("resourceId")); + String allLevel = Util.null2String(jsonObj.get("allLevel")); + String isNoAccount = Util.null2String(jsonObj.get("isNoAccount")); + String viewScope = Util.null2String(jsonObj.get("viewScope")); + String isFromMyAttendance = Util.null2String(jsonObj.get("isFromMyAttendance"));//鏄惁鏄潵鑷垜鐨勮冨嫟鐨勮姹傦紝濡傛灉鏄紝涓嶅姞杞借冨嫟鎶ヨ〃鏉冮檺鍏变韩鐨勯檺鍒讹紝涓嶇劧鎴戠殑鑰冨嫟浼氭彁绀烘棤鏉冮檺 + int pageIndex = Util.getIntValue(Util.null2String(jsonObj.get("pageIndex")), 1); + int pageSize = KQReportBiz.getPageSize(Util.null2String(jsonObj.get("pageSize")), pageUid, user.getUID()); + int count = 0; + int pageCount = 0; + int isHavePre = 0; + int isHaveNext = 0; + + + String rightSql = kqReportBiz.getReportRight("1", "" + user.getUID(), "a"); + if (isFromMyAttendance.equals("1")) { + rightSql = ""; + } + + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + List columns = new ArrayList(); + Map column = null; + List datas = new ArrayList(); + Map data = null; + Map mapChildColumnInfo = null; + List childColumns = null; + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (Util.null2String(kqReportFieldComInfo.getParentid()).length() > 0) continue; + if (kqReportFieldComInfo.getFieldname().equals("kqCalendar")) continue; + if (KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(kqReportFieldComInfo.getFieldname())) + continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month")) + continue; + if ("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname()) && leaveRules.size() == 0) continue; + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("type", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("isSystem", kqReportFieldComInfo.getIsSystem()); + mapChildColumnInfo = this.getChildColumnsInfo(kqReportFieldComInfo.getFieldname(), user); + childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + column.put("rowSpan", 1); + column.put("width", mapChildColumnInfo.get("sumChildColumnWidth")); + column.put("children", childColumns); + } else { + column.put("rowSpan", 3); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + } + column.put("showDetial", kqReportFieldComInfo.getShowDetial()); + if ("濮撳悕".equals(column.get("title"))) { + column.put("fixed", "left"); + } + columns.add(column); + //2024-01-31 浜屽紑 杩熷埌鏃堕暱浣跨敤鍒嗛挓 + List columnsInfo = this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(), user); + columnsInfo.stream().forEach(item -> { + Map map = (Map) item; + String title = (String) map.get("title"); + if (title.contains("杩熷埌鏃堕暱") || title.contains("鏃╅鏃堕暱")) { + map.put("title", title + "(鍒嗛挓)"); + map.put("unit", ""); + } + }); + columns.addAll(columnsInfo); + } + boolean isEnd = false; + Calendar cal = DateUtil.getCalendar(); + String today = DateUtil.getCurrentDate(); +// if(DateUtil.compDate(today, toDate)>0){//缁撴潫鏃ユ湡涓嶅ぇ浜庝粖澶 +// toDate = today; +// if(DateUtil.compDate(today, fromDate)>0){//缁撴潫鏃ユ湡涓嶅ぇ浜庝粖澶 +// fromDate = today; +// } +// } + + childColumns = new ArrayList<>(); + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + column = new HashMap(); + column.put("title", DateUtil.geDayOfMonth(date)); + column.put("dataIndex", date); + column.put("key", date); + column.put("type", date); + column.put("rowSpan", 1); + column.put("width", 65); + column.put("isCalendar", 1); + childColumns.add(column); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(386476, user.getLanguage())); + column.put("dataIndex", "kqCalendar"); + column.put("key", "kqCalendar"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + column.put("rowSpan", 1); + column.put("width", childColumns.size() * 65); + column.put("children", childColumns); + } + columns.add(column); + + String forgotBeginWorkCheck_field = " sum(b.forgotBeginWorkCheck) "; + + if (rs.getDBType().equalsIgnoreCase("oracle")) { + forgotBeginWorkCheck_field = " sum(nvl(b.forgotBeginWorkCheck,0)) "; + } else if ((rs.getDBType()).equalsIgnoreCase("mysql")) { + forgotBeginWorkCheck_field = " sum(ifnull(b.forgotBeginWorkCheck,0)) "; + } else { + forgotBeginWorkCheck_field = " sum(isnull(b.forgotBeginWorkCheck,0)) "; + } + + Map definedFieldInfo = new KQFormatBiz().getDefinedField(); + String definedFieldSum = Util.null2String(definedFieldInfo.get("definedFieldSum")); + //鏀彺鐝缁熻 + String supportSerId = new BaseBean().getPropValue("nbkq_main", "supportSerId"); + String backFields = " (select sum(workdays) from kq_format_total where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and (DATEPART(dw, kqdate) = 7 or DATEPART(dw, kqdate) = 1)) as saturdayworkdays," + + " (select count(0) from kq_shiftschedule where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and serialid=" + supportSerId + " )as supportTotal," + + " (select sum(attendancedays) from kq_format_total where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and (DATEPART(dw, kqdate) = 7 or DATEPART(dw, kqdate) = 1)) as saturdayattendancedays," + + " (select sum(workdays) from kq_format_total where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and DATEPART(dw, kqdate) != 7 and DATEPART(dw, kqdate) != 1) as weekdayworkdays," + + " (select sum(attendancedays) from kq_format_total where resourceid = a.id and kqdate >='" + fromDate + "' and kqdate <='" + toDate + "' and DATEPART(dw, kqdate) != 7 and DATEPART(dw, kqdate) != 1) as weekdayattendancedays," + + "a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1 as subcompanyid,a.departmentid,a.jobtitle," + + " sum(b.workdays) as workdays,sum(b.workMins) as workMins,sum(b.attendancedays) as attendancedays," + + " sum(b.attendanceMins) as attendanceMins,sum(b.beLate) as beLate,sum(b.beLateMins) as beLateMins, " + + " sum(b.graveBeLate) as graveBeLate, sum(b.graveBeLateMins) as graveBeLateMins,sum(b.leaveEearly) as leaveEearly," + + " sum(b.leaveEarlyMins) as leaveEarlyMins, sum(b.graveLeaveEarly) as graveLeaveEarly, " + + " sum(b.graveLeaveEarlyMins) as graveLeaveEarlyMins,sum(b.absenteeism) as absenteeism, " + + " sum(b.signdays) as signdays,sum(b.signmins) as signmins, " + + " sum(b.absenteeismMins) as absenteeismMins, sum(b.forgotCheck)+" + forgotBeginWorkCheck_field + " as forgotCheck " + (definedFieldSum.length() > 0 ? "," + definedFieldSum + "" : ""); + + if (rs.getDBType().equals("oracle")) { + backFields = "/*+ index(kq_format_total IDX_KQ_FORMAT_TOTAL_KQDATE) */ " + backFields; + } + String sqlFrom = " from hrmresource a, kq_format_total b ,kq_ShiftManagement c " + + "where a.id= b.resourceid and c.id=b.serialid and (c.rest_shift is null or c.rest_shift=0) " + + "and b.kqdate >='" + fromDate + "' and b.kqdate <='" + toDate + "'"; + String sqlWhere = rightSql; + String groupBy = " group by a.id,a.lastname,a.workcode,a.dsporder,b.resourceid,a.subcompanyid1,a.departmentid,a.jobtitle "; + if (subCompanyId.length() > 0) { + sqlWhere += " and a.subcompanyid1 in(" + subCompanyId + ") "; + } + + if (departmentId.length() > 0) { + sqlWhere += " and a.departmentid in(" + departmentId + ") "; + } + + if (resourceId.length() > 0) { + sqlWhere += " and a.id in(" + resourceId + ") "; + } + + if (viewScope.equals("4")) {//鎴戠殑涓嬪睘 + if (allLevel.equals("1")) {//鎵鏈変笅灞 + sqlWhere += " and a.managerstr like '%," + user.getUID() + ",%'"; + } else { + sqlWhere += " and a.managerid=" + user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null " + (rs.getDBType().equals("oracle") ? "" : " and a.loginid<>'' "); + } + + if (status.length() > 0) { + if (!status.equals("8") && !status.equals("9")) { + sqlWhere += " and a.status = " + status + ""; + } else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + + sql = " select count(*) as c from ( select 1 as c " + sqlFrom + sqlWhere + groupBy + ") t"; + rs.execute(sql); + if (rs.next()) { + count = rs.getInt("c"); + } + + if (count <= 0) { + pageCount = 0; + } + + pageCount = count / pageSize + ((count % pageSize > 0) ? 1 : 0); + + isHaveNext = (pageIndex + 1 <= pageCount) ? 1 : 0; + + isHavePre = (pageIndex - 1 >= 1) ? 1 : 0; + + String orderBy = " order by t.dsporder asc, t.lastname asc "; + String descOrderBy = " order by t.dsporder desc, t.lastname desc "; + + //榛樿鎺掑簭璁剧疆 start锛屾湁鎬ц兘闂锛屽厛鍙栨秷锛屽悗闈㈠啀鐪嬬湅鏈夋病鏈夊ソ鐨勬柟寮 +// String orderBySql = "select * from kq_report_order where userId=? and sort=1 order by orders"; +// rs.executeQuery(orderBySql, user.getUID()); +// if (rs.getCounts() <= 0) { +// orderBySql = "select * from kq_report_order where userId=0 and sort=1 order by orders"; +// rs.executeQuery(orderBySql); +// } +// while (rs.next()) { +// String dataIndex = rs.getString("dataIndex"); +// String ascOrDesc = rs.getString("ascOrDesc"); +// String ascOrDesc1 = (ascOrDesc.equals("")||ascOrDesc.equals("asc"))?"desc":"asc"; +// if (dataIndex.equals("organization")) { +// orderBy += ",showOrderOfDeptTree " + ascOrDesc + ",dept_id " + ascOrDesc; +// descOrderBy += ",showOrderOfDeptTree " + ascOrDesc1 + ",dept_id " + ascOrDesc1; +// } +// if (dataIndex.equalsIgnoreCase("dspOrder") || dataIndex.equalsIgnoreCase("lastName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",id " + ascOrDesc1; +// } else if (dataIndex.equalsIgnoreCase("deptShowOrder") || dataIndex.equalsIgnoreCase("deptName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",dept_id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",dept_id " + ascOrDesc1; +// } else if (dataIndex.equalsIgnoreCase("subcomShowOrder") || dataIndex.equalsIgnoreCase("subcomName")) { +// orderBy += "," + dataIndex + " " + ascOrDesc + ",subcom_id " + ascOrDesc; +// descOrderBy += "," + dataIndex + " " + ascOrDesc1 + ",subcom_id " + ascOrDesc1; +// } +// } +// orderBy = orderBy.startsWith(",") ? orderBy.substring(1) : orderBy; +// descOrderBy = descOrderBy.startsWith(",") ? descOrderBy.substring(1) : descOrderBy; +// orderBy = orderBy.equals("") ? " t.dspOrder,t.id " : orderBy; +// descOrderBy = descOrderBy.equals("") ? " t.dspOrder,t.id " : descOrderBy; +// orderBy = "order by "+orderBy; + + sql = backFields + sqlFrom + sqlWhere + groupBy; + + if (pageIndex > 0 && pageSize > 0) { + if (rs.getDBType().equals("oracle")) { + sql = " select * from (select " + sql + ") t " + orderBy; + sql = "select * from ( select row_.*, rownum rownum_ from ( " + sql + " ) row_ where rownum <= " + + (pageIndex * pageSize) + ") where rownum_ > " + ((pageIndex - 1) * pageSize); + } else if (rs.getDBType().equals("mysql")) { + sql = " select * from (select " + sql + ") t " + orderBy; + sql = "select t1.* from (" + sql + ") t1 limit " + ((pageIndex - 1) * pageSize) + "," + pageSize; + } else if (rs.getDBType().equals("postgresql")) { + sql = " select * from (select " + sql + ") t " + orderBy; + sql = "select t1.* from (" + sql + ") t1 limit " + pageSize + " offset " + ((pageIndex - 1) * pageSize); + } else { + orderBy = " order by dsporder asc, lastname asc "; + descOrderBy = " order by dsporder desc, lastname desc "; + if (pageIndex > 1) { + int topSize = pageSize; + if (pageSize * pageIndex > count) { + topSize = count - (pageSize * (pageIndex - 1)); + } + sql = " select top " + topSize + " * from ( select top " + topSize + " * from ( select top " + + (pageIndex * pageSize) + sql + orderBy + " ) tbltemp1 " + descOrderBy + ") tbltemp2 " + orderBy; + } else { + sql = " select top " + pageSize + sql + orderBy; + } + } + } else { + sql = " select " + sql; + } + + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞 + String fullPathMainKey = "show_full_path"; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey), "0"); + + Map flowData = kqReportBiz.getFlowData(params, user); + Map saturdayFlowLeaveData = kqReportBiz.getSaturdayFlowLeaveData(params, user); + rs.execute(sql); + rs.writeLog("========== GetKQReportCmd sql ========== " + sql); + while (rs.next()) { + data = new HashMap<>(); + kqReportFieldComInfo.setTofirstRow(); + String id = rs.getString("id"); + data.put("resourceId", id); + while (kqReportFieldComInfo.next()) { + if (!Util.null2String(kqReportFieldComInfo.getIsdataColumn()).equals("1")) continue; + if (!kqReportFieldComInfo.getReportType().equals("all") && !kqReportFieldComInfo.getReportType().equals("month")) + continue; + if ("leave".equalsIgnoreCase(kqReportFieldComInfo.getFieldname()) && leaveRules.size() == 0) { + continue; + } + String fieldName = kqReportFieldComInfo.getFieldname(); + String fieldValue = ""; + if (fieldName.equals("subcompany")) { + String tmpSubcompanyId = Util.null2String(rs.getString("subcompanyid")); + if (tmpSubcompanyId.length() == 0) { + tmpSubcompanyId = Util.null2String(resourceComInfo.getSubCompanyID(id)); + } + data.put("subcompanyId", tmpSubcompanyId); + + fieldValue = "1".equals(isShowFullPath) ? + SubCompanyComInfo.getSubcompanyRealPath(tmpSubcompanyId, "/", "0") : + subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + + // fieldValue = subCompanyComInfo.getSubCompanyname(tmpSubcompanyId); + } else if (fieldName.equals("department")) { + String tmpDepartmentId = Util.null2String(rs.getString("departmentid")); + if (tmpDepartmentId.length() == 0) { + tmpDepartmentId = Util.null2String(resourceComInfo.getDepartmentID(id)); + } + data.put("departmentId", tmpDepartmentId); + + fieldValue = "1".equals(isShowFullPath) ? + departmentComInfo.getDepartmentRealPath(tmpDepartmentId, "/", "0") : + departmentComInfo.getDepartmentname(tmpDepartmentId); + + // fieldValue = departmentComInfo.getDepartmentname(tmpDepartmentId); + } else if (fieldName.equals("jobtitle")) { + String tmpJobtitleId = Util.null2String(rs.getString("jobtitle")); + if (tmpJobtitleId.length() == 0) { + tmpJobtitleId = Util.null2String(resourceComInfo.getJobTitle(id)); + } + data.put("jobtitleId", tmpJobtitleId); + fieldValue = jobTitlesComInfo.getJobTitlesname(tmpJobtitleId); + } else if (fieldName.equals("attendanceSerial")) { + List serialIds = null; + if (attendanceSerial.length() > 0) { + serialIds = Util.splitString2List(attendanceSerial, ","); + } + for (int i = 0; serialIds != null && i < serialIds.size(); i++) { + data.put(serialIds.get(i), kqReportBiz.getSerialCount(id, fromDate, toDate, serialIds.get(i))); + } + } else if (kqReportFieldComInfo.getParentid().equals("overtime") || kqReportFieldComInfo.getParentid().equals("overtime_nonleave") + || kqReportFieldComInfo.getParentid().equals("overtime_4leave") || fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) { + if (fieldName.equals("overtimeTotal")) { + 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; + + fieldValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + } else if (fieldName.equals("businessLeave") || fieldName.equals("officialBusiness")) { + String businessLeaveData = Util.null2s(Util.null2String(flowData.get(id + "|" + fieldName)), "0.0"); + String backType = fieldName + "_back"; + String businessLeavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + backType)), "0.0"); + String businessLeave = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (businessLeaveData.length() == 0) { + businessLeaveData = "0.0"; + } + if (businessLeavebackData.length() == 0) { + businessLeavebackData = "0.0"; + } + BigDecimal b_businessLeaveData = new BigDecimal(businessLeaveData); + BigDecimal b_businessLeavebackData = new BigDecimal(businessLeavebackData); + businessLeave = b_businessLeaveData.subtract(b_businessLeavebackData).toString(); + if (Util.getDoubleValue(businessLeave, -1) < 0) { + businessLeave = "0.0"; + } + } catch (Exception e) { + } + fieldValue = KQDurationCalculatorUtil.getDurationRound(businessLeave); + } else { + fieldValue = KQDurationCalculatorUtil.getDurationRound(Util.null2String(flowData.get(id + "|" + fieldName))); + } + } else { + fieldValue = Util.null2String(rs.getString(fieldName)); + if (Util.null2String(kqReportFieldComInfo.getUnittype()).length() > 0) { + if (fieldValue.length() == 0) { + fieldValue = "0"; + } else { + //2024-01-31 浜屽紑 杩熷埌浣跨敤鍒嗛挓 + writeLog("testreport-" + fieldName + fieldValue); + if (kqReportFieldComInfo.getUnittype().equals("2") + && !fieldName.contains("LateMins") && !fieldName.contains("EarlyMins")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + } + data.put(fieldName, fieldValue); + } + rs.writeLog("================ GetKQReportCmd 111 data ============" + data); + + //璇峰亣 + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + Map leaveRule = null; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(flowData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(flowData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + data.put(flowType, flowLeaveData); + } + + BaseBean baseBean = new BaseBean(); + String sjbjcjidStr = baseBean.getPropValue("nbkq_main", "sjbjcjid"); + String[] sjbjcjidArr = sjbjcjidStr.split(","); + List sjbjcjidList = new ArrayList<>(); + for (String idT : sjbjcjidArr) { + sjbjcjidList.add(Integer.valueOf(idT)); + } + String hjsjidStr = baseBean.getPropValue("nbkq_main", "hjsjid"); + String[] hjsjidArr = hjsjidStr.split(","); + List hjsjidList = new ArrayList<>(); + for (String idT : hjsjidArr) { + hjsjidList.add(Integer.valueOf(idT)); + } + String sjbjcjRes = "0.0"; + String hjsjRes = "0.0"; + for (int i = 0; allLeaveRules != null && i < allLeaveRules.size(); i++) { + if (((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i)) || + ((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i))) { + leaveRule = (Map) allLeaveRules.get(i); + String flowType = Util.null2String("leaveType_" + leaveRule.get("id")); + String leaveData = Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowType)); + String flowLeaveBackType = Util.null2String("leavebackType_" + leaveRule.get("id")); + String leavebackData = Util.null2s(Util.null2String(saturdayFlowLeaveData.get(id + "|" + flowLeaveBackType)), "0.0"); + String b_flowLeaveData = ""; + String flowLeaveData = ""; + try { + //浠ラ槻姝㈠嚭鐜扮簿搴﹂棶棰 + if (leaveData.length() == 0) { + leaveData = "0.0"; + } + if (leavebackData.length() == 0) { + leavebackData = "0.0"; + } + 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"; + } + } 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))); + } + if (StringUtils.isEmpty(flowLeaveData)) { + flowLeaveData = "0.0"; + } + if ((!CollectionUtils.isEmpty(sjbjcjidList)) && sjbjcjidList.contains(i)) { + sjbjcjRes = new BigDecimal(sjbjcjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + if ((!CollectionUtils.isEmpty(hjsjidList)) && hjsjidList.contains(i)) { + hjsjRes = new BigDecimal(hjsjRes).add(new BigDecimal(flowLeaveData)).toString(); + } + } + } + data.put("saturdaysbcjsc", sjbjcjRes); // 鍛ㄥ叚浜嬪亣鐥呭亣浜у亣鏃堕暱 + data.put("saturdayshjsc", hjsjRes); // 鍛ㄥ叚涓у亣濠氬亣鏃堕暱 + + //鍔犵彮鏁版嵁 鈥 鍙栧姞鐝彴璐︾殑鏁版嵁 + //鍔犵彮涓嶅叧鑱旇皟浼戝伐浣滄棩鍔犵彮 + double workingDayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "0", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戜紤鎭棩鍔犵彮 + double restDayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "1", "1"); + //鍔犵彮涓嶅叧鑱旇皟浼戣妭鍋囨棩鍔犵彮 + double holidayOvertime_nonleave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "2", "1"); + //鍔犵彮鍏宠仈璋冧紤宸ヤ綔鏃ュ姞鐝 + double workingDayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "0", "0"); + //鍔犵彮鍏宠仈璋冧紤浼戞伅鏃ュ姞鐝 + double restDayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "1", "0"); + //鍔犵彮鍏宠仈璋冧紤鑺傚亣鏃ュ姞鐝 + double holidayOvertime_4leave = kqReportBiz.getOverTimeCount(fromDate, toDate, id, "2", "0"); + + rs.writeLog("================ GetKQReportCmd workingDayOvertime_nonleave ============" + workingDayOvertime_nonleave); + rs.writeLog("================ GetKQReportCmd restDayOvertime_nonleave ============" + restDayOvertime_nonleave); + rs.writeLog("================ GetKQReportCmd holidayOvertime_nonleave ============" + holidayOvertime_nonleave); + rs.writeLog("================ GetKQReportCmd workingDayOvertime_4leave ============" + workingDayOvertime_4leave); + rs.writeLog("================ GetKQReportCmd restDayOvertime_4leave ============" + restDayOvertime_4leave); + rs.writeLog("================ GetKQReportCmd holidayOvertime_4leave ============" + holidayOvertime_4leave); + + data.put("workingDayOvertime_nonleave", workingDayOvertime_nonleave); + data.put("restDayOvertime_nonleave", restDayOvertime_nonleave); + data.put("holidayOvertime_nonleave", holidayOvertime_nonleave); + data.put("workingDayOvertime_4leave", workingDayOvertime_4leave); + data.put("restDayOvertime_4leave", restDayOvertime_4leave); + data.put("holidayOvertime_4leave", holidayOvertime_4leave); + + String totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + workingDayOvertime_nonleave)); + data.put("workdayovertotal", totalValue); + totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(restDayOvertime_4leave + restDayOvertime_nonleave)); + data.put("restdayovertotal", totalValue); + totalValue = KQDurationCalculatorUtil.getDurationRound(String.valueOf(holidayOvertime_4leave + holidayOvertime_nonleave)); + data.put("holidayovertotal", totalValue); + data.put("supportTotal", rs.getString("supportTotal")); + + String overtimeTotal = KQDurationCalculatorUtil.getDurationRound(String.valueOf(workingDayOvertime_4leave + restDayOvertime_4leave + holidayOvertime_4leave + + workingDayOvertime_nonleave + restDayOvertime_nonleave + holidayOvertime_nonleave)); + data.put("overtimeTotal", overtimeTotal); + + //澶滅彮琛ヨ创娆℃暟 + String nightSubsidy = KQDurationCalculatorUtil.getDurationRound(String.valueOf(kqReportBiz.getNightSubsidyTotal(fromDate, toDate, id))); + data.put("nightSubsidy", nightSubsidy); + + //琛ュ崱娆℃暟int + String fillCard = KQDurationCalculatorUtil.getDurationRound(String.valueOf(kqReportBiz.getFillCardCount(fromDate, toDate, id))); + data.put("fillCard", fillCard); + + rs.writeLog("================ GetKQReportCmd 222 data ============" + data); + + Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user); +// new KQLog().info("id:"+id+":detialDatas:"+detialDatas); + isEnd = false; + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + if (DateUtil.compDate(today, date) > 0) { + data.put(date, ""); + } else { +// new KQLog().info("id:date:"+(id+"|"+date)+":detialDatas.get:"+detialDatas.get(id+"|"+date)); + data.put(date, detialDatas.get(id + "|" + date) == null ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : detialDatas.get(id + "|" + date)); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + datas.add(data); + } + + List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope("" + user.getUID(), fromDate, toDate); + retmap.put("holidays", lsHolidays); + + retmap.put("columns", columns); + retmap.put("datas", datas); + retmap.put("pagesize", pageSize); + retmap.put("pageindex", pageIndex); + retmap.put("count", count); + retmap.put("pagecount", pageCount); + retmap.put("ishavepre", isHavePre); + retmap.put("ishavenext", isHaveNext); + } catch (Exception e) { + writeLog(e); + } + return retmap; + } + + private Map getChildColumnsInfo(String parentid, User user) { + Map returnMap = new HashMap<>(); + List lsChildColumns = new ArrayList<>(); + Map column = null; + int sumChildColumnWidth = 0; + if (parentid.equals("attendanceSerial")) {//鑰冨嫟鐝 + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + List serialIds = null; + if (Util.null2String(jsonObj.get("attendanceSerial")).length() > 0) { + serialIds = Util.splitString2List(Util.null2String(jsonObj.get("attendanceSerial")), ","); + } + for (int i = 0; serialIds != null && i < serialIds.size(); i++) { + column = new HashMap(); + column.put("title", kqShiftManagementComInfo.getSerial(serialIds.get(i))); + column.put("unit", ""); + column.put("width", 65); + column.put("dataIndex", serialIds.get(i)); + column.put("key", serialIds.get(i)); + column.put("rowSpan", 2); + column.put("colSpan", 1); + sumChildColumnWidth += 65; + lsChildColumns.add(column); + } + } else if (parentid.equals("leave")) { + KQLeaveRulesBiz kqLeaveRulesBiz = new KQLeaveRulesBiz(); + List> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + for (int i = 0; leaveRules != null && i < leaveRules.size(); i++) { + Map leaveRule = leaveRules.get(i); + String id = "leaveType_" + Util.null2String(leaveRule.get("id")); + String name = Util.null2String(leaveRule.get("name")); + String unitType = Util.null2String(leaveRule.get("unitType")); + column = new HashMap(); + column.put("title", name); + column.put("unit", KQUnitBiz.isLeaveHour(unitType) ? SystemEnv.getHtmlLabelName(391, user.getLanguage()) : SystemEnv.getHtmlLabelName(1925, user.getLanguage())); + column.put("width", 65); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 2); + column.put("colSpan", 1); + column.put("showDetial", "1"); + sumChildColumnWidth += 65; + lsChildColumns.add(column); + } + } else if (parentid.equals("overtime")) { + String[] overtimeChild = {"overtime_nonleave", "overtime_4leave", "overtimeTotal", "workdayovertotal", "restdayovertotal", "holidayovertotal"}; + for (int i = 0; i < overtimeChild.length; i++) { + String id = overtimeChild[i]; + column = new HashMap(); + String fieldlabel = ""; + column.put("unit", ""); + if ("overtime_nonleave".equalsIgnoreCase(id)) { + fieldlabel = "125805"; + } else if ("overtime_4leave".equalsIgnoreCase(id)) { + fieldlabel = "125804"; + } else if ("workdayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "1"; + } else if ("restdayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "2"; + } else if ("holidayovertotal".equalsIgnoreCase(id)) { + fieldlabel = "3"; + } else { + fieldlabel = "523"; + column.put("showDetial", "1"); + String unitType = (KQOvertimeRulesBiz.getMinimumUnit() == 3 || KQOvertimeRulesBiz.getMinimumUnit() == 5 || KQOvertimeRulesBiz.getMinimumUnit() == 6) ? "2" : "1"; + String unitTypeName = ""; + if (Util.null2String(unitType).length() > 0) { + if (unitType.equals("1")) { + unitTypeName = SystemEnv.getHtmlLabelName(1925, user.getLanguage()); + } else if (unitType.equals("2")) { + unitTypeName = SystemEnv.getHtmlLabelName(391, user.getLanguage()); + } else if (unitType.equals("3")) { + unitTypeName = SystemEnv.getHtmlLabelName(18083, user.getLanguage()); + } + } + column.put("unit", unitTypeName); + } + column.put("title", SystemEnv.getHtmlLabelNames(fieldlabel, user.getLanguage())); + column.put("dataIndex", id); + column.put("key", id); + column.put("rowSpan", 1); + Map mapChildColumnInfo = getChildColumnsInfo(id, user); + int childWidth = 65; + List childColumns = (List) mapChildColumnInfo.get("childColumns"); + if (childColumns.size() > 0) {//璺ㄥ垪width鍙栧瓙鍒楃殑width + column.put("children", childColumns); + childWidth = Util.getIntValue(Util.null2String(mapChildColumnInfo.get("sumChildColumnWidth")), 65); + } + column.put("width", childWidth + ""); + sumChildColumnWidth += childWidth; + lsChildColumns.add(column); + } + } else { + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + while (kqReportFieldComInfo.next()) { + if (kqReportFieldComInfo.getParentid().equals(parentid)) { + if (!kqReportFieldComInfo.getReportType().equals("month")) continue; + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("rowSpan", 1); + column.put("colSpan", 1); + column.put("showDetial", kqReportFieldComInfo.getShowDetial()); + sumChildColumnWidth += Util.getIntValue(kqReportFieldComInfo.getWidth()); + lsChildColumns.add(column); + } + } + } + returnMap.put("childColumns", lsChildColumns); + returnMap.put("sumChildColumnWidth", sumChildColumnWidth); + return returnMap; + } + + private List getCascadeKeyColumnsInfo(String cascadeKey, User user) { + List lsChildColumns = new ArrayList<>(); + if (Util.null2String(cascadeKey).length() == 0) { + return lsChildColumns; + } + Map column = null; + List lsCascadeKey = Util.splitString2List(cascadeKey, ","); + KQReportFieldComInfo kqReportFieldComInfo = new KQReportFieldComInfo(); + for (int i = 0; i < lsCascadeKey.size(); i++) { + kqReportFieldComInfo.setTofirstRow(); + while (kqReportFieldComInfo.next()) { + if (!kqReportFieldComInfo.getReportType().equals("month")) continue; + if (kqReportFieldComInfo.getFieldname().equals(lsCascadeKey.get(i))) { + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelNames(kqReportFieldComInfo.getFieldlabel(), user.getLanguage())); + column.put("unit", KQReportBiz.getUnitType(kqReportFieldComInfo, user)); + column.put("width", Util.getIntValue(kqReportFieldComInfo.getWidth())); + column.put("dataIndex", kqReportFieldComInfo.getFieldname()); + column.put("key", kqReportFieldComInfo.getFieldname()); + column.put("rowSpan", 1); + column.put("colSpan", 1); + column.put("showDetial", kqReportFieldComInfo.getShowDetial()); + column.put("isSystem", kqReportFieldComInfo.getIsSystem()); + lsChildColumns.add(column); + } + } + } + return lsChildColumns; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/reportdetial/GetBeLateInfoCmd.java b/src/com/engine/kq/cmd/reportdetial/GetBeLateInfoCmd.java new file mode 100644 index 0000000..571a5ec --- /dev/null +++ b/src/com/engine/kq/cmd/reportdetial/GetBeLateInfoCmd.java @@ -0,0 +1,167 @@ +package com.engine.kq.cmd.reportdetial; + +import com.cloudstore.dev.api.util.Util_TableMap; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.hrm.util.HrmUtil; +import com.engine.kq.biz.KQReportBiz; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.enums.ReportColumnEnum; +import com.engine.kq.util.PageUidFactory; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/*** + * 杩熷埌鐩稿叧淇℃伅 + */ +public class GetBeLateInfoCmd extends AbstractCommonCommand> { + + public GetBeLateInfoCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String dialogTitle = SystemEnv.getHtmlLabelName(20088, user.getLanguage()); + String tabKey = Util.null2String(params.get("tabKey")); + String resourceId = Util.null2String(params.get("resourceId")); + String keyWord = Util.null2String(params.get("keyWord")); + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String typeselect =Util.null2String(params.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String viewScope = Util.null2String(params.get("viewScope")); + String subCompanyId = Util.null2String(params.get("subCompanyId")); + String departmentId = Util.null2String(params.get("departmentId")); + String allLevel = Util.null2String(params.get("allLevel")); + String isNoAccount = Util.null2String(params.get("isNoAccount")); + String formula = Util.null2String(params.get("formula")); + + String backFields = " a.id, b.resourceid,a.departmentid, a.lastname, a.workcode, a.status, a.dsporder, kqdate, serialid, serialid as serialid1," + + " workbegintime,workendtime, signintime,signouttime, beLateMins, graveBeLateMins "; + String sqlFrom = "from hrmresource a, kq_format_detail b "; + String sqlWhere = " where a.id = b.resourceid"; + String orderby = " kqdate asc, workbegintime asc, a.id asc " ; + String tableString = ""; + + String rightSql = new KQReportBiz().getReportRight("1",""+user.getUID(),"a"); + if(rightSql.length()>0){ + sqlWhere += rightSql; + } + + if (keyWord.length() > 0){ + sqlWhere += " and lastname = "+keyWord; + } + + if (fromDate.length() > 0){ + sqlWhere += " and kqdate >= '"+fromDate+"'"; + } + + if (toDate.length() > 0){ + sqlWhere += " and kqdate <= '"+toDate+"'"; + } + + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if (resourceId.length() > 0){ + sqlWhere += " and b.resourceid in ( "+resourceId+")"; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + if(tabKey.equals("2")){ + sqlWhere += " and graveBeLateMins>0 "; + }else{ + sqlWhere += " and beLateMins>0 "; + } + + if(formula.length()>0){ + formula = formula.replace("${beLateMins}>","").replace("${beLateMins}<=","").replace("?1:0","").replace(" && ","-"); + String[] tmpValue = Util.splitString(formula,"-"); + sqlWhere += " and beLateMins>"+tmpValue[0]+" and beLateMins<= "+tmpValue[1]; + } + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞闇姹 + String transMethodString = HrmUtil.getKqDepartmentTransMethod(); + + String pageUid = PageUidFactory.getHrmPageUid("KQReportDetialList"); + + tableString=""+ + ""+ + ""+ + ""+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; + if(tabKey.equals("2")){ + tableString += " "; + }else{ + tableString += " "; + } + tableString += ""+ + "
"; + + //涓昏鐢ㄤ簬 鏄剧ず瀹氬埗鍒椾互鍙 琛ㄦ牸 姣忛〉灞曠ず璁板綍鏁伴夋嫨 + String sessionkey = pageUid + "_" + Util.getEncrypt(Util.getRandom()); + Util_TableMap.setVal(sessionkey, tableString); + + retmap.put("dialogTitle",dialogTitle); + retmap.put("sessionkey", sessionkey); + retmap.put("status", "1"); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/reportdetial/GetLeaveEearlyInfoCmd.java b/src/com/engine/kq/cmd/reportdetial/GetLeaveEearlyInfoCmd.java new file mode 100644 index 0000000..49dfe34 --- /dev/null +++ b/src/com/engine/kq/cmd/reportdetial/GetLeaveEearlyInfoCmd.java @@ -0,0 +1,167 @@ +package com.engine.kq.cmd.reportdetial; + +import com.cloudstore.dev.api.util.Util_TableMap; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.hrm.util.HrmUtil; +import com.engine.kq.biz.KQReportBiz; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.enums.ReportColumnEnum; +import com.engine.kq.util.PageUidFactory; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/*** + * 鏃╅鐩稿叧淇℃伅 + */ +public class GetLeaveEearlyInfoCmd extends AbstractCommonCommand> { + + public GetLeaveEearlyInfoCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String dialogTitle = SystemEnv.getHtmlLabelName(20089, user.getLanguage()); + String tabKey = Util.null2String(params.get("tabKey")); + String resourceId = Util.null2String(params.get("resourceId")); + String keyWord = Util.null2String(params.get("keyWord")); + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String typeselect =Util.null2String(params.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String viewScope = Util.null2String(params.get("viewScope")); + String subCompanyId = Util.null2String(params.get("subCompanyId")); + String departmentId = Util.null2String(params.get("departmentId")); + String allLevel = Util.null2String(params.get("allLevel")); + String isNoAccount = Util.null2String(params.get("isNoAccount")); + String formula = Util.null2String(params.get("formula")); + + String backFields = " a.id, b.resourceid,a.departmentid, a.lastname, a.workcode, a.status, a.dsporder, kqdate, serialid, serialid as serialid1," + + " workbegintime,workendtime, signintime,signouttime, leaveEarlyMins, graveLeaveEarlyMins "; + String sqlFrom = "from hrmresource a, kq_format_detail b "; + String sqlWhere = " where a.id = b.resourceid"; + String orderby = " kqdate asc, workbegintime asc " ; + String tableString = ""; + + String rightSql = new KQReportBiz().getReportRight("1",""+user.getUID(),"a"); + if(rightSql.length()>0){ + sqlWhere += rightSql; + } + + if (keyWord.length() > 0){ + sqlWhere += " and lastname = "+keyWord; + } + + if (fromDate.length() > 0){ + sqlWhere += " and kqdate >= '"+fromDate+"'"; + } + + if (toDate.length() > 0){ + sqlWhere += " and kqdate <= '"+toDate+"'"; + } + + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if (resourceId.length() > 0){ + sqlWhere += " and b.resourceid in ( "+resourceId+")"; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + if(tabKey.equals("2")){ + sqlWhere += " and graveLeaveEarlyMins>0 "; + }else{ + sqlWhere += " and leaveEarlyMins>0 "; + } + + if(formula.length()>0){ + formula = formula.replace("${leaveEarlyMins}>","").replace("${leaveEarlyMins}<=","").replace("?1:0","").replace(" && ","-"); + String[] tmpValue = Util.splitString(formula,"-"); + sqlWhere += " and leaveEarlyMins>"+tmpValue[0]+" and leaveEarlyMins<= "+tmpValue[1]; + } + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞闇姹 + String transMethodString = HrmUtil.getKqDepartmentTransMethod(); + + String pageUid = PageUidFactory.getHrmPageUid("KQReportDetialList"); + + tableString=""+ + ""+ + ""+ + ""+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "; + if(tabKey.equals("2")){ + tableString += " "; + }else{ + tableString += " "; + } + tableString += ""+ + "
"; + + //涓昏鐢ㄤ簬 鏄剧ず瀹氬埗鍒椾互鍙 琛ㄦ牸 姣忛〉灞曠ず璁板綍鏁伴夋嫨 + String sessionkey = pageUid + "_" + Util.getEncrypt(Util.getRandom()); + Util_TableMap.setVal(sessionkey, tableString); + + retmap.put("dialogTitle",dialogTitle); + retmap.put("sessionkey", sessionkey); + retmap.put("status", "1"); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/reportdetial/GetWorkDayInfoCmd.java b/src/com/engine/kq/cmd/reportdetial/GetWorkDayInfoCmd.java new file mode 100644 index 0000000..249321e --- /dev/null +++ b/src/com/engine/kq/cmd/reportdetial/GetWorkDayInfoCmd.java @@ -0,0 +1,146 @@ +package com.engine.kq.cmd.reportdetial; + +import com.cloudstore.dev.api.util.Util_TableMap; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.hrm.util.HrmUtil; +import com.engine.kq.biz.KQReportBiz; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.enums.ReportColumnEnum; +import com.engine.kq.util.PageUidFactory; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/*** + * 搴斿嚭鍕ゆ槑缁 + */ +public class GetWorkDayInfoCmd extends AbstractCommonCommand> { + + public GetWorkDayInfoCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String dialogTitle = SystemEnv.getHtmlLabelName(390956,user.getLanguage()); + String resourceId = Util.null2String(params.get("resourceId")); + String keyWord = Util.null2String(params.get("keyWord")); + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + String typeselect =Util.null2String(params.get("typeselect")); + if(typeselect.length()==0)typeselect = "3"; + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + String viewScope = Util.null2String(params.get("viewScope")); + String subCompanyId = Util.null2String(params.get("subCompanyId")); + String departmentId = Util.null2String(params.get("departmentId")); + String allLevel = Util.null2String(params.get("allLevel")); + String isNoAccount = Util.null2String(params.get("isNoAccount")); + String backFields = " a.id, b.resourceid,a.departmentid, a.lastname, a.workcode, a.status, a.dsporder, kqdate, " + + " serialid, workmins, workbegintime,workendtime "; + String sqlFrom = "from hrmresource a, kq_format_detail b,kq_ShiftManagement c "; + String sqlWhere = " where a.id = b.resourceid and workmins>0 and b.serialid=c.id and (c.rest_shift is null or c.rest_shift=0) "; + String orderby = " kqdate asc, workbegintime asc " ; + String tableString = ""; + String rightSql = new KQReportBiz().getReportRight("1",""+user.getUID(),"a"); + if(rightSql.length()>0){ + sqlWhere += rightSql; + } + if (keyWord.length() > 0){ + sqlWhere += " and lastname = "+keyWord; + } + + if (fromDate.length() > 0){ + sqlWhere += " and kqdate >= '"+fromDate+"'"; + } + + if (toDate.length() > 0){ + sqlWhere += " and kqdate <= '"+toDate+"'"; + } + + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+subCompanyId+") "; + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+departmentId+") "; + } + + if (resourceId.length() > 0){ + sqlWhere += " and b.resourceid in ( "+resourceId+")"; + } + + if(viewScope.equals("4")){//鎴戠殑涓嬪睘 + if(allLevel.equals("1")){//鎵鏈変笅灞 + sqlWhere+=" and a.managerstr like '%,"+user.getUID()+",%'"; + }else{ + sqlWhere+=" and a.managerid="+user.getUID();//鐩存帴涓嬪睘 + } + } + if (!"1".equals(isNoAccount)) { + sqlWhere += " and a.loginid is not null "+(rs.getDBType().equals("oracle")?"":" and a.loginid<>'' "); + } + + // #1475814-姒傝堪锛氭弧瓒宠冨嫟鎶ュ垎閮ㄩ儴闂ㄦ樉绀哄強瀵煎嚭鏃舵樉绀哄叏璺緞闇姹 + String transMethodString = HrmUtil.getKqDepartmentTransMethod(); + + String pageUid = PageUidFactory.getHrmPageUid("KQReportDetialList"); + + tableString=""+ + ""+ + ""+ + ""+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + ""+ + "
"; + + //涓昏鐢ㄤ簬 鏄剧ず瀹氬埗鍒椾互鍙 琛ㄦ牸 姣忛〉灞曠ず璁板綍鏁伴夋嫨 + String sessionkey = pageUid + "_" + Util.getEncrypt(Util.getRandom()); + Util_TableMap.setVal(sessionkey, tableString); + + retmap.put("dialogTitle",dialogTitle); + retmap.put("sessionkey", sessionkey); + retmap.put("status", "1"); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/entity/WorkTimeEntity.java b/src/com/engine/kq/entity/WorkTimeEntity.java new file mode 100644 index 0000000..b358c44 --- /dev/null +++ b/src/com/engine/kq/entity/WorkTimeEntity.java @@ -0,0 +1,136 @@ +package com.engine.kq.entity; + +import java.util.List; +import java.util.Map; + +/*** + * 宸ヤ綔鏃堕棿 + */ +public class WorkTimeEntity { + private String groupId;//鎵灞炶冨嫟缁 + private String groupName;//鎵灞炶冨嫟缁 + private String kqType;//鑰冨嫟绫诲瀷 + private String serialId;//鐝 + private Map shiftRuleInfo;//鐝浜烘у寲瑙勫垯 + private List signTime;//鍏佽鎵撳崱鏃堕棿 + private List workTime;//宸ヤ綔鏃堕棿 + private List restTime;//浼戞伅鏃堕棿 + private int workMins;//宸ヤ綔鏃堕暱 + private String isAcross;//鏄惁璺ㄥぉ + private String signstart;//鑷敱宸ユ椂寮濮嬫墦鍗℃椂闂 + private boolean isExclude;//鏃犻渶鑰冨嫟浜哄憳 + private String calmethod;//鑷敱鐝埗璁$畻鏂瑰紡 + private int restShift; + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public String getKQType() { + return kqType; + } + + public void setKQType(String kqType) { + this.kqType = kqType; + } + + public String getSerialId() { + return serialId; + } + + public void setSerialId(String serialId) { + this.serialId = serialId; + } + + public Map getShiftRuleInfo() { + return shiftRuleInfo; + } + + public void setShiftRuleInfo(Map shiftRuleInfo) { + this.shiftRuleInfo = shiftRuleInfo; + } + + public List getWorkTime() { + return workTime; + } + + public void setWorkTime(List workTime) { + this.workTime = workTime; + } + + public List getRestTime() { + return restTime; + } + + public void setRestTime(List restTime) { + this.restTime = restTime; + } + + public int getWorkMins() { + return workMins; + } + + public void setWorkMins(int workMins) { + this.workMins = workMins; + } + + public String getIsAcross() { + return isAcross; + } + + public void setIsAcross(String isAcross) { + this.isAcross = isAcross; + } + + public String getSignStart() { + return signstart; + } + + public void setSignStart(String signstart) { + this.signstart = signstart; + } + + public List getSignTime() { + return signTime; + } + + public void setSignTime(List signTime) { + this.signTime = signTime; + } + + public boolean getIsExclude() { + return isExclude; + } + + public void setIsExclude(boolean isExclude) { + this.isExclude = isExclude; + } + + public String getCalmethod() { + return calmethod; + } + + public void setCalmethod(String calmethod) { + this.calmethod = calmethod; + } + +public int getRestShift() { + return restShift; +} + +public void setRestShift(int restShift) { + this.restShift = restShift; +} +} diff --git a/src/com/engine/kq/service/impl/KQReportDetailServiceImpl.java b/src/com/engine/kq/service/impl/KQReportDetailServiceImpl.java new file mode 100644 index 0000000..517a9e0 --- /dev/null +++ b/src/com/engine/kq/service/impl/KQReportDetailServiceImpl.java @@ -0,0 +1,54 @@ +package com.engine.kq.service.impl; + +import com.engine.core.impl.Service; +import com.engine.kq.cmd.reportdetial.*; +import com.engine.kq.service.KQReportDetailService; +import weaver.hrm.User; +import java.util.Map; + +public class KQReportDetailServiceImpl extends Service implements KQReportDetailService { + @Override + public Map getTabs(Map params, User user) { + return commandExecutor.execute(new GetTabsCmd(params, user)); + } + + @Override + public Map getWorkDayInfo(Map params, User user) { + return commandExecutor.execute(new GetWorkDayInfoCmd(params, user)); + } + + @Override + public Map getSignInfo(Map params, User user) { + return commandExecutor.execute(new GetSignInfoCmd(params, user)); + } + + @Override + public Map getBeLateInfo(Map params, User user) { + return commandExecutor.execute(new GetBeLateInfoCmd(params, user)); + } + + @Override + public Map getLeaveEearlyInfo(Map params, User user) { + return commandExecutor.execute(new GetLeaveEearlyInfoCmd(params, user)); + } + + @Override + public Map getAbsenteeismInfo(Map params, User user) { + return commandExecutor.execute(new GetAbsenteeismInfoCmd(params, user)); + } + + @Override + public Map getForgotCheckInfo(Map params, User user) { + return commandExecutor.execute(new GetForgotCheckInfoCmd(params, user)); + } + + @Override + public Map getLeaveInfo(Map params, User user) { + return commandExecutor.execute(new GetLeaveInfoCmd(params, user)); + } + + @Override + public Map getDailyDetialInfo(Map params, User user) { + return commandExecutor.execute(new GetDailyDetialInfoCmd(params, user)); + } +} diff --git a/src/com/engine/kq/util/KQDurationCalculatorUtil.java b/src/com/engine/kq/util/KQDurationCalculatorUtil.java new file mode 100644 index 0000000..cc3b434 --- /dev/null +++ b/src/com/engine/kq/util/KQDurationCalculatorUtil.java @@ -0,0 +1,652 @@ +package com.engine.kq.util; + +import com.engine.kq.biz.KQLeaveRulesBiz; +import com.engine.kq.biz.KQLeaveRulesComInfo; +import com.engine.kq.biz.KQShiftManagementComInfo; +import com.engine.kq.biz.KQWorkTime; +import com.engine.kq.biz.chain.cominfo.ShiftInfoCominfoBean; +import com.engine.kq.biz.chain.duration.NonDayUnitSplitChain; +import com.engine.kq.biz.chain.duration.NonHalfUnitSplitChain; +import com.engine.kq.biz.chain.duration.NonHourUnitSplitChain; +import com.engine.kq.biz.chain.duration.NonWholeUnitSplitChain; +import com.engine.kq.biz.chain.duration.NonWorkDurationChain; +import com.engine.kq.biz.chain.duration.WorkDayUnitSplitChain; +import com.engine.kq.biz.chain.duration.WorkDurationChain; +import com.engine.kq.biz.chain.duration.WorkHalfUnitSplitChain; +import com.engine.kq.biz.chain.duration.WorkHourUnitSplitChain; +import com.engine.kq.biz.chain.duration.WorkWholeUnitSplitChain; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.enums.DurationTypeEnum; +import com.engine.kq.log.KQLog; +import com.engine.kq.wfset.bean.SplitBean; +import com.engine.kq.wfset.util.KQFlowUtil; + +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import weaver.common.StringUtil; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.report.schedulediff.HrmScheduleDiffUtil; + +public class KQDurationCalculatorUtil extends BaseBean { + private KQLog kqLog = new KQLog(); + private final String resourceid; + private String fromDate; + private String toDate; + private String fromTime; + private String toTime; + private String newLeaveType; + /** + * 鑾峰彇鏈灏忚绠楀崟浣 + * 1-鎸夊ぉ璁$畻 + * 2-鎸夊崐澶╄绠 + * 3-鎸夊皬鏃惰绠 + * 4-鎸夋暣澶╄绠 + */ + private String durationrule; + /** + * 1-鎸夊伐浣滄棩璁$畻璁$畻鏃堕暱 + * 2-鎸夎嚜鐒舵棩璁$畻璁$畻鏃堕暱 + */ + private String computingMode; + + /** + * 鍔犵彮绫诲瀷 + */ + private String overtime_type; + + private DurationTypeEnum durationTypeEnum; + + //澶栭儴绫荤殑鏋勯犲嚱鏁 + private KQDurationCalculatorUtil(DurationParamBuilder build) { + this.resourceid = build.resourceid; + this.fromDate = build.fromDate; + this.toDate = build.toDate; + this.fromTime = build.fromTime; + this.toTime = build.toTime; + this.newLeaveType = build.newLeaveType; + this.durationrule = build.durationrule; + this.computingMode = build.computingMode; + this.durationTypeEnum = build.durationTypeEnum; + this.overtime_type = build.overtime_type; + } + + /** + * 鏍规嵁浜哄拰鎸囧畾鐨勬棩鏈熻幏鍙栧姙鍏椂娈 + * + * @param resourceid + * @param date + * @param containYesterday + * @return + */ + public static ShiftInfoBean getWorkTime(String resourceid, String date, boolean containYesterday) { + + User user = User.getUser(Util.getIntValue(resourceid), 0); + if (user == null) { + return null; + } + return getWorkTime(user, date, containYesterday); + } + + public static ShiftInfoBean getWorkTimeNew(String resourceid, String date, boolean containYesterday) { + User user = User.getUser(Util.getIntValue(resourceid), 0); + if (user == null) { + return null; + } + return getWorkTime(user, date, containYesterday, true, false); + } + + /** + * 涓嶈褰曟棩蹇楃殑锛屾祦绋嬬殑瓒呮椂鎻愰啋鏃ュ織澶ぇ + * + * @param resourceid + * @param date + * @param containYesterday + * @param isLog + * @return + */ + public static ShiftInfoBean getWorkTime(String resourceid, String date, boolean containYesterday, boolean isLog) { + User user = User.getUser(Util.getIntValue(resourceid), 0); + if (user == null) { + return null; + } + return getWorkTime(user, date, containYesterday, isLog); + } + + public static ShiftInfoCominfoBean getShiftInfoCominfoBean(String resourceid, String date) { + KQWorkTime kqWorkTime = new KQWorkTime(); + Map kqWorkTimeMap = new HashMap<>(); + ShiftInfoCominfoBean shiftInfoCominfoBean = kqWorkTime.getShiftInfoCominfoBean(resourceid, date); + return shiftInfoCominfoBean; + } + + /** + * 鐩存帴鏍规嵁user鏉ヨ幏鍙 + * + * @param user + * @param date + * @param containYesterday + * @param isLog + * @return + */ + public static ShiftInfoBean getWorkTime(User user, String date, boolean containYesterday, boolean isLog) { + return getWorkTime(user, date, containYesterday, isLog, true); + } + + public static ShiftInfoBean getWorkTime(User user, String date, boolean containYesterday, boolean isLog, boolean isUsedRestShift) { + KQWorkTime kqWorkTime = new KQWorkTime(); + Map kqWorkTimeMap = new HashMap<>(); + kqWorkTimeMap = kqWorkTime.getWorkDuration("" + user.getUID(), date, containYesterday, isLog); + boolean isfree = "1".equalsIgnoreCase(Util.null2String(kqWorkTimeMap.get("isfree"))); + if (isfree) { + ShiftInfoBean shiftInfoBean = new ShiftInfoBean(); + shiftInfoBean.setIsfree(true); + String signStart = Util.null2String(kqWorkTimeMap.get("signStart")); + String workMins = Util.null2String(kqWorkTimeMap.get("workMins")); + shiftInfoBean.setFreeSignStart(signStart); + shiftInfoBean.setFreeWorkMins(workMins); + shiftInfoBean.setSplitDate(date); + if (signStart.length() > 0 && workMins.length() > 0) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm"); + LocalTime signLocalTime = LocalTime.parse(signStart, dateTimeFormatter); + shiftInfoBean.setFreeSignEnd(signLocalTime.plusMinutes(Util.getIntValue(workMins)).format(dateTimeFormatter)); + shiftInfoBean.setFreeSignMiddle(signLocalTime.plusMinutes(Util.getIntValue(workMins) / 2).format(dateTimeFormatter)); + } + + return shiftInfoBean; + } else { + if (kqWorkTimeMap.get("shiftInfoBean") != null) { + ShiftInfoBean shiftInfoBean = (ShiftInfoBean) kqWorkTimeMap.get("shiftInfoBean"); + if (isUsedRestShift) { + int serialid = Util.getIntValue(Util.null2String(shiftInfoBean.getSerialid()), 0); + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + int restShift = StringUtil.parseToInt(kQShiftManagementComInfo.getRestShift(String.valueOf(serialid)), 0); + if (restShift == 1) { + return null; + } + } + return shiftInfoBean; + } else { + return null; + } + } + } + + /** + * 鐩存帴鏍规嵁user鏉ヨ幏鍙 + * + * @param user + * @param date + * @param containYesterday + * @return + */ + public static ShiftInfoBean getWorkTime(User user, String date, boolean containYesterday) { + return getWorkTime(user, date, containYesterday, true); + } + + public static Map getWorkButton(String resourceid, String date, boolean containYesterday) { + User user = User.getUser(Util.getIntValue(resourceid), 0); + return getWorkButton(user, date, containYesterday); + } + + public static Map getWorkButton(User user, String date, boolean containYesterday) { + KQWorkTime kqWorkTime = new KQWorkTime(); + Map kqWorkTimeMap = new HashMap<>(); + kqWorkTimeMap = kqWorkTime.getWorkButton("" + user.getUID(), date, containYesterday); + + return kqWorkTimeMap; + } + + /** + * 鏍规嵁浼犲叆鐨勭敤鎴峰拰鏃舵杩斿洖闈炲伐浣滄椂闀 + * + * @return + */ + public Map getNonWorkDuration() { + + Map durationMap = new HashMap<>(); + try { + double D_Duration = 0.0; + double Min_Duration = 0.0; + //鍏紬鍋囨棩鍔犵彮鏃堕暱 + double D_Pub_Duration = 0.0; + double D_Pub_Mins = 0.0; + //宸ヤ綔鏃ュ姞鐝椂闀 + double D_Work_Duration = 0.0; + double D_Work_Mins = 0.0; + //浼戞伅鏃ュ姞鐝椂闀 + double D_Rest_Duration = 0.0; + double D_Rest_Mins = 0.0; + + SplitBean splitBean = new SplitBean(); + splitBean.setFromDate(fromDate); + splitBean.setFromTime(fromTime); + splitBean.setToDate(toDate); + splitBean.setToTime(toTime); + splitBean.setResourceId(resourceid); + splitBean.setFromdatedb(fromDate); + splitBean.setTodatedb(toDate); + splitBean.setFromtimedb(fromTime); + splitBean.setTotimedb(toTime); + splitBean.setDurationrule(durationrule); + splitBean.setComputingMode(computingMode); + splitBean.setDurationTypeEnum(DurationTypeEnum.OVERTIME); + splitBean.setOvertime_type(overtime_type); + + List splitBeans = new ArrayList<>(); + + NonWorkDurationChain hourUnitSplitChain = new NonHourUnitSplitChain(splitBeans); + NonWorkDurationChain dayUnitSplitChain = new NonDayUnitSplitChain(splitBeans); + NonWorkDurationChain halfUnitSplitChain = new NonHalfUnitSplitChain(splitBeans); + NonWorkDurationChain wholeUnitSplitChain = new NonWholeUnitSplitChain(splitBeans); + + //璁剧疆鎵ц閾 + hourUnitSplitChain.setDurationChain(dayUnitSplitChain); + dayUnitSplitChain.setDurationChain(halfUnitSplitChain); + halfUnitSplitChain.setDurationChain(wholeUnitSplitChain); + //鎶婂垵濮嬫暟鎹缃繘鍘 + hourUnitSplitChain.handleDuration(splitBean); + + //姣忎竴澶╃殑娴佺▼鏃堕暱閮藉湪杩欓噷浜嗭紝鎼炲惂 + for (SplitBean sb : splitBeans) { +// * 1-鍏紬鍋囨棩銆2-宸ヤ綔鏃ャ3-浼戞伅鏃 + int changeType = sb.getChangeType(); + double durations = Util.getDoubleValue(sb.getDuration(), 0.0); + double durationMins = sb.getD_Mins(); + if (1 == changeType) { + D_Pub_Duration += durations; + D_Pub_Mins += durationMins; + } + if (2 == changeType) { + D_Work_Duration += durations; + D_Work_Mins += durationMins; + } + if (3 == changeType) { + D_Rest_Duration += durations; + D_Rest_Mins += durationMins; + } + } + Min_Duration = D_Pub_Mins + D_Work_Mins + D_Rest_Mins; + + if ("3".equalsIgnoreCase(durationrule) || "5".equalsIgnoreCase(durationrule) || "6".equalsIgnoreCase(durationrule)) { + double d_hour = Min_Duration / 60.0; + durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound("" + d_hour)); + } else { + double oneDayHour = KQFlowUtil.getOneDayHour(DurationTypeEnum.OVERTIME, ""); + double d_day = Min_Duration / (oneDayHour * 60); + durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound("" + d_day)); + } + + durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound("" + Min_Duration)); + + } catch (Exception e) { + e.printStackTrace(); + } + return durationMap; + } + + /** + * 鏍规嵁浼犲叆鐨勭敤鎴峰拰鏃舵杩斿洖宸ヤ綔鏃堕暱 + * + * @return + */ + public Map getWorkDuration() { + writeLog("KQDurationCalculatorUtil-getWorkDuration"); + + Map durationMap = new HashMap<>(); + try { + if (!isValidate(fromDate, toDate, fromTime, toTime)) { + durationMap.put("duration", "0.0"); + return durationMap; + } + if (durationTypeEnum != DurationTypeEnum.COMMON_CAL) { + kqLog.info("getWorkDuration:" + durationTypeEnum.getDurationType() + ":fromDate:" + fromDate + ":toDate:" + toDate + ":fromTime:" + fromTime + ":toTime:" + toTime + ":durationrule:" + durationrule + ":computingMode:" + computingMode); + } + //濡傛灉鏄姞鐝 + if (durationTypeEnum == DurationTypeEnum.OVERTIME) { + return getNonWorkDuration(); + } + //鏃堕暱 + double D_Duration = 0.0; + //鍒嗛挓鏁 + double Min_Duration = 0.0; + + SplitBean splitBean = new SplitBean(); + splitBean.setFromDate(fromDate); + splitBean.setFromTime(fromTime); + splitBean.setToDate(toDate); + splitBean.setToTime(toTime); + splitBean.setResourceId(resourceid); + splitBean.setFromdatedb(fromDate); + splitBean.setTodatedb(toDate); + splitBean.setFromtimedb(fromTime); + splitBean.setTotimedb(toTime); + splitBean.setDurationrule(durationrule); + splitBean.setDurationTypeEnum(durationTypeEnum); + splitBean.setComputingMode(computingMode); + splitBean.setNewLeaveType(newLeaveType); + writeLog("getWorkDuration-" + splitBean); + if ("2".equalsIgnoreCase(computingMode)) { + double oneDayHour = KQFlowUtil.getOneDayHour(durationTypeEnum, newLeaveType); + splitBean.setOneDayHour(oneDayHour); + if (durationTypeEnum == DurationTypeEnum.LEAVE) { + //鍙湁鑷劧鏃 璇峰亣鎵嶆湁杩欎釜鎺掗櫎鑺傚亣鏃ャ佷紤鎭棩鐨勫姛鑳 + splitBean.setFilterholidays(KQLeaveRulesBiz.getFilterHolidays(splitBean.getNewLeaveType())); + } + } + if (durationTypeEnum == DurationTypeEnum.LEAVE || durationTypeEnum == DurationTypeEnum.LEAVEBACK) { + if (newLeaveType.length() > 0) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + String conversion = kqLeaveRulesComInfo.getConversion(newLeaveType); + splitBean.setConversion(conversion); + } + } + + List splitBeans = new ArrayList<>(); + + WorkDurationChain hourUnitSplitChain = new WorkHourUnitSplitChain(splitBeans); + WorkDurationChain dayUnitSplitChain = new WorkDayUnitSplitChain(splitBeans); + WorkDurationChain halfUnitSplitChain = new WorkHalfUnitSplitChain(splitBeans); + WorkDurationChain wholeUnitSplitChain = new WorkWholeUnitSplitChain(splitBeans); + + //璁剧疆鎵ц閾 + hourUnitSplitChain.setDurationChain(dayUnitSplitChain); + dayUnitSplitChain.setDurationChain(halfUnitSplitChain); + halfUnitSplitChain.setDurationChain(wholeUnitSplitChain); + //鎶婂垵濮嬫暟鎹缃繘鍘 + hourUnitSplitChain.handleDuration(splitBean); + + //姣忎竴澶╃殑娴佺▼鏃堕暱閮藉湪杩欓噷浜嗭紝鎼炲惂 + for (SplitBean sb : splitBeans) { + double durations = Util.getDoubleValue(sb.getDuration(), 0.0); + double min_durations = sb.getD_Mins(); + D_Duration += durations; + Min_Duration += min_durations; + } + + durationMap.put("duration", KQDurationCalculatorUtil.getDurationRound("" + D_Duration)); + durationMap.put("min_duration", KQDurationCalculatorUtil.getDurationRound("" + Min_Duration)); + + } catch (Exception e) { + e.printStackTrace(); + } + return durationMap; + } + + /** + * 鏍¢獙鏄紶鍏ョ殑鍙傛暟鏁版嵁鏄惁姝e父 + * + * @return false 琛ㄧず鏁版嵁鏈夎 + */ + private boolean isValidate(String fromDate, String toDate, String fromTime, String toTime) { + + if (fromDate.length() == 0 || toDate.length() == 0) { + return false; + } + if (fromTime.length() == 0 || toTime.length() == 0) { + return false; + } + + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + String fromDateTime = fromDate + " " + fromTime + ":00"; + String toDateTime = toDate + " " + toTime + ":00"; + + LocalDateTime localFromDateTime = LocalDateTime.parse(fromDateTime, fullFormatter); + LocalDateTime localToDateTime = LocalDateTime.parse(toDateTime, fullFormatter); + + if (localFromDateTime.isAfter(localToDateTime) || localFromDateTime.isEqual(localToDateTime)) { + return false; + } + return true; + } + + /** + * 寰楀埌鎺掗櫎闈炲伐浣滄椂闂寸殑鏃堕暱 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public Map getTotalWorkingDurations(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + KQDurationCalculatorUtil kqDurationCalculatorUtil = new DurationParamBuilder(resourceid). + fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).durationRuleParam("1") + .computingModeParam("1").durationTypeEnumParam(DurationTypeEnum.COMMON_CAL).build(); + + Map durationMap = kqDurationCalculatorUtil.getWorkDuration(); + return durationMap; + } + + /** + * 寰楀埌鎺掗櫎闈炲伐浣滄椂闂寸殑澶╂暟 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public String getTotalWorkingDays(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + Map durationMap = getTotalWorkingDurations(fromDate, fromTime, toDate, toTime, resourceid); + + String duration4day = Util.null2s(Util.null2String(durationMap.get("duration")), "0"); + return KQDurationCalculatorUtil.getDurationRound(duration4day); + } + + /** + * 寰楀埌鎺掗櫎闈炲伐浣滄椂闂寸殑灏忔椂 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public String getTotalWorkingHours(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + Map durationMap = getTotalWorkingDurations(fromDate, fromTime, toDate, toTime, resourceid); + String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")), "0"); + double duration4hour = Util.getDoubleValue(duration4min) / 60.0; + + return KQDurationCalculatorUtil.getDurationRound(duration4hour + ""); + } + + /** + * 寰楀埌鎺掗櫎闈炲伐浣滄椂闂寸殑鍒嗛挓 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public String getTotalWorkingMins(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + Map durationMap = getTotalWorkingDurations(fromDate, fromTime, toDate, toTime, resourceid); + String duration4min = Util.null2s(Util.null2String(durationMap.get("min_duration")), "0"); + + return KQDurationCalculatorUtil.getDurationRound(duration4min + ""); + } + + /** + * 寰楀埌闈炲伐浣滄椂闂寸殑澶╂暟 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public String getTotalNonWorkingDays(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + KQDurationCalculatorUtil kqDurationCalculatorUtil = new DurationParamBuilder(resourceid). + fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1"). + durationRuleParam("1").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build(); + Map durationMap = kqDurationCalculatorUtil.getNonWorkDuration(); + + String duration = Util.null2String(durationMap.get("duration")); + return KQDurationCalculatorUtil.getDurationRound(duration); + } + + /** + * 寰楀埌闈炲伐浣滄椂闂寸殑灏忔椂 + * + * @param fromDate + * @param fromTime + * @param toDate + * @param toTime + * @param resourceid + * @return + */ + public String getTotalNonWorkingHours(String fromDate, String fromTime, String toDate, String toTime, String resourceid) { + KQDurationCalculatorUtil kqDurationCalculatorUtil = new DurationParamBuilder(resourceid). + fromDateParam(fromDate).toDateParam(toDate).fromTimeParam(fromTime).toTimeParam(toTime).computingModeParam("1"). + durationRuleParam("3").durationTypeEnumParam(DurationTypeEnum.OVERTIME).build(); + Map durationMap = kqDurationCalculatorUtil.getNonWorkDuration(); + + String duration = Util.null2String(durationMap.get("duration")); + return KQDurationCalculatorUtil.getDurationRound(duration); + } + + /** + * 鑰冨嫟閫氱敤绮惧害 2 + * + * @param duration + * @return + */ + public static String getDurationRound(String duration) { + if (HrmScheduleDiffUtil.isFromFlow()) { + return Util.round(duration, 5); + } + return Util.round(duration, 2); + } + + /** + * 鑰冨嫟娴佺▼涓棿琛ㄧ簿搴 5 + * + * @param duration + * @return + */ + public static String getDurationRound5(String duration) { + return Util.round(duration, 5); + } + + /** + * 閽堝鍙兘瀛樺湪鐨勫绉嶅弬鏁扮被鍨 鍒涘缓鍙傛暟闈欐佸唴閮ㄧ被Builder + */ + public static class DurationParamBuilder { + + //蹇呴夊彉閲 浜哄憳鐪嬫庝箞閮芥槸闇瑕佺殑 + private final String resourceid; + + //鍙夊彉閲 + private String fromDate = ""; + private String toDate = ""; + private String fromTime = ""; + private String toTime = ""; + /** + * 璇峰亣鐢ㄧ殑璇峰亣绫诲瀷 + */ + private String newLeaveType = ""; + /** + * 鍗曚綅 + * 1-鎸夊ぉ鍑哄樊 + * 2-鎸夊崐澶╁嚭宸 + * 3-鎸夊皬鏃跺嚭宸 + * 4-鎸夋暣澶╁嚭宸 + */ + private String durationrule = ""; + /** + * 鏃堕暱璁$畻鏂瑰紡 + * 1-鎸夌収宸ヤ綔鏃ヨ绠楄鍋囨椂闀 + * 2-鎸夌収鑷劧鏃ヨ绠楄鍋囨椂闀 + */ + private String computingMode = ""; + + /** + * 鍔犵彮绫诲瀷 + */ + private String overtime_type = ""; + + /** + * 鍝绫诲瀷鐨勬椂闀胯绠楋紝璇峰亣杩樻槸鍑哄樊杩樻槸鍏嚭杩樻槸鍔犵彮 + */ + private DurationTypeEnum durationTypeEnum; + + public DurationParamBuilder(String resourceid) { + this.resourceid = resourceid; + //鍒濆鍖栫殑鏃跺欓渶瑕佹妸鍏朵粬鍙傛暟鍏堟竻绌轰笅 + this.fromDate = ""; + this.toDate = ""; + this.fromTime = ""; + this.toTime = ""; + this.newLeaveType = ""; + this.durationrule = ""; + this.computingMode = ""; + this.overtime_type = ""; + } + + //鎴愬憳鏂规硶杩斿洖鍏惰嚜韬紝鎵浠ュ彲浠ラ摼寮忚皟鐢 + public DurationParamBuilder fromDateParam(final String fromDate) { + this.fromDate = fromDate; + return this; + } + + public DurationParamBuilder toDateParam(final String toDate) { + this.toDate = toDate; + return this; + } + + public DurationParamBuilder fromTimeParam(final String fromTime) { + this.fromTime = fromTime; + return this; + } + + public DurationParamBuilder toTimeParam(final String toTime) { + this.toTime = toTime; + return this; + } + + public DurationParamBuilder newLeaveTypeParam(final String newLeaveType) { + this.newLeaveType = newLeaveType; + return this; + } + + public DurationParamBuilder durationRuleParam(final String durationrule) { + this.durationrule = durationrule; + return this; + } + + public DurationParamBuilder computingModeParam(final String computingMode) { + this.computingMode = computingMode; + return this; + } + + public DurationParamBuilder overtime_typeParam(final String overtime_type) { + this.overtime_type = overtime_type; + return this; + } + + public DurationParamBuilder durationTypeEnumParam(final DurationTypeEnum durationTypeEnum) { + this.durationTypeEnum = durationTypeEnum; + return this; + } + + //Builder鐨刡uild鏂规硶锛岃繑鍥炲閮ㄧ被鐨勫疄渚 + public KQDurationCalculatorUtil build() { + return new KQDurationCalculatorUtil(this); + } + } + +} diff --git a/src/com/engine/kq/util/TimeRangeCalculator.java b/src/com/engine/kq/util/TimeRangeCalculator.java new file mode 100644 index 0000000..a7e0e82 --- /dev/null +++ b/src/com/engine/kq/util/TimeRangeCalculator.java @@ -0,0 +1,21 @@ +package com.engine.kq.util; + +import java.time.Duration; +import java.time.LocalTime; + +public class TimeRangeCalculator { + public static double getRestTime(String startTime, String endTime, String restStartTime, String restEndTime) { + LocalTime workStart = LocalTime.parse(startTime); + LocalTime workEnd = LocalTime.parse(endTime); + LocalTime restStart = LocalTime.parse(restStartTime); + LocalTime restEnd = LocalTime.parse(restEndTime); + Duration restDuration = Duration.ZERO; + if (!restStart.isAfter(workEnd) && !restEnd.isBefore(workStart)) { + + LocalTime effectiveRestStart = restStart.isBefore(workStart) ? workStart : restStart; + LocalTime effectiveRestEnd = restEnd.isAfter(workEnd) ? workEnd : restEnd; + restDuration = Duration.between(effectiveRestStart, effectiveRestEnd); + } + return restDuration.getSeconds(); + } +} \ No newline at end of file diff --git a/src/com/engine/kq/util/TransMethod.java b/src/com/engine/kq/util/TransMethod.java new file mode 100644 index 0000000..1b70d8b --- /dev/null +++ b/src/com/engine/kq/util/TransMethod.java @@ -0,0 +1,929 @@ +package com.engine.kq.util; + +import com.api.browser.bean.SearchConditionOption; +import com.engine.kq.biz.*; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.enums.KQSettingsEnum; +import com.engine.kq.enums.KqSplitFlowTypeEnum; +import com.engine.kq.wfset.util.SplitSelectSet; +import java.text.DecimalFormat; +import java.util.*; +import weaver.systeminfo.systemright.CheckSubCompanyRight; +import weaver.common.DateUtil; +import weaver.common.StringUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.systeminfo.SystemEnv; +import weaver.workflow.workflow.WorkflowComInfo; +import weaver.workflow.workflow.WorkflowRequestComInfo; + +public class TransMethod extends BaseBean { + private static DecimalFormat df = new DecimalFormat("0.00"); + + public ArrayList getOperateByGroup(String id, String otherPara) { + ArrayList resultList = new ArrayList(); + String[] splitStr = Util.splitString(otherPara, "+"); + String kqType = Util.null2String(splitStr[0]); + String subcompanyid = Util.null2String(splitStr[1]); + String userid = Util.null2String(splitStr[2]); + int resourceid = Util.getIntValue(userid); + CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight(); + int operatelevel = checkSubCompanyRight.ChkComRightByUserRightCompanyId(resourceid, "HrmKQGroup:Add", Util.getIntValue(subcompanyid, -1)); + if (operatelevel > 0) { + resultList.add("true"); + resultList.add("true"); + resultList.add("true"); + resultList.add(String.valueOf(kqType.equals("2"))); + }else{ + resultList.add("false"); + resultList.add("false"); + resultList.add("false"); + resultList.add("false"); + } + if (operatelevel > 1) { + resultList.add(this.getKQGroupCheckbox(id)); + }else{ + resultList.add("false"); + } + resultList.add("true"); + return resultList; + } + + public ArrayList getOperate(String id, String kqType){ + ArrayList resultList = new ArrayList(); + + resultList.add("true"); + resultList.add("true"); + resultList.add("true"); + resultList.add(String.valueOf(kqType.equals("2"))); + resultList.add(this.getKQGroupCheckbox(id)); + resultList.add("true"); + return resultList; + } + + public ArrayList getGroupMembersOperate(String id, String groupId){ + ArrayList resultList = new ArrayList(); + String result = getKQGroupMembersCheckbox(id+"+"+groupId); + + resultList.add(result); + return resultList; + } + + public String getKQGroupName(String groupname, String otherPara){ + String kqGroupName = groupname; + String[] splitStr = Util.splitString(otherPara, "+"); + String groupid = Util.null2String(splitStr[0]); + String resourceid = Util.null2String(splitStr[1]); + String kqdate = Util.null2String(splitStr[2]); + String strLanguage = Util.null2String(splitStr[3]); + if(resourceid.length()>0){ + int language = Util.getIntValue(strLanguage,7); + if(kqdate.length()==0) { + kqdate = DateUtil.getCurrentDate(); + } + String currentGroupId = Util.null2String(new KQGroupMemberComInfo().getKQGroupId(resourceid,kqdate)); + if(groupid.equals(currentGroupId)) { + kqGroupName += "("+ SystemEnv.getHtmlLabelName(509551, language)+")"; + } + } + return kqGroupName; + } + + public int getGroupUserCount(String groupid){ + int count = 0; + RecordSet rs = new RecordSet(); + String sql = ""; + sql = " SELECT count(distinct id) FROM ( "+ + " SELECT a.id,a.status FROM HrmResource a, kq_groupmember b "+ + " WHERE (a.id=b.typevalue and b.type =1 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" ) "+ + " UNION ALL "+ + " SELECT a.id,a.status FROM HrmResource a, kq_groupmember b "+ + " WHERE (a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" ) "+ + " UNION ALL "+ + " SELECT a.id,a.status FROM HrmResource a, kq_groupmember b "+ + " WHERE (a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" ) "+ + " UNION ALL "+ + " SELECT a.id,a.status FROM HrmResource a, kq_groupmember b "+ + " WHERE (a.jobtitle = b.typevalue AND b.type=5 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))))" + + " UNION ALL "+ + " select a.id,a.status from hrmresource a where seclevel>=(select min(seclevel) from kq_groupmember where type=6 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" ) and seclevel<= (select max(seclevelto) from kq_groupmember where type=6 and (isdelete is null or isdelete <> '1') and groupid = "+groupid+" )" + + "UNION all " + + " select id,status from hrmresource h " + + " where JOBTITLE in (select id from hrmjobtitles h " + + " where JOBACTIVITYID in (select id from hrmjobactivities h2 " + + " where jobgroupid in (select typevalue from kq_groupmember b " + + " where b.type =10 and (isdelete is null or isdelete <> '1') and b.groupid = "+groupid+"))))t " + + " where t.status in(0,1,2,3) "; + rs.executeQuery(sql) ; + if(rs.next()){ + count=rs.getInt(1); + } + return count; + } + + public String getKQTypeName(String kqtype, String strLanguage){ + int language = Util.getIntValue(strLanguage,7); + String kQTypeName = ""; + if(kqtype.equals("1")){ + kQTypeName = SystemEnv.getHtmlLabelName(389127,language); + }else if(kqtype.equals("2")){ + kQTypeName = SystemEnv.getHtmlLabelName(389128,language); + }else if(kqtype.equals("3")){ + kQTypeName = SystemEnv.getHtmlLabelName(520551,language); + } + return kQTypeName; + } + + public String getKQGroupDetial(String id,String otherPara){ + String kQGroupDetial = ""; + String[] splitStr = Util.splitString(otherPara, "+"); + String kqtype = Util.null2String(splitStr[0]); + int language = Util.getIntValue(splitStr[1],7); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + + if(kqtype.equals("1")){ + String sql = ""; + RecordSet rs = new RecordSet(); + LinkedHashMap map = new LinkedHashMap<>(); + sql = "select * from kq_fixedschedulce where groupid = ? order by weekday "; + rs.executeQuery(sql,id); + while(rs.next()){ + int weekday = rs.getInt("weekday"); + String serialid = Util.null2String(rs.getString("serialid")); + if(serialid.length()==0)serialid="0"; + if(map.get(serialid)==null){ + map.put(serialid,UtilKQ.getWeekDay(weekday,language) ); + }else{ + String value = map.get(serialid); + value=value+"銆"+UtilKQ.getWeekDay(weekday,language); + map.put(serialid,value); + } + } + Iterator> iter = map.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + String serialid = entry.getKey(); + String weeks = entry.getValue(); + if(kQGroupDetial.length()>0)kQGroupDetial+="
"; + if(serialid.equals("0")){ + kQGroupDetial += weeks + SystemEnv.getHtmlLabelName(26593,language); + }else{ + kQGroupDetial += weeks + shiftManagementToolKit.getShiftOnOffWorkSections(serialid,language); + } + } + }else if(kqtype.equals("2")){ + List serialids = Util.splitString2List(kqGroupComInfo.getSerialids(id),",") ; + List lsSerialids = new ArrayList<>(); + for (String serialid : serialids) { + if(Util.null2String(serialid).length()==0 || lsSerialids.contains(serialid) + ||Util.null2String(shiftManagementToolKit.getShiftOnOffWorkSections(serialid,language)).length()==0)continue; + lsSerialids.add(serialid); + if(kQGroupDetial.length()>0)kQGroupDetial+="
"; + kQGroupDetial += shiftManagementToolKit.getShiftOnOffWorkSections(serialid,language); + } + }else if(kqtype.equals("3")){ + kQGroupDetial = SystemEnv.getHtmlLabelName(389120,language); + } + return kQGroupDetial; + } + + public String getSignTime(String signDate, String signTime){ + return signDate+" "+signTime; + } + + public String getFlowDurationByUnit(String duration, String otherPara){ + String[] splitStr = Util.splitString(otherPara, "+"); + String kqType = ""; + String durationrule = ""; + String lan = ""; + String newLeaveType = ""; + String requestid = ""; + String typeselect = ""; + String fromDate = ""; + String toDate = ""; + String backduraion = ""; + + if(splitStr.length == 6){ + kqType = splitStr[0]; + durationrule = splitStr[1]; + lan = splitStr[2]; + newLeaveType = splitStr[3]; + requestid = splitStr[4]; + backduraion = splitStr[5]; + }else if(splitStr.length == 5){ + kqType = splitStr[0]; + durationrule = splitStr[1]; + lan = splitStr[2]; + requestid = splitStr[3]; + backduraion = splitStr[4]; + }else if(splitStr.length == 8){ + kqType = splitStr[0]; + durationrule = splitStr[1]; + lan = splitStr[2]; + newLeaveType = splitStr[3]; + requestid = splitStr[4]; + typeselect = splitStr[5]; + fromDate = splitStr[6]; + toDate = splitStr[7]; + }else if(splitStr.length == 3){ + kqType = splitStr[0]; + durationrule = splitStr[1]; + lan = splitStr[2]; + } + if(Util.getIntValue(kqType) == 0 && newLeaveType.length() == 0){ + return duration; + } + + return getUnitByKQType(kqType,newLeaveType,durationrule,Util.getDoubleValue(duration),requestid,lan,backduraion); + + } + + /** + * 鏍规嵁鑰冨嫟娴佺▼绫诲瀷+璇峰亣绫诲瀷id寰楀埌鍗曚綅 + * @param kqType + * @param newLeaveType + * @param durationrule + * @param duration + * @param requestid + * @param lan + * @param backduraion + * @return + */ + private String getUnitByKQType(String kqType, String newLeaveType, String durationrule, + double duration, String requestid, String lan, String backduraion) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); +// String unit = ""; + double kq_duration = duration; + double proportion = 0.0; + Map backDuraion = new HashMap<>(); + double backDuration = Util.getDoubleValue(Util.null2s(backduraion,"0.0"),0.0); + String minimumUnit = ""; + switch (kqType){ + case "0": + proportion = Util.getDoubleValue(kqLeaveRulesComInfo.getProportion(newLeaveType)); + minimumUnit = ""+KQLeaveRulesBiz.getMinimumUnit(newLeaveType); +// if(requestid.length() > 0){ +// backDuraion = getLeaveBackDuraion(requestid,typeselect,fromDate,toDate); +// } +// unit = getMinimumUnitName(""+minimumUnit, lan); + break; + case "1": + minimumUnit = KQTravelRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQTravelRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 +// unit = getMinimumUnitName(minimumUnit,lan); + break; + case "2": + minimumUnit = KQExitRulesBiz.getMinimumUnit();//鍗曚綅绫诲瀷 + proportion = Util.getDoubleValue(KQExitRulesBiz.getHoursToDay());//鎹㈢畻鍏崇郴 +// unit = getMinimumUnitName(minimumUnit,lan); + break; + case "3": + minimumUnit = ""+KQOvertimeRulesBiz.getMinimumUnit();//褰撳墠鍔犵彮鍗曚綅 + proportion = KQOvertimeRulesBiz.getHoursToDay();//褰撳墠澶╄窡灏忔椂璁$畻鍏崇郴 +// unit = getMinimumUnitName(minimumUnit,lan); + break; + case "4": + break; + case "5": + break; + case "6": + break; + case "7": + break; + default: + break; + } + + + if(KQUnitBiz.isLeaveHour(minimumUnit)){//鎸夊皬鏃 + if(!KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) { + kq_duration = duration*proportion; + backDuration = backDuration*proportion; + } + } + }else{//鎸夊ぉ + if(KQUnitBiz.isLeaveHour(durationrule)){ + if(proportion>0) { + kq_duration = duration/proportion; + backDuration = backDuration/proportion; + } + } + } +// if(unit.length() > 0){ +// return kq_duration+"("+unit+")"; +// }else{ +// } + if(backDuration > 0){ + return KQDurationCalculatorUtil.getDurationRound(""+kq_duration)+"("+SystemEnv.getHtmlLabelName(24473, + Util.getIntValue(lan))+":"+KQDurationCalculatorUtil.getDurationRound(""+backDuration)+")"; + }else{ + return KQDurationCalculatorUtil.getDurationRound(""+kq_duration); + } + } + + /** + * 鏍规嵁璇峰亣娴佺▼id鑾峰彇琚攢鍋囨暟鎹殑鏃堕暱 + * @param requestid + * @param typeselect + * @param fromDate + * @param toDate + * @return + */ + public Map getLeaveBackDuraion(String requestid, String typeselect, + String fromDate, String toDate) { + if(typeselect.length()==0){ + typeselect = "3"; + } + if(!typeselect.equals("") && !typeselect.equals("0")&& !typeselect.equals("6")){ + if(typeselect.equals("1")){ + fromDate = TimeUtil.getCurrentDateString(); + toDate = TimeUtil.getCurrentDateString(); + }else{ + fromDate = TimeUtil.getDateByOption(typeselect,"0"); + toDate = TimeUtil.getDateByOption(typeselect,"1"); + } + } + Map backDuraion = new HashMap<>(); + RecordSet rs = new RecordSet(); + String getLeaveBackDuraion = "select sum(cast(duration as decimal(18,4))) as duration1,durationrule from kq_flow_split_leaveback where leavebackrequestid = ? "; + if (fromDate.length() > 0 && toDate.length() > 0){ + getLeaveBackDuraion += " and ( fromDate between '"+fromDate+"' and '"+toDate+"' or toDate between '"+fromDate+"' and '"+toDate+"' " + + " or '"+fromDate+"' between fromDate and toDate or '"+toDate+"' between fromDate and toDate) "; + } + getLeaveBackDuraion += " group by durationrule "; + rs.executeQuery(getLeaveBackDuraion, requestid); + if (rs.next()){ + String duration1 = rs.getString("duration1"); + String durationrule = rs.getString("durationrule"); + backDuraion.put("durationrule", durationrule); + backDuraion.put("duration", duration1); + } + return backDuraion; + } + + private String getMinimumUnitName(String minimumUnit,int lan){ + String minimumUnitName = ""; + switch (minimumUnit) { + case "1": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "2": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + case "3": + minimumUnitName = SystemEnv.getHtmlLabelName(391, lan); + break; + case "4": + minimumUnitName = SystemEnv.getHtmlLabelName(1925, lan); + break; + default: + break; + } + return minimumUnitName; + } + + public String getSerailName(String serialid,String otherPara) { + String serailName = ""; + if(Util.null2String(serialid).trim().length()==0) return serailName; + String workSections = ""; + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + String[] params = Util.splitString(otherPara, "+"); + String workbegintime = Util.null2String(params[0]).trim(); + String workendtime = Util.null2String(params[1]).trim(); + + serailName = kqShiftManagementComInfo.getSerial(serialid); + if(workbegintime.length()>0&&workendtime.length()>0){ + //鍙湁涓嬬彮鏃堕棿鍙兘璺ㄥぉ + workendtime = kqTimesArrayComInfo.turn48to24Time(workendtime); + workSections += workbegintime+"-"+workendtime; + } + if(workSections.length()>0) { + serailName += "(" + workSections + ")"; + } + return serailName; + } + + /** + * 涓婄彮鎵撳崱鏃堕棿 + * @param serialid + * @param otherPara + * @return + */ + public String getReportDetialSignInTime(String serialid,String otherPara) { + String signTime = ""; + String[] params = Util.splitString(otherPara, "+"); + String begintime = Util.null2String(params[0]).trim(); + String kqdate = Util.null2String(params[1]).trim(); + String resourceid = Util.null2String(params[2]).trim(); + int language = Util.getIntValue(params[3],7); + + if(begintime.length()>0){ + signTime += begintime; + } + + if(Util.null2String(serialid).length()>0){ + if(signTime.length()==0){ + signTime = SystemEnv.getHtmlLabelName(25994,language); + } + }else{ + //寮规у伐鏃舵墦鍗℃椂闂村彇鑷鍒扮閫鏁版嵁 + } + + return signTime; + } + + /** + * 涓嬬彮鎵撳崱鏃堕棿 + * @param serialid + * @param otherPara + * @return + */ + public String getReportDetialSignOutTime(String serialid,String otherPara) { + String signTime = ""; + String[] params = Util.splitString(otherPara, "+"); + String endtime = Util.null2String(params[0]).trim(); + String kqdate = Util.null2String(params[1]).trim(); + String resourceid = Util.null2String(params[2]).trim(); + int language = Util.getIntValue(params[3],7); + + if(endtime.length()>0){ + signTime += endtime; + } + + if(Util.null2String(serialid).length()>0){ + if(signTime.length()==0){ + signTime = SystemEnv.getHtmlLabelName(25994,language); + } + }else{ + //寮规у伐鏃舵墦鍗℃椂闂村彇鑷鍒扮閫鏁版嵁 + } + + return signTime; + } + + + public String getReportDetialSignTime(String serialid,String otherPara) { + String signTime = ""; + String[] params = Util.splitString(otherPara, "+"); + String begintime = Util.null2String(params[0]).trim(); + String endtime = Util.null2String(params[1]).trim(); + String kqdate = Util.null2String(params[2]).trim(); + String resourceid = Util.null2String(params[3]).trim(); + int language = Util.getIntValue(params[4],7); + + if(begintime.length()>0&&endtime.length()>0){ + signTime += begintime+"-"+endtime; + }else if(begintime.length()>0){ + signTime += begintime; + }else if(endtime.length()>0){ + signTime += endtime; + } + + if(Util.null2String(serialid).length()>0){ + if(signTime.length()==0){ + signTime = SystemEnv.getHtmlLabelName(25994,language); + } + }else{ + //寮规у伐鏃舵墦鍗℃椂闂村彇鑷鍒扮閫鏁版嵁 + } + + return signTime; + } + + public String getReportDetialMinToHour(String value) { + value = value.trim(); + if(value.length()>0){ + value = df.format(Util.getDoubleValue(value)/60); + } + return value; + } + + public String getLeavetype(String newleavetype) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + if(newleavetype.length() == 0){ + return ""; + } + boolean show_leave_type_unit = KQSettingsBiz.showLeaveTypeSet(KQSettingsEnum.LEAVETYPE_UNIT.getMain_key()); + String name = kqLeaveRulesComInfo.getLeaveName(newleavetype); + if(show_leave_type_unit){ + name += kqLeaveRulesComInfo.getUnitName(newleavetype, 7); + } + return name; + } + + public String getLeavetype(String newleavetype, String otherPara) { + String[] splitStr = Util.splitString(otherPara, "+"); + String languageId = (splitStr==null || splitStr.length<1) ? "7":splitStr[0]; + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + if(newleavetype.length() == 0){ + return ""; + } + boolean show_leave_type_unit = KQSettingsBiz.showLeaveTypeSet(KQSettingsEnum.LEAVETYPE_UNIT.getMain_key()); + String name = kqLeaveRulesComInfo.getLeaveName(newleavetype); + if(show_leave_type_unit){ + name += kqLeaveRulesComInfo.getUnitName(newleavetype, Util.getIntValue(languageId)); + } + return name; + } + + public String getKQGroupCheckboxByGroup(String otherPara){ + String returnVal = "true"; + + RecordSet rs = new RecordSet(); + String[] splitStr = Util.splitString(otherPara, "+"); + String id = Util.null2String(splitStr[0]); + String subcompanyid = Util.null2String(splitStr[1]); + String userid = Util.null2String(splitStr[2]); + int resourceid = Util.getIntValue(userid); + CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight(); + int operatelevel = checkSubCompanyRight.ChkComRightByUserRightCompanyId(resourceid, "HrmKQGroup:Add", Util.getIntValue(subcompanyid, -1)); + if (operatelevel <= 1) { + returnVal = "false"; + } + String sql = ""; + //鏈夎冨嫟缁勬垚鍛 + if(returnVal.equals("true")) { + sql = " SELECT count(1) FROM kq_groupmember WHERE (isdelete is null or isdelete <> '1') AND groupid=" + id; + rs.executeQuery(sql); + if (rs.next()) { + if (rs.getInt(1) > 0) { + returnVal = "false"; + } + } + } + + //鏈夎冨嫟鎺掔彮 + if(returnVal.equals("true")){ + sql = " SELECT count(1) FROM kq_shiftschedule where (isdelete is null or isdelete <> '1') AND groupid="+id; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + returnVal = "false"; + } + } + } + return returnVal; + } + + public String getKQGroupCheckbox(String id){ + String returnVal = "true"; + String sql = ""; + RecordSet rs = new RecordSet(); + + //鏈夎冨嫟缁勬垚鍛 + sql = " SELECT count(1) FROM kq_groupmember WHERE (isdelete is null or isdelete <> '1') AND groupid="+id; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + returnVal = "false"; + } + } + + //鏈夎冨嫟鎺掔彮 + if(returnVal.equals("true")){ + sql = " SELECT count(1) FROM kq_shiftschedule where (isdelete is null or isdelete <> '1') AND groupid="+id; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + returnVal = "false"; + } + } + } + return returnVal; + } + + public String getKQGroupMembersCheckbox(String params){ + String returnVal = "true"; + String[] arrParams = Util.splitString(params,"+"); + String id = arrParams[0]; + String groupId = arrParams[1]; + String sql = ""; + RecordSet rs = new RecordSet(); + sql = " SELECT count(1) FROM (\n" + + " SELECT DISTINCT t.id, t.resourceid, t.groupid, t.status, t.dsporder,t.lastname,t.subcompanyid1, t.departmentid, t.loginid FROM ( \n" + + " SELECT b.id,a.id AS resourceid, b.groupid, a.status,a.dsporder,a.lastname,a.subcompanyid1, a.departmentid, a.loginid FROM HrmResource a, kq_groupmember b \n" + + " WHERE a.id=b.typevalue and b.type =1 and (b.isdelete is null or b.isdelete <> '1') \n" + + " UNION ALL \n" + + " SELECT b.id,a.id AS resourceid, b.groupid, a.status,a.dsporder,a.lastname,a.subcompanyid1, a.departmentid, a.loginid FROM HrmResource a, kq_groupmember b \n" + + " WHERE a.subcompanyid1 = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=2 and (b.isdelete is null or b.isdelete <> '1') \n" + + " UNION ALL \n" + + " SELECT b.id,a.id AS resourceid, b.groupid, a.status,a.dsporder,a.lastname,a.subcompanyid1, a.departmentid, a.loginid FROM HrmResource a, kq_groupmember b \n" + + " WHERE a.departmentid = b.typevalue AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto AND b.type=3 and (b.isdelete is null or b.isdelete <> '1') \n" + + " UNION ALL \n" + + " SELECT b.id,a.id AS resourceid, b.groupid, a.status,a.dsporder,a.lastname,a.subcompanyid1, a.departmentid, a.loginid FROM HrmResource a, kq_groupmember b \n" + + " WHERE (a.jobtitle = b.typevalue AND b.type=5 and (b.isdelete is null or b.isdelete <> '1') AND (b.jobtitlelevel=1 OR (b.jobtitlelevel=2 AND a.subcompanyid1 IN(b.jobtitlelevelvalue)) OR (b.jobtitlelevel=3 AND a.departmentid IN(b.jobtitlelevelvalue))))) t \n" + + " UNION ALL \n" + + " SELECT b.id,a.id AS resourceid, b.groupid, a.status,a.dsporder,a.lastname,a.subcompanyid1, a.departmentid, a.loginid FROM HrmResource a, kq_groupmember b \n" + + " WHERE b.type=6 AND a.seclevel>=b.seclevel AND a.seclevel<=b.seclevelto and (b.isdelete is null or b.isdelete <> '1')) t, kq_shiftschedule a\n" + + " where t.resourceid=a.resourceid AND t.groupid=a.groupid AND (a.isdelete is null or a.isdelete <> '1') AND t.id="+id + " and t.groupId="+groupId; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>0){ + returnVal = "false"; + } + } + return returnVal; + } + + public String getFlowTimeByUnit(String time, String otherPara){ + String compareTime = time; + String timename = time; + String[] splitStr = Util.splitString(otherPara, "+"); + String kqtype = ""; + String timetype = "";//0琛ㄧず寮濮嬫椂闂达紝1琛ㄧず缁撴潫鏃堕棿 + String lan = ""; + String newLeaveType = ""; + String durationrule = ""; + String timeselection = "1"; + String selectiontype = ""; + String changeType = ""; + KQTimeSelectionComInfo kqTimeSelectionComInfo = new KQTimeSelectionComInfo(); + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + Map half_map = new HashMap<>(); + if(splitStr.length == 5){ + //褰掓。 + kqtype = splitStr[0]; + timetype = splitStr[1]; + lan = splitStr[2]; + newLeaveType = splitStr[3]; + durationrule = splitStr[4]; + }else if(splitStr.length == 4){ + kqtype = splitStr[0]; + timetype = splitStr[1]; + lan = splitStr[2]; + newLeaveType = splitStr[3]; + } + switch (kqtype){ + case "0": + durationrule = (durationrule.length() > 0 ? durationrule : ""+KQLeaveRulesBiz.getMinimumUnit(newLeaveType)); + timeselection = kqLeaveRulesComInfo.getTimeSelection(newLeaveType); + selectiontype = ""+KqSplitFlowTypeEnum.LEAVE.getFlowtype(); + changeType = kqLeaveRulesComInfo.getMinimumUnit(newLeaveType); + break; + case "1": + durationrule = (durationrule.length() > 0 ? durationrule : ""+KQTravelRulesBiz.getMinimumUnit()); + timeselection = KQTravelRulesBiz.getTimeselection(); + selectiontype = ""+KqSplitFlowTypeEnum.EVECTION.getFlowtype(); + changeType = durationrule; + newLeaveType = "0"; + break; + case "2": + durationrule = (durationrule.length() > 0 ? durationrule : ""+KQExitRulesBiz.getMinimumUnit()); + timeselection = KQExitRulesBiz.getTimeselection(); + selectiontype = ""+KqSplitFlowTypeEnum.OUT.getFlowtype(); + changeType = durationrule; + newLeaveType = "0"; + break; + case "3": + durationrule = (durationrule.length() > 0 ? durationrule : ""+KQOvertimeRulesBiz.getMinimumUnit()); + timeselection = KQOvertimeRulesBiz.getTimeselection(); + selectiontype = ""+KqSplitFlowTypeEnum.OVERTIME.getFlowtype(); + changeType = durationrule; + newLeaveType = "0"; + if(compareTime.length() > 5){ + compareTime = compareTime.substring(0,5); + } + break; + case "4": + break; + case "5": + break; + case "6": + break; + case "7": + break; + default: + break; + } + if("2".equalsIgnoreCase(durationrule) || "4".equalsIgnoreCase(durationrule)){ + if("2".equalsIgnoreCase(durationrule)){ + half_map = kqTimeSelectionComInfo.getTimeselections(selectiontype,newLeaveType,changeType); + if("1".equalsIgnoreCase(timeselection)){ + //涓嬫媺妗嗘樉绀 + String cus_am = ""; + String cus_pm = ""; + if(half_map != null && !half_map.isEmpty()){ + cus_am = Util.null2String(half_map.get("half_on")); + cus_pm = Util.null2String(half_map.get("half_off")); + } + if("0".equalsIgnoreCase(timetype)){ + if(compareTime.equalsIgnoreCase(SplitSelectSet.forenoon_start)){ + timename = SystemEnv.getHtmlLabelName(16689,Util.getIntValue(lan)); + if(cus_am.length() > 0){ + timename = cus_am; + } + }else if(compareTime.equalsIgnoreCase(SplitSelectSet.forenoon_end)){ + timename = SystemEnv.getHtmlLabelName(16690,Util.getIntValue(lan)); + if(cus_pm.length() > 0){ + timename = cus_pm; + } + } + }else if("1".equalsIgnoreCase(timetype)){ + if(compareTime.equalsIgnoreCase(SplitSelectSet.afternoon_start)){ + timename = SystemEnv.getHtmlLabelName(16689,Util.getIntValue(lan)); + if(cus_am.length() > 0){ + timename = cus_am; + } + }else if(compareTime.equalsIgnoreCase(SplitSelectSet.afternoon_end)){ + timename = SystemEnv.getHtmlLabelName(16690,Util.getIntValue(lan)); + if(cus_pm.length() > 0){ + timename = cus_pm; + } + } + } + }else{ + + } + } + if("4".equalsIgnoreCase(durationrule)){ + if("0".equalsIgnoreCase(timetype)){ + if(compareTime.equalsIgnoreCase(SplitSelectSet.forenoon_start)){ + timename = SystemEnv.getHtmlLabelName(390728,Util.getIntValue(lan)); + } + }else if("1".equalsIgnoreCase(timetype)){ + if(compareTime.equalsIgnoreCase(SplitSelectSet.afternoon_end)){ + timename = SystemEnv.getHtmlLabelName(390728,Util.getIntValue(lan)); + } + } + + } + } + return timename; + } + + /** + * 鑰冨嫟鎶ヨ〃锛屽姞鐝槑缁嗛噷鏍规嵁褰撳墠鍔犵彮鍗曚綅鏄剧ず鍔犵彮鏃堕暱 + * @param duration + * @return + */ + public String getDuration_minByUnit(String duration){ + + int uintType = KQOvertimeRulesBiz.getMinimumUnit();//褰撳墠鍔犵彮鍗曚綅 + double hoursToDay = KQOvertimeRulesBiz.getHoursToDay();//褰撳墠澶╄窡灏忔椂璁$畻鍏崇郴 + + String valueField = ""; + if(uintType==3 || uintType== 5 || uintType== 6){//鎸夊皬鏃惰绠 + valueField = KQDurationCalculatorUtil.getDurationRound(""+(Util.getDoubleValue(duration)/(60))); + }else{//鎸夊ぉ璁$畻 + valueField = KQDurationCalculatorUtil.getDurationRound(""+(Util.getDoubleValue(duration)/(60*hoursToDay))); + } + + return valueField; + } + + /** + * 鑰冨嫟鎶ヨ〃锛屽姞鐝槑缁嗛噷鏍规嵁褰撳墠鍔犵彮鏁版嵁鏄惁鍏宠仈璋冧紤 + * @param paidLeaveEnable + * @param otherPram + * @return + */ + public String getPaidLeaveEnable(String paidLeaveEnable,String otherPram){ + int lan = Util.getIntValue(otherPram,7); + if("1".equalsIgnoreCase(paidLeaveEnable)){ + return SystemEnv.getHtmlLabelName(163, lan); + }else{ + return SystemEnv.getHtmlLabelName(161, lan); + } + } + + /** + * 鑰冨嫟鎶ヨ〃锛屽姞鐝槑缁嗛噷鏍规嵁褰撳墠鍔犵彮鏁版嵁鏉ユ簮 + * @param computingMode + * @param otherPram + * @return + */ + public String getComputingMode(String computingMode,String otherPram){ +// String mode = ""; +// if("1".equalsIgnoreCase(computingMode)){ +// mode = "浠ュ姞鐝祦绋嬩负鍑"; +// }else if("2".equalsIgnoreCase(computingMode)){ +// mode = "浠ユ墦鍗′负鍑嗭紝浣嗕笉鑳借秴杩囧姞鐝祦绋嬫椂闀"; +// }else if("3".equalsIgnoreCase(computingMode)){ +// mode = "鏍规嵁鎵撳崱鏃堕棿璁$畻鍔犵彮鏃堕暱"; +// } + int lan = Util.getIntValue(otherPram,7); + if("1".equalsIgnoreCase(computingMode)){ + return SystemEnv.getHtmlLabelName(30045, lan); + }else{ + return SystemEnv.getHtmlLabelName(500502, lan); + } + } + + public String getSchedulecode(String params){ + String schedulecode = ""; + String sql = ""; + RecordSet rs = new RecordSet(); + try{ + boolean isOneDevice = true; + sql = " select count(1) from kq_schedule_device "; + rs.executeQuery(sql); + if(rs.next()){ + if(rs.getInt(1)>1){ + isOneDevice = false; + } + } + + if(isOneDevice){ + sql = " SELECT schedulecode FROM kq_schedule_code where resourceid="+params; + rs.executeQuery(sql); + while (rs.next()){ + if(schedulecode.length()>0)schedulecode+=","; + schedulecode += Util.null2String(rs.getString("schedulecode")); + } + }else{ + sql = " SELECT count(1) as cnt FROM kq_schedule_code where resourceid="+params; + rs.executeQuery(sql); + if(rs.next()){ + schedulecode = ""+rs.getInt("cnt"); + } + } + }catch (Exception e){ + writeLog(e); + } + return schedulecode; + } + public String getScheduleDeviceCheckbox(String id){ + String returnVal = "true"; + + String sql = ""; + RecordSet rs = new RecordSet(); + try{ + sql = " select count(1) from kq_schedule_code where deviceid = ? "; + rs.executeQuery(sql,id); + if(rs.next()){ + if(rs.getInt(1)>0){ + returnVal = "false"; + } + } + }catch (Exception e){ + writeLog(e); + } + return returnVal; + } + + public ArrayList getScheduleDeviceOperate(String id){ + ArrayList resultList = new ArrayList(); + + resultList.add("true"); + resultList.add(this.getScheduleDeviceCheckbox(id)); + resultList.add("true"); + return resultList; + } + + public String getWorkflowname(String field001){ + WorkflowComInfo workflowComInfo = new WorkflowComInfo(); + return workflowComInfo.getWorkflowname(field001); + } + + public String getFlowTypeName(String field006, String strLanguage){ + if("0".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(83393, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("1".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(83394, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("2".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(83395, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("3".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(83396, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("5".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(390737, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("6".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(389117, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("7".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(390274, Util.getIntValue(Util.getIntValue(strLanguage))); + }else if("8".equalsIgnoreCase(field006)){ + return SystemEnv.getHtmlLabelName(513400, Util.getIntValue(Util.getIntValue(strLanguage))); + }else { + return ""; + } + } + + public String getRequestLink(String fromDate,String req_requestid){ + WorkflowRequestComInfo workflowRequestComInfo = new WorkflowRequestComInfo(); + if(req_requestid.length() > 0 && Util.getIntValue(req_requestid) > 0){ + return "" + fromDate + ""; + }else{ + return fromDate; + } + } + + public String getOvertimeCard(String fromdate,String otherPara){ + String[] splitStr = Util.splitString(otherPara, "+"); + if(splitStr.length == 3){ + String fromtime = splitStr[0]; + String todate = splitStr[1]; + String totime = splitStr[2]; + //澶氭椂鍖轰細鎶婅繖涓枃瀛楃粰杞崲鏀规垚/ + String tmpfromdate = fromdate.replaceAll("-", "/"); + String tmptodate = todate.replaceAll("-", "/"); + String datetime = tmpfromdate+" "+fromtime+"-"+tmptodate+" "+totime; + return datetime; + } + return ""; + } +} diff --git a/src/com/engine/kq/web/KQReportDetailAction.java b/src/com/engine/kq/web/KQReportDetailAction.java new file mode 100644 index 0000000..0294c19 --- /dev/null +++ b/src/com/engine/kq/web/KQReportDetailAction.java @@ -0,0 +1,144 @@ +package com.engine.kq.web; + +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.common.util.ParamUtil; +import com.engine.common.util.ServiceUtil; +import com.engine.kq.biz.KQReportFieldComInfo; +import com.engine.kq.enums.KqSplitFlowTypeEnum; +import com.engine.kq.service.KQReportDetailService; +import com.engine.kq.service.impl.KQReportDetailServiceImpl; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import java.util.HashMap; +import java.util.Map; + +/** + * 鑰冨嫟鎶ヨ〃 + */ +public class KQReportDetailAction extends BaseBean { + + private KQReportDetailService getService(User user) { + return (KQReportDetailService) ServiceUtil.getService(KQReportDetailServiceImpl.class, user); + } + + /** + * 鑾峰彇鑰冨嫟鎶ヨ〃鏄庣粏Tabs + * @param request + * @param response + * @return + */ + @POST + @Path("/getTabs") + @Produces(MediaType.TEXT_PLAIN) + public String getTabs(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + apidatas = getService(user).getTabs(ParamUtil.request2Map(request), user); + } catch (Exception e) { + apidatas.put("status", "-1"); + writeLog(e); + } + return JSONObject.toJSONString(apidatas); + } + + /** + * 鑾峰彇鑰冨嫟鎶ヨ〃鏄庣粏 + * @param request + * @param response + * @return + */ + @POST + @Path("/getKQReportDetail") + @Produces(MediaType.TEXT_PLAIN) + public String getKQReportDetail(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + Map params =ParamUtil.request2Map(request) ; + params.put("isNoAccount","1") ; + RecordSet rs = new RecordSet(); + String sql = ""; + try { + User user = HrmUserVarify.getUser(request, response); + String type = Util.null2String(request.getParameter("type")); + String reportType = Util.null2String(request.getParameter("reportType")); + + if(KQReportFieldComInfo.cascadekey2fieldname.keySet().contains(type)){ + type=KQReportFieldComInfo.cascadekey2fieldname.get(type); + } + if(reportType.equals("month")) { + sql = "select formula from kq_report_field where fieldname = ? "; + rs.executeQuery(sql, type); + if(rs.next()){ + String formula = Util.null2String(rs.getString("formula")); + if(formula.indexOf("beLateMins")>-1){ + type = "beLate"; + params.put("type",type); + }else if(formula.indexOf("leaveEarlyMins")>-1){ + type = "leaveEearly"; + params.put("type",type); + } + params.put("formula",formula); + } + } + + if(type.equals("workdays")||type.equals("workmins")){ + apidatas = getService(user).getWorkDayInfo(params, user); + }else if(type.equals("attendancedays")||type.equals("attendanceMins")|| + type.equals("signdays")||type.equals("signmins")){ + apidatas = getService(user).getSignInfo(params, user); + }else if(type.equals("beLate")||type.equals("beLateMins")|| + type.equals("graveBeLate")||type.equals("graveBeLateMins")){ + apidatas = getService(user).getBeLateInfo(params, user); + }else if(type.equals("leaveEearly")||type.equals("leaveEarlyMins")|| + type.equals("graveLeaveEarly")||type.equals("graveLeaveEarlyMins")){ + apidatas = getService(user).getLeaveEearlyInfo(params, user); + }else if(type.equals("absenteeism")||type.equals("absenteeismMins")){ + apidatas = getService(user).getAbsenteeismInfo(params, user); + }else if(type.equals("forgotCheck")){ + apidatas = getService(user).getForgotCheckInfo(params, user); + }else if(type.equals("leave")||type.startsWith("leaveType_")||type.equals("overtimeTotal")|| + type.equals("businessLeave")||type.equals("officialBusiness")|| + type.equals("leaveDeduction")){ + apidatas = getService(user).getLeaveInfo(params, user); + } + } catch (Exception e) { + apidatas.put("status", "-1"); + writeLog(e); + } + return JSONObject.toJSONString(apidatas); + } + + /** + * 鑾峰彇鑰冨嫟鎶ヨ〃鏄庣粏淇℃伅 + * @param request + * @param response + * @return + */ + @POST + @Path("/getDailyDetialInfo") + @Produces(MediaType.TEXT_PLAIN) + public String getDailyDetialInfo(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap(); + try { + User user = HrmUserVarify.getUser(request, response); + apidatas = getService(user).getDailyDetialInfo(ParamUtil.request2Map(request), user); + } catch (Exception e) { + apidatas.put("status", "-1"); + writeLog(e); + } + return JSONObject.toJSONString(apidatas); + } +} diff --git a/src/com/engine/kq/wfset/action/KqSplitAction.java b/src/com/engine/kq/wfset/action/KqSplitAction.java new file mode 100644 index 0000000..8ab67a6 --- /dev/null +++ b/src/com/engine/kq/wfset/action/KqSplitAction.java @@ -0,0 +1,72 @@ +package com.engine.kq.wfset.action; + +import com.engine.kq.biz.KQFlowActiontBiz; +import com.engine.kq.log.KQLog; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.RequestInfo; +import weaver.workflow.workflow.WorkflowComInfo; + +/** + * 鑰冨嫟娴佺▼鏁版嵁鎷嗗垎action + */ +public class KqSplitAction extends BaseBean implements Action { + private KQLog kqLog = new KQLog(); + + @Override + public String execute(RequestInfo request) { + this.writeLog("KqSplitAction", "do action on request:" + request.getRequestid()); + String requestid = request.getRequestid(); + kqLog.info("do KqSplitAction on requestid:"+requestid); + int requestidInt = Util.getIntValue(requestid, 0); + + String workflowid = request.getWorkflowid(); + String formid = new WorkflowComInfo().getFormId(workflowid); + + try { + KQFlowActiontBiz kqFlowActiontBiz = new KQFlowActiontBiz(); + RecordSet rs = new RecordSet(); + String proc_set_sql = "select * from kq_att_proc_set where field001 = ? and field002 = ? "; + rs.executeQuery(proc_set_sql, workflowid,formid); + if(rs.next()){ + String proc_set_id = rs.getString("id"); + //寰楀埌杩欎釜鑰冨嫟娴佺▼璁剧疆鏄惁浣跨敤鏄庣粏 + String usedetails = rs.getString("usedetail"); + + int kqtype = Util.getIntValue(rs.getString("field006")); + kqLog.info("do action on kqtype:" + kqtype+":requestidInt:"+requestidInt); + Map map = new HashMap(); + if(requestidInt > 0){ + map.put("requestId", "and t.requestId = " + requestidInt); + } + + Map result = kqFlowActiontBiz.handleKQFlowAction(proc_set_id, usedetails, requestidInt, kqtype, Util.getIntValue(workflowid), false,false,map); + + if(!result.isEmpty()){ + String error = Util.null2String(result.get("message")); + request.getRequestManager().setMessageid("666" + request.getRequestid() + "999"); + request.getRequestManager().setMessagecontent(error); + return Action.FAILURE_AND_CONTINUE; + } + } + } catch (Exception e) { + kqLog.info("娴佺▼鏁版嵁鎶ラ敊:KqSplitAction:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + request.getRequestManager().setMessageid("11111" + request.getRequestid() + "22222"); + request.getRequestManager().setMessagecontent("銆愯冨嫟鎶ヨ〃缁熻action銆戞姤閿欙紝璇疯仈绯荤鐞嗗憳锛"); + return Action.FAILURE_AND_CONTINUE; + } + + return Action.SUCCESS; + + } + +} diff --git a/src/com/engine/kq/wfset/util/SplitActionUtil.java b/src/com/engine/kq/wfset/util/SplitActionUtil.java new file mode 100644 index 0000000..dc26692 --- /dev/null +++ b/src/com/engine/kq/wfset/util/SplitActionUtil.java @@ -0,0 +1,3208 @@ +package com.engine.kq.wfset.util; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.bean.KQHrmScheduleSign; +import com.engine.kq.biz.*; +import com.engine.kq.biz.chain.duration.WorkHalfUnitSplitChain; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.entity.KQOvertimeRulesDetailEntity; +import com.engine.kq.enums.DurationTypeEnum; +import com.engine.kq.log.KQLog; +import com.engine.kq.timer.KQQueue; +import com.engine.kq.timer.KQTaskBean; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.wfset.bean.OvertimeBalanceTimeBean; +import com.engine.kq.wfset.bean.SplitBean; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.BeanUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +public class SplitActionUtil extends BaseBean { + public static KQLog kqLog = new KQLog(); + + private static BaseBean baseBean = new BaseBean(); + /** + * 鐜板湪鍏堢敤姝e父鐨勫幓鎵ц鍚 + * @param splitBeans + * @param requestid + */ + public static void handleLeaveAction(List splitBeans, String requestid) { + for(int i = 0 ; i < splitBeans.size() ; i++){ + SplitBean splitBean = splitBeans.get(i); + String resourceId = splitBean.getResourceId(); + String duration = splitBean.getDuration(); + String newLeaveType = splitBean.getNewLeaveType(); + String durationrule = splitBean.getDurationrule(); + String fromdate = splitBean.getFromDate(); + String fromdatedb = splitBean.getFromdatedb(); + kqLog.info("璇峰亣鎵e噺:resourceId:"+resourceId+":fromdate:"+fromdate+":duration:"+duration+":newLeaveType:"+newLeaveType+":durationrule:"+durationrule+":requestid:"+requestid+":fromdatedb:"+fromdatedb); + KQBalanceOfLeaveBiz.addUsedAmount(resourceId, fromdate, newLeaveType, duration, "",requestid,fromdatedb); + } + } + + /** + * 鍗曠嫭閽堝鍔犵彮瑙勫垯鐨勭浜岀妯″紡 鐢熸垚鍔犵彮鏁版嵁 + * @param splitBeans + * @param requestid + */ + public static void handleOverTimeActionMode2(List splitBeans, String requestid) { + clearSameRequestTX(requestid); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + List overKeys = new ArrayList<>(); + for(int i = 0 ; i < splitBeans.size() ; i++){ + SplitBean splitBean = splitBeans.get(i); + int computingMode = Util.getIntValue(splitBean.getComputingMode()); + if(computingMode == 2 || computingMode == 4){ + //鍒ゆ柇娴佺▼瀵瑰簲鐨勬棩鏈熶笅鏈夋病鏈夋墦鍗℃暟鎹紝濡傛灉鏈夌殑璇濓紝闇瑕佺敓鎴愮浉搴旂殑璋冧紤鏁版嵁 + String belongDate = splitBean.getBelongDate(); + String resourceId = splitBean.getResourceId(); + String fromtime = splitBean.getFromTime(); + int fromtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + String key = resourceId+"_"+belongDate+"_"+ belongDate; + if(fromtimeIndex > 1439){ + //璺ㄥぉ浜 + key = resourceId+"_"+belongDate+"_"+ DateUtil.addDate(belongDate, 1); + } + if(!overKeys.contains(key)){ + overKeys.add(key); + } + } + if(computingMode == 1){ + doComputingMode1_splitBean(splitBean); + } + } + KQOverTimeRuleCalBiz kqOvertimeCalBiz = new KQOverTimeRuleCalBiz(); + kqLog.info("鍔犵彮鐢熸垚璋冧紤:handleOverTimeActionMode2 overKeys:"+JSON.toJSONString(overKeys)); + if(overKeys != null && !overKeys.isEmpty()){ + for(String key : overKeys){ + String[] keys = key.split("_",-1); + if(keys.length == 3){ + String resourceId = keys[0]; + String belongDate = keys[1]; + String belongToDate = keys[2]; + kqOvertimeCalBiz.buildOvertime(resourceId, belongDate, belongToDate,"鍔犵彮娴佺▼鐢熸垚鍔犵彮#flow,requestId:"+requestid); + } + } + } + } + + public static void turnOvertimeBeansWithRule(List splitBeans){ + + Map> resourceMap = new HashMap<>(); + //鍏紬鍋囨棩鍔犵彮鏃堕暱 + double D_Pub_Duration = 0.0; + double D_Pub_Mins = 0.0; + //宸ヤ綔鏃ュ姞鐝椂闀 + double D_Work_Duration = 0.0; + double D_Work_Mins = 0.0; + //浼戞伅鏃ュ姞鐝椂闀 + double D_Rest_Duration = 0.0; + double D_Rest_Mins = 0.0; + + //鍏紬鍋囨棩鍔犵彮 + List holiday = new ArrayList<>(); + //宸ヤ綔鏃ュ姞鐝 + List work = new ArrayList<>(); + //浼戞伅鏃ュ姞鐝 + List rest = new ArrayList<>(); + + String pub_date = ""; + String work_date = ""; + String rest_date = ""; + + //姣忎竴澶╃殑娴佺▼鏃堕暱閮藉湪杩欓噷浜嗭紝鎼炲惂 + for(SplitBean sb : splitBeans){ +// * 1-鍏紬鍋囨棩銆2-宸ヤ綔鏃ャ3-浼戞伅鏃 + String tmpResid = sb.getResourceId(); + if(resourceMap.containsKey(tmpResid)){ + resourceMap.get(tmpResid).add(sb); + }else{ + List splitBeans_tmp = new ArrayList<>(); + splitBeans_tmp.add(sb); + resourceMap.put(tmpResid, splitBeans_tmp); + } + } + if(!resourceMap.isEmpty()){ + for(Map.Entry> me : resourceMap.entrySet()){ + String resourceid = me.getKey(); + List tmp_splitbeans = me.getValue(); + for(SplitBean sb : tmp_splitbeans){ +// * 1-鍏紬鍋囨棩銆2-宸ヤ綔鏃ャ3-浼戞伅鏃 + int changeType = sb.getChangeType(); + double durations = Util.getDoubleValue(sb.getDuration(), 0.0); + double durationMins = sb.getD_Mins(); + if(1 == changeType){ + D_Pub_Duration += durations; + D_Pub_Mins += durationMins; + pub_date = sb.getBelongDate(); + holiday.add(sb); + } + if(2 == changeType){ + D_Work_Duration += durations; + D_Work_Mins += durationMins; + work_date = sb.getBelongDate(); + work.add(sb); + } + if(3 == changeType){ + D_Rest_Duration += durations; + D_Rest_Mins += durationMins; + rest_date = sb.getBelongDate(); + rest.add(sb); + } + } + + if(D_Pub_Duration > 0){ + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceid, pub_date); + if(D_Pub_Mins < minimumUnit){ + for(SplitBean tmp : holiday){ + tmp.setDuration("0.0"); + tmp.setD_Mins(0.0); + } + } + } + if(D_Work_Duration > 0){ + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceid, work_date); + if(D_Work_Mins < minimumUnit){ + for(SplitBean tmp : work){ + tmp.setDuration("0.0"); + tmp.setD_Mins(0.0); + } + } + } + if(D_Rest_Duration > 0){ + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceid, rest_date); + if(D_Rest_Mins < minimumUnit){ + for(SplitBean tmp : rest){ + tmp.setDuration("0.0"); + tmp.setD_Mins(0.0); + } + } + } + } + } + + } + + /** + * 鐢熸垚鍔犵彮鏁版嵁 + * @param splitBeans + * @param requestid + * @param canMode2 鏄惁鏄綊妗h妭鐐 褰掓。鑺傜偣鎵嶅彲浠ユ妸鍔犵彮鏁版嵁鍐欏埌鍔犵彮涓棿琛,涓嶆槸褰掓。鑺傜偣鐨勮瘽鎰忓懗鐫鍙敓鎴愯皟浼戜笉鐢熸垚鍔犵彮,鍙湁寮哄埗褰掓。canMode2鎵嶆槸true + * @param from_uuid 鏉ヨ嚜action鐨剈uid + */ + public static void handleOverTimeAction(List splitBeans, String requestid, + boolean canMode2, String from_uuid) throws Exception{ +// 淇濊瘉鍚屼竴涓猺equestid鑳介噸澶嶇敓鎴愯皟浼戝拰鍔犵彮 + if(canMode2){ + clearSameRequestTX(requestid); + } + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + RecordSet rs = new RecordSet(); + List overKeys = new ArrayList<>(); + for(int i = 0 ; i < splitBeans.size() ; i++){ + SplitBean splitBean = splitBeans.get(i); + String resourceId = splitBean.getResourceId(); + String belongDate = splitBean.getBelongDate(); + String toDate = splitBean.getToDate(); + String duration = splitBean.getDuration(); + String durationrule = splitBean.getDurationrule(); + + int computingMode = Util.getIntValue(splitBean.getComputingMode()); + int changeType = splitBean.getChangeType(); + String paidSql = "insert into KQ_PAID_VACATION (requestId,workflowId,dataid,detailid,resourceId,fromDate,fromTime,toDate,toTime,duration,durationrule,computingMode,changeType)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isLog = rs.executeUpdate(paidSql, splitBean.getRequestId(), splitBean.getWorkflowId(), + splitBean.getDataId(), splitBean.getDetailId(), splitBean.getResourceId(), + splitBean.getFromDate(), splitBean.getFromTime(), splitBean.getToDate(), + splitBean.getToTime(), splitBean.getDuration(),splitBean.getDurationrule(), computingMode,changeType); + if(isLog){ + kqLog.info("鍔犵彮鐢熸垚璋冧紤:resourceId:"+resourceId+":computingMode:"+computingMode+":belongDate:"+belongDate+":duration:"+duration+":durationrule:"+durationrule+":requestid:"+requestid); + + if(computingMode == 1){ + doComputingMode1_4TX(splitBean); + if(canMode2){ + doComputingMode1_splitBean(splitBean); + } + } + if(canMode2 && (computingMode == 2 || computingMode == 4)){ + //鍒ゆ柇娴佺▼瀵瑰簲鐨勬棩鏈熶笅鏈夋病鏈夋墦鍗℃暟鎹紝濡傛灉鏈夌殑璇濓紝闇瑕佺敓鎴愮浉搴旂殑璋冧紤鏁版嵁 + String fromtime = splitBean.getFromTime(); + int fromtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + String key = resourceId+"_"+belongDate+"_"+ belongDate; + if(fromtimeIndex > 1439){ + //璺ㄥぉ浜 + key = resourceId+"_"+belongDate+"_"+ DateUtil.addDate(belongDate, 1); + } + if(!overKeys.contains(key)){ + overKeys.add(key); + } + } + } + } + KQOverTimeRuleCalBiz kqOvertimeCalBiz = new KQOverTimeRuleCalBiz(); + kqLog.info("鍔犵彮鐢熸垚璋冧紤:handleOverTimeAction overKeys:"+JSON.toJSONString(overKeys)); + if(overKeys != null && !overKeys.isEmpty()){ + for(String key : overKeys){ + String[] keys = key.split("_",-1); + if(keys.length == 3){ + String resourceId = keys[0]; + String belongDate = keys[1]; + String belongToDate = keys[2]; + kqOvertimeCalBiz.buildOvertime(resourceId, belongDate, belongToDate, "鍔犵彮娴佺▼鐢熸垚鍔犵彮#flow,requestId:"+requestid+"#from_uuid|"+from_uuid); + } + } + } + } + + /** + * 淇濊瘉鍚屼竴涓猺equestid鑳介噸澶嶇敓鎴愯皟浼戝拰鍔犵彮 + * @param requestid + */ + public static void clearSameRequestTX(String requestid) { + String all_tiaoxiuids = ""; + List all_tiaoxiuidList = Lists.newArrayList(); + RecordSet rs = new RecordSet(); + String sql = "select * from kq_flow_overtime where requestid = ? "; + rs.executeQuery(sql, requestid); + while (rs.next()){ + String tiaoxiuid = Util.null2String(rs.getString("tiaoxiuid"),""); + if(tiaoxiuid.length() > 0 && Util.getIntValue(tiaoxiuid) > 0){ + all_tiaoxiuids += ","+tiaoxiuid; + all_tiaoxiuidList.add(tiaoxiuid); + } + } + if(all_tiaoxiuids.length() > 0){ + all_tiaoxiuids = all_tiaoxiuids.substring(1); + String tiaoxiuidis0 = ""; + String delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " baseamount =0 and extraamount=0 and usedamount=0 and baseamount2=0 and extraamount2=0 and usedamount2=0 "; + + if(rs.getDBType().equalsIgnoreCase("oracle")) { + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " nvl(baseamount,0) =0 and nvl(extraamount,0)=0 and nvl(usedamount,0)=0 and nvl(baseamount2,0)=0 " + + " and nvl(extraamount2,0)=0 and nvl(usedamount2,0)=0 "; + }else if((rs.getDBType()).equalsIgnoreCase("mysql")){ + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " ifnull(baseamount,0) =0 and ifnull(extraamount,0)=0 and ifnull(usedamount,0)=0 and ifnull(baseamount2,0)=0 " + + " and ifnull(extraamount2,0)=0 and ifnull(usedamount2,0)=0 "; + }else { + delSql0 = "select * from kq_balanceofleave where "+Util.getSubINClause(all_tiaoxiuids, "id", "in")+" and " + + " isnull(baseamount,0) =0 and isnull(extraamount,0)=0 and isnull(usedamount,0)=0 and isnull(baseamount2,0)=0 " + + " and isnull(extraamount2,0)=0 and isnull(usedamount2,0)=0 "; + } + rs.executeQuery(delSql0); + kqLog.info("all_tiaoxiuidList:"+all_tiaoxiuidList); + kqLog.info("clearSameRequestTX:"+delSql0); + while (rs.next()){ + String tiaoxiuid = Util.null2String(rs.getString("id"),""); + if(tiaoxiuid.length() > 0 && Util.getIntValue(tiaoxiuid) > 0){ + tiaoxiuidis0 += ","+tiaoxiuid; + all_tiaoxiuidList.remove(tiaoxiuid); + } + } + kqLog.info("all_tiaoxiuidList:"+all_tiaoxiuidList); + kqLog.info("tiaoxiuidis0:"+tiaoxiuidis0); + if(tiaoxiuidis0.length() > 0){ + tiaoxiuidis0 = tiaoxiuidis0.substring( 1); + String delSql = "delete from kq_balanceofleave where "+Util.getSubINClause(tiaoxiuidis0, "id", "in"); + boolean isok = rs.executeUpdate(delSql); + kqLog.info("delSql:"+delSql+":isok:"+isok); + } + if(!all_tiaoxiuidList.isEmpty()){ + String clear_tiaoxiuids = all_tiaoxiuidList.stream().collect(Collectors.joining(",")); + String clearSql = "update kq_balanceofleave set tiaoxiuamount=0.0 where "+Util.getSubINClause(clear_tiaoxiuids, "id", "in"); + boolean isclearOk = rs.executeUpdate(clearSql); + kqLog.info("clearSql:"+clearSql+":isclearOk:"+isclearOk); + } + + String delUsageSql = "delete from kq_usagehistory where "+Util.getSubINClause(all_tiaoxiuids, "balanceofleaveid", "in"); + boolean isdelUsageOk = rs.executeUpdate(delUsageSql); + kqLog.info("delUsageSql:"+delUsageSql+":isdelUsageOk:"+isdelUsageOk); + } + String delSql = "delete from kq_flow_overtime where requestid = ? "; + boolean isDelOk = rs.executeUpdate(delSql,requestid); + kqLog.info("delSql:"+delSql+":requestid:"+requestid+":isDelOk:"+isDelOk); + } + + /** + * 鍔犵彮鏂瑰紡鏄涓绉嶏紝濡傛灉鏄厛鐢熸垚璋冧紤锛屽悗闈㈡墠鐢熸垚鍔犵彮锛岄渶瑕佸厛鎶婅皟浼戠粰鎸夌収鍔犵彮瑙勫垯缁欑敓鎴愬嚭鏉 + * @param splitBean + */ + public static void doComputingMode1_4TX(SplitBean splitBean) { + RecordSet rs = new RecordSet(); + int changeType = splitBean.getChangeType(); + String resourceId = splitBean.getResourceId(); + String belongDate = splitBean.getBelongDate(); + String duration = splitBean.getDuration(); + String fromdateDB = splitBean.getFromdatedb(); + String requestId = splitBean.getRequestId(); + String fromdate = splitBean.getFromDate(); + String fromtime = splitBean.getFromTime(); + String todate = splitBean.getToDate(); + String totime = splitBean.getToTime(); + String overtime_type = splitBean.getOvertime_type(); + double D_Mins = splitBean.getD_Mins(); + int workMins = splitBean.getWorkmins(); + String workingHours = Util.null2String(workMins/60.0); + Map changeTypeMap = Maps.newHashMap(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + Map overRulesDetailMap = Maps.newHashMap(); + Map> restTimeMap = Maps.newHashMap(); + Map computingModeMap = Maps.newHashMap(); + //鍏堣幏鍙栦竴浜涘墠鎻愭暟鎹紝鍔犵彮瑕忓墖鍜屽亣鏈熻鍓 + kqOverTimeRuleCalBiz.getOverTimeDataMap(resourceId, belongDate, belongDate, dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap); + + String changeType_key = belongDate + "_" + changeType; + if(!overRulesDetailMap.containsKey(changeType_key)){ + return; + } +// 鏍规嵁鍔犵彮鍗曚綅閲嶆柊鐢熸垚涓嬪姞鐝垎閽熸暟 + D_Mins = kqOverTimeRuleCalBiz.getD_MinsByUnit(D_Mins); + + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + int paidLeaveEnable = kqOverTimeRuleCalBiz.getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type); + boolean needSplitByTime = kqOverTimeRuleCalBiz.getNeedSplitByTime(kqOvertimeRulesDetailEntity, paidLeaveEnable); + if(needSplitByTime) { + List overtimeBalanceTimeBeans = kqOverTimeRuleCalBiz + .getOvertimeBalanceTimeBean(resourceId, fromdate, fromtime, todate, totime, changeTypeMap, + kqOvertimeRulesDetailEntity, splitBean, restTimeMap,overRulesDetailMap); + if (overtimeBalanceTimeBeans != null && !overtimeBalanceTimeBeans.isEmpty()) { + for(int i = 0 ; i < overtimeBalanceTimeBeans.size() ;i++){ + OvertimeBalanceTimeBean overtimeBalanceTimeBean = overtimeBalanceTimeBeans.get(i); + String timepoint = overtimeBalanceTimeBean.getTimepoint(); + boolean needTX = overtimeBalanceTimeBean.isNeedTX(); + if(needTX){ + Map otherParam = Maps.newHashMap(); + otherParam.put("overtime_type", overtime_type); + otherParam.put("OvertimeBalanceTimeBean", overtimeBalanceTimeBean); + int timepoint_mins = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_mins == 0){ + continue; + } + String tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,belongDate,timepoint_mins+"","0",workingHours,requestId,"1",fromdateDB,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + //涓哄暐瑕佺敤kq_overtime_tiaoxiu杩欎釜琛ㄥ憿锛屽洜涓簁qpaidleaveaction鍙兘鍜宻plitaction涓嶆槸鍦ㄥ悓涓涓綊妗e墠鑺傜偣 + String split_key = splitBean.getRequestId()+"_"+splitBean.getDataId()+"_"+splitBean.getDetailId()+"_" + +splitBean.getFromDate()+"_"+splitBean.getFromTime()+"_"+splitBean.getToDate()+"_"+ + splitBean.getToTime()+"_"+splitBean.getD_Mins()+"_"+timepoint; + String tiaoxiuId_sql = "insert into kq_overtime_tiaoxiu(split_key,tiaoxiu_id) values(?,?) "; + rs.executeUpdate(tiaoxiuId_sql, split_key,tiaoxiuId); + kqLog.info("doComputingMode1 鍔犵彮鐢熸垚璋冧紤鎴愬姛锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1 鍔犵彮鐢熸垚璋冧紤澶辫触锛侊紒锛"); + } + } + } + }else{ + //璁剧疆浜嗘寜鐓ф椂闂村尯闂寸敓鎴愯皟浼戯紝浣嗘槸娌℃湁鏃堕棿鍖洪棿 + } + }else{ + Map otherParam = Maps.newHashMap(); + otherParam.put("overtime_type", overtime_type); + + String tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,belongDate,D_Mins+"","0",workingHours,requestId,"1",fromdateDB,otherParam); + if(Util.getIntValue(tiaoxiuId) > 0){ + //涓哄暐瑕佺敤kq_overtime_tiaoxiu杩欎釜琛ㄥ憿锛屽洜涓簁qpaidleaveaction鍙兘鍜宻plitaction涓嶆槸鍦ㄥ悓涓涓綊妗e墠鑺傜偣 + String split_key = splitBean.getRequestId()+"_"+splitBean.getDataId()+"_"+splitBean.getDetailId()+"_" + +splitBean.getFromDate()+"_"+splitBean.getFromTime()+"_"+splitBean.getToDate()+"_"+ + splitBean.getToTime()+"_"+splitBean.getD_Mins(); + String tiaoxiuId_sql = "insert into kq_overtime_tiaoxiu(split_key,tiaoxiu_id) values(?,?) "; + rs.executeUpdate(tiaoxiuId_sql, split_key,tiaoxiuId); + kqLog.info("doComputingMode1 鍔犵彮鐢熸垚璋冧紤鎴愬姛锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1 鍔犵彮鐢熸垚璋冧紤澶辫触锛侊紒锛"); + } + } + + } + + /** + * 鍔犵彮鏂瑰紡鏄涓绉嶏紝鐒跺悗鍐嶆祦绋嬪綊妗g殑鏃跺欐妸鍔犵彮鏁版嵁鍐欏埌鍔犵彮涓棿琛ㄩ噷 + * @param splitBean + */ + public static void doComputingMode1_splitBean(SplitBean splitBean) { + try{ + kqLog.info("doComputingMode1_splitBean:splitBean: "+ (splitBean != null ? JSON.toJSONString(splitBean) : "null")); + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + int changeType = splitBean.getChangeType(); + String requestId = splitBean.getRequestId(); + String resourceId = splitBean.getResourceId(); + String belongDate = splitBean.getBelongDate(); + String duration = splitBean.getDuration(); + String durationrule = splitBean.getDurationrule(); + String fromdateDB = splitBean.getFromdatedb(); + String fromtimedb = splitBean.getFromtimedb(); + String todatedb = splitBean.getTodatedb(); + String totimedb = splitBean.getTotimedb(); + String fromdate = splitBean.getFromDate(); + String fromtime = splitBean.getFromTime(); + String todate = splitBean.getToDate(); + String totime = splitBean.getToTime(); + double D_Mins = splitBean.getD_Mins(); + Map changeTypeMap = Maps.newHashMap(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + Map overRulesDetailMap = Maps.newHashMap(); + Map> restTimeMap = Maps.newHashMap(); + Map computingModeMap = Maps.newHashMap(); + //鍏堣幏鍙栦竴浜涘墠鎻愭暟鎹紝鍔犵彮瑕忓墖鍜屽亣鏈熻鍓 + kqOverTimeRuleCalBiz.getOverTimeDataMap(resourceId, belongDate, belongDate, dateFormatter,changeTypeMap,overRulesDetailMap,restTimeMap,computingModeMap); + String overtime_type = splitBean.getOvertime_type(); + String changeType_key = belongDate + "_" + changeType; + if(!overRulesDetailMap.containsKey(changeType_key)){ + return; + } + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + int paidLeaveEnable = kqOverTimeRuleCalBiz.getPaidLeaveEnable(kqOvertimeRulesDetailEntity,overtime_type); + boolean needSplitByTime = false;//kqOverTimeRuleCalBiz.getNeedSplitByTime(kqOvertimeRulesDetailEntity,paidLeaveEnable); + + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + if(needSplitByTime){ + List overtimeBalanceTimeBeans = kqOverTimeRuleCalBiz.getOvertimeBalanceTimeBean(resourceId, fromdate, fromtime, todate, totime, changeTypeMap, kqOvertimeRulesDetailEntity, splitBean, restTimeMap, + overRulesDetailMap); + if(overtimeBalanceTimeBeans != null && !overtimeBalanceTimeBeans.isEmpty()){ + for(int i = 0 ; i < overtimeBalanceTimeBeans.size() ;i++){ + OvertimeBalanceTimeBean overtimeBalanceTimeBean = overtimeBalanceTimeBeans.get(i); + String timepoint = overtimeBalanceTimeBean.getTimepoint(); + boolean needTX = overtimeBalanceTimeBean.isNeedTX(); + String tiaoxiu_id = ""; + String overtime_tiaoxiu_id = ""; + if(needTX){ + String split_key = splitBean.getRequestId()+"_"+splitBean.getDataId()+"_"+splitBean.getDetailId()+"_" + +splitBean.getFromDate()+"_"+splitBean.getFromTime()+"_"+splitBean.getToDate()+"_"+ + splitBean.getToTime()+"_"+splitBean.getD_Mins()+"_"+timepoint;; + String check_tiaoxiu_sql = "select * from kq_overtime_tiaoxiu where split_key=? "; + rs1.executeQuery(check_tiaoxiu_sql, split_key); + if(rs1.next()){ + overtime_tiaoxiu_id = rs1.getString("id"); + tiaoxiu_id = rs1.getString("tiaoxiu_id"); + } + } + int timepoint_mins = overtimeBalanceTimeBean.getTimepoint_mins(); + if(timepoint_mins == 0){ + continue; + } + String timePointStart = overtimeBalanceTimeBean.getTimepoint_start(); + String timePointEnd = overtimeBalanceTimeBean.getTimepoint_end(); + int timePointStart_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointStart); + int timePointEnd_index = kqTimesArrayComInfo.getArrayindexByTimes(timePointEnd); + String pointFromtime = timePointStart+":00"; + String pointTotime = timePointEnd + ":00"; + String flow_overtime_sql = "insert into kq_flow_overtime(requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,fromdatedb,fromtimedb,todatedb,totimedb,tiaoxiuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestId,resourceId,fromdate,pointFromtime,todate,pointTotime,timepoint_mins,"",belongDate,"", + unit,changeType,paidLeaveEnable,"1",fromdateDB,fromtimedb,todatedb,totimedb,tiaoxiu_id); + if(!isUp){ + kqLog.info("doComputingMode1 鍔犵彮鏁版嵁flow_overtime_sql璁板綍澶辫触锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1:flow_overtime_sql: "+flow_overtime_sql); + kqLog.info("doComputingMode1:requestId:"+requestId+":resourceId:"+resourceId+":fromdate:"+fromdate+":fromtime:"+fromtime + +":todate:"+todate+":totime:"+totime+":D_Mins:"+D_Mins+":belongDate:"+belongDate+":unit:"+unit+":changeType:"+changeType + +":paidLeaveEnable:"+paidLeaveEnable+":fromdateDB:"+fromdateDB+":fromtimedb:"+fromtimedb+":todatedb:"+todatedb+":totimedb:"+totimedb); + } + if(overtime_tiaoxiu_id.length() > 0 && Util.getIntValue(overtime_tiaoxiu_id) > 0){ + String delSql = "delete from kq_overtime_tiaoxiu where id = ? "; + rs1.executeUpdate(delSql, overtime_tiaoxiu_id); + } + } + }else{ + String tiaoxiu_id = ""; + String overtime_tiaoxiu_id = ""; + String split_key = splitBean.getRequestId()+"_"+splitBean.getDataId()+"_"+splitBean.getDetailId()+"_" + +splitBean.getFromDate()+"_"+splitBean.getFromTime()+"_"+splitBean.getToDate()+"_"+ + splitBean.getToTime()+"_"+splitBean.getD_Mins(); + String check_tiaoxiu_sql = "select * from kq_overtime_tiaoxiu where split_key=? "; + rs1.executeQuery(check_tiaoxiu_sql, split_key); + if(rs1.next()){ + overtime_tiaoxiu_id = rs1.getString("id"); + tiaoxiu_id = rs1.getString("tiaoxiu_id"); + } + + fromtime = fromtime+":00"; + totime = totime + ":00"; + String flow_overtime_sql = "insert into kq_flow_overtime(requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,fromdatedb,fromtimedb,todatedb,totimedb,tiaoxiuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestId,resourceId,fromdate,fromtime,todate,totime,D_Mins,"",belongDate,"", + unit,changeType,paidLeaveEnable,"1",fromdateDB,fromtimedb,todatedb,totimedb,tiaoxiu_id); + if(!isUp){ + kqLog.info("doComputingMode1 鍔犵彮鏁版嵁flow_overtime_sql璁板綍澶辫触锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1:flow_overtime_sql: "+flow_overtime_sql); + kqLog.info("doComputingMode1:requestId:"+requestId+":resourceId:"+resourceId+":fromdate:"+fromdate+":fromtime:"+fromtime + +":todate:"+todate+":totime:"+totime+":D_Mins:"+D_Mins+":belongDate:"+belongDate+":unit:"+unit+":changeType:"+changeType + +":paidLeaveEnable:"+paidLeaveEnable+":fromdateDB:"+fromdateDB+":fromtimedb:"+fromtimedb+":todatedb:"+todatedb+":totimedb:"+totimedb); + } + if(overtime_tiaoxiu_id.length() > 0 && Util.getIntValue(overtime_tiaoxiu_id) > 0){ + String delSql = "delete from kq_overtime_tiaoxiu where id = ? "; + rs1.executeUpdate(delSql, overtime_tiaoxiu_id); + } + } + }else{ + + String tiaoxiu_id = ""; + String overtime_tiaoxiu_id = ""; + + String split_key = splitBean.getRequestId()+"_"+splitBean.getDataId()+"_"+splitBean.getDetailId()+"_" + +splitBean.getFromDate()+"_"+splitBean.getFromTime()+"_"+splitBean.getToDate()+"_"+ + splitBean.getToTime()+"_"+splitBean.getD_Mins(); + String check_tiaoxiu_sql = "select * from kq_overtime_tiaoxiu where split_key=? "; + rs1.executeQuery(check_tiaoxiu_sql, split_key); + if(rs1.next()){ + overtime_tiaoxiu_id = rs1.getString("id"); + tiaoxiu_id = rs1.getString("tiaoxiu_id"); + } + + fromtime = fromtime+":00"; + totime = totime + ":00"; + String flow_overtime_sql = "insert into kq_flow_overtime(requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,fromdatedb,fromtimedb,todatedb,totimedb,tiaoxiuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestId,resourceId,fromdate,fromtime,todate,totime,D_Mins,"",belongDate,"", + unit,changeType,paidLeaveEnable,"1",fromdateDB,fromtimedb,todatedb,totimedb,tiaoxiu_id); + if(!isUp){ + kqLog.info("doComputingMode1 鍔犵彮鏁版嵁flow_overtime_sql璁板綍澶辫触锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1:flow_overtime_sql: "+flow_overtime_sql); + kqLog.info("doComputingMode1:requestId:"+requestId+":resourceId:"+resourceId+":fromdate:"+fromdate+":fromtime:"+fromtime + +":todate:"+todate+":totime:"+totime+":D_Mins:"+D_Mins+":belongDate:"+belongDate+":unit:"+unit+":changeType:"+changeType + +":paidLeaveEnable:"+paidLeaveEnable+":fromdateDB:"+fromdateDB+":fromtimedb:"+fromtimedb+":todatedb:"+todatedb+":totimedb:"+totimedb); + } + if(overtime_tiaoxiu_id.length() > 0 && Util.getIntValue(overtime_tiaoxiu_id) > 0){ + String delSql = "delete from kq_overtime_tiaoxiu where id = ? "; + rs1.executeUpdate(delSql, overtime_tiaoxiu_id); + } + } + + }catch (Exception e){ + kqLog.info("鍔犵彮鐢熸垚鏁版嵁鎶ラ敊:doComputingMode1_splitBean:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + + } + + /** + * 绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁 + * @param taskBeans + */ + public void handleOverTime(List taskBeans) throws Exception{ + try{ + if(true){ + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + for(int i = 0 ;i < taskBeans.size() ; i++){ + KQTaskBean taskBean = taskBeans.get(i); + String tasktype = taskBean.getTasktype(); + String eventtype = ""; + if("punchcard".equalsIgnoreCase(tasktype)){ + eventtype = "鑰冨嫟鎵撳崱鐢熸垚鍔犵彮."; + } + kqOverTimeRuleCalBiz.buildOvertime(taskBean.getResourceId(), taskBean.getOvertime_fromdate(),taskBean.getOvertime_todate(), + eventtype); + } + }else{ + handleOverTime_old(taskBeans); + } + }catch (Exception e){ + kqLog.info("鍔犵彮鐢熸垚鏁版嵁鎶ラ敊:handleOverTime:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + } + + public void handleOverTime_old(List taskBeans) throws Exception{ + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + int workMins = (int)(KQFlowUtil.getOneDayHour(DurationTypeEnum.OVERTIME, "")*60); + kqLog.info("handleOverTime:start:"+(taskBeans != null ? JSON.toJSONString(taskBeans) : "is empty")); + //闃叉bean閲岄噸澶嶇殑 + List repeat_taskBeans = new ArrayList<>(); + for(int i = 0 ;i < taskBeans.size() ; i++){ + KQTaskBean taskBean = taskBeans.get(i); + if(repeat_taskBeans.contains(taskBean)){ + continue; + }else{ + repeat_taskBeans.add(taskBean); + } + taskBean.setWorkmins(workMins); + String resourceId = taskBean.getResourceId(); + String taskDate = taskBean.getTaskDate(); + int overtimeEnable = KQOvertimeRulesBiz.getOvertimeEnable(resourceId, taskDate); + + //濡傛灉浜哄啀褰撳墠鎸囧畾鏃ユ湡涓嬫湭寮鍚姞鐝紝鐩存帴璺宠繃 + if(overtimeEnable != 1){ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁 handleOverTimeBySign:resourceId锛"+resourceId+":taskDate:"+taskDate+"涓嶅厑璁稿姞鐝"); + continue; + } + + int computingMode = KQOvertimeRulesBiz.getComputingMode(resourceId, taskDate); + kqLog.info("鍔犵彮鐢熸垚璋冧紤鏂瑰紡:resourceId:"+resourceId+":taskDate:"+taskDate+":computingMode:"+computingMode); + if(computingMode == 1) { +// 闇瀹℃壒锛屼互瀹℃壒鍗曚负鍑 + doComputingMode1(taskBean,fullFormatter); + } + if(computingMode == 2){ +// 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屼絾鏄笉鑳借秴杩囧鎵规椂闀 + doComputingMode2(taskBean,fullFormatter); + } + if(computingMode == 3){ +// 鏃犻渶瀹℃壒锛屾牴鎹墦鍗℃椂闂磋绠楀姞鐝椂闀 + doComputingMode3(taskBean,fullFormatter); + } + } + } + + /** + * 娴佺▼涓轰富鐨勫氨鍦ㄦ祦绋嬪綊妗g殑鏃跺欏鐞嗕笅锛屼笉鍦ㄩ槦鍒楅噷杩涜澶勭悊浜 + * @param taskBean + * @param fullFormatter + * @throws Exception + */ + @Deprecated + private void doComputingMode1(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + SplitBean splitBean = taskBean.getSplitBean(); + kqLog.info("doComputingMode1:splitBean: start"); + if(splitBean != null){ + RecordSet rs = new RecordSet(); + int changeType = splitBean.getChangeType(); + String requestId = splitBean.getRequestId(); + String resourceId = splitBean.getResourceId(); + String belongDate = splitBean.getBelongDate(); + String duration = splitBean.getDuration(); + String durationrule = splitBean.getDurationrule(); + String fromdateDB = splitBean.getFromdatedb(); + String fromtimedb = splitBean.getFromtimedb(); + String todatedb = splitBean.getTodatedb(); + String totimedb = splitBean.getTotimedb(); + String fromdate = splitBean.getFromDate(); + String fromtime = splitBean.getFromTime(); + String todate = splitBean.getToDate(); + String totime = splitBean.getToTime(); + double D_Mins = splitBean.getD_Mins(); + + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, belongDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + + fromtime = fromtime+":00"; + totime = totime + ":00"; + String flow_overtime_sql = "insert into kq_flow_overtime(requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,fromdatedb,fromtimedb,todatedb,totimedb)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestId,resourceId,fromdate,fromtime,todate,totime,D_Mins,"",belongDate,"", + unit,changeType,paidLeaveEnable,"1",fromdateDB,fromtimedb,todatedb,totimedb); + if(!isUp){ + kqLog.info("doComputingMode1 鍔犵彮鏁版嵁flow_overtime_sql璁板綍澶辫触锛侊紒锛"); + }else{ + kqLog.info("doComputingMode1:flow_overtime_sql: "+flow_overtime_sql); + kqLog.info("doComputingMode1:requestId:"+requestId+":resourceId:"+resourceId+":fromdate:"+fromdate+":fromtime:"+fromtime + +":todate:"+todate+":totime:"+totime+":D_Mins:"+D_Mins+":belongDate:"+belongDate+":unit:"+unit+":changeType:"+changeType + +":paidLeaveEnable:"+paidLeaveEnable+":fromdateDB:"+fromdateDB+":fromtimedb:"+fromtimedb+":todatedb:"+todatedb+":totimedb:"+totimedb); + } + } + } + + /** + * 鏃犻渶瀹℃壒锛屼互鎵撳崱涓哄噯锛屼絾鏄笉鑳借秴杩囧鎵规椂闀 + * @param taskBean + * @param fullFormatter + */ + private void doComputingMode2(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + String resourceId = taskBean.getResourceId(); + String taskDate = taskBean.getTaskDate(); + KQFlowDataBiz kqFlowDataBiz = new KQFlowDataBiz.FlowDataParamBuilder().belongDateParam(taskDate).resourceidParam(resourceId).build(); + Map flowMaps = new HashMap<>(); + List splitBeans = kqFlowDataBiz.getOverTimeData(flowMaps); + if(!splitBeans.isEmpty()){ + Map flowMap = new HashMap<>(); + Map requestMap = new HashMap<>(); + for(int i = 0 ; i < splitBeans.size() ; i ++){ + SplitBean splitBean = splitBeans.get(i); + String changeTpe = ""+splitBean.getChangeType(); + String requestid = splitBean.getRequestId(); + String flowMins = Util.null2String(splitBean.getD_Mins()); + if(flowMap.get(changeTpe) != null){ + double tmpMins = Util.getDoubleValue(Util.null2String(flowMap.get(changeTpe)),0.0); + flowMap.put(changeTpe, ""+(tmpMins+Util.getDoubleValue(flowMins))); + }else{ + flowMap.put(changeTpe, flowMins); + } + if(requestMap.get(changeTpe) != null){ + String tmpRequestid = Util.null2String(requestMap.get(changeTpe)); + if((","+tmpRequestid+",").indexOf(requestid) < 0){ + requestMap.put(changeTpe, tmpRequestid+","+requestid); + } + }else{ + requestMap.put(changeTpe, requestid); + } + } + int changeType = KQOvertimeRulesBiz.getChangeType(resourceId, taskDate); + if(requestMap.get(""+changeType) != null){ + taskBean.setRequestId(requestMap.get(""+changeType)); + } + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doComputingMode2:鍔犵彮娴佺▼鏁版嵁涓 flowMap:"+flowMap); +// 1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃 + if(changeType == 1){ + doMode2ChangeType1(taskBean,fullFormatter,flowMap.get("1")); + } + if(changeType == 2){ + doMode2ChangeType2(taskBean,fullFormatter,flowMap.get("2")); + } + if(changeType == 3){ + doMode2ChangeType3(taskBean,fullFormatter,flowMap.get("3")); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doComputingMode2:鍔犵彮娴佺▼鏁版嵁涓虹┖:resourceId:"+resourceId+":taskDate:"+taskDate); + } + } + + + /** + * 闇瀹℃壒锛屼互鎵撳崱涓哄噯 + * 浼戞伅鏃 + * @param taskBean + * @param fullFormatter + * @param flowMins + */ + private void doMode2ChangeType3(KQTaskBean taskBean, DateTimeFormatter fullFormatter, + String flowMins) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String signInTime4Out = taskBean.getSignInTime4Out(); + String requestid = taskBean.getRequestId(); + String signDate = taskBean.getSignDate(); + String signEndDate= taskBean.getSignEndDate(); + String timesource = Util.null2String(taskBean.getTimesource()); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + if(taskSignTime.length() > 0 && signInTime4Out.length() > 0){ + + long mins = calNonWorkDuration(signInTime4Out,taskSignTime,taskDate,resourceId); + if(isBefore && signEndDate.compareTo(signDate) < 0){ + //鎵撳崱鏃ユ湡鍜屽綊灞炴棩鏈熶笉鏄悓涓澶╃殑璇 + String fromDateTime = signEndDate+" "+signInTime4Out; + String toDateTime = signDate+" "+taskSignTime; +// 杩橀渶瑕佷氦鎹竴涓嬪紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡 + String tmpDate = signDate; + signDate = signEndDate; + signEndDate = tmpDate; + mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + } + if(mins > 0){ + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit && Util.getDoubleValue(flowMins) >= minimumUnit){ + RecordSet rs = new RecordSet(); + String fromtime = ""; + String totime = ""; + double D_flowMins = Util.getDoubleValue(flowMins); + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + }else{ + checkLastSignTime = after_checkLastSignTime; + } + if(checkLastSignTime.compareTo(signInTime4Out) > 0){ + fromtime = checkLastSignTime; + }else{ + fromtime = signInTime4Out; + } + totime = taskSignTime; + if(hasMins >= D_flowMins){ + //濡傛灉宸茬粡鐢熸垚杩囩殑鍔犵彮鏁版嵁宸茬粡澶т簬绛変簬娴佺▼鏃堕暱浜嗭紝閭d箞姝ゆ鐨勫姞鐝椂闀垮氨鏄0 + mins = 0; + }else{ + if(isBefore){ + //濡傛灉鏄笂鐝墠 褰撳墠鐨勬墦鍗℃椂闀+涓嬬彮鍚庡凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+after_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-after_hasMins-before_hasMins); + }else{ + mins = (long) (mins-before_hasMins); + } + }else{ + //濡傛灉鏄笅鐝悗 褰撳墠鐨勬墦鍗℃椂闀+涓婄彮鍓嶅凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+before_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-before_hasMins-after_hasMins); + }else{ + mins = (long) (mins-after_hasMins); + } + } + } + }else{ + fromtime = signInTime4Out; + totime = taskSignTime; + if(D_flowMins > 0 && mins > D_flowMins){ + //涔嬪墠娌℃湁鐢熸垚杩囧姞鐝 鎵撳崱鍔犵彮鏃堕暱涓嶈兘瓒呰繃娴佺▼鏃堕暱 + mins = (long) D_flowMins; + } + } + mins = mins < 0 ? 0 : mins; + if(mins <= 0){ + return; + } + + String tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0","",requestid,"",taskDate,null); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁鎴愬姛 doMode2ChangeType3:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁澶辫触 doMode2ChangeType3:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + } + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceId,signDate,fromtime,signEndDate,totime,mins,"",taskDate,"",unit,"3",paidLeaveEnable,"2",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType3 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + + logMultiSign(resourceId,taskDate,taskSignTime,"",0,signInTime4Out,mins,signEndDate,timesource, + uuid, tiaoxiuId); + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType2:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit+":娴佺▼鏃堕暱:Util.getDoubleValue(flowMins):"+Util.getDoubleValue(flowMins)); + } + + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType3:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode2ChangeType3:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + + } + + /** + * 闇瀹℃壒锛屼互鎵撳崱涓哄噯 + * 宸ヤ綔鏃 + * @param taskBean + * @param fullFormatter + * @param flowMins + */ + private void doMode2ChangeType2(KQTaskBean taskBean, DateTimeFormatter fullFormatter, + String flowMins) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String lastWorkTime = taskBean.getLastWorkTime(); + String signDate = taskBean.getSignDate(); + String signEndDate = taskBean.getSignEndDate(); + String requestid = taskBean.getRequestId(); + String timesource = Util.null2String(taskBean.getTimesource()); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + int workMins = taskBean.getWorkmins(); + if(taskSignTime.length() > 0 && lastWorkTime.length() > 0){ + if(lastWorkTime.length() == 5){ + lastWorkTime = lastWorkTime+":00"; + } + String fromDateTime = signDate+" "+lastWorkTime; + String toDateTime = signEndDate+" "+taskSignTime; + int startTime = KQOvertimeRulesBiz.getStartTime(resourceId, taskDate); + startTime = startTime < 0 ? 0 : startTime; + if(isBefore){ + //涓婄彮鍓嶅氨涓嶄笉闇瑕佽冭檻涓嬬彮鍚庡涔呯畻鍔犵彮杩欎釜閫昏緫浜 + startTime = 0; + } + long mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter).plusMinutes(startTime), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + if(mins > 0){ + String workingHours = Util.null2String(workMins/60.0); + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit && Util.getDoubleValue(flowMins) >= minimumUnit){ + RecordSet rs = new RecordSet(); + boolean isLateoutlatein = checkIsLateoutlatein(resourceId, taskDate); + if(!isLateoutlatein){ + String fromDate = ""; + String fromtime = ""; + String toDate = ""; + String totime = ""; + double D_flowMins = Util.getDoubleValue(flowMins); + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + String before_checkLastSignTimesource = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + String after_checkLastSignTimesource = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_checkLastSignTimesource = Util.null2String(tmpMap.get("checkLastSignTimesource")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_checkLastSignTimesource = Util.null2String(tmpMap.get("checkLastSignTimesource")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + String checkLastSignDate = ""; + String checkLastSignTimesource = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + checkLastSignDate = before_checkLastSignDate; + checkLastSignTimesource = before_checkLastSignTimesource; + }else{ + checkLastSignTime = after_checkLastSignTime; + checkLastSignDate = after_checkLastSignDate; + checkLastSignTimesource = after_checkLastSignTimesource; + } + if(isBefore){ + fromDate = signDate; + fromtime = lastWorkTime; + if("before".equalsIgnoreCase(checkLastSignTimesource)){ + toDate = checkLastSignDate; + totime = checkLastSignTime; + }else{ + String[] toDateTimes = toDateTime.split(" "); + if(toDateTimes.length == 2){ + toDate = toDateTimes[0]; + totime = toDateTimes[1]; + } + } + }else{ + if(checkLastSignDate.length() > 0 && checkLastSignTime.length() > 0){ + fromDate = checkLastSignDate; + fromtime = checkLastSignTime; + }else{ + fromDate = signDate; + fromtime = lastWorkTime; + } + toDate = signEndDate; + totime = taskSignTime; + } + + if(hasMins >= D_flowMins){ + //濡傛灉宸茬粡鐢熸垚杩囩殑鍔犵彮鏁版嵁宸茬粡澶т簬绛変簬娴佺▼鏃堕暱浜嗭紝閭d箞姝ゆ鐨勫姞鐝椂闀垮氨鏄0 + mins = 0; + }else{ + if(isBefore){ + //濡傛灉鏄笂鐝墠 褰撳墠鐨勬墦鍗℃椂闀+涓嬬彮鍚庡凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+after_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-after_hasMins-before_hasMins); + }else{ + mins = (long) (mins-before_hasMins); + } + }else{ + //濡傛灉鏄笅鐝悗 褰撳墠鐨勬墦鍗℃椂闀+涓婄彮鍓嶅凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+before_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-before_hasMins-after_hasMins); + }else{ + mins = (long) (mins-after_hasMins); + } + } + } + }else{ + String[] fromDateTimes = fromDateTime.split(" "); + String[] toDateTimes = toDateTime.split(" "); + if(fromDateTimes.length == 2){ + fromDate = fromDateTimes[0]; + fromtime = fromDateTimes[1]; + } + if(toDateTimes.length == 2){ + toDate = toDateTimes[0]; + totime = toDateTimes[1]; + } + if(D_flowMins > 0 && mins > D_flowMins){ + //涔嬪墠娌℃湁鐢熸垚杩囧姞鐝 鎵撳崱鍔犵彮鏃堕暱涓嶈兘瓒呰繃娴佺▼鏃堕暱 + mins = (long) D_flowMins; + } + } + mins = mins < 0 ? 0 : mins; + if(mins <= 0){ + return; + } + + String tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0",workingHours,requestid,"",taskDate,null); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁涓烘垚鍔 doMode2ChangeType2:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins+":workingHours:"+workingHours); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁涓哄け璐 doMode2ChangeType2:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins+":workingHours:"+workingHours); + } + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceId,signDate,fromtime,signEndDate,totime,mins,"",taskDate,"",unit,"2",paidLeaveEnable,"2",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType2 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + + logMultiSign(resourceId,taskDate,taskSignTime,lastWorkTime,0,"",mins,signEndDate,timesource, + uuid, tiaoxiuId); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType2:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit+":娴佺▼鏃堕暱:Util.getDoubleValue(flowMins):"+Util.getDoubleValue(flowMins)); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType2:fromDateTime:"+fromDateTime+":toDateTime:"+toDateTime+":mins:"+mins); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode2ChangeType2:taskSignTime:"+taskSignTime+":lastWorkTime:"+lastWorkTime); + } + + } + + /** + * 闇瀹℃壒锛屼互鎵撳崱涓哄噯 + * 鑺傚亣鏃 + * @param taskBean + * @param fullFormatter + * @param flowMins + */ + private void doMode2ChangeType1(KQTaskBean taskBean, DateTimeFormatter fullFormatter, + String flowMins) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String signInTime4Out = taskBean.getSignInTime4Out(); + String requestid = taskBean.getRequestId(); + String signDate = taskBean.getSignDate(); + String signEndDate= taskBean.getSignEndDate(); + String timesource = Util.null2String(taskBean.getTimesource()); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + if(taskSignTime.length() > 0 && signInTime4Out.length() > 0){ + + long mins = calNonWorkDuration(signInTime4Out,taskSignTime,taskDate,resourceId); + if(isBefore && signEndDate.compareTo(signDate) < 0){ + //鎵撳崱鏃ユ湡鍜屽綊灞炴棩鏈熶笉鏄悓涓澶╃殑璇 + String fromDateTime = signEndDate+" "+signInTime4Out; + String toDateTime = signDate+" "+taskSignTime; +// 杩橀渶瑕佷氦鎹竴涓嬪紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡 + String tmpDate = signDate; + signDate = signEndDate; + signEndDate = tmpDate; + mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + } + if(mins > 0){ + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit && Util.getDoubleValue(flowMins) >= minimumUnit){ + RecordSet rs = new RecordSet(); + String fromtime = ""; + String totime = ""; + double D_flowMins = Util.getDoubleValue(flowMins); + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + }else{ + checkLastSignTime = after_checkLastSignTime; + } + if(checkLastSignTime.compareTo(signInTime4Out) > 0){ + fromtime = checkLastSignTime; + }else{ + fromtime = signInTime4Out; + } + totime = taskSignTime; + if(hasMins >= D_flowMins){ + //濡傛灉宸茬粡鐢熸垚杩囩殑鍔犵彮鏁版嵁宸茬粡澶т簬绛変簬娴佺▼鏃堕暱浜嗭紝閭d箞姝ゆ鐨勫姞鐝椂闀垮氨鏄0 + mins = 0; + }else{ + if(mins > D_flowMins){ + //濡傛灉鎵撳崱鏃堕暱澶т簬娴佺▼鏃堕暱 + mins = (long) (D_flowMins-hasMins); + }else { + if(isBefore){ + //濡傛灉鏄笂鐝墠 褰撳墠鐨勬墦鍗℃椂闀+涓嬬彮鍚庡凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+after_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-after_hasMins-before_hasMins); + }else{ + mins = (long) (mins-before_hasMins); + } + }else{ + //濡傛灉鏄笅鐝悗 褰撳墠鐨勬墦鍗℃椂闀+涓婄彮鍓嶅凡缁忕敓鎴愯繃鐨勫姞鐝椂闀匡紝鍜屾祦绋嬫绘椂闀跨殑姣旇緝 + double before_after_mins = mins+before_hasMins; + if(before_after_mins > D_flowMins){ + mins = (long) (D_flowMins-before_hasMins-after_hasMins); + }else{ + mins = (long) (mins-after_hasMins); + } + } + } + } + }else{ + fromtime = signInTime4Out; + totime = taskSignTime; + if(D_flowMins > 0 && mins > D_flowMins){ + //涔嬪墠娌℃湁鐢熸垚杩囧姞鐝 鎵撳崱鍔犵彮鏃堕暱涓嶈兘瓒呰繃娴佺▼鏃堕暱 + mins = (long) D_flowMins; + } + } + mins = mins < 0 ? 0 : mins; + if(mins <= 0){ + return; + } + + String tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0","",requestid,"",taskDate,null); + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁鎴愬姛 doMode2ChangeType1:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁澶辫触 doMode2ChangeType1:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + } + + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestid,resourceId,signDate,fromtime,signEndDate,totime,mins,"",taskDate,"",unit,"1",paidLeaveEnable,"2",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType1 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + logMultiSign(resourceId,taskDate,taskSignTime,"",0,signInTime4Out,mins,signEndDate,timesource, + uuid, tiaoxiuId); + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType1:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit+":娴佺▼鏃堕暱:Util.getDoubleValue(flowMins):"+Util.getDoubleValue(flowMins)); + } + + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode2ChangeType1:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode2ChangeType1:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + + } + + /** + * 鎵撳崱璁$畻闈炲伐浣滄椂闀 + * @param fromTime + * @param toTime + * @param date + * @param resourceid + * @return + */ + private int calNonWorkDuration(String fromTime,String toTime,String date,String resourceid) { + fromTime = (fromTime.length() > 6 ? fromTime.substring(0,5) : fromTime); + toTime = (toTime.length() > 6 ? toTime.substring(0,5) : toTime); + + List restTimeList = KQOvertimeRulesBiz.getRestTimeList(resourceid, date); + KQTimesArrayComInfo arrayComInfo = new KQTimesArrayComInfo(); + int[] initArrays = arrayComInfo.getInitArr(); + int startIndex = 0; + int endIndex = 0; + startIndex = arrayComInfo.getArrayindexByTimes(fromTime); + endIndex = arrayComInfo.getArrayindexByTimes(toTime); + if(startIndex > endIndex){ + return 0; + } + + //鍏堟妸瑕佽绠楃殑鏃堕暱濉厖涓0 + Arrays.fill(initArrays, startIndex, endIndex, 0); + + //鍐嶆妸浼戞伅鏃堕棿濉厖涓婂幓 + if(!restTimeList.isEmpty()){ + for(int i =0 ; i < restTimeList.size() ; i++){ + String[] restTimes = restTimeList.get(i); + if(restTimes.length == 2){ + int restStart = arrayComInfo.getArrayindexByTimes(restTimes[0]); + int restEnd = arrayComInfo.getArrayindexByTimes(restTimes[1]); + Arrays.fill(initArrays, restStart, restEnd, 1); + } + } + } + //鏈鍚庢帓闄ゆ帀浼戞伅鏃堕棿杩樺墿澶氬皯鍔犵彮鏃堕暱灏辨槸鏈缁堢殑缁撴灉 + int curMins = arrayComInfo.getCnt(initArrays, startIndex, endIndex+1, 0); + + return curMins; + } + + /** + * 鏃犻渶瀹℃壒锛屾牴鎹墦鍗℃椂闂磋绠楀姞鐝椂闀 + * @param taskBean + * @param fullFormatter + */ + private void doComputingMode3(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + String resourceId = taskBean.getResourceId(); + String taskDate = taskBean.getTaskDate(); + int changeType = KQOvertimeRulesBiz.getChangeType(resourceId, taskDate); +// 1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃 + if(changeType == 1){ + doMode3ChangeType1(taskBean,fullFormatter); + } + if(changeType == 2){ + doMode3ChangeType2(taskBean,fullFormatter); + } + if(changeType == 3){ + doMode3ChangeType3(taskBean,fullFormatter); + } + } + + /** + * 鏃犻渶瀹℃壒锛屾牴鎹墦寮鏃堕棿璁$畻鍔犵彮鏃堕暱 + * 浼戞伅鏃ュ鐞 + * @param taskBean + * @param fullFormatter + */ + private void doMode3ChangeType3(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String signInTime4Out = taskBean.getSignInTime4Out(); + String signDate = taskBean.getSignDate(); + String signEndDate= taskBean.getSignEndDate(); + String timesource = Util.null2String(taskBean.getTimesource()); + String up_tiaoxiuid = taskBean.getTiaoxiuId(); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + if(taskSignTime.length() > 0 && signInTime4Out.length() > 0){ + + long mins = calNonWorkDuration(signInTime4Out,taskSignTime,taskDate,resourceId); + if(isBefore && signEndDate.compareTo(signDate) < 0){ + //鎵撳崱鏃ユ湡鍜屽綊灞炴棩鏈熶笉鏄悓涓澶╃殑璇 + String fromDateTime = signEndDate+" "+signInTime4Out; + String toDateTime = signDate+" "+taskSignTime; +// 杩橀渶瑕佷氦鎹竴涓嬪紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡 + String tmpDate = signDate; + signDate = signEndDate; + signEndDate = tmpDate; + mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + } + if(mins > 0){ + RecordSet rs = new RecordSet(); + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit){ + if(taskSignTime.length() == 5){ + taskSignTime += ":00"; + } + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + + String fromtime = ""; + String totime = ""; + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + }else{ + checkLastSignTime = after_checkLastSignTime; + } + if(checkLastSignTime.compareTo(signInTime4Out) > 0){ + fromtime = checkLastSignTime; + }else{ + fromtime = signInTime4Out; + } + totime = taskSignTime; + if(isBefore){ + mins = (long) (mins-before_hasMins); + }else{ + mins = (long) (mins-after_hasMins); + } + }else{ + fromtime = signInTime4Out; + totime = taskSignTime; + } + mins = mins < 0 ? 0 : mins; + + String tiaoxiuId = ""; + if(up_tiaoxiuid.length() > 0 && Util.getIntValue(up_tiaoxiuid) > 0){ + boolean is_tiaoxiuId = KQBalanceOfLeaveBiz.updateExtraAmountByDis5(up_tiaoxiuid,Util.getDoubleValue(mins+""), ""); + tiaoxiuId = up_tiaoxiuid; + }else{ + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0","","","",taskDate,null); + } + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁鎴愬姛 doMode3ChangeType3:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁澶辫触 doMode3ChangeType3:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + } + + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, "",resourceId,signDate,fromtime,signEndDate,totime,mins,"",taskDate,"",unit,"3",paidLeaveEnable,"3",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType1 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + logMultiSign(resourceId,taskDate,taskSignTime,"",0,signInTime4Out,mins,signEndDate,timesource, + uuid, tiaoxiuId); + + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType3:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit); + } + + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType3:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode3ChangeType3:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + + } + + + /** + * 鏃犻渶瀹℃壒锛屾牴鎹墦寮鏃堕棿璁$畻鍔犵彮鏃堕暱 + * 宸ヤ綔鏃ュ鐞 + * @param taskBean + * @param fullFormatter + */ + private void doMode3ChangeType2(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String lastWorkTime = taskBean.getLastWorkTime(); + String signDate = taskBean.getSignDate(); + String signEndDate = taskBean.getSignEndDate(); + String timesource = taskBean.getTimesource(); + String up_tiaoxiuid = taskBean.getTiaoxiuId(); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + int workMins = taskBean.getWorkmins(); + if(taskSignTime.length() > 0 && lastWorkTime.length() > 0){ + if(lastWorkTime.length() == 5){ + lastWorkTime = lastWorkTime+":00"; + } + String fromDateTime = signDate+" "+lastWorkTime; + String toDateTime = signEndDate+" "+taskSignTime; + int startTime = KQOvertimeRulesBiz.getStartTime(resourceId, taskDate); + startTime = startTime < 0 ? 0 : startTime; + if(isBefore){ + //涓婄彮鍓嶅氨涓嶄笉闇瑕佽冭檻涓嬬彮鍚庡涔呯畻鍔犵彮杩欎釜閫昏緫浜 + startTime = 0; + } + long mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter).plusMinutes(startTime), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + if(mins > 0){ + String workingHours = Util.null2String(workMins/60.0); + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit){ + if(taskSignTime.length() == 5){ + taskSignTime += ":00"; + } + RecordSet rs = new RecordSet(); + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + String before_checkLastSignTimesource = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + String after_checkLastSignTimesource = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_checkLastSignTimesource = Util.null2String(tmpMap.get("checkLastSignTimesource")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_checkLastSignTimesource = Util.null2String(tmpMap.get("checkLastSignTimesource")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + boolean isLateoutlatein = checkIsLateoutlatein(resourceId, taskDate); + if(!isLateoutlatein){ + String fromDate = ""; + String fromtime = ""; + String toDate = ""; + String totime = ""; + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + String checkLastSignDate = ""; + String checkLastSignTimesource = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + checkLastSignDate = before_checkLastSignDate; + checkLastSignTimesource = before_checkLastSignTimesource; + }else{ + checkLastSignTime = after_checkLastSignTime; + checkLastSignDate = after_checkLastSignDate; + checkLastSignTimesource = after_checkLastSignTimesource; + } + if(isBefore){ + fromDate = signDate; + fromtime = lastWorkTime; + if("before".equalsIgnoreCase(checkLastSignTimesource)){ + toDate = checkLastSignDate; + totime = checkLastSignTime; + }else{ + String[] toDateTimes = toDateTime.split(" "); + if(toDateTimes.length == 2){ + toDate = toDateTimes[0]; + totime = toDateTimes[1]; + } + } + mins = (long) (mins-before_hasMins); + }else{ + if(checkLastSignDate.length() > 0 && checkLastSignTime.length() > 0) { + fromDate = checkLastSignDate; + fromtime = checkLastSignTime; + }else{ + fromDate = signDate; + fromtime = lastWorkTime; + } + toDate = signEndDate; + totime = taskSignTime; + mins = (long) (mins-after_hasMins); + } + }else{ + String[] fromDateTimes = fromDateTime.split(" "); + String[] toDateTimes = toDateTime.split(" "); + if(fromDateTimes.length == 2){ + fromDate = fromDateTimes[0]; + fromtime = fromDateTimes[1]; + } + if(toDateTimes.length == 2){ + toDate = toDateTimes[0]; + totime = toDateTimes[1]; + } + } + mins = mins < 0 ? 0 : mins; + + String tiaoxiuId = ""; + if(up_tiaoxiuid.length() > 0 && Util.getIntValue(up_tiaoxiuid) > 0){ + boolean is_tiaoxiuId = KQBalanceOfLeaveBiz.updateExtraAmountByDis5(up_tiaoxiuid,Util.getDoubleValue(mins+""), ""); + tiaoxiuId = up_tiaoxiuid; + }else{ + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0","","","",taskDate,null); + } + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁鎴愬姛 doMode3ChangeType2:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins+":workingHours:"+workingHours); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁澶辫触 doMode3ChangeType2:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins+":workingHours:"+workingHours); + } + + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, "",resourceId,fromDate,fromtime,toDate,totime,mins,"",taskDate,"",unit,"2",paidLeaveEnable,"3",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType1 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + logMultiSign(resourceId,taskDate,taskSignTime,lastWorkTime,workMins,"",mins,signEndDate,timesource, + uuid, tiaoxiuId); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType2:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType2:fromDateTime:"+fromDateTime+":toDateTime:"+toDateTime+":mins:"+mins); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode3ChangeType2:taskSignTime:"+taskSignTime+":lastWorkTime:"+lastWorkTime); + } + + } + + /** + * 鏍¢獙澶氭绛鹃闂 + * @param taskSignTime 鏈鏂扮殑绛鹃鏃ユ湡鏃堕棿 + * @param fullFormatter + */ + public Map checkMultiSign(String resourceId, String taskDate,String taskSignTime, DateTimeFormatter fullFormatter,String timesource) { + RecordSet rs = new RecordSet(); + Map mutiMap = new HashMap<>(); + long mins = 0L; + boolean hasSigned = false; + //鍊掓暟绗簩鏂扮殑绛鹃鏃堕棿 + String signDate = ""; + String checkLastSignTime = ""; + String checkLastSignTimesource = ""; + Map> sourceMap = new HashMap<>(); + Map minsMap = new HashMap<>(); + Map datetimeMap = new HashMap<>(); + //宸茬粡鐢熸垚浜嗙殑鍔犵彮鏃堕暱 + long hasMins = 0L; + String checkSql = "select * from kq_overtime_signtask where resourceid=? and belongdate=? order by signdate ,signtime "; + rs.executeQuery(checkSql,resourceId,taskDate); + while(rs.next()){ + signDate = rs.getString("signdate"); + checkLastSignTime = rs.getString("signtime"); + checkLastSignTimesource = rs.getString("timesource"); + double tmp_mins = Util.getDoubleValue(rs.getString("mins"),0.0); + hasMins += tmp_mins; + if(sourceMap.containsKey(checkLastSignTimesource)){ + Map tmp_minsMap = sourceMap.get(checkLastSignTimesource); + String tmp_hasMins = tmp_minsMap.get("hasMins"); + if(checkLastSignTimesource.equalsIgnoreCase("after")){ + tmp_minsMap.put("checkLastSignDate", signDate); + tmp_minsMap.put("checkLastSignTime", checkLastSignTime); + tmp_minsMap.put("checkLastSignTimesource", checkLastSignTimesource); + }else{ + //before 涓婄彮鍓嶇殑鏃跺欙紝绗竴鏉″氨鏄渶鏃╃殑鎵撳崱鏃堕棿鎵浠ュ悗闈笉闇瑕佹洿鏂颁簡 + } + double sourceMins = Util.getDoubleValue(tmp_hasMins,0.0); + tmp_minsMap.put("hasMins", (tmp_mins+sourceMins)+""); + }else{ + minsMap = new HashMap<>(); + minsMap.put("hasMins", tmp_mins+""); + minsMap.put("checkLastSignDate", signDate+""); + minsMap.put("checkLastSignTime", checkLastSignTime+""); + minsMap.put("checkLastSignTimesource", checkLastSignTimesource+""); + sourceMap.put(checkLastSignTimesource, minsMap); + } + hasSigned = true; + } + mutiMap.put("hasSign", hasSigned ? "1":"0"); + mutiMap.put("hasMins", ""+(hasMins <=0 ? 0 : hasMins)); + mutiMap.put("sourceMap", sourceMap); + return mutiMap; + } + + /** + * 璁板綍涓嬪娆$閫鐢熸垚鍔犵彮鏁版嵁闂 + * @param resourceId + * @param taskDate + * @param taskSignTime + * @param lastWorkTime + * @param workMins + * @param signInTime4Out + * @param mins + * @param signDate + * @param timesource + * @param uuid + * @param tiaoxiuId + */ + private void logMultiSign(String resourceId, String taskDate, String taskSignTime, + String lastWorkTime, int workMins, String signInTime4Out, long mins, String signDate, + String timesource, String uuid, String tiaoxiuId) throws Exception{ + RecordSet rs = new RecordSet(); + String logSql = "insert into kq_overtime_signtask(resourceid,belongdate,signtime,lastworktime,workmins,signInTime4Out,mins,signDate,timesource,uuid,tiaoxiuId) values(?,?,?,?,?,?,?,?,?,?,?) "; + boolean isLog = false; + if("before".equalsIgnoreCase(timesource)){ + isLog = rs.executeUpdate(logSql,resourceId,taskDate,lastWorkTime,taskSignTime,workMins,signInTime4Out,mins,signDate,timesource,uuid,tiaoxiuId); + }else{ + isLog = rs.executeUpdate(logSql,resourceId,taskDate,taskSignTime,lastWorkTime,workMins,signInTime4Out,mins,signDate,timesource,uuid,tiaoxiuId); + } + + kqLog.info("璁板綍涓嬪娆$閫鐢熸垚鍔犵彮鏁版嵁闂 logMultiSign:logSql:"+logSql+":resourceId:"+resourceId+":isLog:"+isLog + +":taskDate:"+taskDate+":taskSignTime:"+taskSignTime+":lastWorkTime:"+lastWorkTime+":workMins:"+workMins+":signInTime4Out:" + +signInTime4Out+":mins:"+mins+":signDate:"+signDate+":timesource:"+timesource); + + } + + /** + * 鏃犻渶瀹℃壒锛屾牴鎹墦寮鏃堕棿璁$畻鍔犵彮鏃堕暱 + * 鑺傚亣鏃ュ鐞 + * @param taskBean + * @param fullFormatter + */ + private void doMode3ChangeType1(KQTaskBean taskBean, + DateTimeFormatter fullFormatter) throws Exception{ + String taskDate = taskBean.getTaskDate(); + String resourceId = taskBean.getResourceId(); + String taskSignTime = taskBean.getTaskSignTime(); + String signInTime4Out = taskBean.getSignInTime4Out(); + String signDate = taskBean.getSignDate(); + String signEndDate= taskBean.getSignEndDate(); + String timesource = Util.null2String(taskBean.getTimesource()); + String up_tiaoxiuid = taskBean.getTiaoxiuId(); + boolean isBefore = false; + if("before".equalsIgnoreCase(timesource)){ + isBefore = true; + } + if(taskSignTime.length() > 0 && signInTime4Out.length() > 0){ + + long mins = calNonWorkDuration(signInTime4Out,taskSignTime,taskDate,resourceId); + if(isBefore && signEndDate.compareTo(signDate) < 0){ + //鎵撳崱鏃ユ湡鍜屽綊灞炴棩鏈熶笉鏄悓涓澶╃殑璇 + String fromDateTime = signEndDate+" "+signInTime4Out; + String toDateTime = signDate+" "+taskSignTime; +// 杩橀渶瑕佷氦鎹竴涓嬪紑濮嬫棩鏈熷拰缁撴潫鏃ユ湡 + String tmpDate = signDate; + signDate = signEndDate; + signEndDate = tmpDate; + mins = Duration.between(LocalDateTime.parse(fromDateTime, fullFormatter), LocalDateTime.parse(toDateTime, fullFormatter)).toMinutes(); + } + if(mins > 0){ + int minimumUnit = KQOvertimeRulesBiz.getMinimumLen(resourceId, taskDate); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + int paidLeaveEnable = KQOvertimeRulesBiz.getPaidLeaveEnable(resourceId, taskDate); + paidLeaveEnable = paidLeaveEnable == 1?1:0; + if(mins >= minimumUnit){ + if(taskSignTime.length() == 5){ + taskSignTime += ":00"; + } + RecordSet rs = new RecordSet(); + String tmp_taskSignTime = signEndDate+" "+taskSignTime; + Map mutiMap = checkMultiSign(resourceId,taskDate,tmp_taskSignTime,fullFormatter,timesource); + String hasSign = Util.null2String(mutiMap.get("hasSign")); + Map> sourceMap = (Map>) mutiMap.get("sourceMap"); + String before_checkLastSignTime = ""; + String before_checkLastSignDate = ""; + double before_hasMins = 0.0; + + String after_checkLastSignTime = ""; + String after_checkLastSignDate = ""; + double after_hasMins = 0.0; + if(sourceMap.containsKey("before")){ + Map tmpMap = sourceMap.get("before"); + before_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + before_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + before_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + if(sourceMap.containsKey("after")){ + Map tmpMap = sourceMap.get("after"); + after_checkLastSignDate = Util.null2String(tmpMap.get("checkLastSignDate")); + after_checkLastSignTime = Util.null2String(tmpMap.get("checkLastSignTime")); + after_hasMins = Util.getDoubleValue(Util.null2String(tmpMap.get("hasMins")),0.0); + } + long hasMins = Long.parseLong(Util.null2String(mutiMap.get("hasMins"))); + + String fromtime = ""; + String totime = ""; + if("1".equalsIgnoreCase(hasSign)){ + String checkLastSignTime = ""; + if(isBefore){ + checkLastSignTime = before_checkLastSignTime; + }else{ + checkLastSignTime = after_checkLastSignTime; + } + if(checkLastSignTime.compareTo(signInTime4Out) > 0){ + fromtime = checkLastSignTime; + }else{ + fromtime = signInTime4Out; + } + totime = taskSignTime; + if(isBefore){ + mins = (long) (mins-before_hasMins); + }else{ + mins = (long) (mins-after_hasMins); + } + }else{ + fromtime = signInTime4Out; + totime = taskSignTime; + } + mins = mins < 0 ? 0 : mins; + + String tiaoxiuId = ""; + if(up_tiaoxiuid.length() > 0 && Util.getIntValue(up_tiaoxiuid) > 0){ + boolean is_tiaoxiuId = KQBalanceOfLeaveBiz.updateExtraAmountByDis5(up_tiaoxiuid,Util.getDoubleValue(mins+""), ""); + tiaoxiuId = up_tiaoxiuid; + }else{ + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceId,taskDate,mins+"","0","","","",taskDate,null); + } + + if(Util.getIntValue(tiaoxiuId) > 0){ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁鎴愬姛 doMode3ChangeType1:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + }else{ + kqLog.info("鐢熸垚鍔犵彮鏁版嵁澶辫触 doMode3ChangeType1:resourceId:"+resourceId+":taskDate:"+taskDate+":mins:"+mins); + } + String uuid = UUID.randomUUID().toString(); + String flow_overtime_sql = "insert into kq_flow_overtime (requestid,resourceid,fromdate,fromtime,todate,totime,duration_min,expiringdate,belongdate,workMins,durationrule,changetype,paidLeaveEnable,computingMode,tiaoxiuId,uuid)"+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + boolean isUp = rs.executeUpdate(flow_overtime_sql, "",resourceId,signDate,fromtime,signEndDate,totime,mins,"",taskDate,"",unit,"1",paidLeaveEnable,"3",tiaoxiuId,uuid); + if(!isUp){ + kqLog.info("doMode2ChangeType1 鍔犵彮鏁版嵁璁板綍澶辫触锛侊紒锛"); + } + + logMultiSign(resourceId,taskDate,taskSignTime,"",0,signInTime4Out,mins,signEndDate,timesource,uuid,tiaoxiuId); + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType1:瀹為檯鍔犵彮鏃堕暱mins:"+mins+":鏈灏忓姞鐝椂闀縨inimumUnit:"+minimumUnit); + } + + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁涓 doMode3ChangeType1:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + }else{ + kqLog.info("绛惧埌绛鹃 鐢熸垚鍔犵彮鏁版嵁寮傚父 doMode3ChangeType1:taskSignTime:"+taskSignTime+":signInTime4Out:"+signInTime4Out); + } + + } + + /** + * 鏍规嵁姣忎竴澶╃殑鐝鏉ユ媶鍒 + * @param splitBean + * @param splitBeans + * @return + */ + public void doSerialSplitList(SplitBean splitBean,List splitBeans) throws Exception{ + String resourceid = splitBean.getResourceId(); + String fromDate = splitBean.getFromdatedb(); + String toDate = splitBean.getTodatedb(); + DurationTypeEnum durationTypeEnum = splitBean.getDurationTypeEnum(); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate preFromDate = localFromDate.minusDays(1); + + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + boolean shouldLog = true; + if(durationTypeEnum == DurationTypeEnum.COMMON_CAL){ + shouldLog = false; + } + if(shouldLog){ + kqLog.info("resourceid::"+resourceid+"::doSerialSplitList:"+ (splitBean != null ? JSON.toJSONString(splitBean):null)); + } + long betweenDays = localToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + LocalDate curLocalDate = preFromDate.plusDays(i); + String splitDate = curLocalDate.format(dateFormatter); + ShiftInfoBean shiftInfoBean = null; + if(shouldLog){ + shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, splitDate,false); + }else{ + shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, splitDate,false,false); + } + if(shouldLog){ + kqLog.info("resourceid::"+resourceid+"::splitDate:"+splitDate+":shiftInfoBean:"+ (shiftInfoBean != null ? JSON.toJSONString(shiftInfoBean):null)); + } + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + boolean isSplit = true; + if(shiftInfoBean != null){ + splitBean.setSerialid(Util.null2String(shiftInfoBean.getSerialid())); + if(!shiftInfoBean.isIsfree()){ + isSplit = commonShiftSplit(shiftInfoBean,splitBean,i,kqTimesArrayComInfo,initArrays,localFromDate,localToDate,betweenDays,shouldLog); + if(!isSplit){ + continue; + } + }else{ + isSplit = freeShiftSplit(shiftInfoBean,splitBean,i,kqTimesArrayComInfo,initArrays,localFromDate,localToDate,betweenDays); + if(!isSplit){ + continue; + } + } + //鏍规嵁鍗曚綅杞崲鏃堕暱 + turnDuration(splitBean,false); + }else{ + //闈炲伐浣滄椂闀 + String computingMode = splitBean.getComputingMode(); + if("2".equalsIgnoreCase(computingMode)){ + String filterholidays = splitBean.getFilterholidays(); + boolean is_filterholidays = check_filterholidays(filterholidays,resourceid,splitDate,i); + if(is_filterholidays){ + continue; + } + ShiftInfoBean preShiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, curLocalDate.minusDays(1).format(dateFormatter),false); + isSplit = nonWorkDaySplit(preShiftInfoBean,splitBean,i,kqTimesArrayComInfo,initArrays,localFromDate,localToDate,betweenDays); + if(!isSplit){ + continue; + } + //鏍规嵁鍗曚綅杞崲鏃堕暱 + turnDuration(splitBean,true); + }else{ + if(shouldLog){ + kqLog.info("resourceid::"+resourceid+"::doSerialSplitList splitDate:"+splitDate+":resourceid:"+resourceid+"鏄潪宸ヤ綔鏃"); + } + continue; + } + } + + SplitBean newsplitBean = new SplitBean(); + //鐒跺悗鎶奲ean閲嶆柊璧嬪间笅锛屾牴鎹媶鍒嗗悗鐨勬椂闂 + BeanUtils.copyProperties(splitBean, newsplitBean); + newsplitBean.setFromDate(splitDate); + newsplitBean.setToDate(splitDate); + newsplitBean.setBelongDate(splitDate); + splitBeans.add(newsplitBean); + } + } + + /** + * 鐩戞祴鎸夌収鑷劧鏃ヨ绠楋紝鏍规嵁鎺掗櫎浼戞伅鏃ュ拰鑺傚亣鏃ョ殑璁剧疆锛屽垽鏂綋鍓嶈嚜鐒舵棩鏄惁闇瑕佹帓闄よ绠 + * @param filterholidays + * @param resourceid + * @param splitDate + * @param i + */ + public boolean check_filterholidays(String filterholidays, String resourceid, String splitDate, + int i) { + boolean is_filterholidays = false; + if (i == 0) { + return is_filterholidays; + } + if(Util.null2String(filterholidays).length() > 0){ + List filterholidayList = Arrays.asList(filterholidays.split(",")); + if(filterholidayList != null && !filterholidayList.isEmpty()){ + //鏃ユ湡绫诲瀷锛1-鑺傚亣鏃ャ2-宸ヤ綔鏃ャ3-浼戞伅鏃(鑺傚亣鏃ヨ缃殑浼樺厛绾ч珮浜庤冨嫟缁勪腑鐨勮缃) + int changeType = KQOvertimeRulesBiz.getChangeType(resourceid,splitDate); + if(filterholidayList.contains("1")){ + //鎺掗櫎鑺傚亣鏃 + if(filterholidayList.contains("2")){ + //鎺掗櫎浼戞伅鏃 + if(changeType == 3 || changeType == 1){ + is_filterholidays = true; + } + }else { + if(changeType == 1){ + is_filterholidays = true; + } + } + }else if(filterholidayList.contains("2")){ + //鎺掗櫎浼戞伅鏃 + if(changeType == 3){ + is_filterholidays = true; + } + }else{ + //涓嶆帓闄や紤鎭棩锛屼篃涓嶆帓闄よ妭鍋囨棩 + } + } + } + return is_filterholidays; + } + + /** + * 鑷敱宸ユ椂鐨勬祦绋嬫暟鎹媶鍒 + * @param shiftInfoBean + * @param splitBean + * @param i + * @param kqTimesArrayComInfo + * @param initArrays + * @param localFromDate + * @param localToDate + * @param betweenDays + * @return + */ + public boolean freeShiftSplit(ShiftInfoBean shiftInfoBean, SplitBean splitBean, int i, KQTimesArrayComInfo kqTimesArrayComInfo, int[] initArrays, LocalDate localFromDate, LocalDate localToDate, + long betweenDays) { + + String fromTime = splitBean.getFromtimedb(); + String toTime = splitBean.getTotimedb(); + int fromtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); + int totimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(toTime); + int flowbegintimeIndex = -1; + int flowendtimeIndex = -1; + + boolean isSplit = true; + String freeSignStart = shiftInfoBean.getFreeSignStart(); + String freeSignEnd = shiftInfoBean.getFreeSignEnd(); + if(freeSignStart.length() == 0){ + shiftInfoBean.setD_Mins(0.0); + isSplit = false; + return isSplit; + } + int freeSignStartIndex = kqTimesArrayComInfo.getArrayindexByTimes(freeSignStart); + int freeSignEndIndex = kqTimesArrayComInfo.getArrayindexByTimes(freeSignEnd); + int freeWorkMins = Util.getIntValue(shiftInfoBean.getFreeWorkMins()); + if (i == 0) { + isSplit = false; + return isSplit; + }else{ + if(localFromDate.isEqual(localToDate)){ + if(fromtimeIndex > freeSignStartIndex){ + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = totimeIndex; + }else{ + flowbegintimeIndex = freeSignStartIndex; + flowendtimeIndex = totimeIndex; + } + }else{ + if (i == 1) { + if(fromtimeIndex > freeSignStartIndex){ + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = 1440; + }else{ + flowbegintimeIndex = freeSignStartIndex; + flowendtimeIndex = 1440; + } + } else if (i == betweenDays) { + if(totimeIndex > freeSignStartIndex){ + flowbegintimeIndex = freeSignStartIndex; + flowendtimeIndex = totimeIndex; + }else{ + isSplit = false; + return isSplit; + } + } else { + flowbegintimeIndex = freeSignStartIndex; + flowendtimeIndex = freeSignEndIndex; + } + } + } + kqLog.info("resourceid::"+splitBean.getResourceId()+"::鑷敱鐝埗 isSplit涔嬪墠 i::"+i+"::flowbegintimeIndex:"+flowbegintimeIndex+":flowendtimeIndex:"+ flowendtimeIndex); + + if(isSplit){ + String splitFromTime = kqTimesArrayComInfo.getTimesByArrayindex(flowbegintimeIndex); + String splitToTime = kqTimesArrayComInfo.getTimesByArrayindex(flowendtimeIndex); + int flowMins = flowendtimeIndex - flowbegintimeIndex; + flowMins = flowMins > freeWorkMins ? freeWorkMins : flowMins; + flowMins = flowMins > 0 ? flowMins : 0; + if(flowMins < 0){ + kqLog.info("resourceid::"+splitBean.getResourceId()+"::鑷敱鐝埗 涓嶈褰曚腑闂磋〃 i::"+i+"::flowbegintimeIndex:"+flowbegintimeIndex+":flowendtimeIndex:"+ flowendtimeIndex+":flowMins:"+ flowMins); + return false; + } + splitBean.setD_Mins(flowMins); + splitBean.setWorkmins(freeWorkMins); + splitBean.setOneDayHour((freeWorkMins/60.0)); + splitBean.setFromTime(splitFromTime); + splitBean.setToTime(splitToTime); + } + return isSplit; + } + + /** + * 闈炲伐浣滄椂闀匡紙鑷劧鏃ヨ绠楃殑锛 + * @param preShiftInfoBean + * @param splitBean + * @param i + * @param kqTimesArrayComInfo + * @param initArrays + * @param localFromDate + * @param localToDate + * @param betweenDays + * @return + */ + public boolean nonWorkDaySplit(ShiftInfoBean preShiftInfoBean, SplitBean splitBean, int i, + KQTimesArrayComInfo kqTimesArrayComInfo, int[] initArrays, LocalDate localFromDate, + LocalDate localToDate, long betweenDays) { + + boolean isSplit = true; + if(preShiftInfoBean != null){ + String isAcross = preShiftInfoBean.getIsAcross(); + if("1".equalsIgnoreCase(isAcross)){ + List workAcrossIndex = preShiftInfoBean.getWorkAcrossIndex(); + if(workAcrossIndex !=null && !workAcrossIndex.isEmpty()){ + int[] workIndexs = workAcrossIndex.get(workAcrossIndex.size()-1); + return nonWorkDayCommonSplit(splitBean, i, kqTimesArrayComInfo, localFromDate, localToDate, betweenDays,workIndexs[1]); + } + }else{ + return nonWorkDayCommonSplit(splitBean, i, kqTimesArrayComInfo, localFromDate, localToDate, betweenDays,-1); + } + }else{ + return nonWorkDayCommonSplit(splitBean, i, kqTimesArrayComInfo, localFromDate, localToDate, betweenDays,-1); + } + + return isSplit; + } + + /** + * 闈炲伐浣滄椂闀匡紙鑷劧鏃ヨ绠楃殑锛 + * @param splitBean + * @param i + * @param kqTimesArrayComInfo + * @param localFromDate + * @param localToDate + * @param betweenDays + * @param preLastWorkIndex 濡傛灉鍓嶄竴澶╄法澶╋紝鍓嶄竴澶╂渶鏅氱殑涓嬬彮鏃堕棿 + * @return + */ + public boolean nonWorkDayCommonSplit(SplitBean splitBean, int i, + KQTimesArrayComInfo kqTimesArrayComInfo, LocalDate localFromDate, + LocalDate localToDate, long betweenDays,int preLastWorkIndex) { + boolean isSplit = true; + + String fromTime = splitBean.getFromtimedb(); + String toTime = splitBean.getTotimedb(); + int fromtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); + int totimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(toTime); + int flowbegintimeIndex = -1; + int flowendtimeIndex = -1; + + if (i == 0) { + isSplit = false; + return isSplit; + }else{ + if(localFromDate.isEqual(localToDate)){ + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = totimeIndex; + }else{ + if(i == 1){ + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = 1440; + }else if(i == betweenDays){ + flowbegintimeIndex = 0; + flowendtimeIndex = totimeIndex; + }else{ + flowbegintimeIndex = 0; + flowendtimeIndex = 1440; + } + } + } + if(isSplit){ + String splitFromTime = kqTimesArrayComInfo.getTimesByArrayindex(flowbegintimeIndex); + if(preLastWorkIndex > 0){ + if(preLastWorkIndex > flowbegintimeIndex){ + flowbegintimeIndex = preLastWorkIndex; + } + } + if("2".equalsIgnoreCase(splitBean.getDurationrule())) { + if ("2".equalsIgnoreCase(splitBean.getTimeselection())) { + return WorkHalfUnitSplitChain.getSplitDurationBean4NonTime(kqTimesArrayComInfo,splitBean,flowbegintimeIndex,flowendtimeIndex); + } + }else{ + String splitToTime = kqTimesArrayComInfo.getTimesByArrayindex(flowendtimeIndex); + int flowMins = flowendtimeIndex - flowbegintimeIndex; + flowMins = flowMins > 0 ? flowMins : 0; + splitBean.setD_Mins(flowMins); + splitBean.setFromTime(splitFromTime); + splitBean.setToTime(splitToTime); + } + } + return isSplit; + } + + /** + * 鍥哄畾鐝埗鍜屾帓鐝埗鐨勬暟鎹媶鍒 + * @param shiftInfoBean + * @param splitBean + * @param i + * @param kqTimesArrayComInfo + * @param initArrays + * @param localFromDate + * @param localToDate + * @param betweenDays + * @param shouldLog + * @return + */ + public boolean commonShiftSplit(ShiftInfoBean shiftInfoBean, SplitBean splitBean, int i, + KQTimesArrayComInfo kqTimesArrayComInfo, int[] initArrays, LocalDate localFromDate, + LocalDate localToDate, long betweenDays, boolean shouldLog) { + + boolean isSplit = true; + + String fromTime = splitBean.getFromtimedb(); + String toTime = splitBean.getTotimedb(); + int fromtimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromTime); + int totimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(toTime); + int flowbegintimeIndex = -1; + int flowendtimeIndex = -1; + + String isAcross = shiftInfoBean.getIsAcross(); + List real_allLongWorkTime = Lists.newArrayList(); + List allLongWorkTime = shiftInfoBean.getAllLongWorkTime(); + CollectionUtils.addAll(real_allLongWorkTime,new Object[allLongWorkTime.size()]); + Collections.copy(real_allLongWorkTime, allLongWorkTime); + + List real_workLongTimeIndex = Lists.newArrayList(); + List workLongTimeIndex = shiftInfoBean.getWorkLongTimeIndex(); + + //list甯︽暟缁勶紝杩欓噷瑕佹繁鎷疯礉 + for(int[] tmp : workLongTimeIndex){ + int[] real_tmp = new int[tmp.length]; + System.arraycopy(tmp, 0, real_tmp, 0, tmp.length); + real_workLongTimeIndex.add(real_tmp); + } + List restLongTimeIndex = shiftInfoBean.getRestLongTimeIndex(); + if(real_allLongWorkTime == null || real_allLongWorkTime.isEmpty()){ + isSplit = false; + return isSplit; + } + + if(real_workLongTimeIndex.size() == 1){ + KQShiftRuleInfoBiz kqShiftRuleInfoBiz = new KQShiftRuleInfoBiz(); + kqShiftRuleInfoBiz.rest_workLongTimeIndex(shiftInfoBean,splitBean,real_workLongTimeIndex,kqTimesArrayComInfo,real_allLongWorkTime); + } + + //濡傛灉涓嶈法澶 + if(!isAcross.equalsIgnoreCase("1")){ + //濡傛灉鏄鍋囧紑濮嬫棩鏈熺殑鍓嶄竴澶 + if (i == 0) { + isSplit = false; + return isSplit; + }else{ + int firstTime = kqTimesArrayComInfo.getArrayindexByTimes(real_allLongWorkTime.get(0)); + int lastTime = kqTimesArrayComInfo.getArrayindexByTimes(real_allLongWorkTime.get(real_allLongWorkTime.size()-1)); + + if(localFromDate.isEqual(localToDate)){ + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = totimeIndex; + }else{ + if (i == 1) { + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = lastTime; + } else if (i == betweenDays) { + flowbegintimeIndex = firstTime; + flowendtimeIndex = totimeIndex; + } else { + flowbegintimeIndex = firstTime; + flowendtimeIndex = lastTime; + } + } + //宸ヤ綔鏃舵閲屽~鍏呬笂1 + for(int j=0 ;real_workLongTimeIndex != null && j totimeIndex){ + isSplit = false; + return isSplit; + } + } else { + flowbegintimeIndex = firstTime; + flowendtimeIndex = lastTime; + if(firstTime > lastTime){ + isSplit = false; + return isSplit; + } + } + } + } + //宸ヤ綔鏃舵閲屽~鍏呬笂1 + for(int j=0 ;j 0 ? flowMins : 0; + if(flowMins < 0){ + if(shouldLog){ + kqLog.info("resourceid:"+splitBean.getResourceId()+":::涓嶈褰曚腑闂磋〃 i::"+i+"::flowbegintimeIndex:"+flowbegintimeIndex+":flowendtimeIndex:"+ flowendtimeIndex+":flowMins:"+ flowMins); + } + return false; + } + splitBean.setD_Mins(flowMins); + splitBean.setWorkmins(shiftInfoBean.getWorkmins()); + splitBean.setFromTime(splitFromTime); + splitBean.setToTime(splitToTime); + } + + } + return isSplit; + } + + /** + * 鏍规嵁鍗曚綅鏉ヨ浆鎹㈡椂闀 + * @param splitBean + * @param isComputingMode2 鏄惁鎸夌収鑷劧鏃ヨ绠 + */ + private void turnDuration(SplitBean splitBean,boolean isComputingMode2) { + String durationrule = splitBean.getDurationrule(); + + //璁$畻瑙勫垯 1-鎸夊ぉ璇峰亣 2-鎸夊崐澶╄鍋 3-鎸夊皬鏃惰鍋 4-鎸夋暣澶╄鍋 5鍗婂皬鏃 6鏁村皬鏃 + //鎸夌収澶╁拰灏忔椂鐨勫彲浠ュ湪杩欓噷璁$畻锛屽崐澶╃殑鍜屾暣澶╃殑鍗曠嫭澶勭悊 + if("1".equalsIgnoreCase(durationrule)){ + durationrule1(splitBean,isComputingMode2); + }else if("3".equalsIgnoreCase(durationrule)){ + durationrule3(splitBean,isComputingMode2); + }else if("5".equalsIgnoreCase(durationrule)){ + String conversion= splitBean.getConversion(); + if(conversion.length() > 0 && Util.getIntValue(conversion) > 0){ + double conversionMins = 0.0; + int halfHourInt = 30; + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + conversionMins = kqOverTimeRuleCalBiz.getConversionMins(halfHourInt,splitBean.getD_Mins(),Util.getIntValue(conversion)); + splitBean.setD_Mins(conversionMins); + } + durationrule3(splitBean,isComputingMode2); + }else if("6".equalsIgnoreCase(durationrule)){ + String conversion= splitBean.getConversion(); + if(conversion.length() > 0 && Util.getIntValue(conversion) > 0){ + double conversionMins = 0.0; + int wholeHourInt = 60; + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + conversionMins = kqOverTimeRuleCalBiz.getConversionMins(wholeHourInt,splitBean.getD_Mins(),Util.getIntValue(conversion)); + splitBean.setD_Mins(conversionMins); + } + durationrule3(splitBean,isComputingMode2); + } + + } + + /** + * 鎸夊ぉ璇峰亣 + * @param splitBean + * @param isComputingMode2 鏄惁鎸夌収鑷劧鏃ヨ绠 + * @return + */ + private void durationrule1(SplitBean splitBean,boolean isComputingMode2) { + String computingMode = splitBean.getComputingMode(); + double d_Mins = splitBean.getD_Mins(); + double curDays = 0.0; + if(isComputingMode2){ + double oneDayHour = splitBean.getOneDayHour(); + if(oneDayHour > 0){ + double oneDayMins = oneDayHour * 60.0; + splitBean.setWorkmins(((int)oneDayMins)); + if(d_Mins > oneDayMins){ + d_Mins = oneDayMins; + splitBean.setD_Mins(d_Mins); + } + curDays = (d_Mins)/(oneDayMins); + curDays = curDays > 0 ? curDays : 0.0; + } + }else{ + int workmins = splitBean.getWorkmins(); + if(workmins > 0){ + curDays = d_Mins/(workmins*1.0); + curDays = curDays > 0 ? curDays : 0.0; + } + } + + splitBean.setDuration(KQDurationCalculatorUtil.getDurationRound5(""+(curDays))); + } + + /** + * 鎸夊皬鏃惰鍋 + * @param splitBean + * @param isComputingMode2 + * @return + */ + private double durationrule3(SplitBean splitBean, boolean isComputingMode2) { + double D_Mins = splitBean.getD_Mins(); + double hours = 0.0; + if(isComputingMode2){ + double oneDayHour = splitBean.getOneDayHour(); + if(oneDayHour > 0) { + double oneDayMins = oneDayHour * 60.0; + splitBean.setWorkmins(((int)oneDayMins)); + if(D_Mins > oneDayMins){ + D_Mins = oneDayMins; + splitBean.setD_Mins(D_Mins); + } + } + } + hours = D_Mins/60.0; + hours = hours > 0 ? hours : 0.0; + splitBean.setDuration(KQDurationCalculatorUtil.getDurationRound(""+(hours))); + return hours; + } + + + /** + * 鏍规嵁浼犲叆鐨勬棩鏈熷拰鏃堕棿鎷嗗垎鎴愭瘡涓澶╀竴鏉$殑闆嗗悎 + * @param fromDate + * @param toDate + * @param fromTime + * @param toTime + * @return + */ + public static List> getSplitList(String fromDate,String toDate,String fromTime,String toTime){ + List> splitLists = new ArrayList<>(); + Map splitMap = new HashMap<>(); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + //杩涘叆鍒拌繖閲岃〃绀烘槸澶氬ぉ + if (localFromDate.isBefore(localToDate)) { + long betweenDays = localToDate.toEpochDay() - localFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + splitMap = new HashMap<>(); + LocalDate curLocalDate = localFromDate.plusDays(i); + + splitMap.put("splitDate", curLocalDate.format(dateFormatter)); + if (i == 0) { + splitMap.put("fromTime", fromTime); + splitMap.put("toTime", "23:59"); + } else if (i == betweenDays) { + splitMap.put("fromTime", "00:00"); + splitMap.put("toTime", toTime); + } else { + splitMap.put("fromTime", "00:00"); + splitMap.put("toTime", "23:59"); + } + splitLists.add(splitMap); + } + } else if (localFromDate.isEqual(localToDate)) { + //鍚屼竴澶 + splitMap.put("splitDate", localFromDate.format(dateFormatter)); + splitMap.put("fromTime", fromTime); + splitMap.put("toTime", toTime); + splitLists.add(splitMap); + } + return splitLists; + } + + /** + * 鏍规嵁浼犲叆鐨勬棩鏈熷拰鏃堕棿鎷嗗垎鎴愬崐澶╄鍒欑殑闆嗗悎 + * @param fromDate + * @param toDate + * @param fromTime + * @param toTime + * @return + */ + public static List> getSplitHalfDayList(String fromDate,String toDate,String fromTime,String toTime){ + List> splitLists = new ArrayList<>(); + Map splitMap = new HashMap<>(); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + //杩涘叆鍒拌繖閲岃〃绀烘槸澶氬ぉ + if (localFromDate.isBefore(localToDate)) { + long betweenDays = localToDate.toEpochDay() - localFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + splitMap = new HashMap<>(); + LocalDate curLocalDate = localFromDate.plusDays(i); + splitMap.put("splitDate", curLocalDate.format(dateFormatter)); + if (i == 0) { + int foreOrAfter = SplitSelectSet.foreOrAfter(fromTime, SplitSelectSet.afternoon_end); + splitMap.put("foreOrAfter", ""+foreOrAfter); + } else if (i == betweenDays) { + int foreOrAfter = SplitSelectSet.foreOrAfter(SplitSelectSet.forenoon_start, toTime); + splitMap.put("foreOrAfter", ""+foreOrAfter); + } else { + splitMap.put("foreOrAfter", ""+ SplitSelectSet.fore_after_index); + } + splitLists.add(splitMap); + } + } else if (localFromDate.isEqual(localToDate)) { + //鍚屼竴澶 + splitMap.put("splitDate", localFromDate.format(dateFormatter)); + int foreOrAfter = SplitSelectSet.foreOrAfter(fromTime, toTime); + splitMap.put("foreOrAfter", ""+foreOrAfter); + splitLists.add(splitMap); + } + return splitLists; + } + + /** + * 鏍规嵁浼犲叆鐨勬棩鏈熷垎鎴愰泦鍚 + * @param fromDate + * @param toDate + * @return + */ + public static List> getSplitDayList(String fromDate,String toDate){ + List> splitLists = new ArrayList<>(); + Map splitMap = new HashMap<>(); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + long betweenDays = localToDate.toEpochDay() - localFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + splitMap = new HashMap<>(); + LocalDate curLocalDate = localFromDate.plusDays(i); + splitMap.put("splitDate", curLocalDate.format(dateFormatter)); + splitLists.add(splitMap); + } + return splitLists; + } + + /** + * 瀵逛簬宸ヤ綔鏃ュ姞鐝垽鏂槸鍚︽槸寮鍚簡鏅氳蛋鏅氬埌鐨勮鍒欙紝寮鍚簡鐨勮瘽锛屼笉璇曞仛鍔犵彮 + * @return + */ + public boolean checkIsLateoutlatein(String resourceId ,String taskDate){ + boolean isLateoutlatein = false; + KQWorkTime kqWorkTime = new KQWorkTime(); + Map serialInfo = kqWorkTime.getSerialInfo(resourceId, taskDate, false); + if(serialInfo!=null&&serialInfo.size()>0){ + String serialid = Util.null2String(serialInfo.get(taskDate)); + if(serialid.length() > 0){ + KQShiftPersonalizedRuleCominfo ruleCominfo = new KQShiftPersonalizedRuleCominfo(); + KQShiftPersonalizedRuleDetailComInfo ruleDetailComInfo = new KQShiftPersonalizedRuleDetailComInfo(); + String personalizedruleid = ruleCominfo.getID(serialid); + Map ruleDetailMap = ruleDetailComInfo.getPersonalizedRuleDetail(personalizedruleid); + if(ruleDetailMap != null && !ruleDetailMap.isEmpty()){ + List workSectionList = (List) ruleDetailMap.get("lateoutlatein"); + if(workSectionList != null && !workSectionList.isEmpty()){ +// workSectionList閲屽瓨鐨別nable閮芥槸涓鑷寸殑锛屽彇涓涓氨琛 + Map sectionMap = (Map) workSectionList.get(0); + if(sectionMap != null && !sectionMap.isEmpty()){ + String enable = Util.null2String(sectionMap.get("enable")); + if("1".equalsIgnoreCase(enable)){ + isLateoutlatein = true; + kqLog.info("resourceid:"+resourceId+":taskDate:"+taskDate+":::寮鍚簡鏅氳蛋鏅氬埌瑙勫垯锛屼笉璁$畻鍔犵彮 checkIsLateoutlatein:resourceId:"+resourceId+":taskDate:"+taskDate+":serialid:"+serialid); + return isLateoutlatein; + } + } + } + } + } + } + + return isLateoutlatein; + } + + /** + * 鎺ㄩ 琛ユ墦鍗★紝澶栧嫟锛岃冨嫟鍚屾鏁版嵁锛岃Е鍙戝姞鐝鍒欑敓鎴愬姞鐝暟鎹鐞 + * @param fromDate + * @param toDate + * @param resourceids 鏀寔澶氫釜浜虹殑 + */ + public static void pushOverTimeTasksAll(String fromDate,String toDate,String resourceids){ + + kqLog.info("pushOverTimeTasksAll 鍙傛暟涓:resourceids:"+resourceids+":fromDate:"+fromDate+":toDate:"+toDate); + if(resourceids.length() == 0 || fromDate.length() == 0 || toDate.length() == 0){ + return ; + } + List tasks = new ArrayList<>(); + String[] resourceid_arr = resourceids.split(","); + for(int i = 0 ; i < resourceid_arr.length ; i++){ + pushOverTimeTasks(fromDate, toDate, resourceid_arr[i],tasks); + } + if(!tasks.isEmpty()){ + KQQueue.writeTasks(tasks); + } + + } + + /** + * 鎺ㄩ 琛ユ墦鍗★紝澶栧嫟锛岃冨嫟鍚屾鏁版嵁锛岃Е鍙戝姞鐝鍒欑敓鎴愬姞鐝暟鎹鐞 + * @param fromDate + * @param toDate + * @param resourceid + * @param tasks + */ + public static void pushOverTimeTasks(String fromDate,String toDate,String resourceid,List tasks){ + + try { + if(true){ + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setOvertime_fromdate(fromDate); + kqTaskBean.setOvertime_todate(toDate); + tasks.add(kqTaskBean); + }else{ + pushOverTimeTasks_old(fromDate,toDate,resourceid,tasks); + } + } catch (Exception e) { + baseBean.writeLog(e); + } + } + + public static void pushOverTimeTasks_old(String fromDate, String toDate, String resourceid, List tasks) { + +// kqLog.info("鎵归噺鍔犵彮鎺ㄩ pushOverTimeTasks:fromDate:"+fromDate+"::toDate:"+toDate+"::resourceid:"+resourceid); + + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + long betweenDays = localToDate.toEpochDay() - localFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + LocalDate curLocalDate = localFromDate.plusDays(i); + LocalDate preCurLocalDate = curLocalDate.minusDays(1); + LocalDate nextCurLocalDate = curLocalDate.plusDays(1); + String splitDate = curLocalDate.format(dateFormatter); + String pre_splitDate = preCurLocalDate.format(dateFormatter); + String next_splitDate = nextCurLocalDate.format(dateFormatter); + Map pre_todayLineMap = KQDurationCalculatorUtil.getWorkButton(resourceid, pre_splitDate,false); + Map todayLineMap = KQDurationCalculatorUtil.getWorkButton(resourceid, splitDate,false); + //鍥犱负鐜板湪鏄笂鐝墠閮藉綊灞炲墠涓澶╋紝鎵浠ヨ繖閲屽瓨涓涓嬩笂鐝墠鐨勫紑濮嬫椂闂 + Map workTimeStartMap = new HashMap<>(); + //濡傛灉鏄ㄥぉ鏄伐浣滄棩锛屾槰澶╃殑涓婄彮鏃堕棿浣滀负浠婂ぉ鐨勫厑璁稿姞鐝紑濮嬫椂闂达紙鍥犱负涓嬬彮鍚庡姞鐝兘灞炰簬鍓嶄竴澶╃殑锛 + String pre_workTime = ""; + if(pre_todayLineMap.get("signTime") != null){ + pre_workTime = getEndWorktime(pre_todayLineMap,splitDate,workTimeStartMap,resourceid,pre_splitDate); + }else{ + workTimeStartMap.put("pre_isrest", "1"); + } + //濡傛灉浠婂ぉ鏄潪宸ヤ綔鏃ワ紝鏄庡ぉ鏄伐浣滄棩锛屾槑澶╃殑涓婄彮鏃堕棿浣滀负浠婂ぉ鐨勫厑璁稿姞鐝粨鏉熸椂闂 + String next_workTime = ""; + Map next_todayLineMap = KQDurationCalculatorUtil.getWorkButton(resourceid, next_splitDate,false); + + if(next_todayLineMap.get("signTime") != null){ + next_workTime = getStartWorktime(next_todayLineMap,splitDate,workTimeStartMap); + }else{ + workTimeStartMap.put("next_isrest", "1"); + } + boolean isTodayWorkDay = todayLineMap.get("signTime") != null; + + kqLog.info("pushOverTimeTasks splitDate:"+splitDate+":isTodayWorkDay:"+isTodayWorkDay+":pre_workTime:"+pre_workTime+":next_workTime:"+next_workTime); + //濡傛灉褰撳墠鏃ユ湡鏄伐浣滄棩 + if(isTodayWorkDay){ + List> todaySignTime = (List>)todayLineMap.get("signTime"); + if(todaySignTime != null && !todaySignTime.isEmpty()){ + overTime4Work(splitDate, pre_splitDate, resourceid, tasks, todayLineMap, todaySignTime,workTimeStartMap); + }else{ + overTime4NonWork(splitDate, pre_workTime, resourceid, tasks,next_workTime,workTimeStartMap,pre_splitDate); + } + }else{ + overTime4NonWork(splitDate, pre_workTime, resourceid, tasks,next_workTime,workTimeStartMap,pre_splitDate); + } + } +// kqLog.info("鎵归噺鍔犵彮鎺ㄩ 鏁版嵁涓:"+(JSON.toJSONString(tasks))); + + } + + /** + * 鑾峰彇鏈鏅氬厑璁镐笅鐝椂闂 + * @param pre_todayLineMap + * @param splitDate + * @param workTimeStartMap + * @param resourceid + * @param pre_splitDate + * @return + */ + private static String getEndWorktime(Map pre_todayLineMap, String splitDate, + Map workTimeStartMap, String resourceid, String pre_splitDate) { + String pre_workTime = ""; + List> pre_todaySignTime = (List>)pre_todayLineMap.get("signTime"); + if(pre_todaySignTime != null && !pre_todaySignTime.isEmpty()){ + Map pre_todaySignMap = pre_todaySignTime.get(pre_todaySignTime.size()-1); + String endtime = pre_todaySignMap.get("endtime"); + String endtime_across = pre_todaySignMap.get("endtime_across"); + if("1".equalsIgnoreCase(endtime_across)){ + pre_workTime = splitDate+" "+endtime+":59"; + } + Map first_SignMap = pre_todaySignTime.get(0); + String workbengintime = first_SignMap.get("workbengintime"); + workTimeStartMap.put("pre_workbengintime", workbengintime); + if(pre_todaySignTime.size() == 1){ + boolean is_flow_humanized = KQSettingsBiz.is_flow_humanized(); + if(is_flow_humanized){ + ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(resourceid, pre_splitDate,false); + Map shifRuleMap = Maps.newHashMap(); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean, resourceid, shifRuleMap); + if(!shifRuleMap.isEmpty()){ + if(shifRuleMap.containsKey("shift_beginworktime")){ + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + if(shift_beginworktime.length() > 0){ + workTimeStartMap.put("pre_workbengintime", shift_beginworktime); + } + } + if(shifRuleMap.containsKey("shift_endworktime")){ + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if(shift_endworktime.length() > 0){ + pre_workTime = shift_endworktime; + } + } + } + } + } + }else{ + workTimeStartMap.put("pre_isrest", "1"); + } + return pre_workTime; + } + + /** + * 鑾峰彇鏈鏃╁厑璁镐笂鐝椂闂 + * @param next_todayLineMap + * @param splitDate + * @return + */ + private static String getStartWorktime(Map next_todayLineMap,String splitDate, + Map workTimeStartMap) { + String next_workTime = ""; + List> next_todaySignTime = (List>)next_todayLineMap.get("signTime"); + if(next_todaySignTime != null && !next_todaySignTime.isEmpty()){ + Map next_todaySignMap = next_todaySignTime.get(0); + String bengintime = next_todaySignMap.get("bengintime"); + String workbengintime = next_todaySignMap.get("workbengintime"); + String bengintime_pre_across = next_todaySignMap.get("bengintime_pre_across"); + if("1".equalsIgnoreCase(bengintime_pre_across)){ + next_workTime = splitDate+" "+bengintime+":00"; + } + workTimeStartMap.put("next_workbengintime", workbengintime); + }else{ + workTimeStartMap.put("next_isrest", "1"); + } + return next_workTime; + } + + public static void overTime4Work(String splitDate, String pre_splitDate, String resourceid, + List tasks, Map todayLineMap, + List> todaySignTime, + Map workTimeStartMap) { + + //鐜板湪鏍囧噯鏄粯璁ゅ彇鏈鍚庝竴涓彮娆′綔涓哄姞鐝 + Map todaySignMap = Maps.newHashMap(); + if(todaySignTime.size() == 1){ + todaySignMap = todaySignTime.get(0); + overTime4WorkSign(todaySignMap,splitDate, pre_splitDate, resourceid, tasks, todayLineMap, workTimeStartMap,""); + }else if(todaySignTime.size() > 1){ + for(int i = 0 ; i < 2 ; i++) { + if (i == 0) { + todaySignMap = todaySignTime.get(0); + overTime4WorkSign(todaySignMap,splitDate, pre_splitDate, resourceid, tasks, todayLineMap, workTimeStartMap,"before"); + } else if (i == 1) { + todaySignMap = todaySignTime.get(todaySignTime.size() - 1); + overTime4WorkSign(todaySignMap,splitDate, pre_splitDate, resourceid, tasks, todayLineMap, workTimeStartMap,"after"); + } + } + } + } + + public static void overTime4WorkSign( + Map todaySignMap, String splitDate, String pre_splitDate, + String resourceid, List tasks, + Map todayLineMap, + Map workTimeStartMap, String signsource) { + RecordSet rs = new RecordSet(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter datetimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + + List allWorkTime = (List) todayLineMap.get("allWorkTime"); + String firstWorkTime = ""; + String lastWorkTime = ""; + if(allWorkTime != null && !allWorkTime.isEmpty()){ + firstWorkTime = allWorkTime.get(0); + lastWorkTime = allWorkTime.get(allWorkTime.size()-1); + } + String yesterday = LocalDate.parse(splitDate).minusDays(1).format(dateFormatter); + String nextday = LocalDate.parse(splitDate).plusDays(1).format(dateFormatter); + + String workbengintime = Util.null2s(todaySignMap.get("workbengintime"),""); + String bengintime = Util.null2s(todaySignMap.get("bengintime"),""); + //涓婄彮寮濮嬫椂闂存槸鍚﹁法澶╁埌鍚庝竴澶 + String bengintime_across = Util.null2s(todaySignMap.get("bengintime_across"),""); + //涓婄彮鎵撳崱寮濮嬫椂闂存槸鍚﹁法澶╁埌鍓嶄竴澶 + String bengintime_pre_across = Util.null2s(todaySignMap.get("bengintime_pre_across"),""); + String bengintime_end = Util.null2s(todaySignMap.get("bengintime_end"),""); + String bengintime_end_across = Util.null2s(todaySignMap.get("bengintime_end_across"),""); + + String endtime = Util.null2s(todaySignMap.get("endtime"),""); + String endtime_across = Util.null2s(todaySignMap.get("endtime_across"),""); + String endtime_start = Util.null2s(todaySignMap.get("endtime_start"),""); + String endtime_start_across = Util.null2s(todaySignMap.get("endtime_start_across"),""); + + String workendtime_across = Util.null2s(todaySignMap.get("workendtime_across"),""); + boolean isEndTimeAcross = false; + if("1".equalsIgnoreCase(workendtime_across)) { + isEndTimeAcross = true; + } + + String signInDateTime = splitDate + " " +bengintime+":00"; + if("1".equalsIgnoreCase(bengintime_pre_across)) { + signInDateTime = yesterday + " " +bengintime+":00"; + } + if("1".equalsIgnoreCase(bengintime_across)) { + signInDateTime = nextday + " " +bengintime+":00"; + } + String signInEndDateTime = ""; + if(bengintime_end.length() > 0){ + signInEndDateTime = splitDate + " " +bengintime_end+":00"; + if("1".equalsIgnoreCase(bengintime_end_across)) { + signInEndDateTime = nextday + " " +bengintime_end+":00"; + } + } +// if(pre_workTime.length() > 0){ +// signInDateTime = splitDate + " " +pre_workTime+":00"; +// } + String signOutDateTime = splitDate + " " +endtime+":59"; + if("1".equalsIgnoreCase(endtime_across)) { + signOutDateTime = nextday + " " +endtime+":59"; + } + String signOutBeginDateTime = ""; + if(endtime_start.length() > 0){ + signOutBeginDateTime = splitDate + " " +endtime_start+":59"; + if("1".equalsIgnoreCase(endtime_start_across)) { + signOutBeginDateTime = nextday + " " +endtime_start+":59"; + } + } + String sign_signSectionTime = ""; + String sign_signSectionEndTime = ""; + String sign_signSectionBeginTime = ""; + String sign_offSignSectionTime = ""; + if(signInEndDateTime.length() == 0 && signOutBeginDateTime.length() == 0){ + //濡傛灉娌¤缃笂鐝悗锛屼笅鐝墠鎵撳崱 + sign_signSectionTime = signInDateTime; + sign_offSignSectionTime = signOutDateTime; + }else{ + if(signInEndDateTime.length() > 0){ + if(signOutBeginDateTime.length() > 0){ + //濡傛灉涓婄彮鍚庯紝涓嬬彮鍓嶆墦鍗¤寖鍥撮兘鍋氫簡鎺у埗 + sign_signSectionTime = signInDateTime; + sign_signSectionEndTime = signInEndDateTime; + sign_signSectionBeginTime = signOutBeginDateTime; + sign_offSignSectionTime = signOutDateTime; + + }else{ + LocalDateTime onLocalDateEndTime = LocalDateTime.parse(signInEndDateTime,fullFormatter); + //濡傛灉鍙槸涓婄彮鍚庢墦鍗¤寖鍥村仛浜嗘帶鍒 + LocalDateTime tmp = LocalDateTime.parse(onLocalDateEndTime.plusMinutes(1).format(datetimeFormatter)+":00",fullFormatter); + String tmp_datetime = tmp.format(fullFormatter); + sign_signSectionTime = signInDateTime; + sign_signSectionEndTime = signInEndDateTime; + sign_signSectionBeginTime = tmp_datetime; + sign_offSignSectionTime = signOutDateTime; + + } + }else if(signOutBeginDateTime.length() > 0){ + //濡傛灉鍙槸涓嬬彮鍓嶆墦鍗¤寖鍥村仛浜嗘帶鍒 + LocalDateTime offLocalDateBeginTime = LocalDateTime.parse(signOutBeginDateTime,fullFormatter); + LocalDateTime tmp = LocalDateTime.parse(offLocalDateBeginTime.minusMinutes(1).format(datetimeFormatter)+":59",fullFormatter); + String tmp_datetime = tmp.format(fullFormatter); + sign_signSectionTime = signInDateTime; + sign_signSectionEndTime = tmp_datetime; + sign_signSectionBeginTime = signOutBeginDateTime; + sign_offSignSectionTime = signOutDateTime; + } + } + + KQScheduleSignBiz kqScheduleSignBiz = new KQScheduleSignBiz.KQScheduleSignParamBuilder().resourceidParam(resourceid) + .signSectionTimeParam(sign_signSectionTime).signSectionEndTimeParam(sign_signSectionEndTime) + .signSectionBeginTimeParam(sign_signSectionBeginTime).offSignSectionTimeParam(sign_offSignSectionTime).build(); + Map signMap = kqScheduleSignBiz.getScheduleSignInfoWithCardRange(); + if(signMap != null && !signMap.isEmpty()) { + KQHrmScheduleSign signInTimeBean = signMap.get("signin"); + KQHrmScheduleSign signOutTimeBean = signMap.get("signout"); + if(allWorkTime.size() == 2){ + boolean is_flow_humanized = KQSettingsBiz.is_flow_humanized(); + if(is_flow_humanized){ + //涓澶╀竴娆℃墦鍗$殑鎯呭喌涓嬮渶瑕佽冭檻涓у寲璁剧疆 + if(todayLineMap.containsKey("shiftRuleMap")){ + Map shiftRuleMap = (Map) todayLineMap.get("shiftRuleMap"); + if (shiftRuleMap != null && !shiftRuleMap.isEmpty() && shiftRuleMap.containsKey("ruleDetail")) {//澶勭悊浜烘у寲璁剧疆鍏朵粬瑙勫垯 + Map ruleDetail = (Map) shiftRuleMap.get("ruleDetail"); + if (ruleDetail != null && !ruleDetail.isEmpty()) { + Map shifRuleMap = KQShiftRuleInfoBiz.do4ShiftRule(ruleDetail,signInTimeBean,signOutTimeBean,allWorkTime,splitDate,nextday,resourceid); + if(!shifRuleMap.isEmpty()){ + if(shifRuleMap.containsKey("shift_beginworktime")){ + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + firstWorkTime = shift_beginworktime; + } + if(shifRuleMap.containsKey("shift_endworktime")){ + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if(shift_endworktime.length() > 0){ + lastWorkTime = shift_endworktime; + int lastWorkTime_index = kqTimesArrayComInfo.getArrayindexByTimes(lastWorkTime); + if(lastWorkTime_index >= 1440){ + isEndTimeAcross = true; + lastWorkTime = kqTimesArrayComInfo.turn48to24Time(lastWorkTime); + }else{ + isEndTimeAcross = false; + } + + } + } + } + } + } + } + } + } + if(signsource.length() > 0){ + if("before".equalsIgnoreCase(signsource)){ + signOutTimeBean = null; + } + if("after".equalsIgnoreCase(signsource)){ + signInTimeBean = null; + } + } + if(signInTimeBean != null){ + String signdate = Util.null2String(signInTimeBean.getSigndate()); + String signtime= Util.null2String(signInTimeBean.getSigntime()); + String pre_bengintime = Util.null2String(workTimeStartMap.get("pre_workbengintime")); + if(pre_bengintime.length() > 0){ + //褰撳墠鏄伐浣滄棩锛屽墠涓澶╂槸宸ヤ綔鏃ョ殑鎯呭喌 + pre_bengintime = pre_bengintime+":00"; + String tmp_pre_bengintime = splitDate+" "+pre_bengintime; + String tmp_workbengintime = splitDate+" "+workbengintime+":00"; + if(tmp_pre_bengintime.compareTo(tmp_workbengintime) > 0){ + pre_bengintime = workbengintime+":00"; + } + if(firstWorkTime.length() > 0) { + String tmp_firstWorkTime = splitDate + " " + firstWorkTime + ":00"; + if(tmp_pre_bengintime.compareTo(tmp_firstWorkTime) > 0){ + tmp_pre_bengintime = tmp_firstWorkTime; + pre_bengintime = firstWorkTime + ":00"; + } + } + String tmp_signtime = signdate+" "+signtime; + if(tmp_pre_bengintime.compareTo(tmp_signtime) > 0){ + if(signtime.length() > 0){ + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(pre_splitDate); + kqTaskBean.setLastWorkTime(signtime); + kqTaskBean.setTaskSignTime(pre_bengintime); + kqTaskBean.setSignDate(signdate); + kqTaskBean.setSignEndDate(splitDate); + kqTaskBean.setTimesource("before"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + }else{ + kqLog.info("overTime4Work::signtime is null:"+signtime); + } + } + }else{ + //褰撳墠鏄伐浣滄棩锛屽墠涓澶╂槸闈炲伐浣滄棩鐨勬儏鍐 + String pre_isrest = Util.null2String(workTimeStartMap.get("pre_isrest")); + if("1".equalsIgnoreCase(pre_isrest)){ + if(firstWorkTime.length() > 0){ + String tmp_firstWorkTime = splitDate+" "+firstWorkTime+":00"; + String tmp_signtime = signdate+" "+signtime; + if(tmp_firstWorkTime.compareTo(tmp_signtime) > 0){ + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(pre_splitDate); + kqTaskBean.setSignDate(splitDate); + kqTaskBean.setSignEndDate(signdate); + kqTaskBean.setSignInTime4Out(signtime); + kqTaskBean.setTaskSignTime(firstWorkTime+":00"); + kqTaskBean.setTimesource("before"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + } + } + } + } + } + if(signOutTimeBean != null){ + String signdate = Util.null2String(signOutTimeBean.getSigndate()); + String signtime= Util.null2String(signOutTimeBean.getSigntime()); + + if(lastWorkTime.length() > 0 && signtime.length() > 0){ + if(signtime.length() == 5){ + signtime += ":00"; + } + if(lastWorkTime.length() == 5){ + lastWorkTime += ":00"; + } + String tmpsigndatetime = signdate+" "+signtime; + String tmpworkdatetime = splitDate+" "+lastWorkTime; + if(isEndTimeAcross){ + tmpworkdatetime = nextday+" "+lastWorkTime; + } + if(tmpsigndatetime.compareTo(tmpworkdatetime) > 0){ + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(splitDate); + kqTaskBean.setLastWorkTime(lastWorkTime); + kqTaskBean.setTaskSignTime(signtime); + if(isEndTimeAcross){ + kqTaskBean.setSignDate(nextday); + }else{ + kqTaskBean.setSignDate(splitDate); + } + kqTaskBean.setSignEndDate(signdate); + kqTaskBean.setTimesource("after"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + } + }else{ + kqLog.info("overTime4Work:lastWorkTime is null :"+lastWorkTime+":signtime is null:"+signtime); + } + } + } + } + /** + * 閽堝闈炲伐浣滄棩鎺ㄩ佸姞鐝暟鎹 + * @param splitDate + * @param pre_workTime 鍓嶄竴澶╂槸宸ヤ綔鏃ワ紝鍓嶄竴澶╁伐浣滄棩鏈鍚庝笅鐝椂闂磋法澶╀簡浼氬奖鍝嶅埌浠婂ぉ寮濮嬫墦鍗℃椂闂 + * @param resourceid + * @param tasks + * @param next_workTime 鍚庝竴澶╂槸宸ヤ綔鏃ワ紝鍚庝竴澶╃殑鏈鏃╀笂鐝椂闂磋法澶╀簡锛屼細褰卞搷鍒颁粖澶╃殑缁撴潫鎵撳崱鏃堕棿 + * @param workTimeStartMap + * @param pre_splitDate + */ + public static void overTime4NonWork(String splitDate, String pre_workTime, String resourceid, + List tasks, String next_workTime, + Map workTimeStartMap, String pre_splitDate){ + + String signInTime4Out = ""; + String signTime = ""; + String bengintime = "00:00"; + String endtime = "23:59"; + String signInDateTime = splitDate + " " +bengintime+":00"; + if(pre_workTime.length() > 0){ + signInDateTime = pre_workTime; + } + String signOutDateTime = splitDate + " " +endtime+":59"; + if(next_workTime.length() > 0){ + signOutDateTime = next_workTime; + } + String signDateTimeSql = ""; + String buildSql = KQSignUtil.buildSignSql(signInDateTime, signOutDateTime); + if(buildSql.length() > 0){ + signDateTimeSql += buildSql; + } + KQScheduleSignBiz kqScheduleSignBiz = new KQScheduleSignBiz.KQScheduleSignParamBuilder().resourceidParam(resourceid). + signDateTimeSqlParam(signDateTimeSql).signDateParam(splitDate).build(); + Map signMap = kqScheduleSignBiz.getScheduleSignInfo(); + if(signMap != null && !signMap.isEmpty()) { + KQHrmScheduleSign signInTimeBean = signMap.get("signin"); + KQHrmScheduleSign signOutTimeBean = signMap.get("signout"); + if(signInTimeBean != null){ + signInTime4Out = Util.null2String(signInTimeBean.getSigntime()); + } + if(signOutTimeBean != null){ + signTime = Util.null2String(signOutTimeBean.getSigntime()); + } + } + + String pre_bengintime = Util.null2String(workTimeStartMap.get("pre_workbengintime")); + if(pre_bengintime.length() > 0) { + pre_bengintime = pre_bengintime + ":00"; + if (pre_bengintime.compareTo(signInTime4Out) > 0) { + //闈炲伐浣滄棩鍔犵彮鐨勮瘽锛岀閫鏁版嵁閮介渶瑕佸幓鎼炰竴閬嶈皟浼 + if(pre_bengintime.length() > 0 && signInTime4Out.length() > 0) { + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(pre_splitDate); + kqTaskBean.setLastWorkTime(signInTime4Out); + kqTaskBean.setTaskSignTime(pre_bengintime); + kqTaskBean.setSignDate(splitDate); + kqTaskBean.setSignEndDate(splitDate); + kqTaskBean.setTimesource("before"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + }else{ + kqLog.info("overTime4NonWork:pre_bengintime is null :"+pre_bengintime+":signInTime4Out is null:"+signInTime4Out); + } + if(pre_bengintime.length() > 0 && signTime.length() > 0) { + //TODO pre_bengintime signTime 闇瑕佹瘮杈冧竴涓嬪ぇ灏 + if(signTime.compareTo(pre_bengintime) > -1){ + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(splitDate); + kqTaskBean.setSignDate(splitDate); + kqTaskBean.setSignEndDate(splitDate); + //瀵逛簬闈炲伐浣滄椂娈碉紝绛惧埌灏辨槸浠栫殑鏈鍚庝竴娆′笅鐝椂闂 + kqTaskBean.setSignInTime4Out(pre_bengintime); + kqTaskBean.setTaskSignTime(signTime); + kqTaskBean.setTimesource("after"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + } + }else{ + kqLog.info("overTime4NonWork:pre_bengintime is null :"+pre_bengintime+":signTime is null:"+signTime); + } + + }else{ + //闈炲伐浣滄棩鍔犵彮鐨勮瘽锛岀閫鏁版嵁閮介渶瑕佸幓鎼炰竴閬嶈皟浼 + if(signInTime4Out.length() > 0 && signTime.length() > 0) { + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(splitDate); + kqTaskBean.setSignDate(splitDate); + kqTaskBean.setSignEndDate(splitDate); + //瀵逛簬闈炲伐浣滄椂娈碉紝绛惧埌灏辨槸浠栫殑鏈鍚庝竴娆′笅鐝椂闂 + kqTaskBean.setSignInTime4Out(signInTime4Out); + kqTaskBean.setTimesource("after"); + kqTaskBean.setTaskSignTime(signTime); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + }else{ + kqLog.info("overTime4NonWork:signInTime4Out is null :"+signInTime4Out+":signTime is null:"+signTime); + } + } + }else{ + //闈炲伐浣滄棩鍔犵彮鐨勮瘽锛岀閫鏁版嵁閮介渶瑕佸幓鎼炰竴閬嶈皟浼 + if(signInTime4Out.length() > 0 && signTime.length() > 0) { + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(splitDate); + kqTaskBean.setSignDate(splitDate); + kqTaskBean.setSignEndDate(splitDate); + //瀵逛簬闈炲伐浣滄椂娈碉紝绛惧埌灏辨槸浠栫殑鏈鍚庝竴娆′笅鐝椂闂 + kqTaskBean.setSignInTime4Out(signInTime4Out); + kqTaskBean.setTaskSignTime(signTime); + kqTaskBean.setTimesource("after"); + if(!tasks.contains(kqTaskBean)){ + tasks.add(kqTaskBean); + } + }else{ + kqLog.info("overTime4NonWork:signInTime4Out is null :"+signInTime4Out+":signTime is null:"+signTime); + } + } + + } + +} diff --git a/src/weaver/interfaces/bnkq/action/GdJbUpdateAction.java b/src/weaver/interfaces/bnkq/action/GdJbUpdateAction.java new file mode 100644 index 0000000..1327a7a --- /dev/null +++ b/src/weaver/interfaces/bnkq/action/GdJbUpdateAction.java @@ -0,0 +1,707 @@ + +package weaver.interfaces.bnkq.action; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.engine.kq.biz.*; +import com.engine.kq.entity.KQOvertimeRulesDetailEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.timer.KQOvertimeCardBean; +import com.engine.kq.util.TimeRangeCalculator; +import com.engine.kq.wfset.bean.OvertimeBalanceTimeBean; +import com.engine.kq.wfset.bean.SplitBean; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import weaver.conn.RecordSet; +import weaver.formmode.setup.ModeRightInfo; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.resource.ResourceComInfo; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.Property; +import weaver.soa.workflow.request.RequestInfo; + +import java.io.PrintWriter; +import java.io.StringWriter; +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.util.*; + +/** + * 鍥哄畾鍔犵彮鏃堕暱鍐欏叆鍔犵彮鍙拌处 + */ +public class GdJbUpdateAction implements Action { + + static String dateFormat = "yyyy-MM-dd"; + static SimpleDateFormat format = new SimpleDateFormat(dateFormat); + + public GdJbUpdateAction() { + } + + @Override + public String execute(RequestInfo info) { + new BaseBean(); + BaseBean bb = new BaseBean(); + bb.writeLog("鍥哄畾鍔犵彮鏃堕暱鍐欏叆鍔犵彮鍙拌处"); + RecordSet rs = new RecordSet(); + int userid = info.getRequestManager().getUser().getUID(); + String wfid = info.getWorkflowid(); + String reqid = info.getRequestid(); + String tablaName = info.getRequestManager().getBillTableName(); + try { + //鑾峰彇涓昏〃鏁版嵁 + Map mainInfo = getMainInfo(info); + //鍔犵彮浜 + String jbr = Util.null2String(mainInfo.get("jbr")); + //寮濮嬫棩鏈 + String ksrq = Util.null2String(mainInfo.get("ksrq")); + //缁撴潫鏃ユ湡 + String jsrq = Util.null2String(mainInfo.get("jsrq")); + //鍔犵彮鏂瑰紡 + String jblx = Util.null2String(mainInfo.get("jbxz")); + //鎶ラ攢鏂瑰紡 + String bcfs = Util.null2String(mainInfo.get("bcfs")); + //鐢宠浜嬬敱 + String sqsy = Util.null2String(mainInfo.get("sqsy")); + //寮濮嬫椂闂 + String kssj = Util.null2String(mainInfo.get("kssj")); + //缁撴潫鏃堕棿 + String jssj = Util.null2String(mainInfo.get("jssj")); + + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(jbr, ksrq); + + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main", "glrygroupid"); + bb.writeLog("鑾峰彇褰撳墠浜哄憳groupId:" + groupId + "glrygroupid:" + glrygroupid); + if (groupId.equals(glrygroupid)) { + buildOvertime(jbr, ksrq, jsrq, "鍥哄畾鍔犵彮娴佺▼鐢熸垚鍙拌处", jblx, bcfs, sqsy, ksrq, jsrq, kssj, jssj); + } + + + } catch (Exception e) { + e.printStackTrace(); + bb.writeLog(e); + bb.writeLog("鍥哄畾鍔犵彮鏃堕暱鍐欏叆鍔犵彮鍙拌处error" + e.getMessage()); + info.getRequestManager().setMessageid("2000"); + info.getRequestManager().setMessagecontent("鍥哄畾鍔犵彮鏃堕暱鍐欏叆鍔犵彮鍙拌处error"); + return Action.FAILURE_AND_CONTINUE; + } + return Action.SUCCESS; + } + + /** + * 鐢熸垚鍔犵彮鏁版嵁 + * + * @param resourceid + * @param fromDate + * @param toDate + * @param eventtype + */ + public void buildOvertime(String resourceid, String fromDate, String toDate, String eventtype, String jblx, String bxfs, String sqsy, String ksrq, String jsrq, String kssj, String jssj) { + BaseBean bb = new BaseBean(); + RecordSet singleRs = new RecordSet(); + try { + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + Map changeTypeMap = Maps.newHashMap(); + Map overRulesDetailMap = Maps.newHashMap(); + Map> restTimeMap = Maps.newHashMap(); + Map computingModeMap = Maps.newHashMap(); + //鍏堣幏鍙栦竴浜涘墠鎻愭暟鎹紝鍔犵彮瑕忓墖鍜屽亣鏈熻鍓 + kqOverTimeRuleCalBiz.getOverTimeDataMap(resourceid, fromDate, toDate, dateFormatter, changeTypeMap, overRulesDetailMap, restTimeMap, computingModeMap); + Map eventLogMap = Maps.newHashMap(); + eventLogMap.put("fromDate", fromDate); + eventLogMap.put("toDate", toDate); + eventLogMap.put("eventtype", eventtype); + String logKey = "|key|" + resourceid + "_" + fromDate + "_" + toDate; + bb.writeLog("buildOvertime|鐢熸垚鍔犵彮璋冧紤" + JSONObject.toJSONString(eventLogMap) + "logKey" + logKey); + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate localToDate = LocalDate.parse(toDate); + LocalDate preFromDate = localFromDate.minusDays(1); + LocalDate nextToDate = localToDate.plusDays(1); + //涔嬪墠鏄冭檻澶栭儴鑰冨嫟鏁版嵁瀵煎叆璺ㄥぉ鎵撳崱锛屽垽鏂綊灞炵殑闂锛屽悜鍓嶇畻涓澶╋紝鐜板湪涓嶇浜嗭紝閮芥槸榛樿鍙鐞嗗綋澶╃殑 + if (eventtype.indexOf("#flow,") > -1 || eventtype.indexOf("punchcard") > -1 || true) { + //濡傛灉鏄甯歌蛋鐨勫姞鐝祦绋嬶紝灏辨槸娴佺▼寮濮嬫棩鏈熷拰缁撴潫鏃ユ湡锛屽彧鏈夎ˉ鍗★紝鎵撳崱锛屽悓姝ョ殑鏃跺欐墠闇瑕佸鐞嗕竴涓嬪墠涓澶╁拰鍚庝竴澶╃殑鏁版嵁 + preFromDate = localFromDate; + nextToDate = localToDate; + } + long betweenDays = nextToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + LocalDate curLocalDate = preFromDate.plusDays(i); + String splitDate = curLocalDate.format(dateFormatter); +// 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屽彇娴佺▼鍜屾墦鍗$殑浜ら泦 + doComputingMode4(resourceid, splitDate, dateFormatter, changeTypeMap, overRulesDetailMap, restTimeMap, + computingModeMap, kqTimesArrayComInfo, "", jblx, bxfs, sqsy, ksrq, jsrq, kssj, jssj, singleRs); + } + } catch (Exception e) { + bb.writeLog("鍔犵彮鐢熸垚鏁版嵁鎶ラ敊:KQOverTimeRuleCalBiz:"); + } + } + + /** + * 闇瀹℃壒锛屼互鎵撳崱涓哄噯锛屽彇娴佺▼鍜屾墦鍗$殑浜ら泦 + * + * @param resourceid + * @param splitDate + * @param dateFormatter + * @param changeTypeMap + * @param overRulesDetailMap + * @param restTimeMap + * @param computingModeMap + * @param kqTimesArrayComInfo + * @param main_uuid + * @param singleRs + */ + private void doComputingMode4(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, String jblx, String bxfs, String sqsy, String ksrq, String jsrq, String kssj, String jssj, RecordSet singleRs) throws Exception { + String key = resourceid + "_" + splitDate; + //鍔犵彮鏃ュ織璁板綍绫 + KQWorkTime kqWorkTime = new KQWorkTime(); + BaseBean bb = new BaseBean(); + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceid, splitDate); + Map workTimeEntityLogMap = Maps.newHashMap(); + workTimeEntityLogMap.put("resourceid", resourceid); + workTimeEntityLogMap.put("splitDate", splitDate); + workTimeEntityLogMap.put("workTimeEntity", workTimeEntity); + Map overtimeLogMap = Maps.newLinkedHashMap(); + Map eventMap = Maps.newLinkedHashMap(); + Map lsCheckInfoMaps = Maps.newLinkedHashMap(); + KQOverTimeRuleCalBiz kqOverTimeRuleCalBiz = new KQOverTimeRuleCalBiz(); + //鑾峰彇鍔犵彮鎵撳崱鏁版嵁 + kqOverTimeRuleCalBiz.getOverTimeCardDataMap(resourceid, splitDate, splitDate, dateFormatter, kqTimesArrayComInfo, overRulesDetailMap, changeTypeMap, lsCheckInfoMaps, eventMap); + bb.writeLog("鑾峰彇鎵撳崱鏁版嵁缁撴潫lsCheckInfoMaps:" + JSONObject.toJSONString(lsCheckInfoMaps)); + if (lsCheckInfoMaps.isEmpty()) { + bb.writeLog("瀵瑰簲鐨勫姞鐝祦绋嬫暟鎹甼ey" + key); + return; + } + Iterator> iterator = lsCheckInfoMaps.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry next = iterator.next(); + String mapKey = next.getKey(); + KQOvertimeCardBean kqOvertimeCardBean = next.getValue(); + String[] mapKeys = mapKey.split("_"); + if (mapKeys.length != 2) { + continue; + } + String realSplitDate = mapKeys[1]; + Map> splitBeanMaps = Maps.newHashMap(); + //鑾峰彇鍔犵彮娴佺▼鏁版嵁 + getOverTimeFlowData(resourceid, realSplitDate, realSplitDate, splitBeanMaps, dateFormatter); + String change_key = realSplitDate + "_" + resourceid; + int changeType = Util.getIntValue("" + changeTypeMap.get(change_key), -1); + String changeType_key = realSplitDate + "_" + changeType; + String changetypeName = 1 == changeType ? "鑺傚亣鏃" : (2 == changeType ? "宸ヤ綔鏃" : (3 == changeType ? "浼戞伅鏃" : "寮傚父")); + String changetypeLogInfo = change_key + "|changeType|" + changeType + "|" + changetypeName + "changeType_key" + changeType_key; + bb.writeLog("changetypeLogInfo:" + changetypeLogInfo); + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + if (kqOvertimeCardBean != null) { + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + List> hasOverTime4SignList = Lists.newArrayList(); + getHasOverTimeData(resourceid, realSplitDate, hasOverTime4SignList); + bb.writeLog("kqOvertimeCardBean:" + JSONObject.toJSONString(kqOvertimeCardBean)); + bb.writeLog("realSplitDate:" + realSplitDate); + bb.writeLog("hasOverTime4SignList:" + JSONObject.toJSONString(hasOverTime4SignList)); + Map signinoffMap = kqOverTimeRuleCalBiz.buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key, initArrays, hasOverTime4SignList, + overRulesDetailMap, true, overtimeLogMap); + bb.writeLog("signinoffMap:" + JSONObject.toJSONString(signinoffMap)); + String signinTime = Util.null2String(signinoffMap.get("signinTime")); + String signoutTime = Util.null2String(signinoffMap.get("signoutTime")); + String signinDate = Util.null2String(signinoffMap.get("signinDate")); + String signoutDate = Util.null2String(signinoffMap.get("signoutDate")); + int signinTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signinTime); + int signoutTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(signoutTime); + Integer check = Integer.valueOf(signinTime.substring(0, 2)); + if (check > 24) { + bb.writeLog("涓嶆彃鍏ュ彴璐"); + } else { + if (signinTimeIndex < signoutTimeIndex) { + int across_mins = 0; + int kssjIndex = kqTimesArrayComInfo.getArrayindexByTimes(kssj + ":00"); + int jssjIndex = kqTimesArrayComInfo.getArrayindexByTimes(jssj + ":00"); + int checkIndex = kqTimesArrayComInfo.getArrayindexByTimes("20:00:00"); + int check2Index = kqTimesArrayComInfo.getArrayindexByTimes("06:30:00"); + String endTime = ""; + if (signoutTimeIndex < jssjIndex) { + endTime = signoutTime; + } else { + endTime = jssj + ":00"; + } + bb.writeLog("endTime" + endTime); + if (jssjIndex < checkIndex) { + //澶滅彮 + //鐧界彮 + String kssjNew = ""; + if (kssjIndex < check2Index) { + kssjNew = "06:30"; + } else { + kssjNew = kssj; + } + across_mins = divide(String.valueOf(TimeUtil.timeInterval(ksrq + " " + kssjNew + ":00", jsrq + " " + endTime)), "60").intValue(); + } else { + //鐧界彮 + String kssjNew = ""; + if (kssjIndex < checkIndex) { + kssjNew = "20:00"; + } else { + kssjNew = kssj; + } + + across_mins = divide(String.valueOf(TimeUtil.timeInterval(ksrq + " " + kssjNew + ":00", jsrq + " " + endTime)), "60").intValue(); + } + + + bb.writeLog("鏈缁堢敓鎴愮殑鍔犵彮鍒嗛挓鏁" + across_mins); + /*鑾峰彇鑰冨嫟缁勭殑ID锛屽洜涓鸿冨嫟缁勬湁鏈夋晥鏈燂紝鎵浠ラ渶瑕佷紶鍏ユ棩鏈*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceid, realSplitDate); + bb.writeLog("鑾峰彇褰撳墠浜哄憳groupId:" + groupId + "across_mins:" + across_mins); + //绠$悊浜哄憳12灏忔椂鐝埗鑰冨嫟缁刬d + String glrygroupid = bb.getPropValue("nbkq_main", "glrygroupid"); + Integer bxszh = changeBxs(across_mins); + Integer yxszh = changeyxs(across_mins); + String searIdFrom = workTimeEntity.getSerialId(); + bb.writeLog("鍗婂皬鏃惰鎻愭椂闀縝xszh:" + bxszh + "yxszh:" + yxszh + "searIdFrom:" + searIdFrom); + bb.writeLog("jblx:" + jblx); + if (groupId.equals(glrygroupid)) { + bb.writeLog("鏄鐞嗕汉鍛12灏忔椂"); + //鏄鐞嗕汉鍛12灏忔椂鐝 + if ("0".equals(jblx)) { + //涓存椂鍘讳竴绾 + //鍒ゆ柇鏄惁灏忎簬0.5 + if (across_mins < 30) { + bb.writeLog("灏忎簬鍗婂皬鏃惰0"); + across_mins = 0; + } else { + bb.writeLog("鍗婂皬鏃惰鎻"); + across_mins = bxszh; + } + } else { + //绠$悊浜哄憳鐨12灏忔椂鐝埗鍔犵彮瑙勫垯鏄姞鐝渶灏忓崟浣嶆槸1灏忔椂锛屼互1灏忔椂涓洪掑璁$畻鍗曚綅,渚嬪1銆2銆3 + //鍒ゆ柇鏄惁灏忎簬1 + if (across_mins < 60) { + bb.writeLog("灏忎簬1灏忔椂璁0"); + across_mins = 0; + } else { + bb.writeLog("1灏忔椂璁℃彁"); + across_mins = yxszh; + } + } + } + + bb.writeLog("棰勮鎻掑叆鏃堕暱:" + across_mins); + + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + + if (changeType == 2) { + deleteJbtz(resourceid, "0", realSplitDate); + insertJbtz(resourceid, String.valueOf(across_mins), resourceid, jblx, bxfs, + signinDate + " " + signinTime, signoutDate + " " + signoutTime, "0", + String.valueOf(changeType), ksrq, jsrq, sqsy, kssj, jssj, realSplitDate, searIdFrom, singleRs); + } + } else { + + bb.writeLog("鎵撳崱鏁版嵁寮傚父"); + } + } + + } else { + bb.writeLog("鎵撳崱鏁版嵁KQOvertimeCardBean涓簄ull"); + } + } + } + + /** + * 鑾峰彇涓や釜鏃ユ湡涔嬮棿鎵鏈夌殑鏃ユ湡 + * + * @param date1 + * @param date2 + * @return + */ + public static ArrayList days(String date1, String date2) { + ArrayList L = new ArrayList(); + if (date1.equals(date2)) { + System.out.println("涓や釜鏃ユ湡鐩哥瓑!"); + return L; + } + + String tmp; + if (date1.compareTo(date2) > 0) { // 纭繚 date1鐨勬棩鏈熶笉鏅氫簬date2 + tmp = date1; + date1 = date2; + date2 = tmp; + } + + tmp = format.format(str2Date(date1).getTime() + 3600 * 24 * 1000); + + int num = 0; + while (tmp.compareTo(date2) < 0) { + L.add(tmp); + num++; + tmp = format.format(str2Date(tmp).getTime() + 3600 * 24 * 1000); + } + + if (num == 0) { + System.out.println("涓や釜鏃ユ湡鐩搁偦!"); + } + return L; + } + + + private static Date str2Date(String str) { + if (str == null) { + return null; + } + + try { + return format.parse(str); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + + /** + * 鑾峰彇涓昏〃鏁版嵁 + * + * @param requestInfo + * @return + */ + private static Map getMainInfo(RequestInfo requestInfo) { + Map map = new HashMap(); + Property[] property = requestInfo.getMainTableInfo().getProperty(); + for (int i = 0; i < property.length; i++) { + map.put(property[i].getName().toLowerCase(), Util.null2String(property[i].getValue())); + } + return map; + } + + /** + * 鎻愪緵绮剧‘鐨勪箻娉曡繍绠椼 + * + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static Double multiply(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.multiply(b2).doubleValue(); + } + + /** + * 鎻掑叆璇峰亣鎷嗗垎琛 + * + * @param requestid + * @param userid + * @param fromDate + * @param MaxHours + */ + private static void insertLeave(String requestid, Integer userid, String fromDate, Double MaxHours, String durationrule, String newleavetype, String subcompany, String department, String toDate, String wfid, String tablename) { + BaseBean bb = new BaseBean(); + //鎻掑叆鍔犵彮鏃堕棿 + RecordSet rsInsert = new RecordSet(); + String sql = "insert into kq_flow_split_evection (requestid,resourceid,fromdate,fromtime,todate,totime,duration,durationrule,belongdate,newleavetype,subcompanyid,departmentid,workflowid,tablenamedb) " + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + rsInsert.executeUpdate(sql, requestid, userid, fromDate, "08:00", toDate, "17:00", MaxHours, durationrule, fromDate, newleavetype, subcompany, department, wfid, tablename); + bb.writeLog("insertSql:" + sql); + } + + + /** + * 鍗婂皬鏃惰浆鎹 + * + * @param value + * @return + */ + public static Integer changeBxs(Integer value) { + return (value / 30) * 30; + } + + /** + * 1灏忔椂杞崲 + * + * @param value + * @return + */ + public static Integer changeyxs(Integer value) { + return (value / 60) * 60; + } + + /** + * 鍏堝垹闄ゅ彴璐 + * + * @param jbr + * @param ly + * @param date + */ + public static void deleteJbtz(String jbr, String ly, String date) { + RecordSet rs = new RecordSet(); + String sql = "delete from uf_jbtz where jbr='" + jbr + "' and ly =" + ly + " and gzrq = '" + date + "' "; + rs.executeUpdate(sql); + } + + + /** + * 鍔犵彮鍙拌处鏁版嵁鍐欏叆 + */ + public static void insertJbtz(String jbr, String gjsc, String sqr, String jbxz, String bcfs, String zzdksj, String zwdkrq, String ly, String jblx, String ksrq, String jsrq, String sqsy, String kssj, String jssj, String szrq, String searIdFrom, RecordSet singleRs) { + RecordSet rs = new RecordSet(); + String idNew = "1"; + int modeid = getFormModeIdByCubeName("uf_jbtz"); + SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss"); + String modedatacreatedate = sdfDate.format(new Date()); + String modedatacreatetime = sdfTime.format(new Date()); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String bm = resourceComInfo.getDepartmentID(jbr); + String szbm = resourceComInfo.getDepartmentID(sqr); + String sjh = resourceComInfo.getTelephone(jbr); + String gh = resourceComInfo.getWorkcode(jbr); + String zw = resourceComInfo.getJobActivityDesc(jbr); + Double sc = divide(gjsc, "60"); + String jblxNew = ""; + if ("1".equals(jblx)) { + jblxNew = "2"; + } else if ("2".equals(jblx)) { + jblxNew = "0"; + } else if ("3".equals(jblx)) { + jblxNew = "1"; + } + int weekDay = TimeUtil.dateWeekday(ksrq); + if (weekDay == 0 || weekDay == 6) { + jblxNew = "1"; + } + //濡傛灉鏄紤鐝锛屽姞鐝被鍨嬩负浼戞伅鏃ュ姞鐝 + if (isRestSerial(searIdFrom, rs)) { + jblxNew = "1"; + sc = recalculateOverTime(sc, searIdFrom, ksrq, kssj, jsrq, jssj, rs, singleRs); + } + + + String sqlMode = "insert into uf_jbtz (jbr,gjsc,bcfs,jbxz,sqr,szbm,sjh,zzdksj,zwdkrq,ly,gh,bm,zw,jblx,ksrq,jsrq,sqsy,kssj,jssj,gzrq,FORMMODEID,MODEDATACREATER,MODEDATACREATERTYPE,MODEDATACREATEDATE,MODEDATACREATETIME) \n" + + "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + rs.executeUpdate(sqlMode, jbr, sc, bcfs, jbxz, sqr, szbm, sjh, zzdksj, zwdkrq, ly, gh, bm, zw, jblxNew, ksrq, jsrq, sqsy, kssj, jssj, szrq, modeid, jbr, "0", modedatacreatedate, modedatacreatetime); + + RecordSet findNew = new RecordSet(); + String sqlFindnew = "select Id from uf_jbtz where jbr = '" + jbr + "' and zzdksj = '" + zzdksj + "' and zwdkrq = '" + zwdkrq + "' order by" + + " modedatacreatedate desc,modedatacreatetime desc"; + findNew.execute(sqlFindnew); + + if (findNew.next()) { + idNew = Util.null2String(findNew.getString("id")); + } + + // 鏉冮檺閲嶆瀯 + int dataId = Integer.valueOf(idNew); + ModeRightInfo modeRightInfo = new ModeRightInfo(); + modeRightInfo.editModeDataShare(Integer.valueOf(jbr), modeid, dataId); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static Double recalculateOverTime(Double sc, String serialId, String ksrq, String kssj, String jsrq, String jssj, RecordSet rs, RecordSet singleRs) { + BaseBean bb = new BaseBean(); + try { + boolean isAcross = false; + BigDecimal workTimeTotal = new BigDecimal(TimeUtil.timeInterval(ksrq + " " + kssj + ":00", jsrq + " " + jssj + ":00")); + BigDecimal restTimeCount = new BigDecimal(0); + if (ksrq.compareTo(jsrq) > 0) { + isAcross = true; + } + String restStartSql = "select * from kq_ShiftRestTimeSections where serialid=? and resttype='start'"; + rs.executeQuery(restStartSql, serialId); + while (rs.next()) { + //浼戞伅寮濮嬫椂闂 + String startTime = rs.getString("time"); + String record1 = rs.getString("record1"); + //浼戞伅缁撴潫鏃堕棿 + String restEndSql = "select * from kq_ShiftRestTimeSections where record1=? and resttype='end'"; + singleRs.executeQuery(restEndSql, record1); + singleRs.next(); + String endTime = singleRs.getString("time"); + if (isAcross) { + double restTime1 = TimeRangeCalculator.getRestTime(kssj, "23:59", startTime, endTime); + double restTime2 = TimeRangeCalculator.getRestTime("00:00", jssj, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime1)); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime2)); + + } else { + double restTime = TimeRangeCalculator.getRestTime(kssj, jssj, startTime, endTime); + restTimeCount = restTimeCount.add(BigDecimal.valueOf(restTime)); + } + } + sc = divideRoundModeDown(workTimeTotal.subtract(restTimeCount).toString(), "3600"); + //鍔犵彮鏈灏忓崟浣嶆槸2灏忔椂 + //涓灏忔椂鍜屼袱灏忔椂璧蜂紤鐝id + String twoStartSerId = bb.getPropValue("nbkq_main", "twoStartSerId"); + if (Arrays.asList(twoStartSerId.split(",")).contains(serialId) && sc < 2) { + sc = 0.0; + } + return sc; + } catch (Exception e) { + bb.writeLog("recalculateOverTime-e-" + e.getMessage()); + return sc; + } + } + + private static boolean isRestSerial(String serialId, RecordSet rs) { + try { + String querySql = "select rest_shift from kq_ShiftManagement where id=?"; + rs.executeQuery(querySql, serialId); + if (rs.next()) { + return rs.getInt("rest_shift") == 1; + } + } catch (Exception e) { + return false; + } + return false; + } + + /** + * 鎻愪緵绮剧‘鐨勯櫎娉曡繍绠椼 + * + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static Double divide(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP).doubleValue(); + } + + public static Double divideRoundModeDown(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + BigDecimal divide = b1.divide(b2, 2, BigDecimal.ROUND_HALF_UP); + return divide.setScale(0, RoundingMode.DOWN).doubleValue(); + } + + /** + * 鎵惧埌褰掑睘鏃ユ湡褰撳ぉ宸茬敓鎴愮殑鎵撳崱鏃堕暱 + * + * @return + */ + public static Double findSc(String jbr, String gsrq) { + RecordSet rs = new RecordSet(); + String sql = "select gjsc from uf_jbtz where jbr = " + jbr + " and gzrq = '" + gsrq + "'"; + rs.executeQuery(sql); + String gjsc = ""; + if (rs.next()) { + gjsc = Util.null2String(rs.getString("gjsc")); + } + return multiply(gjsc, "60"); + + } + + /** + * 鏍规嵁寤烘ā琛ㄥ悕鑾峰彇formModeId + * + * @param cubeName 寤烘ā琛ㄦ槑 + * @return int formModeId + */ + private static int getFormModeIdByCubeName(String cubeName) { + RecordSet rs = new RecordSet(); + rs.executeQuery("select t1.id from modeinfo t1\n" + + " left join workflow_bill t2\n" + + " on t1.formid=t2.id\n" + + " where t2.tablename='" + cubeName + "'"); + rs.next(); + return rs.getInt("id"); + } + + /** + * 鑾峰彇鍔犵彮娴佺▼鏁版嵁 + * + * @param resourceid + * @param fromDate + * @param toDate + * @param splitBeanMaps + * @param dateFormatter + */ + private void getOverTimeFlowData(String resourceid, String fromDate, String toDate, + Map> splitBeanMaps, + DateTimeFormatter dateFormatter) { + LocalDate localFromDate = LocalDate.parse(fromDate); + LocalDate preFromDate = localFromDate.minusDays(1); + LocalDate localToDate = LocalDate.parse(toDate); + long betweenDays = localToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int k = 0; k <= betweenDays; k++) { + LocalDate curLocalDate = preFromDate.plusDays(k); + String splitDate = curLocalDate.format(dateFormatter); + String key = resourceid + "_" + splitDate; + String order_sql = " order by belongdate,fromtime "; + KQFlowDataBiz kqFlowDataBiz = new KQFlowDataBiz.FlowDataParamBuilder().belongDateParam(splitDate).resourceidParam(resourceid).orderby_sqlParam(order_sql).build(); + Map flowMaps = Maps.newHashMap(); + List splitBeans = kqFlowDataBiz.getOverTimeData(flowMaps); + if (!splitBeans.isEmpty()) { + splitBeanMaps.put(key, splitBeans); + } + } + } + + /** + * 鑾峰彇宸茬粡鐢熸垚杩囩殑鍔犵彮鏁版嵁 + * + * @param resourceid + * @param belongdate + * @param hasOverTimeList + */ + private void getHasOverTimeData(String resourceid, String belongdate, List> hasOverTimeList) { + RecordSet rs = new RecordSet(); + + String sql = " select * from kq_flow_overtime where resourceid = ? and belongdate = ? "; + rs.executeQuery(sql, resourceid, belongdate); + while (rs.next()) { + String requestid = rs.getString("requestid"); + String fromdate = rs.getString("fromdate"); + String fromtime = rs.getString("fromtime"); + String todate = rs.getString("todate"); + String totime = rs.getString("totime"); + String duration_min = Util.null2String(rs.getString("duration_min")); + String flow_dataid = Util.null2String(rs.getString("flow_dataid")); + String ori_belongdate = Util.null2String(rs.getString("ori_belongdate")); + //娴佺▼+鎵撳崱鐨勬椂鍊欙紝瀛樼殑瀵瑰簲鐨勬祦绋嬫暟鎹 + String fromdate_flow = rs.getString("fromdatedb"); + String fromtime_flow = rs.getString("fromtimedb"); + String todate_flow = rs.getString("todatedb"); + String totime_flow = rs.getString("totimedb"); + Map hasOverTimeMap = Maps.newHashMap(); + hasOverTimeMap.put("resourceid", resourceid); + hasOverTimeMap.put("belongdate", belongdate); + hasOverTimeMap.put("requestid", requestid); + hasOverTimeMap.put("fromdate", fromdate); + hasOverTimeMap.put("fromtime", fromtime); + hasOverTimeMap.put("todate", todate); + hasOverTimeMap.put("totime", totime); + hasOverTimeMap.put("fromdate_flow", fromdate_flow); + hasOverTimeMap.put("fromtime_flow", fromtime_flow); + hasOverTimeMap.put("todate_flow", todate_flow); + hasOverTimeMap.put("totime_flow", totime_flow); + hasOverTimeMap.put("duration_min", duration_min); + hasOverTimeMap.put("flow_dataid", flow_dataid); + hasOverTimeMap.put("ori_belongdate", ori_belongdate); + + hasOverTimeList.add(hasOverTimeMap); + } + } +} diff --git a/src/weaver/interfaces/bnkq/action/UpdateCcTimeAction.java b/src/weaver/interfaces/bnkq/action/UpdateCcTimeAction.java new file mode 100644 index 0000000..6a637e6 --- /dev/null +++ b/src/weaver/interfaces/bnkq/action/UpdateCcTimeAction.java @@ -0,0 +1,189 @@ + +package weaver.interfaces.bnkq.action; + +import com.engine.kq.biz.KQWorkTime; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.workflow.service.HtmlToPdfService; +import org.apache.commons.lang3.StringUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.PinyinUtil; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.interfaces.workflow.action.Action; +import weaver.soa.workflow.request.Property; +import weaver.soa.workflow.request.RequestInfo; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +/** + * 鏇存柊鍑哄樊鏃堕暱Action + */ +public class UpdateCcTimeAction implements Action { + + static String dateFormat = "yyyy-MM-dd"; + static SimpleDateFormat format = new SimpleDateFormat(dateFormat); + + public UpdateCcTimeAction() { + } + + @Override + public String execute(RequestInfo info) { + new BaseBean(); + BaseBean bb = new BaseBean(); + bb.writeLog("鏇存柊浜哄憳鍑哄樊鏃堕暱"); + RecordSet rs = new RecordSet(); + int userid = info.getRequestManager().getUser().getUID(); + String wfid = info.getWorkflowid(); + String reqid = info.getRequestid(); + String tablaName = info.getRequestManager().getBillTableName(); + try { + //鑾峰彇涓昏〃鏁版嵁 + Map mainInfo = getMainInfo(info); + //鐢宠浜 + String sqr = Util.null2String(mainInfo.get("ccr")); + //瀹為檯鍑哄樊寮濮嬫椂闂 + String sjksrq = Util.null2String(mainInfo.get("sjccksrq")); + //瀹為檯鍑哄樊缁撴潫鏃堕棿 + String sjccjsrq = Util.null2String(mainInfo.get("sjccjsrq")); + //閮ㄩ棬 + String szbm = Util.null2String(mainInfo.get("szbm")); + //鍒嗛儴 + String szgs = Util.null2String(mainInfo.get("szgs")); + //鐩稿樊澶╂暟 + Integer cz = TimeUtil.dateInterval(sjksrq, sjccjsrq) + 1; + //鎻掑叆鍑哄樊琛 + Double czours = multiply(String.valueOf(cz), "8"); + + Set all = new HashSet<>(); + all.add(sjksrq); + List back = days(sjksrq, sjccjsrq); + all.addAll(back); + all.add(sjccjsrq); + KQWorkTime kqWorkTime = new KQWorkTime(); + kqWorkTime.setIsFormat(true); + + for (String date : all) { + bb.writeLog("date:" + date); + WorkTimeEntity tmpworkTime = kqWorkTime.getWorkTime(sqr, date); + if (tmpworkTime.getWorkMins() > 0) { + bb.writeLog("褰撳ぉ鎺掔彮浜:" + tmpworkTime.getWorkMins()); + insertLeave(reqid, Integer.valueOf(sqr), date, 8.00, "3", "1", szgs, szbm, date, wfid, tablaName); + insertDetail(sqr, date, rs); + } + } + + } catch (Exception e) { + e.printStackTrace(); + bb.writeLog(e); + bb.writeLog("鏇存柊浜哄憳鍑哄樊鏃堕暱error" + e.getMessage()); + info.getRequestManager().setMessageid("2000"); + info.getRequestManager().setMessagecontent("鏇存柊浜哄憳鍑哄樊鏃堕暱error"); + return Action.FAILURE_AND_CONTINUE; + } + return Action.SUCCESS; + } + + private void insertDetail(String resourceId, String date, RecordSet rs) { + String sql = "update kq_format_detail set evectionMins=480,absenteeismMins=0 where resourceid=? and kqdate='" + date + "'"; + rs.executeUpdate(sql, resourceId); + } + + + /** + * 鑾峰彇涓や釜鏃ユ湡涔嬮棿鎵鏈夌殑鏃ユ湡 + * + * @param date1 + * @param date2 + * @return + */ + public static ArrayList days(String date1, String date2) { + ArrayList L = new ArrayList(); + if (date1.equals(date2)) { + System.out.println("涓や釜鏃ユ湡鐩哥瓑!"); + return L; + } + + String tmp; + if (date1.compareTo(date2) > 0) { // 纭繚 date1鐨勬棩鏈熶笉鏅氫簬date2 + tmp = date1; + date1 = date2; + date2 = tmp; + } + + tmp = format.format(str2Date(date1).getTime() + 3600 * 24 * 1000); + + int num = 0; + while (tmp.compareTo(date2) < 0) { + L.add(tmp); + num++; + tmp = format.format(str2Date(tmp).getTime() + 3600 * 24 * 1000); + } + + if (num == 0) + System.out.println("涓や釜鏃ユ湡鐩搁偦!"); + return L; + } + + private static Date str2Date(String str) { + if (str == null) + return null; + + try { + return format.parse(str); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + + + /** + * 鑾峰彇涓昏〃鏁版嵁 + * + * @param requestInfo + * @return + */ + private static Map getMainInfo(RequestInfo requestInfo) { + Map map = new HashMap(); + Property[] property = requestInfo.getMainTableInfo().getProperty(); + for (int i = 0; i < property.length; i++) { + map.put(property[i].getName().toLowerCase(), Util.null2String(property[i].getValue())); + } + return map; + } + + /** + * 鎻愪緵绮剧‘鐨勪箻娉曡繍绠椼 + * + * @param v1 琚姞鏁 + * @param v2 鍔犳暟 + * @return 涓や釜鍙傛暟鐨勫拰 + */ + public static Double multiply(String v1, String v2) { + BigDecimal b1 = new BigDecimal(v1); + BigDecimal b2 = new BigDecimal(v2); + return b1.multiply(b2).doubleValue(); + } + + /** + * 鎻掑叆璇峰亣鎷嗗垎琛 + * + * @param requestid + * @param userid + * @param fromDate + * @param MaxHours + */ + private static void insertLeave(String requestid, Integer userid, String fromDate, Double MaxHours, String durationrule, String newleavetype, String subcompany, String department, String toDate, String wfid, String tablename) { + BaseBean bb = new BaseBean(); + //鎻掑叆鍔犵彮鏃堕棿 + RecordSet rsInsert = new RecordSet(); + String sql = "insert into kq_flow_split_evection (requestid,resourceid,fromdate,fromtime,todate,totime,duration,durationrule,belongdate,newleavetype,subcompanyid,departmentid,workflowid,tablenamedb) " + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + rsInsert.executeUpdate(sql, requestid, userid, fromDate, "08:00", toDate, "17:00", MaxHours, durationrule, fromDate, newleavetype, subcompany, department, wfid, tablename); + bb.writeLog("insertSql:" + sql); + } +}