package com.dy.rtuMw.server.rtuData.p206V202404; import com.dy.common.mw.protocol.Data; import com.dy.common.mw.protocol.p206V202404.DataV202404; import com.dy.common.mw.protocol.p206V202404.upVos.DataCd83Vo; import com.dy.pipIrrGlobal.pojoPr.PrController; import com.dy.pipIrrGlobal.pojoRm.RmTimingReportHistory; import com.dy.pipIrrGlobal.pojoRm.RmTimingReportLast; import com.dy.rtuMw.server.rtuData.TaskSurpport; import com.dy.rtuMw.server.rtuData.dbSv.DbSv; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * @Author: liurunyu * @Date: 2024/5/20 20:29 * @Description 控制器定时上报(功能码83) */ public class TkDealTimingReportV202404 extends TaskSurpport { private static final Logger log = LogManager.getLogger(TkDealTimingReportV202404.class.getName()); //类ID,一定与Tree.xml配置文件中配置一致 public static final String taskId = "TkDealTimingReportV202404"; /** * 执行节点任务:报警及状态 * * @param data 需要处理的数据 */ @Override public void execute(Object data) { Data d = (Data) data; DataV202404 dV202404 = (DataV202404) d.getSubData();//前面任务已经判断不为null Object cdObj = dV202404.subData; if (cdObj != null && cdObj instanceof DataCd83Vo) { try { Object[] objs = this.getTaskResults(TkPreGenObjsV202404.taskId); DbSv sv = (DbSv) objs[0]; PrController controller = (PrController) objs[1]; this.doDeal(sv, controller, d.getRtuAddr(), dV202404, (DataCd83Vo)cdObj); } catch (Exception e) { log.error("保存控制器控制器定时报数据时发生异常", e); } } } /** * 处理阀上报数据 * @param sv 服务 * @param controller 控制器对象 * @param rtuAddr 控制器地址 * @param dataV202404 协议数据 * @param cdData 功能数据 */ private void doDeal(DbSv sv, PrController controller, String rtuAddr, DataV202404 dataV202404, DataCd83Vo cdData) throws Exception { this.saveOrUpdateLast(sv, controller, rtuAddr, dataV202404, cdData); this.saveHistory(sv, controller, rtuAddr, dataV202404, cdData); } /** * 保存或更新控制器该上报最新数据 * @param sv 服务bean * @param controller 控制器对象 * @param rtuAddr 控制器地址 * @param dataV202404 协议数据 * @param cdData 功能数据 */ private void saveOrUpdateLast(DbSv sv, PrController controller, String rtuAddr, DataV202404 dataV202404, DataCd83Vo cdData)throws Exception { RmTimingReportLast po = sv.getRmTimingReportLast(controller.getIntakeId()) ; if(po == null){ po = new RmTimingReportLast(); po.controllerId = controller==null?null:controller.getId(); po.intakeId = controller==null?null:controller.getIntakeId(); po.rtuAddr = rtuAddr; po.valueFrom(dataV202404, cdData); sv.saveRmTimingReportLast(po) ; }else{ po.controllerId = controller==null?null:controller.getId(); po.intakeId = controller==null?null:controller.getIntakeId(); po.valueFrom(dataV202404, cdData); sv.updateRmTimingReportLast(po); } } /** * 保存或更新控制器该上报历史数据 * @param sv 服务bean * @param controller 控制器对象 * @param rtuAddr 控制器地址 * @param dataV202404 协议数据 * @param cdData 功能数据 */ private void saveHistory(DbSv sv, PrController controller, String rtuAddr, DataV202404 dataV202404, DataCd83Vo cdData)throws Exception { RmTimingReportHistory po = new RmTimingReportHistory(); po.controllerId = controller==null?null:controller.getId(); po.intakeId = controller==null?null:controller.getIntakeId(); po.rtuAddr = rtuAddr; po.valueFrom(dataV202404, cdData); sv.saveRmTimingReportHistory(po); ; } }