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<Long> workStationIdList = visualBaseVO.getWorkStationIdList();
|
String timeLevel = visualBaseVO.getTimeLevel();
|
VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
|
List<Workstation> workstations = this.workstationService.workStationList(workStationIdList);
|
List<SuperAggregateState> 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<Long> workStationIdList = timeStatusVO.getWorkStationIdList();
|
String timeLevel = timeStatusVO.getTimeLevel();
|
Integer top = timeStatusVO.getTop();
|
VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
|
List<StatusTimeTopVO> statusTimeByWcs = this.superAggregateStateService.getStatusTimeByWcs(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime(), status, top);
|
return this.wrapper.deviceStatusDuration(statusTimeByWcs, status, top);
|
}
|
|
|
public ChartNameValueDataVO getStatusDistribution(VisualBaseVO vo) {
|
List<Long> workStationIdList = vo.getWorkStationIdList();
|
String timeLevel = vo.getTimeLevel();
|
VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
|
List<SuperAggregateState> data = this.superAggregateStateService.getStatusByTimeSection(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime());
|
return this.wrapper.entityToChartName(data);
|
}
|
|
|
public ChartNameValueDataVO getOeeAnalysis(VisualBaseVO vo) {
|
List<Long> workStationIdList = vo.getWorkStationIdList();
|
String timeLevel = vo.getTimeLevel();
|
VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
|
List<SuperAggregateState> data = this.superAggregateStateService.getOeeAnalysis(workStationIdList, visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime());
|
return this.wrapper.entityToOee(data);
|
}
|
|
/*
|
public ChartDataTableVO getWorkstationRealStatus(VisualBaseVO visualBaseVO) {
|
List<Long> workStationList = visualBaseVO.getWorkStationIdList();
|
Map<String, Object> header = new LinkedHashMap<>();
|
int[] index = {0};
|
if (workStationList == null) {
|
workStationList = Collections.EMPTY_LIST;
|
}
|
List<ICard> 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<RealTimeStatusVO> 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<RealTimeStatusVO> 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<Long> workStationList = vo.getWorkStationIdList();
|
List<ICard> voList = new ArrayList<>();
|
workStationList.stream().map(item -> {
|
return this.workstationService.getDetail(item);
|
}).map(item2 -> {
|
List<RealTimeStatusVO> 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<WorkstationAlarmDTO> 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<List<WorkstationAlarmDTO>>() { // from class: org.springblade.modules.visual.service.impl.VisualStatusServiceImpl.1
|
}, new Feature[0]);
|
}
|
List<WorkstationAlarmDTO> 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<Long> workStationIdList = vo.getWorkStationIdList();
|
List<Workstation> 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<SuperAggregateState> 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<Workstation> 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<SuperAggregateState> 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<Long> workStationIdList = vo.getWorkStationIdList();
|
if (Func.isEmpty(workStationIdList)) {
|
return new ChartNameValueDataVO().addValue(MdcConstant.GROUP_RUNNING, "");
|
}
|
List<Workstation> 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<SuperAggregateState> shiftStatusData = this.superAggregateStateService.getShiftStatusData(workStationIdList, factoryDate, shiftIndex);
|
Integer code = DefaultWcsEnum.RUNNING.getCode();
|
List<SuperAggregateState> 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<Long> workStationIdList = visualBaseVO.getWorkStationIdList();
|
List<Workstation> workstations = this.workstationService.workStationList(workStationIdList);
|
LocalDateTime now = LocalDateTime.now();
|
List<SuperAggregateState> superAggregateStateList = this.superAggregateStateService.getStatusByCondition(workStationIdList, LocalDateTimeUtils.getDayStart(now), LocalDateTimeUtils.getDayEnd(now));
|
return this.wrapper.entityVO(workstations, superAggregateStateList);
|
}
|
|
|
public ChartNameValueDataVO getStatusToDayDistribution(VisualBaseVO vo) {
|
List<Long> workStationIdList = vo.getWorkStationIdList();
|
LocalDate now = LocalDate.now();
|
LocalDateTime startTime = LocalDateTime.of(now, LocalTime.MIN);
|
LocalDateTime endTime = LocalDateTime.of(now, LocalTime.MAX);
|
List<SuperAggregateState> data = this.superAggregateStateService.getStatusByCondition(workStationIdList, startTime, endTime);
|
return this.wrapper.entityToChartName(data);
|
}
|
|
|
public ChartNameValueDataVO getStatusShiftDistribution(VisualBaseVO vo) {
|
List<Long> workStationIdList = vo.getWorkStationIdList();
|
List<Workstation> workstations = this.workstationService.listByIds(workStationIdList);
|
List<GlobalWcs> 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<SuperAggregateState> states = Lists.newArrayList();
|
Map<String, List<Workstation>> 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<Long> 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<SuperAggregateState> 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<Long> workStationIdList = visualBaseVO.getWorkStationIdList();
|
List<SuperAggregateState> stateList = new ArrayList<>();
|
List<Workstation> workstationList = this.workstationService.list(Wrappers.<Workstation>lambdaQuery().in(Workstation::getId, workStationIdList));
|
/*
|
List<Workstation> workstationList = this.workstationService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
|
return v0.getId();
|
}, workStationIdList));*/
|
if (Func.isNotEmpty(workstationList)) {
|
Map<String, List<Workstation>> calendarCodeMap = workstationList.stream().collect(Collectors.groupingBy((v0) -> {
|
return v0.getCalendarCode();
|
}));
|
calendarCodeMap.forEach((k, v) -> {
|
List<Long> 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<SuperAggregateState> superAggregateOutputList = this.superAggregateStateMapper.getEquipmentStatusRecord(workstationIds, timeSliceShift.getShiftIndex(), Integer.valueOf(Func.toInt(timeSliceShift.getFactoryDate().replaceAll("-", ""))));
|
if (Func.isNotEmpty(superAggregateOutputList)) {
|
stateList.addAll(superAggregateOutputList);
|
}
|
}
|
});
|
}
|
List<SuperAggregateState> 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<Workstation> workstations = this.workstationService.workStationList(vo.getWorkStationIdList());
|
List<SuperAggregateState> statusByCondition = this.superAggregateStateService.getStatusByCondition(vo.getWorkStationIdList(), dayStart, dayEnd);
|
List<SuperAggregateState> 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<SuperAggregateState> statusByCondition = this.superAggregateStateService.getStatusByCondition(vo.getWorkStationIdList(), dayStart, dayEnd);
|
List<SuperAggregateState> 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<Long> workStationIdList = timeStatusVO.getWorkStationIdList();
|
if (Func.isEmpty(workStationIdList)) {
|
return new ChartSeriesDataVO();
|
}
|
List<Workstation> workstations = this.workstationService.listByIds(workStationIdList);
|
String timeLevel = timeStatusVO.getTimeLevel();
|
VisualTimeDTO visualTimeDTO = VisualUtils.getTimeSectionByLevel(timeLevel);
|
List<SuperAggregateState> statusByCondition = this.superAggregateStateService.getStatusByTimeSection(timeStatusVO.getWorkStationIdList(), visualTimeDTO.getStartTime(), visualTimeDTO.getEndTime());
|
List<SuperAggregateState> 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<Long> 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<SuperAggregateState> data = this.superAggregateStateService.getCurrMonthState(ids, Integer.valueOf(monthValue));
|
return this.wrapper.entityToMonthOee(FilterOffUtils.filterOffDay(data, OpenTypeEnums.OEE));
|
}
|
|
|
public ChartNameValueDataVO getCurrMonthRunning(VisualBaseVO vo) {
|
List<Long> 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<SuperAggregateState> data = this.superAggregateStateService.getCurrMonthState(ids, Integer.valueOf(monthValue));
|
return this.wrapper.entityToMonthRunning(data);
|
}
|
|
|
public ChartSeriesDataVO getCurrMonthAlarm(VisualBaseVO vo) {
|
List<Long> ids = vo.getWorkStationIdList();
|
if (Func.isEmpty(ids)) {
|
ChartSeriesDataVO res = new ChartSeriesDataVO();
|
res.setCategories(Lists.newArrayList());
|
res.setSeries(Lists.newArrayList());
|
return res;
|
}
|
List<Workstation> workstations = this.workstationService.listByIds(ids);
|
if (Func.isEmpty(workstations)) {
|
ChartSeriesDataVO res2 = new ChartSeriesDataVO();
|
res2.setCategories(Lists.newArrayList());
|
res2.setSeries(Lists.newArrayList());
|
return res2;
|
}
|
Map<Long, Workstation> workstationMap = (Map) workstations.stream().collect(Collectors.toMap((v0) -> {
|
return v0.getId();
|
}, v -> {
|
return v;
|
}));
|
List<Long> workIds = workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
LocalDate now = LocalDate.now();
|
int monthValue = now.getMonthValue();
|
List<SuperAggregateState> 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<Workstation> workstations, Map<Long, Workstation> workstationMap, List<SuperAggregateState> data, String name) {
|
Map<Long, Long> 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<Map.Entry<Long, Long>> 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<Workstation> codes = Lists.newArrayList();
|
SeriesItem<String> item = new SeriesItem<>();
|
List<String> xData = Lists.newArrayList();
|
for (Map.Entry<Long, Long> 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<Long> 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<Workstation> workstations = this.workstationService.listByIds(ids);
|
if (Func.isEmpty(workstations)) {
|
ChartSeriesDataVO res2 = new ChartSeriesDataVO();
|
res2.setCategories(Lists.newArrayList());
|
res2.setSeries(Lists.newArrayList());
|
return res2;
|
}
|
List<Long> workIds = workstations.stream().map((v0) -> {
|
return v0.getId();
|
}).collect(Collectors.toList());
|
List<SuperAggregateState> data = this.superAggregateStateService.getCurrWeekAlarmState(workIds, week, DefaultWcsEnum.ALARM.getCode());
|
List<SuperAggregateState> data2 = FilterOffUtils.filterOffDay(data, OpenTypeEnums.TIME_USED_ANALYSIS);
|
Map<Long, Workstation> 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<Long, String> settings = this.workstationWcsService.list(Lambda.<WorkstationWcs>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<Long, String> 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<String, Long> 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;
|
}
|
}
|