package com.engine.attendance.attendanceanalysis.cmd; import com.engine.attendance.enums.*; import com.engine.common.biz.AbstractCommonCommand; import com.engine.common.entity.BizLogContext; import com.engine.common.util.DateUtil; import com.engine.common.util.Utils; import com.engine.core.interceptor.CommandContext; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import weaver.general.Util; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 计算出勤时长 */ @Slf4j public class ComputeAttendanceDurationCmd extends AbstractCommonCommand> { public ComputeAttendanceDurationCmd(Map params){ this.params=params; } @Override public BizLogContext getLogContext() { return null; } @Override public Map execute(CommandContext commandContext) { Map resultMap = Maps.newHashMap(); //排班 List> scheduleResult = (List>)params.get("scheduleResult"); //请假记录 List> askForLeaveList = (List>)params.get("askForLeaveList"); //请假项目 Map> askForLeaveItems = (Map>)params.get("askForLeaveItems"); //外出记录 List> evectionList = (List>)params.get("evectionList"); //外出项目 Map> evectionItems = (Map>)params.get("evectionItems"); //请假后消除的异常 List> offsetAskForLeaveAnomaly = (List>)params.get("offsetAskForLeaveAnomaly"); //出差外出后消除的异常 List> offsetEvectionAnomaly = (List>)params.get("offsetEvectionAnomaly"); //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //考勤项目 List> attendanceItems = (List>)params.get("attendanceItems"); //经过请假外出处理过的异常项目 List> abnormalClockInList = (List>)params.get("abnormalClockInList"); //单位小时 double edsc = Double.valueOf(scheduleResult.get(0).get("edsc").toString()); if (0 == edsc){ resultMap.put("attendanceDuration",edsc); return resultMap; } //单位分钟 /** * 当工作时间段存在异常项目时 */ //abnormalClockInList = abnormalClockInList.stream().filter(e->e.get("bdlx").equals(ClassSegmentTypeEnum.WORK_TIME.getKey())).collect(Collectors.toList()); Map>> abnormalClockInGroupMap = abnormalClockInList.stream().filter(e->e.get("bdlx").equals(ClassSegmentTypeEnum.WORK_TIME.getKey())) .collect(Collectors.groupingBy(e->e.get("clcokInTimeData"))); List> filterAbnormalList = Lists.newArrayList(); abnormalClockInGroupMap.entrySet().forEach(e->{ List> list = e.getValue(); if (list.size() > 1){ list = list.stream().sorted(Comparator.comparing(f->(Integer)f.get("betweenMinutes"))).collect(Collectors.toList()); filterAbnormalList.add(list.get(list.size()-1)); list.get(list.size()-1).put("record",true); }else if (list.size() == 1){ filterAbnormalList.add(list.get(0)); } }); double abnormalTime = 0; for (Map abnormalClockInMap : filterAbnormalList){ AttendanceItemTypeEnum itemType = (AttendanceItemTypeEnum)abnormalClockInMap.get("itemType"); String kczgsc = Util.null2String(abnormalClockInMap.get("kczgsc")); if (itemType == AttendanceItemTypeEnum.MISSE_CARD){ //早上漏卡 abnormalTime = abnormalTime + edsc*60; } if (!CheckBoxEnum.CHECKED.getKey().equals(kczgsc)){ continue; } int betweenMinutes = Integer.valueOf(Util.null2String(abnormalClockInMap.get("betweenMinutes")==null?"0":abnormalClockInMap.get("betweenMinutes"))); String item = Util.null2String(abnormalClockInMap.get("item")); List> abnormalItemList = attendanceItems.stream().filter(e->e.get("key").equals(item)).collect(Collectors.toList()); if (abnormalItemList.size() > 0){ //起步扣除分钟数 int qbkcsc = Integer.valueOf(Util.null2String(abnormalItemList.get(0).get("qbkcsc"))); //超出后单次累加扣除分钟数 int cckcbc = Integer.valueOf(Util.null2String(abnormalItemList.get(0).get("cckcbc"))); if (betweenMinutes <= qbkcsc){ betweenMinutes = qbkcsc; }else { int deductionDuration = betweenMinutes-qbkcsc; betweenMinutes = Double.valueOf(Utils.getItemduration(cckcbc,AccountingUnitEnum.MINUTES.getKey(),deductionDuration,AccountingUnitEnum.MINUTES)).intValue()+qbkcsc; } } abnormalTime = abnormalTime+betweenMinutes; } /** * 当存在请假时,考虑扣除请假时长 */ double askForLeaveTime = removeAskForLeave(analysisDate,scheduleResult,askForLeaveList,askForLeaveItems,offsetAskForLeaveAnomaly); /** * 当存在外出时,考虑扣除外出时长 */ double evectionTimeTime = removeEvection(analysisDate,scheduleResult,evectionList,evectionItems,offsetEvectionAnomaly); log.debug("abnormalTime : {},askForLeaveTime : {},evectionTimeTime:{}",abnormalTime,askForLeaveTime,evectionTimeTime); double deductTime = Double.valueOf(String.format ("%.2f",(abnormalTime+askForLeaveTime+evectionTimeTime)/60)); edsc = edsc-deductTime; if (edsc < 0){ edsc=0; } resultMap.put("attendanceDuration",String.format ("%.2f", edsc)); return resultMap; } public double removeAskForLeave(String analysisDate,List> scheduleResult,List> askForLeaveList, Map> askForLeaveItems,List> offsetAskForLeaveAnomaly){ double employTime = 0; double edsc = Double.valueOf(scheduleResult.get(0).get("edsc").toString()); for (int i=0;i askForLeaveItem = askForLeaveItems.get(askForLeaveList.get(i).get("jqlx")); //半天请假 String btj = Util.null2String(askForLeaveList.get(i).get("btj")); //作用时段 String zysd = Util.null2String(askForLeaveItem.get("zysd")); if (!zysd.contains(WorkForTimeEnum.WORK_TIME.getKey()) && !WorkForTimeEnum.ALL_TIME.getKey().equals(zysd)){ continue; } if ("".equals(Util.null2String(askForLeaveList.get(i).get("kssj"))) || "".equals(Util.null2String(askForLeaveList.get(i).get("jssj")))){ //弹性请假,半天出差 if (CheckBoxEnum.CHECKED.getKey().equals(btj)){ //半天出差 employTime = employTime + edsc*30; }else if (!"".equals(qjsc)){ //时长请假 if (offsetAskForLeaveAnomaly.size() > 0){ List> list = offsetAskForLeaveAnomaly.stream().filter(e->ClassSegmentTypeEnum.WORK_TIME.getKey().equals(e.get("bdlx"))).collect(Collectors.toList()); employTime += Math.round(list.size()/Double.valueOf(offsetAskForLeaveAnomaly.size()) *Double.valueOf(qjsc)*60); }else { employTime +=Double.valueOf(qjsc)*60; } } }else { //按照开始时间,结束时间请假 for (Map scheduleMap:scheduleResult){ if (ClassSegmentTypeEnum.WORK_TIME.getKey().equals(scheduleMap.get("bdlx"))){ String dtkssj = Utils.getkssjTime(scheduleMap,analysisDate); String dtjssj = Utils.getjssjTime(scheduleMap,analysisDate); employTime +=Utils.getStartAndEndTime(dtkssj,dtjssj,askForLeaveList.get(i)); } } } } return employTime; } public double removeEvection(String analysisDate,List> scheduleResult,List> evectionList, Map> evectionItems,List> offsetEvectionAnomaly){ double employTime = 0; double edsc = Double.valueOf(scheduleResult.get(0).get("edsc").toString()); for (int i=0;i askForLeaveItem = evectionItems.get(evectionList.get(i).get("cclx")); //半天请假 String btcc = Util.null2String(evectionList.get(i).get("btcc")); //作用时段 String zysd = Util.null2String(askForLeaveItem.get("zysd")); if (!zysd.contains(WorkForTimeEnum.WORK_TIME.getKey()) && !WorkForTimeEnum.ALL_TIME.getKey().equals(zysd)){ continue; } if ("".equals(Util.null2String(evectionList.get(i).get("kssj"))) || "".equals(Util.null2String(evectionList.get(i).get("jssj")))){ //弹性请假,半天出差 if (CheckBoxEnum.CHECKED.getKey().equals(btcc)){ //半天出差 employTime = employTime + edsc*30; }else if (!"".equals(ccsc)){ //时长请假 if (offsetEvectionAnomaly.size() > 0){ List> list = offsetEvectionAnomaly.stream().filter(e->ClassSegmentTypeEnum.WORK_TIME.getKey().equals(e.get("bdlx"))).collect(Collectors.toList()); employTime += Math.round(list.size()/Double.valueOf(offsetEvectionAnomaly.size()) *Double.valueOf(ccsc)*60); }else { employTime += Double.valueOf(ccsc)*60; } } }else { //按照开始时间,结束时间请假 for (Map scheduleMap:scheduleResult){ String dtkssj = Utils.getkssjTime(scheduleMap,analysisDate); String dtjssj = Utils.getjssjTime(scheduleMap,analysisDate); if (ClassSegmentTypeEnum.WORK_TIME.getKey().equals(scheduleMap.get("bdlx"))){ employTime +=Utils.getStartAndEndTime(dtkssj,dtjssj,evectionList.get(i)); } } } } return employTime; } }