package com.qianwen.smartman.modules.mdc.service.impl; import cn.hutool.core.lang.Tuple; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.util.ArrayList; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.qianwen.smartman.common.cache.cps.TimeSliceCache; import com.qianwen.smartman.common.cache.cps.WorkstationCache; import com.qianwen.smartman.common.constant.DateConstant; import com.qianwen.smartman.common.constant.ExcelConstant; import com.qianwen.smartman.common.constant.MdcConstant; import com.qianwen.smartman.common.enums.WcsDataTypeEnums; import com.qianwen.smartman.common.utils.ListUtils; import com.qianwen.smartman.common.utils.MessageUtils; import com.qianwen.core.log.exception.ServiceException; import com.qianwen.core.mp.support.Query; import com.qianwen.core.oss.model.BladeFile; import com.qianwen.core.tool.jackson.JsonUtil; import com.qianwen.core.tool.utils.DateUtil; import com.qianwen.core.tool.utils.Func; import com.qianwen.smartman.modules.cps.dto.CalendarShiftDTO; import com.qianwen.smartman.modules.cps.dto.CalendarShiftTimeSlicesDTO; import com.qianwen.smartman.modules.cps.dto.WorkstationWcsDmpDTO; import com.qianwen.smartman.modules.cps.entity.GlobalWcs; import com.qianwen.smartman.modules.cps.entity.Workstation; import com.qianwen.smartman.modules.cps.service.ICalendarService; import com.qianwen.smartman.modules.cps.service.IWorkstationService; import com.qianwen.smartman.modules.cps.utils.ThrowFun; import com.qianwen.smartman.modules.cps.vo.ShiftTimeDetailVO; import com.qianwen.smartman.modules.mdc.dto.GroupWorkDTO; import com.qianwen.smartman.modules.mdc.dto.NewParamDTO; import com.qianwen.smartman.modules.mdc.dto.ParamDTO; import com.qianwen.smartman.modules.mdc.dto.ProParamResDTO; import com.qianwen.smartman.modules.mdc.dto.ProcessParameterRealVO; import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO; import com.qianwen.smartman.modules.mdc.dto.ProcessWcsDTO; import com.qianwen.smartman.modules.mdc.dto.StatusDTO; import com.qianwen.smartman.modules.mdc.enums.ProcessParamEnum; import com.qianwen.smartman.modules.mdc.mapper.SuperCollectJsonMapper; import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper; import com.qianwen.smartman.modules.mdc.service.IProcessParameterService; import com.qianwen.smartman.modules.mdc.utils.ExcelStrategyUtil; import com.qianwen.smartman.modules.mdc.vo.AllShiftTimeDetail; import com.qianwen.smartman.modules.mdc.vo.CollectParamResVO; import com.qianwen.smartman.modules.mdc.vo.CollectParamSearchVO; import com.qianwen.smartman.modules.mdc.vo.ProParamSheetVO; import com.qianwen.smartman.modules.mdc.vo.ProcessParameterItemSearchVO; import com.qianwen.smartman.modules.mdc.vo.ProcessParameterResVO; import com.qianwen.smartman.modules.mdc.vo.ProcessParameterSearchVO; import com.qianwen.smartman.modules.mdc.vo.ShiftTimeVO; import com.qianwen.smartman.modules.mdc.vo.WorkstationShiftSearchVO; import com.qianwen.smartman.modules.mdc.vo.excel.ProcessParamExcelVO; import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; @Service /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/mdc/service/impl/ProcessParameterServiceImpl.class */ public class ProcessParameterServiceImpl implements IProcessParameterService { private static final Logger log = LoggerFactory.getLogger(ProcessParameterServiceImpl.class); private final SuperCollectJsonMapper collectJsonMapper; private final IWorkstationService workstationService; private final OssBuilder ossBuilder; private final SuperProcessParameterMapper parameterMapper; private final ICalendarService calendarService; public ProcessParameterServiceImpl(final SuperCollectJsonMapper collectJsonMapper, final IWorkstationService workstationService, final OssBuilder ossBuilder, final SuperProcessParameterMapper parameterMapper, final ICalendarService calendarService) { this.collectJsonMapper = collectJsonMapper; this.workstationService = workstationService; this.ossBuilder = ossBuilder; this.parameterMapper = parameterMapper; this.calendarService = calendarService; } @Override // org.springblade.modules.mdc.service.IProcessParameterService public ProcessParameterResVO queryProcessParameterChart(ProcessParameterSearchVO vo) { ProcessParamEnum methodEnum = vo.getMethodEnum(); switch (methodEnum) { case HOUR: return buildProcessDate(vo); case SHIFT: return buildProcessShift(vo); default: return new ProcessParameterResVO(); } } @Override // org.springblade.modules.mdc.service.IProcessParameterService public List listGlobalWcs() { return WorkstationCache.getDefaultWcs(); } @Override // org.springblade.modules.mdc.service.IProcessParameterService public IPage pageProcessParameter(Query query, ProcessParameterItemSearchVO vo) { int size = query.getSize().intValue(); int current = query.getCurrent().intValue(); long startTime = vo.getStartTime().getTime(); long endTime = vo.getEndTime().getTime(); String workstationId = vo.getWorkstationId(); Integer flag = vo.getFlag(); String item = vo.getItem(); long total = Optional.ofNullable(this.parameterMapper.countProcessParameter(item, Long.valueOf(startTime), Long.valueOf(endTime), workstationId)).orElse(0L).longValue(); Page page = new Page<>(current, size, total); if (total == 0) { return page; } List res = this.parameterMapper.pageProcessParameter(Integer.valueOf(size), Integer.valueOf((current - 1) * size), Long.valueOf(startTime), Long.valueOf(endTime), item, workstationId); Map map = getWcsMap(); List collect = res.stream().map(c -> { String value; if (MdcConstant.FLAG.equals(flag)) { value = (String) map.get(c.getValue()); } else { value = c.getValue(); } return ProcessParameterRealVO.builder().time(DateUtil.format(c.getTime(), "yyyy-MM-dd HH:mm:ss.SSS")).collectItem(c.getCollectItem()).value(value).build(); }).collect(Collectors.toList()); page.setRecords(collect); return page; } @Override // org.springblade.modules.mdc.service.IProcessParameterService public List processParam(String workstationId) { List vos =WorkstationCache.getWorkstationWcsList(workstationId).stream().filter((v0) -> { return v0.getProcessParameter(); }).collect(Collectors.toList()); if (Func.isEmpty(vos)) { return Lists.newArrayList(); } return vos; } @Override // org.springblade.modules.mdc.service.IProcessParameterService public ProParamSheetVO queryProcessParameterSheet(ProcessParameterSearchVO vo, Boolean isFilterProcessParameter) { ProcessParamEnum methodEnum = vo.getMethodEnum(); switch (methodEnum) { case HOUR: return buildProcessHourSheet(vo, isFilterProcessParameter); case SHIFT: return buildProcessShiftSheet(vo, isFilterProcessParameter); default: return new ProParamSheetVO(); } } @Override // org.springblade.modules.mdc.service.IProcessParameterService public BladeFile exportProcessParam(ProcessParamExcelVO vo) { try { return exportByHour(vo); } catch (Exception e) { log.error("exportProcessParam异常",e); throw new RuntimeException(e); } } @Override // org.springblade.modules.mdc.service.IProcessParameterService public ShiftTimeVO getShiftTime(ProcessParameterSearchVO vo) { String workstationId = vo.getWorkstationId(); LocalDate queryTime = vo.getQueryTime(); Integer shift = vo.getShift(); Workstation workstation = (Workstation) this.workstationService.getById(Long.valueOf(Func.toLong(workstationId))); return (ShiftTimeVO) Optional.ofNullable(workstation).map(w -> { CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(workstation.getCalendarCode(), queryTime, shift); return (ShiftTimeVO) Optional.ofNullable(timeSliceShift).map(time -> { return ShiftTimeVO.builder().startTime(time.getStartTime()).endTime(time.getEndTime()).build(); }).orElse(new ShiftTimeVO()); }).orElse(new ShiftTimeVO()); } @Override // org.springblade.modules.mdc.service.IProcessParameterService public CollectParamResVO queryProcessParameterOneChart(CollectParamSearchVO vo) { Date startTime = vo.getStartTime(); Date endTime = vo.getEndTime(); if (Func.isNull(startTime) || Func.isNull(endTime)) { throw new ServiceException(MessageUtils.message("mdc.process.time.not.null", new Object[0])); } Date now = DateUtil.now(); if (startTime.after(now)) { return new CollectParamResVO<>(); } String workstationId = vo.getWorkstationId(); List processParameterList = getProcessParameterList(startTime, endTime, workstationId, vo.getDmpDTO()); return getCollectParamResVO(vo.getDmpDTO(), processParameterList); } private CollectParamResVO getCollectParamResVO(WorkstationWcsDmpDTO dmpDTO, List processParameterList) { if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) { Map colorMap = Maps.newHashMap(); Map nameMap = Maps.newHashMap(); Set codes = Sets.newHashSet(); buildWcsMap(colorMap, nameMap, codes); List list = processParameterList.stream().filter(c -> codes.contains(c.getValue())).map(param -> StatusDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param.getRealTime().longValue()))).name((String)nameMap.get(param.getValue())).color((String)colorMap.get(param.getValue())).value(param.getValue()).build()).collect(Collectors.toList()); /* List collect = processParameterList.stream().filter(c -> { return codes.contains(c.getValue()); }).map(param -> { return StatusDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param.getRealTime().longValue()))).name((String) nameMap.get(param.getValue())).color((String) colorMap.get(param.getValue())).value(param.getValue()).build(); }).collect(Collectors.toList());*/ return CollectParamResVO.builder() .collectItem(dmpDTO.getDescription()) .collectRealItem(dmpDTO.getName()) .data(list) .build(); //return CollectParamResVO.builder().collectItem(dmpDTO.getDescription()).collectRealItem(dmpDTO.getName()).data(list).build(); } List collect = processParameterList.stream().map(param -> ParamDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param.getRealTime().longValue()))).value(param.getValue()).build()).collect(Collectors.toList()); return CollectParamResVO.builder() .collectItem(dmpDTO.getDescription()) .collectRealItem(dmpDTO.getName()) .data(collect) .build(); /* List collect2 = (List) processParameterList.stream().map(param2 -> { return ParamDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param2.getRealTime().longValue()))).value(param2.getValue()).build(); }).collect(Collectors.toList()); return CollectParamResVO.builder().collectItem(dmpDTO.getDescription()).collectRealItem(dmpDTO.getName()).data(collect2).build(); */ } private void buildWcsMap(Map colorMap, Map nameMap, Set codes) { List globalWcsList = listGlobalWcs(); for (GlobalWcs globalWcs : globalWcsList) { colorMap.put(globalWcs.getCode(), globalWcs.getColor()); nameMap.put(globalWcs.getCode(), globalWcs.getName()); codes.add(globalWcs.getCode()); } } private List getProcessParameterList(Date startTime, Date endTime, String workstationId, WorkstationWcsDmpDTO dmpDTO) { ProcessParameterVO firstStatue = oldFirstStatue(startTime, dmpDTO.getName(), workstationId); ProcessParameterVO endStatue = oldLastStatue(endTime, dmpDTO.getName(), workstationId); List processParameterList = oldOneCollectList(startTime, endTime, dmpDTO.getName(), workstationId); if (Func.isNotEmpty(processParameterList)) { if (Func.notNull(firstStatue) && !firstStatue.getRealTime().equals(Long.valueOf(startTime.getTime()))) { firstStatue.setRealTime(Long.valueOf(startTime.getTime())); processParameterList.add(0, firstStatue); } if (Func.notNull(endStatue) && !endStatue.getRealTime().equals(Long.valueOf(endTime.getTime()))) { endStatue.setRealTime(Long.valueOf(Math.min(DateUtil.now().getTime(), endTime.getTime()))); processParameterList.add(endStatue); } } else { if (Func.notNull(firstStatue)) { firstStatue.setRealTime(Long.valueOf(startTime.getTime())); processParameterList.add(firstStatue); } if (Func.notNull(endStatue)) { endStatue.setRealTime(Long.valueOf(Math.min(DateUtil.now().getTime(), endTime.getTime()))); processParameterList.add(endStatue); } } return processParameterList; } @Override // org.springblade.modules.mdc.service.IProcessParameterService public List getAllShiftTime(WorkstationShiftSearchVO vo) { String workstationId = vo.getWorkstationId(); List dates = vo.getDates(); Workstation workstation = (Workstation) this.workstationService.getById(Long.valueOf(Func.toLong(workstationId))); LocalDate firstDays = ((LocalDate) ListUtils.getFirst(dates)).minusDays(1L); LocalDate lastDays = ((LocalDate) ListUtils.getLast(dates)).plusDays(1L); dates.add(firstDays); dates.add(lastDays); List shiftDetailDates = this.calendarService.getShiftDetailDates(workstation.getCalendarCode(), dates.stream().distinct().collect(Collectors.toList())); if (Func.isEmpty(shiftDetailDates)) { return Lists.newArrayList(); } return shiftDetailDates.stream().map(shiftTime -> { LocalDate date = shiftTime.getCalendarDate(); LocalDateTime startTime = LocalDateTime.of(date, LocalTime.MIN).plusMinutes(shiftTime.getShiftStartTime().intValue()); LocalDateTime endTime = LocalDateTime.of(date, LocalTime.MIN).plusMinutes(shiftTime.getShiftEndTime().intValue()); String indexName = shiftTime.getIndexName(); if (Func.isBlank(indexName)) { indexName = MessageUtils.message("calendar.page.shift.model.shift", new Object[0]) + shiftTime.getShiftIndex(); } return AllShiftTimeDetail.builder().color(shiftTime.getColour()).shiftIndex(shiftTime.getShiftIndex()).shiftName(indexName).startTime(DateUtil.toDate(startTime)).endTime(DateUtil.toDate(endTime)).build(); }).sorted(Comparator.comparing((v0) -> { return v0.getStartTime(); })).collect(Collectors.toList()); } private ProcessParameterResVO buildProcessDate(ProcessParameterSearchVO vo) { Date startTime = vo.getStartTime(); Date endTime = vo.getEndTime(); if (Func.isNull(startTime) || Func.isNull(endTime)) { throw new ServiceException(MessageUtils.message("mdc.process.time.not.null", new Object[0])); } String workstationId = vo.getWorkstationId(); List vos = WorkstationCache.getWorkstationWcsList(workstationId).stream().filter((v0) -> { return v0.getProcessParameter(); }).collect(Collectors.toList()); if (Func.isEmpty(vos)) { return new ProcessParameterResVO(); } Map collectItemMap = vos.stream().collect(Collectors.toMap((v0) -> { return v0.getName(); }, v -> { return v; })); log.info("工位的采集项:{}", vos); WorkstationWcsDmpDTO wcs = WorkstationCache.getDmpStatus(workstationId); List collectItems = vos.stream().map((v0) -> { return v0.getName(); }).collect(Collectors.toList()); List dtoList = oldProcessParameterList(startTime, endTime, collectItems, workstationId); if (Func.isEmpty(dtoList)) { return new ProcessParameterResVO(); } return entityVO(dtoList, wcs, collectItemMap); } private ProcessParameterResVO buildProcessShift(ProcessParameterSearchVO vo) { Integer shift = vo.getShift(); if (Func.isNull(shift)) { throw new ServiceException(MessageUtils.message("mdc.process.shift.not.null", new Object[0])); } LocalDate queryTime = vo.getQueryTime(); if (Func.isNull(queryTime)) { throw new ServiceException(MessageUtils.message("mdc.process.time.not.null", new Object[0])); } String workstationId = vo.getWorkstationId(); Workstation workstation = (Workstation) this.workstationService.getById(workstationId); if (Func.isNull(workstation)) { return new ProcessParameterResVO(); } List vos = WorkstationCache.getWorkstationWcsList(workstationId).stream().filter((v0) -> { return v0.getProcessParameter(); }).collect(Collectors.toList()); if (Func.isEmpty(vos)) { return new ProcessParameterResVO(); } Map collectItemMap = vos.stream().collect(Collectors.toMap((v0) -> { return v0.getName(); }, v -> { return v; })); log.info("工位的采集项:{}", vos); WorkstationWcsDmpDTO wcs = WorkstationCache.getDmpStatus(workstationId); CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(workstation.getCalendarCode(), queryTime, shift); return (ProcessParameterResVO) Optional.ofNullable(timeSliceShift).map(time -> { Date startTime = time.getStartTime(); Date endTime = time.getEndTime(); List collectItems = vos.stream().map((v0) -> { return v0.getName(); }).collect(Collectors.toList()); List parameterList = oldProcessParameterList(startTime, endTime, collectItems, workstationId); if (Func.isEmpty(parameterList)) { return new ProcessParameterResVO(); } return entityVO(parameterList, wcs, collectItemMap); }).orElse(new ProcessParameterResVO()); } private ProParamSheetVO buildProcessHourSheet(ProcessParameterSearchVO vo, Boolean isFilterProcessParameter) { Date startTime = vo.getStartTime(); Date endTime = vo.getEndTime(); if (Func.isNull(startTime) || Func.isNull(endTime)) { throw new ServiceException(MessageUtils.message("mdc.process.time.not.null", new Object[0])); } String workstationId = vo.getWorkstationId(); Workstation workstation = (Workstation) this.workstationService.getById(workstationId); if (Func.isNull(workstation)) { return new ProParamSheetVO(); } List vos = getWorkstationWcsDmpDTO(isFilterProcessParameter, workstationId); if (isFilterProcessParameter.booleanValue()) { vos = vos.stream().filter((v0) -> { return v0.getProcessParameter(); }).collect(Collectors.toList()); } if (Func.isEmpty(vos)) { return new ProParamSheetVO(); } WorkstationWcsDmpDTO wcs = WorkstationCache.getDmpStatus(workstationId); List dtoList = processParameterList(startTime, endTime, workstationId); if (Func.isEmpty(dtoList)) { return new ProParamSheetVO(); } return buildSheetVO(vos, dtoList, wcs, getWcsMap()); } private ProParamSheetVO buildProcessShiftSheet(ProcessParameterSearchVO vo, Boolean isFilterProcessParameter) { Integer shift = vo.getShift(); LocalDate queryTime = vo.getQueryTime(); if (Func.isEmpty(queryTime)) { throw new ServiceException(MessageUtils.message("mdc.process.time.not.null", new Object[0])); } String workstationId = vo.getWorkstationId(); Workstation workstation = (Workstation) this.workstationService.getById(workstationId); if (Func.isEmpty(workstation)) { return new ProParamSheetVO(); } CalendarShiftTimeSlicesDTO timeSliceShift = TimeSliceCache.getTimeSliceShift(workstation.getCalendarCode(), queryTime, shift); if (Func.isEmpty(timeSliceShift)) { return new ProParamSheetVO(); } List vos = getWorkstationWcsDmpDTO(isFilterProcessParameter, workstationId); if (Func.isEmpty(vos)) { return new ProParamSheetVO(); } WorkstationWcsDmpDTO wcs = WorkstationCache.getDmpStatus(workstationId); List dtoList = processParameterList(timeSliceShift.getStartTime(), timeSliceShift.getEndTime(), workstationId); if (Func.isEmpty(dtoList)) { return new ProParamSheetVO(); } return buildSheetVO(vos, dtoList, wcs, getWcsMap()); } private BladeFile exportByHour(ProcessParamExcelVO vo) throws Exception { Date startTime = vo.getStartTime(); Date endTime = vo.getEndTime(); ThrowFun.isTrue(Func.isEmpty(startTime) || Func.isEmpty(endTime)).throwMessage(MessageUtils.message("mdc.process.time.not.null", new Object[0])); List collectItem = vo.getCollectItem(); List> head = buildExcelHeadByHour(collectItem); Long workstationId = vo.getWorkstationId(); List> content = buildExcelContentByHour(workstationId, collectItem, startTime, endTime); String fileName = String.format("%s-%s.xlsx", ExcelConstant.PROCESS_PARAMETER, DateUtil.time()); MultipartFile multipartFile = ExcelStrategyUtil.customerStyleExport(fileName, ExcelConstant.SHEET, head, content); return this.ossBuilder.tempTemplate().putFile(multipartFile.getOriginalFilename(), multipartFile); } private List> buildExcelContentByHour(Long workstationId, List collectItem, Date startTime, Date endTime) { Workstation workstation = (Workstation) this.workstationService.getById(workstationId); Map groupWorkMap = this.workstationService.queryGroupWorkStation(Lists.newArrayList(new Long[]{workstation.getId()})); GroupWorkDTO groupWorkDTO = groupWorkMap.getOrDefault(workstation.getId(), new GroupWorkDTO()); String groupName = groupWorkDTO.getName(); String id = String.valueOf(workstationId); WorkstationWcsDmpDTO wcs = WorkstationCache.getDmpStatus(id); List timeShiftAll = this.calendarService.getTimeShiftAll(workstation.getCalendarCode(), startTime, endTime); log.info("班次信息: {}", timeShiftAll); List parameterList = processParameterList(startTime, endTime, id); if (Func.isEmpty(parameterList)) { return Lists.newArrayList(); } return buildExcelContentByHour(collectItem, parameterList, wcs, workstation, groupName, timeShiftAll); } private List> buildExcelContentByHour(List collectItem, List parameterList, WorkstationWcsDmpDTO wcs, Workstation workstation, String groupName, List timeShiftAll) { List times = timeShiftAll.stream().map(calendarShiftDTO -> { Date startTime = DateUtil.plusMinutes(DateUtil.parse(calendarShiftDTO.getCalendarDate(), DateConstant.PATTERN_DATE), calendarShiftDTO.getShiftStartTime().intValue()); Date endTime = DateUtil.plusMinutes(DateUtil.parse(calendarShiftDTO.getCalendarDate(), DateConstant.PATTERN_DATE), calendarShiftDTO.getShiftEndTime().intValue()); long start = startTime.getTime(); long end = endTime.getTime(); String name = calendarShiftDTO.getIndexName(); return new Tuple(new Object[]{Long.valueOf(start), Long.valueOf(end), Func.isNotBlank(name) ? name : MessageUtils.message("calendar.page.shift.model.shift", new Object[0]) + calendarShiftDTO.getShiftIndex()}); }).collect(Collectors.toList()); List> res = Lists.newArrayList(); String code = workstation.getCode(); String name = workstation.getName(); Map wcsMap = getWcsMap(); parameterList.forEach(dto -> { Long time = dto.getTs(); Map valueMap = JsonUtil.toMap(dto.getV()); ArrayList newArrayList = Lists.newArrayList(); newArrayList.add(groupName); newArrayList.add(code); newArrayList.add(name); String shiftName = getShiftName(time.longValue(), times); newArrayList.add(shiftName); String firstContent = DateUtil.format(DateUtil.fromMilliseconds(time.longValue()), "yyyy-MM-dd HH:mm:ss.SSS"); newArrayList.add(firstContent); buildContent(collectItem, valueMap, wcs, wcsMap, newArrayList); res.add(newArrayList); }); return res; } private List> buildExcelHeadByHour(List collectItem) { List> head = Lists.newArrayList(); head.add(Lists.newArrayList(new String[]{MessageUtils.message("excel.import.process.parameter.group", new Object[0])})); head.add(Lists.newArrayList(new String[]{MessageUtils.message("excel.import.process.parameter.code", new Object[0])})); head.add(Lists.newArrayList(new String[]{MessageUtils.message("excel.import.process.parameter.name", new Object[0])})); head.add(Lists.newArrayList(new String[]{MessageUtils.message("calendar.page.shift.model.shift", new Object[0])})); head.add(Lists.newArrayList(new String[]{MessageUtils.message("calendar.page.shift.model.time", new Object[0])})); for (WorkstationWcsDmpDTO dto : collectItem) { head.add(Lists.newArrayList(new String[]{dto.getDescription()})); } return head; } private List processParameterList(Date startTime, Date endTime, String workstationId) { return this.collectJsonMapper.queryProcessParameter(workstationId, Long.valueOf(startTime.getTime()), Long.valueOf(endTime.getTime())); } private List oldProcessParameterList(Date startTime, Date endTime, List collectItems, String workstationId) { return this.parameterMapper.queryProcessParameter(workstationId, collectItems, Long.valueOf(startTime.getTime()), Long.valueOf(endTime.getTime())); } private ProcessParameterVO oldFirstStatue(Date startTime, String item, String workstationId) { ProcessParameterVO vo = this.parameterMapper.oldFirstStatue(workstationId, item, Long.valueOf(startTime.getTime())); if (Func.notNull(vo)) { vo.setCollectItem(item); } return vo; } private ProcessParameterVO oldLastStatue(Date endTime, String item, String workstationId) { ProcessParameterVO vo = this.parameterMapper.oldLastStatue(workstationId, item, Long.valueOf(endTime.getTime())); if (Func.notNull(vo)) { vo.setCollectItem(item); } return vo; } private List oldOneCollectList(Date startTime, Date endTime, String item, String workstationId) { return this.parameterMapper.oldOneCollectList(workstationId, item, Long.valueOf(startTime.getTime()), Long.valueOf(endTime.getTime())); } private ProcessParameterResVO entityVO(List dtoList, WorkstationWcsDmpDTO wcs, Map collectItemMap) { List globalWcsList = listGlobalWcs(); Map colorMap = new HashMap<>(globalWcsList.size()); Map nameMap = new HashMap<>(globalWcsList.size()); Set codes = Sets.newHashSet(); for (GlobalWcs globalWcs : globalWcsList) { colorMap.put(globalWcs.getCode(), globalWcs.getColor()); nameMap.put(globalWcs.getCode(), globalWcs.getName()); codes.add(globalWcs.getCode()); } Map> map = dtoList.stream().collect(Collectors.groupingBy((v0) -> { return v0.getCollectItem(); })); List res = Lists.newArrayList(); map.forEach((k, v) -> { ProParamResDTO dto; if (Func.isNotEmpty(wcs) && wcs.getName().equals(k)) { List collect = v.stream().filter(c -> { return codes.contains(c.getValue()); }).map(c2 -> { return ProcessWcsDTO.builder().realTime(c2.getRealTime()).time(DateUtil.format(c2.getTime(), "yyyy-MM-dd HH:mm:ss.SSS")).name((String) nameMap.get(c2.getValue())).value(c2.getValue()).color((String) colorMap.get(c2.getValue())).build(); }).sorted(Comparator.comparing((v0) -> { return v0.getTime(); })).collect(Collectors.toList()); dto = ProParamResDTO.builder().collectRealItem(k).collectItem(wcs.getDescription()).dataType(wcs.getWcsDataType()).statusData(collect).build(); } else { List collect2 = v.stream().map(c3 -> { return ProcessParameterRealVO.builder().realTime(c3.getRealTime()).time(DateUtil.format(c3.getTime(), "yyyy-MM-dd HH:mm:ss.SSS")).collectItem(c3.getCollectItem()).value(c3.getValue()).build(); }).sorted(Comparator.comparing((v0) -> { return v0.getTime(); })).collect(Collectors.toList()); dto = ProParamResDTO.builder().dataType(((WorkstationWcsDmpDTO) collectItemMap.get(k)).getDataType()).collectRealItem(k).collectItem(((WorkstationWcsDmpDTO) collectItemMap.get(k)).getDescription()).data(collect2).build(); } res.add(dto); }); ProcessParameterResVO process = new ProcessParameterResVO(); process.setRes(res); return process; } private String getShiftName(long time, List times) { for (Tuple tuple : times) { long start = ((Long) tuple.get(0)).longValue(); long end = ((Long) tuple.get(1)).longValue(); if (start <= time && time <= end) { return (String) tuple.get(2); } } return ""; } private ProParamSheetVO buildSheetVO(List vos, List dtoList, WorkstationWcsDmpDTO wcs, Map wcsMap) { List head = buildSheetHead(vos); List> content = buildSheetContent(vos, dtoList, wcs, wcsMap); return ProParamSheetVO.builder().head(head).content(content).build(); } private List buildSheetHead(List vos) { List res = Lists.newArrayList(new String[]{MessageUtils.message("calendar.page.shift.model.time", new Object[0])}); for (WorkstationWcsDmpDTO dto : vos) { res.add(dto.getDescription()); } return res; } private List> buildSheetContent(List vos, List dtoList, WorkstationWcsDmpDTO wcs, Map wcsMap) { List> res = Lists.newArrayList(); dtoList.forEach(dto -> { Long time = dto.getTs(); Map valueMap = JsonUtil.toMap(dto.getV()); String firstContent = DateUtil.format(DateUtil.fromMilliseconds(time.longValue()), "yyyy-MM-dd HH:mm:ss.SSS"); ArrayList newArrayList = Lists.newArrayList(new Object[]{firstContent}); buildContent(vos, valueMap, wcs, wcsMap, newArrayList); res.add(newArrayList); }); return res; } private void buildContent(List vos, Map valueMap, WorkstationWcsDmpDTO wcs, Map wcsMap, List content) { for (WorkstationWcsDmpDTO dto : vos) { String name = dto.getName(); String value = Func.toStr(valueMap.get(name)); if (Func.notNull(value)) { if (Func.isNotEmpty(wcs) && name.equals(wcs.getName())) { content.add(wcsMap.getOrDefault(value, "-")); } else { content.add(value); } } else { content.add("-"); } } } private Map getWcsMap() { List globalWcs = listGlobalWcs(); return globalWcs.stream().collect(Collectors.toMap((v0) -> { return v0.getCode(); }, (v0) -> { return v0.getName(); })); } private List getWorkstationWcsDmpDTO(Boolean isFilterProcessParameter, String workstationId) { List vos = WorkstationCache.getWorkstationWcsList(workstationId); if (isFilterProcessParameter.booleanValue()) { vos = vos.stream().filter((v0) -> { return v0.getProcessParameter(); }).collect(Collectors.toList()); } return vos; } }