yangys
2024-10-24 c994ea497a71f7f6a17b3f0d54fc076aff22ca00
代码整理
已修改15个文件
已添加1个文件
227 ■■■■ 文件已修改
smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java 56 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/websocket/realtime/RealTimeDataJsonMessageHandler.java 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/MyTestController.java 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/controller/RealTimeDataController.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/enums/OpenTypeEnums.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IOutputStatisticsService.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IRealTimeDataService.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/RealTimeDataService.java 56 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/OutputStatisticsServiceImpl.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/RealTimeDataServiceImpl.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/utils/FilterOffUtils.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateOutputMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateMapper.xml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
smart-man-boot/src/main/java/com/qianwen/smartman/common/config/MdcMqttConfig.java
@@ -30,6 +30,10 @@
import com.qianwen.smartman.common.cache.cps.WorkstationCache;
import com.qianwen.smartman.common.websocket.realtime.RealTimeDaraResponseJsonWebSocketMessage;
import com.qianwen.smartman.modules.cps.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
import com.qianwen.smartman.modules.mdc.entity.WorkstationCollectData;
import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
import com.qianwen.smartman.modules.mdc.service.RealTimeDataService;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.util.ObjectUtil;
@@ -50,6 +54,11 @@
    @Autowired
    private RedisMessageDistributor messageDistributor;
    
    //@Autowired
    //private SuperProcessParameterMapper processParamMapper;
    @Autowired
    private RealTimeDataService realTimeDataService;
    public static final String DEFAULT_TOPIC = "mdc";
    /**
     * åé¦ˆåˆ›å»ºçš„topic(mdc中),本应用接收并处理
@@ -127,31 +136,46 @@
                //发送websocket消息
                RealTimeDaraResponseJsonWebSocketMessage jsonWebSocketMessage = new RealTimeDaraResponseJsonWebSocketMessage();
                jsonWebSocketMessage.setId(""+workstationId);
                //从缓存(或直接查询)加载最新的数据,发送websocket
                Map<String, Object> map = WorkstationCache.getWorkstationRealTime(workstationId+"");
                realTimeDataService.addPreTimeInDeviceStatus(workstationId, map);
                /*
                jsonWebSocketMessage.setData(new HashMap<String, Object>() { // from class: org.springblade.modules.cps.message.consumer.TelemetryDataRealTimeConsumer.1
                    {
                        put(name, telemetryDataResponseDTO);
                    }
                });
                //找到状态的数据,加入上一个状态的
                final String statusDpName = "DeviceStatus";
                if(map.containsKey(statusDpName)) {
                    TelemetryDataResponseDTO statusDTO = (TelemetryDataResponseDTO) map.get(statusDpName);
                    JSONObject statusJson = new JSONObject();
                    statusJson.put("t", statusDTO.getT());
                    statusJson.put("v", statusDTO.getV());
                    long preT = statusDTO.getT();
                    //最后一条不同值(v)的数据
                    ProcessParameterVO diffStatusVO = processParamMapper.lastParameterNotEqValue(workstationId, statusDpName, statusDTO.getV());
                    ProcessParameterVO tempStatusVO;
                    if(diffStatusVO != null) {
                        tempStatusVO = processParamMapper.firstParameterEqValueGtTime(workstationId, statusDpName, statusDTO.getV(), diffStatusVO.getTime().getTime());
                    }else {
                        tempStatusVO = processParamMapper.firstParameterEqValue(workstationId, statusDpName, statusDTO.getV());
                    }
                    if(tempStatusVO != null) {
                        preT = tempStatusVO.getTime().getTime();
                    }
                    statusJson.put("preT", preT);
                    map.put(statusDpName, statusJson);//覆盖原来的DeviceStatus
                }
                */
                
                Map<String, Object> map = WorkstationCache.getWorkstationRealTime(workstationId+"");
                jsonWebSocketMessage.setData(map);
                //RedisMessageDistributor messageDistributor = (RedisMessageDistributor) SpringUtil.getBean(RedisMessageDistributor.class);
                MessageDO messageDO = new MessageDO();
                messageDO.setNeedBroadcast(false);
                String msgtxt =JSONUtil.toJsonStr(jsonWebSocketMessage);
                logger.info("websockettxt={}",msgtxt);
                messageDO.setMessageText(msgtxt);
                /*
                JSONObject testMsg = new JSONObject();
                JSONObject msgdata = JSONObject.parseObject(JSONUtil.toJsonStr(map));
                testMsg.put("data", msgdata);
                testMsg.put("id", workstationId+"");
                String msgtxt = testMsg.toJSONString();
                */
               
                messageDistributor.distribute(messageDO);
                
smart-man-boot/src/main/java/com/qianwen/smartman/common/websocket/realtime/RealTimeDataJsonMessageHandler.java
@@ -9,9 +9,11 @@
import com.qianwen.core.websocket.handler.JsonMessageHandler;
import com.qianwen.smartman.modules.coproduction.entity.OrderWorkstation;
import com.qianwen.smartman.modules.coproduction.service.IOrderWorkstationService;
import com.qianwen.smartman.modules.mdc.service.RealTimeDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;
@@ -21,11 +23,14 @@
@Component
public class RealTimeDataJsonMessageHandler implements JsonMessageHandler<RealTimeDataRequestJsonWebSocketMessage> {
    private Logger log = LoggerFactory.getLogger(this.getClass());
    private final IOrderWorkstationService orderWorkstationService;
    //private final IOrderWorkstationService orderWorkstationService;
    @Autowired
    private RealTimeDataService realTimeDataService;
    /*
    public RealTimeDataJsonMessageHandler(final IOrderWorkstationService orderWorkstationService) {
        this.orderWorkstationService = orderWorkstationService;
    }
    }*/
    public void handle(WebSocketSession session, RealTimeDataRequestJsonWebSocketMessage message) {
        List<String> workstationIdList = message.getWorkstationIdList();
@@ -43,6 +48,8 @@
                if("1656819188967653378".equals(workstationId)) {
                    log.info(workstationId+"收到:"+map);
                }
                long wid = Long.parseLong(workstationId);
                realTimeDataService.addPreTimeInDeviceStatus(wid, map);
                //map.put("orderCode", Func.isEmpty(orderWorkstationMap.get(Long.valueOf(workstationId))) ? "-" : orderWorkstationMap.get(Long.valueOf(workstationId)));
                jsonWebSocketMessage.setData(map);
                jsonWebSocketMessage.setId(workstationId);
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/MyTestController.java
@@ -33,6 +33,8 @@
import com.qianwen.smartman.modules.cps.vo.CollectDeviceTypeVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationDatapointsVO;
import com.qianwen.smartman.modules.cps.vo.WorkstationGroupVO;
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
import cn.hutool.json.JSONUtil;
@@ -58,6 +60,8 @@
    DataScopeProperties dsp;
    @Autowired
    QueryInterceptor qi;
    @Autowired
    SuperProcessParameterMapper pmapper;
    
    @GetMapping({"/dsp"})
    @ApiOperation("dsp")
@@ -123,5 +127,14 @@
        return R.data(typeService.typeList());
    }
    
    @GetMapping({"/lastP"})
    @ApiOperation("采集类型列表")
    public R<ProcessParameterVO> lastP() {//1656818952295661569_DeviceStatus
        ProcessParameterVO vo = this.pmapper.lastParameterNotEqValue(1656818952295661569L, "DeviceStatus", "2");
        ProcessParameterVO vo1 = this.pmapper.firstParameterEqValueGtTime(1656818952295661569L, "DeviceStatus", "2",System.currentTimeMillis()-20000);
        return R.data(vo);
    }
    
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/cps/controller/WorkstationWcsController.java
@@ -43,6 +43,8 @@
     * @param workstationWcsSaveVOList
     * @return
     */
    //20241021 yangys注释
    /*
    @PreAuth
    @PostResource({"/save"})
    @ApiOperation("新增或更改工况参数信息")
@@ -104,4 +106,5 @@
    public R<List<WorkstationWcsVO>> listWcsSetting() {
        return R.data(this.workstationWcsService.listWcsSetting());
    }
    */
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/controller/RealTimeDataController.java
@@ -24,16 +24,18 @@
    public RealTimeDataController(final IRealTimeDataService realTimeDataService) {
        this.realTimeDataService = realTimeDataService;
    }
    //yangys 20241022注释,估计是没用了,准备删除
    /*
    @PostResource({"/status"})
    @ApiOperation(value = "获取工位的状态", notes = "传入工位组ID或者工位ID列表")
    public R<List<DmpStatusVariableVO>> getWorkstationRealTimeStatus(@RequestBody WorkstationVO workstationVO) {
        return R.data(this.realTimeDataService.getWorkstationRealTimeStatus(workstationVO));
    }
    @GetResource({"/dmp-variables/{workstationId}"})
    @ApiOperation(value = "获取工位的采集项", notes = "传入workstationId")
    public R<List<DmpVariablesVO>> getWorkstationDmpVariables(@PathVariable Long workstationId) {
        return R.data(this.realTimeDataService.getWorkstationDmpVariables(workstationId));
    }
    */
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/enums/OpenTypeEnums.java
@@ -5,7 +5,7 @@
public enum OpenTypeEnums {
    /**
     * "mdc_open_type"
     * "mdc_open_type",blade_param表中的一个参数
     */
    PARAM_KEY_TYPE("mdc_open_type"),
    /**
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.java
@@ -15,7 +15,7 @@
@DS("iotdb")
@InterceptorIgnore(tenantLine = FmsConstant.AUTOMATIC)
public interface SuperProcessParameterMapper {
    //这个在ProcessParameterService中实现了,mp对此有bug
    //这个在ProcessParameterService中实现了,mybatisplus对此有bug
    //List<WorkstationCollectData> queryLastParameter(@Param("workstationId") String workstationId);
    /**
     * æŸ¥è¯¢å·¥ä½æœ€æ–°å‚数,yys增加,可能需要使用queryLastParameter了(如果没问题)
@@ -65,7 +65,23 @@
    //ProcessParameterVO oldLastStatue(@Param("workstationId") String workstationId, @Param("item") String item, @Param("endTime") Long endTime);
    //LastProcessParam lastParameterGreaterThanTime(@Param("workstationId") Long workstationId, @Param("item") String item, @Param("endTime") Long endTime);
    
    /**
     * èŽ·å–ä¸€ä¸ªé‡‡é›†å‚æ•°ä¸ç­‰äºŽæŸå€¼çš„æœ€åŽä¸€æ¡
     * @param workstationId å·¥ä½id
     * @param item å‚数名称
     * @param value å€¼
     * @return
     */
    ProcessParameterVO lastParameterNotEqValue(@Param("workstationId") Long workstationId,@Param("item")String item,@Param("value")String value);
    
    ProcessParameterVO firstParameterEqValueGtTime(@Param("workstationId") Long workstationId,@Param("item")String item,@Param("value")String value,@Param("time")long time);
    /**
     * èŽ·å–ä¸€ä¸ªé‡‡é›†å‚æ•°ç­‰äºŽæŸå€¼çš„æœ€æ—©ä¸€æ¡
     * @param workstationId
     * @param n
     * @param value
     * @return
     */
    ProcessParameterVO firstParameterEqValue(@Param("workstationId") Long workstationId,@Param("item")String item,@Param("value")String value);
    
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IOutputStatisticsService.java
@@ -14,5 +14,10 @@
     */
    StatisticsVO outputStatistics(StatisticsAnalysisQueryVO statisticsAnalysisQueryVO, Query query);
    /**
     * äº§é‡ç»Ÿè®¡å¯¼å‡º
     * @param analysisQueryVO
     * @return
     */
    BladeFile export(StatisticsAnalysisQueryVO analysisQueryVO);
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/IRealTimeDataService.java
@@ -4,9 +4,13 @@
import com.qianwen.smartman.modules.cps.vo.DmpStatusVariableVO;
import com.qianwen.smartman.modules.cps.vo.DmpVariablesVO;
import com.qianwen.smartman.modules.mdc.vo.WorkstationVO;
/**
 * å®žæ—¶æ•°æ®
 */
public interface IRealTimeDataService {
    List<DmpStatusVariableVO> getWorkstationRealTimeStatus(WorkstationVO workstationVO);
    //List<DmpStatusVariableVO> getWorkstationRealTimeStatus(WorkstationVO workstationVO);
    List<DmpVariablesVO> getWorkstationDmpVariables(Long workstationId);
    //List<DmpVariablesVO> getWorkstationDmpVariables(Long workstationId);
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/RealTimeDataService.java
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,56 @@
package com.qianwen.smartman.modules.mdc.service;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.qianwen.smartman.modules.cps.message.dto.TelemetryDataResponseDTO;
import com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO;
import com.qianwen.smartman.modules.mdc.mapper.SuperProcessParameterMapper;
@Service
public class RealTimeDataService {
    private static final Logger log = LoggerFactory.getLogger(RealTimeDataService.class);
    @Autowired
    private SuperProcessParameterMapper processParamMapper;
    public final String statusDpName = "DeviceStatus";
    /**
     * ä¸ºè®¾å¤‡çŠ¶æ€å¢žåŠ å½“å‰çŠ¶æ€çš„æœ€æ—©æ—¶é—´preT
     * @param workstationId å·¥ä½id
     * @param map å·¥ä½id对应的所有最新数据
     */
    public void addPreTimeInDeviceStatus(long workstationId,Map<String, Object> map) {
        //找到状态的数据,加入上一个状态的
        if(map.containsKey(statusDpName)) {
            TelemetryDataResponseDTO statusDTO = (TelemetryDataResponseDTO) map.get(statusDpName);
            JSONObject statusJson = new JSONObject();
            statusJson.put("t", statusDTO.getT());
            statusJson.put("v", statusDTO.getV());
            long preT = statusDTO.getT();
            //最后一条不同值(v)的数据
            ProcessParameterVO diffStatusVO = processParamMapper.lastParameterNotEqValue(workstationId, statusDpName, statusDTO.getV());
            ProcessParameterVO tempStatusVO;
            if(diffStatusVO != null) {
                tempStatusVO = processParamMapper.firstParameterEqValueGtTime(workstationId, statusDpName, statusDTO.getV(), diffStatusVO.getTime().getTime());
            }else {
                tempStatusVO = processParamMapper.firstParameterEqValue(workstationId, statusDpName, statusDTO.getV());
            }
            if(tempStatusVO != null) {
                preT = tempStatusVO.getTime().getTime();
            }
            statusJson.put("preT", preT);
            map.put(statusDpName, statusJson);//覆盖原来的DeviceStatus
        }
    }
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/OutputStatisticsServiceImpl.java
@@ -86,15 +86,7 @@
        List<String> workStationIdList = statisticsAnalysisQueryVO.getWorkStationIdList();
        if (Func.isEmpty(workStationIdList)) {
            workStationIdList = this.workstationService.list(Wrappers.<Workstation>lambdaQuery().eq(Workstation::getType, WorkstationTypeEnum.MACHINE.getCode())
                    .eq(Workstation::getStatus, CommonConstant.ENABLE)).stream().map(s -> Func.toStr(s.getId())).collect(Collectors.toList());
            /*
            workStationIdList = (List) this.workstationService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
                return v0.getType();
            }, WorkstationTypeEnum.MACHINE.getCode())).eq((v0) -> {
                return v0.getStatus();
            }, CommonConstant.ENABLE)).stream().map(s -> {
                return Func.toStr(s.getId());
            }).collect(Collectors.toList());*/
                    .eq(Workstation::getStatus, CommonConstant.ENABLE)).stream().map(s -> Func.toStr(s.getId())).collect(Collectors.toList());
        }
        IPage<WorkstationVO> workstationVOPage = this.workstationMapper.queryWorkstationAndGroup(Condition.getPage(query), Func.toLongList(workStationIdList));
        IPage<Workstation> workstationPage = WorkstationConvert.INSTANCE.convert(workstationVOPage);
@@ -109,7 +101,7 @@
        return this.wrapper.entityVO(statisticsWrapperDto);
    }
    @Override
    public BladeFile export(StatisticsAnalysisQueryVO analysisQueryVO) {
        StatisticalMethodEnum statisticalMethod = analysisQueryVO.getStatisticalMethod();
        List<String> workStationIdList = analysisQueryVO.getWorkStationIdList();
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/service/impl/RealTimeDataServiceImpl.java
@@ -21,7 +21,7 @@
import com.qianwen.smartman.modules.mdc.vo.WorkstationVO;
import org.springframework.stereotype.Service;
@Service
@Service("oldRealTimeDataService")
public class RealTimeDataServiceImpl implements IRealTimeDataService {
    private final WorkstationMapper workstationMapper;
    private final IWorkstationOfMachineService workstationOfMachineService;
@@ -32,7 +32,7 @@
        this.workstationOfMachineService = workstationOfMachineService;
        this.dmpVariablesService = dmpVariablesService;
    }
    /*
    @Override
    public List<DmpStatusVariableVO> getWorkstationRealTimeStatus(WorkstationVO workstationVO) {
        List<Long> workstationIdList = workstationVO.getWorkstationIdList();
@@ -64,4 +64,5 @@
        List<DmpVariablesVO> dmpVariables = this.dmpVariablesService.getDmpVariablesByWorkstationId(Long.valueOf(workstationId.longValue()));
        return dmpVariables.stream().filter(DmpVariablesVO::getRealTimeData).collect(Collectors.toList());
    }
    */
}
smart-man-boot/src/main/java/com/qianwen/smartman/modules/mdc/utils/FilterOffUtils.java
@@ -25,8 +25,7 @@
        boolean filterType = whetherToFilter(OpenTypeEnums.PARAM_KEY_TYPE, openTypeEnums);//mdc_open_type,是否过滤该类型
        boolean filterShift = whetherToFilter(OpenTypeEnums.PARAM_KEY_SHIFT, openTypeEnums);//mdc_open_shift,是否过滤班制
        //这里简化,不过滤了,数据在win服务器有,blade_boot_blade_param-0418bak.sql有,是个json数组
        //boolean filterType = false;
       // boolean filterShift = false;
        if (!filterType && !filterShift) {
            return data;
        }
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateOutputMapper.xml
@@ -352,7 +352,7 @@
    <!-- åˆ—名中,program和已下的实际上都没有 -->
    <sql id="aggregateOutputColumns">
        pre_time as preTime,
        output,
        output as output,
        cur_output as curOutput,
        pre_output as preOutput,
        calendar_code as calendarCode,
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperAggregateStateMapper.xml
@@ -1039,7 +1039,7 @@
        where factory_date = #{factoryDate}
        and wcs > 0
        and shift_index = #{shiftIndex}
        and calendar_code = '${calendarCode}'
        and calendar_code = "#{calendarCode}"
        and is_deleted = false
        <if test="ids != null and ids.size() > 0">
            AND workstation_id IN
smart-man-boot/src/main/resources/com/qianwen/smartman/modules/mdc/mapper/SuperProcessParameterMapper.xml
@@ -198,5 +198,26 @@
        order by time
        align by device
    </select>
    <select id="lastParameterNotEqValue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v&lt;&gt;"#{value}"
        order by time desc limit 1
    </select>
    <select id="firstParameterEqValueGtTime" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v="#{value}" and time &gt; #{time}
        order by time limit 1
    </select>
    <select id="firstParameterEqValue" resultType="com.qianwen.smartman.modules.mdc.dto.ProcessParameterVO">
        select n as collectItem,v as valueCollect
        from root.f2.process_param_${workstationId}_${item}
        where v="#{value}"
        order by time limit 1
    </select>
</mapper>