| | |
| | | package com.qianwen.smartman.modules.mdc.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Tuple; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | 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.sql.ResultSet; |
| | | import java.sql.SQLException; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | |
| | | import java.util.Optional; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.jdbc.core.RowMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | 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 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.common.cache.cps.TimeSliceCache; |
| | | import com.qianwen.smartman.common.cache.cps.WorkstationCache; |
| | | import com.qianwen.smartman.common.constant.DateConstant; |
| | |
| | | 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.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.entity.LastProcessParam; |
| | | import com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData; |
| | | import com.qianwen.smartman.modules.mdc.enums.ProcessParamEnum; |
| | | import com.qianwen.smartman.modules.mdc.mapper.SuperCollectJsonMapper; |
| | |
| | | import com.qianwen.smartman.modules.mdc.vo.excel.ProcessParamExcelVO; |
| | | import com.qianwen.smartman.modules.resource.builder.oss.OssBuilder; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.jdbc.core.JdbcTemplate; |
| | | import org.springframework.jdbc.core.RowMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import cn.hutool.core.lang.Tuple; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | |
| | | @Service |
| | | public class ProcessParameterServiceImpl implements IProcessParameterService { |
| | |
| | | |
| | | @Autowired |
| | | private ProcessParameterHelperService helperService; |
| | | /* |
| | | 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 |
| | | public ProcessParameterResVO queryProcessParameterChart(ProcessParameterSearchVO vo) { |
| | | ProcessParamEnum methodEnum = vo.getMethodEnum(); |
| | |
| | | page.setRecords(collect); |
| | | return page; |
| | | } |
| | | |
| | | /* |
| | | @Override |
| | | public List<WorkstationWcsDmpDTO> processParam(String workstationId) { |
| | | /* |
| | | List<WorkstationWcsDmpDTO> vos =WorkstationCache.getWorkstationWcsList(workstationId).stream().filter((v0) -> { |
| | | return v0.getProcessParameter(); |
| | | }).collect(Collectors.toList()); |
| | | if (Func.isEmpty(vos)) { |
| | | return Lists.newArrayList(); |
| | | } |
| | | return vos;*/ |
| | | |
| | | |
| | | //获取展示在过程参数中的变量 |
| | | List<WorkstationWcsDmpDTO> dps = new ArrayList<>(); |
| | |
| | | } |
| | | return dps; |
| | | } |
| | | |
| | | */ |
| | | @Override |
| | | public List<DatapointDTO> processParams(String workstationId) { |
| | | //获取展示在过程参数中的变量 |
| | |
| | | if (startTime.after(now)) { |
| | | return new CollectParamResVO<>(); |
| | | } |
| | | //String workstationId = vo.getWorkstationId(); |
| | | |
| | | Long workstationId = Long.parseLong(vo.getWorkstationId()); |
| | | List<ProcessParameterVO> processParameterList = getProcessParameterList(startTime, endTime, workstationId, vo.getDmpDTO()); |
| | | return getCollectParamResVO(vo.getDmpDTO(), processParameterList); |
| | | List<ProcessParameterVO> processParameterList = getProcessParameterList(startTime, endTime, workstationId, vo.getDpDTO()); |
| | | return getCollectParamResVO(vo.getDpDTO(), processParameterList); |
| | | } |
| | | |
| | | private CollectParamResVO<?> getCollectParamResVO(WorkstationWcsDmpDTO dmpDTO, List<ProcessParameterVO> processParameterList) { |
| | | private CollectParamResVO<?> getCollectParamResVO(DatapointDTO dpDTO, List<ProcessParameterVO> processParameterList) {//WorkstationWcsDmpDTO dmpDTO |
| | | //状态特殊处理? |
| | | //if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) {//yys |
| | | if (WcsDataTypeEnums.WcsDataType.STATE.getCode().equals(dmpDTO.getWcsDataType())) { |
| | | if ("DeviceStatus".equals(dpDTO.getDpName())) {//状态,需要特殊处理 |
| | | Map<String, String> colorMap = Maps.newHashMap(); |
| | | Map<String, String> nameMap = Maps.newHashMap(); |
| | | Set<String> codes = Sets.newHashSet(); |
| | |
| | | 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.<StatusDTO>builder() |
| | | .collectItem(dmpDTO.getDescription()) |
| | | .collectRealItem(dmpDTO.getName()) |
| | | .collectItem(dpDTO.getDpLabel()) |
| | | .collectRealItem(dpDTO.getDpName()) |
| | | .data(list) |
| | | .build(); |
| | | //return CollectParamResVO.builder().collectItem(dmpDTO.getDescription()).collectRealItem(dmpDTO.getName()).data(list).build(); |
| | | } |
| | | //空指针 |
| | | List<ParamDTO> collect = processParameterList.stream().map(param -> ParamDTO.builder().time(DateUtil.formatDateTime(DateUtil.fromMilliseconds(param.getRealTime().longValue()))).value(param.getValue()).build()).collect(Collectors.toList()); |
| | | /* |
| | | return CollectParamResVO.<ParamDTO>builder() |
| | | .collectItem(dmpDTO.getDescription()) |
| | | .collectRealItem(dmpDTO.getName()) |
| | | .data(collect) |
| | | .build(); |
| | | /* |
| | | List<ParamDTO> 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(); |
| | | */ |
| | | */ |
| | | return CollectParamResVO.<ParamDTO>builder() |
| | | .collectItem(dpDTO.getDpLabel()) |
| | | .collectRealItem(dpDTO.getDpName()) |
| | | .data(collect) |
| | | .build(); |
| | | } |
| | | |
| | | private void buildWcsMap(Map<String, String> colorMap, Map<String, String> nameMap, Set<String> codes) { |
| | |
| | | * @param dmpDTO |
| | | * @return |
| | | */ |
| | | private List<ProcessParameterVO> getProcessParameterList(Date startTime, Date endTime, Long workstationId, WorkstationWcsDmpDTO dmpDTO) { |
| | | ProcessParameterVO firstStatue = oldFirstStatue(startTime, dmpDTO.getName(), workstationId); |
| | | ProcessParameterVO endStatue = oldLastStatue(endTime, dmpDTO.getName(), workstationId); |
| | | private List<ProcessParameterVO> getProcessParameterList(Date startTime, Date endTime, Long workstationId, DatapointDTO dpDTO) {//WorkstationWcsDmpDTO dmpDTO |
| | | ProcessParameterVO firstStatue = oldFirstStatue(startTime, dpDTO.getDpName(), workstationId); |
| | | ProcessParameterVO endStatue = oldLastStatue(endTime, dpDTO.getDpName(), workstationId); |
| | | |
| | | List<ProcessParameterVO> processParameterList = oldOneCollectList(startTime, endTime, dmpDTO.getName(), workstationId); |
| | | List<ProcessParameterVO> processParameterList = oldOneCollectList(startTime, endTime, dpDTO.getDpName(), workstationId); |
| | | if (Func.isNotEmpty(processParameterList)) { |
| | | if (Func.notNull(firstStatue) && !firstStatue.getRealTime().equals(Long.valueOf(startTime.getTime()))) { |
| | | if (Func.notNull(firstStatue) && !firstStatue.getRealTime().equals(startTime.getTime())) { |
| | | firstStatue.setRealTime(startTime.getTime()); |
| | | processParameterList.add(0, firstStatue); |
| | | } |
| | |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param endTime |
| | | * @param item 数据点名称,如Output |
| | | * @param workstationId |
| | | * @return |
| | | */ |
| | | private ProcessParameterVO oldLastStatue(Date endTime, String item, Long workstationId) { |
| | | //ProcessParameterVO vo = this.parameterMapper.oldLastStatue(workstationId, item, Long.valueOf(endTime.getTime())); |
| | | ProcessParameterVO vo = helperService.getLastParameterGreaterThenTime(workstationId, item, endTime.getTime()); |
| | |
| | | return vo; |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * @param startTime |
| | | * @param endTime |
| | | * @param item 数据点名称,如Output |
| | | * @param workstationId |
| | | * @return |
| | | */ |
| | | private List<ProcessParameterVO> oldOneCollectList(Date startTime, Date endTime, String item, Long workstationId) { |
| | | List<ProcessParameterVO> list = this.parameterMapper.oldOneCollectList(workstationId, item, startTime.getTime(), endTime.getTime()); |
| | | list.forEach(p -> {p.setRealTime(p.getTime().getTime());}); |