package com.engine.attendance.attendanceanalysis.wrapper; import com.engine.attendance.attendanceanalysis.cmd.UpdateAttendanceResultsCmd; import com.engine.attendance.attendanceanalysis.cmd.item.WorkOvertimeItemCmd; import com.engine.attendance.attendanceanalysis.service.*; import com.engine.attendance.attendanceanalysis.service.impl.*; import com.engine.attendance.enums.*; import com.engine.common.util.DateUtil; import com.engine.common.util.ServiceUtil; import com.engine.common.util.Utils; import com.engine.core.impl.Service; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import weaver.general.Util; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @Slf4j public class UpdateAttendanceResultWrapper extends Service { private AbnormalAttendanceService beLateService = ServiceUtil.getService(AbnormalAttendanceServiceImpl.class); private ForgetClockInService forgetClockInService = ServiceUtil.getService(ForgetClockInServiceImpl.class); private AskForLeaveService askForLeaveService= ServiceUtil.getService(AskForLeaveServiceImpl.class); private EvectionService evectionService= ServiceUtil.getService(EvectionServiceImpl.class); private WorkOverTimeService workOverTimeService = ServiceUtil.getService(WorkOverTimeServiceImpl.class); /** * 记录异常打卡 * */ public List> recordAbnormalClockIn(Map params){ //卡点 List>> clcokInTimeList = (List>>)params.get("clcokInTimeList"); //考勤项目 List> attendanceItems = (List>)params.get("attendanceItems"); //排班 List> scheduleResult = (List>)params.get("scheduleResult"); //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //人员 String userId = Util.null2String(params.get("userId")); //以开始时间分割班次 Map>> startScheduleResult = scheduleResult.stream().collect(Collectors.groupingBy(e->e.get("dtkssj").toString())); //以结束时间分割班次 Map>> endScheduleResult = scheduleResult.stream().collect(Collectors.groupingBy(e->e.get("dtjssj").toString())); List> resultList = Lists.newArrayList(); for (Map> clcokInTimeMap :clcokInTimeList){ //卡点 String point = ""; //当天打卡数据 Map clcokInTimeData = null; for (Map.Entry> entry :clcokInTimeMap.entrySet()){ point = entry.getKey(); clcokInTimeData = entry.getValue(); } //需要计算的班次打卡时间点 String pointTime = point.split("\\|")[0]; //start:开始打卡时间点,end:结束打卡时间点 String pointType = point.split("\\|")[1]; //empty:漏卡,equal:打卡时间和班次时间相等,before:打卡时间在班次时间之前,after:打卡时间在班次时间之后 String timeType = point.split("\\|")[2]; //班次 Map classInfo = Maps.newHashMap(); if (ClockPointEnum.START.getKey().equals(pointType)){ classInfo = startScheduleResult.get(pointTime.split(" ")[1]).get(0); }else if (ClockPointEnum.END.getKey().equals(pointType)){ classInfo = endScheduleResult.get(pointTime.split(" ")[1]).get(0); } if (ClockPointEnum.EMPTY.getKey().equals(timeType) || clcokInTimeData == null){ //漏卡 Map missCardParams = Maps.newHashMap(); missCardParams.put("classInfo",classInfo); missCardParams.put("clcokInTimeData",clcokInTimeData); missCardParams.put("attendanceItems",attendanceItems); missCardParams.put("analysisDate",analysisDate); missCardParams.put("userId",userId); missCardParams.put("point",point); missCardParams.put("scheduleResult",scheduleResult); log.info("missCardParams classInfo: [{}],clcokInTimeData:[{}]",classInfo,clcokInTimeData); List> iforgetClockIn = forgetClockInService.forgetClockIn(missCardParams); if (iforgetClockIn.size() >0){ iforgetClockIn.get(0).put("pointTime",pointTime); iforgetClockIn.get(0).put("bdlx",classInfo.get("bdlx")); resultList.add(iforgetClockIn.get(0)); } }else if (ClockPointEnum.START.getKey().equals(pointType) && ClockPointEnum.AFTER.getKey().equals(timeType)){ //迟到 Map beLateParams = Maps.newHashMap(); beLateParams.put("classInfo",classInfo); beLateParams.put("clcokInTimeData",clcokInTimeData); beLateParams.put("attendanceItems",attendanceItems); beLateParams.put("analysisDate",analysisDate); beLateParams.put("userId",userId); beLateParams.put("point",point); beLateParams.put("scheduleResult",scheduleResult); log.info("beLateParams classInfo: [{}],clcokInTimeData:[{}]",classInfo,clcokInTimeData); List> ifBeLate = beLateService.beLate(beLateParams); if (ifBeLate.size() > 0){ ifBeLate.get(0).put("pointTime",pointTime); ifBeLate.get(0).put("bdlx",classInfo.get("bdlx")); resultList.add(ifBeLate.get(0)); } }else if (ClockPointEnum.END.getKey().equals(pointType) && ClockPointEnum.BEFORE.getKey().equals(timeType)){ //早退 Map leaveEarlyParams = Maps.newHashMap(); leaveEarlyParams.put("classInfo",classInfo); leaveEarlyParams.put("clcokInTimeData",clcokInTimeData); leaveEarlyParams.put("attendanceItems",attendanceItems); leaveEarlyParams.put("analysisDate",analysisDate); leaveEarlyParams.put("userId",userId); leaveEarlyParams.put("point",point); leaveEarlyParams.put("scheduleResult",scheduleResult); log.info("leaveEarlyParams classInfo: [{}],clcokInTimeData:[{}]",classInfo,clcokInTimeData); List> ifLeaveEarly = beLateService.leaveEarly(leaveEarlyParams); if (ifLeaveEarly.size() > 0){ ifLeaveEarly.get(0).put("pointTime",pointTime); ifLeaveEarly.get(0).put("bdlx",classInfo.get("bdlx")); resultList.add(ifLeaveEarly.get(0)); } } } // if (iforgetClockIn || ifBeLate ||ifLeaveEarly){ // return true; // } return resultList; } /** * 记录加班 * @param params * @return */ public List> recordWorkOverTime(Map params){ return workOverTimeService.recordWorkOverTime(params); } /** * 请假 * @param params * @return */ public Map recordAskForLeave(Map params){ //请假项目 Map> askForLeaveItems = (Map>)params.get("askForLeaveItems"); //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //排班 List> scheduleResult = (List>)params.get("scheduleResult"); //请假记录 List> askForLeaveList = (List>)params.get("askForLeaveList"); //异常记录 List> abnormalClockInList = (List>)params.get("abnormalClockInList"); //请假抵消异常 List> offsetAskForLeaveAnomaly = Lists.newArrayList(); Map map = Maps.newHashMap(); List> resultList = Lists.newArrayList(); for (int i=0;i resultMap = Maps.newHashMap(); resultList.add(resultMap); resultMap.put("item",askForLeaveList.get(i).get("jqlx")); String kssj = askForLeaveList.get(i).get("ksrq") + " "+askForLeaveList.get(i).get("kssj"); String jssj = askForLeaveList.get(i).get("jsrq")+ " "+askForLeaveList.get(i).get("jssj"); //半天请假 String btj = Util.null2String(askForLeaveList.get(i).get("btj")); //请假时长 String qjsc = Util.null2String(askForLeaveList.get(i).get("qjsc")); //请假项目 Map askForLeaveItem = askForLeaveItems.get(askForLeaveList.get(i).get("jqlx")); //自动移除时间区间内的非工作时长 String zdycbcndfgzsd = Util.null2String(askForLeaveItem.get("zdycbcndfgzsd")); //同一天可抵消多个异常 String tybcndbjlhbjs = Util.null2String(askForLeaveItem.get("tybcndbjlhbjs")); //作用时段 String zysd = Util.null2String(askForLeaveItem.get("zysd")); //核算量 double hsl = Double.valueOf(Util.null2String(askForLeaveItem.get("hsl"))); //核算单位 String hsdw = Util.null2String(askForLeaveItem.get("hsdw")); Map param = Maps.newHashMap(); param.put("abnormalClockInList",abnormalClockInList); param.put("zysd",zysd); param.put("scheduleResult",scheduleResult); param.put("analysisDate",analysisDate); double itemduration = 0; if ("".equals(Util.null2String(askForLeaveList.get(i).get("kssj"))) || "".equals(Util.null2String(askForLeaveList.get(i).get("jssj")))){ //弹性请假,半天请假 if (CheckBoxEnum.CHECKED.getKey().equals(btj)){ //半天请假 askForLeaveService.askForLeaveByHalfDay(param); }else if (!"".equals(qjsc)){ //时长请假 itemduration = Utils.getItemduration(hsl,hsdw,Double.valueOf(Double.valueOf(qjsc)*60).intValue(),AccountingUnitEnum.MINUTES); resultMap.put("itemduration",itemduration); param.put("qjsc",qjsc); param.put("tybcndbjlhbjs",tybcndbjlhbjs); if (abnormalClockInList.size()>0){ Map map1 = askForLeaveService.askForLeaveByDurationTime(param); abnormalClockInList =(List>)map1.get("abnormalClockInList"); offsetAskForLeaveAnomaly.addAll((List>)map1.get("offsetAskForLeaveAnomaly")); } } }else { //按照开始时间,结束时间请假 int timeMinutes = DateUtil.getBetWeenMinutes(kssj,jssj); if (CheckBoxEnum.CHECKED.getKey().equals(zdycbcndfgzsd)){ timeMinutes = Utils.removeRestTime(kssj,jssj,scheduleResult,analysisDate); } log.info("recordAskForLeave timeMinutes :[{}] ,hsl:{},hsdw",timeMinutes,hsl,hsdw); itemduration = Utils.getItemduration(hsl,hsdw,timeMinutes,AccountingUnitEnum.MINUTES); resultMap.put("itemduration",itemduration); param.put("kssj",kssj); param.put("jssj",jssj); if (abnormalClockInList.size()>0){ Map map1 = askForLeaveService.askForLeaveByTime(param); abnormalClockInList = (List>)map1.get("abnormalClockInList"); offsetAskForLeaveAnomaly.addAll((List>)map1.get("offsetAskForLeaveAnomaly")); } } } map.put("resultList",resultList); map.put("abnormalClockInList",abnormalClockInList); map.put("offsetAskForLeaveAnomaly",offsetAskForLeaveAnomaly); return map; } /** * 外出 * @param params * @return */ public Map recordEvection(Map params){ //外出项目 Map> evectionItems = (Map>)params.get("evectionItems"); //排班 List> scheduleResult = (List>)params.get("scheduleResult"); //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //出差记录 List> evectionList = (List>)params.get("evectionList"); //异常记录 List> abnormalClockInList = (List>)params.get("abnormalClockInList"); //外出抵消异常 List> offsetEvectionAnomaly = Lists.newArrayList(); Map map = Maps.newHashMap(); List> resultList = Lists.newArrayList(); for (int i=0;i resultMap = Maps.newHashMap(); resultList.add(resultMap); resultMap.put("item",evectionList.get(i).get("cclx")); String kssj = evectionList.get(i).get("ksrq") + " "+evectionList.get(i).get("kssj"); String jssj = evectionList.get(i).get("jsrq")+ " "+evectionList.get(i).get("jssj"); //半天请假 String btj = Util.null2String(evectionList.get(i).get("btcc")); //请假时长 String qjsc = Util.null2String(evectionList.get(i).get("ccsc")); //请假项目 Map evectionItem = evectionItems.get(evectionList.get(i).get("cclx")); //自动移除时间区间内的非工作时长 String zdycbcndfgzsd = Util.null2String(evectionItem.get("zdycbcndfgzsd")); //同一天可抵消多个异常 String tybcndbjlhbjs = Util.null2String(evectionItem.get("tybcndbjlhbjs")); //核算量 double hsl = Double.valueOf(Util.null2String(evectionItem.get("hsl"))); //核算单位 String hsdw = Util.null2String(evectionItem.get("hsdw")); //作用时间段 String zysd = Util.null2String(evectionItem.get("zysd")); Map param = Maps.newHashMap(); param.put("abnormalClockInList",abnormalClockInList); param.put("zysd",zysd); double itemduration = 0; if ("".equals(Util.null2String(evectionList.get(i).get("kssj"))) || "".equals(Util.null2String(evectionList.get(i).get("jssj")))){ //弹性请假,半天出差 if (CheckBoxEnum.CHECKED.getKey().equals(btj)){ //半天出差 evectionService.evectionByHalfDay(param); }else if (!"".equals(qjsc)){ //时长出差 itemduration = Utils.getItemduration(hsl,hsdw,Double.valueOf(Double.valueOf(qjsc)*60).intValue(),AccountingUnitEnum.MINUTES); resultMap.put("itemduration",itemduration); param.put("ccsc",qjsc); param.put("tybcndbjlhbjs",tybcndbjlhbjs); if (abnormalClockInList.size()>0){ Map map1 =evectionService.evectionByDurationTime(param); abnormalClockInList = (List>)map1.get("abnormalClockInList"); offsetEvectionAnomaly.addAll((List>)map1.get("offsetEvectionAnomaly")); } } }else { //按照开始时间,结束时间出差 int timeMinutes = DateUtil.getBetWeenMinutes(kssj,jssj); if (CheckBoxEnum.CHECKED.getKey().equals(zdycbcndfgzsd)){ timeMinutes = Utils.removeRestTime(kssj,jssj,scheduleResult,analysisDate); } log.info("recordEvection timeMinutes :[{}] ,hsl:{},hsdw",timeMinutes,hsl,hsdw); itemduration = Utils.getItemduration(hsl,hsdw,timeMinutes,AccountingUnitEnum.MINUTES); resultMap.put("itemduration",itemduration); param.put("kssj",kssj); param.put("jssj",jssj); if (abnormalClockInList.size()>0){ Map map1 = evectionService.evectionByTime(param); abnormalClockInList = (List>)map1.get("abnormalClockInList"); offsetEvectionAnomaly.addAll((List>)map1.get("offsetEvectionAnomaly")); } } } map.put("resultList",resultList); map.put("abnormalClockInList",abnormalClockInList); map.put("offsetEvectionAnomaly",offsetEvectionAnomaly); return map; } /** * 正常上下班,填写 * @param params * @return */ public List> recordNormal(Map params){ //排班 List> scheduleResult = (List>)params.get("scheduleResult"); //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //人员 String userId = Util.null2String(params.get("userId")); //日期类型 String rqlx = Util.null2String(scheduleResult.get(0).get("rqlx")); List> resultList = Lists.newArrayList(); Map normalParams = Maps.newHashMap(); // normalParams.put("userId",userId); // normalParams.put("date",analysisDate); // normalParams.put("classInfo",scheduleResult); // normalParams.put("modeId",params.get("modeId")); if (DateTypeEnum.WORK_DAY.getKey().equals(rqlx) || DateTypeEnum.CHANGECLASS.getKey().equals(rqlx)){ //工作日 normalParams.put("item",SystemItemEnum.WORK_DAY.getKey()); }else if (DateTypeEnum.HOLIDAY.getKey().equals(rqlx)){ //节假日 normalParams.put("item",SystemItemEnum.HOLIDAY.getKey()); }else if (DateTypeEnum.PUBLIC_RESTDAY.getKey().equals(rqlx) || DateTypeEnum.EXCHANGE_LEAVEDAY.getKey().equals(rqlx)){ //休息日 normalParams.put("item",SystemItemEnum.REST_DAY.getKey()); } resultList.add(normalParams); //commandExecutor.execute(new UpdateAttendanceResultsCmd(normalParams)); return resultList; } /** * 没有排班 * @param params * @return */ public boolean recordNoClass(Map params){ //分析日期 String analysisDate = Util.null2String(params.get("analysisDate")); //人员 String userId = Util.null2String(params.get("userId")); Map normalParams = Maps.newHashMap(); normalParams.put("userId",userId); normalParams.put("date",analysisDate); normalParams.put("modeId",params.get("modeId")); normalParams.put("scheduleList",params.get("scheduleList")); log.info("userId : {} ,analysisDate: {} have no class",userId,analysisDate); commandExecutor.execute(new UpdateAttendanceResultsCmd(normalParams)); return false; } }