package com.qianwen.smartman.modules.visual.service.impl; import java.math.BigDecimal; import java.math.RoundingMode; import java.sql.Timestamp; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.TreeMap; import java.util.stream.Collectors; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.parser.Feature; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import com.qianwen.core.tool.utils.DateUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.core.tool.utils.StringUtil; import com.qianwen.smartman.common.cache.cps.TimeSliceCache; import com.qianwen.smartman.common.cache.cps.WorkstationCache; import com.qianwen.smartman.common.constant.CalendarConstant; import com.qianwen.smartman.common.constant.CommonConstant; import com.qianwen.smartman.common.constant.MdcConstant; import com.qianwen.smartman.common.enums.DefaultWcsEnum; import com.qianwen.smartman.common.enums.GlobalWcsTypeEnum; import com.qianwen.smartman.common.enums.WcsDataTypeEnums; import com.qianwen.smartman.common.enums.WorkstationParamTypeEnum; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.smartman.common.utils.LocalDateTimeUtils; import com.qianwen.smartman.modules.smis.dto.CalendarShiftTimeSlicesDTO; import com.qianwen.smartman.modules.smis.dto.WorkstationAlarmDTO; import com.qianwen.smartman.modules.smis.entity.GlobalWcs; import com.qianwen.smartman.modules.smis.entity.Workstation; import com.qianwen.smartman.modules.smis.entity.WorkstationWcs; import com.qianwen.smartman.modules.smis.service.IGlobalWcsService; import com.qianwen.smartman.modules.smis.service.IWorkstationService; import com.qianwen.smartman.modules.smis.service.IWorkstationWcsService; import com.qianwen.smartman.modules.smis.vo.RealTimeStatusVO; 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.mapper.SuperAggregateStateMapper; import com.qianwen.smartman.modules.mdc.service.ISuperAggregateStateService; import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils; import com.qianwen.smartman.modules.mdc.vo.StatusTimeTopVO; import com.qianwen.smartman.modules.system.entity.SeriesItem; import com.qianwen.smartman.modules.system.vo.ChartDataTableVO; import com.qianwen.smartman.modules.system.vo.ChartGanttStatusDataVO; import com.qianwen.smartman.modules.system.vo.ChartNameValueDataVO; import com.qianwen.smartman.modules.system.vo.ChartSeriesDataVO; import com.qianwen.smartman.modules.system.vo.ICard; import com.qianwen.smartman.modules.system.vo.WorkstationChartSeriesDataVO; import com.qianwen.smartman.modules.visual.dto.VisualTimeDTO; import com.qianwen.smartman.modules.visual.service.IVisualStatusService; import com.qianwen.smartman.modules.visual.utils.VisualUtils; import com.qianwen.smartman.modules.visual.vo.TimeStatusVO; import com.qianwen.smartman.modules.visual.vo.VisualBaseVO; import com.qianwen.smartman.modules.visual.vo.VisualWorkStationStatusVO; import com.qianwen.smartman.modules.visual.vo.WorkStationAlarmVO; import com.qianwen.smartman.modules.visual.wrapper.StatusWrapper; @Service public class VisualStatusServiceImpl implements IVisualStatusService { private final ISuperAggregateStateService superAggregateStateService; private final IWorkstationService workstationService; private final StatusWrapper wrapper; private final SuperAggregateStateMapper superAggregateStateMapper; private final IGlobalWcsService globalWcsService; private final IWorkstationWcsService workstationWcsService; private final Integer OUT_OF_SHIFT = -1; public VisualStatusServiceImpl(final ISuperAggregateStateService superAggregateStateService, final IWorkstationService workstationService, final StatusWrapper wrapper, final SuperAggregateStateMapper superAggregateStateMapper, final IGlobalWcsService globalWcsService, final IWorkstationWcsService workstationWcsService) { this.superAggregateStateService = superAggregateStateService; this.workstationService = workstationService; this.wrapper = wrapper; this.superAggregateStateMapper = superAggregateStateMapper; this.globalWcsService = globalWcsService; this.workstationWcsService = workstationWcsService; } public ChartGanttStatusDataVO getVisualStatusRecord(VisualBaseVO visualBaseVO) { List workStationIdList = visualBaseVO.getWorkStationIdList(); String timeLevel = visualBaseVO.getTimeLevel(); VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); List workstations = this.workstationService.workStationList(workStationIdList); List superAggregateStateList = this.superAggregateStateService.getStatusByTimeSection(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime()); return this.wrapper.entityVO(workstations, superAggregateStateList); } public ChartSeriesDataVO getDeviceStatusDuration(TimeStatusVO timeStatusVO, Integer status) { if (Func.isEmpty(timeStatusVO.getWorkStationIdList())) { return new ChartSeriesDataVO(); } List workStationIdList = timeStatusVO.getWorkStationIdList(); String timeLevel = timeStatusVO.getTimeLevel();//小时数,如24小时 Integer top = timeStatusVO.getTop();//查询多少个 VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); List statusTimeByWcs = this.superAggregateStateService.getStatusTimeByWcs(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime(), status, top); return this.wrapper.deviceStatusDuration(statusTimeByWcs, status, top); } public ChartNameValueDataVO getStatusDistribution(VisualBaseVO vo) { List workStationIdList = vo.getWorkStationIdList(); String timeLevel = vo.getTimeLevel(); VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); List data = this.superAggregateStateService.getStatusByTimeSection(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime()); return this.wrapper.entityToChartName(data); } public ChartNameValueDataVO getOeeAnalysis(VisualBaseVO vo) { List workStationIdList = vo.getWorkStationIdList(); String timeLevel = vo.getTimeLevel(); VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); List data = this.superAggregateStateService.getOeeAnalysis(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime()); return this.wrapper.entityToOee(data); } /* public ChartDataTableVO getWorkstationRealStatus(VisualBaseVO visualBaseVO) { List workStationList = visualBaseVO.getWorkStationIdList(); Map header = new LinkedHashMap<>(); int[] index = {0}; if (workStationList == null) { workStationList = Collections.EMPTY_LIST; } List list = workStationList.stream().map(item -> { return this.workstationService.getDetail(item); }).map(item2 -> { return new VisualWorkStationStatusVO(item2.getId(), item2.getMachineId(), item2.getName(), null, item2.getAvatar()); }).map(item3 -> { List realTimeProperties = this.workstationService.getRealTimeProperties(item3.getId(), item3.getMachineId()); realTimeProperties.stream().filter((v0) -> { return v0.getBigScreen(); }).map(data -> { item3.put(data.getKey() + index[0], data.getValue()); return data; }).filter(data2 -> { return !WorkstationParamTypeEnum.isAlarm(data2.getWcsDataType()); }).filter(data3 -> { return WorkstationParamTypeEnum.of(data3.getWcsDataType()) != WorkstationParamTypeEnum.STATE; }).forEach(data4 -> { header.put(data4.getKey() + index[0], data4.getName()); index[0] = index[0] + 1; }); DefaultWcsEnum wcsEnum = getWorkstationDefaultWcsEnum(realTimeProperties); item3.setBkColor(wcsEnum == null ? null : WorkstationCache.getDefaultWcsColor(Func.toStr(wcsEnum.getCode()))); item3.setStatusCode(wcsEnum == null ? null : wcsEnum.getCode().toString()); return item3; }).collect(Collectors.toList()); ChartDataTableVO chartDataTableVO = new ChartDataTableVO().setData(list).setHeader(header); return chartDataTableVO; }*/ public DefaultWcsEnum getWorkstationDefaultWcsEnum(final List realTimeProperties) { return (DefaultWcsEnum) realTimeProperties.stream().filter(p -> { return p.getWcsDataType() != null; }).filter(p2 -> { return WorkstationParamTypeEnum.STATE.getType().equals(p2.getWcsDataType()); }).filter((v0) -> { return v0.getBigScreen(); }).findFirst().map(data -> { return Integer.valueOf(Func.toInt(data.getValue())); }).map(value -> { return DefaultWcsEnum.ofDefault(value, DefaultWcsEnum.OFFLINE); }).orElse(null); } /* public ChartDataTableVO getWorkstationAlarm(final VisualBaseVO vo) { List workStationList = vo.getWorkStationIdList(); List voList = new ArrayList<>(); workStationList.stream().map(item -> { return this.workstationService.getDetail(item); }).map(item2 -> { List realTimeProperties = this.workstationService.getRealTimeProperties(item2.getId(), item2.getMachineId()); realTimeProperties.stream().filter(p -> { return WorkstationParamTypeEnum.ALARM.getType().equals(p.getWcsDataType()) || WorkstationParamTypeEnum.ALARM_NO.getType().equals(p.getWcsDataType()); }).forEach(data -> { List list; if (Func.isEmpty(data.getValue())) { list = Collections.emptyList(); } else if (data.getValue().startsWith("{")) { list = Collections.singletonList(JSON.parseObject(data.getValue(), WorkstationAlarmDTO.class)); } else { list = (List) JSON.parseObject(data.getValue(), new TypeReference>() { // from class: org.springblade.modules.visual.service.impl.VisualStatusServiceImpl.1 }, new Feature[0]); } List alarmDTOList = list; alarmDTOList.stream().forEach(alarm -> { voList.add(new WorkStationAlarmVO(item2.getName(), alarm.getCode(), alarm.getMsg())); }); }); return item2; }).collect(Collectors.toList()); ChartDataTableVO chartDataTableVO = new ChartDataTableVO().setData(voList).addHeader("code", "报警编码").addHeader(CommonConstant.ALARM_MSG, "报警信息"); return chartDataTableVO; } */ public ChartNameValueDataVO getAverageEfficiencyAnalysis(VisualBaseVO vo, ProductivityTypeEnum productivityTypeEnum) { List workStationIdList = vo.getWorkStationIdList(); List workstations = this.workstationService.listByIds(workStationIdList); Date date = new Date(); if (Func.isNotEmpty(workstations)) { String calendarCode = workstations.get(0).getCalendarCode(); CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, date); if (Func.isNotEmpty(timeSliceShift)) { String factoryDate = timeSliceShift.getFactoryDate(); Integer shiftIndex = timeSliceShift.getShiftIndex(); if (this.OUT_OF_SHIFT.equals(shiftIndex)) { return buildEmptyChartNameValueDataVO(productivityTypeEnum); } List shiftStatusData = this.superAggregateStateService.getShiftStatusData(workStationIdList, factoryDate, shiftIndex); return this.wrapper.entityToEfficiencyAverageVo(FilterOffUtils.filterOffDay(shiftStatusData, OpenTypeEnums.OEE), productivityTypeEnum); } } return buildEmptyChartNameValueDataVO(productivityTypeEnum); } public ChartNameValueDataVO buildEmptyChartNameValueDataVO(ProductivityTypeEnum productivityTypeEnum) { ChartNameValueDataVO chartNameValueDataVO = new ChartNameValueDataVO(); switch (productivityTypeEnum) { case ALARM: chartNameValueDataVO.addValue("平均报警率", ""); break; case RUNNING: chartNameValueDataVO.addValue("平均运行率", ""); break; default: chartNameValueDataVO.addValue("平均稼动率", ""); break; } return chartNameValueDataVO; } public ChartSeriesDataVO getEfficiencyAnalysisShiftTop(TimeStatusVO timeStatusVO, ProductivityTypeEnum productivityTypeEnum) { List workstations = this.workstationService.listByIds(timeStatusVO.getWorkStationIdList()); Date date = new Date(); if (Func.isNotEmpty(workstations)) { String calendarCode = workstations.get(0).getCalendarCode(); CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, date); if (Func.isNotEmpty(timeSliceShift)) { String factoryDate = timeSliceShift.getFactoryDate(); Integer shiftIndex = timeSliceShift.getShiftIndex(); if (this.OUT_OF_SHIFT.equals(shiftIndex)) { return new ChartSeriesDataVO(); } List shiftStatusData = this.superAggregateStateService.getShiftStatusData(timeStatusVO.getWorkStationIdList(), factoryDate, shiftIndex); return this.wrapper.entityToEfficiencyTopVo(FilterOffUtils.filterOffDay(shiftStatusData, OpenTypeEnums.OEE), productivityTypeEnum, timeStatusVO.getTop(), workstations, "当前班次稼动率"); } } return new ChartSeriesDataVO(); } public ChartNameValueDataVO getGroupRunning(VisualBaseVO vo, ProductivityTypeEnum productivityTypeEnum) { List workStationIdList = vo.getWorkStationIdList(); if (Func.isEmpty(workStationIdList)) { return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, ""); } List workstations = this.workstationService.listByIds(workStationIdList); if (Func.isEmpty(workstations)) { return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, ""); } Date date = new Date(); String calendarCode = (String) workstations.stream().map((v0) -> { return v0.getCalendarCode(); }).filter(c -> { return Func.isNotEmpty(c) && !CalendarConstant.DEFAULT_CALENDAR.equals(c); }).distinct().findAny().orElse(""); CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, date); if (Func.isNotEmpty(timeSliceShift) && !timeSliceShift.getShiftIndex().equals(-1)) { String factoryDate = timeSliceShift.getFactoryDate(); Integer shiftIndex = timeSliceShift.getShiftIndex(); if (this.OUT_OF_SHIFT.equals(shiftIndex)) { return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, ""); } List shiftStatusData = this.superAggregateStateService.getShiftStatusData(workStationIdList, factoryDate, shiftIndex); Integer code = DefaultWcsEnum.RUNNING.getCode(); List aggregateStates = (List) shiftStatusData.stream().filter(c2 -> { return code.equals(c2.getWcs()); }).collect(Collectors.toList()); return this.wrapper.entityToGroupRunning(aggregateStates, Integer.valueOf(workstations.size())); } return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, ""); } public ChartGanttStatusDataVO getNatureStatusRecord(VisualBaseVO visualBaseVO) { List workStationIdList = visualBaseVO.getWorkStationIdList(); List workstations = this.workstationService.workStationList(workStationIdList); LocalDateTime now = LocalDateTime.now(); List superAggregateStateList = this.superAggregateStateService.getStatusByCondition(workStationIdList, LocalDateTimeUtils.getDayStart(now), LocalDateTimeUtils.getDayEnd(now)); return this.wrapper.entityVO(workstations, superAggregateStateList); } public ChartNameValueDataVO getStatusToDayDistribution(VisualBaseVO vo) { List workStationIdList = vo.getWorkStationIdList(); LocalDate now = LocalDate.now(); LocalDateTime startTime = LocalDateTime.of(now, LocalTime.MIN); LocalDateTime endTime = LocalDateTime.of(now, LocalTime.MAX); List data = this.superAggregateStateService.getStatusByCondition(workStationIdList, startTime, endTime); return this.wrapper.entityToChartName(data); } public ChartNameValueDataVO getStatusShiftDistribution(VisualBaseVO vo) { List workStationIdList = vo.getWorkStationIdList(); List workstations = this.workstationService.listByIds(workStationIdList); List defaultWcs = WorkstationCache.getDefaultWcs(); ChartNameValueDataVO res = new ChartNameValueDataVO(); if (Func.isEmpty(workstations)) { defaultWcs.forEach(w -> { res.addValue(w.getName(), Double.valueOf(0.0d), "", w.getColor()); }); return res; } List states = Lists.newArrayList(); Map> calendarCodeMap = workstations.stream().filter(c -> { return Func.isNotEmpty(c.getCalendarCode()); }).collect(Collectors.groupingBy((v0) -> { return v0.getCalendarCode(); })); calendarCodeMap.forEach((calendarCode, workstationList) -> { CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, DateUtil.now()); List ids = workstationList.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); if (Func.isNotEmpty(timeSliceShift) && !this.OUT_OF_SHIFT.equals(timeSliceShift.getShiftIndex())) { String factoryDate = timeSliceShift.getFactoryDate(); Integer shiftIndex = timeSliceShift.getShiftIndex(); List data = this.superAggregateStateService.getStatusByFactory(ids, factoryDate, shiftIndex); states.addAll(data); } }); if (Func.isNotEmpty(states)) { return this.wrapper.entityToChartName(states); } return res; } public ChartGanttStatusDataVO getEquipmentStatusRecord(VisualBaseVO visualBaseVO) { List workStationIdList = visualBaseVO.getWorkStationIdList(); List stateList = new ArrayList<>(); List workstationList = this.workstationService.list(Wrappers.lambdaQuery().in(Workstation::getId, workStationIdList)); /* List workstationList = this.workstationService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getId(); }, workStationIdList));*/ if (Func.isNotEmpty(workstationList)) { Map> calendarCodeMap = workstationList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getCalendarCode(); })); calendarCodeMap.forEach((k, v) -> { List workstationIds = v.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(k, new Date()); if (timeSliceShift != null && !this.OUT_OF_SHIFT.equals(timeSliceShift.getShiftIndex())) { List superAggregateOutputList = this.superAggregateStateMapper.getEquipmentStatusRecord(workstationIds, timeSliceShift.getShiftIndex(), Integer.valueOf(Func.toInt(timeSliceShift.getFactoryDate().replaceAll("-", "")))); if (Func.isNotEmpty(superAggregateOutputList)) { stateList.addAll(superAggregateOutputList); } } }); } List collect = stateList.stream().peek(s -> { if (Func.isNull(s.getEndTime())) { s.setEndTime(new Timestamp(DateUtil.now().getTime())); } }).collect(Collectors.toList()); return this.wrapper.entityVO(workstationList, collect); } public ChartSeriesDataVO getTodayStatusStatistics(VisualBaseVO vo, ProductivityTypeEnum productivityTypeEnum) { if (Func.isEmpty(vo.getWorkStationIdList())) { return new ChartSeriesDataVO(); } LocalDateTime now = LocalDateTime.now(); LocalDateTime dayStart = LocalDateTimeUtils.getDayStart(now); LocalDateTime dayEnd = LocalDateTimeUtils.getDayEnd(now); List workstations = this.workstationService.workStationList(vo.getWorkStationIdList()); List statusByCondition = this.superAggregateStateService.getStatusByCondition(vo.getWorkStationIdList(), dayStart, dayEnd); List collect = (List) FilterOffUtils.filterOffDay(statusByCondition, OpenTypeEnums.OEE).stream().filter(s -> { return s.getRps().intValue() > 0; }).collect(Collectors.toList()); return this.wrapper.entityToEfficiencyTopVo(collect, productivityTypeEnum, Integer.valueOf(workstations.size()), workstations, "自然日设备稼动率"); } public ChartNameValueDataVO getTodayAverageStatusStatistics(VisualBaseVO vo, ProductivityTypeEnum productivityTypeEnum) { LocalDateTime now = LocalDateTime.now(); LocalDateTime dayStart = LocalDateTimeUtils.getDayStart(now); LocalDateTime dayEnd = LocalDateTimeUtils.getDayEnd(now); List statusByCondition = this.superAggregateStateService.getStatusByCondition(vo.getWorkStationIdList(), dayStart, dayEnd); List collect = FilterOffUtils.filterOffDay(statusByCondition, OpenTypeEnums.OEE).stream().filter(s -> { return s.getRps().intValue() > 0; }).collect(Collectors.toList()); return this.wrapper.entityToEfficiencyAverageVo(collect, productivityTypeEnum); } public ChartSeriesDataVO getEfficiencyAnalysisTop(TimeStatusVO timeStatusVO, ProductivityTypeEnum productivityTypeEnum) { List workStationIdList = timeStatusVO.getWorkStationIdList(); if (Func.isEmpty(workStationIdList)) { return new ChartSeriesDataVO(); } List workstations = this.workstationService.listByIds(workStationIdList); String timeLevel = timeStatusVO.getTimeLevel(); VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); List statusByCondition = this.superAggregateStateService.getStatusByTimeSection(timeStatusVO.getWorkStationIdList(), visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime()); List collect = FilterOffUtils.filterOffDay(statusByCondition, OpenTypeEnums.OEE).stream().filter(s -> { return s.getRps().intValue() > 0; }).collect(Collectors.toList()); return this.wrapper.entityToEfficiencyTopVo(collect, productivityTypeEnum, timeStatusVO.getTop(), workstations, StringUtil.format("近{}小时稼动率排名", new Object[]{timeLevel})); } public ChartNameValueDataVO getCurrMonthOee(VisualBaseVO vo) { List ids = vo.getWorkStationIdList(); if (Func.isEmpty(ids)) { return new ChartNameValueDataVO().addValue(MdcConstant.MONTH_OEE_NAME, Double.valueOf(0.0d)); } LocalDate now = LocalDate.now(); int monthValue = now.getMonthValue(); List data = this.superAggregateStateService.getCurrMonthState(ids, Integer.valueOf(monthValue)); return this.wrapper.entityToMonthOee(FilterOffUtils.filterOffDay(data, OpenTypeEnums.OEE)); } public ChartNameValueDataVO getCurrMonthRunning(VisualBaseVO vo) { List ids = vo.getWorkStationIdList(); if (Func.isEmpty(ids)) { return new ChartNameValueDataVO().addValue(MdcConstant.MONTH_RUNNING_NAME, Double.valueOf(0.0d)); } LocalDate now = LocalDate.now(); int monthValue = now.getMonthValue(); List data = this.superAggregateStateService.getCurrMonthState(ids, Integer.valueOf(monthValue)); return this.wrapper.entityToMonthRunning(data); } public ChartSeriesDataVO getCurrMonthAlarm(VisualBaseVO vo) { List ids = vo.getWorkStationIdList(); if (Func.isEmpty(ids)) { ChartSeriesDataVO res = new ChartSeriesDataVO(); res.setCategories(Lists.newArrayList()); res.setSeries(Lists.newArrayList()); return res; } List workstations = this.workstationService.listByIds(ids); if (Func.isEmpty(workstations)) { ChartSeriesDataVO res2 = new ChartSeriesDataVO(); res2.setCategories(Lists.newArrayList()); res2.setSeries(Lists.newArrayList()); return res2; } Map workstationMap = (Map) workstations.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, v -> { return v; })); List workIds = workstations.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); LocalDate now = LocalDate.now(); int monthValue = now.getMonthValue(); List data = this.superAggregateStateService.getCurrMonthAlarmState(workIds, Integer.valueOf(monthValue), DefaultWcsEnum.ALARM.getCode()); return getChartSeriesDataVO(workstations, workstationMap, FilterOffUtils.filterOffDay(data, OpenTypeEnums.TIME_USED_ANALYSIS), "月设备报警时长排名"); } private ChartSeriesDataVO getChartSeriesDataVO(List workstations, Map workstationMap, List data, String name) { Map workMap = data.stream().collect(Collectors.groupingBy((v0) -> { return v0.getWorkstationId(); }, TreeMap::new, Collectors.mapping((v0) -> { return v0.getDurationCollect(); }, Collectors.reducing(0L, (v0, v1) -> { return Long.sum(v0, v1); })))); List> list = Lists.newArrayList(workMap.entrySet()); list.sort((o1, o2) -> { return Math.toIntExact(((Long) o2.getValue()).longValue() - ((Long) o1.getValue()).longValue()); }); WorkstationChartSeriesDataVO res = new WorkstationChartSeriesDataVO(); List codes = Lists.newArrayList(); SeriesItem item = new SeriesItem<>(); List xData = Lists.newArrayList(); for (Map.Entry entry : list) { Long id = entry.getKey(); Workstation workstation = workstationMap.get(id); if (Func.notNull(workstation)) { codes.add(workstation); xData.add(secondToHour(entry.getValue()) + ""); } } for (Workstation workstation2 : workstations) { Long duration = workMap.get(workstation2.getId()); if (Func.isNull(duration)) { codes.add(workstation2); xData.add("0"); } } item.setName(name); item.setData(xData); res.generateCategories(codes); res.setSeries(Lists.newArrayList(new SeriesItem[]{item})); return res; } public ChartSeriesDataVO getCurrWeekAlarm(VisualBaseVO vo) { List ids = vo.getWorkStationIdList(); if (Func.isEmpty(ids)) { ChartSeriesDataVO res = new ChartSeriesDataVO(); res.setCategories(Lists.newArrayList()); res.setSeries(Lists.newArrayList()); return res; } Integer week = LocalDateTimeUtils.getWeek(LocalDate.now()); List workstations = this.workstationService.listByIds(ids); if (Func.isEmpty(workstations)) { ChartSeriesDataVO res2 = new ChartSeriesDataVO(); res2.setCategories(Lists.newArrayList()); res2.setSeries(Lists.newArrayList()); return res2; } List workIds = workstations.stream().map((v0) -> { return v0.getId(); }).collect(Collectors.toList()); List data = this.superAggregateStateService.getCurrWeekAlarmState(workIds, week, DefaultWcsEnum.ALARM.getCode()); List data2 = FilterOffUtils.filterOffDay(data, OpenTypeEnums.TIME_USED_ANALYSIS); Map workstationMap = workstations.stream().collect(Collectors.toMap((v0) -> { return v0.getId(); }, v -> { return v; })); return getChartSeriesDataVO(workstations, workstationMap, data2, "周设备报警时长排名"); } private double secondToHour(Long second) { BigDecimal bg = new BigDecimal(second.longValue()); BigDecimal bg2 = new BigDecimal(3600000); return bg.divide(bg2, 2, RoundingMode.HALF_UP).doubleValue(); } public ChartNameValueDataVO getWorkstationRealStatusChart(VisualBaseVO vo) { Map settings = this.workstationWcsService.list(Lambda.in(WorkstationWcs::getWorkstationId, vo.getWorkStationIdList()) .eq(WorkstationWcs::getDataType, WcsDataTypeEnums.WcsDataType.STATE.getCode()).select(WorkstationWcs::getCollectSettingItem, WorkstationWcs::getWorkstationId )) .stream().collect(Collectors.toMap(WorkstationWcs::getWorkstationId, WorkstationWcs::getCollectSettingItem)); /* Map settings = (Map) this.workstationWcsService.list(((ExtraLambdaQueryWrapper) Lambda.in((v0) -> { return v0.getWorkstationId(); }, vo.getWorkStationIdList()).eq((v0) -> { return v0.getDataType(); }, WcsDataTypeEnums.WcsDataType.STATE.getCode())).select((v0) -> { return v0.getCollectSettingItem(); }, (v0) -> { return v0.getWorkstationId(); })).stream().collect(Collectors.toMap((v0) -> { return v0.getWorkstationId(); }, (v0) -> { return v0.getCollectSettingItem(); }));*/ Map statusCollect = vo.getWorkStationIdList().stream().map(id -> { return WorkstationCache.getWorkstationRealTime(id, (String) settings.getOrDefault(id, MdcConstant.DEVICE_STATUS)); }).filter((v0) -> { return Objects.nonNull(v0); }).collect(Collectors.groupingBy((v0) -> { return v0.getV(); }, Collectors.counting())); ChartNameValueDataVO chartNameValueDataVO = new ChartNameValueDataVO(); this.globalWcsService.getGlobalWcsList(GlobalWcsTypeEnum.DEFAULT).forEach(item -> { long count = ((Long) statusCollect.getOrDefault(item.getCode(), 0L)).longValue(); chartNameValueDataVO.addValue(item.getName(), Long.valueOf(count), Integer.parseInt(item.getCode())); }); return chartNameValueDataVO; } }