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<>"#{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 > #{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>