|
|
@@ -0,0 +1,237 @@
|
|
|
+package com.kingdee.eas.hr.ats.function;
|
|
|
+
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import com.kingdee.bos.BOSException;
|
|
|
+import com.kingdee.bos.Context;
|
|
|
+import com.kingdee.eas.common.EASBizException;
|
|
|
+import com.kingdee.eas.hr.ats.*;
|
|
|
+import com.kingdee.eas.hr.ats.app.formula.calculate.data.Tools;
|
|
|
+import com.kingdee.eas.util.app.DbUtil;
|
|
|
+import com.kingdee.jdbc.rowset.IRowSet;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+
|
|
|
+import java.sql.SQLException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * description: TyphoonWorkTimeFunction <br>
|
|
|
+ * date: 2025/8/5 10:57 <br>
|
|
|
+ * author: lhbj <br>
|
|
|
+ * version: 1.0 <br>
|
|
|
+ */
|
|
|
+
|
|
|
+//台风应上班时数= max(0,min(一段班次下班时间,台风结束时间)-max(一段班次上班时间,台风开始时间))
|
|
|
+// + max(0,min(二段班次下班时间,台风结束时间)-max(二段班次上班时间,台风开始时间))
|
|
|
+// + max(0,min(三段班次下班时间,台风结束时间)-max(三段班次上班时间,台风开始时间))
|
|
|
+//
|
|
|
+//台风实际上班时数= max(0,min(一段班次下班打卡时间,台风结束时间)-max(一段班次上班打卡时间,台风开始时间))
|
|
|
+// + max(0,min(二段班次下班打卡时间,台风结束时间)-max(二段班次上班打卡时间,台风开始时间))
|
|
|
+// + max(0,min(三段班次下班打卡时间,台风结束时间)-max(三段班次上班打卡时间,台风开始时间))
|
|
|
+//台风上班时数= min(台风应上班时数,台风实际上班时数)
|
|
|
+public class TyphoonWorkTimeFunction {
|
|
|
+
|
|
|
+ private SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+
|
|
|
+ public double getTyphoonOtTime(Map paramMap, String workOrOt) throws EASBizException, BOSException {
|
|
|
+
|
|
|
+ String personId = (String) paramMap.get("T_HR_ATS_ATTENDANCERESULT_FPROPOSERID");
|
|
|
+ String currDateStr = (String) paramMap.get("T_HR_ATS_ATTENDANCERESULT_FATTENCEDATE");
|
|
|
+ Map globalMap = (Map) paramMap.get("globalMapKey");
|
|
|
+ System.out.println("personId:" + personId + "currDateStr:" + currDateStr);
|
|
|
+ long TyphoonWordUp = 0;
|
|
|
+ long TyphoonWordDw = 0;
|
|
|
+ double typhoon = 0D;
|
|
|
+ try {
|
|
|
+ Context ctx = Tools.getInstance().getCtx();
|
|
|
+ String sqlTy = "select CFStartTime, CFEndTime from CT_SS_TimeSheetOfTyphoon where to_char(CFEndTime,'yyyy-MM-dd') >= '" + currDateStr + "' and to_char(CFStartTime,'yyyy-MM-dd')<='" + currDateStr + "'";
|
|
|
+ IRowSet rowTy = DbUtil.executeQuery(ctx, sqlTy);
|
|
|
+ Date typhoonStart = null;
|
|
|
+ Date typhoonEnd = null;
|
|
|
+ if (rowTy.next()) {
|
|
|
+ typhoonStart = rowTy.getDate("CFStartTime");
|
|
|
+ typhoonEnd = rowTy.getDate("CFEndTime");
|
|
|
+
|
|
|
+ Map<String,List<PunchCardRecordInfo>> punchCardInfoMap = ((Map<String,List<PunchCardRecordInfo>>) globalMap.get("punchCardInfoMap"));
|
|
|
+
|
|
|
+ System.out.println("punchCardInfoMap.size():" + punchCardInfoMap.size());
|
|
|
+ if (punchCardInfoMap != null && punchCardInfoMap.size() > 0) {
|
|
|
+ List<PunchCardRecordInfo> punchCardInfoList = punchCardInfoMap.get(personId + "_" + currDateStr);
|
|
|
+ PunchCardRecordInfo s2Info = punchCardInfoList.get(punchCardInfoList.size()-1);
|
|
|
+ PunchCardRecordInfo s1Info = punchCardInfoList.get(0);
|
|
|
+ Timestamp s2 = s2Info.getPunchCardTime();
|
|
|
+ Timestamp s1 = s1Info.getPunchCardTime();
|
|
|
+ Map<String, List<AtsOverTimeBillEntryInfo>> atsOverTimeBillObject = (Map) globalMap.get("T_HR_ATS_OverTimeBillEntry");
|
|
|
+ if (atsOverTimeBillObject != null && atsOverTimeBillObject.size() > 0) {
|
|
|
+ List<AtsOverTimeBillEntryInfo> list = (List) atsOverTimeBillObject.get(personId + "_" + currDateStr);
|
|
|
+ AtsOverTimeBillEntryInfo atsBillEntryInfo = null;
|
|
|
+ int listSize = list != null ? list.size() : 0;
|
|
|
+
|
|
|
+ for (int i = 0; i < listSize; ++i) {
|
|
|
+ atsBillEntryInfo = (AtsOverTimeBillEntryInfo) list.get(i);
|
|
|
+ //计算一段班台风时间
|
|
|
+
|
|
|
+ //计算一段班台风时间
|
|
|
+ if (null != s1 && null != s2) {
|
|
|
+
|
|
|
+ TyphoonWordDw +=
|
|
|
+ Math.max(0, Math.min(Math.min(atsBillEntryInfo.getRealEndTime().getTime(), s2.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(atsBillEntryInfo.getRealStartTime().getTime(), s1.getTime()), typhoonStart.getTime()));
|
|
|
+
|
|
|
+ }
|
|
|
+ System.out.println("TyphoonWordDw3:" + TyphoonWordDw);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ typhoon = TyphoonWordDw;
|
|
|
+ System.out.println("typhoon.min:" + typhoon);
|
|
|
+ typhoon = Math.round(typhoon / 60D / 60D) / 1000D;
|
|
|
+ System.out.println("typhoon.toHour:" + typhoon);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return typhoon;
|
|
|
+ }
|
|
|
+
|
|
|
+ public double getTyphoonWorkTime(Map paramMap, String workOrOt) throws EASBizException, BOSException {
|
|
|
+
|
|
|
+ String personId = (String) paramMap.get("T_HR_ATS_ATTENDANCERESULT_FPROPOSERID");
|
|
|
+ String currDateStr = (String) paramMap.get("T_HR_ATS_ATTENDANCERESULT_FATTENCEDATE");
|
|
|
+ Map globalMap = (Map) paramMap.get("globalMapKey");
|
|
|
+ System.out.println("personId:" + personId + "currDateStr:" + currDateStr);
|
|
|
+ long TyphoonWordUp = 0;
|
|
|
+ long TyphoonWordDw = 0;
|
|
|
+ double typhoon = 0D;
|
|
|
+ try {
|
|
|
+ Context ctx = Tools.getInstance().getCtx();
|
|
|
+ String sqlTy = "select CFStartTime, CFEndTime from CT_SS_TimeSheetOfTyphoon where to_char(CFEndTime,'yyyy-MM-dd') >= '" + currDateStr + "' and to_char(CFStartTime,'yyyy-MM-dd')<='" + currDateStr + "'";
|
|
|
+ IRowSet rowTy = DbUtil.executeQuery(ctx, sqlTy);
|
|
|
+ Date typhoonStart = null;
|
|
|
+ Date typhoonEnd = null;
|
|
|
+ if (rowTy.next()) {
|
|
|
+ typhoonStart = rowTy.getDate("CFStartTime");
|
|
|
+ typhoonEnd = rowTy.getDate("CFEndTime");
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, List<ScheduleShiftInfo>> shiftMap = (Map) globalMap.get("T_HR_ATS_ScheduleShift");
|
|
|
+ List<ScheduleShiftInfo> schedulelList = shiftMap != null && shiftMap.size() > 0 ? (List) shiftMap.get(personId + "_" + currDateStr) : null;
|
|
|
+ Map<String, ScheduleShiftItemInfo> scheduleShiftItemMap = Maps.newHashMap();
|
|
|
+
|
|
|
+ int i = 0;
|
|
|
+ int shiftItemSize = 0;
|
|
|
+ ScheduleShiftInfo scheduleShiftInfo = null;
|
|
|
+ ScheduleShiftItemCollection scheduleShiftItemCollection = null;
|
|
|
+ for (int shiftSize = schedulelList != null ? schedulelList.size() : 0; i < shiftSize; ++i) {
|
|
|
+ scheduleShiftInfo = (ScheduleShiftInfo) schedulelList.get(i);
|
|
|
+ if (scheduleShiftInfo != null) {
|
|
|
+ scheduleShiftItemCollection = scheduleShiftInfo.getItems();
|
|
|
+ shiftItemSize = scheduleShiftItemCollection.size();
|
|
|
+ ScheduleShiftItemInfo scheduleShiftItemInfo = null;
|
|
|
+
|
|
|
+ for (int j = 0; j < shiftItemSize; ++j) {
|
|
|
+ scheduleShiftItemInfo = scheduleShiftItemCollection.get(j);
|
|
|
+ if (scheduleShiftItemInfo != null) {
|
|
|
+ scheduleShiftItemMap.put(scheduleShiftItemInfo.getSegment().getValue(), scheduleShiftItemInfo);
|
|
|
+ if (null != scheduleShiftItemInfo.getRestNextDateTime() && null != scheduleShiftItemInfo.getRestPreDateTime()) {
|
|
|
+ TyphoonWordUp += (Math.max(0, Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), typhoonEnd.getTime())
|
|
|
+ - Math.max(scheduleShiftItemInfo.getRestNextDateTime().getTime(), typhoonStart.getTime())))
|
|
|
+ +
|
|
|
+ Math.max(0, Math.min(scheduleShiftItemInfo.getRestPreDateTime().getTime(), typhoonEnd.getTime())
|
|
|
+ - Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), typhoonStart.getTime()));
|
|
|
+ } else {
|
|
|
+ TyphoonWordUp += Math.max(0, Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), typhoonEnd.getTime()) - Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), typhoonStart.getTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("TyphoonWordUp:" + TyphoonWordUp);
|
|
|
+ java.sql.Date sqlDate = new java.sql.Date(this.df.parse(currDateStr).getTime());
|
|
|
+ Object[] params = new Object[]{personId, sqlDate};
|
|
|
+ String sql = "select S1,S2,S3,S4,S5,S6 from t_hr_ats_attendanceresult where fproposerid = ? and fattencedate = ?";
|
|
|
+ IRowSet row = DbUtil.executeQuery(ctx, sql, params);
|
|
|
+ System.out.println("row.size():" + row.size());
|
|
|
+ while (row.next()) {
|
|
|
+ Timestamp s6 = row.getTimestamp("S6");
|
|
|
+ Timestamp s5 = row.getTimestamp("S5");
|
|
|
+ Timestamp s4 = row.getTimestamp("S4");
|
|
|
+ Timestamp s3 = row.getTimestamp("S3");
|
|
|
+ Timestamp s2 = row.getTimestamp("S2");
|
|
|
+ Timestamp s1 = row.getTimestamp("S1");
|
|
|
+ ScheduleShiftItemInfo scheduleShiftItemInfo = null;
|
|
|
+ if(scheduleShiftItemMap.size()>0) {
|
|
|
+ //计算一段班台风时间
|
|
|
+ if (null != s1 && null != s2) {
|
|
|
+ scheduleShiftItemInfo = scheduleShiftItemMap.get("1");
|
|
|
+ if (null != scheduleShiftItemInfo.getRestNextDateTime() && null != scheduleShiftItemInfo.getRestPreDateTime()) {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ (Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s2.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(scheduleShiftItemInfo.getRestNextDateTime().getTime(), typhoonStart.getTime())))
|
|
|
+ +
|
|
|
+ Math.max(0, Math.min(scheduleShiftItemInfo.getRestPreDateTime().getTime(), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s1.getTime()), typhoonStart.getTime()));
|
|
|
+ } else {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s2.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s1.getTime()), typhoonStart.getTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("TyphoonWordDw1:" + TyphoonWordDw);
|
|
|
+ if (null != s3 && null != s4) {
|
|
|
+ scheduleShiftItemInfo = scheduleShiftItemMap.get("2");
|
|
|
+ if (null != scheduleShiftItemInfo.getRestNextDateTime() && null != scheduleShiftItemInfo.getRestPreDateTime()) {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ (Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s4.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(scheduleShiftItemInfo.getRestNextDateTime().getTime(), typhoonStart.getTime())))
|
|
|
+ +
|
|
|
+ Math.max(0, Math.min(scheduleShiftItemInfo.getRestPreDateTime().getTime(), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s3.getTime()), typhoonStart.getTime()));
|
|
|
+ } else {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s4.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s3.getTime()), typhoonStart.getTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("TyphoonWordDw2:" + TyphoonWordDw);
|
|
|
+ if (null != s5 && null != s6) {
|
|
|
+ scheduleShiftItemInfo = scheduleShiftItemMap.get("3");
|
|
|
+ if (null != scheduleShiftItemInfo.getRestNextDateTime() && null != scheduleShiftItemInfo.getRestPreDateTime()) {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ (Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s6.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(scheduleShiftItemInfo.getRestNextDateTime().getTime(), typhoonStart.getTime())))
|
|
|
+ +
|
|
|
+ Math.max(0, Math.min(scheduleShiftItemInfo.getRestPreDateTime().getTime(), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s5.getTime()), typhoonStart.getTime()));
|
|
|
+ } else {
|
|
|
+ TyphoonWordDw +=
|
|
|
+ Math.max(0, Math.min(Math.min(scheduleShiftItemInfo.getNextDateTime().getTime(), s6.getTime()), typhoonEnd.getTime())
|
|
|
+ - Math.max(Math.max(scheduleShiftItemInfo.getPreDateTime().getTime(), s5.getTime()), typhoonStart.getTime()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("TyphoonWordDw3:" + TyphoonWordDw);
|
|
|
+ }
|
|
|
+
|
|
|
+ typhoon = Math.min(TyphoonWordDw, TyphoonWordUp);
|
|
|
+ System.out.println("typhoon.min:" + typhoon);
|
|
|
+ typhoon = Math.round(typhoon / 60D / 60D) / 1000D;
|
|
|
+ System.out.println("typhoon.toHour:" + typhoon);
|
|
|
+ }
|
|
|
+ } catch (BOSException var18) {
|
|
|
+ var18.printStackTrace();
|
|
|
+ } catch (SQLException var19) {
|
|
|
+ var19.printStackTrace();
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+
|
|
|
+ }
|
|
|
+ return typhoon;
|
|
|
+ }
|
|
|
+}
|