yangys
2024-11-02 f69073b835f1a0c66590130e1830edcdd75ebb8a
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/WorkstationAnalysisServiceImpl.java
@@ -17,6 +17,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -30,15 +31,15 @@
import com.qianwen.smartman.common.constant.DateConstant;
import com.qianwen.smartman.common.enums.GlobalWcsTypeEnum;
import com.qianwen.smartman.common.utils.LocalDateTimeUtils;
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.enums.TrayEnum;
import com.qianwen.smartman.modules.cps.enums.WorkstationTypeEnum;
import com.qianwen.smartman.modules.cps.mapper.WorkstationMapper;
import com.qianwen.smartman.modules.cps.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.cps.service.IGlobalWcsService;
import com.qianwen.smartman.modules.cps.service.IWorkstationService;
import com.qianwen.smartman.modules.smis.dto.WorkstationWcsDmpDTO;
import com.qianwen.smartman.modules.smis.entity.GlobalWcs;
import com.qianwen.smartman.modules.smis.entity.Workstation;
import com.qianwen.smartman.modules.smis.enums.TrayEnum;
import com.qianwen.smartman.modules.smis.enums.WorkstationTypeEnum;
import com.qianwen.smartman.modules.smis.mapper.WorkstationMapper;
import com.qianwen.smartman.modules.smis.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.smis.service.IGlobalWcsService;
import com.qianwen.smartman.modules.smis.service.IWorkstationService;
import com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData;
import com.qianwen.smartman.modules.mdc.mapper.SuperAggregateStateMapper;
import com.qianwen.smartman.modules.mdc.mapper.SuperAlarmMapper;
@@ -55,24 +56,19 @@
public class WorkstationAnalysisServiceImpl implements IWorkstationAnalysisService {
    private static final Logger log = LoggerFactory.getLogger(WorkstationAnalysisServiceImpl.class);
    public static final String STATUS = "STATUS";
    private final SuperAggregateStateMapper superAggregateStateMapper;
    private final SuperAlarmMapper superAlarmMapper;
    private final IGlobalWcsService globalWcsService;
    private final WorkstationMapper workstationMapper;
    private final SuperProcessParameterMapper superProcessParameterMapper;
    private final IWorkstationService workstationService;
    @Autowired
    private  SuperAggregateStateMapper superAggregateStateMapper;
    @Autowired
    private  SuperAlarmMapper superAlarmMapper;
    @Autowired
    private  IGlobalWcsService globalWcsService;
    @Autowired
    private  WorkstationMapper workstationMapper;
    @Autowired
    private IWorkstationService workstationService;
    @Autowired
    private IProcessParameterService processParameterService;
    public WorkstationAnalysisServiceImpl(final SuperAggregateStateMapper superAggregateStateMapper, final SuperAlarmMapper superAlarmMapper, final IGlobalWcsService globalWcsService, final WorkstationMapper workstationMapper, final SuperProcessParameterMapper superProcessParameterMapper, final IWorkstationService workstationService,IProcessParameterService aProcessParameterService) {
        this.superAggregateStateMapper = superAggregateStateMapper;
        this.superAlarmMapper = superAlarmMapper;
        this.globalWcsService = globalWcsService;
        this.workstationMapper = workstationMapper;
        this.superProcessParameterMapper = superProcessParameterMapper;
        this.workstationService = workstationService;
        this.processParameterService = aProcessParameterService;
    }
    @Override 
    public List<StatusAnalysisWorkstationVO> statusByWorkstation(String workstationId) {
@@ -102,6 +98,9 @@
        List<AlarmAnalysisWorkstationVO> result;
        try {
            result = this.superAlarmMapper.alarmByWorkstation(workstationId, Integer.valueOf((query.getCurrent() - 1) * query.getSize()), query.getSize());
            result.forEach(a -> {
               a.setAlarmTime(DateUtil.formatDateTime(new Date(a.getTime().getTime())));
            });
            total = this.superAlarmMapper.alarmByWorkstationTotal(workstationId);
        } catch (Exception e) {
           log.error("查询报警异常",e);
@@ -195,7 +194,9 @@
        
        //deviceMap key为wcs的code值,value是设备数量(该状态的)
        Map<String, Long> deviceMap = wIds.stream().map(wId -> {
            Map<String, Object> realTimeData = WorkstationCache.getWorkstationAllCollect(wId);
           //下面的缓存是TelemetryDataRealTimeConsumer中设置的(接收数据)。需要再collect中设置,避免格式问题,我们不需要这么干了,直接查询
            Map<String, Object> realTimeData = WorkstationCache.getWorkstationAllCollect(wId);
            //WorkstationWcsDmpDTO dmpDTO = WorkstationCache.getDmpStatus(wId);//这里使用了blade_workstation_wcs blade_dmp_variables表,考虑去掉了,我们没有dmp
            WorkstationWcsDmpDTO dmpDTO = new WorkstationWcsDmpDTO();
            dmpDTO.setName("DeviceStatus");
@@ -205,11 +206,10 @@
                return dto.getV();
            }
            
            //如果缓存没有数据
            //this error
            //如果以上从缓存没有拿到数据(我们肯定没有缓存,不知道缓存哪儿来的),查询最新时序数据
            //List<WorkstationCollectData> workstationCollectData = this.superProcessParameterMapper.queryLastParameter(wId);//该工位最新的last(ts),last(v)
            List<WorkstationCollectData> workstationCollectData = processParameterService.lastParameter(Long.parseLong(wId));
            List<WorkstationCollectData> workstationCollectData = processParameterService.queryLastParameter(Long.parseLong(wId));
            if (Func.isNotEmpty(workstationCollectData)) {
               //resultMapping ,key:n ,value:TelemetryDataResponseDTO{last(ts),last(v)}
                Map<String, Object> resultMapping = workstationCollectData.stream().collect(Collectors.toMap((v0) -> {