package com.qianwen.smartman.modules.mdc.wrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.qianwen.smartman.common.constant.MdcConstant; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.cps.entity.Workstation; import com.qianwen.smartman.modules.mdc.dto.IntervalDateDto; import com.qianwen.smartman.modules.mdc.dto.ShiftIndexNameDTO; import com.qianwen.smartman.modules.mdc.dto.StatisticsWrapperDto; import com.qianwen.smartman.modules.mdc.entity.SuperAggregate; import com.qianwen.smartman.modules.mdc.entity.SuperAggregateOutput; import com.qianwen.smartman.modules.mdc.entity.SuperAggregateState; import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums; import com.qianwen.smartman.modules.mdc.enums.ProductivityTypeEnum; import com.qianwen.smartman.modules.mdc.service.ITimeUsedAnalysisService; import com.qianwen.smartman.modules.mdc.utils.EifficiencyUtils; import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils; import com.qianwen.smartman.modules.mdc.vo.StatisticsAnalysisQueryVO; import com.qianwen.smartman.modules.mdc.vo.StatisticsDataVO; import com.qianwen.smartman.modules.mdc.vo.StatisticsVO; import org.springframework.stereotype.Component; @Component /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/mdc/wrapper/StatisticsWrapper.class */ public class StatisticsWrapper { private static final Logger log = LoggerFactory.getLogger(StatisticsWrapper.class); private final ITimeUsedAnalysisService timeUsedAnalysisService; public StatisticsWrapper(final ITimeUsedAnalysisService timeUsedAnalysisService) { this.timeUsedAnalysisService = timeUsedAnalysisService; } public StatisticsVO entityVO(StatisticsWrapperDto statisticsWrapperDto) { StatisticsVO statisticsVO; StatisticsAnalysisQueryVO statisticsAnalysisQueryVO = statisticsWrapperDto.getStatisticsAnalysisQueryVO(); List intervalDates = statisticsWrapperDto.getIntervalDates(); List superAggregates = new ArrayList<>(statisticsWrapperDto.getSuperAggregateList()); IPage workstationPage = statisticsWrapperDto.getWorkstationPage(); Boolean isOutput = statisticsWrapperDto.getIsOutput(); Integer queryType = statisticsAnalysisQueryVO.getQueryType(); List shiftIndexList = statisticsAnalysisQueryVO.getShiftIndexList(); new StatisticsVO(); ProductivityTypeEnum productivityType = statisticsAnalysisQueryVO.getProductivityType(); switch (statisticsAnalysisQueryVO.getStatisticalMethod()) { case DAY: if (MdcConstant.SHEET.equals(queryType)) { statisticsVO = buildDateDataSheet(intervalDates, superAggregates, workstationPage, isOutput, productivityType); break; } else { statisticsVO = buildDateData(intervalDates, superAggregates, workstationPage.getRecords(), isOutput, productivityType); break; } case WEEK: if (MdcConstant.SHEET.equals(queryType)) { statisticsVO = buildMonthOrWeekDataSheet(intervalDates, superAggregates, workstationPage, MdcConstant.WEEK, isOutput, productivityType); break; } else { statisticsVO = buildMonthOrWeekData(intervalDates, superAggregates, workstationPage.getRecords(), MdcConstant.WEEK, isOutput, productivityType); break; } case MONTH: if (MdcConstant.SHEET.equals(queryType)) { statisticsVO = buildMonthOrWeekDataSheet(intervalDates, superAggregates, workstationPage, MdcConstant.MONTH, isOutput, productivityType); break; } else { statisticsVO = buildMonthOrWeekData(intervalDates, superAggregates, workstationPage.getRecords(), MdcConstant.MONTH, isOutput, productivityType); break; } default: List workstationIds = (List) workstationPage.getRecords().stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); Map> idToValue = this.timeUsedAnalysisService.queryWorkStationShiftIndex(workstationIds, statisticsAnalysisQueryVO.getStartDate()); statisticsVO = buildShiftData(superAggregates, workstationPage, shiftIndexList, idToValue, isOutput, productivityType); break; } return statisticsVO; } public StatisticsVO buildDateDataSheet(List intervalDates, List superAggregates, IPage workstationIPage, Boolean isOutput, ProductivityTypeEnum productivityType) { StatisticsVO statisticsVO = new StatisticsVO(); Map>> collectGroupByDate = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryDate(); }))); List dayList = intervalDates.get(0).getDayList(); List statisticsDataVOS = new ArrayList<>(); List workstationList = workstationIPage.getRecords(); workstationList.forEach(workstation -> { StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); statisticsDataVO.setId(workstation.getId().toString()); statisticsDataVO.setWorkstationCode(workstation.getCode()); statisticsDataVO.setWorkstationName(workstation.getName()); Map> map = (Map) collectGroupByDate.get(workstation.getId()); LinkedHashMap data = new LinkedHashMap<>(); if (Func.isEmpty(map)) { dayList.forEach(day -> { data.put(day, "0"); }); } else { dayList.forEach(day2 -> { List superAggregateList = (List) map.get(Integer.valueOf(day2.replaceAll("-", ""))); String value = getValue(superAggregateList, isOutput, productivityType); data.put(day2, value); }); } statisticsDataVO.setData(data); statisticsDataVOS.add(statisticsDataVO); }); Page page = new Page(); page.setRecords(statisticsDataVOS); page.setTotal(workstationIPage.getTotal()).setPages(workstationIPage.getPages()).setSize(workstationIPage.getSize()).setCurrent(workstationIPage.getCurrent()); statisticsVO.setItems(page); return statisticsVO; } public StatisticsVO buildDateData(List intervalDates, List superAggregates, List workstationList, Boolean isOutput, ProductivityTypeEnum productivityType) { Map workstationIdToValue = (Map) workstationList.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, v -> { return v; })); List workstationIdList = (List) workstationList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); StatisticsVO statisticsVO = new StatisticsVO(); Map>> collectGroupByDate = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getFactoryDate(); }, Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }))); List dayList = intervalDates.get(0).getDayList(); List statisticsDataVOS = new ArrayList<>(); dayList.forEach(day -> { StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); statisticsDataVO.setId(day); Map> map = (Map) collectGroupByDate.get(Integer.valueOf(day.replaceAll("-", ""))); LinkedHashMap data = new LinkedHashMap<>(); LinkedHashMap nameData = new LinkedHashMap<>(); if (Func.isEmpty(map)) { workstationIdList.forEach(workstationId -> { data.put(workstationId.toString(), "0"); nameData.put(String.valueOf(workstationId), ((Workstation) workstationIdToValue.get(workstationId)).getName()); }); } else { workstationIdList.forEach(workstationId2 -> { List superAggregateList = (List) map.get(workstationId2); String value = getValue(superAggregateList, isOutput, productivityType); data.put(workstationId2.toString(), value); nameData.put(String.valueOf(workstationId2), ((Workstation) workstationIdToValue.get(workstationId2)).getName()); }); } statisticsDataVO.setData(data); statisticsDataVO.setNameData(nameData); statisticsDataVOS.add(statisticsDataVO); }); Page page = new Page(); page.setRecords(statisticsDataVOS).setSize(-1L); statisticsVO.setItems(page); return statisticsVO; } public StatisticsVO buildMonthOrWeekDataSheet(List intervalDates, List superAggregates, IPage workstationIPage, Boolean isMonth, Boolean isOutput, ProductivityTypeEnum productivityType) { StatisticsVO statisticsVO = new StatisticsVO(); Map>>> collectGroupByMonth = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryYear(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryMonth(); })))); Map>>> collectGroupByWeek = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryYear(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryWeek(); })))); List statisticsDataVOS = new ArrayList<>(); List workstationList = workstationIPage.getRecords(); workstationList.forEach(workstation -> { Map>> yearMap; StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); statisticsDataVO.setId(String.valueOf(workstation.getId())); statisticsDataVO.setWorkstationCode(workstation.getCode()); statisticsDataVO.setWorkstationName(workstation.getName()); LinkedHashMap data = new LinkedHashMap<>(); if (isMonth.booleanValue()) { yearMap = (Map) collectGroupByMonth.get(workstation.getId()); } else { yearMap = (Map) collectGroupByWeek.get(workstation.getId()); } if (Func.isEmpty(yearMap)) { intervalDates.forEach(intervalDateDto -> { Integer year = intervalDateDto.getYear(); if (isMonth.booleanValue()) { intervalDateDto.getMonthList().forEach(month -> { data.put(year + "-" + month, "0"); }); } else { intervalDateDto.getWeekList().forEach(week -> { data.put(year + "-" + week, "0"); }); } }); } else { Map>> map = yearMap; intervalDates.forEach(intervalDateDto2 -> { Map> monthOrWeekMap = (Map) map.get(intervalDateDto2.getYear()); if (Func.isEmpty(monthOrWeekMap)) { if (isMonth.booleanValue()) { List monthList = intervalDateDto2.getMonthList(); monthList.forEach(month -> { data.put(intervalDateDto2.getYear() + "-" + month, "0"); }); return; } List weekList = intervalDateDto2.getWeekList(); weekList.forEach(week -> { data.put(intervalDateDto2.getYear() + "-" + week, "0"); }); } else if (isMonth.booleanValue()) { intervalDateDto2.getMonthList().forEach(month2 -> { List superAggregateList = (List) monthOrWeekMap.get(month2); String value = getValue(superAggregateList, isOutput, productivityType); data.put(intervalDateDto2.getYear() + "-" + month2, value); }); } else { intervalDateDto2.getWeekList().forEach(week2 -> { List superAggregateList = (List) monthOrWeekMap.get(week2); String value = getValue(superAggregateList, isOutput, productivityType); data.put(intervalDateDto2.getYear() + "-" + week2, value); }); } }); } statisticsDataVO.setData(data); statisticsDataVOS.add(statisticsDataVO); }); Page page = new Page(); page.setRecords(statisticsDataVOS); page.setTotal(workstationIPage.getTotal()).setPages(workstationIPage.getPages()).setSize(workstationIPage.getSize()).setCurrent(workstationIPage.getCurrent()); statisticsVO.setItems(page); return statisticsVO; } public StatisticsVO buildMonthOrWeekData(List intervalDates, List superAggregates, List workstationList, Boolean isMonth, Boolean isOutput, ProductivityTypeEnum productivityType) { Map>>> collectGroupByMonthOrWeek; Map workstationIdToValue = (Map) workstationList.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, v -> { return v; })); List workstationIdList = (List) workstationList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); StatisticsVO statisticsVO = new StatisticsVO(); if (isMonth.booleanValue()) { collectGroupByMonthOrWeek = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getFactoryYear(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryMonth(); }, Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })))); } else { collectGroupByMonthOrWeek = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getFactoryYear(); }, Collectors.groupingBy((v0) -> { return v0.getFactoryWeek(); }, Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); })))); } List statisticsDataVOS = new ArrayList<>(); Map>>> finalCollectGroupByMonthOrWeek = collectGroupByMonthOrWeek; intervalDates.forEach(intervalDateDto -> { List monthOrWeekList; Integer year = intervalDateDto.getYear(); Map>> monthOrWeekToValue = (Map) finalCollectGroupByMonthOrWeek.get(year); if (isMonth.booleanValue()) { monthOrWeekList = intervalDateDto.getMonthList(); } else { monthOrWeekList = intervalDateDto.getWeekList(); } if (Func.isEmpty(monthOrWeekToValue)) { monthOrWeekList.forEach(monthOrWeek -> { StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); LinkedHashMap data = new LinkedHashMap<>(); LinkedHashMap nameData = new LinkedHashMap<>(); statisticsDataVO.setId(year + "-" + monthOrWeek); workstationIdList.forEach(workstationId -> { data.put(workstationId.toString(), "0"); nameData.put(workstationId.toString(), ((Workstation) workstationIdToValue.get(workstationId)).getName()); }); statisticsDataVO.setData(data); statisticsDataVO.setNameData(nameData); statisticsDataVOS.add(statisticsDataVO); }); } else { monthOrWeekList.forEach(monthOrWeek2 -> { StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); LinkedHashMap data = new LinkedHashMap<>(); LinkedHashMap nameData = new LinkedHashMap<>(); statisticsDataVO.setId(year + "-" + monthOrWeek2); Map> workstationMap = (Map) monthOrWeekToValue.get(monthOrWeek2); if (Func.isEmpty(workstationMap)) { workstationIdList.forEach(workstationId -> { data.put(workstationId.toString(), "0"); nameData.put(workstationId.toString(), ((Workstation) workstationIdToValue.get(workstationId)).getName()); }); } else { workstationIdList.forEach(workstationId2 -> { List superAggregateList = (List) workstationMap.get(workstationId2); String value = getValue(superAggregateList, isOutput, productivityType); data.put(workstationId2.toString(), value); nameData.put(workstationId2.toString(), ((Workstation) workstationIdToValue.get(workstationId2)).getName()); }); } statisticsDataVO.setData(data); statisticsDataVO.setNameData(nameData); statisticsDataVOS.add(statisticsDataVO); }); } }); Page page = new Page(); page.setRecords(statisticsDataVOS).setSize(-1L); statisticsVO.setItems(page); return statisticsVO; } public StatisticsVO buildShiftData(List superAggregates, IPage workstationIPage, List shiftIndexList, Map> idToValue, Boolean isOutput, ProductivityTypeEnum productivityType) { Map>> collectGroupByShift = (Map) superAggregates.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }, Collectors.groupingBy((v0) -> { return v0.getShiftIndex(); }))); StatisticsVO statisticsVO = new StatisticsVO(); List workstationList = workstationIPage.getRecords(); List statisticsDataVOS = new ArrayList<>(); workstationList.forEach(workstation -> { StatisticsDataVO statisticsDataVO = new StatisticsDataVO(); statisticsDataVO.setId(String.valueOf(workstation.getId())); statisticsDataVO.setWorkstationCode(workstation.getCode()); statisticsDataVO.setWorkstationName(workstation.getName()); Map> map = (Map) collectGroupByShift.get(workstation.getId()); LinkedHashMap data = new LinkedHashMap<>(); LinkedHashMap shiftData = new LinkedHashMap<>(); List shiftDetails = (List) idToValue.get(workstation.getId()); List trueShiftIndexList = new ArrayList<>(); Map shiftIndexToName = new HashMap<>(); if (Func.isNotEmpty(shiftDetails)) { trueShiftIndexList = (List) shiftDetails.stream().map((v0) -> { return v0.getShiftIndex(); }).collect(Collectors.toList()); shiftIndexToName = (Map) shiftDetails.stream().collect(Collectors.toMap((v0) -> { return v0.getShiftIndex(); }, (v0) -> { return v0.getIndexName(); })); } if (Func.isEmpty(map)) { List finalTrueShiftIndexList = trueShiftIndexList; Map finalShiftIndexToName = shiftIndexToName; shiftIndexList.forEach(shiftIndex -> { if (finalTrueShiftIndexList.contains(shiftIndex)) { data.put(shiftIndex.toString(), "0"); shiftData.put(shiftIndex.toString(), finalShiftIndexToName.get(shiftIndex)); return; } data.put(shiftIndex.toString(), "-"); shiftData.put(shiftIndex.toString(), MessageUtils.message("mdc.not.schedule", new Object[0])); }); } else { Map finalShiftIndexToName1 = shiftIndexToName; List finalTrueShiftIndexList1 = trueShiftIndexList; shiftIndexList.forEach(shiftIndex2 -> { if (finalTrueShiftIndexList1.contains(shiftIndex2)) { List superAggregateList = (List) map.get(shiftIndex2); String value = getValue(superAggregateList, isOutput, productivityType); data.put(shiftIndex2.toString(), value); shiftData.put(shiftIndex2.toString(), finalShiftIndexToName1.get(shiftIndex2)); return; } data.put(shiftIndex2.toString(), "-"); shiftData.put(shiftIndex2.toString(), MessageUtils.message("mdc.not.schedule", new Object[0])); }); } statisticsDataVO.setData(data); statisticsDataVO.setNameData(shiftData); statisticsDataVOS.add(statisticsDataVO); }); Page page = new Page(); page.setRecords(statisticsDataVOS); page.setTotal(workstationIPage.getTotal()).setPages(workstationIPage.getPages()).setSize(workstationIPage.getSize()).setCurrent(workstationIPage.getCurrent()); statisticsVO.setItems(page); return statisticsVO; } public String getValue(List superAggregateList, Boolean output, ProductivityTypeEnum productivityType) { String value; if (output.booleanValue()) { List superAggregateOutputList = getSuperAggregateOutputList(superAggregateList); value = String.valueOf(calculateOutput(superAggregateOutputList)); } else { List superAggregateStateList = getSuperAggregateStateList(superAggregateList); value = String.valueOf(EifficiencyUtils.calculationResults(superAggregateStateList, productivityType)); } return value; } public List getSuperAggregateOutputList(List superAggregateList) { List superAggregateOutputList = new ArrayList<>(); if (Func.isEmpty(superAggregateList)) { return superAggregateOutputList; } superAggregateList.forEach(superAggregate -> { if (superAggregate instanceof SuperAggregateOutput) { superAggregateOutputList.add((SuperAggregateOutput) superAggregate); } }); return superAggregateOutputList; } public List getSuperAggregateStateList(List superAggregateList) { List superAggregateStateList = new ArrayList<>(); if (Func.isEmpty(superAggregateList)) { return superAggregateStateList; } superAggregateList.forEach(superAggregate -> { if (superAggregate instanceof SuperAggregateState) { superAggregateStateList.add((SuperAggregateState) superAggregate); } }); return superAggregateStateList; } public Long calculateOutput(List superAggregateOutputList) { List superAggregateOutputList2 = FilterOffUtils.filterOffDay(superAggregateOutputList, OpenTypeEnums.OUT_PUT); if (Func.isEmpty(superAggregateOutputList2)) { return 0L; } return Long.valueOf(superAggregateOutputList2.stream().mapToLong((v0) -> { return v0.getOutput(); }).sum()); } }