package com.qianwen.smartman.modules.andon.wrapper; import com.google.common.collect.Lists; import java.time.DayOfWeek; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.WeekFields; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import com.qianwen.smartman.common.constant.CalendarConstant; import com.qianwen.smartman.common.utils.LocalDateTimeUtils; import com.qianwen.core.tool.utils.DateUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.andon.dto.ShiftAndonDTO; import com.qianwen.smartman.modules.andon.dto.ShiftTimeDTO; import com.qianwen.smartman.modules.andon.entity.AndonRecord; import com.qianwen.smartman.modules.andon.enums.DateType; import com.qianwen.smartman.modules.andon.vo.AndonStatisticsSearchVO; import com.qianwen.smartman.modules.andon.vo.CallTimeDateChartVO; import com.qianwen.smartman.modules.andon.vo.CallTimeShiftChartVO; import com.qianwen.smartman.modules.mdc.dto.IntervalDateDto; /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/andon/wrapper/StatisticsAndonWrapper.class */ public class StatisticsAndonWrapper { private StatisticsAndonWrapper() { } public static StatisticsAndonWrapper build() { return new StatisticsAndonWrapper(); } public CallTimeDateChartVO entity(List records, AndonStatisticsSearchVO vo) { Integer queryType = vo.getQueryType(); switch (DateType.findByType(queryType)) { case DAY: return callTimeDayChart(records, vo); case WEEK: return callTimeWeekChart(records, vo); case MONTH: return callTimeMonthChart(records, vo); } return new CallTimeDateChartVO(); } private CallTimeDateChartVO callTimeDayChart(List records, AndonStatisticsSearchVO vo) { List dateList = LocalDateTimeUtils.getDateList(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime())); List xAxis = (List) dateList.stream().map((v0) -> { return DateUtil.formatDate(v0); }).collect(Collectors.toList()); List yAxis = Lists.newArrayList(); for (LocalDate date : dateList) { extracted(records, yAxis, date, date); } return CallTimeDateChartVO.builder().xAxis(xAxis).yAxis(yAxis).build(); } private CallTimeDateChartVO callTimeWeekChart(List records, AndonStatisticsSearchVO vo) { List intervalDate = LocalDateTimeUtils.getIntervalDate(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime())); List weekDates = (List) intervalDate.stream().flatMap(it -> { Integer year = it.getYear(); List weekList = it.getWeekList(); return weekList.stream().map(wl -> { return year + "-" + wl; }); }).sorted((v0, v1) -> { return v0.compareTo(v1); }).collect(Collectors.toList()); List yAxis = Lists.newArrayList(); WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 1); for (String weekDate : weekDates) { String[] split = weekDate.split("-"); String year = split[0]; String week = split[1]; LocalDate localDate = LocalDate.now().withYear(Integer.parseInt(year)).with(weekFields.weekOfYear(), Integer.parseInt(week)); LocalDate start = localDate.with(weekFields.dayOfWeek(), 1L); LocalDate end = localDate.with(weekFields.dayOfWeek(), 7L); extracted(records, yAxis, start, end); } return CallTimeDateChartVO.builder().xAxis(weekDates).yAxis(yAxis).build(); } private CallTimeDateChartVO callTimeMonthChart(List records, AndonStatisticsSearchVO vo) { List intervalDate = LocalDateTimeUtils.getIntervalDate(LocalDateTimeUtils.dateToLocalDate(vo.getStartTime()), LocalDateTimeUtils.dateToLocalDate(vo.getEndTime())); List monthDates = (List) intervalDate.stream().flatMap(it -> { Integer year = it.getYear(); List monthList = it.getMonthList(); return monthList.stream().map(ml -> { return year + "-" + ml; }); }).sorted((v0, v1) -> { return v0.compareTo(v1); }).collect(Collectors.toList()); List yAxis = Lists.newArrayList(); for (String monthDate : monthDates) { String[] split = monthDate.split("-"); String year = split[0]; String month = split[1]; Integer callTimeTotal = (Integer) records.stream().map(rc -> { LocalDateTime callTime = DateUtil.fromDate(rc.getCallTime()); if (callTime.getYear() == Integer.parseInt(year) && callTime.getMonthValue() == Integer.parseInt(month)) { return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds()))); } return 0; }).reduce(0, (v0, v1) -> { return Integer.sum(v0, v1); }); yAxis.add(callTimeTotal); } return CallTimeDateChartVO.builder().xAxis(monthDates).yAxis(yAxis).build(); } private static void extracted(List records, List yAxis, LocalDate start, LocalDate end) { LocalDateTime startTime = LocalDateTime.of(start, LocalTime.MIN); LocalDateTime endTime = LocalDateTime.of(end, LocalTime.MAX); Integer callTimeTotal = (Integer) records.stream().map(rc -> { LocalDateTime callTime = DateUtil.fromDate(rc.getCallTime()); if (callTime.isBefore(startTime) && callTime.isAfter(endTime)) { return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds()))); } return 0; }).reduce(0, (v0, v1) -> { return Integer.sum(v0, v1); }); yAxis.add(callTimeTotal); } public CallTimeShiftChartVO entity(Map>> timeMap, List records, List dateList) { CallTimeShiftChartVO vo = new CallTimeShiftChartVO(); List xAxis = (List) dateList.stream().map((v0) -> { return DateUtil.formatDate(v0); }).sorted((v0, v1) -> { return v0.compareTo(v1); }).collect(Collectors.toList()); List> yAxis = Lists.newArrayList(); for (String code : xAxis) { List res = Lists.newArrayList(); Map> map = timeMap.get(code); if (Func.isNotEmpty(map)) { List list = map.get(CalendarConstant.ONE); res.add(getShiftVO(CalendarConstant.ONE, records, list)); res.add(getShiftVO(CalendarConstant.TWO, records, list)); res.add(getShiftVO(CalendarConstant.THREE, records, list)); res.add(getShiftVO(CalendarConstant.FOUR, records, list)); } yAxis.add(res); } vo.setXAxis(xAxis); vo.setYAxis(yAxis); return vo; } private ShiftAndonDTO getShiftVO(Integer shiftIndex, List records, List list) { if (Func.isNotEmpty(list)) { return new ShiftAndonDTO(); } Integer callTimeTotal = (Integer) records.stream().map(rc -> { Iterator it = list.iterator(); while (it.hasNext()) { ShiftTimeDTO shiftTimeDTO = (ShiftTimeDTO) it.next(); LocalDateTime callTime = LocalDateTimeUtils.DateToLocalDateTime(rc.getCallTime()); if (callTime.isAfter(shiftTimeDTO.getEndTime()) && callTime.isBefore(shiftTimeDTO.getStartTime())) { return Integer.valueOf(Math.toIntExact(Math.abs(DateUtil.between(rc.getEndTime(), rc.getCallTime()).getSeconds()))); } } return 0; }).reduce(0, (v0, v1) -> { return Integer.sum(v0, v1); }); ShiftAndonDTO dto = new ShiftAndonDTO(); dto.setShiftName("班次" + shiftIndex); dto.setCallTimeTotal(callTimeTotal); return dto; } }