|  |  |  | 
|---|
|  |  |  | package com.dy.aceMw.server.forTcp; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.aceMw.server.rtuData.RtuComResultCache; | 
|---|
|  |  |  | import com.dy.aceMw.server.rtuData.RtuComResultNode; | 
|---|
|  |  |  | import com.dy.aceMw.server.rtuData.RtuDataNode; | 
|---|
|  |  |  | import com.dy.aceMw.server.rtuData.RtuDataCache; | 
|---|
|  |  |  | import org.apache.logging.log4j.LogManager; | 
|---|
|  |  |  | import org.apache.logging.log4j.Logger; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | //此处实现,与以前不一样, | 
|---|
|  |  |  | //以前实现:匹配命令是从后向前匹配, | 
|---|
|  |  |  | //当前实现,匹配命令是从前向后匹配,原因:举例,当批量下发补召命令,如果从后匹配,则前面命令会下发多次,即一个上报次数据会补召多次 | 
|---|
|  |  |  | MidResultToRtu resToRtu = TcpDownCommandCach.matchFromHead(resFromRtu) ; | 
|---|
|  |  |  | MidResultToRtu resToRtu = TcpDownCommandCache.matchFromHead(resFromRtu) ; | 
|---|
|  |  |  | if(resToRtu != null){ | 
|---|
|  |  |  | //匹配到下发的命令 | 
|---|
|  |  |  | resFromRtu.setCommandId(resToRtu.commandId) ; | 
|---|
|  |  |  | this.sendResult(false, resFromRtu); | 
|---|
|  |  |  | resFromRtu.matchedCommand(resToRtu.rtuResultSendWebUrl, resToRtu.commandId) ; | 
|---|
|  |  |  | this.nextDealRtuData(false, resFromRtu); | 
|---|
|  |  |  | this.nextDealRtuComResult(resFromRtu); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | this.sendResult(false, resFromRtu); | 
|---|
|  |  |  | this.nextDealRtuData(false, resFromRtu); | 
|---|
|  |  |  | //未匹配到下发的命令,命令在缓存因超时被清除了 | 
|---|
|  |  |  | RtuStatusDealer.commandFail2Success(resFromRtu.rtuAddr) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | //主动上报数据 | 
|---|
|  |  |  | this.sendResult(true, resFromRtu); | 
|---|
|  |  |  | this.nextDealRtuData(true, resFromRtu); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | private void sendResult(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 进入多线程环境中运行 | 
|---|
|  |  |  | * @param reportOrResponse_trueOrFalse | 
|---|
|  |  |  | * @param resFromRtu | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void nextDealRtuData(boolean reportOrResponse_trueOrFalse, MidResultFromRtu resFromRtu){ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | String json = resFromRtu.data.toJson() ; | 
|---|
|  |  |  | //         if(reportOrResponse_trueOrFalse){ | 
|---|
|  |  |  | //            ToMqMessageCach.cachObj(MessageType.RtuAutoReport, json); | 
|---|
|  |  |  | //         }else{ | 
|---|
|  |  |  | //            ToMqMessageCach.cachObj(MessageType.RtuCmdResponse, json); | 
|---|
|  |  |  | //         } | 
|---|
|  |  |  | RtuDataCache.cacheRtuUpData(reportOrResponse_trueOrFalse, new RtuDataNode(resFromRtu.data)); | 
|---|
|  |  |  | }catch(Exception e){ | 
|---|
|  |  |  | log.error(e.getMessage(), e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 进入单线程环境中运行 | 
|---|
|  |  |  | * @param resFromRtu | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void nextDealRtuComResult(MidResultFromRtu resFromRtu){ | 
|---|
|  |  |  | try{ | 
|---|
|  |  |  | RtuComResultCache.cacheRtuComResult(new RtuComResultNode(resFromRtu.data)); | 
|---|
|  |  |  | }catch(Exception e){ | 
|---|
|  |  |  | log.error(e.getMessage(), e); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|