import com.engine.attendance.enums.ClockPointEnum; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import java.util.HashMap; import java.util.List; import java.util.Map; public class TestRecordData { public static void main(String[] args) { List>> clcokInTimeData = Lists.newArrayList(); Map> map1 = new HashMap(){{ put("2023-11-30 09:00|0|4",new HashMap(){{ put("signtime","08:38:00"); put("signdate","2023-11-30"); }}); }}; Map> map2 = new HashMap(){{ put("2023-11-30 10:00|1|5|0",new HashMap(){{ put("signtime","10:29:00"); put("signdate","2023-11-30"); }}); }}; Map> map3 = new HashMap(){{ put("2023-11-30 11:00|0|4|0",null); }}; Map> map4 = new HashMap(){{ put("2023-11-30 11:00|1|5|0",new HashMap(){{ put("signtime","11:38:00"); put("signdate","2023-11-30"); }}); }}; Map> map5 = new HashMap(){{ put("2023-11-30 18:00|0|5|0",new HashMap(){{ put("signtime","18:29:00"); put("signdate","2023-11-30"); }}); }}; clcokInTimeData.add(map1); clcokInTimeData.add(map2); clcokInTimeData.add(map3); clcokInTimeData.add(map4); clcokInTimeData.add(map5); System.out.println(getNeedRecordClockInTime(clcokInTimeData)); } public static Map getNeedRecordClockInTime(List>> clcokInTimeData) { Map resultMap = Maps.newHashMap(); int inIndex = 1; int outIndex = 1; int jcCloumns = 8; for (Map> clcokInTimeMap : clcokInTimeData){ //卡点 String point = ""; //当天打卡数据 Map clcokInTime = null; for (Map.Entry> entry :clcokInTimeMap.entrySet()){ point = entry.getKey(); clcokInTime = entry.getValue(); } //需要计算的班次打卡时间点 String pointTime = point.split("\\|")[0]; //start:开始打卡时间点,end:结束打卡时间点 String pointType = point.split("\\|")[1]; //empty:漏卡,equal:打卡时间和班次时间相等,before:打卡时间在班次时间之前,after:打卡时间在班次时间之后 String timeType = point.split("\\|")[2]; if (ClockPointEnum.START.getKey().equals(pointType)){ //开始时间打卡 String key = "j"+inIndex; if (!ClockPointEnum.EMPTY.getKey().equals(timeType) && clcokInTime != null){ String value = "'"+clcokInTime.get("signtime")+"'"; resultMap.put(key,value); }else { resultMap.put(key,"NULL"); } inIndex++; }else if (ClockPointEnum.END.getKey().equals(pointType)){ //结束时间打卡 String key = "c"+outIndex; if (!ClockPointEnum.EMPTY.getKey().equals(timeType) && clcokInTime != null){ String value = "'"+clcokInTime.get("signtime")+"'"; resultMap.put(key,value); }else { resultMap.put(key,"NULL"); } outIndex++; } } for (int i=inIndex;i