package com.qianwen.smartman.modules.visual.service.impl; import cn.hutool.core.date.LocalDateTimeUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.google.common.collect.Lists; import java.lang.invoke.SerializedLambda; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; import com.qianwen.smartman.common.cache.cps.TimeSliceCache; import com.qianwen.smartman.common.constant.DateConstant; import com.qianwen.smartman.common.constant.VisualConstant; import com.qianwen.smartman.common.utils.Lambda; import com.qianwen.core.tool.utils.DateUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.cps.dto.CalendarShiftTimeSlicesDTO; import com.qianwen.smartman.modules.cps.entity.Workstation; import com.qianwen.smartman.modules.cps.entity.WorkstationWcsUsage; import com.qianwen.smartman.modules.cps.service.IWorkstationService; import com.qianwen.smartman.modules.cps.service.IWorkstationWcsUsageService; import com.qianwen.smartman.modules.mdc.entity.SuperAggregateOutput; import com.qianwen.smartman.modules.mdc.enums.OpenTypeEnums; import com.qianwen.smartman.modules.mdc.mapper.SuperAggregateOutputMapper; import com.qianwen.smartman.modules.mdc.utils.FilterOffUtils; import com.qianwen.smartman.modules.system.entity.SeriesItem; import com.qianwen.smartman.modules.system.vo.ChartSeriesDataVO; import com.qianwen.smartman.modules.system.vo.WorkstationChartSeriesDataVO; import com.qianwen.smartman.modules.tdengine.service.IWorkstationDynamicCollectService; import com.qianwen.smartman.modules.visual.dto.DynamicCountDateAggregateDTO; import com.qianwen.smartman.modules.visual.dto.VisualTimeDTO; import com.qianwen.smartman.modules.visual.service.IVisualOutputService; import com.qianwen.smartman.modules.visual.utils.VisualUtils; import com.qianwen.smartman.modules.visual.vo.VisualSingleBaseVO; import com.qianwen.smartman.modules.visual.vo.VisualUsagePolicyEnum; import com.qianwen.smartman.modules.visual.vo.WorkstationCountVisualQueryVO; import com.qianwen.smartman.modules.visual.vo.WorkstationShiftOutput; import com.qianwen.smartman.modules.visual.wrapper.OutputWrapper; import org.springframework.stereotype.Service; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/visual/service/impl/VisualOutputServiceImpl.class */ public class VisualOutputServiceImpl implements IVisualOutputService { private final SuperAggregateOutputMapper superAggregateOutputMapper; private final IWorkstationService workstationService; private final OutputWrapper outputWrapper; private final IWorkstationDynamicCollectService dynamicCollectService; private final IWorkstationWcsUsageService workstationWcsUsageService; public VisualOutputServiceImpl(final SuperAggregateOutputMapper superAggregateOutputMapper, final IWorkstationService workstationService, final OutputWrapper outputWrapper, final IWorkstationDynamicCollectService dynamicCollectService, final IWorkstationWcsUsageService workstationWcsUsageService) { this.superAggregateOutputMapper = superAggregateOutputMapper; this.workstationService = workstationService; this.outputWrapper = outputWrapper; this.dynamicCollectService = dynamicCollectService; this.workstationWcsUsageService = workstationWcsUsageService; } @Override // org.springblade.modules.visual.service.IVisualOutputService public ChartSeriesDataVO getWorkstationHoursOutput(VisualSingleBaseVO visualBaseVO) { List xList = new ArrayList<>(); Long workstationId = visualBaseVO.getWorkStationId(); String timeLevel = visualBaseVO.getTimeLevel(); int level = Integer.parseInt(timeLevel); List localDateTimes = getLocalDateTime(Integer.valueOf(level)); for (LocalDateTime time : localDateTimes) { int dayOfMonth = time.getDayOfMonth(); int hour = time.getHour(); xList.add(dayOfMonth + "-" + hour); } VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel); LocalDateTime startTime = visualTimeDTO.getStartTime(); LocalDateTime endTime = visualTimeDTO.getEndTime(); String name = ((Workstation) this.workstationService.getById(workstationId)).getName(); List outputList = this.superAggregateOutputMapper.getOutputDataByWorkstationAndFactoryDate(workstationId, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME)); return this.outputWrapper.getWorkstationOutput(outputList, xList, name, 1); } @Override // org.springblade.modules.visual.service.IVisualOutputService public ChartSeriesDataVO getWorkstationDaysOutput(VisualSingleBaseVO visualBaseVO) { Long workstationId = visualBaseVO.getWorkStationId(); String timeLevel = visualBaseVO.getTimeLevel(); VisualTimeDTO timeSectionByLevel = VisualUtils.getTimeSectionDayByLevel(timeLevel); LocalDateTime startTime = timeSectionByLevel.getStartTime(); LocalDateTime endTime = timeSectionByLevel.getEndTime(); List xList = getLocalDate(Integer.valueOf(timeLevel)); String name = ((Workstation) this.workstationService.getById(workstationId)).getName(); List outputList = this.superAggregateOutputMapper.getOutputDataByWorkstationAndFactoryDate(workstationId, LocalDateTimeUtil.format(startTime, DateConstant.PATTERN_DATE_TIME), LocalDateTimeUtil.format(endTime, DateConstant.PATTERN_DATE_TIME)); return this.outputWrapper.getWorkstationOutput(outputList, xList, name, 2); } @Override // org.springblade.modules.visual.service.IVisualOutputService public ChartSeriesDataVO getShiftIndexOutput(WorkstationShiftOutput workstationShiftOutput) { WorkstationChartSeriesDataVO chartSeriesDataVO = new WorkstationChartSeriesDataVO(); List xList = new ArrayList<>(); List workStationIdList = workstationShiftOutput.getWorkStationIdList(); List arrayList = new ArrayList<>(); //ArrayList arrayList = new ArrayList(); List list = this.workstationService.list(Wrappers.lambdaQuery().in(Workstation::getId, workStationIdList)); /* List list = this.workstationService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> { return v0.getId(); }, workStationIdList));*/ if (Func.isNotEmpty(list)) { List seriesItems = new ArrayList<>(); //ArrayList arrayList2 = new ArrayList<>(); list.forEach(s -> { xList.add(s); String calendarCode = s.getCalendarCode(); if (Func.isNotBlank(calendarCode)) { CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(calendarCode, DateUtil.now()); if (timeSliceShift != null) { List superAggregateOutputList = this.superAggregateOutputMapper.getShiftOutput(Lists.newArrayList(new Long[]{s.getId()}), timeSliceShift.getShiftIndex(), Integer.valueOf(Func.toInt(timeSliceShift.getFactoryDate().replaceAll("-", "")))); long sum = FilterOffUtils.filterOffDay(superAggregateOutputList, OpenTypeEnums.OUT_PUT).stream().mapToLong((v0) -> { return v0.getOutput(); }).sum(); arrayList.add(Long.valueOf(sum)); return; } arrayList.add(0L); return; } arrayList.add(0L); }); SeriesItem seriesItem = new SeriesItem(); seriesItem.setName(VisualConstant.SHIFT_OUTPUT); seriesItem.setData(arrayList); seriesItems.add(seriesItem); chartSeriesDataVO.generateCategories(xList, 3); chartSeriesDataVO.setSeries(seriesItems); } return chartSeriesDataVO; } private List getLocalDate(Integer day) { List list = Lists.newArrayList(); LocalDate sevenDay = LocalDate.now(); for (int i = day.intValue(); i >= 0; i--) { LocalDate localDate = sevenDay.minusDays(i); list.add(LocalDateTimeUtil.format(localDate, DateConstant.PATTERN_DATE)); } return list; } private List getLocalDateTime(Integer day) { List list = Lists.newArrayList(); LocalDateTime sevenDay = LocalDateTime.now(); for (int i = day.intValue(); i >= 0; i--) { LocalDateTime localDateTime = sevenDay.minusHours(i); list.add(localDateTime); } return list; } @Override // org.springblade.modules.visual.service.IVisualOutputService public ChartSeriesDataVO getCountPulseOutput(final WorkstationCountVisualQueryVO visualQueryVO) { DynamicCountDateAggregateDTO visualCountDateAggregateDTO; WorkstationWcsUsage workstationWcsUsage = (WorkstationWcsUsage) this.workstationWcsUsageService.getOne(Lambda.eq((v0) -> { return v0.getUsageCode(); }, visualQueryVO.getUsageCode())); if (workstationWcsUsage == null) { return null; } if (visualQueryVO.getPolicy().equals(VisualUsagePolicyEnum.SHIFT)) { visualCountDateAggregateDTO = this.dynamicCollectService.getShiftOutput(visualQueryVO.getWorkStationIdList(), workstationWcsUsage); } else { visualCountDateAggregateDTO = this.dynamicCollectService.getOutputDataByWorkstationAndFactoryDate(visualQueryVO.getWorkStationIdList(), visualQueryVO.getTimeLevel(), visualQueryVO.getPolicy(), workstationWcsUsage); } return visualQueryVO.getPolicy().wrapper(visualCountDateAggregateDTO); } }