From 6efd593e654ee477adab949a28a6e420b0fd779f Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Tue, 13 May 2025 18:20:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E7=BE=8E=E5=85=89=E8=80=83=E5=8B=A4?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=AC=AC=E4=B8=80=E6=AC=A1=E6=8B=89=E5=8F=96?= =?UTF-8?q?svn=20=E4=B8=8D=E5=81=9A=E5=90=8E=E7=BB=AD=E5=A4=87=E6=A1=88?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/artifacts/weaver_develop_jar.xml | 2 +- src/com/engine/kq/biz/KQFlowDataBiz.java | 861 ++++ src/com/engine/kq/biz/KQHolidaySetBiz.java | 499 +++ .../engine/kq/biz/KQOverTimeRuleCalBiz.java | 3094 +++++++++++++++ .../engine/kq/cmd/group/GetGroupFormCmd.java | 979 +++++ src/com/engine/kq/cmd/group/SaveGroupCmd.java | 618 +++ .../cmd/holidaySet/GetHolidaySetFormCmd.java | 238 ++ .../myattendance/GetHrmKQReportInfoCmd.java | 446 +++ .../engine/kq/cmd/report/ExportExcelCmd.java | 902 +++++ .../engine/kq/cmd/report/GetKQReportCmd.java | 1010 +++++ .../GetBatchShiftScheduleFromCmd.java | 407 ++ .../kq/cmd/shiftschedule/ImportExcelCmd.java | 630 +++ .../SaveBatchShiftScheduleCmd.java | 475 +++ .../shiftschedule/SaveShiftScheduleCmd.java | 510 +++ .../kq/util/KQDurationCalculatorUtil.java | 692 ++++ .../engine/kq/wfset/util/SplitActionUtil.java | 3487 +++++++++++++++++ 16 files changed, 14849 insertions(+), 1 deletion(-) create mode 100644 src/com/engine/kq/biz/KQFlowDataBiz.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/cmd/group/GetGroupFormCmd.java create mode 100644 src/com/engine/kq/cmd/group/SaveGroupCmd.java create mode 100644 src/com/engine/kq/cmd/holidaySet/GetHolidaySetFormCmd.java create mode 100644 src/com/engine/kq/cmd/myattendance/GetHrmKQReportInfoCmd.java create mode 100644 src/com/engine/kq/cmd/report/ExportExcelCmd.java create mode 100644 src/com/engine/kq/cmd/report/GetKQReportCmd.java create mode 100644 src/com/engine/kq/cmd/shiftschedule/GetBatchShiftScheduleFromCmd.java create mode 100644 src/com/engine/kq/cmd/shiftschedule/ImportExcelCmd.java create mode 100644 src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java create mode 100644 src/com/engine/kq/cmd/shiftschedule/SaveShiftScheduleCmd.java create mode 100644 src/com/engine/kq/util/KQDurationCalculatorUtil.java create mode 100644 src/com/engine/kq/wfset/util/SplitActionUtil.java diff --git a/.idea/artifacts/weaver_develop_jar.xml b/.idea/artifacts/weaver_develop_jar.xml index 6258dfe..2aff103 100644 --- a/.idea/artifacts/weaver_develop_jar.xml +++ b/.idea/artifacts/weaver_develop_jar.xml @@ -1,6 +1,6 @@ - $PROJECT_DIR$/out/artifacts/weaver_develop_jar + $PROJECT_DIR$/../../../../weaver/ecology/WEB-INF/lib diff --git a/src/com/engine/kq/biz/KQFlowDataBiz.java b/src/com/engine/kq/biz/KQFlowDataBiz.java new file mode 100644 index 0000000..d438a68 --- /dev/null +++ b/src/com/engine/kq/biz/KQFlowDataBiz.java @@ -0,0 +1,861 @@ +package com.engine.kq.biz; + +import com.alibaba.fastjson.JSON; +import com.engine.kq.enums.FlowReportTypeEnum; +import com.engine.kq.enums.KqSplitFlowTypeEnum; +import com.engine.kq.wfset.bean.SplitBean; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; + +/** + * 考勤流程数据 相关类 + */ +public class KQFlowDataBiz { + + private String resourceid; + private String fromDate; + private String toDate; + private String fromTime; + private String toTime; + private String belongDate; + private String newLeaveType; + private String orderby_sql; + + public KQFlowDataBiz(FlowDataParamBuilder build){ + this.resourceid = build.resourceid; + this.fromDate = build.fromDate; + this.toDate = build.toDate; + this.fromTime = build.fromTime; + this.toTime = build.toTime; + this.belongDate = build.belongDate; + this.newLeaveType = build.newLeaveType; + this.orderby_sql = build.orderby_sql; + } + + /** + * 获取所有的考勤数据 + * 请假,出差,公出,加班的 + * @param flowMaps + * @param isAll true的时候也返回加班的,false的时候不返回加班的,只返回可以抵扣异常的 + * @return + */ + public List getAllFlowData(Map flowMaps,boolean isAll){ + List allSplitBeans = new ArrayList<>(); + + Map flowDeductCard = getFlowDeductCard(); + + + allSplitBeans.addAll(getEvectionData(flowMaps,flowDeductCard)); + allSplitBeans.addAll(getOutData(flowMaps,flowDeductCard)); + allSplitBeans.addAll(getLeaveData(flowMaps,flowDeductCard)); + if(isAll){ + allSplitBeans.addAll(getOverTimeData(flowMaps)); + } + allSplitBeans.addAll(getOtherData(flowMaps)); + + return allSplitBeans; + } + + /** + * 流程抵扣考勤 + */ + public Map getFlowDeductCard() { + + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + Map flowDeductCard = new HashMap<>(); + + String flowDeductCardSql = "select * from kq_flow_deduct_card t where 1=1 and (isclear is null or isclear<>1) "; + String sqlWhere = sqlFlowCardParamWhere(); + if(sqlWhere.length() > 0){ + flowDeductCardSql += sqlWhere; + } + rs.execute(flowDeductCardSql); + while(rs.next()){ + String requestId= rs.getString("requestId"); + String resourceid= rs.getString("resourceid"); + String signtype= rs.getString("signtype"); + String serialnumber= rs.getString("serialnumber"); + String flowtype= rs.getString("flowtype"); + String key = requestId+"_"+resourceid+"_"+flowtype; + String serial_signtype = serialnumber+"_"+signtype; + if(flowDeductCard.containsKey(key)){ + String tmpSignType = Util.null2String(flowDeductCard.get(key)); + flowDeductCard.put(key, tmpSignType+","+serial_signtype); + }else{ + flowDeductCard.put(key, serial_signtype); + } + } + return flowDeductCard; + } + + /** + * 获取请假相关的数据 + */ + public List getLeaveData(Map flowMaps, + Map flowDeductCard){ + + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + + String tablename = "select * from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" where requestsyncid > 0 "; + +// String tablename = "select a.* from "+KqSplitFlowTypeEnum.LEAVE.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 "; + + String sqlWhere = sqlParamWhere(); + if(sqlWhere.length() > 0){ + tablename += sqlWhere; + } + String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') "; + + if(sqlWhere.length() > 0){ + leaveSql += sqlWhere; + } + List splitBeans = new ArrayList<>(); + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + + rs.executeQuery(tablename); + new BaseBean().writeLog("==leaveSql=="+tablename); + while(rs.next()){ + new BaseBean().writeLog("==zj1=="); + SplitBean splitBean = new SplitBean(); + String requestId= rs.getString("requestid"); + String resourceid= rs.getString("resourceid"); + String fromdate= rs.getString("fromdate"); + String belongdate= rs.getString("belongdate"); + String fromtime= rs.getString("fromtime"); + String todate= rs.getString("todate"); + String totime= rs.getString("totime"); + String newleavetype= rs.getString("newleavetype"); + String duration= rs.getString("duration"); + String durationrule= rs.getString("durationrule"); + String leavebackrequestid= Util.null2String(rs.getString("leavebackrequestid")); + new BaseBean().writeLog("==zj2=="); + + String fromtimedb= rs.getString("fromtimedb"); + String totimedb= rs.getString("totimedb"); + String repeatType = Util.null2String(rs.getString("repeat_type")); + String repeatLate = Util.null2String(rs.getString("repeat_late")); + String repeatEarly = Util.null2String(rs.getString("repeat_early")); + + if(Util.getDoubleValue(duration) <= 0){ + if(repeatType.length() > 0){ + //哺乳假的不需要时长 + }else{ +// continue; + } + } + new BaseBean().writeLog("==zj3=="); + + //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假 + String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2"; + String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.LEAVE.getFlowtype(); + String serial_signtype = ""; + String serial = ""; + String signtype = ""; + if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){ + serial_signtype = Util.null2String(flowDeductCard.get(card_key)); + if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){ + serial = serial_signtype.split("_")[0]; + signtype = serial_signtype.split("_")[1]; + } + } + new BaseBean().writeLog("==zj4=="); + + Map infoMap = new HashMap<>(); + infoMap.put("requestId", requestId); + infoMap.put(newleavetype, duration); + infoMap.put("begintime", fromtime); + infoMap.put("endtime", totime); + infoMap.put("unitType", unitType); + infoMap.put("durationrule", durationrule); + if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){ + infoMap.put("ishalf", "true"); + }else{ + infoMap.put("ishalf", "false"); + } + infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType()); + infoMap.put("newleavetype", newleavetype); + infoMap.put("signtype", signtype); + infoMap.put("serial", serial); + infoMap.put("fromtimedb", fromtimedb); + infoMap.put("totimedb", totimedb); + infoMap.put("repeatType", repeatType); + infoMap.put("repeatLate", repeatLate); + infoMap.put("repeatEarly", repeatEarly); + + String key = resourceid+"|"+belongdate; + String keyRepeat = resourceid+"|"+belongdate+"|repeat"; + new BaseBean().writeLog("==flowMaps=="+ JSON.toJSONString(flowMaps)); + if(flowMaps != null){ + if(flowMaps.get(key) != null){ + if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){ + initArrays = kqTimesArrayComInfo.getInitArr(); + int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime); + Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1); + leavebackrequestid = leavebackrequestid.substring(1); + String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'"; + rs1.executeQuery(backSql); + + while (rs1.next()){ + String back_fromtime = rs1.getString("fromtime"); + String back_totime = rs1.getString("totime"); + if(repeatType.length() > 0){ + //如果是哺乳假似的重复校验,不需要考虑时间 + back_fromtime = fromtime; + back_totime = totime; + } + String back_duration= rs.getString("duration"); + if(Util.getDoubleValue(back_duration) <= 0){ +// continue; + } + if(back_fromtime.equalsIgnoreCase(fromtime)){ + Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1); + }else{ + Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1); + } + } + List> backLists = new ArrayList<>(); + List backList = new ArrayList<>(); + for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){ + if(initArrays[i] == 1){ + backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i)); + }else{ + if(!backList.isEmpty()){ + backLists.add(backList); + backList = new ArrayList<>(); + }else{ + continue; + } + } + } + if(!backList.isEmpty()){ + backLists.add(backList); + } + if(backLists != null && !backLists.isEmpty()){ + List> time_list_tmp = (List>)flowMaps.get(key); + for(int j = 0 ; j < backLists.size() ;j++){ + List backListTmp = backLists.get(j); + String back_tmp_fromtime = backListTmp.get(0); + String back_tmp_totime = backListTmp.get(backListTmp.size()-1); + infoMap = new HashMap<>(); + infoMap.put("requestId", requestId); + infoMap.put(newleavetype, duration); + infoMap.put("begintime", back_tmp_fromtime); + infoMap.put("endtime", back_tmp_totime); + infoMap.put("unitType", unitType); + infoMap.put("durationrule", durationrule); + if("2".equals(durationrule)){ + infoMap.put("ishalf", "true"); + } + infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType()); + infoMap.put("newleavetype", newleavetype); + infoMap.put("repeatType", repeatType); + infoMap.put("repeatLate", repeatLate); + infoMap.put("repeatEarly", repeatEarly); + time_list_tmp.add(infoMap); + } + if(repeatType.length() > 0) { + if (flowMaps.containsKey(keyRepeat)) { + List> time_list_tmp1 = (List>)flowMaps.get(keyRepeat); + time_list_tmp1.add(infoMap); + } + } + } + }else{ + List> time_list_tmp = (List>)flowMaps.get(key); + time_list_tmp.add(infoMap); + } + }else{ + if(leavebackrequestid.length() > 0 && leavebackrequestid.startsWith(",")){ + initArrays = kqTimesArrayComInfo.getInitArr(); + int fromTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(fromtime); + int toTimeIndex = kqTimesArrayComInfo.getArrayindexByTimes(totime); + Arrays.fill(initArrays, fromTimeIndex, toTimeIndex+1, 1); + leavebackrequestid = leavebackrequestid.substring(1); + String backSql = "select * from "+KqSplitFlowTypeEnum.LEAVEBACK.getTablename()+" where "+Util.getSubINClause(leavebackrequestid, "requestid", "in")+" and fromdate= '"+fromdate+"'"; + rs1.executeQuery(backSql); + + while (rs1.next()){ + String back_fromtime = rs1.getString("fromtime"); + String back_totime = rs1.getString("totime"); + if(repeatType.length() > 0){ + //如果是哺乳假似的重复校验,不需要考虑时间 + back_fromtime = fromtime; + back_totime = totime; + } + if(back_fromtime.equalsIgnoreCase(fromtime)){ + Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime), kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1); + }else{ + if(back_fromtime.compareTo(back_totime) < 0){ + Arrays.fill(initArrays, kqTimesArrayComInfo.getArrayindexByTimes(back_fromtime)+1, kqTimesArrayComInfo.getArrayindexByTimes(back_totime)+1, -1); + } + } + } + List> backLists = new ArrayList<>(); + List backList = new ArrayList<>(); + for(int i = fromTimeIndex ; i <= toTimeIndex ; i ++){ + if(initArrays[i] == 1){ + backList.add(kqTimesArrayComInfo.getTimesByArrayindex(i)); + }else{ + if(!backList.isEmpty()){ + backLists.add(backList); + backList = new ArrayList<>(); + }else{ + continue; + } + } + } + if(!backList.isEmpty()){ + backLists.add(backList); + } + if(backLists != null && !backLists.isEmpty()){ + List> time_list = new ArrayList<>(); + for(int j = 0 ; j < backLists.size() ;j++){ + List backListTmp = backLists.get(j); + String back_tmp_fromtime = backListTmp.get(0); + String back_tmp_totime = backListTmp.get(backListTmp.size()-1); + infoMap = new HashMap<>(); + infoMap.put("requestId", requestId); + infoMap.put(newleavetype, duration); + infoMap.put("begintime", back_tmp_fromtime); + infoMap.put("endtime", back_tmp_totime); + infoMap.put("unitType", unitType); + infoMap.put("durationrule", durationrule); + if("2".equals(durationrule)){ + infoMap.put("ishalf", "true"); + } + infoMap.put("flowtype", FlowReportTypeEnum.LEAVE.getFlowType()); + infoMap.put("newleavetype", newleavetype); + infoMap.put("repeatType", repeatType); + infoMap.put("repeatLate", repeatLate); + infoMap.put("repeatEarly", repeatEarly); + time_list.add(infoMap); + } + flowMaps.put(key, time_list); + if(repeatType.length() > 0){ + //单独存一份哺乳假的重复校验 + flowMaps.put(keyRepeat, time_list); + } + } + }else{ + new BaseBean().writeLog("==infoMap=="+JSON.toJSONString(infoMap)); + List> time_list = new ArrayList<>(); + time_list.add(infoMap); + flowMaps.put(key, time_list); + if(repeatType.length() > 0){ + //单独存一份哺乳假的重复校验 + flowMaps.put(keyRepeat, time_list); + } + } + } + } + } + return splitBeans; + } + + /** + * 获取出差相关的数据 + */ + public List getEvectionData(Map flowMaps, + Map flowDeductCard){ + + RecordSet rs = new RecordSet(); + String tablename = "select a.* from "+KqSplitFlowTypeEnum.EVECTION.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 "; + String sqlWhere = sqlParamWhere(); + if(sqlWhere.length() > 0){ + tablename += sqlWhere; + } + String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') "; + + if(sqlWhere.length() > 0){ + leaveSql += sqlWhere; + } + + List splitBeans = new ArrayList<>(); + rs.execute(leaveSql); + while(rs.next()){ + SplitBean splitBean = new SplitBean(); + String requestId= rs.getString("requestId"); + String resourceid= rs.getString("resourceid"); + String fromdate= rs.getString("fromdate"); + String belongdate= rs.getString("belongdate"); + String fromtime= rs.getString("fromtime"); + String todate= rs.getString("todate"); + String totime= rs.getString("totime"); + String newleavetype= rs.getString("newleavetype"); + String duration= rs.getString("duration"); + String durationrule= rs.getString("durationrule"); + + splitBean.setRequestId(requestId); + splitBean.setResourceId(resourceid); + splitBean.setFromDate(fromdate); + splitBean.setFromTime(fromtime); + splitBean.setToDate(todate); + splitBean.setToTime(totime); + splitBean.setNewLeaveType(newleavetype); + splitBean.setDuration(duration); + splitBean.setDurationrule(durationrule); + splitBeans.add(splitBean); + + if(Util.getDoubleValue(duration) <= 0){ +// continue; + } + //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假 + String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2"; + String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.EVECTION.getFlowtype(); + String serial_signtype = ""; + String serial = ""; + String signtype = ""; + if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){ + serial_signtype = Util.null2String(flowDeductCard.get(card_key)); + if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){ + serial = serial_signtype.split("_")[0]; + signtype = serial_signtype.split("_")[1]; + } + } + + Map infoMap = new HashMap<>(); + infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration); + infoMap.put("requestId", requestId); + infoMap.put("begintime", fromtime); + infoMap.put("endtime", totime); + infoMap.put("unitType", unitType); + infoMap.put("durationrule", durationrule); + if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){ + infoMap.put("ishalf", "true"); + }else{ + infoMap.put("ishalf", "false"); + } + infoMap.put("duration", duration); + infoMap.put("flowtype", FlowReportTypeEnum.EVECTION.getFlowType()); + infoMap.put("signtype", signtype); + infoMap.put("serial", serial); + + String key = resourceid+"|"+belongdate; + if(flowMaps != null){ + if(flowMaps.get(key) != null){ + List> time_list_tmp = (List>)flowMaps.get(key); + time_list_tmp.add(infoMap); + }else{ + List> time_list = new ArrayList<>(); + time_list.add(infoMap); + flowMaps.put(key, time_list); + } + } + + } + return splitBeans; + } + + /** + * 获取公出相关的数据 + */ + public List getOutData(Map flowMaps, + Map flowDeductCard){ + + RecordSet rs = new RecordSet(); + String tablename = "select a.* from "+KqSplitFlowTypeEnum.OUT.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 "; + String sqlWhere = sqlParamWhere(); + if(sqlWhere.length() > 0){ + tablename += sqlWhere; + } + String leaveSql = "select * from ("+tablename+") t where 1=1 and (status is null or status <> '1') "; + + if(sqlWhere.length() > 0){ + leaveSql += sqlWhere; + } + List splitBeans = new ArrayList<>(); + rs.execute(leaveSql); + while(rs.next()){ + SplitBean splitBean = new SplitBean(); + String requestId= rs.getString("requestId"); + String resourceid= rs.getString("resourceid"); + String fromdate= rs.getString("fromdate"); + String belongdate= rs.getString("belongdate"); + String fromtime= rs.getString("fromtime"); + String todate= rs.getString("todate"); + String totime= rs.getString("totime"); + String newleavetype= rs.getString("newleavetype"); + String duration= rs.getString("duration"); + String durationrule= rs.getString("durationrule"); + + splitBean.setRequestId(requestId); + splitBean.setResourceId(resourceid); + splitBean.setFromDate(fromdate); + splitBean.setFromTime(fromtime); + splitBean.setToDate(todate); + splitBean.setToTime(totime); + splitBean.setNewLeaveType(newleavetype); + splitBean.setDuration(duration); + splitBean.setDurationrule(durationrule); + splitBeans.add(splitBean); + + if(Util.getDoubleValue(duration) <= 0){ +// continue; + } + //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假 + String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2"; + String card_key = requestId+"_"+resourceid+"_"+KqSplitFlowTypeEnum.OUT.getFlowtype(); + String serial_signtype = ""; + String serial = ""; + String signtype = ""; + if(!flowDeductCard.isEmpty() && flowDeductCard.containsKey(card_key)){ + serial_signtype = Util.null2String(flowDeductCard.get(card_key)); + if(serial_signtype.split("_") != null && serial_signtype.split("_").length == 2){ + serial = serial_signtype.split("_")[0]; + signtype = serial_signtype.split("_")[1]; + } + } + + Map infoMap = new HashMap<>(); + infoMap.put(FlowReportTypeEnum.officialBusiness.getFlowType(), duration); + infoMap.put("requestId", requestId); + infoMap.put("begintime", fromtime); + infoMap.put("endtime", totime); + infoMap.put("unitType", unitType); + infoMap.put("durationrule", durationrule); + if("2".equals(durationrule) && Util.getDoubleValue(duration)<1){ + infoMap.put("ishalf", "true"); + }else{ + infoMap.put("ishalf", "false"); + } + infoMap.put("duration", duration); + infoMap.put("flowtype", FlowReportTypeEnum.OUT.getFlowType()); + infoMap.put("signtype", signtype); + infoMap.put("serial", serial); + + String key = resourceid+"|"+belongdate; + if(flowMaps != null){ + if(flowMaps.get(key) != null){ + List> time_list_tmp = (List>)flowMaps.get(key); + time_list_tmp.add(infoMap); + }else{ + List> time_list = new ArrayList<>(); + time_list.add(infoMap); + flowMaps.put(key, time_list); + } + } + + } + return splitBeans; + } + + /** + * 获取加班相关的数据 + */ + public List getOverTimeData(Map flowMaps){ + + RecordSet rs = new RecordSet(); + String tablename = "select a.* from "+KqSplitFlowTypeEnum.OVERTIME.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 "; + String sqlWhere = sqlParamWhere(); + if(sqlWhere.length() > 0){ + tablename += sqlWhere; + } + String leaveSql = "select * from ("+tablename+") t where 1=1 "; + + if(sqlWhere.length() > 0){ + leaveSql += sqlWhere; + } + List splitBeans = new ArrayList<>(); + if(orderby_sql.length() > 0){ + leaveSql = leaveSql+orderby_sql; + } + rs.execute(leaveSql); + while(rs.next()){ + SplitBean splitBean = new SplitBean(); + String dataid= rs.getString("dataid"); + String detailid= rs.getString("detailid"); + String requestId= rs.getString("requestId"); + String resourceid= rs.getString("resourceid"); + String fromdate= rs.getString("fromdate"); + String belongdate= rs.getString("belongdate"); + String fromtime= rs.getString("fromtime"); + String todate= rs.getString("todate"); + String totime= rs.getString("totime"); + String newleavetype= rs.getString("newleavetype"); + String duration= rs.getString("duration"); + String durationrule= rs.getString("durationrule"); + String changetype= rs.getString("changetype"); + String d_mins= rs.getString("d_mins"); + String overtime_type= rs.getString("overtime_type"); + + String fromdatedb= rs.getString("fromdatedb"); + String fromtimedb= rs.getString("fromtimedb"); + String todatedb= rs.getString("todatedb"); + String totimedb= rs.getString("totimedb"); + + splitBean.setDataId(dataid); + splitBean.setDetailId(detailid); + splitBean.setRequestId(requestId); + splitBean.setResourceId(resourceid); + splitBean.setFromDate(fromdate); + splitBean.setFromTime(fromtime); + splitBean.setToDate(todate); + splitBean.setToTime(totime); + splitBean.setNewLeaveType(newleavetype); + splitBean.setDuration(duration); + splitBean.setDurationrule(durationrule); + splitBean.setChangeType(Util.getIntValue(changetype)); + splitBean.setD_Mins(Util.getDoubleValue(d_mins)); + splitBean.setOvertime_type(overtime_type); + splitBean.setFromdatedb(fromdatedb); + splitBean.setFromtimedb(fromtimedb); + splitBean.setTodatedb(todatedb); + splitBean.setTotimedb(totimedb); + splitBeans.add(splitBean); + + //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假 + String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2"; + unitType = "2".equalsIgnoreCase(durationrule)?"1":"2"; + + Map infoMap = new HashMap<>(); + infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration); + infoMap.put("begintime", fromtime); + infoMap.put("endtime", totime); + infoMap.put("unitType", unitType); + infoMap.put("duration", duration); + infoMap.put("flowtype", FlowReportTypeEnum.OVERTIME.getFlowType()); + + String key = resourceid+"|"+belongdate; + if(flowMaps != null){ + if(flowMaps.get(key) != null){ + List> time_list_tmp = (List>)flowMaps.get(key); + time_list_tmp.add(infoMap); + }else{ + List> time_list = new ArrayList<>(); + time_list.add(infoMap); + flowMaps.put(key, time_list); + } + } + } + return splitBeans; + } + + /** + * 获取异常流程的数据 + */ + public List getOtherData(Map flowMaps){ + + RecordSet rs = new RecordSet(); + String tablename = "select a.* from "+KqSplitFlowTypeEnum.OTHER.getTablename()+" a left join workflow_requestbase b on a.requestid = b.requestid where b.requestid > 0 "; + String sqlWhere = sqlParamWhere(); + if(sqlWhere.length() > 0){ + tablename += sqlWhere; + } + String leaveSql = "select * from ("+tablename+") t where 1=1 "; + + if(sqlWhere.length() > 0){ + leaveSql += sqlWhere; + } + List splitBeans = new ArrayList<>(); + rs.execute(leaveSql); + while(rs.next()){ + SplitBean splitBean = new SplitBean(); + String requestId= rs.getString("requestId"); + String resourceid= rs.getString("resourceid"); + String fromdate= rs.getString("fromdate"); + String belongdate= rs.getString("belongdate"); + String fromtime= rs.getString("fromtime"); + String todate= rs.getString("todate"); + String totime= rs.getString("totime"); + String newleavetype= rs.getString("newleavetype"); + String duration= rs.getString("duration"); + String durationrule= rs.getString("durationrule"); + + splitBean.setRequestId(requestId); + splitBean.setResourceId(resourceid); + splitBean.setFromDate(fromdate); + splitBean.setFromTime(fromtime); + splitBean.setToDate(todate); + splitBean.setToTime(totime); + splitBean.setNewLeaveType(newleavetype); + splitBean.setDuration(duration); + splitBean.setDurationrule(durationrule); + splitBeans.add(splitBean); + + //计算规则 1-按天请假 2-按半天请假 3-按小时请假 4-按整天请假 + String unitType = "4".equalsIgnoreCase(durationrule)?"1":"2"; + + Map infoMap = new HashMap<>(); + infoMap.put(FlowReportTypeEnum.businessLeave.getFlowType(), duration); + infoMap.put("begintime", fromtime); + infoMap.put("endtime", totime); + infoMap.put("unitType", unitType); + + String key = resourceid+"|"+belongdate; + if(flowMaps != null){ + if(flowMaps.get(key) != null){ + List> time_list_tmp = (List>)flowMaps.get(key); + time_list_tmp.add(infoMap); + }else{ + List> time_list = new ArrayList<>(); + time_list.add(infoMap); + flowMaps.put(key, time_list); + } + } + } + return splitBeans; + } + + /** + * 根据请假类型判断是否被流程引用 + * @param ruleid + * @return true表示被引用 + */ + public static boolean leaveTypeUsed(String ruleid){ + KQFlowDataBiz kqFlowDataBiz = new FlowDataParamBuilder().newLeaveTypeParam(ruleid).build(); + List splitBeans = kqFlowDataBiz.getLeaveData(null, new HashMap<>()); + if(!splitBeans.isEmpty()){ + return true; + }else{ + return false; + } + } + + /** + * 生成相应的查询条件 + * @return + */ + private String sqlParamWhere() { + String sqlWhere = ""; + if(resourceid.length() > 0){ + sqlWhere += " and resourceid in ( "+resourceid+" )"; + } + if(fromDate.length() > 0 && toDate.length() > 0){ + sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )"; + }else{ + if(fromDate.length() > 0){ + sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' "; + } + if(toDate.length() > 0){ + sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' "; + } + } + if(belongDate.length() > 0){ + sqlWhere += " and belongdate = '"+belongDate+"' "; + } + if(fromTime.length() > 0){ + sqlWhere += " and fromtime >= '"+fromTime+"' "; + } + if(toTime.length() > 0){ + sqlWhere += " and totime <= '"+toTime+"' "; + } + if(newLeaveType.length() > 0){ + sqlWhere += " and newleavetype in ( "+newLeaveType+" )"; + } + return sqlWhere; + } + + private String sqlFlowCardParamWhere() { + String sqlWhere = ""; + if(resourceid.length() > 0){ + sqlWhere += " and resourceid in ( "+resourceid+" )"; + } + if(fromDate.length() > 0 && toDate.length() > 0){ + sqlWhere += " and ( fromdate between '"+fromDate+"' and '"+toDate+"' or todate between '"+fromDate+"' and '"+toDate+"' )"; + }else{ + if(fromDate.length() > 0){ + sqlWhere += " and fromdate between '"+fromDate+"' and '"+fromDate+"' "; + } + if(toDate.length() > 0){ + sqlWhere += " and todate between '"+toDate+"' and '"+toDate+"' "; + } + } + if(belongDate.length() > 0){ + sqlWhere += " and belongdate = '"+belongDate+"' "; + } + if(fromTime.length() > 0){ + sqlWhere += " and fromtime >= '"+fromTime+"' "; + } + if(toTime.length() > 0){ + sqlWhere += " and totime <= '"+toTime+"' "; + } + return sqlWhere; + } + + /** + * 针对可能存在的多种参数类型 创建参数静态内部类Builder + */ + public static class FlowDataParamBuilder { + + private String resourceid = ""; + private String fromDate = ""; + private String toDate = ""; + private String fromTime = ""; + private String toTime = ""; + private String belongDate = ""; + /** + * 请假用的请假类型 + */ + private String newLeaveType = ""; + private String orderby_sql = ""; + + public FlowDataParamBuilder() { + this.resourceid = ""; + //初始化的时候需要把其他参数先清空下 + this.fromDate = ""; + this.toDate = ""; + this.fromTime = ""; + this.toTime = ""; + this.newLeaveType = ""; + this.belongDate = ""; + this.orderby_sql = ""; + } + + //成员方法返回其自身,所以可以链式调用 + public FlowDataParamBuilder resourceidParam(final String resourceid) { + this.resourceid = resourceid; + return this; + } + + public FlowDataParamBuilder fromDateParam(final String fromDate) { + this.fromDate = fromDate; + return this; + } + + public FlowDataParamBuilder toDateParam(final String toDate) { + this.toDate = toDate; + return this; + } + + public FlowDataParamBuilder fromTimeParam(final String fromTime) { + this.fromTime = fromTime; + return this; + } + + public FlowDataParamBuilder toTimeParam(final String toTime) { + this.toTime = toTime; + return this; + } + + public FlowDataParamBuilder newLeaveTypeParam(final String newLeaveType) { + this.newLeaveType = newLeaveType; + return this; + } + + public FlowDataParamBuilder belongDateParam(final String belongDate) { + this.belongDate = belongDate; + return this; + } + + public FlowDataParamBuilder orderby_sqlParam(final String orderby_sql) { + this.orderby_sql = orderby_sql; + return this; + } + + //Builder的build方法,返回外部类的实例 + public KQFlowDataBiz build() { + return new KQFlowDataBiz(this); + } + } +} diff --git a/src/com/engine/kq/biz/KQHolidaySetBiz.java b/src/com/engine/kq/biz/KQHolidaySetBiz.java new file mode 100644 index 0000000..f3560aa --- /dev/null +++ b/src/com/engine/kq/biz/KQHolidaySetBiz.java @@ -0,0 +1,499 @@ +package com.engine.kq.biz; + +import com.engine.integration.util.MyX509TrustManager; +import com.engine.kq.log.KQLog; +import net.sf.json.JSONObject; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.file.Prop; +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.*; + +/** + * 节假日设置相关接口数据 + */ +public class KQHolidaySetBiz { + + private static KQLog logger = new KQLog(); + + /** + * 获取指定考勤组ID获取节假日设置数据 + * + * @param resourceId 指定人员的ID + * @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; + } + + /** + * 获取指定考勤组ID获取节假日设置数据 + * + * @param resourceId 指定人员的ID + * @param year 指定年份 + * @param month 指定月份 指定月份为空时查询指定年份一整年的数据 + * @return + */ + public static List getKQHolidaySetList(String resourceId, String year, String month) { + + 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 指定人员的ID + * @param startDate 指定日期范围的起点 + * @param endDate 指定日期范围的终点 + * @return + */ + public static List getHolidaySetListByScope(String resourceId, String startDate, String endDate) { + Map valueMap = new HashMap(); + List> valueList = new ArrayList>(); + + + 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("")&&!getWorkDay(resourceId, date)) { + 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-节假日、false、不是节假日 + */ + public static boolean isHoliday(String resourceId, String date) { + return isHoliday(resourceId, date, false); + } + + /** + * 判断某天是否是节假日(公众假日+调配休息日+周末) + * + * @param resourceId 指定人员ID + * @param date 指定日期 + * @param containWeekend 是否包含周末 为true包含周末、false不包含 + * @return true-节假日、false、不是节假日 + */ + public static boolean isHoliday(String resourceId, String date, boolean containWeekend) { + boolean flag = false; + if(getWorkDay(resourceId, date)){ + return flag; + } + /*获取考勤组的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 resourceId 指定人员ID + * @param date 指定日期 + * @return true-节假日、false、不是节假日 + */ + public static boolean isDouble(String resourceId, String date) { + boolean flag = false; + /*获取考勤组的ID,因为考勤组有有效期,所以需要传入日期*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date); + + int changeType = getChangeType(groupId, date); + if (changeType == 1 || changeType == 3) { + flag = true; + } + return flag; + } + + /** + * 获取人员指定日期是否有排班的考勤排班:(当考勤组属于排班制时) + * + * @param resourceId 指定人员的ID + * @param date 指定日期 + * @return + */ + public static boolean getWorkDay(String resourceId, String date) { + boolean flag = false; + /*获取考勤组的ID,因为考勤组有有效期,所以需要传入日期*/ + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + String groupId = kqGroupMemberComInfo.getKQGroupId(resourceId, date); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String holiday_is_priority = Util.null2String(kqSettingsComInfo.getMain_val("holiday_is_priority"),"0"); + if("0".equals(holiday_is_priority)) { + return flag; + } + /*排班制不支持调配节假日数据*/ + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + String KQType = kqGroupComInfo.getKqtype(groupId);//考勤类型:1-固定班制、2-排班制、3-自由班制 + if (KQType.equals("2")) { + flag = true; + } + return flag; + } + /** + * 获取当前日期是何种类型(这里只考虑节假日设置) + * + * @param groupId 考勤组ID + * @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(); + String tmpChangetype = kqHolidaySetComInfo.getChangeType(groupId, date); + if(null != tmpChangetype){ + changeType = Util.getIntValue(tmpChangetype, -1); + } + + return changeType; + } + + /** + * 获取调配工作日时的指定工作日(当考勤组不属于排班制时) + * + * @param resourceId 指定人员的ID + * @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 指定考勤组ID(多个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, ",");//考勤组ID集合 + 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(); + + if(holidayList.size()>0){ + String tmpsql = "delete from kq_HolidaySet where groupId='"+groupId+"' and holidayDate>='"+year+"-01-01' and holidayDate<='"+year+"-12-31' "; + recordSet.executeUpdate(tmpsql); + } + + 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("初始化节假日数据,格式化考勤报表。groupIdList=" + com.alibaba.fastjson.JSONObject.toJSONString(groupIds) + + "。holidayDateList=" + com.alibaba.fastjson.JSONObject.toJSONString(holidayDateList)); + List groupIdList = Util.TokenizerString(groupIds, ",");//考勤组ID集合 + new KQHolidaySetThread(groupIdList,holidayDateList).start(); + } + return resultMap; + } + + /** + * 请求网络上的节假日API接口,获取节假日设置数据 + * + * @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); + + //将bufferReader的值给放到buffer里 + String str = null; + while ((str = bufferedReader.readLine()) != null) { + buffer.append(str); + } + //关闭bufferReader和输入流 + bufferedReader.close(); + inputStreamReader.close(); + inputStream.close(); + inputStream = null; + //断开连接 + httpUrlConn.disconnect(); + + /** + * 解析JSON字符串 + */ + String jsonStr = buffer.toString(); + JSONObject jsonObject = JSONObject.fromObject(jsonStr).getJSONObject("data"); + int code = jsonObject.optInt("code");//0服务正常。-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..053a547 --- /dev/null +++ b/src/com/engine/kq/biz/KQOverTimeRuleCalBiz.java @@ -0,0 +1,3094 @@ +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.jucailin.util.KQDateUtil; +import com.engine.kq.log.KQLog; +import com.engine.kq.timer.KQOvertimeCardBean; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.KQLockAttendaUtil; +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 org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.file.Prop; +import weaver.general.Util; +import weaver.hrm.resource.ResourceComInfo; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.sql.Timestamp; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Collectors; + +/** + * 根据加班规则计算加班和调休数据 + * 主要是针对 流程+打卡 打卡 这几种方式 + */ +public class KQOverTimeRuleCalBiz { + private KQLog kqLog = new KQLog(); + + private static final String LOCK_DEGREE = Util.null2String(Prop.getPropValue("kqLockAttenda", "LOCK_DEGREE")); + + /** + * 生成加班数据 + * + * @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"); + + 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 main_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; + // 强控 + if (LOCK_DEGREE.equals("1")&&new KQLockAttendaUtil().checkLockStatus(resourceid, splitDate)) { + kqLog.info("锁定程度强控:人员考勤数据已被锁定,"+"userId:"+resourceid+":kqDate:"+splitDate); + continue; + } + + + String nextDate = DateUtil.addDate(splitDate, 1); + Map overtimeLogMap = Maps.newLinkedHashMap(); + Map eventMap = Maps.newLinkedHashMap(); + //加班日志记录类 + 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); + String uuid = kqEventLogBiz.logDetailWorkTimeEntity(resourceid, workTimeEntityLogMap, main_uuid, "doComputingMode|加班打卡|key|" + key); + + try { + Map lsCheckInfoMaps = Maps.newLinkedHashMap(); + //获取加班打卡数据 + + getOverTimeCardDataMap(resourceid, splitDate, splitDate, dateFormatter, kqTimesArrayComInfo, overRulesDetailMap, changeTypeMap, lsCheckInfoMaps, eventMap); + Map nextLsCheckInfoMaps = Maps.newLinkedHashMap(); + Map nextEventMap = Maps.newLinkedHashMap(); + getOverTimeCardDataMap(resourceid, nextDate, nextDate, dateFormatter, kqTimesArrayComInfo, overRulesDetailMap, changeTypeMap, nextLsCheckInfoMaps, nextEventMap); + eventMap.put("nextEventMap", JSON.toJSONString(nextEventMap)); + if (MapUtils.isNotEmpty(nextLsCheckInfoMaps)) { + for (Map.Entry nextBean : nextLsCheckInfoMaps.entrySet()) { + String nextInTodayKey = nextBean.getKey(); + String[] mapKeys = nextInTodayKey.split("_"); + if (mapKeys.length == 3) { + eventMap.put("nextInBefore", JSON.toJSONString(nextBean)); + lsCheckInfoMaps.put(nextInTodayKey, nextBean.getValue()); + } + } + } + + 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]; + if (mapKeys.length == 3) { + splitDate = mapKeys[2]; + mapKey = resourceid + "_" + realSplitDate; + } + String change_key = realSplitDate + "_" + resourceid; + int changeType = Util.getIntValue("" + changeTypeMap.get(change_key), -1); + String changeType_key = realSplitDate + "_" + changeType; + int computingMode = Util.getIntValue("" + computingModeMap.get(changeType_key), -1); + + boolean isOk = true; +//把原来下面一个方法里的内容要抽出来,是因为存在如下的问题,如果我是跨天打卡,次日3点,加班归属点设置的是次日2点,2-3这部分的是属于第二天的,需要判断下第二天的加班方式是不是doComputingMode2,如果不是就需要去走对应的doComputingMode方法 + if (2 == computingMode) { + isOk = doComputingMode2WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (3 == computingMode) { + isOk = doComputingMode3WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (4 == computingMode) { + isOk = doComputingMode4WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } + if (!isOk) { + continue; + } + } + } catch (Exception e) { + kqLog.info("加班生成数据报错:KQOverTimeRuleCalBiz:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } finally { + kqEventLogBiz.logDetailOvertimeMap(resourceid, overtimeLogMap, uuid); + kqEventLogBiz.logDetailEvent(resourceid, eventMap, uuid, "doComputingMode|对应的加班数据|key|" + key); + } + + } + fromDate = preFromDate.format(dateFormatter); + updateTiaoXiu(resourceid, fromDate, toDate); + } catch (Exception e) { + kqLog.info("加班生成数据报错:KQOverTimeRuleCalBiz:"); + StringWriter errorsWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(errorsWriter)); + kqLog.info(errorsWriter.toString()); + } + } + + + /** + * 更新调休 + * + * @param resourceid + * @param fromDate + * @param toDate + */ + public void updateTiaoXiu(String resourceid, String fromDate, String toDate) { + Timestamp updateDate = KQDateUtil.getUpdateTimeStamp(); + RecordSet recordSet = new RecordSet(); + //假期类型的缓存类 + try { + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + ResourceComInfo resourceComInfo = new ResourceComInfo(); + String subCompanyId = resourceComInfo.getSubCompanyID(resourceid); + String departmentId = resourceComInfo.getDepartmentID(resourceid); + //[调休]的假期类型的ID + String leaveRulesId = ""; + //找到[调休]的假期类型ID + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + if (KQLeaveRulesBiz.isTiaoXiu(rulesComInfo.getId(), subCompanyId, departmentId, resourceid)) { + if ("1".equals(rulesComInfo.getIsEnable())) { + leaveRulesId = rulesComInfo.getId(); + break; + } + } + } + if ("".equals(leaveRulesId) || null == leaveRulesId) { + return; + } + + String sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceid + + " and leaveRulesId=" + leaveRulesId + + " and effectiveDate>='" + fromDate + "' and effectiveDate<='" + toDate + "'" + + " order by belongYear asc,effectiveDate asc,id asc "; + recordSet.executeQuery(sql); + String all_tiaoxiuids = ""; + BigDecimal duration = new BigDecimal("0"); + while (recordSet.next()) { + //额外 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0")); + //加班生成调休 + BigDecimal tiaoxiuAmount = new BigDecimal(Util.null2s(recordSet.getString("tiaoxiuamount"), "0")); + //已休 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0")); + + if (extraAmount.add(tiaoxiuAmount).subtract(usedAmount).doubleValue() >= 0) { + continue; + } + String id = recordSet.getString("id"); + if (id.length() > 0 && Util.getIntValue(id) > 0) { + all_tiaoxiuids += "," + id; + duration = duration.add(extraAmount).add(tiaoxiuAmount).subtract(usedAmount); + } + } + duration = duration.abs(); + List updateList = new ArrayList(); + sql = " select * from kq_balanceOfLeave " + + " where (isDelete is null or isDelete<>1) and resourceId=" + resourceid + + " and leaveRulesId=" + leaveRulesId + + " and effectiveDate>='" + fromDate + "'" + + " order by belongYear asc,effectiveDate asc,id asc "; + recordSet.executeQuery(sql); + int total = recordSet.getCounts(); + int index = 0; + while (recordSet.next()) { + index++; + String id = recordSet.getString("id"); + //额外 + BigDecimal extraAmount = new BigDecimal(Util.null2s(recordSet.getString("extraAmount"), "0")); + //加班生成调休 + BigDecimal tiaoxiuAmount = new BigDecimal(Util.null2s(recordSet.getString("tiaoxiuamount"), "0")); + //已休 + BigDecimal usedAmount = new BigDecimal(Util.null2s(recordSet.getString("usedAmount"), "0")); + + if (extraAmount.add(tiaoxiuAmount).subtract(usedAmount).doubleValue() <= 0) { + continue; + } + BigDecimal temp = extraAmount.add(tiaoxiuAmount).subtract(usedAmount).subtract(duration); + /*该假期剩余假期余额不足以扣减,记录错误日志,退出方法*/ + if (index == total && temp.doubleValue() < 0) { + kqLog.info("该人员的该假期所有的剩余假期余额都不足以扣减。" + + "resourceId=" + resourceid + ",date=" + fromDate + ",ruleId=" + leaveRulesId + ",duration=" + duration + ",extraAmount=" + extraAmount.doubleValue() + ",usedAmount=" + usedAmount.doubleValue()); + String newUsedAmount = usedAmount.add(duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + break; + } + if (temp.doubleValue() >= 0) { + String newUsedAmount = usedAmount.add(duration).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + break; + } else { + duration = duration.add(usedAmount).subtract(extraAmount).subtract(tiaoxiuAmount); + String newUsedAmount = extraAmount.add(tiaoxiuAmount).setScale(5, RoundingMode.HALF_UP).toPlainString(); + String updateSql = "update kq_balanceOfLeave set usedAmount=" + (newUsedAmount) + ", update_time=? where id=" + id; + updateList.add(updateSql); + continue; + } + } + if (all_tiaoxiuids.length() > 0) { + all_tiaoxiuids = all_tiaoxiuids.substring(1); + updateList.add("update kq_balanceOfLeave set isDelete=1, update_time=? where id in (" + all_tiaoxiuids + ")"); + } + kqLog.info("updateList:" + updateList); + /*SQL操作批处理*/ + for (int i = 0; i < updateList.size(); i++) { + boolean flag = recordSet.executeUpdate(updateList.get(i), updateDate); + if (!flag) { + kqLog.info("刷新加班流程数据失败:数据库更新失败"); + return; + } + } + } catch (Exception e) { + recordSet.writeLog(e); + } + } + + /** + * 需审批,以打卡为准,取流程和打卡的交集 + */ + private void doComputingMode4(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, + Map lsCheckInfoMaps) 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(); + + 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; + int computingMode = Util.getIntValue("" + computingModeMap.get(changeType_key), -1); + + boolean isOk = true; +//把原来下面一个方法里的内容要抽出来,是因为存在如下的问题,如果我是跨天打卡,次日3点,加班归属点设置的是次日2点,2-3这部分的是属于第二天的,需要判断下第二天的加班方式是不是doComputingMode2,如果不是就需要去走对应的doComputingMode方法 + if (2 == computingMode) { + isOk = doComputingMode2WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (3 == computingMode) { + isOk = doComputingMode3WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (4 == computingMode) { + isOk = doComputingMode4WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } + if (!isOk) { + continue; + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid, overtimeLogMap, uuid); + kqEventLogBiz.logDetailEvent(resourceid, eventMap, uuid, "doComputingMode4|对应的加班流程数据|key|" + key); + + } + + /** + * 把获取打卡数据后处理的部分拆出来 + */ + private boolean doComputingMode4WithCard(KQOvertimeCardBean kqOvertimeCardBean, String mapKey, String resourceid, Map changeTypeMap, DateTimeFormatter dateFormatter, Map overtimeLogMap, + String splitDate, Map overRulesDetailMap, Map eventMap, KQTimesArrayComInfo kqTimesArrayComInfo, Map> restTimeMap, KQOvertimeLogBiz kqEventLogBiz, String uuid, + String realSplitDate) throws Exception { + + 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; + LocalDate localbelongDate = LocalDate.parse(realSplitDate); + LocalDate preLocalDate = localbelongDate.minusDays(1); + String preSplitDate = preLocalDate.format(dateFormatter); + String preChange_key = preSplitDate + "_" + resourceid; + int preChangeType = Util.getIntValue("" + changeTypeMap.get(preChange_key), -1); + String preChangeType_key = preSplitDate + "_" + preChangeType; + LocalDate nextLocalDate = localbelongDate.plusDays(1); + String nextSplitDate = nextLocalDate.format(dateFormatter); + String nextChange_key = nextSplitDate + "_" + resourceid; + int nextChangeType = Util.getIntValue("" + changeTypeMap.get(nextChange_key), -1); + String nextChangeType_key = nextSplitDate + "_" + nextChangeType; + + 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 + "|" + "加班规则为null|kqOvertimeRulesDetailEntity"); + return false; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if (overtimeEnable != 1) { + String overtimeEnableInfo = "overtimeEnable:" + overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey + "|" + "未开启加班规则|overtimeEnable"); + return false; + } + + 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, preChangeType_key, nextChangeType_key); + 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 false; + } + + 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); + + 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"); + + 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; + int maxMumLen = kqOvertimeRulesDetailEntity.getMaxmumLen(); + if (across_mins > maxMumLen) { + across_mins = maxMumLen; + } + 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); + otherParam.put("changeType", String.valueOf(changeType)); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if (2 == paidLeaveEnableType) { + logOvertimeMap(overtimeLogMap, overtime_type, flow_key + "|关联调休与否来自于流程选择,加班类型下拉框值|overtime_type"); + } + + int paidLeaveEnable = getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type); + + otherParam.put("overtimeLogMap", overtimeLogMap); + logOvertimeMap(overtimeLogMap, across_mins, flow_key + "|最终生成的加班分钟数|overtime_mins"); + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid, realSplitDate, across_mins + "", "0", workingHours, requestid, "1", realSplitDate, otherParam); + if (Util.getIntValue(tiaoxiuId) > 0) { + kqLog.info("doComputingMode4 生成调休成功,调休id:" + tiaoxiuId + ":resourceid:" + resourceid + ":realSplitDate:" + realSplitDate); + } else { + kqLog.info("doComputingMode4 生成调休失败,调休id:" + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + if (rs.getDBType().equals("postgresql")) { + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) "; + } + signinTime = kqTimesArrayComInfo.turn48to24Time(signinTime); + signoutTime = kqTimesArrayComInfo.turn48to24Time(signoutTime); + if (signinTime.length() == 5) { + signinTime = signinTime + ":00"; + } + if (signoutTime.length() == 5) { + signoutTime = signoutTime + ":00"; + } + Long cur = System.currentTimeMillis(); + Timestamp date = new Timestamp(cur); + 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, date, date, Util.getIntValue(resourceid)); + + 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为null", mapKey + "|" + "打卡和上下班数据|KQOvertimeCardBean"); + } + return true; + } + + /** + * 得到有效的打卡区间,这个区间肯定已经是去除了上下班时间和休息时间还有重复打卡的部分 + * + * @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); + } + } + + /** + * 处理加班方式是 无需审批,根据打卡时间计算加班时长 + */ + private void doComputingMode3(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, + Map lsCheckInfoMaps) 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(); + kqEventLogBiz.logDetailEvent(resourceid, eventMap, uuid, "doComputingMode3|对应的打卡数据|key|" + key); + + 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; + int computingMode = Util.getIntValue("" + computingModeMap.get(changeType_key), -1); + + boolean isOk = true; +//把原来下面一个方法里的内容要抽出来,是因为存在如下的问题,如果我是跨天打卡,次日3点,加班归属点设置的是次日2点,2-3这部分的是属于第二天的,需要判断下第二天的加班方式是不是doComputingMode2,如果不是就需要去走对应的doComputingMode方法 + if (2 == computingMode) { + isOk = doComputingMode2WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (3 == computingMode) { + isOk = doComputingMode3WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (4 == computingMode) { + isOk = doComputingMode4WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } + if (!isOk) { + continue; + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid, overtimeLogMap, uuid); + kqEventLogBiz.logDetailEvent(resourceid, eventMap, uuid, "doComputingMode3|对应的加班流程数据|key|" + key); + + + } + + /** + * 把获取打卡数据后处理的部分拆出来 + */ + private boolean doComputingMode3WithCard(KQOvertimeCardBean kqOvertimeCardBean, String mapKey, String resourceid, Map changeTypeMap, DateTimeFormatter dateFormatter, Map overtimeLogMap, + String splitDate, Map overRulesDetailMap, Map eventMap, KQTimesArrayComInfo kqTimesArrayComInfo, Map> restTimeMap, KQOvertimeLogBiz kqEventLogBiz, String uuid, + String realSplitDate) throws Exception { + String change_key = realSplitDate + "_" + resourceid; + int changeType = Util.getIntValue("" + changeTypeMap.get(change_key), -1); + String changeType_key = realSplitDate + "_" + changeType; + LocalDate localbelongDate = LocalDate.parse(realSplitDate); + LocalDate preLocalDate = localbelongDate.minusDays(1); + String preSplitDate = preLocalDate.format(dateFormatter); + String preChange_key = preSplitDate + "_" + resourceid; + int preChangeType = Util.getIntValue("" + changeTypeMap.get(preChange_key), -1); + String preChangeType_key = preSplitDate + "_" + preChangeType; + LocalDate nextLocalDate = localbelongDate.plusDays(1); + String nextSplitDate = nextLocalDate.format(dateFormatter); + String nextChange_key = nextSplitDate + "_" + resourceid; + int nextChangeType = Util.getIntValue("" + changeTypeMap.get(nextChange_key), -1); + String nextChangeType_key = nextSplitDate + "_" + nextChangeType; + + 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 + "|" + "加班规则为null|kqOvertimeRulesDetailEntity"); + return false; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if (overtimeEnable != 1) { + String overtimeEnableInfo = "overtimeEnable:" + overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey + "|" + "未开启加班规则|overtimeEnable"); + return false; + } + if (kqOvertimeCardBean != null) { + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + Map signinoffMap = buildOvertimeCard(kqOvertimeCardBean, resourceid, realSplitDate, kqTimesArrayComInfo, restTimeMap, changeType_key, initArrays, Lists.newArrayList(), overRulesDetailMap, + true, overtimeLogMap, preChangeType_key, nextChangeType_key); + 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) { + return false; + } + 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"); + return false; + } + logOvertimeMap(overtimeLogMap, over_count, mapKey + "|" + "经历过休息时间之后的加班时长|over_rest_count"); + + int mins = over_count; + int maxMumLen = kqOvertimeRulesDetailEntity.getMaxmumLen(); + if (mins > maxMumLen) { + mins = maxMumLen; + } + 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(); + otherParam.put("changeType", String.valueOf(changeType)); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + + int paidLeaveEnable = kqOvertimeRulesDetailEntity.getPaidLeaveEnable(); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + + logOvertimeMap(overtimeLogMap, mins, flow_cross_key + "|最终生成的加班分钟数|overtime_mins"); + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid, realSplitDate, mins + "", "0", workingHours, "", "", realSplitDate, otherParam); + if (Util.getIntValue(tiaoxiuId) > 0) { + kqLog.info("doComputingMode3 生成调休成功,调休id:" + tiaoxiuId + ":resourceid:" + resourceid + ":realSplitDate:" + realSplitDate); + } else { + kqLog.info("doComputingMode3 生成调休失败,调休id:" + tiaoxiuId + ":resourceid:" + resourceid + ":realSplitDate:" + realSplitDate); + } + Long cur = System.currentTimeMillis(); + Timestamp date = new Timestamp(cur); + + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + if (rs.getDBType().equals("postgresql")) { + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) "; + } + 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, date, date, Util.getIntValue(resourceid)); + + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + } else { + logOvertimeMap(overtimeLogMap, "打卡区间不正确|" + flow_cross_key, mapKey + "|" + "打卡区间,得到打卡时长|over_count"); + } + } else { + logOvertimeMap(overtimeLogMap, "打卡数据KQOvertimeCardBean为null", mapKey + "|" + "打卡和上下班数据|KQOvertimeCardBean"); + } + return true; + } + + /** + * 获取生成的加班id + * + * @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); + } + } + } + + /** + * 处理加班方式是 需审批,以打卡为准,但是不能超过审批时长的加班时长 + */ + private void doComputingMode2(String resourceid, String splitDate, + DateTimeFormatter dateFormatter, Map changeTypeMap, + Map overRulesDetailMap, + Map> restTimeMap, Map computingModeMap, + KQTimesArrayComInfo kqTimesArrayComInfo, String main_uuid, + Map lsCheckInfoMaps) 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(); + + 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; + int computingMode = Util.getIntValue("" + computingModeMap.get(changeType_key), -1); + + boolean isOk = true; +//把原来下面一个方法里的内容要抽出来,是因为存在如下的问题,如果我是跨天打卡,次日3点,加班归属点设置的是次日2点,2-3这部分的是属于第二天的,需要判断下第二天的加班方式是不是doComputingMode2,如果不是就需要去走对应的doComputingMode方法 + if (2 == computingMode) { + isOk = doComputingMode2WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (3 == computingMode) { + isOk = doComputingMode3WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } else if (4 == computingMode) { + isOk = doComputingMode4WithCard(kqOvertimeCardBean, mapKey, resourceid, changeTypeMap, + dateFormatter, overtimeLogMap, splitDate, overRulesDetailMap, eventMap, kqTimesArrayComInfo, + restTimeMap, kqEventLogBiz, uuid, realSplitDate); + } + if (!isOk) { + continue; + } + } + kqEventLogBiz.logDetailOvertimeMap(resourceid, overtimeLogMap, uuid); + kqEventLogBiz.logDetailEvent(resourceid, eventMap, uuid, "doComputingMode2|对应的加班流程数据|key|" + key); + + } + + /** + * 把获取打卡数据后处理的部分拆出来 + */ + public boolean doComputingMode2WithCard(KQOvertimeCardBean kqOvertimeCardBean, String mapKey, + String resourceid, Map changeTypeMap, DateTimeFormatter dateFormatter, + Map overtimeLogMap, String splitDate, + Map overRulesDetailMap, + Map eventMap, KQTimesArrayComInfo kqTimesArrayComInfo, + Map> restTimeMap, KQOvertimeLogBiz kqEventLogBiz, String uuid, + String realSplitDate) throws Exception { + String change_key = realSplitDate + "_" + resourceid; + int changeType = Util.getIntValue("" + changeTypeMap.get(change_key), -1); + String changeType_key = realSplitDate + "_" + changeType; + + Map> splitBeanMaps = Maps.newHashMap(); + //获取加班流程数据 + getOverTimeFlowData(resourceid, realSplitDate, realSplitDate, splitBeanMaps, dateFormatter); + LocalDate localbelongDate = LocalDate.parse(realSplitDate); + LocalDate preLocalDate = localbelongDate.minusDays(1); + String preSplitDate = preLocalDate.format(dateFormatter); + String preChange_key = preSplitDate + "_" + resourceid; + int preChangeType = Util.getIntValue("" + changeTypeMap.get(preChange_key), -1); + String preChangeType_key = preSplitDate + "_" + preChangeType; + LocalDate nextLocalDate = localbelongDate.plusDays(1); + String nextSplitDate = nextLocalDate.format(dateFormatter); + String nextChange_key = nextSplitDate + "_" + resourceid; + int nextChangeType = Util.getIntValue("" + changeTypeMap.get(nextChange_key), -1); + String nextChangeType_key = nextSplitDate + "_" + nextChangeType; + + 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 + "|" + "加班规则为null|kqOvertimeRulesDetailEntity"); + return false; + } + int overtimeEnable = kqOvertimeRulesDetailEntity.getOvertimeEnable(); + if (overtimeEnable != 1) { + String overtimeEnableInfo = "overtimeEnable:" + overtimeEnable; + logOvertimeMap(overtimeLogMap, overtimeEnableInfo, mapKey + "|" + "未开启加班规则|overtimeEnable"); + return false; + } + + 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为null", mapKey + "|" + "打卡和上下班数据|KQOvertimeCardBean"); + return false; + } + 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小时,d_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, preChangeType_key, nextChangeType_key); + + 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; + int maxMumLen = kqOvertimeRulesDetailEntity.getMaxmumLen(); + if (mins > maxMumLen) { + mins = maxMumLen; + } + 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); + otherParam.put("changeType", String.valueOf(changeType)); + int paidLeaveEnableType = kqOvertimeRulesDetailEntity.getPaidLeaveEnableType(); + if (2 == paidLeaveEnableType) { + logOvertimeMap(overtimeLogMap, overtime_type, flow_cross_key + "|关联调休与否来自于流程选择,加班类型下拉框值|overtime_type"); + } + + int paidLeaveEnable = getPaidLeaveEnable(kqOvertimeRulesDetailEntity, overtime_type); + + logOvertimeMap(overtimeLogMap, mins, flow_cross_key + "|最终生成的加班时长|mins"); + otherParam.put("overtimeLogMap", overtimeLogMap); + + tiaoxiuId = KQBalanceOfLeaveBiz.addExtraAmountByDis5(resourceid, realSplitDate, mins + "", "0", workingHours, requestid, "1", flow_fromdate, otherParam); + if (Util.getIntValue(tiaoxiuId) > 0) { + kqLog.info("doComputingMode2 生成调休成功,调休id:" + tiaoxiuId + ":resourceid:" + resourceid + ":realSplitDate:" + realSplitDate + ":requestid:" + requestid); + } else { + kqLog.info("doComputingMode2 生成调休失败,调休id:" + tiaoxiuId + ":resourceid:" + resourceid + ":realSplitDate:" + realSplitDate + ":requestid:" + requestid); + } + logOvertimeMap(overtimeLogMap, tiaoxiuId, flow_cross_key + "|最终生成的调休id|tiaoxiuId"); + + Long cur = System.currentTimeMillis(); + Timestamp date = new Timestamp(cur); + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + if (rs.getDBType().equals("postgresql")) { + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) "; + } + 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, date, date, Util.getIntValue(resourceid)); + String overtimeid = get_overtime_uuid(overtime_uuid); + kqEventLogBiz.updateOvertimeId(uuid, overtimeid); + } + } + } else { + logOvertimeMap(overtimeLogMap, "流程时长d_mins为0,不生成加班", flow_key + "|加班流程信息|flowLogInfo"); + } + } + } + + } else { + logOvertimeMap(overtimeLogMap, "打卡数据KQOvertimeCardBean为null", "打卡和上下班数据|KQOvertimeCardBean"); + } + return true; + } + + /** + * 打卡的时长计算,流程+打卡 和纯打卡的可以拿来共用 + * 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, String preChangeType_key, String nextChangeType_key) 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(preChangeType_key)) { + //昨日的排除休息时间跨天的情况 + List restTimeList = restTimeMap.get(preChangeType_key); + if (CollectionUtils.isNotEmpty(restTimeList)) { + for (int k = 0; k < restTimeList.size(); k++) { + String[] restTimes = restTimeList.get(k); + if (restTimes.length == 2) { + int restStart = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[0]); + int restEnd = kqTimesArrayComInfo.getArrayindexByTimes(restTimes[1]); + restStart = restStart - 1440; + restEnd = restEnd - 1440; + if (restEnd > 0) { + //休息时段跨天了 + if (restStart > 0) { + Arrays.fill(initArrays, restStart, restEnd, 1); + } else { + Arrays.fill(initArrays, 0, restEnd, 1); + } + } + } + } + } + + } + 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; + } + if (restStart < restEnd) { + Arrays.fill(initArrays, restStart, restEnd, -2); + } + } + } + } + } + } +// handleType 是否是处理昨日的,今日的还是明日的,0是处理今日的,1是处理明日的上下班时间和休息时间都要+1440,2是处理昨日的,需要减去1440 + int handleType = 2; + KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity = overRulesDetailMap.get(preChangeType_key); + clearWorkAndRestTime(resourceid, DateUtil.addDate(splitDate, -1), handleType, kqTimesArrayComInfo, overtimeLogMap, preKqOvertimeRulesDetailEntity, initArrays, signinTimeIndex); + handleType = 0; + clearWorkAndRestTime(resourceid, splitDate, handleType, kqTimesArrayComInfo, overtimeLogMap, kqOvertimeRulesDetailEntity, initArrays, signinTimeIndex); + handleType = 1; + KQOvertimeRulesDetailEntity nextKqOvertimeRulesDetailEntity = overRulesDetailMap.get(nextChangeType_key); + clearWorkAndRestTime(resourceid, DateUtil.addDate(splitDate, 1), handleType, kqTimesArrayComInfo, + overtimeLogMap, nextKqOvertimeRulesDetailEntity, 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 handleType 是否是处理昨日的,今日的还是明日的,0是处理今日的,1是处理明日的上下班时间和休息时间都要+1440,2是处理昨日的 + * @param kqTimesArrayComInfo + * @param overtimeLogMap + * @param kqOvertimeRulesDetailEntity + * @param initArrays + * @param signinTimeIndex + */ + public void clearWorkAndRestTime(String resourceid, String splitDate, int handleType, + KQTimesArrayComInfo kqTimesArrayComInfo, + Map overtimeLogMap, + KQOvertimeRulesDetailEntity kqOvertimeRulesDetailEntity, int[] initArrays, + int signinTimeIndex) { + + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTime = kqWorkTime.getWorkTime(resourceid, splitDate); + if (workTime == null || (workTime != null && (workTime.getWorkMins() == 0 || workTime.getNonWorkShift() == 1))) { + } 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()); + int workBeginIdx = kqTimesArrayComInfo.getArrayindexByTimes(workBeginTime); + String workEndTime = Util.null2String(workTimeScope.getEndTime()); + int workEndIdx = kqTimesArrayComInfo.getArrayindexByTimes(workEndTime); + + 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 (1 == handleType) { + begintimeIndex = begintimeIndex + 1440; + endtimeIndex = endtimeIndex + 1440; + if (begintimeIndex >= initArrays.length) { + begintimeIndex = initArrays.length - 1; + } + if (endtimeIndex >= initArrays.length) { + endtimeIndex = initArrays.length - 1; + } + } + if (2 == handleType) { + begintimeIndex = begintimeIndex - 1440; + endtimeIndex = endtimeIndex - 1440; + } + String workTimeLogInfo = "begintime:" + begintime + ":endtime:" + endtime + ":handleType:" + handleType; + logOvertimeMap(overtimeLogMap, workTimeLogInfo, "工作日的上下班时间|workTimeLogInfo"); + if (begintimeIndex >= 0 && endtimeIndex >= 0 && begintimeIndex < endtimeIndex) { + Arrays.fill(initArrays, begintimeIndex, endtimeIndex, -2); + } + if (0 == handleType) { + if (kqOvertimeRulesDetailEntity != null) { + int startTime = kqOvertimeRulesDetailEntity.getStartTime(); + if (startTime > -1) { + int after_endtimeIndex = endtimeIndex + startTime; + if (after_endtimeIndex > 0 && after_endtimeIndex > endtimeIndex) { + if (endtimeIndex < 0) { + endtimeIndex = 0; + } + 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 && begintimeIndex > 0) { + int before_begintimeIndex = begintimeIndex - before_startTime; + if (before_begintimeIndex < 0) { + before_begintimeIndex = 0; + } + if (before_begintimeIndex > signinTimeIndex) { + Arrays.fill(initArrays, signinTimeIndex, before_begintimeIndex, -2); + } + } + } + } + } + if (2 == handleType) { + if (kqOvertimeRulesDetailEntity != null) { + int startTime = kqOvertimeRulesDetailEntity.getStartTime(); + if (startTime > -1) { + int after_endtimeIndex = endtimeIndex + startTime; + if (after_endtimeIndex > 0 && after_endtimeIndex > endtimeIndex) { + if (endtimeIndex < 0) { + endtimeIndex = 0; + } + 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 < 0) { + before_begintimeIndex = 0; + } + 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 (1 == handleType) { + begintimeIndex = begintimeIndex + 1440; + endtimeIndex = endtimeIndex + 1440; + if (begintimeIndex >= initArrays.length) { + begintimeIndex = initArrays.length - 1; + } + if (endtimeIndex >= initArrays.length) { + endtimeIndex = initArrays.length - 1; + } + } + if (2 == handleType) { + begintimeIndex = begintimeIndex - 1440; + if (begintimeIndex < 0) { + begintimeIndex = 0; + } + endtimeIndex = endtimeIndex - 1440; + if (endtimeIndex < 0) { + endtimeIndex = 0; + } + } + if (begintimeIndex >= 0 && endtimeIndex >= 0 && 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("pre_has_cut_point", pre_has_cut_point); + 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) { + boolean isfree = pre_shiftInfoBean.isIsfree(); + eventMap.put("isfree", isfree); + if (!isfree) { + 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]); + } + } else { + //自由班制直接给0点 + pre_overtime_cut_point = "00:00"; + } + if (result.containsKey("beginTime")) { + String beginTime = Util.null2String(result.get("beginTime")); + if(pre_overtime_cut_point.compareTo(beginTime) > 0){ + pre_overtime_cut_point = beginTime; + } + } + 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, has_cut_point, result, nextkey); + } + } else { + String errorMsg = "前一天是工作日但是前一天的ShiftInfoBean班次获取不到信息"; + eventMap.put("errorMsg", errorMsg); + } + } else { + eventMap.put("changeType", changeType); + if (changeType == 2) { + eventMap.put("firstworkTime", firstworkTime); + result.put("cut_point", cut_point); + if (has_cut_point == 1 && before_startTime > 0) { + firstworkTime = kqTimesArrayComInfo.getTimesByArrayindex(kqTimesArrayComInfo.getArrayindexByTimes(firstworkTime) - before_startTime); + } + //如果前一天是非工作日,今天是工作日的话 + rePutCheckInfoMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, firstworkTime, splitDate, + eventMap, has_cut_point, result, nextkey); + } else { + if (result.containsKey("nonWorkBeginTime")) { + String nonWorkBeginTime = result.get("nonWorkBeginTime"); + eventMap.put("nonWorkBeginTime", nonWorkBeginTime); + //如果前一天是非工作日,今天是非工作日班次的话 + rePutCheckInfoMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, nonWorkBeginTime, splitDate, + eventMap, has_cut_point, result, nextkey); + } else { + //如果前一天是非工作日,今天是非工作日的话,那就是打卡获取的是啥就是啥 + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + } + } + } else { + List pre_lsCheckInfos = Lists.newArrayList(); + getSignData(resourceid, preSplitDate, dateFormatter, eventMap, pre_lsCheckInfos, changeTypeMap, overRulesDetailMap); + + Map preSignMap = Maps.newHashMap(); + if (!pre_lsCheckInfos.isEmpty()) { + preSignMap = (Map) pre_lsCheckInfos.get(0); + } + eventMap.put("pre_cut_point", pre_cut_point); + //设置了打卡归属 那么一天的打卡就可能被前一天给拆成两部分和后一天的打卡归属给拆分成两部分 + rePutCheckInfoCutPointMap(lsCheckInfoMaps, kqOvertimeBean, preKey, key, pre_cut_point, splitDate, + eventMap, cut_point, nextSplitDate, nextkey, has_cut_point, result, pre_has_cut_point, preSignMap); + } + } + eventMap.put("lsCheckInfos_after", lsCheckInfoMaps); + } + + /** + * 获取打卡数据 + * + * @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; + + KQOvertimeRulesDetailEntity curKqOvertimeRulesDetailEntity = overRulesDetailMap.get(changeType_key); + KQOvertimeRulesDetailEntity preKqOvertimeRulesDetailEntity = 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); + int signoutOnlyoff = 0; + + LocalDate pre_curLocalDate = localbelongDate.minusDays(1); + String preDate = pre_curLocalDate.format(dateFormatter); + LocalDate next_curLocalDate = localbelongDate.plusDays(1); + String nextDate = next_curLocalDate.format(dateFormatter); + boolean isNonWork = false; + if (workTime == null || (workTime.getWorkMins() == 0 && workTime.getNonWorkShift() != 1)) { + isNonWork = true; + } + + if (isNonWork) { + 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) { + signoutOnlyoff = workTime.getSignoutOnlyoff(); + if (workTime.getNonWorkShift() == 1) { + //非工作日班次 计算逻辑 + lsSignTime = workTime.getSignTime();//允许打卡时间 + List nonWorkTime = workTime.getWorkTime(); + TimeScopeEntity signTimeScopeStart = lsSignTime.get(0); + TimeScopeEntity signTimeScopeEnd = lsSignTime.get(lsSignTime.size() - 1); + TimeScopeEntity signTimeScope = new TimeScopeEntity(); + signTimeScope.setBeginTime(signTimeScopeStart.getBeginTime()); + signTimeScope.setBeginTimeAcross(signTimeScopeStart.getBeginTimeAcross()); + signTimeScope.setEndTime(signTimeScopeEnd.getEndTime()); + signTimeScope.setEndTimeAcross(signTimeScopeEnd.getEndTimeAcross()); + signTimeScope.setBeginTimePreAcross(signTimeScopeStart.isBeginTimePreAcross()); + + int i = 0; + result.put("lsWorkTime_size", "1"); + if (CollectionUtils.isNotEmpty(nonWorkTime)) { + TimeScopeEntity wTimeScopeEntity = nonWorkTime.get(0); + result.put("nonWorkBeginTime", wTimeScopeEntity.getBeginTime()); + } + Map signMap = getSignInfo(resourceid, signTimeScope, null, splitDate, preDate, nextDate, kqTimesArrayComInfo, eventMap, i, result,signoutOnlyoff); + if (signMap != null && !signMap.isEmpty()) { + //目前一天多次打卡的话,只获取第一次和最后一次打卡 + lsCheckInfos.add(signMap); + } + } else { + lsSignTime = workTime.getSignTime();//允许打卡时间 + lsWorkTime = workTime.getWorkTime();//工作时间 + result.put("lsWorkTime_size", "" + lsWorkTime.size()); + lsRestTime = workTime.getRestTime();//休息时段时间 + oneSign = lsWorkTime != null && lsWorkTime.size() == 1; + if (lsWorkTime != null) { + TimeScopeEntity timeScopeEntity0 = lsWorkTime.get(0); + TimeScopeEntity timeScopeEntity1 = lsWorkTime.get(lsWorkTime.size() - 1); + String beginTime = timeScopeEntity0.getBeginTime(); + String endTime = timeScopeEntity1.getEndTime(); + boolean endTimeAcross = timeScopeEntity1.getEndTimeAcross(); + result.put("beginTime", beginTime); + result.put("endTime", endTime); + result.put("endTimeAcross", endTimeAcross ? "1" : "0"); + } + 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,signoutOnlyoff); + 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, Map result, + int pre_has_cut_point, Map preSignMap) { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + String preDate = DateUtil.addDate(splitDate, -1); + + 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_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")); + } + + 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_signindate.length() > 0 && pre_signintime.length() > 0) { + preKqOvertimeBean.setSigninDate(pre_signindate); + preKqOvertimeBean.setSigninTime(pre_signintime); + 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) { + //如果归属大于签退时间 表示这个时间都是属于前一天的 + if (signindate.length() > 0 && signintime.length() > 0 && signoutdate.length() > 0 && signouttime.length() > 0) { + lsCheckInfoMaps.put(preKey, kqOvertimeBean); + } + } else { + if (signindate.length() > 0 && signintime.length() > 0 && signoutdate.length() > 0 && signouttime.length() > 0) { + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + } + if (signoutdate.length() > 0) { + if (signoutdate.compareTo(splitDate) > 0) { + if (1 == has_cut_point) { + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String overtimePoint = Util.null2String(kqSettingsComInfo.getMain_val("overtime_point"), "0"); + boolean needPointCut = false; + if ("1".equals(overtimePoint)) { + needPointCut = true; + } + //如果签退大于签到 表示打卡跨天 + 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); + if (needPointCut) { + //这个是新加的开关,为了保证历史数据,只能这样加了 + if (result.containsKey("beginTime")) { + //上班前打卡和班次开始时间作为第一段加班区间 + curOvertimeBean.setSignoutDate(splitDate); + curOvertimeBean.setSignoutTime(result.get("beginTime") + ":00"); + } + } + curOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(key, curOvertimeBean); + + KQOvertimeCardBean nextOvertimeBean = new KQOvertimeCardBean(); + nextOvertimeBean.setSigninDate(nextDate); + nextOvertimeBean.setSigninTime(cut_points); + if (needPointCut) { + //这个是新加的开关,为了保证历史数据,只能这样加了 + if (result.containsKey("endTime") && result.containsKey("endTimeAcross")) { + if (result.get("endTimeAcross").equals("1")) { + String endTime = kqTimesArrayComInfo.turn48to24Time(result.get("endTime")) + ":00"; + if (cut_points.compareTo(endTime) > 0) { + //如果下班时间跨天了,但是下班时间早于临界点 + //下班时间和开启的加班归属点作为第二段加班区间 + KQOvertimeCardBean curNextOvertimeBean = new KQOvertimeCardBean(); + curNextOvertimeBean.setSigninDate(nextDate); + curNextOvertimeBean.setSigninTime(endTime); + curNextOvertimeBean.setSignoutDate(nextDate); + curNextOvertimeBean.setSignoutTime(cut_points); + curNextOvertimeBean.setBelongDate(splitDate); + if (lsCheckInfoMaps.containsKey(key)) { + KQOvertimeCardBean kqOvertimeCardBean = lsCheckInfoMaps.get(key); + curNextOvertimeBean.setSigninDate(kqOvertimeCardBean.getSigninDate()); + curNextOvertimeBean.setSigninTime(kqOvertimeCardBean.getSigninTime()); + } + lsCheckInfoMaps.put(key, curNextOvertimeBean); + } else { + nextOvertimeBean.setSigninDate(nextDate); + nextOvertimeBean.setSigninTime(endTime); + } + } else { + //下班时间和开启的加班归属点作为第二段加班区间 + String endTime = result.get("endTime") + ":00"; + KQOvertimeCardBean curNextOvertimeBean = new KQOvertimeCardBean(); + curNextOvertimeBean.setSigninDate(splitDate); + curNextOvertimeBean.setSigninTime(endTime); + curNextOvertimeBean.setSignoutDate(nextDate); + curNextOvertimeBean.setSignoutTime(cut_points); + curNextOvertimeBean.setBelongDate(splitDate); + if (lsCheckInfoMaps.containsKey(key)) { + KQOvertimeCardBean kqOvertimeCardBean = lsCheckInfoMaps.get(key); + curNextOvertimeBean.setSigninDate(kqOvertimeCardBean.getSigninDate()); + curNextOvertimeBean.setSigninTime(kqOvertimeCardBean.getSigninTime()); + } + lsCheckInfoMaps.put(key, curNextOvertimeBean); + } + } + } + nextOvertimeBean.setSignoutDate(signoutdate); + nextOvertimeBean.setSignoutTime(signouttime); + nextOvertimeBean.setBelongDate(nextDate); + //加班归属点和跨天的下班签退卡作为第三段加班区间 + lsCheckInfoMaps.put(nextkey, nextOvertimeBean); + } + } + } + } + //如果存在签到时间跨到前一天的情况 + if (signindate.length() > 0 && signindate.compareTo(splitDate) < 0) { + if (1 == pre_has_cut_point) { + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String overtimePoint = Util.null2String(kqSettingsComInfo.getMain_val("overtime_point"), "0"); + boolean needPointCut = false; + if ("1".equals(overtimePoint)) { + needPointCut = true; + } + if (needPointCut) { + if (signindatetime.compareTo(pre_date_cut_point) < 0) { + if (lsCheckInfoMaps.containsKey(preKey)) { + if (signoutdate.length() > 0 && signouttime.length() > 0) { + KQOvertimeCardBean preKqOvertimeBean = new KQOvertimeCardBean(); + preKqOvertimeBean.setSigninDate(pre_signindate); + preKqOvertimeBean.setSigninTime(pre_signintime); + preKqOvertimeBean.setSignoutDate(pre_signoutdate); + preKqOvertimeBean.setSignoutTime(pre_signouttime); + preKqOvertimeBean.setBelongDate(preDate); + lsCheckInfoMaps.put(preKey, preKqOvertimeBean); + + //这是一种特殊情况,跨天临界点是0点,然后签到时间跨到前一天去了,如果这时候还开了0点拆分,那么0点前的部分和0点后的部分都需要处理 + String[] keys = key.split("_"); + if (keys.length > 1) { + String resourceid = keys[0]; + String beforeKey = resourceid + "_" + signindate + "_" + splitDate; + KQOvertimeCardBean todayInPreOvertimeBean = new KQOvertimeCardBean(); + todayInPreOvertimeBean.setSigninDate(signindate); + todayInPreOvertimeBean.setSigninTime(signintime); + todayInPreOvertimeBean.setSignoutDate(splitDate); + todayInPreOvertimeBean.setSignoutTime(pre_cut_points); + todayInPreOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(beforeKey, todayInPreOvertimeBean); + } + } + } else { + //这是一种特殊情况,跨天临界点是0点,然后签到时间跨到前一天去了,如果这时候还开了0点拆分,那么0点前的部分和0点后的部分都需要处理 + String[] keys = key.split("_"); + if (keys.length > 1) { + String resourceid = keys[0]; + String beforeKey = resourceid + "_" + signindate + "_" + splitDate; + KQOvertimeCardBean todayInPreOvertimeBean = new KQOvertimeCardBean(); + todayInPreOvertimeBean.setSigninDate(signindate); + todayInPreOvertimeBean.setSigninTime(signintime); + todayInPreOvertimeBean.setSignoutDate(splitDate); + todayInPreOvertimeBean.setSignoutTime(pre_cut_points); + todayInPreOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(beforeKey, todayInPreOvertimeBean); + } + } + } + } + } + } + } + + + /** + * 重新把打卡数据按照归属来赋值 + */ + public void rePutCheckInfoMap(Map lsCheckInfoMaps, + KQOvertimeCardBean kqOvertimeBean, + String preKey, String key, String overtime_cut_point, String splitDate, + Map eventMap, int has_cut_point, Map result, String nextkey) { + KQTimesArrayComInfo kqTimesArrayComInfo = new KQTimesArrayComInfo(); + + String nextDate = DateUtil.addDate(splitDate, 1); + String cut_point = Util.null2String(result.get("cut_point")); + String next_overtime_cut_points = cut_point + ":00"; + String next_date_cut_point = nextDate + " " + next_overtime_cut_points; + + 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) { + //如果归属大于签退时间 表示这个时间都是属于前一天的 + if (signindate.length() > 0 && signintime.length() > 0 && signoutdate.length() > 0 && signouttime.length() > 0) { + lsCheckInfoMaps.put(preKey, kqOvertimeBean); + } + } else { + //如果归属 小于签到时间,则都属于今天 + if (signindate.length() > 0 && signintime.length() > 0 && signoutdate.length() > 0 && signouttime.length() > 0) { + lsCheckInfoMaps.put(key, kqOvertimeBean); + } + } + + if (signoutdate.length() > 0) { + if (signoutdate.compareTo(splitDate) > 0) { + if (1 == has_cut_point) { + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String overtimePoint = Util.null2String(kqSettingsComInfo.getMain_val("overtime_point"), "0"); + boolean needPointCut = false; + if ("1".equals(overtimePoint)) { + needPointCut = true; + } + //没这个开关的话不会有下面的逻辑 + if (needPointCut) { + //如果签退大于签到 表示打卡跨天 + if (next_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(next_overtime_cut_points); + //这个是新加的开关,为了保证历史数据,只能这样加了 + if (result.containsKey("beginTime")) { + //上班前打卡和班次开始时间作为第一段加班区间 + curOvertimeBean.setSignoutDate(splitDate); + curOvertimeBean.setSignoutTime(result.get("beginTime") + ":00"); + } + curOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(key, curOvertimeBean); + + KQOvertimeCardBean nextOvertimeBean = new KQOvertimeCardBean(); + nextOvertimeBean.setSigninDate(nextDate); + nextOvertimeBean.setSigninTime(next_overtime_cut_points); + //这个是新加的开关,为了保证历史数据,只能这样加了 + if (result.containsKey("endTime") && result.containsKey("endTimeAcross")) { + if (result.get("endTimeAcross").equals("1")) { + String tmp1 = nextDate + " " + kqTimesArrayComInfo.turn48to24Time(result.get("endTime")) + ":00"; + if (next_date_cut_point.compareTo(tmp1) > 0) { + //如果跨天归属点大于下班时间,需要再根据归属点分割下 + KQOvertimeCardBean curNextOvertimeBean = new KQOvertimeCardBean(); + curNextOvertimeBean.setSigninDate(nextDate); + curNextOvertimeBean.setSigninTime(kqTimesArrayComInfo.turn48to24Time(result.get("endTime")) + ":00"); + curNextOvertimeBean.setSignoutDate(nextDate); + curNextOvertimeBean.setSignoutTime(next_overtime_cut_points); + curNextOvertimeBean.setBelongDate(splitDate); + if (lsCheckInfoMaps.containsKey(key)) { + KQOvertimeCardBean kqOvertimeCardBean = lsCheckInfoMaps.get(key); + curNextOvertimeBean.setSigninDate(kqOvertimeCardBean.getSigninDate()); + curNextOvertimeBean.setSigninTime(kqOvertimeCardBean.getSigninTime()); + } + lsCheckInfoMaps.put(key, curNextOvertimeBean); + } else { + nextOvertimeBean.setSigninDate(nextDate); + nextOvertimeBean.setSigninTime(kqTimesArrayComInfo.turn48to24Time(result.get("endTime")) + ":00"); + } + } else { + //下班时间和开启的加班归属点作为第二段加班区间 + KQOvertimeCardBean curNextOvertimeBean = new KQOvertimeCardBean(); + curNextOvertimeBean.setSigninDate(splitDate); + curNextOvertimeBean.setSigninTime(result.get("endTime") + ":00"); + curNextOvertimeBean.setSignoutDate(nextDate); + curNextOvertimeBean.setSignoutTime(next_overtime_cut_points); + curNextOvertimeBean.setBelongDate(splitDate); + if (lsCheckInfoMaps.containsKey(key)) { + KQOvertimeCardBean kqOvertimeCardBean = lsCheckInfoMaps.get(key); + curNextOvertimeBean.setSigninDate(kqOvertimeCardBean.getSigninDate()); + curNextOvertimeBean.setSigninTime(kqOvertimeCardBean.getSigninTime()); + } + lsCheckInfoMaps.put(key, curNextOvertimeBean); + } + } + nextOvertimeBean.setSignoutDate(signoutdate); + nextOvertimeBean.setSignoutTime(signouttime); + nextOvertimeBean.setBelongDate(nextDate); + //加班归属点和跨天的下班签退卡作为第三段加班区间 + lsCheckInfoMaps.put(nextkey, nextOvertimeBean); + } + } + } + } + } + //如果存在签到时间跨到前一天的情况 + if (signindate.length() > 0 && signindate.compareTo(splitDate) < 0) { + if (signindatetime.compareTo(date_cut_point) < 0) { + //这是一种特殊情况,跨天临界点是0点,然后签到时间跨到前一天去了,如果这时候还开了0点拆分,那么0点前的部分和0点后的部分都需要处理 + String[] keys = key.split("_"); + if (keys.length > 1) { + String resourceid = keys[0]; + String beforeKey = resourceid + "_" + signindate + "_" + splitDate; + KQOvertimeCardBean todayInPreOvertimeBean = new KQOvertimeCardBean(); + todayInPreOvertimeBean.setSigninDate(signindate); + todayInPreOvertimeBean.setSigninTime(signintime); + todayInPreOvertimeBean.setSignoutDate(splitDate); + todayInPreOvertimeBean.setSignoutTime(overtime_cut_points); + todayInPreOvertimeBean.setBelongDate(splitDate); + lsCheckInfoMaps.put(beforeKey, todayInPreOvertimeBean); + } + } + } + } + + + /** + * 获取加班流程数据 + * + * @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(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String overtimePoint = Util.null2String(kqSettingsComInfo.getMain_val("overtime_point"), "0"); + boolean needPointCut = false; + if ("1".equals(overtimePoint)) { + needPointCut = true; + } + 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点,那么如果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 (!needPointCut && 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; + } + /** + 打卡数据:2022/04/29 09:00:00----2022/04/29 23:59:59---2022/04/30 00:00:00----2022/04/30 02:00:00 + 加班流程:2022-04-29 20:00---2022-04-30 03:00 + 加班规则:2022-04-29周五工作日自定义跨天归属设置为00:00,取交集,然后30号的00:00-02:00两个小时加班无法生成 + 问题原因:当29的下班卡结束打卡时间在自定义跨天00:00之后,那么读卡范围是:29号结束打卡时间(pre_Worktime4Today)开始的 + */ + pre_Worktime4Today = cut_point + ":01"; + } + } + if (pre_Worktime4Today.length() == 5) { + pre_Worktime4Today += ":00"; + } + signBeginDateTime = kqDate + " " + pre_Worktime4Today; + } else { + if (!needPointCut && 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 (!needPointCut && 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 (false) { + 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("昨日开启了打卡归属,非工作日打卡sql|nonwork_card_sql", nonwork_card_sql); + eventMap.put("昨日开启了打卡归属,非工作日打卡sql结果|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) { + return getSignInfo(userId, signTimeScope, workTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo, eventMap, index, result,0); + } + public Map getSignInfo(String userId, TimeScopeEntity signTimeScope, + TimeScopeEntity workTimeScope, String kqDate, String preDate, + String nextDate, KQTimesArrayComInfo kqTimesArrayComInfo, Map eventMap, + int index, Map result,int signoutOnlyoff) { + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String overtimePoint = Util.null2String(kqSettingsComInfo.getMain_val("overtime_point"), "0"); + boolean needPointCut = true; + if ("1".equals(overtimePoint)) { + needPointCut = false; + } + + 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"))); + + List> sqlConditions = kqFormatSignData.getCanSignInfo(signTimeScope, kqDate, preDate, nextDate, kqTimesArrayComInfo,workTimeScope,signoutOnlyoff); + base_sql = kqFormatSignData.signSignSql(rs); + + if (sqlConditions != null && !sqlConditions.isEmpty()) { + boolean hasSignIn = false; + 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 (needPointCut && has_cut_point == 1) { + String cut_point_datettime = nextDate + " " + cut_point + ":59"; + signEndDateTime = cut_point_datettime; + } + } + if (index == 0 && i == 0) { + //第一次的打卡范围会被打卡临界点给修改 + if (needPointCut && 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")); + String signoutOnlyoff_flag = Util.null2String(sqlMap.get("signoutOnlyoff")); + 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("工作日打卡sql|work_card_sql_" + index, work_card_sql); + eventMap.put("工作日打卡sql结果|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 (signoutOnlyoff_flag.length()>0) { + if("signin".equals(signoutOnlyoff_flag) && idx == 1){ + checkInfo.put("signType", "1"); + checkInfo.put("type", "signin"); + lsCheckInfo.add(checkInfo); + hasSignIn = true; + } + if("signoff".equals(signoutOnlyoff_flag)){ + if ((hasSignIn && idx == rs.getCounts() && idx > 1) || (!hasSignIn && idx == rs.getCounts())) {//第一条可能是签到卡需要处理下,否则可能会导致一条上班卡同时识别为上班卡和下班卡 + checkInfo.put("signType", "2"); + checkInfo.put("type", "signoff"); + lsCheckInfo.add(checkInfo); + } + } + }else{ + if (idx == 1) {//第一条算签到 + checkInfo.put("signType", "1"); + lsCheckInfo.add(checkInfo); + hasSignIn = true; + } 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 (workTimeScope != null) { + 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", kqTimesArrayComInfo.turn48to24Time(workTimeScope.getBeginTime()) + ":00"); + } else if ("signoff".equalsIgnoreCase(type)) { + signMap.put("signindate", workTimeScope.getEndTimeAcross() ? nextDate : kqDate); + signMap.put("signintime", kqTimesArrayComInfo.turn48to24Time(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", kqTimesArrayComInfo.turn48to24Time(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 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"); + boolean flag = rs.executeUpdate(delSql); + if (!flag) { + kqLog.info("加班流程删除之前的调休数据失败:数据库更新失败"); + } + } + 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, update_time=? where " + Util.getSubINClause(clear_tiaoxiuids, "id", "in"); + isclearOk = rs.executeUpdate(clearSql, KQDateUtil.getUpdateTimeStamp()); + } + + 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; + } +} diff --git a/src/com/engine/kq/cmd/group/GetGroupFormCmd.java b/src/com/engine/kq/cmd/group/GetGroupFormCmd.java new file mode 100644 index 0000000..81fa78e --- /dev/null +++ b/src/com/engine/kq/cmd/group/GetGroupFormCmd.java @@ -0,0 +1,979 @@ +package com.engine.kq.cmd.group; + +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.util.HrmFieldSearchConditionComInfo; +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.kq.biz.KQGroupComInfo; +import com.engine.kq.cmd.shiftmanagement.toolkit.ShiftManagementToolKit; +import com.engine.kq.util.PageUidFactory; +import com.engine.kq.util.UtilKQ; +import com.google.common.collect.Maps; +import org.apache.commons.collections.CollectionUtils; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.moduledetach.ManageDetachComInfo; +import weaver.hrm.settings.ChgPasswdReminder; +import weaver.hrm.settings.RemindSettings; +import weaver.proj.util.SQLUtil; +import weaver.systeminfo.SystemEnv; +import weaver.systeminfo.systemright.CheckSubCompanyRight; + +import java.util.*; + +public class GetGroupFormCmd extends AbstractCommonCommand> { + + public GetGroupFormCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + List> grouplist = new ArrayList>(); + Map groupitem = null; + List itemlist = null; + Map otherparam = null; + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + //必要的权限判断 + if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + + ChgPasswdReminder reminder=new ChgPasswdReminder(); + RemindSettings settings=reminder.getRemindSettings(); + KQGroupComInfo kQGroupComInfo = new KQGroupComInfo(); + ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo(); + boolean hrmdetachable = manageDetachComInfo.isUseHrmManageDetach();//是否开启了人力资源模块的管理分权 + + String id = Util.null2String(params.get("id")); + String subcompanyid = Util.null2String(params.get("subcompanyid"));//所属分部 + String tabKey = Util.null2String(params.get("tabKey")); + Map> fieldGroups= new LinkedHashMap>(); + List lsField = new ArrayList(); + HrmFieldBean hrmFieldBean = null; + List options = null; + + String groupname = "";//考勤组名称 + String kqtype = "1";//考勤类型 默认固定班制 + String excludeid = "";//考勤组排除人员 + String excludecount = "";//考勤组排除人员是否参与统计 + String serialids = "";//考勤班次 + String overtimeRuleId = "";//加班班次 + String overtimeType = "0";//加班类型 + List lsWeekday = new ArrayList<>();//考勤工作日 + String weekday = ""; + String signstart = "";//考勤开始时间 + String workhour = "";//工作时长 + String signintype = "1";//打卡方式 + String ipscope = "";//应用IP范围 + String ipscope_v4_pc = "";//应用IP范围 v4 pc端 + String ipscope_v4_em = "";//应用IP范围 v4 移动端 + String ipscope_v6_pc = "";//应用IP范围 v6 pc端 + String ipscope_v6_em = "";//应用IP范围 v6 移动端 + String locationcheck = "";//启用办公地点考勤 + //String locationcheckscope = "300";//有效范围 + String wificheck = "";//启用wifi考勤 + String outsidesign = "";//允许外勤打卡 + String outsignapprove = "";//545427 外勤打卡需要审批 + String validity = "";//考勤组有效期 + String validityfromdate = "";//考勤组有效期开始时间 + String validityenddate = "";//考勤组有效期结束时间 + String locationfacecheck = "";//办公地点启用人脸识别拍照打卡 + String locationfacechecktype = "";//办公地点启用人脸识别拍照打卡方式 + String locationshowaddress = "";//有效识别半径内显示同一地址 + String wififacecheck = "";//wifi启用人脸识别拍照打卡 + String wififacechecktype = "";//wifi启用人脸识别拍照打卡方式 + String self_shift = "0";//启用员工自我排班 + String auto_checkin = "0";//允许客户端设置自动考勤 上班卡 + String auto_checkin_before = "30";//允许客户端设置自动考勤 上班卡开始分钟数 + String auto_checkin_after = "30";//允许客户端设置自动考勤 上班卡结束分钟时 + String auto_checkout = "0";//允许客户端设置自动考勤 下班卡 + String auto_checkout_before = "5";//允许客户端设置自动考勤 下班卡 下班卡开始分钟数 + String auto_checkout_after = "60";//允许客户端设置自动考勤 下班卡 下班卡结束分钟时 + String calmethod = "1";//工作时长计算方式 1是打卡时间累加计算 2是打卡时间成对计算 + String abnormalremind = "0";//考勤异常提醒 1是打开 0是关闭 + String isPhotoPunchEnabled = "0";//启用考勤拍照打卡 + + List> replaceDatas = new ArrayList>(); + if(id.length()>0){ + sql = "select * from kq_group where id=?"; + rs.executeQuery(sql,id); + if(rs.next()){ + groupname = Util.null2String(rs.getString("groupname")); + excludeid = Util.null2String(rs.getString("excludeid")); + excludecount = Util.null2String(rs.getString("excludecount")); + subcompanyid = Util.null2String(rs.getString("subcompanyid")); + kqtype = Util.null2String(rs.getString("kqtype")); + serialids=Util.null2String(rs.getString("serialids")); + overtimeType=Util.null2s(rs.getString("overtime_type"),"0"); + weekday = Util.null2String(rs.getString("weekday")); + signstart = Util.null2String(rs.getString("signstart")); + workhour = Util.null2String(rs.getString("workhour")); + signintype = Util.null2String(rs.getString("signintype")); + ipscope = Util.null2String(rs.getString("ipscope")); + ipscope_v4_pc = Util.null2String(rs.getString("ipscope_v4_pc")); + ipscope_v4_em = Util.null2String(rs.getString("ipscope_v4_em")); + ipscope_v6_pc = Util.null2String(rs.getString("ipscope_v6_pc")); + ipscope_v6_em = Util.null2String(rs.getString("ipscope_v6_em")); + locationcheck = Util.null2String(rs.getString("locationcheck")); + //locationcheckscope = Util.null2String(rs.getString("locationcheckscope")); + wificheck = Util.null2String(rs.getString("wificheck")); + outsidesign = Util.null2String(rs.getString("outsidesign")); + outsignapprove = Util.null2String(rs.getString("outsignapprove")); + validity = Util.null2String(rs.getString("validity")); + validityfromdate = Util.null2String(rs.getString("validityfromdate")); + validityenddate = Util.null2String(rs.getString("validityenddate")); + locationfacecheck = Util.null2String(rs.getString("locationfacecheck")); + locationfacechecktype = Util.null2String(rs.getString("locationfacechecktype")); + locationshowaddress = Util.null2String(rs.getString("locationshowaddress")); + wififacecheck = Util.null2String(rs.getString("wififacecheck")); + wififacechecktype = Util.null2String(rs.getString("wififacechecktype")); + self_shift = Util.null2String(rs.getString("self_shift")); + auto_checkin = Util.null2String(rs.getString("auto_checkin"),"0"); + auto_checkin_before = Util.null2String(rs.getString("auto_checkin_before"),"30"); + auto_checkin_after = Util.null2String(rs.getString("auto_checkin_after"),"30"); + auto_checkout = Util.null2String(rs.getString("auto_checkout"),"0"); + auto_checkout_before = Util.null2String(rs.getString("auto_checkout_before"),"5"); + auto_checkout_after = Util.null2String(rs.getString("auto_checkout_after"),"60"); + calmethod = Util.null2s(rs.getString("calmethod"),"1"); + isPhotoPunchEnabled = Util.null2s(rs.getString("isPhotoPunchEnabled"),"0"); + abnormalremind = Util.null2String(rs.getString("abnormalremind")); + } + if("0".equals(overtimeType)){ + String dbtype = rs.getDBType(); + String overSql = "select * from kq_overtimerules where ','+convert(varchar(2000),groupids)+',' like '%," + id + ",%' and (isDelete is null or isDelete!=1) "; + if ("oracle".equalsIgnoreCase(dbtype)) { + overSql = "select * from kq_overtimerules where "+SQLUtil.filteSql(rs.getDBType(), " ','+groupids+',' like '%," + id + ",%' and (isDelete is null or isDelete!=1) "); + }else if("mysql".equalsIgnoreCase(dbtype)){ + overSql = "select * from kq_overtimerules where CONCAT(',',cast(groupids as char),',') like '%,"+id+",%' and (isDelete is null or isDelete!=1) "; + }else if ("postgresql".equalsIgnoreCase(dbtype)) { + overSql = "select * from kq_overtimerules where CONCAT(',',groupids,',') like '%,"+id+",%' and (isDelete is null or isDelete!=1) "; + } + Map map = new HashMap(); + rs.execute(overSql); + if(rs.next()){ + String oId = rs.getString("id"); + overtimeRuleId = oId; + String name = rs.getString("name"); + map.put("id", oId); + map.put("name", name); + replaceDatas.add(map); + } + } + } + + if(tabKey.equals("1")){ + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("groupname"); + hrmFieldBean.setFieldlabel("388700"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(groupname); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setRules("required|string"); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("excludeid"); + hrmFieldBean.setFieldlabel("388703"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("17"); + hrmFieldBean.setFieldvalue(excludeid); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("overtime_type"); + hrmFieldBean.setFieldlabel("388881"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("3"); + options = new ArrayList(); + options.add(new SearchConditionOption("0",SystemEnv.getHtmlLabelName(126821, user.getLanguage()),overtimeType.equals("0"))); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(546276, user.getLanguage()),overtimeType.equals("1"))); + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setFieldvalue(overtimeType); + hrmFieldBean.setViewAttr(2); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("overtime_rule_id"); + hrmFieldBean.setFieldlabel("388881"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("kqovertimerule"); + hrmFieldBean.setFieldvalue(overtimeRuleId); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("excludecount"); + hrmFieldBean.setFieldlabel("507794"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(excludecount); + lsField.add(hrmFieldBean); + + //增加有效期设置 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("validity"); + hrmFieldBean.setFieldlabel("15030"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(validity); + lsField.add(hrmFieldBean); + + //考勤异常提醒 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("abnormalremind"); + hrmFieldBean.setFieldlabel("547511"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(abnormalremind); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("validityfromdate"); + hrmFieldBean.setFieldlabel("742"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(validityfromdate); + hrmFieldBean.setRules("required|string"); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setIsFormField(true); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("validityenddate"); + hrmFieldBean.setFieldlabel("743"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(validityenddate); + hrmFieldBean.setRules("required|string"); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setIsFormField(true); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("self_shift"); + hrmFieldBean.setFieldlabel("517026"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(self_shift); + lsField.add(hrmFieldBean); + + String defaultSubcompanyid = ""; + if(hrmdetachable){ + CheckSubCompanyRight newCheck=new CheckSubCompanyRight(); + int[] subcomids = newCheck.getSubComByUserRightId(user.getUID(),"HrmKQGroup:Add",0); + ManageDetachComInfo detachComInfo = new ManageDetachComInfo(); + if(detachComInfo.isUseHrmManageDetach()){ + defaultSubcompanyid = detachComInfo.getHrmdftsubcomid(); + }else{ + rs.executeProc("SystemSet_Select",""); + if(rs.next()){ + if(subcompanyid.length()==0||subcompanyid.equals("0")){ + defaultSubcompanyid = Util.null2String(rs.getString("dftsubcomid")); + } + } + } + + boolean hasRight = false; + for (int i = 0; subcomids!=null&& i < subcomids.length; i++) { + if((""+subcomids[i]).equals(defaultSubcompanyid)){ + hasRight = true; + break; + } + } + + if(!hasRight){ + defaultSubcompanyid = ""; + } + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("subcompanyid"); + hrmFieldBean.setFieldlabel("19799"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("169"); + hrmFieldBean.setFieldvalue(subcompanyid.length()==0&&id.length()==0?defaultSubcompanyid:subcompanyid); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setRules("required|integer"); + lsField.add(hrmFieldBean); + } + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("kqtype"); + hrmFieldBean.setFieldlabel("388704"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("3"); + hrmFieldBean.setFieldvalue(kqtype); + + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(500385, user.getLanguage()),kqtype.equals("1"))); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(500386, user.getLanguage()),kqtype.equals("2"))); + options.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(500387, user.getLanguage()),kqtype.equals("3"))); + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setViewAttr(id.length()>0?1:2); + lsField.add(hrmFieldBean); + + //固定班制 + retmap.put("fixedSchedulce",getFixedSchedulce()); + //排班制 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("serialids"); + hrmFieldBean.setFieldlabel("389098"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("mkqshift"); + hrmFieldBean.setFieldvalue(serialids); + lsField.add(hrmFieldBean); + retmap.put("shiftSchedulceTable",getShiftSchedulceTable()); + + //自由班制 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("weekday"); + hrmFieldBean.setFieldlabel("389097"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(weekday); + options = new ArrayList(); + for(int i=0;i<7;i++){ + options.add(new SearchConditionOption(""+i,UtilKQ.getWeekDay(i,user.getLanguage()),lsWeekday.contains(i))); + } + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("signstart"); + hrmFieldBean.setFieldlabel("16039"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("19"); + hrmFieldBean.setFieldvalue(signstart); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setRules("required|string"); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("workhour"); + hrmFieldBean.setFieldlabel("390053"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(workhour); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setRules("required|numeric"); + otherparam = new HashMap(); + otherparam.put("min","1"); + otherparam.put("precision",1); + otherparam.put("max","24"); + hrmFieldBean.setOtherparam(otherparam); + lsField.add(hrmFieldBean); + + if(id.length()>0){ +// 编辑的时候只有弹性的显示这个说明 + if(kqtype.equals("3")){ + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("calmethod"); + hrmFieldBean.setFieldlabel("529683"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("3"); + hrmFieldBean.setFieldvalue(calmethod); + + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(529686, user.getLanguage()),calmethod.equals("1"))); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(529685, user.getLanguage()),calmethod.equals("2"))); + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setViewAttr(3); + lsField.add(hrmFieldBean); + } + }else{ + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("calmethod"); + hrmFieldBean.setFieldlabel("529683"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("3"); + hrmFieldBean.setFieldvalue(calmethod); + + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(529686, user.getLanguage()),calmethod.equals("1"))); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(529685, user.getLanguage()),calmethod.equals("2"))); + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setViewAttr(3); + lsField.add(hrmFieldBean); + } + + if(id.length()>0){ +// 编辑的时候只有弹性的显示这个说明 + if(kqtype.equals("3")){ + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("desc"); + hrmFieldBean.setFieldlabel("85"); + hrmFieldBean.setFieldhtmltype("8"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(SystemEnv.getHtmlLabelName(520468, Util.getIntValue(user.getLanguage())) + +"
"+SystemEnv.getHtmlLabelName(520469, Util.getIntValue(user.getLanguage())) + +"
"+SystemEnv.getHtmlLabelName(520859, Util.getIntValue(user.getLanguage()))); + hrmFieldBean.setViewAttr(1); + lsField.add(hrmFieldBean); + } + }else{ + //新增的时候需要前端控制显示这个字段 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("desc"); + hrmFieldBean.setFieldlabel("85"); + hrmFieldBean.setFieldhtmltype("8"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(SystemEnv.getHtmlLabelName(520468, Util.getIntValue(user.getLanguage())) + +"
"+SystemEnv.getHtmlLabelName(520469, Util.getIntValue(user.getLanguage())) + +"
"+SystemEnv.getHtmlLabelName(520859, Util.getIntValue(user.getLanguage()))); + hrmFieldBean.setViewAttr(1); + lsField.add(hrmFieldBean); + } + + fieldGroups.put("1361", lsField); + }else if(tabKey.equals("2")){ + //signintype,ipscope,locationcheck,locationcheckscope,wificheck + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("signintype"); + hrmFieldBean.setFieldlabel("388708"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("3"); + hrmFieldBean.setFieldvalue(signintype); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(389938, user.getLanguage()),signintype.equals("1"))); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(388710, user.getLanguage()),signintype.equals("2"))); + options.add(new SearchConditionOption("3",SystemEnv.getHtmlLabelName(389939, user.getLanguage()),signintype.equals("3"))); + options.add(new SearchConditionOption("4",SystemEnv.getHtmlLabelName(502765, user.getLanguage()),signintype.equals("4"))); + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("ipscope_v4_pc"); + hrmFieldBean.setFieldlabel("388712"); + hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712, Util.getIntValue(user.getLanguage()))+"( ipv4 )"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(ipscope_v4_pc); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("ipscope_v4_em"); + hrmFieldBean.setFieldlabel("388712"); + hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712, Util.getIntValue(user.getLanguage()))+"( ipv4 )"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(ipscope_v4_em); + lsField.add(hrmFieldBean); + +// hrmFieldBean = new HrmFieldBean(); +// hrmFieldBean.setFieldname("ipscope_v6_pc"); +// hrmFieldBean.setFieldlabel("388712"); +// hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712,weaver.general.Util.getIntValue(user.getLanguage()))+"( ipv6 )"); +// hrmFieldBean.setFieldhtmltype("1"); +// hrmFieldBean.setType("1"); +// hrmFieldBean.setFieldvalue(ipscope_v6_pc); +// lsField.add(hrmFieldBean); +// +// hrmFieldBean = new HrmFieldBean(); +// hrmFieldBean.setFieldname("ipscope_v6_em"); +// hrmFieldBean.setFieldlabel("388712"); +// hrmFieldBean.setFieldlabelname(SystemEnv.getHtmlLabelName(388712,weaver.general.Util.getIntValue(user.getLanguage()))+"( ipv6 )"); +// hrmFieldBean.setFieldhtmltype("1"); +// hrmFieldBean.setType("1"); +// hrmFieldBean.setFieldvalue(ipscope_v6_em); +// lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("outsidesign"); + hrmFieldBean.setFieldlabel("390302"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelNames("545433,545434,545435" ,user.getLanguage())); + hrmFieldBean.setFieldvalue(outsidesign); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("isPhotoPunchEnabled"); + hrmFieldBean.setFieldlabel("547013"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(isPhotoPunchEnabled); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("outsignapprove"); + hrmFieldBean.setFieldlabel("545427"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(545466,user.getLanguage())); + hrmFieldBean.setFieldvalue(outsignapprove); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("locationcheck"); + hrmFieldBean.setFieldlabel("388713"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(locationcheck); + lsField.add(hrmFieldBean); + +// hrmFieldBean = new HrmFieldBean(); +// hrmFieldBean.setFieldname("locationcheckscope"); +// hrmFieldBean.setFieldlabel("388714"); +// hrmFieldBean.setFieldhtmltype("5"); +// hrmFieldBean.setType("1"); +// hrmFieldBean.setFieldvalue(locationcheckscope); +// options = new ArrayList(); +// options.add(new SearchConditionOption("50","50"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("50"))); +// options.add(new SearchConditionOption("100","100"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("100"))); +// options.add(new SearchConditionOption("200","200"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("200"))); +// options.add(new SearchConditionOption("300","300"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("300"))); +// options.add(new SearchConditionOption("400","400"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("400"))); +// options.add(new SearchConditionOption("500","500"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("500"))); +// options.add(new SearchConditionOption("600","600"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("600"))); +// options.add(new SearchConditionOption("700","700"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("700"))); +// options.add(new SearchConditionOption("800","800"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("800"))); +// options.add(new SearchConditionOption("900","900"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("900"))); +// options.add(new SearchConditionOption("1000","1000"+SystemEnv.getHtmlLabelName(125675, user.getLanguage()),locationcheckscope.equals("1000"))); +// hrmFieldBean.setSelectOption(options); +// lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("locationfacecheck"); + hrmFieldBean.setFieldlabel("507921"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(locationfacecheck); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("locationfacechecktype"); + hrmFieldBean.setFieldlabel("537091"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(locationfacechecktype); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(537092,user.getLanguage()),true)); + if("1".equals(settings.getSecondCL())){ + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(537093,user.getLanguage()))); + } + + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(537095,user.getLanguage())); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("locationshowaddress"); + hrmFieldBean.setFieldlabel("507922"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(locationshowaddress); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(507990,user.getLanguage())); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("wificheck"); + hrmFieldBean.setFieldlabel("388715"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(wificheck); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("wififacecheck"); + hrmFieldBean.setFieldlabel("507921"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(wififacecheck); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("wififacechecktype"); + hrmFieldBean.setFieldlabel("537091"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(wififacechecktype); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(537092,user.getLanguage()))); + if("1".equals(settings.getSecondCL())){ + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(537093,user.getLanguage()))); + } + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(537095,user.getLanguage())); + lsField.add(hrmFieldBean); + + if(!"3".equalsIgnoreCase(kqtype)){ + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkin"); + hrmFieldBean.setFieldlabel("518736"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin,"0")); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(521383,user.getLanguage())); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkin_before"); + hrmFieldBean.setFieldlabel("518737"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin_before,"30")); + hrmFieldBean.setRules("required|integer"); + otherparam = new HashMap(); + otherparam.put("min","1"); + hrmFieldBean.setOtherparam(otherparam); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkin_after"); + hrmFieldBean.setFieldlabel("518737"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkin_after,"30")); + hrmFieldBean.setRules("required|integer"); + otherparam = new HashMap(); + otherparam.put("min","0"); + hrmFieldBean.setOtherparam(otherparam); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkout"); + hrmFieldBean.setFieldlabel("518738"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout,"0")); + hrmFieldBean.setTip(SystemEnv.getHtmlLabelName(521383,user.getLanguage())); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkout_before"); + hrmFieldBean.setFieldlabel("518739"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout_before,"5")); + hrmFieldBean.setRules("required|integer"); + otherparam = new HashMap(); + otherparam.put("min","0"); + hrmFieldBean.setOtherparam(otherparam); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("auto_checkout_after"); + hrmFieldBean.setFieldlabel("518739"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(Util.null2s(auto_checkout_after,"60")); + hrmFieldBean.setRules("required|integer"); + otherparam = new HashMap(); + otherparam.put("min","0"); + hrmFieldBean.setOtherparam(otherparam); + lsField.add(hrmFieldBean); + } + + //排班校验下拉框 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("pbcheck"); + hrmFieldBean.setFieldlabel("-85230"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue("1"); + + options = new ArrayList(); + options.add(new SearchConditionOption("1", "不校验")); + options.add(new SearchConditionOption("2", "做五休二")); + options.add(new SearchConditionOption("3", "做四休二")); + hrmFieldBean.setSelectOption(options); + hrmFieldBean.setViewAttr(id.length()>0?1:2); + + fieldGroups.put("20331", lsField); + retmap.put("locationSessionKey",getKQLocationList("")); + retmap.put("wifiSessionKey",getKQWifiList("")); + Map helpTipMap = Maps.newHashMap(); + helpTipMap.put("auto_checkin_before", SystemEnv.getHtmlLabelName(521211, user.getLanguage())); + helpTipMap.put("auto_checkout_before", SystemEnv.getHtmlLabelName(521211, user.getLanguage())); + retmap.put("helpTipMap",helpTipMap); + + } + + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + SearchConditionItem searchConditionItem = null; + Iterator>> iter = fieldGroups.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry> entry = iter.next(); + String grouplabel = entry.getKey(); + List fields = entry.getValue(); + groupitem = new HashMap(); + groupitem.put("title", SystemEnv.getHtmlLabelNames(grouplabel, user.getLanguage())); + groupitem.put("defaultshow", true); + + itemlist = new ArrayList(); + for (int j = 0; j < fields.size(); j++) { + hrmFieldBean = fields.get(j); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if(hrmFieldBean.getFieldname().equals("subcompanyid")){ + searchConditionItem.getBrowserConditionParam().getDataParams().put("rightStr", "HrmKQGroup:Add"); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("rightStr", "HrmKQGroup:Add"); + } + if(hrmFieldBean.getFieldname().equals("overtime_rule_id")){ + if(CollectionUtils.isNotEmpty(replaceDatas)){ + searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas); + } + } + if(hrmFieldBean.getFieldname().equals("overtime_type")){ + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(546300, user.getLanguage())); + } + itemlist.add(searchConditionItem); + } + groupitem.put("items", itemlist); + grouplist.add(groupitem); + } + retmap.put("formField", grouplist); + retmap.put("status", "1"); + int operatelevel = -1; + if(hrmdetachable){ + if(subcompanyid.length()>0 && !subcompanyid.equalsIgnoreCase("0")){ + CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight(); + operatelevel=checkSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(),"HrmKQGroup:Add",Util.getIntValue(subcompanyid,-1)); + } + }else{ + operatelevel = 2; + } + + if(user.getUID() == 1 || subcompanyid.length()==0 || subcompanyid.equalsIgnoreCase("0")){ + operatelevel = 2; + } + if(operatelevel > 0){ + retmap.put("canAdd", true); + }else{ + retmap.put("canAdd", false); + } + retmap.put("kqtype", kqtype); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + public String getKQLocationList(String locationname){ + String sessionKey = ""; + String groupId = Util.null2String(params.get("id")); + String backFields = " id,locationname,longitude,latitude,address,checkscope "; + String sqlFrom = " kq_location "; + String sqlWhere = " where groupid= "+groupId; + String orderby = " id " ; + String tableString = ""; + + if (locationname.length() > 0){ + sqlWhere += " and locationname like '%"+locationname+"%' "; + } + + String pageUid = PageUidFactory.getHrmPageUid("KQLocationList"); + + tableString=""+ + ""+ + ""+ + ""+ + " "+ + " "+ + " "+ + " "+ + " "+ + " "+ + ""+ + "
"; + + //主要用于 显示定制列以及 表格 每页展示记录数选择 + sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom()); + Util_TableMap.setVal(sessionKey, tableString); + + return sessionKey; + } + + public String getKQWifiList(String wifiname){ + String sessionKey = ""; + String groupId = Util.null2String(params.get("id")); + String backFields = " id,wifiname,mac "; + String sqlFrom = " kq_wifi "; + String sqlWhere = " where groupid= "+groupId; + String orderby = " id " ; + String tableString = ""; + + if (wifiname.length() > 0){ + sqlWhere += " and wifiname like '%"+wifiname+"%' "; + } + + String pageUid = PageUidFactory.getHrmPageUid("KQLocationList"); + + tableString=""+ + ""+ + ""+ + ""+ + " "+ + " "+ + " "+ + ""+ + "
"; + + //主要用于 显示定制列以及 表格 每页展示记录数选择 + sessionKey = pageUid + "_" + Util.getEncrypt(Util.getRandom()); + Util_TableMap.setVal(sessionKey, tableString); + + return sessionKey; + } + + /** + * 固定班制 + * @return + */ + public Map getFixedSchedulce(){ + Map fixedSchedulce = new HashMap<>(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String groupid = Util.null2String(params.get("id")); + //固定班次 + Map table = new HashMap(); + List columns = new ArrayList(); + Map column = null; + LinkedList> datas = new LinkedList>(); + Map data = null; + ShiftManagementToolKit shiftManagementToolKit = new ShiftManagementToolKit(); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(28387, user.getLanguage())); + column.put("dataIndex", "weekday"); + column.put("width", "30%"); + columns.add(column); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(388984, user.getLanguage())); + column.put("dataIndex", "serialinfo"); + column.put("width", "40%"); + columns.add(column); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(104, user.getLanguage())); + column.put("dataIndex", "operate"); + column.put("width", "30%"); + columns.add(column); + + if(groupid.length()>0){ + List lsWeeks = new ArrayList<>(); + + sql = " select * from kq_fixedschedulce where groupid = ? order by weekday asc "; + rs.executeQuery(sql,groupid); + while(rs.next()){ + data = new HashMap(); + data.put("id",rs.getString("id")); + data.put("weekday",UtilKQ.getWeekDay(rs.getInt("weekday"),user.getLanguage())); + data.put("serialid",rs.getString("serialid")); + data.put("serialinfo",shiftManagementToolKit.getShiftOnOffWorkSections(rs.getString("serialid"),user.getLanguage())); + datas.add(data); + lsWeeks.add(rs.getInt("weekday")); + } + + //加强性修改 + for(int i=0;i<7;i++){ + if(!lsWeeks.contains(i)){ + data = new HashMap(); + data.put("id",i); + data.put("weekday",UtilKQ.getWeekDay(i,user.getLanguage())); + data.put("serialid",""); + data.put("serialinfo",SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + datas.add(data); + } + } + }else{ + for(int i=0;i<7;i++){ + data = new HashMap(); + data.put("id",i); + data.put("weekday",UtilKQ.getWeekDay(i,user.getLanguage())); + data.put("serialid",""); + data.put("serialinfo",SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + datas.add(data); + } + } + fixedSchedulce.put("columns",columns); + fixedSchedulce.put("datas",datas); + + }catch (Exception e){ + writeLog(e); + } + return fixedSchedulce; + } + + /** + * 排班制 + * @return + */ + public Map getShiftSchedulceTable(){ + Map shiftSchedulce = new HashMap<>(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + String groupid = Util.null2String(params.get("id")); + //排班制 + List columns = new ArrayList(); + Map column = null; + LinkedList> datas = new LinkedList>(); + Map data = null; + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(388722, user.getLanguage())); + column.put("dataIndex", "shiftcyclename"); + column.put("width", "30%"); + columns.add(column); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(500480, user.getLanguage())); + column.put("dataIndex", "serial"); + column.put("width", "30%"); + columns.add(column); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(500481, user.getLanguage())); + column.put("dataIndex", "shiftcycleday"); + column.put("width", "20%"); + columns.add(column); + + column = new HashMap(); + column.put("title", SystemEnv.getHtmlLabelName(30585, user.getLanguage())); + column.put("dataIndex", "operate"); + column.put("width", "20%"); + columns.add(column); + + if(groupid.length()>0){ + sql = " select id,shiftcyclename,shiftcycleserialids,groupid from kq_group_shiftcycle where groupid = ? order by id asc "; + rs.executeQuery(sql,groupid); + while(rs.next()){ + data = new HashMap(); + data.put("id",rs.getString("id")); + data.put("shiftcyclename",rs.getString("shiftcyclename")); + data.put("serial",rs.getString("shiftcycleserialids")); + data.put("shiftcycleday",Util.splitString(Util.null2String(rs.getString("shiftcycleserialids")),",").length); + datas.add(data); + } + } + shiftSchedulce.put("columns",columns); + shiftSchedulce.put("datas",datas); + }catch (Exception e){ + writeLog(e); + } + return shiftSchedulce; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/group/SaveGroupCmd.java b/src/com/engine/kq/cmd/group/SaveGroupCmd.java new file mode 100644 index 0000000..73a7285 --- /dev/null +++ b/src/com/engine/kq/cmd/group/SaveGroupCmd.java @@ -0,0 +1,618 @@ +package com.engine.kq.cmd.group; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.constant.BizLogSmallType4Hrm; +import com.engine.common.constant.BizLogType; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQAutoCheckComInfo; +import com.engine.kq.biz.KQFixedSchedulceComInfo; +import com.engine.kq.biz.KQGroupComInfo; +import com.engine.kq.log.KQLog; +import weaver.conn.BatchRecordSet; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.proj.util.SQLUtil; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class SaveGroupCmd extends AbstractCommonCommand> { + + private SimpleBizLogger logger; + SimpleBizLogger.SubLogInfo subLogInfo; + SimpleBizLogger.SubLogInfo subLogInfo1; + public SaveGroupCmd(Map params, User user) { + this.user = user; + this.params = params; + + if (params != null && params.containsKey("data")) { + String datas = Util.null2String(params.get("data")); + JSONObject jsonObj = JSON.parseObject(datas); + String id = Util.null2String(jsonObj.get("id")); + if(id.length()==0) { + id = "-1"; + } + this.logger = new SimpleBizLogger(); + BizLogContext logContext = new BizLogContext(); + logContext.setDateObject(new Date()); + logContext.setLogType(BizLogType.HRM_ENGINE); + logContext.setBelongType(BizLogSmallType4Hrm.HRM_ENGINE_KQGROUP); + logContext.setLogSmallType(BizLogSmallType4Hrm.HRM_ENGINE_KQGROUP); + logContext.setParams(params); + logger.setUser(user);//当前操作人 + + String mainSql = " select * from kq_group where id= "+id; + logger.setMainSql(mainSql);//主表sql + logger.setMainPrimarykey("id");//主日志表唯一key + logger.setMainTargetNameColumn("groupname"); + + subLogInfo1 = logger.getNewSubLogInfo(); + String subSql1 = "select * from kq_fixedschedulce where groupid="+id; + subLogInfo1.setSubPrimarykey("id"); + subLogInfo1.setSubTargetNameColumn("weekday"); + subLogInfo1.setGroupId("0"); //所属分组, 按照groupid排序显示在详情中, 不设置默认按照add的顺序。 + subLogInfo1.setSubGroupNameLabel(505654); //在详情中显示的分组名称,不设置默认显示明细x + subLogInfo1.setSubSql(subSql1); + logger.addSubLogInfo(subLogInfo1); + + subLogInfo = logger.getNewSubLogInfo(); + String subSql = " select * from kq_group_shiftcycle where groupid = "+id; + subLogInfo.setSubSql(subSql); + subLogInfo.setSubPrimarykey("id"); + subLogInfo.setSubTargetNameColumn("shiftcyclename"); + subLogInfo.setGroupId("1"); //所属分组, 按照groupid排序显示在详情中, 不设置默认按照add的顺序。 + subLogInfo.setSubGroupNameLabel(389225); //在详情中显示的分组名称,不设置默认显示明细x + logger.addSubLogInfo(subLogInfo); + logger.before(logContext); + } + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + String sql = ""; + try{ + //必要的权限判断 + if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + + KQGroupComInfo kQGroupComInfo = new KQGroupComInfo(); + KQFixedSchedulceComInfo kqFixedSchedulceComInfo = new KQFixedSchedulceComInfo(); + new KQLog().info("SaveGroupCmd params:"+params); + String datas = Util.null2String(params.get("data")); + JSONObject jsonObj = JSON.parseObject(datas); + String tabKey = Util.null2String(params.get("tabKey"));//分组id + String id = Util.null2String(jsonObj.get("id"));//考勤组id + String groupname = Util.null2String(jsonObj.get("groupname"));//考勤组名称 + String overtimeType = Util.null2String(jsonObj.get("overtime_type"));//加班类型 + String overtimeRuleId = Util.null2String(jsonObj.get("overtime_rule_id"));//加班id + String kqtype = Util.null2String(jsonObj.get("kqtype"));//考勤类型 + String subcompanyid = Util.null2String(jsonObj.get("subcompanyid"));//所属分部 + String excludeid = Util.null2String(jsonObj.get("excludeid"));//考勤组排除人员 + String excludecount = Util.null2String(jsonObj.get("excludecount"));//考勤组排除人员是否参与统计 + String abnormalremind = Util.null2String(jsonObj.get("abnormalremind"));//考勤异常提醒 + String signintype = Util.null2String(jsonObj.get("signintype"));//打卡方式 + String serialids = Util.null2String(jsonObj.get("serialids"));//考勤班次 + String weekday = Util.null2String(jsonObj.get("weekday"));//考勤类型 + String signstart = Util.null2String(jsonObj.get("signstart"));//考勤类型 + String workhour = Util.null2String(jsonObj.get("workhour"));//工作时长 + String ipscope =Util.null2String( jsonObj.get("ipscope"));//应用IP范围 + String calmethod = Util.null2s(Util.null2String(jsonObj.get("calmethod")),"1");//工作时长计算方式 1是打卡时间累加计算 2是打卡时间成对计算 + + String ipscope_v4_pc =Util.null2String( jsonObj.get("ipscope_v4_pc"));//应用IP范围 ipv4 pc端 + String ipscope_v4_em =Util.null2String( jsonObj.get("ipscope_v4_em"));//应用IP范围 ipv4 移动端 + String ipscope_v6_pc =Util.null2String( jsonObj.get("ipscope_v6_pc"));//应用IP范围 ipv6 pc端 + String ipscope_v6_em =Util.null2String( jsonObj.get("ipscope_v6_em"));//应用IP范围 ipv6 移动端 + + String locationcheck = Util.null2String(jsonObj.get("locationcheck"));//启用办公地点考勤 + //String locationcheckscope = Util.null2String(jsonObj.get("locationcheckscope"));//有效范围 + String wificheck = Util.null2String(jsonObj.get("wificheck"));//启用wifi考勤 + String outsidesign = Util.null2String(jsonObj.get("outsidesign"));//允许外勤打卡 + String outsignapprove = Util.null2String(jsonObj.get("outsignapprove"));//外勤打卡需要审批 + String validity = Util.null2String(jsonObj.get("validity"));//考勤组有效期 + String validityfromdate = Util.null2String(jsonObj.get("validityfromdate"));//考勤组有效期开始时间 + String validityenddate = Util.null2String(jsonObj.get("validityenddate"));//考勤组有效期结束时间 + String locationfacecheck = Util.null2String(jsonObj.getString("locationfacecheck"));//办公地点启用人脸识别拍照打卡 + String locationfacechecktype = Util.null2String(jsonObj.getString("locationfacechecktype"));//办公地点启用人脸识别拍照打卡方式 + String locationshowaddress = Util.null2String(jsonObj.getString("locationshowaddress"));//有效识别半径内显示同一地址 + String wififacecheck = Util.null2String(jsonObj.getString("wififacecheck"));//wifi启用人脸识别拍照打卡 + String wififacechecktype = Util.null2String(jsonObj.getString("wififacechecktype"));//wifi启用人脸识别拍照打卡方式 + String self_shift = Util.null2String(jsonObj.getString("self_shift"));//启用员工自我排班 + String auto_checkin = Util.null2String(jsonObj.getString("auto_checkin"));//允许客户端设置自动考勤 上班卡 + String auto_checkout = Util.null2String(jsonObj.getString("auto_checkout"));//允许客户端设置自动考勤 下班卡 + String auto_checkin_before = Util.null2String(jsonObj.getString("auto_checkin_before"));//允许客户端设置自动考勤 上班卡开始分钟数 + String auto_checkin_after = Util.null2String(jsonObj.getString("auto_checkin_after"));//允许客户端设置自动考勤 上班卡结束分钟时 + String auto_checkout_before = Util.null2String(jsonObj.getString("auto_checkout_before"));//允许客户端设置自动考勤 下班卡 下班卡开始分钟数 + String auto_checkout_after = Util.null2String(jsonObj.getString("auto_checkout_after"));//允许客户端设置自动考勤 下班卡 下班卡结束分钟时 + String isPhotoPunchEnabled = Util.null2String(jsonObj.getString("isPhotoPunchEnabled"));//启用考勤拍照打卡 + String pbcheck = Util.null2String(jsonObj.getString("pbcheck"));//启用考勤拍照打卡 + + if("".equals(id)) { + sql = "select * from kq_group where groupname=? and (isDelete is null or isDelete !=1) "; + rs.executeQuery(sql, groupname); + } else { + sql = "select * from kq_group where groupname=? and id != ? and (isDelete is null or isDelete !=1) "; + rs.executeQuery(sql, groupname, id); + } + if(rs.next()) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(531673, user.getLanguage())); + return retmap; + } + + if("1".equalsIgnoreCase(signintype) || "3".equalsIgnoreCase(signintype)){ + //如果有移动端打卡,但是办公地点和wifi都没开启,也把自动打卡重置 + if(!"1".equalsIgnoreCase(locationcheck) && !"1".equalsIgnoreCase(wificheck)){ + auto_checkin = "0"; + auto_checkout = "0"; + auto_checkin_before = "30"; + auto_checkin_after = "30"; + auto_checkout_before = "5"; + auto_checkout_after = "60"; + } + }else{ + //如果不是移动端打卡,需要把自动打卡重置 + auto_checkin = "0"; + auto_checkout = "0"; + auto_checkin_before = "30"; + auto_checkin_after = "30"; + auto_checkout_before = "5"; + auto_checkout_after = "60"; + } + + List lsParams = new ArrayList<>(); + if(tabKey.equals("1")){ + if(id.length()>0) { + sql = " update kq_group set groupname=?,subcompanyid=?,excludeid=?,excludecount=?,abnormalremind=?,kqtype=?," + + " serialids=?,weekday=?,signstart=?,workhour=?,validity=?,validityfromdate=?,validityenddate=?,self_shift=?,calmethod=?,overtime_type=?,pbcheck=? " + + " where id=? "; + lsParams.add(groupname.length()==0?null:groupname); + lsParams.add(subcompanyid.length()==0?null:subcompanyid); + lsParams.add(excludeid.length()==0?null:excludeid); + lsParams.add(excludecount.length()==0?null:excludecount); + lsParams.add(abnormalremind.length()==0?null:abnormalremind); + lsParams.add(kqtype.length()==0?null:kqtype); + lsParams.add(serialids.length()==0?null:serialids); + lsParams.add(weekday.length()==0?null:weekday); + lsParams.add(signstart.length()==0?null:signstart); + lsParams.add(workhour.length()==0?null:workhour); + lsParams.add(validity.length()==0?null:validity); + lsParams.add(validityfromdate.length()==0?null:validityfromdate); + lsParams.add(validityenddate.length()==0?null:validityenddate); + lsParams.add(self_shift.length()==0?0:self_shift); + lsParams.add(calmethod.length()==0?"1":calmethod); + lsParams.add(overtimeType.length()==0?"0":overtimeType); + lsParams.add(pbcheck.length()==0?"1":pbcheck); + lsParams.add(id); + rs.executeUpdate(sql,lsParams); + if(kqtype.equals("2")){ + this.saveKqTypeInfo(); + } + + }else { + sql = " insert into kq_group (" + + " groupname,subcompanyid,excludeid,excludecount,abnormalremind,kqtype,serialids," + + " weekday,signstart,workhour,signintype,validity,validityfromdate,validityenddate,locationcheckscope,calmethod,overtime_type,self_shift,pbcheck) " + + " values(?,?,?,?,?,?,?, ?,?,?,1,?,?,?,300,?,?,?,?)"; + lsParams.add(groupname.length()==0?null:groupname); + lsParams.add(subcompanyid.length()==0?null:subcompanyid); + lsParams.add(excludeid.length()==0?null:excludeid); + lsParams.add(excludecount.length()==0?null:excludecount); + lsParams.add(abnormalremind.length()==0?null:abnormalremind); + lsParams.add(kqtype.length()==0?null:kqtype); + lsParams.add(serialids.length()==0?null:serialids); + + lsParams.add(weekday.length()==0?null:weekday); + lsParams.add(signstart.length()==0?null:signstart); + lsParams.add(workhour.length()==0?null:workhour); + lsParams.add(validity.length()==0?null:validity); + lsParams.add(validityfromdate.length()==0?null:validityfromdate); + lsParams.add(validityenddate.length()==0?null:validityenddate); + lsParams.add(calmethod.length()==0?"1":calmethod); + lsParams.add(overtimeType.length()==0?"0":overtimeType); + lsParams.add(self_shift.length()==0?"0":self_shift); + lsParams.add(pbcheck.length()==0?"1":pbcheck); + rs.executeUpdate(sql,lsParams); + + rs.executeQuery("select max(id) from kq_group") ; + if(rs.next()){ + id = rs.getString(1); + } + } + params.put("id",id); + this.saveKqTypeInfo(); + + updateOverByGroupId(id,overtimeRuleId,overtimeType); + }else if(tabKey.equals("2")){ + sql = " update kq_group set signintype=?, ipscope_v4_pc=?,ipscope_v4_em=?,ipscope_v6_pc=?,ipscope_v6_em=?,locationcheck=?,wificheck=?,outsidesign=?,outsignapprove=?, " +//locationcheckscope=?, + " locationfacecheck=?,locationfacechecktype=?,locationshowaddress=?,wififacecheck=?,wififacechecktype=?,auto_checkin=?,auto_checkout=?," + + " auto_checkin_before=?,auto_checkin_after=?,auto_checkout_before=?,auto_checkout_after=?,isPhotoPunchEnabled=? where id=? "; + lsParams.add(signintype.length()==0?null:signintype); + lsParams.add(ipscope_v4_pc.length()==0?null:ipscope_v4_pc); + lsParams.add(ipscope_v4_em.length()==0?null:ipscope_v4_em); + lsParams.add(ipscope_v6_pc.length()==0?null:ipscope_v6_pc); + lsParams.add(ipscope_v6_em.length()==0?null:ipscope_v6_em); + lsParams.add(locationcheck.length()==0?null:locationcheck); + //lsParams.add(locationcheckscope.length()==0?null:locationcheckscope); + lsParams.add(wificheck.length()==0?null:wificheck); + lsParams.add(outsidesign.length()==0?null:outsidesign); + lsParams.add(outsignapprove.length()==0?null:outsignapprove); + lsParams.add(locationfacecheck.length()==0?null:locationfacecheck); + lsParams.add(locationfacechecktype.length()==0?null:locationfacechecktype); + lsParams.add(locationshowaddress.length()==0?null:locationshowaddress); + lsParams.add(wififacecheck.length()==0?null:wififacecheck); + lsParams.add(wififacechecktype.length()==0?null:wififacechecktype); + lsParams.add(auto_checkin.length()==0?0:auto_checkin); + lsParams.add(auto_checkout.length()==0?0:auto_checkout); + lsParams.add(auto_checkin_before.length()==0?30:auto_checkin_before); + lsParams.add(auto_checkin_after.length()==0?30:auto_checkin_after); + lsParams.add(auto_checkout_before.length()==0?5:auto_checkout_before); + lsParams.add(auto_checkout_after.length()==0?60:auto_checkout_after); + lsParams.add(isPhotoPunchEnabled.length()==0?0:isPhotoPunchEnabled); + String ori_auto_checkin = kQGroupComInfo.getAuto_checkin(id); + String ori_auto_checkout = kQGroupComInfo.getAuto_checkout(id); + + //关于自动打卡开启或者关闭后的一些逻辑处理 + group_auto_check(id,auto_checkin,auto_checkout,ori_auto_checkin,ori_auto_checkout,retmap,kQGroupComInfo,locationcheck,wificheck,locationfacecheck,wififacecheck); + if(!retmap.isEmpty()){ + return retmap; + } + + lsParams.add(id); + rs.executeUpdate(sql,lsParams); + } + + kQGroupComInfo.removeCache(); + if(kqtype.equals("1")){ + kqFixedSchedulceComInfo.removeCache(); + } + + String mainSql = " select * from kq_group where id= "+id; + logger.setMainSql(mainSql);//主表sql + + String subSql1 = "select * from kq_fixedschedulce where groupid= "+id; + subLogInfo1.setSubSql(subSql1); + + String subSql = " select * from kq_group_shiftcycle where groupid = "+id; + subLogInfo.setSubSql(subSql); + + retmap.put("id", id); + retmap.put("status", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage())); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + /** + * 更新加班规则 + */ + private void updateOverByGroupId(String id, String overtimeRuleId, String overtimeType) { + RecordSet rs = new RecordSet(); + RecordSet rs1 = new RecordSet(); + + if(id.length() > 0){ + //更新的情况 + //先根据考勤规则id查询一下原加班规则 + String dbtype = rs.getDBType(); + String overSql = "select * from kq_overtimerules where ','+convert(varchar(2000),groupids)+',' like ? and (isDelete is null or isDelete!=1) "; + if ("oracle".equalsIgnoreCase(dbtype)) { + overSql = "select * from kq_overtimerules where "+ SQLUtil.filteSql(rs.getDBType(), " ','+groupids+',' like ? and (isDelete is null or isDelete!=1) "); + }else if("mysql".equalsIgnoreCase(dbtype)){ + overSql = "select * from kq_overtimerules where CONCAT(',',cast(groupids as char),',') like ? and (isDelete is null or isDelete!=1) "; + }else if ("postgresql".equalsIgnoreCase(dbtype)) { + overSql = "select * from kq_overtimerules where CONCAT(',',groupids,',') like ? and (isDelete is null or isDelete!=1) "; + } + rs.executeQuery(overSql,"%,"+id+",%"); + String preOverId = ""; + String overGroupIds = ""; + if(rs.next()) { + preOverId = rs.getString("id"); + String groupids = rs.getString("groupids"); + if(groupids.length() > 0){ + String[] groupidsArr = groupids.split(","); + if(groupidsArr.length > 0){ + for (int i = 0; i < groupidsArr.length; i++) { + String gId = groupidsArr[i]; + if(gId.equals(id)){ + continue; + } + if(overGroupIds.length() == 0){ + overGroupIds = gId; + }else{ + overGroupIds += ","+gId; + } + } + } + } + } + //先把原加班规则里的当前考勤规则剔除掉 + if(preOverId.length() > 0){ + String updateOverSql = "update kq_overtimerules set groupids=? where id = ?"; + rs1.executeUpdate(updateOverSql,overGroupIds,preOverId); + } + }else{ + //新增的情况 + } + //再根据传入的新的加班规则查一下有的考勤规则id + if("0".equals(overtimeType)){ + //只有是考勤组关联加班规则的时候才有这个逻辑 + if(overtimeRuleId.length() > 0){ + String getSql = "select * from kq_overtimerules where id=?"; + rs.executeQuery(getSql,overtimeRuleId); + if(rs.next()){ + String groupids = Util.null2s(rs.getString("groupids"),""); + if(groupids.length() > 0){ + groupids += ","+id; + }else { + groupids = id; + } + String updateOverSql = "update kq_overtimerules set groupids=? where id = ?"; + rs1.executeUpdate(updateOverSql,groupids,overtimeRuleId); + } + } + } + } + + /** + * 关于自动打卡开启或者关闭后的一些逻辑处理 + * @param id + * @param auto_checkin + * @param auto_checkout + * @param ori_auto_checkin + * @param ori_auto_checkout + * @param retmap + * @param kQGroupComInfo + * @param locationcheck + * @param wificheck + */ + public void group_auto_check(String id, String auto_checkin, String auto_checkout, + String ori_auto_checkin, String ori_auto_checkout, + Map retmap, KQGroupComInfo kQGroupComInfo, String locationcheck, + String wificheck, String locationfacecheck, String wififacecheck) { + KQAutoCheckComInfo kqAutoCheckComInfo = new KQAutoCheckComInfo(); + RecordSet rs = new RecordSet(); + + if(!"1".equalsIgnoreCase(auto_checkin) && !"1".equalsIgnoreCase(auto_checkout)){ + //如果自动打卡 都关闭了,那么自定义设置的也需要被清空 + String del_cus_autoset = "delete from kq_autocheck_set where groupid = ? "; + rs.executeUpdate(del_cus_autoset,id); + kqAutoCheckComInfo.removeCache(); + }else{ + String tmp_kqtype = kQGroupComInfo.getKqtype(id); + if("3".equalsIgnoreCase(tmp_kqtype)){ + //如果是弹性工作制 + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(519990,user.getLanguage())); + } + boolean has_location_list = has_location_list(id); + boolean has_wifi_list = has_wifi_list(id); + if("1".equalsIgnoreCase(locationcheck)){ + //地理位置的开关开启了 + if("1".equalsIgnoreCase(wificheck)){ + //wifi的开关开启了 + if(!has_location_list && !has_wifi_list){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage())); + } + if("1".equalsIgnoreCase(wififacecheck)){ + //如果开启了人脸打卡 + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage())); + } + }else{ + if(!has_location_list){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage())); + } + } + if("1".equalsIgnoreCase(locationfacecheck)){ + //如果开启了人脸打卡 + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage())); + } + }else{ + //地理位置没开启 + if("1".equalsIgnoreCase(wificheck)){ + //wifi的开关开启了 + if(!has_wifi_list){ + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(519989,user.getLanguage())); + } + if("1".equalsIgnoreCase(wififacecheck)){ + //如果开启了人脸打卡 + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(521384,user.getLanguage())); + } + } + } + + if(!ori_auto_checkin.equalsIgnoreCase(auto_checkin)){ + //如果上班自动打卡变化了,需要去更新掉自定义的设置 + String up_cus_autoset = "update kq_autocheck_set set auto_checkin=? where groupid = ? "; + rs.executeUpdate(up_cus_autoset, auto_checkin,id); + } + if(!ori_auto_checkout.equalsIgnoreCase(ori_auto_checkout)){ + //如果下班自动打卡变化了,需要去更新掉自定义的设置 + String up_cus_autoset = "update kq_autocheck_set set auto_checkout=? where groupid = ? "; + rs.executeUpdate(up_cus_autoset, auto_checkout,id); + } + kqAutoCheckComInfo.removeCache(); + } + } + + /** + * 判断当前考勤组是否有考勤wifi列表 + * @param id + * @return + */ + public boolean has_wifi_list(String id) { + RecordSet rs = new RecordSet(); + String wifi_list_sql = "select 1 from kq_wifi where groupid = ? "; + rs.executeQuery(wifi_list_sql,id); + if(!rs.next()){ + return false; + } + return true; + } + + /** + * 判断当前考勤组是否有考勤地理位置列表 + * @param id + * @return + */ + public boolean has_location_list(String id) { + + RecordSet rs = new RecordSet(); + String location_list_sql = "select 1 from kq_location where groupid = ? "; + rs.executeQuery(location_list_sql,id); + if(!rs.next()){ + return false; + } + return true; + } + + private Map saveKqTypeInfo(){ + Map kqTypeInfo = new HashMap<>(); + RecordSet rs = new RecordSet(); + BatchRecordSet batchRecordSet = new BatchRecordSet(); + String sql = ""; + try{ + String groupid = Util.null2String(params.get("id")); + JSONObject jsonObj = JSON.parseObject(Util.null2String(params.get("data"))); + String kqtype = Util.null2String(jsonObj.get("kqtype"));//考勤类型 + + if(kqtype.equals("1")){//固定班次 + JSONArray fixedSchedulce = jsonObj.getJSONArray("fixedSchedulce");//固定班次明细表 + + if(fixedSchedulce==null || fixedSchedulce.size()>7) return kqTypeInfo; + for(int i=0;fixedSchedulce!=null&&i0){ + sql = "update kq_fixedschedulce set serialid =? where id=? "; + rs.executeUpdate(sql,serialid.length()==0?null:serialid,id); + }else{ + sql = "insert into kq_fixedschedulce(weekday,serialid,groupid) values(?,?,?)"; + rs.executeUpdate(sql,weekday,serialid.length()==0?null:serialid,groupid); + } + } + } + else if(kqtype.equals("2")){//排班制 + JSONArray shiftSchedulce = jsonObj.getJSONArray("shiftSchedulce");//固定班次明细表 + + List lsDelete = new ArrayList<>(); + sql = " select id from kq_group_shiftcycle where groupid = ? "; + rs.executeQuery(sql, groupid); + while(rs.next()){ + lsDelete.add(rs.getString("id")); + } + + List> paramUpdate = new ArrayList<>(); + List> paramInsert = new ArrayList<>(); + List shiftSchedulceParams = null; + for(int i=0;shiftSchedulce!=null&&i(); + if(id.length()>0){ + shiftSchedulceParams.add(shiftcyclename); + shiftSchedulceParams.add(shiftcycleday); + shiftSchedulceParams.add(shiftcycleserialids); + shiftSchedulceParams.add(id); + paramUpdate.add(shiftSchedulceParams); + lsDelete.remove(id); + }else{ + shiftSchedulceParams.add(shiftcyclename); + shiftSchedulceParams.add(shiftcycleday); + shiftSchedulceParams.add(shiftcycleserialids); + shiftSchedulceParams.add(groupid); + paramInsert.add(shiftSchedulceParams); + } + } + sql = " update kq_group_shiftcycle set shiftcyclename=?, shiftcycleday=?,shiftcycleserialids=? where id = ? "; + batchRecordSet.executeBatchSql(sql, paramUpdate); + + sql = " insert into kq_group_shiftcycle (shiftcyclename, shiftcycleday, shiftcycleserialids,groupid) values (?,?,?,?)"; + batchRecordSet.executeBatchSql(sql, paramInsert); + + for(int i=0;i> lsParams = new ArrayList>(); +// for(int i=0;i params = new ArrayList(); +// params.add(weekdays[i]); +// params.add(signstart); +// params.add(groupid); +// lsParams.add(params); +// } +// } +// } +// if(lsParams.size()>0){ +// sql = "insert into kq_freeschedulce(weekday,signstart,groupid) values(?,?,?)"; +// rs.executeUpdate(sql,lsParams); +// } +// } + }catch (Exception e){ + writeLog(e); + } + return kqTypeInfo; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } +} diff --git a/src/com/engine/kq/cmd/holidaySet/GetHolidaySetFormCmd.java b/src/com/engine/kq/cmd/holidaySet/GetHolidaySetFormCmd.java new file mode 100644 index 0000000..178db70 --- /dev/null +++ b/src/com/engine/kq/cmd/holidaySet/GetHolidaySetFormCmd.java @@ -0,0 +1,238 @@ +package com.engine.kq.cmd.holidaySet; + +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.util.HrmFieldSearchConditionComInfo; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.biz.KQGroupComInfo; +import weaver.conn.RecordSet; +import weaver.filter.XssUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.country.CountryComInfo; +import weaver.hrm.moduledetach.ManageDetachComInfo; +import weaver.systeminfo.SystemEnv; +import weaver.systeminfo.systemright.CheckSubCompanyRight; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 节假日设置--新建或编辑的表单 + */ +public class GetHolidaySetFormCmd extends AbstractCommonCommand> { + + public GetHolidaySetFormCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public Map execute(CommandContext commandContext) { + Map resultMap = new HashMap(); + String id = Util.null2String(params.get("id"));//ID + String groupId = Util.null2String(params.get("groupId"));//考勤组的ID + String holidayDate = Util.null2String(params.get("holidayDate"));//节假日日期 + String holidayDesc = "";//说明 + String changeType = "1";//类型:1-公众假日、2-调配工作日、3-调配休息日 + String relatedDay = "";//对应工作日:0-星期一、1-星期二、2-星期三、3-星期四、4-星期五、5-星期六、6-星期日 + String shiftId = "";//班次ID + + /*参数有误*/ + if (id.equals("") && groupId.equals("")) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(388858, user.getLanguage())); + return resultMap; + } + + /*是否具有编辑的权限*/ + boolean canEdit = HrmUserVarify.checkUserRight("KQHolidaySetEdit:Edit", user); + if (!canEdit) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return resultMap; + } + + List> groupList = new ArrayList>(); + Map groupItem = new HashMap(); + List itemList = new ArrayList(); + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + SearchConditionItem searchConditionItem = null; + HrmFieldBean hrmFieldBean = null; + List> replaceDatas = new ArrayList>(); + Map datas = new HashMap(); + + boolean isEdit = false; + if (!id.equals("")) { + String sql = "select * from kq_HolidaySet where id=" + id; + RecordSet recordSet = new RecordSet(); + recordSet.executeQuery(sql); + if (recordSet.next()) { + isEdit = true; + holidayDate = recordSet.getString("holidayDate"); + groupId = recordSet.getString("groupId"); + holidayDesc = recordSet.getString("holidayDesc"); + changeType = recordSet.getString("changeType"); + relatedDay = recordSet.getString("relatedDay"); + shiftId = recordSet.getString("shiftId"); + } + } + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("groupId");//考勤组 + hrmFieldBean.setFieldlabel("390221"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("kqgroup"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(1); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + replaceDatas = new ArrayList>(); + datas = new HashMap(); + datas.put("id", groupId); + datas.put("name", kqGroupComInfo.getGroupname(groupId)); + replaceDatas.add(datas); + searchConditionItem.getBrowserConditionParam().setReplaceDatas(replaceDatas); + Map OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + searchConditionItem.setRules("required|string"); + itemList.add(searchConditionItem); + + if (isEdit) { + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("holidayDate");//日期 + hrmFieldBean.setFieldlabel("97"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(holidayDate); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(1); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + searchConditionItem.setRules("required|string"); + itemList.add(searchConditionItem); + } else { + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("startDate");//开始日期 + hrmFieldBean.setFieldlabel("740"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(holidayDate); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|string"); + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("endDate");//结束日期 + hrmFieldBean.setFieldlabel("741"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setFieldvalue(holidayDate); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|string"); + itemList.add(searchConditionItem); + } + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("holidayDesc");//说明 + hrmFieldBean.setFieldlabel("85"); + hrmFieldBean.setFieldhtmltype("1"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(holidayDesc); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + if (hrmFieldBean.getViewAttr() == 1) { + OtherParamsMap = new HashMap(); + OtherParamsMap.put("hasBorder", true); + searchConditionItem.setOtherParams(OtherParamsMap); + } + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("changeType");//类型 + hrmFieldBean.setFieldlabel("132033"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(changeType); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + List statusOptions = new ArrayList(); + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(16478, user.getLanguage()), changeType.equals("1"))); + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(16752, user.getLanguage()), changeType.equals("3"))); + if (!Util.null2String(kqGroupComInfo.getKqtype(groupId)).equals("2")) { + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(16751, user.getLanguage()), changeType.equals("2"))); + } + searchConditionItem.setOptions(statusOptions); + searchConditionItem.setHelpfulTip(SystemEnv.getHtmlLabelName(529901, user.getLanguage())); + searchConditionItem.setDetailtype(3); + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("relatedDay");//对应工作日 + hrmFieldBean.setFieldlabel("16754"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue(relatedDay); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + statusOptions = new ArrayList(); + statusOptions.add(new SearchConditionOption("0", SystemEnv.getHtmlLabelName(392, user.getLanguage()), relatedDay.equals("0") || relatedDay.equals(""))); + statusOptions.add(new SearchConditionOption("1", SystemEnv.getHtmlLabelName(393, user.getLanguage()), relatedDay.equals("1"))); + statusOptions.add(new SearchConditionOption("2", SystemEnv.getHtmlLabelName(394, user.getLanguage()), relatedDay.equals("2"))); + statusOptions.add(new SearchConditionOption("3", SystemEnv.getHtmlLabelName(395, user.getLanguage()), relatedDay.equals("3"))); + statusOptions.add(new SearchConditionOption("4", SystemEnv.getHtmlLabelName(396, user.getLanguage()), relatedDay.equals("4"))); + statusOptions.add(new SearchConditionOption("5", SystemEnv.getHtmlLabelName(397, user.getLanguage()), relatedDay.equals("5"))); + statusOptions.add(new SearchConditionOption("6", SystemEnv.getHtmlLabelName(398, user.getLanguage()), relatedDay.equals("6"))); + searchConditionItem.setOptions(statusOptions); + itemList.add(searchConditionItem); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("isSync");//同步到其他考勤组 + hrmFieldBean.setFieldlabel("506392"); + hrmFieldBean.setFieldhtmltype("4"); + hrmFieldBean.setType("1"); + hrmFieldBean.setIsFormField(true); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + Map otherParamsMap = new HashMap(); + otherParamsMap.put("display", "switch"); + searchConditionItem.setOtherParams(otherParamsMap); + itemList.add(searchConditionItem); + +// XssUtil xssUtil = new XssUtil(); + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("syncGroupIds");//同步到考勤组--多选 + hrmFieldBean.setFieldlabel("390664"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("mkqgroup"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(3); + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user); + searchConditionItem.setRules("required|string"); + Map dataMap = new HashMap(); +// dataMap.put("sqlWhere",xssUtil.put(" kqtype!=2 ")); + searchConditionItem.getBrowserConditionParam().setDataParams(dataMap); + itemList.add(searchConditionItem); + + groupItem.put("items", itemList); + groupList.add(groupItem); + resultMap.put("condition", groupList); + return resultMap; + } +} diff --git a/src/com/engine/kq/cmd/myattendance/GetHrmKQReportInfoCmd.java b/src/com/engine/kq/cmd/myattendance/GetHrmKQReportInfoCmd.java new file mode 100644 index 0000000..76fe495 --- /dev/null +++ b/src/com/engine/kq/cmd/myattendance/GetHrmKQReportInfoCmd.java @@ -0,0 +1,446 @@ +package com.engine.kq.cmd.myattendance; + +import com.alibaba.fastjson.JSON; +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.entity.WorkTimeEntity; +import weaver.common.DateUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; +import org.apache.commons.lang3.StringUtils; + +import java.util.*; + +/** + * 前台--人事--我的考勤 + */ +public class GetHrmKQReportInfoCmd extends AbstractCommonCommand> { + + public GetHrmKQReportInfoCmd(Map params, User user) { + this.user = user; + this.params = params; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + private static boolean isIndirectSuperId(String id,String checkSuperId,ResourceComInfo info){ + + int loopBreakTimes = 20 ; + for(String loopId = id; + isRightResourceId(loopId) && (loopBreakTimes--)>0 ; + loopId = info.getManagerID(loopId)){ + if(isDirectSuperId(loopId,checkSuperId,info)) return true ; + } + return false ; + } + + private static boolean isDirectSuperId(String id,String checkSuperId,ResourceComInfo info){ + String superId = Util.null2String(info.getManagerID(id)) ; + return isRightResourceId(superId) && superId.equals(checkSuperId) ; + } + + private static boolean isRightResourceId(String id){ + return StringUtils.isNotBlank(id) && !"0".equals(id) ; + } + + @Override + public Map execute(CommandContext commandContext) { + Map resultMap = new HashMap(); + try { + ResourceComInfo resourceComInfo = new ResourceComInfo(); + /** + * 判断是否有权限 + */ + int subCompanyId = Util.getIntValue((String) params.get("subCompanyId"), 0); + int departmentId = Util.getIntValue((String) params.get("departmentId"), 0); + String resourceId = Util.null2String(params.get("resourceId")); + if (resourceId.equals("")) { + resourceId = "" + user.getUID(); + } + String lastName = resourceComInfo.getResourcename(resourceId); + if (resourceId.equals("" + user.getUID())) { + resultMap.put("title", SystemEnv.getHtmlLabelName(513095, user.getLanguage())); + } else { + resultMap.put("title", SystemEnv.getHtmlLabelName(515562, user.getLanguage()).replace("{name}", lastName)); + } + if (subCompanyId == 0 || departmentId == 0) { + subCompanyId = Util.getIntValue(resourceComInfo.getSubCompanyID(resourceId), 0); + departmentId = Util.getIntValue(resourceComInfo.getDepartmentID(resourceId), 0); + } + if (!resourceId.equals("" + user.getUID()) && !isIndirectSuperId(resourceId, user.getUID() + "", resourceComInfo) && !HrmUserVarify.checkUserRight("HrmResource:Absense", user, departmentId)) { + resultMap.put("status", "-1"); + resultMap.put("hasRight", false); + return resultMap; + } + String fromDate = Util.null2String(params.get("fromDate")); + String toDate = Util.null2String(params.get("toDate")); + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1"); + String realFromDate = getRealDate.get("fromDate"); + String realToDate = getRealDate.get("toDate"); + if("-1".equals(realFromDate) || "-1".equals(realToDate)) { + resultMap.put("status", "-1"); + resultMap.put("message", SystemEnv.getHtmlLabelName(543747, user.getLanguage())); + return resultMap; + } + + Calendar today = Calendar.getInstance(); + /**今年*/ + String currentDate = Util.add0(today.get(Calendar.YEAR), 4) + "-" + + Util.add0(today.get(Calendar.MONTH) + 1, 2) + "-" + + Util.add0(today.get(Calendar.DAY_OF_MONTH), 2); + /**上一年*/ + String lastYearDate = Util.add0(today.get(Calendar.YEAR) - 1, 4) + "-12-31"; + + + String currentYear = currentDate.substring(0,4); + String balanceDate = currentDate; + String typevalue = Util.null2String(params.get("typevalue"));//指定的年份或者指定的月份 + String type = Util.null2String(params.get("type"));//是查看一年的数据还是一月的数据:1-年、2-月 + if (type.equals("1")) {//年 + if (typevalue.length() == 0 || typevalue.length() != 4) { + typevalue = DateUtil.getYear(); + } + if(typevalue.compareTo(currentYear)<0){ + balanceDate = typevalue + "-12-31"; + }else if(typevalue.compareTo(currentYear)==0){ + balanceDate = currentDate; + }else if(typevalue.compareTo(currentYear)>0){ + balanceDate = typevalue + "-01-01"; + } + } else if (type.equals("2")) {//月 + if (typevalue.length() == 0) { + typevalue = DateUtil.getYear() + "-" + DateUtil.getMonth(); + } + balanceDate = typevalue + "-01"; + } + + + + /** + * 拼凑前端所属数据格式 + */ + Map groupMap = new HashMap(); + List groupItemList = new ArrayList(); + Map groupItem = new HashMap(); + List itemList = new ArrayList(); + Map itemMap = new HashMap(); + List itemList5 = new ArrayList(); + Map groupItem5 = new HashMap(); + /** + * 出勤统计 + * workDays:应出勤天数 + * realWorkDays:实际出勤天数 + * leaveDays:缺勤天数 + */ + double workDays = 0.00; + double realWorkDays = 0.00; + double leaveDays = 0.00; + /** + * beLate:迟到次数 + * graveBeLate;严重迟到次数 + * leaveEearly:早退次数 + * graveLeaveEarly:严重迟到次数 + * absenteeism:旷工次数 + * forgotCheck:漏签次数 + */ + int beLate = 0; + int graveBeLate = 0; + int leaveEearly = 0; + int graveLeaveEarly = 0; + int absenteeism = 0; + int forgotCheck = 0; + /** + * or_minimumUnit:最小加班单位 + * or_unitName:(小时)/(天) + * tr_minimumUnit:最小出差单位 + * tr_unitName:(小时)/(天) + * er_minimumUnit:最小公出单位 + * er_unitName:(小时)/(天) + */ + int or_minimumUnit = KQOvertimeRulesBiz.getMinimumUnit();//最小加班单位 + String or_unitName = (or_minimumUnit == 3 || or_minimumUnit == 5 || or_minimumUnit == 6) ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage()); + KQTravelRulesComInfo kqTravelRulesComInfo = new KQTravelRulesComInfo(); + int tr_minimumUnit = Util.getIntValue(kqTravelRulesComInfo.getMinimumUnit("1"));//最小出差单位 + String tr_unitName = tr_minimumUnit == 3 ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage()); + KQExitRulesComInfo kqExitRulesComInfo = new KQExitRulesComInfo(); + int er_minimumUnit = Util.getIntValue(kqExitRulesComInfo.getMinimumUnit("1"));//最小公出单位 + String er_unitName = er_minimumUnit == 3 ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage()); + /** + * overtimeTotal:加班时长 + * businessLeave:出差时长 + * officialBusiness:公出时长 + */ + double overtimeTotal = 0.00;//加班时长 + double businessLeave = 0.00;//出差时长 + double officialBusiness = 0.00;//公出时长 + /** + * 记录请假时长(考虑到人员调整部门之后,考勤汇总报表会存在两条记录,用于累计请假时长) + */ + KQLeaveRulesComInfo rulesComInfo = new KQLeaveRulesComInfo(); + Map leaveMap = new HashMap(); + /** + * 获取考勤的相关统计数据,数据来源于考勤汇总报表,在service层调用了考勤汇总报表的接口重新封装了数据传入此接口 + * 调用的考勤汇总报表的接口为:com/engine/kq/cmd/report/GetKQReportCmd.java + */ + List> datasList = new ArrayList>(); + Map datasMap = new HashMap<>(); + + datasList = (List>) params.get("datas"); + boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + for (int i = 0; datasList != null && i < datasList.size(); i++) { + datasMap = (Map) datasList.get(i); + //String rowSpan = Util.null2String(datasMap.get("rowSpan")); + //if ("2".equalsIgnoreCase(rowSpan)) { + // 如果是开启了半天开关,那么就不可能是一天多次上下班,所以这里直接显示第一次结果就行了 + if(isKqReportHalfOpen && i>0) { + break; + } + workDays += Util.getDoubleValue((String) datasMap.get("workdays"), 0.00);//应出勤天数 + realWorkDays += Util.getDoubleValue((String) datasMap.get("attendancedays"), 0.00);//实际出勤天数 + leaveDays = workDays - realWorkDays;//缺勤天数 + + beLate += Util.getIntValue((String) datasMap.get("beLate"), 0);//迟到次数 + graveBeLate += Util.getIntValue((String) datasMap.get("graveBeLate"), 0);//严重迟到次数 + leaveEearly += Util.getIntValue((String) datasMap.get("leaveEearly"), 0);//早退次数 + graveLeaveEarly += Util.getIntValue((String) datasMap.get("graveLeaveEarly"), 0);//严重迟到次数 + absenteeism += Util.getIntValue((String) datasMap.get("absenteeism"), 0);//旷工次数 + forgotCheck += Util.getIntValue((String) datasMap.get("forgotCheck"), 0);//漏签次数 + + overtimeTotal += Util.getDoubleValue((String) datasMap.get("overtimeTotal"), 0.00);//加班时长 + businessLeave += Util.getDoubleValue((String) datasMap.get("businessLeave"), 0.00);//出差时长 + officialBusiness += Util.getDoubleValue((String) datasMap.get("officialBusiness"), 0.00);//公出时长 + + rulesComInfo.setTofirstRow(); + while (i == 0 && rulesComInfo.next()) { + double value = Util.getDoubleValue(String.valueOf(leaveMap.get("leaveType_" + rulesComInfo.getId())), 0.00); + value += Util.getDoubleValue((String) datasMap.get("leaveType_" + rulesComInfo.getId()), 0.00);//请假时长 + leaveMap.put("leaveType_" + rulesComInfo.getId(), value); + } + //} + } + + /**统计应出勤天数*/ + KQWorkTime kqWorkTime = new KQWorkTime(); + if (!toDate.equals("") && toDate.compareTo(currentDate) > 0 && Util.getIntValue(resourceComInfo.getStatus(resourceId), 0) < 4) { + workDays = 0.00; + if (!fromDate.equals("") && fromDate.compareTo(currentDate) > 0) { + //查询没有到的月份,缺勤天数以及出勤天数应该都为0 + realWorkDays = 0.00; + leaveDays = 0.00; + } + + boolean isEnd = false; + for (String date = fromDate; !isEnd; ) { + if (date.compareTo(toDate)>=0) { + isEnd = true; + } + + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(resourceId, date); + String dayType = workTimeEntity.getDayType(); + String convertAttendDay = Util.null2s(workTimeEntity.getConvertAttendDay(),"1.0"); + boolean isWorkDay = "work".equalsIgnoreCase(dayType); + if (isWorkDay) { + workDays += (1.00*Util.getDoubleValue(convertAttendDay, 1.0)); + } + + date = DateUtil.getDate(date, 1); + } + } + + /**********************************************************************************************************/ + + itemList = new ArrayList(); + itemMap = new HashMap(); + itemMap.put("id", "leaveDays"); + itemMap.put("name", SystemEnv.getHtmlLabelName(506345, user.getLanguage()));//未出勤 + itemMap.put("title", SystemEnv.getHtmlLabelName(506345, user.getLanguage())); + itemMap.put("type", "ABSENT"); + itemMap.put("value", String.format("%.2f", leaveDays)); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("id", "realWorkDays"); + itemMap.put("name", SystemEnv.getHtmlLabelName(130566, user.getLanguage()));//实际出勤 + itemMap.put("title", SystemEnv.getHtmlLabelName(130566, user.getLanguage())); + itemMap.put("type", "REALWORKDAYS"); + itemMap.put("value", String.format("%.2f", realWorkDays)); + itemList.add(itemMap); + + groupItem = new HashMap(); + groupItem.put("id", "workDays"); + groupItem.put("name", SystemEnv.getHtmlLabelName(513089, user.getLanguage()));//应出勤(天) + groupItem.put("title", SystemEnv.getHtmlLabelName(16732, user.getLanguage())); + groupItem.put("value", String.format("%.2f", workDays)); + groupItem.put("items", itemList); + resultMap.put("groupitem1", groupItem); + + /**********************************************************************************************************/ + + itemList = new ArrayList(); + itemMap = new HashMap(); + itemMap.put("name", "evection"); + itemMap.put("title", SystemEnv.getHtmlLabelName(20084, user.getLanguage()) + tr_unitName);//出差 + itemMap.put("type", "EVECTION"); + itemMap.put("value", String.format("%.2f",businessLeave)); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "outDays"); + itemMap.put("title", SystemEnv.getHtmlLabelName(24058, user.getLanguage()) + er_unitName);//公出 + itemMap.put("type", "OUTDAYS"); + itemMap.put("value",String.format("%.2f",officialBusiness)); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "overTimes"); + itemMap.put("title", SystemEnv.getHtmlLabelName(6151, user.getLanguage()) + or_unitName);//加班 + itemMap.put("type", "OVERTIME"); + itemMap.put("value", String.format("%.2f",overtimeTotal)); + itemList.add(itemMap); + + groupItem = new HashMap(); + groupItem.put("items", itemList); + resultMap.put("groupitem2", groupItem); + + /**********************************************************************************************************/ + + itemList = new ArrayList(); + itemMap = new HashMap(); + itemMap.put("name", "beLate"); + itemMap.put("title", SystemEnv.getHtmlLabelName(34089, user.getLanguage()));//迟到 + itemMap.put("type", "BELATE"); + itemMap.put("value", beLate); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "graveBeLate"); + itemMap.put("title", SystemEnv.getHtmlLabelName(535131, user.getLanguage()));//严重迟到 + itemMap.put("type", "graveBeLate"); + itemMap.put("value", graveBeLate); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "leaveEarly"); + itemMap.put("title", SystemEnv.getHtmlLabelName(34098, user.getLanguage()));//早退 + itemMap.put("type", "LEAVEEARLY"); + itemMap.put("value", leaveEearly); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "graveLeaveEarly"); + itemMap.put("title", SystemEnv.getHtmlLabelName(535132, user.getLanguage()));//严重早退 + itemMap.put("type", "graveLeaveEarly"); + itemMap.put("value", graveLeaveEarly); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "absentFromWork"); + itemMap.put("title", SystemEnv.getHtmlLabelName(10000344, user.getLanguage()));//旷工 + itemMap.put("type", "ABSENT"); + itemMap.put("value", absenteeism); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("name", "noSign"); + itemMap.put("title", SystemEnv.getHtmlLabelName(34099, user.getLanguage()));//漏签 + itemMap.put("type", "noSign"); + itemMap.put("value", forgotCheck); + itemList.add(itemMap); + + groupItem = new HashMap(); + groupItem.put("items", itemList); + resultMap.put("groupitem3", groupItem); + + /**********************************************************************************************************/ + + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + if (!rulesComInfo.getIsEnable().equals("1") || !rulesComInfo.getBalanceEnable().equals("1")) { + continue; + } +// writeLog("lxr2018>.resourceId="+resourceId+ +// ";getScopeType="+rulesComInfo.getScopeType()+ +// ";getScopeValue="+rulesComInfo.getScopeValue()); + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(resourceId, rulesComInfo.getScopeType(), rulesComInfo.getScopeValue(), subCompanyId+"", departmentId+""); + if (flag) { + continue; + } +// writeLog("lxr2018>.flag="+flag); + String allRestAmount = KQBalanceOfLeaveBiz.getRestAmount("" + resourceId, rulesComInfo.getId(), balanceDate, true, true); + String currentRestAmount = KQBalanceOfLeaveBiz.getRestAmount("" + resourceId, rulesComInfo.getId(), balanceDate, true, false); + String beforeRestAmount = String.format("%.2f", Util.getDoubleValue(allRestAmount, 0) - Util.getDoubleValue(currentRestAmount, 0)); + itemList = new ArrayList(); + if(KQSettingsBiz.show_split_balance()) { + itemMap = new HashMap(); + itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513286, user.getLanguage()) : SystemEnv.getHtmlLabelName(513287, user.getLanguage())); + itemMap.put("value", beforeRestAmount); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(504395, user.getLanguage()) : SystemEnv.getHtmlLabelName(504394, user.getLanguage())); + itemMap.put("value", currentRestAmount); + itemList.add(itemMap); + + itemMap = new HashMap(); + itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513288, user.getLanguage()) : SystemEnv.getHtmlLabelName(513289, user.getLanguage())); + itemMap.put("value", allRestAmount); + itemList.add(itemMap); + }else{ + itemMap = new HashMap(); + itemMap.put("title", (KQUnitBiz.isLeaveHour(rulesComInfo.getMinimumUnit())) ? SystemEnv.getHtmlLabelName(513288, user.getLanguage()) : SystemEnv.getHtmlLabelName(513289, user.getLanguage())); + itemMap.put("value", allRestAmount); + itemList.add(itemMap); + } + + groupItem = new HashMap(); + groupItem.put("color", "#25C6DA"); + groupItem.put("icon", "icon-Human-resources-adjustment"); + groupItem.put("title", rulesComInfo.getLeaveName()); + groupItem.put("item", itemList); + groupItemList.add(groupItem); + } + groupMap.put("items", groupItemList); + groupMap.put("title", SystemEnv.getHtmlLabelName(132058, user.getLanguage())); + resultMap.put("groupitem4", groupMap); + + /**********************************************************************************************************/ + + rulesComInfo.setTofirstRow(); + while (rulesComInfo.next()) { + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(resourceId, rulesComInfo.getScopeType(), rulesComInfo.getScopeValue(), subCompanyId+"", departmentId+""); + if (flag) { + continue; + } + double value = Util.getDoubleValue(String.valueOf(leaveMap.get("leaveType_" + rulesComInfo.getId())), 0.00);//请假时长 + if (value > 0) { + String leaveName = Util.formatMultiLang(rulesComInfo.getLeaveName(), "" + user.getLanguage()); + int le_minimumUnit = Util.getIntValue(rulesComInfo.getMinimumUnit(), 1);//最小请假单位 + String le_unitName = (le_minimumUnit == 3 || le_minimumUnit == 5 || le_minimumUnit == 6) ? SystemEnv.getHtmlLabelName(389326, user.getLanguage()) : SystemEnv.getHtmlLabelName(389325, user.getLanguage()); + + itemMap = new HashMap(); + itemMap.put("name", "leaveType_" + rulesComInfo.getId()); + itemMap.put("title", leaveName + le_unitName); + itemMap.put("type", "leaveType_" + rulesComInfo.getId()); + itemMap.put("value", Util.toDecimalDigits("" + value, 2)); + itemList5.add(itemMap); + } + } + groupItem5.put("items", itemList5); + resultMap.put("groupitem5", groupItem5); + resultMap.put("status", "1"); + } catch (Exception e) { + writeLog(e); + } + return resultMap; + } +} 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..e09a9d3 --- /dev/null +++ b/src/com/engine/kq/cmd/report/ExportExcelCmd.java @@ -0,0 +1,902 @@ +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 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 com.google.common.collect.Lists; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.math.BigDecimal; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class ExportExcelCmd extends AbstractCommonCommand> { + + private HttpServletRequest request; + private HttpServletResponse response; + private List lsFieldDataKey; + + private boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + + 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(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + KQReportBiz kqReportBiz = new KQReportBiz(); + new KQReportBiz().insertKqReportExportLog(params, user); + 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); + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1"); + fromDate = getRealDate.get("fromDate"); + toDate = getRealDate.get("toDate"); + if("-1".equals(fromDate) || "-1".equals(toDate)) { + retmap.put("status", "1"); + return retmap; + } + + List paramLists = new ArrayList<>(); + List paramList = null; + 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 backFields = " 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 where a.id= b.resourceid 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("+KQReportBiz.splitParamStr(subCompanyId)+") "; + for(String bean : subCompanyId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + if (departmentId.length() > 0) { + sqlWhere +=" and a.departmentid in("+KQReportBiz.splitParamStr(departmentId)+") "; + for(String bean : departmentId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + if (resourceId.length() > 0) { + sqlWhere +=" and a.id in("+KQReportBiz.splitParamStr(resourceId)+") "; + for(String bean : resourceId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + 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 = ?"; + paramList = new ArrayList<>(); + paramList.add(status); + paramLists.add(paramList); + }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()); + + + String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源 + params.put("show_card_source",show_card_source); + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + params.put("uintType",uintType); + params.put("hoursToDay",hoursToDay); + Map flowData = new KQReportBiz().getFlowData(params, user); + //System.out.println("end" + DateUtil.getFullDate()); + + // #1475814-概述:满足考勤报分部部门显示及导出时显示全路径 + String fullPathMainKey = "show_full_path"; + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + rs.executeQuery(sql, paramLists); + int calIndex = -1; + while (rs.next()) { + data = new ArrayList<>(); + String id = rs.getString("id"); + for (int fieldDataKeyIdx =0;fieldDataKeyIdx 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> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + 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")){ + 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("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;i0){ + fieldid = KQReportFieldComInfo.field2Id.get(lsCascadekey.get(i)); + fieldValue = getFieldValueByUnitType(rs.getString(lsCascadekey.get(i)),kqReportFieldComInfo.getUnittype(fieldid)); + }else{ + fieldValue = "0"; + } + data.add(fieldValue); + } + continue; + }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); + } + + List amData = Lists.newArrayList(); + List pmData = Lists.newArrayList(); + if(isKqReportHalfOpen) { + amData.addAll(data); + pmData.addAll(data); + calIndex = data.size(); + } + + if(showColumns.contains("kqCalendar")) { +// Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true); + Map detialDatas = kqReportBiz.getDetialDatas(id, fromDate, toDate, user,flowData,true,uintType,show_card_source); + String user_endDate = Util.null2String(resourceComInfo.getEndDate(id)); + String user_status = Util.null2String(resourceComInfo.getStatus(id)); + String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim(); + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim(); + if(companyStartDate.length()!=10){ + companyStartDate = ""; + } + if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){ + begindate=companyStartDate; + } + isEnd = false; + for (String date = fromDate; !isEnd; ) { + if (date.equals(toDate)) isEnd = true; + if(DateUtil.compDate(today, date)>0){ + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + }else{ + if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){ + //其他状态 + if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后 + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + } + if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准 + if(isKqReportHalfOpen) { + amData.add(""); + pmData.add(""); + } else { + data.add(""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + if (detialDatas.get(id + "|" + date) != null) { + if(isKqReportHalfOpen) { + amData.add(((Map) detialDatas.get(id + "|" + date)).get("textAM")); + pmData.add(((Map) detialDatas.get(id + "|" + date)).get("textPM")); + } else { + data.add(((Map) detialDatas.get(id + "|" + date)).get("text")); + } + } else { + if(isKqReportHalfOpen) { + amData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + pmData.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + } else { + data.add(SystemEnv.getHtmlLabelName(26593, user.getLanguage())); + } + } + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + } + if(isKqReportHalfOpen) { + dataList.add(amData); + dataList.add(pmData); + } else { + dataList.add(data); + } + } + sheet.put("dataList", dataList); + if(isKqReportHalfOpen) { + sheet.put("calIndex", calIndex); + } + 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,true); + 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; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"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++) { + 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(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + 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;i0){ + 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(); + 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; + } + + /** + * 找到人员入职日期 + * + * @return + */ + public static String findRzrq(String jbr) { + RecordSet rs = new RecordSet(); + String sql = "select id,companystartdate from hrmresource where id ="+jbr; + rs.executeQuery(sql); + String companystartdate = ""; + if (rs.next()) { + companystartdate = Util.null2String(rs.getString("companystartdate")); + } + return companystartdate; + } + + + /** + * 找到人员离职日期 + * + * @return + */ + public static String findLzrq(String jbr) { + RecordSet rs = new RecordSet(); + String sql = "select changedate from HrmStatusHistory where RESOURCEID ="+jbr+" and type_n = 5"; + rs.executeQuery(sql); + String changedate = ""; + if (rs.next()) { + changedate = Util.null2String(rs.getString("changedate")); + } + return changedate; + } + + /** + * 获取入离职缺勤小时 + * @param dateOri + * @param userId + * @return + */ + public String getXcqts(String dateOri,String userId){ + //需出勤天数 + Integer xcqtsAll = 0; + //获取员工的入职日期 + String rzrq = findRzrq(userId); + //获取员工的离职日期 + String lzrq = findLzrq(userId); + String dateOriSub = dateOri.substring(0,7); + //本月第一天 + String fromDate = TimeUtil.getMonthBeginDay(dateOri); + //本月最后一天 + String toDate = TimeUtil.getMonthEndDay(dateOri); + //入职日期处理 + if(StringUtils.isNotBlank(rzrq)){ + String rzrqSub = rzrq.substring(0,7); + if(rzrqSub.equals(dateOriSub)){ + //入职日期在当月 + Set all = new HashSet<>(); + all.add(fromDate); + List back = days(fromDate,rzrq); + all.addAll(back); + for (String date : all) { + Integer zcgzts = 0; + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + String changeTypeNew = holidaySetComInfo.getChangeType("1", date); +// if("2".equals(changeTypeNew)){ +// //调配工作日计正常工作天数 +// zcgzts = 1; +// } + if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){ + //不为周六周日 + if(!"3".equals(changeTypeNew)){ + //不为休息日 + zcgzts = 1; + } + } + + xcqtsAll = xcqtsAll+zcgzts; + } + + } + } + //离职日期处理 + if(StringUtils.isNotBlank(lzrq)){ + String lzrqSub = lzrq.substring(0,7); + if(lzrqSub.equals(dateOriSub)){ + //离职日期在当月 + Set all = new HashSet<>(); + List back = days(lzrq,toDate); + all.addAll(back); + all.add(toDate); + for (String date : all) { + Integer zcgzts = 0; + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + String changeTypeNew = holidaySetComInfo.getChangeType("1", date); +// if("2".equals(changeTypeNew)){ +// //调配工作日计正常工作天数 +// zcgzts = 1; +// } + if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){ + //不为周六周日 + if(!"3".equals(changeTypeNew)){ + //不为休息日 + zcgzts = 1; + } + } + + xcqtsAll = xcqtsAll+zcgzts; + } + + } + } + Integer newXcqTime = xcqtsAll * 8; + new BaseBean().writeLog(userId+"newXcqTime"+newXcqTime); + return String.valueOf(newXcqTime); + } + + /** + * 获取两个日期之间所有的日期 + * @param date1 + * @param date2 + * @return + */ + public static ArrayList days(String date1, String date2) { + String dateFormat = "yyyy-MM-dd"; + SimpleDateFormat format = new SimpleDateFormat(dateFormat); + 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) { + String dateFormat = "yyyy-MM-dd"; + SimpleDateFormat format = new SimpleDateFormat(dateFormat); + if (str == null) + return null; + + try { + return format.parse(str); + } catch (ParseException e) { + e.printStackTrace(); + } + 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..dfe5699 --- /dev/null +++ b/src/com/engine/kq/cmd/report/GetKQReportCmd.java @@ -0,0 +1,1010 @@ +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.weaver.file.Prop; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.util.PageUidFactory; +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.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.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +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(); + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"0"); + + 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()); + boolean isKqReportHalfOpen = "1".equals(new KQSettingsComInfo().getMain_val("kq_report_half")); + if(isKqReportHalfOpen) { + pageSize = pageSize/2; + } + 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()); + columns.add(column); + columns.addAll(this.getCascadeKeyColumnsInfo(kqReportFieldComInfo.getCascadekey(),user)); + } + + 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", 90); + 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()*90); + column.put("children", childColumns); + } + columns.add(column); + + + // 没有权限的人最大只支持查询本季 + Map getRealDate = new KQReportBiz().realDate(fromDate, toDate, user, "1"); + fromDate = getRealDate.get("fromDate"); + toDate = getRealDate.get("toDate"); + + 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 backFields = " 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 where a.id= b.resourceid 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 "; + List paramLists = new ArrayList<>(); + List paramList = null; + if(subCompanyId.length()>0){ + sqlWhere +=" and a.subcompanyid1 in("+KQReportBiz.splitParamStr(subCompanyId)+") "; + for(String bean : subCompanyId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + if(departmentId.length()>0){ + sqlWhere +=" and a.departmentid in("+KQReportBiz.splitParamStr(departmentId)+") "; + for(String bean : departmentId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + if(resourceId.length()>0){ + sqlWhere +=" and a.id in("+KQReportBiz.splitParamStr(resourceId)+") "; + for(String bean : resourceId.split(",")) { + paramList = new ArrayList<>(); + paramList.add(bean); + paramLists.add(paramList); + } + } + + + 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 = ?"; + paramList = new ArrayList<>(); + paramList.add(status); + paramLists.add(paramList); + }else if (status.equals("8")) { + sqlWhere += " and (a.status = 0 or a.status = 1 or a.status = 2 or a.status = 3) "; + } + } + if("-1".equals(fromDate) || "-1".equals(toDate)) { + sqlWhere += " and 1=2 "; + } + sql = " select count(*) as c from ( select 1 as c "+sqlFrom+sqlWhere+groupBy+") t"; + rs.executeQuery(sql, paramLists); + 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"; + String isShowFullPath = Util.null2String(kqSettingsComInfo.getMain_val(fullPathMainKey),"0"); + + String show_card_source = Util.null2String(kqSettingsComInfo.getMain_val("show_card_source"),"0");//是否显示打卡数据,以及打卡数据来源 + params.put("show_card_source",show_card_source); + KQOvertimeRulesBiz kqOvertimeRulesBiz = new KQOvertimeRulesBiz(); + int uintType = kqOvertimeRulesBiz.getMinimumUnit();//当前加班单位 + double hoursToDay = kqOvertimeRulesBiz.getHoursToDay();//当前天跟小时计算关系 + params.put("uintType",uintType); + params.put("hoursToDay",hoursToDay); + Map flowData = kqReportBiz.getFlowData(params,user); + + rs.executeQuery(sql, paramLists); + 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("rlzqqxs")){ + String rlzqqxsTime = getXcqts(fromDate,id); + fieldValue = rlzqqxsTime; + }else if(fieldName.equals("attendanceSerial")){ + List serialIds = null; + if(attendanceSerial.length()>0){ + serialIds = Util.splitString2List(attendanceSerial,","); + } + for(int i=0;serialIds!=null&&i0) { + if(fieldValue.length() == 0){ + fieldValue="0"; + }else{ + if (kqReportFieldComInfo.getUnittype().equals("2")) { + fieldValue = KQDurationCalculatorUtil.getDurationRound(("" + (Util.getDoubleValue(fieldValue) / 60.0))); + } + } + } + } + data.put(fieldName,fieldValue); + } + + //请假 + List> allLeaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if(("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = allLeaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = allLeaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = KQLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + allLeaveRules.remove(i); + } + } + } + Map leaveRule = null; + for(int i=0;allLeaveRules!=null&&i)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); + } + + Map amData = Maps.newHashMap(); + Map pmData = Maps.newHashMap(); + if(isKqReportHalfOpen) { + amData.putAll(data); + pmData.putAll(data); + } + + Map detialDatas = kqReportBiz.getDetialDatas(id,fromDate,toDate,user,flowData,false,uintType,show_card_source); +// new KQLog().info("id:"+id+":detialDatas:"+detialDatas); + String user_endDate = Util.null2String(resourceComInfo.getEndDate(id)); + String user_status = Util.null2String(resourceComInfo.getStatus(id)); + String begindate = Util.null2String(resourceComInfo.getCreatedate(id)).trim(); + String companyStartDate = Util.null2String(resourceComInfo.getCompanyStartDate(id)).trim(); + if(companyStartDate.length()!=10){ + companyStartDate = ""; + } + if(companyStartDate.length()>0 && companyStartDate.indexOf("-")>0){ + begindate=companyStartDate; + } + isEnd = false; + for(String date=fromDate; !isEnd;) { + if(date.equals(toDate)) isEnd = true; + if(DateUtil.compDate(today, date)>0){ + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + }else{ + if(!(user_status.equals("0")||user_status.equals("1")||user_status.equals("2")||user_status.equals("3"))){ + //其他状态 + if(user_endDate.length()>0 && date.compareTo(user_endDate)>0){//人员合同结束日期之后 + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + } + if(begindate.length()>0 && date.compareTo(begindate)<0 ){//人员入职日期前无需计算考勤,如果没有入职日期,已创建日期为准 + if(isKqReportHalfOpen) { + amData.put(date,""); + pmData.put(date,""); + } else { + data.put(date,""); + } + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + continue; + } + + if(isKqReportHalfOpen) { + Map tmpData = Maps.newHashMap(); + Object tmpValue = null; + if(detialDatas.get(id+"|"+date)==null){ + tmpValue = SystemEnv.getHtmlLabelName(26593, user.getLanguage()); + data.put(date,tmpValue); + amData.put(date,tmpValue); + pmData.put(date,tmpValue); + }else { + tmpData = (Map) detialDatas.get(id+"|"+date); + data.put(date,tmpData); + if(tmpData != null){ + tmpData.put("text",Util.null2String(tmpData.get("textAM"))); + + Map amTmpData = Maps.newHashMap(); + amTmpData.put("text",Util.null2String(tmpData.get("textAM"))); + Map pmTmpData = Maps.newHashMap(); + pmTmpData.put("text",Util.null2String(tmpData.get("textPM"))); + amData.put(date,amTmpData); + pmData.put(date,pmTmpData); + } + } + } else { + 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); + } + if(isKqReportHalfOpen) { + amData.put("rowSpan", "2"); + pmData.put("rowSpan", "0"); + datas.add(amData); + datas.add(pmData); + } else { + datas.add(data); + } + } + + List lsHolidays = KQHolidaySetBiz.getHolidaySetListByScope(""+user.getUID(),fromDate,toDate); + retmap.put("holidays", lsHolidays); + + retmap.put("columns",columns); + retmap.put("datas",datas); + if(isKqReportHalfOpen) { + retmap.put("pagesize", pageSize*2); + retmap.put("count", count*2); + } else { + retmap.put("pagesize", pageSize); + retmap.put("count", count); + } + retmap.put("pageindex", pageIndex); + retmap.put("pagecount", pageCount); + retmap.put("ishavepre", isHavePre); + retmap.put("ishavenext", isHaveNext); + retmap.put("isKqReportHalfOpen", isKqReportHalfOpen); + }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; + KQSettingsComInfo kqSettingsComInfo = new KQSettingsComInfo(); + String leavetype_is_on = Util.null2String(kqSettingsComInfo.getMain_val("leavetype_is_on"),"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> leaveRules = kqLeaveRulesBiz.getAllLeaveRules(); + if (("1").equals(leavetype_is_on)) { + KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo(); + for (int i = leaveRules.size() - 1; i >= 0; i--) { + Map leaveRule = leaveRules.get(i); + String leaveId = Util.null2String(leaveRule.get("id")); + boolean flag = kqLeaveRulesBiz.filterSubLeaveRule(kqLeaveRulesComInfo, user, leaveId); + if (flag) { + leaveRules.remove(i); + } + } + } + for(int i=0;leaveRules!=null&&i 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"}; + for(int i=0;i0){ + 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= ? and jbksrq >= ? and sqr = ?"; + RecordSet rs = new RecordSet(); + rs.executeQuery(sql,fromDate, toDate, userid); + + while (rs.next()) { + String workdate = rs.getString("jbksrq"); + boolean workDay = kqWorkTime.isWorkDay(userid, workdate); + boolean isHoliday = KQHolidaySetBiz.isHoliday(userid,workdate); + double dxsc = rs.getDouble("dxsc"); + dxsc = (double)Math.round(dxsc*100)/100; + BigDecimal bigDecimalDxsc = new BigDecimal(Double.toString(dxsc)); + if(workDay){ + if("1".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + }else if(isHoliday ){ + if("2".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + + }else { + if("3".equals(leaveType)){ + bigDecimal.subtract(bigDecimalDxsc); + } + + } + } + return bigDecimal.doubleValue(); + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + public static void main(String[] args) { + String s1 = String.format("%.2f", 1.2); + System.out.println(s1); + + } + + /** + * 找到人员入职日期 + * + * @return + */ + public static String findRzrq(String jbr) { + RecordSet rs = new RecordSet(); + String sql = "select id,companystartdate from hrmresource where id ="+jbr; + rs.executeQuery(sql); + String companystartdate = ""; + if (rs.next()) { + companystartdate = Util.null2String(rs.getString("companystartdate")); + } + return companystartdate; + } + + + /** + * 找到人员离职日期 + * + * @return + */ + public static String findLzrq(String jbr) { + RecordSet rs = new RecordSet(); + String sql = "select changedate from HrmStatusHistory where RESOURCEID ="+jbr+" and type_n = 5"; + rs.executeQuery(sql); + String changedate = ""; + if (rs.next()) { + changedate = Util.null2String(rs.getString("changedate")); + } + return changedate; + } + + /** + * 获取入离职缺勤小时 + * @param dateOri + * @param userId + * @return + */ + public String getXcqts(String dateOri,String userId){ + //需出勤天数 + Integer xcqtsAll = 0; + //获取员工的入职日期 + String rzrq = findRzrq(userId); + //获取员工的离职日期 + String lzrq = findLzrq(userId); + String dateOriSub = dateOri.substring(0,7); + //本月第一天 + String fromDate = TimeUtil.getMonthBeginDay(dateOri); + //本月最后一天 + String toDate = TimeUtil.getMonthEndDay(dateOri); + //入职日期处理 + if(StringUtils.isNotBlank(rzrq)){ + String rzrqSub = rzrq.substring(0,7); + if(rzrqSub.equals(dateOriSub)){ + //入职日期在当月 + Set all = new HashSet<>(); + all.add(fromDate); + List back = days(fromDate,rzrq); + all.addAll(back); + for (String date : all) { + Integer zcgzts = 0; + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + String changeTypeNew = holidaySetComInfo.getChangeType("1", date); +// if("2".equals(changeTypeNew)){ +// //调配工作日计正常工作天数 +// zcgzts = 1; +// } + if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){ + //不为周六周日 + if(!"3".equals(changeTypeNew)){ + //不为休息日 + zcgzts = 1; + } + } + + xcqtsAll = xcqtsAll+zcgzts; + } + + } + } + //离职日期处理 + if(StringUtils.isNotBlank(lzrq)){ + String lzrqSub = lzrq.substring(0,7); + if(lzrqSub.equals(dateOriSub)){ + //离职日期在当月 + Set all = new HashSet<>(); + List back = days(lzrq,toDate); + all.addAll(back); + all.add(toDate); + for (String date : all) { + Integer zcgzts = 0; + KQHolidaySetComInfo holidaySetComInfo = new KQHolidaySetComInfo(); + String changeTypeNew = holidaySetComInfo.getChangeType("1", date); +// if("2".equals(changeTypeNew)){ +// //调配工作日计正常工作天数 +// zcgzts = 1; +// } + if(DateUtil.getWeek(date) != 6 && DateUtil.getWeek(date) != 7){ + //不为周六周日 + if(!"3".equals(changeTypeNew)){ + //不为休息日 + zcgzts = 1; + } + } + + xcqtsAll = xcqtsAll+zcgzts; + } + + } + } + Integer newXcqTime = xcqtsAll * 8; + new BaseBean().writeLog(userId+"newXcqTime"+newXcqTime); + return String.valueOf(newXcqTime); + } + + /** + * 获取两个日期之间所有的日期 + * @param date1 + * @param date2 + * @return + */ + public static ArrayList days(String date1, String date2) { + String dateFormat = "yyyy-MM-dd"; + SimpleDateFormat format = new SimpleDateFormat(dateFormat); + 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) { + String dateFormat = "yyyy-MM-dd"; + SimpleDateFormat format = new SimpleDateFormat(dateFormat); + if (str == null) + return null; + + try { + return format.parse(str); + } catch (ParseException e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/src/com/engine/kq/cmd/shiftschedule/GetBatchShiftScheduleFromCmd.java b/src/com/engine/kq/cmd/shiftschedule/GetBatchShiftScheduleFromCmd.java new file mode 100644 index 0000000..0c3c54c --- /dev/null +++ b/src/com/engine/kq/cmd/shiftschedule/GetBatchShiftScheduleFromCmd.java @@ -0,0 +1,407 @@ +package com.engine.kq.cmd.shiftschedule; + +import com.api.browser.bean.SearchConditionItem; +import com.api.browser.bean.SearchConditionOption; +import com.api.browser.util.ConditionFactory; +import com.api.browser.util.ConditionType; +import com.api.hrm.bean.HrmFieldBean; +import com.api.hrm.bean.SelectOption; +import com.api.hrm.bean.WeaRadioGroup; +import com.api.hrm.util.HrmFieldSearchConditionComInfo; +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.kq.biz.KQGroupBiz; +import com.engine.kq.biz.KQGroupComInfo; +import com.engine.kq.biz.KQHolidaySetBiz; +import com.engine.kq.biz.KQShiftManagementComInfo; +import com.engine.kq.util.PageUidFactory; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.filter.XssUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class GetBatchShiftScheduleFromCmd extends AbstractCommonCommand> { + + public GetBatchShiftScheduleFromCmd(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 = ""; + List lsField = new ArrayList(); + HrmFieldBean hrmFieldBean = null; + List options = null; + Map mapItem = new HashMap<>(); + try{ + //必要的权限判断 + if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + + KQGroupComInfo kQGroupComInfo = new KQGroupComInfo(); + KQShiftManagementComInfo kQShiftManagementComInfo = new KQShiftManagementComInfo(); + String groupId = Util.null2String(params.get("groupId"));//考勤组id + + //排班类型、排班日期、排班人员、班次 + //排班类型、排班开始日期、排班人员、遇节假日、排班周期 + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("shiftScheduleType"); + hrmFieldBean.setFieldlabel("389494"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + hrmFieldBean.setFieldvalue("1"); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(389506, user.getLanguage()),true)); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(389507, user.getLanguage()))); + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("shiftScheduleDate"); + hrmFieldBean.setFieldlabel("16694"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setIsFormField(true); + hrmFieldBean.setViewAttr(3); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("shiftScheduleBeginDate"); + hrmFieldBean.setFieldlabel("16694"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setIsFormField(true); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("shiftScheduleEndDate"); + hrmFieldBean.setFieldlabel("16694"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("2"); + hrmFieldBean.setViewAttr(3); + hrmFieldBean.setIsFormField(true); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("shiftScheduleMember"); + hrmFieldBean.setFieldlabel("125839"); + hrmFieldBean.setFieldhtmltype("3"); + hrmFieldBean.setType("17"); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("holidayType"); + hrmFieldBean.setFieldlabel("500436"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("meetHolidays"); + hrmFieldBean.setFieldlabel("529182"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("meetRestDays"); + hrmFieldBean.setFieldlabel("528922"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + options = new ArrayList(); + options.add(new SearchConditionOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + options.add(new SearchConditionOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + hrmFieldBean.setSelectOption(options); + lsField.add(hrmFieldBean); + + hrmFieldBean = new HrmFieldBean(); + hrmFieldBean.setFieldname("serialId"); + hrmFieldBean.setFieldlabel("24803"); + hrmFieldBean.setFieldhtmltype("5"); + hrmFieldBean.setType("1"); + options = new ArrayList(); + String[] serialids = Util.splitString(Util.null2String(kQGroupComInfo.getSerialids(groupId)),","); + for(int i=0;serialids!=null&&i(); + for(int i=0;serialids!=null&&i(); + for(int i=0;serialids!=null&&i(); + for(int i=0;serialids!=null&&i(); + for(int i=0;serialids!=null&&i(); + sql = "select id,shiftcyclename,shiftcycleserialids from kq_group_shiftcycle where groupid = ? order by id asc "; + rs.executeQuery(sql,groupId); + while(rs.next()){ + options.add(new SearchConditionOption(Util.null2String(rs.getString("id")),Util.null2String(rs.getString("shiftcyclename")),true)); + hrmFieldBean.setSelectOption(options); + } + lsField.add(hrmFieldBean); + + HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo(); + SearchConditionItem searchConditionItem = null; + for (int i = 0; i < lsField.size(); i++) { + searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(lsField.get(i), user); + if(lsField.get(i).getFieldname().equals("shiftScheduleMember")){ + XssUtil xssUtil = new XssUtil(); + Map tmpParams = new HashMap<>(); + tmpParams.put("groupId",groupId); + tmpParams.put("isNoAccount",1); + String groupMemberSql = new KQGroupBiz().getGroupMemberSql(tmpParams); + String inSqlWhere = " hr.id in (select resourceid from (" + groupMemberSql + ") t1)"; + String inSqlWhere1 = " t1.id in (select resourceid from (" + groupMemberSql + ") t1)"; + if(!Util.null2String(kQGroupComInfo.getExcludecount(groupId)).equals("1")) { + //剔除无需排班人员 + String excludeid = Util.null2String(kQGroupComInfo.getExcludeid(groupId)); + if (excludeid.length() > 0) { + inSqlWhere += " and hr.id not in (" + excludeid + ")"; + inSqlWhere1 += " and t1.id not in (" + excludeid + ")"; + } + } + searchConditionItem.getBrowserConditionParam().getDataParams().put("sqlwhere", xssUtil.put(inSqlWhere)); + searchConditionItem.getBrowserConditionParam().getCompleteParams().put("sqlwhere", xssUtil.put(inSqlWhere1)); + } + mapItem.put(lsField.get(i).getFieldname(),searchConditionItem); + } + + //下拉 + List condition = new ArrayList(); + condition.add(mapItem.get("shiftScheduleType")); + + //按天排班 + Map conditionMap = new HashMap(); + List conditionlist = null; + List conditionlist2 = null; + + conditionlist = new ArrayList(); + conditionlist2 = new ArrayList(); + conditionlist2.add(mapItem.get("shiftScheduleDate")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + WeaRadioGroup wrg = new WeaRadioGroup(); + wrg.setLabel(SystemEnv.getHtmlLabelName(125839, user.getLanguage())); + List option = new ArrayList<>(); + Map selectLinkageDatas = new HashMap(); + selectLinkageDatas.put("2" ,mapItem.get("shiftScheduleMember")); + wrg.setSelectLinkageDatas(selectLinkageDatas); + option.add(new SelectOption("1",SystemEnv.getHtmlLabelName(389496, user.getLanguage()),true)); + option.add(new SelectOption("2",SystemEnv.getHtmlLabelName(33210, user.getLanguage()))); + + List domkey = new ArrayList(); + wrg.setOptions(option); + wrg.setConditionType("SELECT_LINKAGE"); + wrg.setFieldcol(18); + wrg.setLabelcol(6); + domkey.add("shiftScheduleMemberType"); + wrg.setDomkey(domkey); + conditionlist2.add(wrg); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + conditionlist2.add(mapItem.get("serialId")); + conditionlist.add(conditionlist2); + conditionMap.put("1",conditionlist); + + //按周期排班 + conditionlist = new ArrayList(); + conditionlist2 = new ArrayList(); + conditionlist2.add(mapItem.get("shiftScheduleBeginDate")); + conditionlist2.add(mapItem.get("shiftScheduleEndDate")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + conditionlist2.add(wrg); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + + WeaRadioGroup wrgH = new WeaRadioGroup(); + wrgH.setLabel(SystemEnv.getHtmlLabelName(500436, user.getLanguage())); + List optionH = new ArrayList<>(); + Map selectLinkageDatasH = new HashMap(); + selectLinkageDatasH.put("3" ,mapItem.get("serialIdSx")); + wrgH.setSelectLinkageDatas(selectLinkageDatasH); + optionH.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + optionH.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + optionH.add(new SelectOption("3","替换为指定班次")); + List domkeyH = new ArrayList(); + wrgH.setOptions(optionH); + wrgH.setConditionType("SELECT_LINKAGE"); + wrgH.setFieldcol(18); + wrgH.setLabelcol(6); + domkeyH.add("holidayType"); + wrgH.setDomkey(domkeyH); + conditionlist2.add(wrgH); + +// conditionlist2.add(mapItem.get("holidayType")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + + WeaRadioGroup wrgJ = new WeaRadioGroup(); + wrgJ.setLabel(SystemEnv.getHtmlLabelName(529182, user.getLanguage())); + List optionJ = new ArrayList<>(); + Map selectLinkageDatasJ = new HashMap(); + selectLinkageDatasJ.put("3" ,mapItem.get("serialIdJjr")); + wrgJ.setSelectLinkageDatas(selectLinkageDatasJ); + optionJ.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + optionJ.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + optionJ.add(new SelectOption("3","替换为指定班次")); + List domkeyJ = new ArrayList(); + wrgJ.setOptions(optionJ); + wrgJ.setConditionType("SELECT_LINKAGE"); + wrgJ.setFieldcol(18); + wrgJ.setLabelcol(6); + domkeyJ.add("meetHolidays"); + wrgJ.setDomkey(domkeyJ); + conditionlist2.add(wrgJ); +// conditionlist2.add(mapItem.get("meetHolidays")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + WeaRadioGroup wrgX = new WeaRadioGroup(); + wrgX.setLabel(SystemEnv.getHtmlLabelName(528922, user.getLanguage())); + List optionX = new ArrayList<>(); + Map selectLinkageDatasX = new HashMap(); + selectLinkageDatasX.put("3" ,mapItem.get("serialIdXxr")); + wrgX.setSelectLinkageDatas(selectLinkageDatasX); + optionX.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + optionX.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + optionX.add(new SelectOption("3","替换为指定班次")); + List domkeyX = new ArrayList(); + wrgX.setOptions(optionX); + wrgX.setConditionType("SELECT_LINKAGE"); + wrgX.setFieldcol(18); + wrgX.setLabelcol(6); + domkeyX.add("meetRestDays"); + wrgX.setDomkey(domkeyX); + conditionlist2.add(wrgX); + +// conditionlist2.add(mapItem.get("meetRestDays")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + WeaRadioGroup wrgG = new WeaRadioGroup(); + wrgG.setLabel("遇调配工作日"); + List optionG = new ArrayList<>(); + Map selectLinkageDatasG = new HashMap(); + selectLinkageDatasG.put("3" ,mapItem.get("serialIdGzr")); + wrgG.setSelectLinkageDatas(selectLinkageDatasG); + optionG.add(new SelectOption("1",SystemEnv.getHtmlLabelName(125899, user.getLanguage()),true)); + optionG.add(new SelectOption("2",SystemEnv.getHtmlLabelName(125837, user.getLanguage()))); + optionG.add(new SelectOption("3","替换为指定班次")); + List domkeyG = new ArrayList(); + wrgG.setOptions(optionG); + wrgG.setConditionType("SELECT_LINKAGE"); + wrgG.setFieldcol(18); + wrgG.setLabelcol(6); + domkeyG.add("meetworkDays"); + wrgG.setDomkey(domkeyG); + conditionlist2.add(wrgG); + +// conditionlist2.add(mapItem.get("meetRestDays")); + conditionlist.add(conditionlist2); + + conditionlist2 = new ArrayList(); + conditionlist2.add(mapItem.get("shiftcycleId")); + conditionlist.add(conditionlist2); + conditionMap.put("2",conditionlist); + condition.add(conditionMap); + + retmap.put("conditions", condition); + 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/shiftschedule/ImportExcelCmd.java b/src/com/engine/kq/cmd/shiftschedule/ImportExcelCmd.java new file mode 100644 index 0000000..f6301c7 --- /dev/null +++ b/src/com/engine/kq/cmd/shiftschedule/ImportExcelCmd.java @@ -0,0 +1,630 @@ +package com.engine.kq.cmd.shiftschedule; + +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.bean.KqShiftscheduleOperateLog; +import com.engine.kq.biz.*; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import weaver.conn.BatchRecordSet; +import weaver.conn.RecordSet; +import weaver.file.ImageFileManager; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.Reminder.KQAutoCardTask; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.text.SimpleDateFormat; +import java.util.*; + +public class ImportExcelCmd extends AbstractCommonCommand> { + private String today = weaver.common.DateUtil.getCurrentDate(); + private SimpleBizLogger logger; + + // 添加日志功能 + private List> operateLogParams = new ArrayList<>(); + // 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id + private List operateLogParam = null; + + public ImportExcelCmd(Map params, User user) { + this.user = user; + this.params = params; + this.logger = new SimpleBizLogger(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + BatchRecordSet bRs = new BatchRecordSet(); + String sql = ""; + try { + //必要的权限判断 + if (!HrmUserVarify.checkUserRight("HrmKQGroup:Add", user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + ResourceComInfo resourceComInfo = new ResourceComInfo(); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + KQShiftManagementComInfo kqShiftManagementComInfo = new KQShiftManagementComInfo(); + + String groupId = Util.null2String(params.get("groupId")); + List managerRoleUserIdList = new KqShiftScheduleRoleBiz().getUfKqShiftScheduleRoleValue(""+user.getUID(), groupId); + + String filename = Util.null2String(params.get("filename")); + + List lsColumn = null; + List> paramInsert = new ArrayList>(); + List> paramUpdate = new ArrayList>(); + List param = null; + List> lsFormatParams = new ArrayList<>(); + List formatParams = null; + + List> delValidateParams = new ArrayList<>(); + List validateParams = null; + + List> lscheckSerialParams = new ArrayList<>(); + List checkSerialParams = null; + + Map mapShiftSchedule = new HashMap<>(); + Map mapSerial = new HashMap<>(); + Map mapGroupMembersWorkCode = new HashMap<>(); + Map mapGroupMembersLastName = new HashMap<>(); + List serialids=Util.splitString2List(kqGroupComInfo.getSerialids(groupId),","); + if(!serialids.contains("-1"))serialids.add("-1"); + for(String serialid : serialids){ + if(serialid.equals("-1")){ + String restLabel = SystemEnv.getHtmlLabelName(26593, user.getLanguage()).trim(); + mapSerial.put(restLabel,serialid); + }else{ + mapSerial.put(Util.formatMultiLang(kqShiftManagementComInfo.getSerial(serialid),""+user.getLanguage()),serialid); + } + } + + Map params = new HashMap<>(); + params.put("groupId",groupId); + params.put("isNoAccount","1"); + List kqGroupMembers = kqGroupBiz.getGroupMembers(params); + + KqMembersValidateBiz kqMembersValidateBiz = new KqMembersValidateBiz(); + + Map> validateResult = new KqMembersValidateBiz(params, user).getKqMembersValidateList(); + + List excludeidList = new ArrayList<>(); + KqShiftscheduleOperateLog bean = null; + boolean needChange = false; + ResourceComInfo rci = new ResourceComInfo(); + if(!Util.null2String(kqGroupComInfo.getExcludecount(groupId)).equals("1")) { + String excludeid = Util.null2String(kqGroupComInfo.getExcludeid(groupId)); + if (excludeid.length() > 0) { + excludeidList = Util.splitString2List(excludeid,","); + } + } + for(String resourceid : kqGroupMembers){ + // 排除无需考勤人员 + if(excludeidList != null && excludeidList.contains(resourceid)) { + continue; + } + String workCode = Util.formatMultiLang(Util.null2String(resourceComInfo.getWorkcode(resourceid)),""+user.getLanguage()); + String lastName = Util.formatMultiLang(Util.null2String(resourceComInfo.getLastname(resourceid)),""+user.getLanguage()); + if(workCode.length()>0){ + mapGroupMembersWorkCode.put(workCode,resourceid); + }else if(lastName.length()>0){ + mapGroupMembersLastName.put(lastName,resourceid); + } + } + + sql = " select id, resourceid, kqdate, serialid from kq_shiftschedule where groupid=? and (isdelete is null or isdelete <> '1') "; + rs.executeQuery(sql,groupId); + while(rs.next()){ + mapShiftSchedule.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),Util.null2String(rs.getString("id"))+"#"+Util.null2String(rs.getString("serialid"))); + } + String ssyfDate = ""; + List lsGroupMembers = new ArrayList<>(); + Map mapShiftScheduleOri = new HashMap<>(); + Set unSavePersonAll = new HashSet<>(); + + int firstRow = 6; + int firstCol = 3; + ImageFileManager manager = new ImageFileManager(); + manager.getImageFileInfoById(Util.getIntValue(filename)); + //Workbook workbook = WorkbookFactory.create(manager.getInputStream()); + Workbook workbook = new XSSFWorkbook(manager.getInputStream()); + for (int idx = 0; idx < workbook.getNumberOfSheets(); idx++) { + Sheet sheet = workbook.getSheetAt(idx); + if(sheet.getSheetName().indexOf("constraintDataSheet")>-1)continue; + Row row = null; + Cell cell = null; + + row = sheet.getRow(firstRow); + lsColumn = new ArrayList(); + for (int cellIndex = firstCol; cellIndex < row.getLastCellNum(); cellIndex++) { + cell = row.getCell((short) cellIndex); + lsColumn.add(Util.null2String(getCellValue(cell)).trim()); + } + firstRow++; + + for (int i = firstRow; firstRow<=sheet.getLastRowNum() && i <= sheet.getLastRowNum(); i++) { + row = sheet.getRow(i); + if (row == null) { + continue; + } + String workCode = Util.null2String(row.getCell(1));//编号 + String lastName = Util.null2String(row.getCell(2));//姓名 + if(workCode.length()==0 && lastName.length()==0){ + continue; + } + String resourceId = Util.null2String(mapGroupMembersWorkCode.get(workCode));//人员id + if(resourceId.length()==0){ + resourceId = Util.null2String(mapGroupMembersLastName.get(lastName));//人员id + } + if(resourceId.length()==0)continue; + if(!managerRoleUserIdList.isEmpty()) { + if(!managerRoleUserIdList.contains(resourceId)) continue; + } + lsGroupMembers.add(resourceId); + for (int cellIndex = firstCol; cellIndex < row.getLastCellNum(); cellIndex++) { + cell = row.getCell((short) cellIndex); + if (cell == null) continue; + String serialId = ""; + String serialName = Util.null2String(getCellValue(cell)).trim(); + if(serialName.length()==0)continue; + String kqdate = Util.null2String(lsColumn.get(cellIndex-firstCol)); + kqdate = kqdate.trim().replace(String.valueOf((char)10), "#"); + kqdate = kqdate.split("#")[0]; + if(!SaveShiftScheduleCmd.isDate(kqdate)) { + continue; + } + //if(weaver.common.DateUtil.timeInterval(kqdate,today)>0)continue;//今天之前的无需处理 + serialId = Util.null2String(mapSerial.get(serialName)); + if(serialId.length()==0)continue; + + String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(kqdate+"|"+resourceId)); + String id = ""; + String oldSerialid = ""; + if(!"".equals(shiftScheduleValue)) { + id = shiftScheduleValue.split("#")[0]; + oldSerialid = shiftScheduleValue.split("#")[1]; + } + + // 如果超过了有效期,就不存储数据 + List validateList = validateResult.get(resourceId); + boolean isInRange = kqMembersValidateBiz.isInRange(kqdate, validateList); + if(!isInRange && oldSerialid.length() > 0) { + validateParams = new ArrayList<>(); + validateParams.add(resourceId); + validateParams.add(kqdate); + delValidateParams.add(validateParams); + lsFormatParams.add(validateParams); + bean = new KqShiftscheduleOperateLog(2,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceId), + kqdate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, "",user.getLanguage()); + addLog(bean); + } + + if(id.length()>0 && !oldSerialid.equals(serialId) && oldSerialid.length() > 0){ + needChange = true; + param = new ArrayList(); + param.add(serialId); + param.add(id); + param.add(resourceId); + paramUpdate.add(param); + bean = new KqShiftscheduleOperateLog(1, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceId), + kqdate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(serialId) + "(id:" + serialId + ")"),user.getLanguage()); + addLog(bean); + ssyfDate = kqdate; + mapShiftScheduleOri.put(kqdate+"|"+resourceId,serialId); + }else{ + if(!oldSerialid.equals(serialId)) { + needChange = true; + param = new ArrayList(); + param.add(kqdate); + param.add(serialId); + param.add(resourceId); + param.add(groupId); + paramInsert.add(param); + bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceId), + kqdate, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftManagementComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); + addLog(bean); + ssyfDate = kqdate; + mapShiftScheduleOri.put(kqdate+"|"+resourceId,serialId); + } + } + if(needChange) { + formatParams = new ArrayList<>(); + formatParams.add(resourceId); + formatParams.add(kqdate); + lsFormatParams.add(formatParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceId); + checkSerialParams.add(kqdate); + checkSerialParams.add(serialId); + lscheckSerialParams.add(checkSerialParams); + } + + } + } + + BaseBean bb = new BaseBean(); + String fromDate = TimeUtil.getMonthBeginDay(ssyfDate); + String toDate = TimeUtil.getMonthEndDay(ssyfDate); + List lsDateNew = new ArrayList<>(); + Calendar calNew = weaver.common.DateUtil.getCalendar(); + boolean isEndNew = false; + for(String date=fromDate; !isEndNew;) { + if(date.equals(toDate)) isEndNew = true; + lsDateNew.add(date); + calNew.setTime(weaver.common.DateUtil.parseToDate(date)); + date = weaver.common.DateUtil.getDate(calNew.getTime(), 1); + } + Map mapShiftScheduleAll = new HashMap<>(); + Set unSavePerson = new HashSet<>(); + //上四休二校验,生成预排班数据结构 + for(String resourceid:lsGroupMembers){ + Map mapShiftScheduleChild = new HashMap<>(); + String sqlChild = " select id, resourceid, kqdate,serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; + //有客户提下面的sql有性能问题,在表数据较多,并且该表数据改动较为频率不适合建索引,所以对mapShiftSchedule先缓存的数据范围过滤下,没必要全表缓存 + sqlChild += " and kqdate>='"+fromDate+"' and kqdate<='"+toDate+"' "; + rs.executeQuery(sqlChild,groupId); + while(rs.next()){ + mapShiftScheduleChild.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),rs.getString("serialid")); + } + //生成这个人员这个月的预生成排班 + for(int i=0;i=0){ + findNextXxb1 = false; + } + } + //将date作为一个锚点,往前找并判断是否满足上四休二 + boolean findBefore = true; + Integer dayB = -1; + //工作班数量 + Integer gzbnum = 0; + //判断前面是否还有休息班标识 + Integer xxbNo = 0; + while (findBefore){ + calNew.setTime(weaver.common.DateUtil.parseToDate(date)); + String dateBefore = weaver.common.DateUtil.getDate(calNew.getTime(), dayB); + dayB--; + String bcidBefore = Util.null2String(mapShiftScheduleAll.get(dateBefore+"|"+resourceid)); + bb.writeLog("bcidBefore"+bcidBefore+"dateBefore"+dateBefore+"dayB"+dayB); + if(StringUtils.isNotBlank(bcidBefore)){ + boolean checkXxbBefore = checkXxr(bcidBefore); + if(checkXxbBefore){ + //找到了第一个休息班,判断间隔了多少个非休息班,不再找了 + bb.writeLog("找到了第一个休息班,判断间隔了多少个非休息班,不再找了"); + findBefore = false; + xxbNo = 1; + }else{ + gzbnum ++; + } + } + //找到月初一号了,不找了 + if(weaver.common.DateUtil.timeInterval(dateBefore,fromDate)>=0){ + findBefore = false; + } + } + bb.writeLog("gzbnum"+gzbnum); + if(xxbNo == 1){ + //当前锚点前面有休息班,若间隔工作班数量不为4,则不符合 + if(gzbnum != 4){ + bb.writeLog("当前锚点前面有休息班,若间隔工作班数量不为4,则不符合"); + unSavePerson.add(resourceid); + } + }else{ + //当前锚点是第一个休息班 + if(gzbnum>4){ + //锚点往前有超过四个工作班,不符合 + bb.writeLog("当前锚点是第一个休息班,锚点往前有超过四个工作班,不符合"); + unSavePerson.add(resourceid); + } + } + + }else{ + //找到的不是休息班,也认为不符合上四休二 + bb.writeLog("找到的不是休息班,也认为不符合上四休二"); + unSavePerson.add(resourceid); + } + }else{ + i++; + } + + //到最后一天也没找到,暂不处理 + if(weaver.common.DateUtil.timeInterval(toDate,dateNext)>=0){ + findNextXxb = false; + } + } + } + } + } + } + bb.writeLog("unSavePerson"+JSONObject.toJSONString(unSavePerson)); + unSavePersonAll.addAll(unSavePerson); + + sql = " update kq_shiftschedule set serialid=?, isDelete=0 where id = ? "; + for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) { + List update_params = paramUpdate.get(i); + String serialid = Util.null2String(update_params.get(0)); + String id = Util.null2String(update_params.get(1)); + String resourceid = Util.null2String(update_params.get(2)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, serialid,id); + } + } + + sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)"; + for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) { + List insert_params = paramInsert.get(i); + String kqdate = Util.null2String(insert_params.get(0)); + String serialid = Util.null2String(insert_params.get(1)); + String resourceid = Util.null2String(insert_params.get(2)); + String groupid = Util.null2String(insert_params.get(3)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid); + } + } + } + + // 删除一些有效期之后的排班 + sql = " update kq_shiftschedule set isdelete =1 where resourceid = ? and kqdate = ? and groupid = "+groupId; + for (List delete_params : delValidateParams) { + String resourceid = Util.null2String(delete_params.get(0)); + String kqdate = Util.null2String(delete_params.get(1)); + if(unSavePersonAll.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid, kqdate); + } + + } + + //删除之前的排的班次,一天只能有一个班次 + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and groupid != "+groupId; + for (int i = 0; lsFormatParams != null && i < lsFormatParams.size(); i++) { + List delete_params = lsFormatParams.get(i); + String resourceid = Util.null2String(delete_params.get(0)); + String kqdate = Util.null2String(delete_params.get(1)); + if(unSavePersonAll.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate); + } + } + + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and serialid != ? "; + for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) { + List check_params = lscheckSerialParams.get(i); + String resourceid = Util.null2String(check_params.get(0)); + String kqdate = Util.null2String(check_params.get(1)); + String serialid = Util.null2String(check_params.get(2)); + if(unSavePersonAll.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate,serialid); + } + } + + sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)"; + bRs.executeBatchSqlNew(sql, operateLogParams); + + new KQShiftScheduleComInfo().removeCache(); + + //刷新报表数据 +// sql = " insert into kq_format_pool (resourceid, kqdate) values (?,?)"; +// bRs.executeBatchSql(sql, lsFormatParams); + new KQFormatBiz().format(lsFormatParams,16); + + KQGroupComInfo kQGroupComInfo = new KQGroupComInfo(); + String auto_checkout = kQGroupComInfo.getAuto_checkout(groupId); + String auto_checkin = kQGroupComInfo.getAuto_checkin(groupId); + if("1".equalsIgnoreCase(auto_checkin) || "1".equalsIgnoreCase(auto_checkout)){ + //如果开启了自动打卡,保存考勤组成员之后需要格式化下缓存 + KQAutoCardTask kqAutoCardTask = new KQAutoCardTask(); + kqAutoCardTask.initAutoCardTask(groupId); + } + + if(unSavePersonAll.size()>0){ + List personNameList = new ArrayList<>(); + for(String personid:unSavePersonAll){ + personNameList.add(resourceComInfo.getLastname(personid)); + } + retmap.put("status", "-1"); + retmap.put("message", "【"+StringUtils.join(personNameList,",")+"】上述员工当前月份排班不符合做四休二规则或存在班次为空的日期"); + return retmap; + } + + 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; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } + + /** + * /** + * 获取excel单元格值 + * + * @param cell 要读取的单元格对象 + * @return + */ + public String getCellValue(Cell cell) { + String cellValue = ""; + if (cell == null) + return ""; + switch (cell.getCellType()) { + case BOOLEAN: // 得到Boolean对象的方法 + cellValue = String.valueOf(cell.getBooleanCellValue()); + break; + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) {// 先看是否是日期格式 + SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd"); + cellValue = String.valueOf(sft.format(cell.getDateCellValue())); // 读取日期格式 + } else { + cellValue = String.valueOf(new Double(cell.getNumericCellValue())); // 读取数字 + if (cellValue.endsWith(".0")) + cellValue = cellValue.substring(0, cellValue.indexOf(".")); + } + break; + case FORMULA: // 读取公式 + cellValue = cell.getCellFormula(); + break; + case STRING: // 读取String + cellValue = cell.getStringCellValue(); + break; + } + + return cellValue; + } + + private void addLog(KqShiftscheduleOperateLog bean) { + operateLogParam = new ArrayList<>(); + operateLogParam.add(bean.getOperatetype()); + operateLogParam.add(bean.getOperator()); + operateLogParam.add(bean.getKqgroupname()); + operateLogParam.add(bean.getChangeduser()); + operateLogParam.add(bean.getChangedshiftdate()); + operateLogParam.add(bean.getChangedshiftname()); + operateLogParam.add(bean.getKqshiftid()); + operateLogParams.add(operateLogParam); + } + + /** + * 获取当前日期是何种类型(这里只考虑节假日设置) + * + * @param groupId 考勤组ID + * @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(); + String tmpChangetype = kqHolidaySetComInfo.getChangeType(groupId, date); + if(null != tmpChangetype){ + changeType = Util.getIntValue(tmpChangetype, -1); + } + + return changeType; + } + + /** + * 判断是否是休息班 + * @param serialid + * @return + */ + private static Boolean checkXxr(String serialid){ + RecordSet rs = new RecordSet(); + String sql = "select * from kq_ShiftManagement where id = "+serialid+" and is_rest = 1"; + rs.execute(sql); + Boolean check = false; + if (rs.getCounts()>0){ + check = true; + } + return check; + } +} diff --git a/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java b/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java new file mode 100644 index 0000000..cffd6f7 --- /dev/null +++ b/src/com/engine/kq/cmd/shiftschedule/SaveBatchShiftScheduleCmd.java @@ -0,0 +1,475 @@ +package com.engine.kq.cmd.shiftschedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.bean.KqShiftscheduleOperateLog; +import com.engine.kq.biz.*; +import weaver.common.DateUtil; +import weaver.conn.BatchRecordSet; +import weaver.conn.DBUtil; +import weaver.conn.RecordSet; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.util.*; + +public class SaveBatchShiftScheduleCmd extends AbstractCommonCommand> { + + private SimpleBizLogger logger; + // 添加日志功能 + private List> operateLogParams = new ArrayList<>(); + // 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id + private List operateLogParam = null; + + public SaveBatchShiftScheduleCmd(Map params, User user) { + this.user = user; + this.params = params; + this.logger = new SimpleBizLogger(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + BatchRecordSet bRs = new BatchRecordSet(); + String today = DateUtil.getCurrentDate(); + String sql = ""; + try{ + //必要的权限判断 + if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + + ResourceComInfo resourceComInfo = new ResourceComInfo(); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + String data = Util.null2String(params.get("data")); + JSONObject jsonObj = JSON.parseObject(data); + String groupId = Util.null2String(jsonObj.get("groupId"));//考勤组id + String shiftScheduleType = Util.null2String(jsonObj.get("shiftScheduleType"));//排班类型 + String shiftScheduleDate = Util.null2String(jsonObj.get("shiftScheduleDate"));//排班日期 + String shiftScheduleBeginDate = Util.null2String(jsonObj.get("shiftScheduleBeginDate"));//排班开始日期 + String shiftScheduleEndDate = Util.null2String(jsonObj.get("shiftScheduleEndDate"));//排班结束日期 + String shiftScheduleMemberType = Util.null2String(jsonObj.get("shiftScheduleMemberType"));//排班人员类型 + String shiftScheduleMember = Util.null2String(jsonObj.get("shiftScheduleMember"));//排班人员 + String holidayType = Util.null2String(jsonObj.get("holidayType"));//遇双休日 + String meetHolidays = Util.null2String(jsonObj.get("meetHolidays"));//遇节假日 + String meetRestDays = Util.null2String(jsonObj.get("meetRestDays"));//遇调配休息日 + String serialId = Util.null2String(jsonObj.get("serialId"));//班次 + String shiftcycleId = Util.null2String(jsonObj.get("shiftcycleId"));//排班周期Id + + // 某个管理员所拥有的维护人员的权限 + List managerRoleUserIdList = new KqShiftScheduleRoleBiz().getUfKqShiftScheduleRoleValue(""+user.getUID(), groupId); + KqMembersValidateBiz kqMembersValidateBiz = new KqMembersValidateBiz(); + Map paramsValidate = new HashMap<>(); + paramsValidate.put("groupId",groupId); + paramsValidate.put("isNoAccount","1"); + if("2".equals(shiftScheduleMemberType)) { // 按人员排班 + paramsValidate.put("resourceId",shiftScheduleMember); + } + Map> validateResult = new KqMembersValidateBiz(paramsValidate, user).getKqMembersValidateList(); + + List> paramInsert = new ArrayList>(); + List> paramUpdate = new ArrayList>(); + List params = null; + String delIds = ""; + + List> lsFormatParams = new ArrayList<>(); + List formatParams = new ArrayList<>(); + + List> lsDeleteParams = new ArrayList<>(); + List deleteParams = null; + + List> lscheckSerialParams = new ArrayList<>(); + List checkSerialParams = new ArrayList<>(); + + List> lsDeleteCancelParams = new ArrayList<>(); + List deleteCancelParams = null; + + List lsGroupMembers = null; + if(shiftScheduleMemberType.equals("1")){//所有考勤组成员 + lsGroupMembers = kqGroupBiz.getGroupMembers(groupId); + }else{//考勤组成员 + lsGroupMembers = Util.splitString2List(shiftScheduleMember,","); + } + List excludeidList = new ArrayList<>(); + if(!Util.null2String(kqGroupComInfo.getExcludecount(groupId)).equals("1")) { + String excludeid = Util.null2String(kqGroupComInfo.getExcludeid(groupId)); + if (excludeid.length() > 0) { + excludeidList = Util.splitString2List(excludeid,","); + } + } + Map mapShiftSchedule = new HashMap<>(); + sql = " select id, resourceid, kqdate, serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; + //有客户提下面的sql有性能问题,在表数据较多,并且该表数据改动较为频率不适合建索引,所以对mapShiftSchedule先缓存的数据范围过滤下,没必要全表缓存 + if("1".equals(shiftScheduleType)){//按天排班 + sql += " and kqdate='"+shiftScheduleDate+"' "; + }else if("2".equals(shiftScheduleType)){ + sql += " and kqdate>='"+shiftScheduleBeginDate+"' and kqdate<='"+shiftScheduleEndDate+"' "; + } + rs.executeQuery(sql,groupId); + while(rs.next()){ + mapShiftSchedule.put(rs.getString("kqdate")+"|"+Util.null2String(rs.getString("resourceid")), Util.null2String(rs.getString("id"))+"#"+Util.null2String(rs.getString("serialid"))); + } + String id = ""; + String oldSerialid = ""; + boolean needChange = false; + KQShiftManagementComInfo kqShiftScheduleComInfo = new KQShiftManagementComInfo(); + ResourceComInfo rci = new ResourceComInfo(); + KqShiftscheduleOperateLog bean = null; + if(shiftScheduleType.equals("1")){//按天排班 + if(SaveShiftScheduleCmd.isDate(shiftScheduleDate)) { + for (String resourceid : lsGroupMembers) { + // 排除无需考勤人员 + if (excludeidList != null && excludeidList.contains(resourceid)) { + continue; + } + if (!managerRoleUserIdList.isEmpty()) { + if (!managerRoleUserIdList.contains(resourceid)) { + continue; + } + } + String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(shiftScheduleDate + "|" + resourceid)); + if (!"".equals(shiftScheduleValue)) { + id = shiftScheduleValue.split("#")[0]; + oldSerialid = shiftScheduleValue.split("#")[1]; + } + // 如果超过了有效期,就不存储数据 + List validateList = validateResult.get(resourceid); + boolean isInRange = kqMembersValidateBiz.isInRange(shiftScheduleDate, validateList); + if (!isInRange && oldSerialid.length() > 0) { + if (delIds.length() > 0) { + delIds += ","; + } + delIds += id; + bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); + addLog(bean); + continue; + } + //if(weaver.common.DateUtil.timeInterval(shiftScheduleDate,today)>0)continue;//今天之前的无需处理 + if (id.length() > 0) { + if (serialId.length() == 0 && oldSerialid.length() > 0) { + if (delIds.length() > 0) { + delIds += ","; + } + delIds += id; + bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); + addLog(bean); + } else { + if (!oldSerialid.equals(serialId) && oldSerialid.length() > 0) { + needChange = true; + params = new ArrayList(); + params.add(serialId); + params.add(id); + paramUpdate.add(params); + bean = new KqShiftscheduleOperateLog(1, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + shiftScheduleDate, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); + addLog(bean); + } + } + } else { + if (serialId.length() == 0) continue; + if(!oldSerialid.equals(serialId)) { + needChange = true; + params = new ArrayList(); + params.add(shiftScheduleDate); + params.add(serialId); + params.add(resourceid); + params.add(groupId); + paramInsert.add(params); + bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + shiftScheduleDate, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); + addLog(bean); + } + } + if (needChange) { + if (DateUtil.timeInterval(shiftScheduleDate, today) >= 0) { + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(shiftScheduleDate); + lsFormatParams.add(formatParams); + } + + deleteParams = new ArrayList<>(); + deleteParams.add(resourceid); + deleteParams.add(shiftScheduleDate); + lsDeleteParams.add(deleteParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceid); + checkSerialParams.add(shiftScheduleDate); + checkSerialParams.add(serialId); + lscheckSerialParams.add(checkSerialParams); + } + } + } + }else if(shiftScheduleType.equals("2")){//按周期排班 + List lsDate = new ArrayList<>(); + Calendar cal = DateUtil.getCalendar(); + writeLog("shiftScheduleBeginDate==" + shiftScheduleBeginDate + "shiftScheduleEndDate==" + shiftScheduleEndDate); + if (DateUtil.timeInterval(shiftScheduleEndDate, shiftScheduleBeginDate) > 0) + { + retmap.put("status", "-1"); + retmap.put("message", ""+ SystemEnv.getHtmlLabelName(10005344,weaver.general.ThreadVarLanguage.getLang())+""); + return retmap; + } + + int shiftcycleday = 0; + String[] shiftcycleserialids = null; + sql = "select shiftcycleday,shiftcycleserialids from kq_group_shiftcycle where id = ? order by id asc "; + rs.executeQuery(sql,shiftcycleId); + if(rs.next()){ + shiftcycleday = rs.getInt("shiftcycleday"); + shiftcycleserialids = Util.splitString(Util.null2String(rs.getString("shiftcycleserialids")), ","); + } + + boolean isEnd = false; + for(String date=shiftScheduleBeginDate; !isEnd;) { + if(date.equals(shiftScheduleEndDate)) isEnd = true; + lsDate.add(date); + cal.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(cal.getTime(), 1); + } + + for(String resourceid:lsGroupMembers){ + // 排除无需考勤人员 + if(excludeidList != null && excludeidList.contains(resourceid)) { + continue; + } + if(!managerRoleUserIdList.isEmpty()) { + if(!managerRoleUserIdList.contains(resourceid)) { + continue; + } + } + boolean needShiftSchedule = false; + int dayCount = 0; + for(int i=0;i0)continue;//今天之前的无需处理 + String date = lsDate.get(i); + if(!SaveShiftScheduleCmd.isDate(date)) { + continue; + } + String shiftScheduleValue = Util.null2String(mapShiftSchedule.get(date+"|"+resourceid)); + if(!"".equals(shiftScheduleValue)) { + id = shiftScheduleValue.split("#")[0]; + oldSerialid = shiftScheduleValue.split("#")[1]; + } + + // 如果超过了有效期,就不存储数据 + List validateList = validateResult.get(resourceid); + boolean isInRange = kqMembersValidateBiz.isInRange(date, validateList); + if(!isInRange) { + if(oldSerialid.length() > 0) { + if (delIds.length() > 0) { + delIds += ","; + } + delIds += id; + bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "", user.getLanguage()); + addLog(bean); + } + continue; + } + + needShiftSchedule = true; + int changeType= KQHolidaySetBiz.getChangeType(groupId, date); + if (changeType != 1 && changeType != 3 && !holidayType.equals("1")) {//遇双休日继续排班 + int weekDay = DateUtil.getWeek(date); + if(weekDay>5){ + needShiftSchedule = false; + } + } + if(!meetHolidays.equals("1")){//遇节假日继续排班 + if(changeType==1){ + needShiftSchedule = false; + } + } + if(!meetRestDays.equals("1")){//遇调配休息日继续排班 + if(changeType==3){ + needShiftSchedule = false; + } + } + + if(needShiftSchedule){ + dayCount++; + int idx = dayCount % shiftcycleday; + if (idx == 0) {//周期最后一天 + serialId = Util.null2String(shiftcycleserialids[shiftcycleserialids.length - 1]); + } else { + serialId = Util.null2String(shiftcycleserialids[idx-1]); + } + if(id.length()>0){ + if(serialId.length()==0 && oldSerialid.length() > 0){ + if(delIds.length()>0) { + delIds+=","; + } + delIds+=id; + bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "",user.getLanguage()); + addLog(bean); + }else { + if(!oldSerialid.equals(serialId) && oldSerialid.length() > 0) { + needChange = true; + params = new ArrayList(); + params.add(serialId); + params.add(id); + paramUpdate.add(params); + bean = new KqShiftscheduleOperateLog(1,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId)+"(id:"+serialId+")"),user.getLanguage()); + addLog(bean); + } + } + }else{ + if(serialId.length()>0){ + if(!oldSerialid.equals(serialId)) { + needChange = true; + params = new ArrayList(); + params.add(date); + params.add(serialId); + params.add(resourceid); + params.add(groupId); + paramInsert.add(params); + bean = new KqShiftscheduleOperateLog(0, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + date, "", id, ("-1".equals(serialId) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialId) + "(id:" + serialId + ")"), user.getLanguage()); + addLog(bean); + } + } + } + }else{ + if(oldSerialid.length() > 0) { + deleteCancelParams = new ArrayList<>(); + deleteCancelParams.add(resourceid); + deleteCancelParams.add(date); + lsDeleteCancelParams.add(deleteCancelParams); + bean = new KqShiftscheduleOperateLog(2, user.getLastname(), kqGroupComInfo.getGroupname(groupId) + "(id:" + groupId + ")", rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid) + "(id:" + oldSerialid + ")"), id, "",user.getLanguage()); + addLog(bean); + } + } + if(needChange) { + if(DateUtil.timeInterval(date,today)>=0) { + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(date); + lsFormatParams.add(formatParams); + } + + deleteParams = new ArrayList<>(); + deleteParams.add(resourceid); + deleteParams.add(date); + lsDeleteParams.add(deleteParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceid); + checkSerialParams.add(shiftScheduleDate); + checkSerialParams.add(serialId); + lscheckSerialParams.add(checkSerialParams); + } + } + } + } + + sql = " update kq_shiftschedule set serialid=?,isDelete=0 where id = ? "; + for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) { + List update_params = paramUpdate.get(i); + String serialid = Util.null2String(update_params.get(0)); + String tmp_id = Util.null2String(update_params.get(1)); + rs.executeUpdate(sql, serialid,tmp_id); + } + + sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)"; + for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) { + List insert_params = paramInsert.get(i); + String kqdate = Util.null2String(insert_params.get(0)); + String serialid = Util.null2String(insert_params.get(1)); + String resourceid = Util.null2String(insert_params.get(2)); + String groupid = Util.null2String(insert_params.get(3)); + rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid); + } + + if(delIds.length()>0){ + List sqlParams = new ArrayList(); + Object[] objects= DBUtil.transListIn(delIds,sqlParams); + sql = "update kq_shiftschedule set isdelete =1 where id in("+objects[0]+") "; + rs.executeUpdate(sql, sqlParams); + } + //删除批量排班,遇双休日、节假日、调配工作日的取消排班 + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? "; + for (int i = 0; lsDeleteCancelParams != null && i < lsDeleteCancelParams.size(); i++) { + List delete_params = lsDeleteCancelParams.get(i); + String resourceid = Util.null2String(delete_params.get(0)); + String kqdate = Util.null2String(delete_params.get(1)); + rs.executeUpdate(sql, resourceid,kqdate); + } + + //删除之前的排的班次,一天只能有一个班次 + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and groupid != "+groupId; + for (int i = 0; lsDeleteParams != null && i < lsDeleteParams.size(); i++) { + List delete_params = lsDeleteParams.get(i); + String resourceid = Util.null2String(delete_params.get(0)); + String kqdate = Util.null2String(delete_params.get(1)); + rs.executeUpdate(sql, resourceid,kqdate); + } + + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and serialid != ? "; + for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) { + List check_params = lscheckSerialParams.get(i); + String resourceid = Util.null2String(check_params.get(0)); + String kqdate = Util.null2String(check_params.get(1)); + String serialid = Util.null2String(check_params.get(2)); + rs.executeUpdate(sql, resourceid,kqdate,serialid); + } + + sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)"; + bRs.executeBatchSqlNew(sql, operateLogParams); + + new KQShiftScheduleComInfo().removeCache(); + + //刷新报表数据 + new KQFormatBiz().format(lsFormatParams,16); + + retmap.put("status", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage())); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private void addLog(KqShiftscheduleOperateLog bean) { + operateLogParam = new ArrayList<>(); + operateLogParam.add(bean.getOperatetype()); + operateLogParam.add(bean.getOperator()); + operateLogParam.add(bean.getKqgroupname()); + operateLogParam.add(bean.getChangeduser()); + operateLogParam.add(bean.getChangedshiftdate()); + operateLogParam.add(bean.getChangedshiftname()); + operateLogParam.add(bean.getKqshiftid()); + operateLogParams.add(operateLogParam); + } + + @Override + public BizLogContext getLogContext() { + return null; + } + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } +} diff --git a/src/com/engine/kq/cmd/shiftschedule/SaveShiftScheduleCmd.java b/src/com/engine/kq/cmd/shiftschedule/SaveShiftScheduleCmd.java new file mode 100644 index 0000000..6374cef --- /dev/null +++ b/src/com/engine/kq/cmd/shiftschedule/SaveShiftScheduleCmd.java @@ -0,0 +1,510 @@ +package com.engine.kq.cmd.shiftschedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.biz.SimpleBizLogger; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.kq.bean.KqShiftscheduleOperateLog; +import com.engine.kq.biz.*; +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.BatchRecordSet; +import weaver.conn.DBUtil; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.TimeUtil; +import weaver.general.Util; +import weaver.hrm.HrmUserVarify; +import weaver.hrm.Reminder.KQAutoCardTask; +import weaver.hrm.User; +import weaver.hrm.resource.ResourceComInfo; +import weaver.systeminfo.SystemEnv; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.*; + +public class SaveShiftScheduleCmd extends AbstractCommonCommand> { + + private SimpleBizLogger logger; + + // 添加日志功能 + private List> operateLogParams = new ArrayList<>(); + // 操作类型 操作人 考勤组名称+id 被修改人 被修改班次日期 被修改班次+id 排班设置行id + private List operateLogParam = null; + + public SaveShiftScheduleCmd(Map params, User user) { + this.user = user; + this.params = params; + this.logger = new SimpleBizLogger(); + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + RecordSet rs = new RecordSet(); + BatchRecordSet bRs = new BatchRecordSet(); + String today = DateUtil.getCurrentDate(); + String sql = ""; + try{ + //必要的权限判断 + if(!HrmUserVarify.checkUserRight("HrmKQGroup:Add",user)) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(2012, user.getLanguage())); + return retmap; + } + String data = Util.null2String(params.get("data")); + JSONObject jsonObj = JSON.parseObject(data); + KQGroupComInfo kqGroupComInfo = new KQGroupComInfo(); + KQShiftManagementComInfo kqShiftScheduleComInfo = new KQShiftManagementComInfo(); + ResourceComInfo rci = new ResourceComInfo(); + String groupId = Util.null2String(jsonObj.get("groupId")); + JSONArray datas = jsonObj.getJSONArray("datas"); + + List> paramInsert = new ArrayList>(); + List> paramUpdate = new ArrayList>(); + List params = null; + String delIds = ""; + List> lsFormatParams = new ArrayList<>(); + List formatParams = null; + List> lsDeleteParams = new ArrayList<>(); + List deleteParams = null; + List> lscheckSerialParams = new ArrayList<>(); + List checkSerialParams = null; + + JSONObject resourceDataObj = null; + JSONArray arrKqDataObj = null; + JSONObject kqDataObj = null; + KqShiftscheduleOperateLog bean = null; + //获取所属月份用日期 + String ssyfDate = ""; + List lsGroupMembers = new ArrayList<>(); + Map mapShiftScheduleOri = new HashMap<>(); + for(int i=0;datas!=null&&i0)continue;//今天之前的无需处理 + if(id.length()>0){ // 更新 + ssyfDate = date; + if(serialid.length()==0 && oldSerialid.length() > 0){ //删除 + if(delIds.length()>0) { + delIds+=","; + } + delIds+=id; + bean = new KqShiftscheduleOperateLog(2,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, "", user.getLanguage()); + addLog(bean); + }else { + if(!oldSerialid.equals(serialid) && oldSerialid.length() > 0) { + needChange = true; + params = new ArrayList(); + params.add(serialid); + params.add(id); + params.add(resourceid); + paramUpdate.add(params); + bean = new KqShiftscheduleOperateLog(1,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceid), + date, ("-1".equals(oldSerialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(oldSerialid)+"(id:"+oldSerialid+")"), id, ("-1".equals(serialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialid)+"(id:"+serialid+")"), user.getLanguage()); + addLog(bean); + } + } + mapShiftScheduleOri.put(date+"|"+resourceid,serialid); + }else{ //新建 + if(serialid.length()==0)continue; + if(!oldSerialid.equals(serialid)) { + ssyfDate = date; + needChange = true; + params = new ArrayList(); + params.add(date); + params.add(serialid); + params.add(resourceid); + params.add(groupId); + paramInsert.add(params); + bean = new KqShiftscheduleOperateLog(0,user.getLastname(),kqGroupComInfo.getGroupname(groupId)+"(id:"+groupId+")",rci.getLastname(resourceid), + date, "", id, ("-1".equals(serialid) ? SystemEnv.getHtmlLabelName(26593, user.getLanguage()) : kqShiftScheduleComInfo.getSerial(serialid)+"(id:"+serialid+")"), user.getLanguage()); + addLog(bean); + mapShiftScheduleOri.put(date+"|"+resourceid,serialid); + } + } + if(needChange) { + deleteParams = new ArrayList<>(); + deleteParams.add(resourceid); + deleteParams.add(date); + lsDeleteParams.add(deleteParams); + + checkSerialParams = new ArrayList<>(); + checkSerialParams.add(resourceid); + checkSerialParams.add(date); + checkSerialParams.add(serialid); + lscheckSerialParams.add(checkSerialParams); + + if(DateUtil.timeInterval(date,today)>=0) { + formatParams = new ArrayList<>(); + formatParams.add(resourceid); + formatParams.add(date); + lsFormatParams.add(formatParams); + } + } + } + } + + BaseBean bb = new BaseBean(); + String fromDate = TimeUtil.getMonthBeginDay(ssyfDate); + String toDate = TimeUtil.getMonthEndDay(ssyfDate); + List lsDateNew = new ArrayList<>(); + Calendar calNew = DateUtil.getCalendar(); + boolean isEndNew = false; + for(String date=fromDate; !isEndNew;) { + if(date.equals(toDate)) isEndNew = true; + lsDateNew.add(date); + calNew.setTime(DateUtil.parseToDate(date)); + date = DateUtil.getDate(calNew.getTime(), 1); + } + Map mapShiftScheduleAll = new HashMap<>(); + Set unSavePerson = new HashSet<>(); + //上四休二校验,生成预排班数据结构 + for(String resourceid:lsGroupMembers){ + Map mapShiftScheduleChild = new HashMap<>(); + String sqlChild = " select id, resourceid, kqdate,serialid from kq_shiftschedule where (isdelete is null or isdelete <> '1') and groupid=? "; + //有客户提下面的sql有性能问题,在表数据较多,并且该表数据改动较为频率不适合建索引,所以对mapShiftSchedule先缓存的数据范围过滤下,没必要全表缓存 + sqlChild += " and kqdate>='"+fromDate+"' and kqdate<='"+toDate+"' "; + rs.executeQuery(sqlChild,groupId); + while(rs.next()){ + mapShiftScheduleChild.put(rs.getString("kqdate")+"|"+rs.getString("resourceid"),rs.getString("serialid")); + } + //生成这个人员这个月的预生成排班 + for(int i=0;i=0){ + findNextXxb1 = false; + } + } + //将date作为一个锚点,往前找并判断是否满足上四休二 + boolean findBefore = true; + Integer dayB = -1; + //工作班数量 + Integer gzbnum = 0; + //判断前面是否还有休息班标识 + Integer xxbNo = 0; + while (findBefore){ + calNew.setTime(DateUtil.parseToDate(date)); + String dateBefore = DateUtil.getDate(calNew.getTime(), dayB); + dayB--; + String bcidBefore = Util.null2String(mapShiftScheduleAll.get(dateBefore+"|"+resourceid)); + bb.writeLog("bcidBefore"+bcidBefore+"dateBefore"+dateBefore+"dayB"+dayB); + if(StringUtils.isNotBlank(bcidBefore)){ + boolean checkXxbBefore = checkXxr(bcidBefore); + if(checkXxbBefore){ + //找到了第一个休息班,判断间隔了多少个非休息班,不再找了 + bb.writeLog("找到了第一个休息班,判断间隔了多少个非休息班,不再找了"); + findBefore = false; + xxbNo = 1; + }else{ + gzbnum ++; + } + } + //找到月初一号了,不找了 + if(DateUtil.timeInterval(dateBefore,fromDate)>=0){ + findBefore = false; + } + } + bb.writeLog("gzbnum"+gzbnum); + if(xxbNo == 1){ + //当前锚点前面有休息班,若间隔工作班数量不为4,则不符合 + if(gzbnum != 4){ + bb.writeLog("当前锚点前面有休息班,若间隔工作班数量不为4,则不符合"); + unSavePerson.add(resourceid); + } + }else{ + //当前锚点是第一个休息班 + if(gzbnum>4){ + //锚点往前有超过四个工作班,不符合 + bb.writeLog("当前锚点是第一个休息班,锚点往前有超过四个工作班,不符合"); + unSavePerson.add(resourceid); + } + } + + }else{ + //找到的不是休息班,也认为不符合上四休二 + bb.writeLog("找到的不是休息班,也认为不符合上四休二"); + unSavePerson.add(resourceid); + } + }else{ + i++; + } + + //到最后一天也没找到,暂不处理 + if(DateUtil.timeInterval(toDate,dateNext)>=0){ + findNextXxb = false; + } + } + } + } + } + } + bb.writeLog("unSavePerson"+JSONObject.toJSONString(unSavePerson)); + + + + sql = " update kq_shiftschedule set serialid=?,isDelete=0 where id = ? "; + for (int i = 0; paramUpdate != null && i < paramUpdate.size(); i++) { + List update_params = paramUpdate.get(i); + String serialid = Util.null2String(update_params.get(0)); + String id = Util.null2String(update_params.get(1)); + String resourceid = Util.null2String(update_params.get(2)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, serialid,id); + } + } + + sql = "insert into kq_shiftschedule (kqdate,serialid,resourceid,groupid,isDelete) values(?,?,?,?,0)"; + for (int i = 0; paramInsert != null && i < paramInsert.size(); i++) { + List insert_params = paramInsert.get(i); + String kqdate = Util.null2String(insert_params.get(0)); + String serialid = Util.null2String(insert_params.get(1)); + String resourceid = Util.null2String(insert_params.get(2)); + String groupid = Util.null2String(insert_params.get(3)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, kqdate,serialid,resourceid,groupid); + } + } + + if(delIds.length()>0){ + List sqlParams = new ArrayList(); + Object[] objects= DBUtil.transListIn(delIds,sqlParams); + sql = "update kq_shiftschedule set isdelete =1 where id in("+objects[0]+") "; + rs.executeUpdate(sql, sqlParams); + } + + //删除之前的排的班次,一天只能有一个班次 + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and groupid != "+groupId; + for (int i = 0; lsDeleteParams != null && i < lsDeleteParams.size(); i++) { + List delete_params = lsDeleteParams.get(i); + String resourceid = Util.null2String(delete_params.get(0)); + String kqdate = Util.null2String(delete_params.get(1)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate); + } + } + + sql = " update kq_shiftschedule set isdelete =1 where (isdelete is null or isdelete <> '1') and resourceid = ? and kqdate = ? and serialid != ? "; + for (int i = 0; lscheckSerialParams != null && i < lscheckSerialParams.size(); i++) { + List check_params = lscheckSerialParams.get(i); + String resourceid = Util.null2String(check_params.get(0)); + String kqdate = Util.null2String(check_params.get(1)); + String serialid = Util.null2String(check_params.get(2)); + if(unSavePerson.contains(resourceid)){ + //该人员不符合规则,不生效 + }else{ + rs.executeUpdate(sql, resourceid,kqdate,serialid); + } + } + + sql = "insert into kq_shiftscheduleoperate_log(operatetype,operator,kqgroupname,changeduser,changedshiftdate,changedshiftname,kqshiftid) values(?,?,?,?,?,?,?)"; + bRs.executeBatchSqlNew(sql, operateLogParams); + + new KQShiftScheduleComInfo().removeCache(); + + //刷新报表数据 + new KQFormatBiz().format(lsFormatParams,16); + + KQGroupComInfo kQGroupComInfo = new KQGroupComInfo(); + String auto_checkout = kQGroupComInfo.getAuto_checkout(groupId); + String auto_checkin = kQGroupComInfo.getAuto_checkin(groupId); + if("1".equalsIgnoreCase(auto_checkin) || "1".equalsIgnoreCase(auto_checkout)){ + //如果开启了自动打卡,保存考勤组成员之后需要格式化下缓存 + KQAutoCardTask kqAutoCardTask = new KQAutoCardTask(); + kqAutoCardTask.initAutoCardTask(groupId); + } + + if(unSavePerson.size()>0){ + ResourceComInfo resourceComInfo = new ResourceComInfo(); + List personNameList = new ArrayList<>(); + for(String personid:unSavePerson){ + personNameList.add(resourceComInfo.getLastname(personid)); + } + retmap.put("status", "-1"); + retmap.put("message", "【"+StringUtils.join(personNameList,",")+"】上述员工当前月份排班不符合做四休二规则或存在班次为空的日期"); + return retmap; + } + + retmap.put("status", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(18758, user.getLanguage())); + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + return retmap; + } + + private void addLog(KqShiftscheduleOperateLog bean) { + operateLogParam = new ArrayList<>(); + operateLogParam.add(bean.getOperatetype()); + operateLogParam.add(bean.getOperator()); + operateLogParam.add(bean.getKqgroupname()); + operateLogParam.add(bean.getChangeduser()); + operateLogParam.add(bean.getChangedshiftdate()); + operateLogParam.add(bean.getChangedshiftname()); + operateLogParam.add(bean.getKqshiftid()); + operateLogParams.add(operateLogParam); + } + + public static boolean isDate(String str) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + sdf.setLenient(false); // 严格匹配 + try { + sdf.parse(str); + return true; + } catch (ParseException e) { + return false; + } + } + + /** + * 获取当前日期是何种类型(这里只考虑节假日设置) + * + * @param groupId 考勤组ID + * @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(); + String tmpChangetype = kqHolidaySetComInfo.getChangeType(groupId, date); + if(null != tmpChangetype){ + changeType = Util.getIntValue(tmpChangetype, -1); + } + + return changeType; + } + + /** + * 判断是否是休息班 + * @param serialid + * @return + */ + private static Boolean checkXxr(String serialid){ + RecordSet rs = new RecordSet(); + String sql = "select * from kq_ShiftManagement where id = "+serialid+" and is_rest = 1"; + rs.execute(sql); + Boolean check = false; + if (rs.getCounts()>0){ + check = true; + } + return check; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + + @Override + public List getLogContexts() { + return logger.getBizLogContexts(); + } +} diff --git a/src/com/engine/kq/util/KQDurationCalculatorUtil.java b/src/com/engine/kq/util/KQDurationCalculatorUtil.java new file mode 100644 index 0000000..5326a5e --- /dev/null +++ b/src/com/engine/kq/util/KQDurationCalculatorUtil.java @@ -0,0 +1,692 @@ +package com.engine.kq.util; + +import com.engine.kq.bean.KQRepeatBean; +import com.engine.kq.biz.KQLeaveRulesBiz; +import com.engine.kq.biz.KQLeaveRulesComInfo; +import com.engine.kq.biz.KQRepeatLengthContext; +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.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.hrm.report.schedulediff.HrmScheduleDiffUtil; +import weaver.hrm.resource.SptmForLeave; + +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); + } + + /** + * 不记录日志的,流程的超时提醒日志太大 + * @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){ + 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"); + 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(){ + + 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); + 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); + String repeatTime = kqLeaveRulesComInfo.getRepeatTime(newLeaveType); + splitBean.setConversion(conversion); + splitBean.setRepeatTime(repeatTime); + } + } + + 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; + } + + /** + * 根据传入的用户和时段返回工作时长 + * @return + */ + public List getWorkDurationCustom(){ + List splitBeans = new ArrayList<>(); + + try{ + if(!isValidate(fromDate,toDate,fromTime,toTime)){ + return splitBeans; + } + 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 splitBeans; + } + //时长 + 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); + 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); + String repeatTime = kqLeaveRulesComInfo.getRepeatTime(newLeaveType); + splitBean.setConversion(conversion); + splitBean.setRepeatTime(repeatTime); + } + } + + + 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); + + + }catch (Exception e){ + e.printStackTrace(); + } + return splitBeans; + } + + /** + * 校验是传入的参数数据是否正常 + * @return false 表示数据有误 + */ + private boolean isValidate(String fromDate,String toDate,String fromTime,String toTime) { + + KQRepeatBean kqRepeatBean = KQRepeatLengthContext.getRepeatBean(); + if(kqRepeatBean != null){ + return true; + } + 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的build方法,返回外部类的实例 + public KQDurationCalculatorUtil build() { + return new KQDurationCalculatorUtil(this); + } + } + +} 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..a6f827a --- /dev/null +++ b/src/com/engine/kq/wfset/util/SplitActionUtil.java @@ -0,0 +1,3487 @@ +package com.engine.kq.wfset.util; + +import org.springframework.beans.BeanUtils; +import com.alibaba.fastjson.JSON; +import com.engine.kq.bean.KQHrmScheduleSign; +import com.engine.kq.bean.KQRepeatBean; +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.jucailin.util.KQDateUtil; +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.SplitBean; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.sql.Date; +import java.sql.Timestamp; +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.apache.commons.lang3.StringUtils; +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(); + + /** + * 现在先用正常的去执行吧 + * + * @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("请假扣减:resourceId:" + resourceId + ":fromdate:" + fromdate + ":duration:" + duration + ":newLeaveType:" + newLeaveType + ":durationrule:" + durationrule + ":requestid:" + requestid + ":fromdatedb:" + fromdatedb); + if(Util.getDoubleValue(duration) <= 0){ + continue; + } + 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 fromDate = keys[1]; + String belongToDate = keys[2]; + if(checkHasKTCard(resourceId, fromDate)){ + fromDate = DateUtil.addDate(fromDate,-1); + } + kqOvertimeCalBiz.buildOvertime(resourceId, fromDate, belongToDate, "加班流程生成加班#flow,requestId:" + requestid); + } + } + } + } + + /** + * 判斷下昨日的打卡有沒有落在今日的數據,如果有,則加班需要往前多算一天 + * @param resourceId + * @param belongDate + * @return + */ + public static boolean checkHasKTCard(String resourceId, String belongDate){ + RecordSet recordSet = new RecordSet(); + //如果打卡存在跨天的情况 + String sql = "select count(*) as cnt from KQ_FORMAT_DETAIL where RESOURCEID="+resourceId+" and KQDATE='"+DateUtil.addDate(belongDate, -1)+"' and (SIGNOUTDATE='"+belongDate+"' or signindate='"+belongDate+"')"; + recordSet.executeQuery(sql); + if(recordSet.next()){ + String cnt = recordSet.getString("cnt"); + if(Util.getIntValue(cnt, 0) > 0){ + return true; + } + } + return false; + } + + 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 是否是归档节点 归档节点才可以把加班数据写到加班中间表,不是归档节点的话意味着只生成调休不生成加班,只有强制归档canMode2才是true + * @param from_uuid 来自action的uuid + */ + public static void handleOverTimeAction(List splitBeans, String requestid, + boolean canMode2, String from_uuid) throws Exception { +// 保证同一个requestid能重复生成调休和加班 + 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 fromDate = keys[1]; + String belongToDate = keys[2]; + if(checkHasKTCard(resourceId, fromDate)){ + fromDate = DateUtil.addDate(fromDate,-1); + } + kqOvertimeCalBiz.buildOvertime(resourceId, fromDate, belongToDate, "加班流程生成加班#flow,requestId:" + requestid + "#from_uuid|" + from_uuid); + } + } + } + } + + /** + * 保证同一个requestid能重复生成调休和加班 + * + * @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,update_time=? where " + Util.getSubINClause(clear_tiaoxiuids, "id", "in"); + if (rs.getDBType().equals("postgresql")) { + clearSql = "update kq_balanceofleave set tiaoxiuamount=0.0,update_time=?::timestamp where " + Util.getSubINClause(clear_tiaoxiuids, "id", "in"); + } + boolean isclearOk = rs.executeUpdate(clearSql,KQDateUtil.getUpdateTimeStamp()); + 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); + 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这个表呢,因为kqpaidleaveaction可能和splitaction不是在同一个归档前节点 + 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 加班生成调休失败!!!"); + } + } + + /** + * 加班方式是第一种,然后再流程归档的时候把加班数据写到加班中间表里 + * + * @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); + int unit = KQOvertimeRulesBiz.getMinimumUnit(); + + 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"; + Long cur = System.currentTimeMillis(); + Timestamp date = new Timestamp(cur); + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + if (rs.getDBType().equals("postgresql")) { + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) "; + } + 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,date,date,Util.getIntValue(resourceId)); + 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()); + } + + } + + public static List> getSplitHalfDayListRepeat(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"); + + 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)); + int foreOrAfter = SplitSelectSet.foreOrAfter(fromTime, toTime); + splitMap.put("foreOrAfter", "" + foreOrAfter); + splitLists.add(splitMap); + } + return splitLists; + } + + /** + * 签到签退 生成加班数据 + * + * @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()); + } + } + + /** + * 这个加班方法后面废弃 + * 新的加班都在这里kqOverTimeRuleCalBiz.buildOvertime + * @param taskBeans + * @throws Exception + */ + @Deprecated + 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); + } + } + } + + /** + * 流程为主的就在流程归档的时候处理下,不在队列里进行处理了 + * + * @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"; + Long cur = System.currentTimeMillis(); + Date date = new Date(cur); + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "; + if (rs.getDBType().equals("postgresql")) { + 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,create_time,update_time,creator)" + + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?::timestamp,?::timestamp,?) "; + } + boolean isUp = rs.executeUpdate(flow_overtime_sql, requestId, resourceId, fromdate, fromtime, todate, totime, D_Mins, "", belongDate, "", + unit, changeType, paidLeaveEnable, "1", fromdateDB, fromtimedb, todatedb, totimedb,date,date,Util.getIntValue(resourceId)); + 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) { + //如果已经生成过的加班数据已经大于等于流程时长了,那么此次的加班时长就是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 + ":最小加班时长minimumUnit:" + 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) { + //如果已经生成过的加班数据已经大于等于流程时长了,那么此次的加班时长就是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 + ":最小加班时长minimumUnit:" + 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) { + //如果已经生成过的加班数据已经大于等于流程时长了,那么此次的加班时长就是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 + ":最小加班时长minimumUnit:" + 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 + ":最小加班时长minimumUnit:" + 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 + ":最小加班时长minimumUnit:" + 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 + ":最小加班时长minimumUnit:" + 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(); + //哺乳假用到 + KQRepeatBean kqRepeatBean = KQRepeatLengthContext.getRepeatBean(); + if(kqRepeatBean != null){ + //流程上有重复时段,就不需要请假类型的重复时间了 + splitBean.setRepeatTime("0"); + } + + 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(); + DurationTypeEnum durationTypeEnum = splitBean.getDurationTypeEnum(); + + boolean shouldLog = true; + if (durationTypeEnum == DurationTypeEnum.COMMON_CAL) { + shouldLog = false; + } + if (shouldLog) { + kqLog.info("resourceid::" + resourceid + "::doSerialSplitList:" + (splitBean != null ? JSON.toJSONString(splitBean) : null)); + } + boolean is_flow_humanized = KQSettingsBiz.is_flow_humanized(); + long betweenDays = localToDate.toEpochDay() - preFromDate.toEpochDay(); + for (int i = 0; i <= betweenDays; i++) { + if(kqRepeatBean != null){ + if(i == 0){ + continue; + } + } + 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 restShift = 0; + if (shiftInfoBean != null) { + restShift = shiftInfoBean.getRestShift(); + } + + int[] initArrays = kqTimesArrayComInfo.getInitArr(); + boolean isSplit = true; + if (shiftInfoBean != null && 1 != restShift) { + splitBean.setSerialid(Util.null2String(shiftInfoBean.getSerialid())); + if (!shiftInfoBean.isIsfree()) { + isSplit = commonShiftSplit(shiftInfoBean, splitBean, i, kqTimesArrayComInfo, initArrays, localFromDate, localToDate, betweenDays, shouldLog, is_flow_humanized); + 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(); + //然后把bean重新赋值下,根据拆分后的时间 + BeanUtils.copyProperties(splitBean, newsplitBean); + // BeanUtil.copyProperties(splitBean,newsplitBean); +// SplitBean newsplitBean = copySplitBean(splitBean); + newsplitBean.setFromDate(splitDate); + newsplitBean.setToDate(splitDate); + newsplitBean.setBelongDate(splitDate); + splitBeans.add(newsplitBean); + } + } + + public SplitBean copySplitBean(SplitBean splitBean) { + SplitBean newsplitBean = new SplitBean(); + if (null == splitBean) { + return newsplitBean; + } + newsplitBean.setRequestId(splitBean.getRequestId()); + newsplitBean.setLeavebackrequestid(splitBean.getLeavebackrequestid()); + newsplitBean.setWorkflowId(splitBean.getWorkflowId()); + newsplitBean.setUsedetail(splitBean.getUsedetail()); + newsplitBean.setDataId(splitBean.getDataId()); +// this.detailId = ""; + newsplitBean.setDetailId(splitBean.getDetailId()); +// this.resourceId = ""; + newsplitBean.setResourceId(splitBean.getResourceId()); +// this.fromDate = ""; + newsplitBean.setFromDate(splitBean.getFromDate()); +// this.fromTime = ""; + newsplitBean.setFromTime(splitBean.getFromTime()); +// this.toDate = ""; + newsplitBean.setToDate(splitBean.getToDate()); +// this.toTime = ""; + newsplitBean.setToTime(splitBean.getToTime()); +// this.newLeaveType = ""; + newsplitBean.setNewLeaveType(splitBean.getNewLeaveType()); +// this.duration = ""; + newsplitBean.setDuration(splitBean.getDuration()); +// this.pub_duration = ""; + newsplitBean.setPub_duration(splitBean.getPub_duration()); +// this.work_duration = ""; + newsplitBean.setWork_duration(splitBean.getWork_duration()); +// this.rest_duration = ""; + newsplitBean.setRest_duration(splitBean.getRest_duration()); +// this.tablenamedb = ""; + newsplitBean.setTablenamedb(splitBean.getTablenamedb()); +// this.fromdatedb = ""; + newsplitBean.setFromdatedb(splitBean.getFromdatedb()); +// this.fromtimedb = ""; + newsplitBean.setFromtimedb(splitBean.getFromtimedb()); +// this.todatedb = ""; + newsplitBean.setTodatedb(splitBean.getTodatedb()); +// this.totimedb = ""; + newsplitBean.setTotimedb(splitBean.getTotimedb()); +// this.durationDB = ""; + newsplitBean.setDurationDB(splitBean.getDurationDB()); +// this.durationrule = ""; + newsplitBean.setDurationrule(splitBean.getDurationrule()); +// this.computingMode = ""; + newsplitBean.setComputingMode(splitBean.getComputingMode()); +// this.vacationInfo = ""; + newsplitBean.setVacationInfo(splitBean.getVacationInfo()); +// this.status = ""; + newsplitBean.setStatus(splitBean.getStatus()); +// this.companion = ""; + newsplitBean.setCompanion(splitBean.getCompanion()); +// this.belongDate = ""; + newsplitBean.setBelongDate(splitBean.getBelongDate()); +// D_Mins = 0; + newsplitBean.setD_Mins(splitBean.getD_Mins()); +// this.serialid = ""; + newsplitBean.setSerialid(splitBean.getSerialid()); +// this.changeType = 0; + newsplitBean.setChangeType(splitBean.getChangeType()); +// this.preChangeType = 0; + newsplitBean.setPreChangeType(splitBean.getPreChangeType()); +// this.subcompanyid = ""; + newsplitBean.setSubcompanyid(splitBean.getSubcompanyid()); +// this.departmentid = ""; + newsplitBean.setDepartmentid(splitBean.getDepartmentid()); +// this.jobtitle = ""; + newsplitBean.setJobtitle(splitBean.getJobtitle()); +// this.durationTypeEnum + newsplitBean.setDurationTypeEnum(splitBean.getDurationTypeEnum()); +// this.workmins = 0; + newsplitBean.setWorkmins(splitBean.getWorkmins()); +// this.oneDayHour = 0.0; + newsplitBean.setOneDayHour(splitBean.getOneDayHour()); +// this.groupid = ""; + newsplitBean.setGroupid(splitBean.getGroupid()); +// this.timeselection = "1"; + newsplitBean.setTimeselection(splitBean.getTimeselection()); +// processChangeSplitBean = new ProcessChangeSplitBean(); + newsplitBean.setProcessChangeSplitBean(splitBean.getProcessChangeSplitBean()); +// this.iscompanion = ""; + newsplitBean.setIscompanion(splitBean.getIscompanion()); +// this.filterholidays = ""; + newsplitBean.setFilterholidays(splitBean.getFilterholidays()); +// this.overtime_type = ""; + newsplitBean.setOvertime_type(splitBean.getOvertime_type()); +// this.duration_type = ""; +// newsplitBean.setDuration_type(splitBean.getDuration_type()); +// this.conversion = ""; + newsplitBean.setConversion(splitBean.getConversion()); +// this.overtimeBalanceTimeBeans = Lists.newArrayList(); + newsplitBean.setOvertimeBalanceTimeBeans(splitBean.getOvertimeBalanceTimeBeans()); + newsplitBean.setRepeatTime(splitBean.getRepeatTime()); + + return 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; + + String fromtimedbOri = splitBean.getFromtimedb(); + String totimedbOri = splitBean.getTotimedb(); + String repeatTime = "0"; + DurationTypeEnum durationTypeEnum = splitBean.getDurationTypeEnum(); + if(DurationTypeEnum.LEAVE == durationTypeEnum || DurationTypeEnum.LEAVEBACK == durationTypeEnum){ + repeatTime = splitBean.getRepeatTime(); + } + + 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); + if("1".equals(repeatTime)) { + int flowbegintimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(fromtimedbOri); + int flowendtimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(totimedbOri); + if(flowbegintimeIndexO > flowbegintimeIndex){ + flowbegintimeIndex = flowbegintimeIndexO; + splitFromTime = kqTimesArrayComInfo.getTimesByArrayindex(flowbegintimeIndex); + } + if(flowendtimeIndexO < flowendtimeIndex){ + flowendtimeIndex = flowendtimeIndexO; + 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 fromtimedbOri = splitBean.getFromtimedb(); + String totimedbOri = splitBean.getTotimedb(); + String repeatTime = "0"; + DurationTypeEnum durationTypeEnum = splitBean.getDurationTypeEnum(); + if(DurationTypeEnum.LEAVE == durationTypeEnum || DurationTypeEnum.LEAVEBACK == durationTypeEnum){ + repeatTime = splitBean.getRepeatTime(); + } + 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("1".equals(repeatTime)){ + int flowbegintimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(fromtimedbOri); + int flowendtimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(totimedbOri); + if(flowbegintimeIndexO > flowbegintimeIndex){ + flowbegintimeIndex = flowbegintimeIndexO; + } + if(flowendtimeIndexO < flowendtimeIndex){ + flowendtimeIndex = flowendtimeIndexO; + } + } + if ("2".equalsIgnoreCase(splitBean.getDurationrule())) { + if ("2".equalsIgnoreCase(splitBean.getTimeselection())) { + return WorkHalfUnitSplitChain.getSplitDurationBean4NonTime(kqTimesArrayComInfo, splitBean, flowbegintimeIndex, flowendtimeIndex); + } + } else { + splitFromTime = kqTimesArrayComInfo.getTimesByArrayindex(flowbegintimeIndex); + 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) { + return commonShiftSplit(shiftInfoBean, splitBean, i, kqTimesArrayComInfo, initArrays, localFromDate, localToDate, betweenDays, shouldLog, false); + } + + public boolean commonShiftSplit(ShiftInfoBean shiftInfoBean, SplitBean splitBean, int i, + KQTimesArrayComInfo kqTimesArrayComInfo, int[] initArrays, LocalDate localFromDate, + LocalDate localToDate, long betweenDays, boolean shouldLog, boolean is_flow_humanized) { + + boolean isSplit = true; + + String fromTime = splitBean.getFromtimedb(); + String toTime = splitBean.getTotimedb(); + String fromtimedbOri = splitBean.getFromtimedb(); + String totimedbOri = splitBean.getTotimedb(); + String repeatTime = "0"; + DurationTypeEnum durationTypeEnum = splitBean.getDurationTypeEnum(); + if(DurationTypeEnum.LEAVE == durationTypeEnum || DurationTypeEnum.LEAVEBACK == durationTypeEnum){ + repeatTime = splitBean.getRepeatTime(); + } + + 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, is_flow_humanized); + } + + //如果不跨天 + 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 < real_workLongTimeIndex.size(); j++) { + int[] longtimeIndexs = real_workLongTimeIndex.get(j); + Arrays.fill(initArrays, longtimeIndexs[0], longtimeIndexs[1], 1); + } + for (int j = 0; restLongTimeIndex != null && j < restLongTimeIndex.size(); j++) { + int[] resttimeIndexs = restLongTimeIndex.get(j); + Arrays.fill(initArrays, resttimeIndexs[0], resttimeIndexs[1], -1); + } + } + + + } else { + int firstTime = kqTimesArrayComInfo.getArrayindexByTimes(real_allLongWorkTime.get(0)); + //lasttime一定是跨天的 + int lastTime = kqTimesArrayComInfo.getArrayindexByTimes(real_allLongWorkTime.get(real_allLongWorkTime.size() - 1)); + if (i == 0) { + int fromtimeIndex48 = kqTimesArrayComInfo.turn24to48TimeIndex(fromtimeIndex); + int totimeIndex48 = kqTimesArrayComInfo.turn24to48TimeIndex(totimeIndex); + if (fromtimeIndex48 < lastTime) { + flowbegintimeIndex = fromtimeIndex48; + if (localFromDate.isEqual(localToDate)) { + if (totimeIndex48 < lastTime) { + flowendtimeIndex = totimeIndex48; + } else { + flowendtimeIndex = lastTime; + } + } else { + if (betweenDays == 2) { + //流程上开始日期和结束日期就相差一天 + if ((totimeIndex48 + 1440) < lastTime) { + flowendtimeIndex = totimeIndex48; + } else { + flowendtimeIndex = lastTime; + } + } else { + //流程上开始日期和结束日期相差超过1天 + flowendtimeIndex = lastTime; + } + + } + } else { + isSplit = false; + return isSplit; + } + } else { + if (localFromDate.isEqual(localToDate)) { + flowbegintimeIndex = fromtimeIndex; + flowendtimeIndex = totimeIndex; + } else { + if (i == 1) { + flowbegintimeIndex = fromtimeIndex; + if ((i + 1) == (betweenDays)) { + int totimeIndex48 = kqTimesArrayComInfo.turn24to48TimeIndex(totimeIndex); + if (totimeIndex48 < lastTime) { + flowendtimeIndex = totimeIndex48; + } else { + flowendtimeIndex = lastTime; + } + } else { + flowendtimeIndex = lastTime; + } + } else if (i == (betweenDays - 1)) { + flowbegintimeIndex = firstTime; + int totimeIndex48 = kqTimesArrayComInfo.turn24to48TimeIndex(totimeIndex); + if (totimeIndex48 < lastTime) { + flowendtimeIndex = totimeIndex48; + } else { + flowendtimeIndex = lastTime; + } + } else if (i == betweenDays) { + flowbegintimeIndex = firstTime; + flowendtimeIndex = totimeIndex; + if (firstTime > totimeIndex) { + isSplit = false; + return isSplit; + } + } else { + flowbegintimeIndex = firstTime; + flowendtimeIndex = lastTime; + if (firstTime > lastTime) { + isSplit = false; + return isSplit; + } + } + } + } + //工作时段里填充上1 + for (int j = 0; j < real_workLongTimeIndex.size(); j++) { + int[] longtimeIndexs = real_workLongTimeIndex.get(j); + Arrays.fill(initArrays, longtimeIndexs[0], longtimeIndexs[1], 1); + + } + for (int j = 0; j < restLongTimeIndex.size(); j++) { + int[] resttimeIndexs = restLongTimeIndex.get(j); + Arrays.fill(initArrays, resttimeIndexs[0], resttimeIndexs[1], -1); + } + } + if (isSplit) { + + if ("2".equalsIgnoreCase(splitBean.getDurationrule())) { + if ("2".equalsIgnoreCase(splitBean.getTimeselection())) { + return WorkHalfUnitSplitChain.getSplitDurationBean4Time(initArrays, shiftInfoBean, kqTimesArrayComInfo, splitBean, flowbegintimeIndex, flowendtimeIndex); + } + } else { + String splitFromTime = kqTimesArrayComInfo.getTimesByArrayindex(flowbegintimeIndex); + String splitToTime = kqTimesArrayComInfo.getTimesByArrayindex(flowendtimeIndex); + int flowMins = kqTimesArrayComInfo.getCnt(initArrays, flowbegintimeIndex, flowendtimeIndex, 1); + if("1".equals(repeatTime)){ + flowMins = 0; + int flowbegintimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(fromtimedbOri); + int flowendtimeIndexO = kqTimesArrayComInfo.getArrayindexByTimes(totimedbOri); + if(flowbegintimeIndexO < flowbegintimeIndex){ + flowbegintimeIndexO = flowbegintimeIndex; + } + if(flowendtimeIndexO > flowendtimeIndex){ + flowendtimeIndexO = flowendtimeIndex; + } + int flowMinsO = kqTimesArrayComInfo.getCnt(initArrays, flowbegintimeIndexO, flowendtimeIndexO, 1); + if(flowMinsO > 0){ + splitFromTime = fromtimedbOri; + splitToTime = totimedbOri; + flowMins += flowMinsO; + } + //还有跨天的情况 + int flowbegintimeIndexN = kqTimesArrayComInfo.getArrayindexByTimes(kqTimesArrayComInfo.turn24to48Time(fromtimedbOri)); + int flowendtimeIndexN = kqTimesArrayComInfo.getArrayindexByTimes(kqTimesArrayComInfo.turn24to48Time(totimedbOri)); + if(flowbegintimeIndexN < flowbegintimeIndex){ + flowbegintimeIndexN = flowbegintimeIndex; + } + if(flowendtimeIndexN > flowendtimeIndex){ + flowendtimeIndexN = flowendtimeIndex; + } + int flowMinsN = kqTimesArrayComInfo.getCnt(initArrays, flowbegintimeIndexN, flowendtimeIndexN, 1); + if(flowMinsN > 0){ + splitFromTime = kqTimesArrayComInfo.turn24to48Time(fromtimedbOri); + splitToTime = kqTimesArrayComInfo.turn24to48Time(totimedbOri); + flowMins += flowMinsN; + } + } + if (shouldLog) { + kqLog.info("resourceid:" + splitBean.getResourceId() + ":::i::" + i + "::flowbegintimeIndex:" + flowbegintimeIndex + ":flowendtimeIndex:" + flowendtimeIndex + ":flowMins:" + flowMins); + } + flowMins = flowMins > 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); + String repeatType = splitBean.getRepeatType(); + if(StringUtils.isNotEmpty(repeatType)){ + if(CollectionUtils.isNotEmpty(real_workLongTimeIndex)){ + int startIdx = real_workLongTimeIndex.get(0)[0]; + int endIdx = real_workLongTimeIndex.get(real_workLongTimeIndex.size()-1)[1]; + splitBean.setFromtimedb(kqTimesArrayComInfo.getTimesByArrayindex(startIdx)); + splitBean.setTotimedb(kqTimesArrayComInfo.getTimesByArrayindex(endIdx)); + splitBean.setFromTime("00:00"); + splitBean.setToTime("00:00"); + } + } + splitBean.setConvertAttendDay(shiftInfoBean.getConvertAttendDay()); + } + + } + return isSplit; + } + + /** + * 根据单位来转换时长 + * + * @param splitBean + * @param isComputingMode2 是否按照自然日计算 + */ + private void turnDuration(SplitBean splitBean, boolean isComputingMode2) { + //哺乳假用到 + KQRepeatBean kqRepeatBean = KQRepeatLengthContext.getRepeatBean(); + if(kqRepeatBean != null){ + Long repeatMins = getRepeatMins(kqRepeatBean); + if(repeatMins != null && repeatMins > 0){ + splitBean.setD_Mins(repeatMins); + } + } + 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); + } + + } + + private Long getRepeatMins(KQRepeatBean kqRepeatBean) { + Long repeatMins = 0L; + try{ + String repeatType = kqRepeatBean.getRepeatType(); + if(StringUtils.isNotEmpty(repeatType)){ + Long repeatLate = kqRepeatBean.getRepeatLate(); + Long repeatEarly = kqRepeatBean.getRepeatEarly(); + if("0".equals(repeatType)){ + if(repeatLate != null){ + repeatMins += new Double(Double.valueOf(repeatLate)).longValue(); + } + } + if("1".equals(repeatType)){ + if(repeatEarly != null){ + repeatMins += new Double(Double.valueOf(repeatEarly)).longValue(); + } + } + if("2".equals(repeatType)){ + if(repeatLate != null){ + repeatMins += new Double(Double.valueOf(repeatLate)).longValue(); + } + if(repeatEarly != null){ + repeatMins += new Double(Double.valueOf(repeatEarly)).longValue(); + } + } + } + }catch (Exception e){ + } + return repeatMins; + } + + /** + * 按天请假 + * + * @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(); + String convertAttendDay = Util.null2s(splitBean.getConvertAttendDay(),"1.0"); + double convertAttendDayD = Util.getDoubleValue(convertAttendDay); + if (workmins > 0) { + curDays = (d_Mins / (workmins * 1.0))*convertAttendDayD; + 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> getSplitListRepeat(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"); + + 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)); + 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) { + boolean isRest = kqWorkTime.isNonWork(serialInfo); + if(isRest){ + return isLateoutlatein; + } + 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里存的enable都是一致的,取一个就行 + 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); + } + } + + } + +}