package com.dy.pipIrrRemote.monitor.common; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.dy.pipIrrGlobal.command.CommandSv; import com.dy.pipIrrGlobal.daoPr.PrCommonIntakesMapper; import com.dy.pipIrrGlobal.daoPr.PrControllerMapper; import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; import com.dy.pipIrrGlobal.pojoPr.PrCommonIntakes; import com.dy.pipIrrGlobal.pojoPr.PrController; import com.dy.pipIrrGlobal.pojoRm.RmCommandHistory; import com.dy.pipIrrGlobal.voRm.VoUnclosedParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.util.Date; /** * @Author: liurunyu * @Date: 2025/5/9 14:45 * @Description */ public class ComSv extends CommandSv { @Autowired protected PrControllerMapper prControllerDao ; @Autowired protected RmCommandHistoryMapper rmCommandHistoryDao ; @Autowired private PrCommonIntakesMapper prCommonIntakesDao; public PrController getRtu(Long intakeId){ return this.getRtu(prControllerDao, intakeId); } /** * 创建命令日志对象 * * @param comId 主键 * @param commandCode 功能码 * @param rtuAddr 阀控器地址 * @param protocol 通讯协议名称 * @param param 参数数据 * @param operator 操作员 * @return */ @Transactional(rollbackFor = Exception.class) public RmCommandHistory saveComHistoryPo(Long comId, String protocol, String commandCode, String commandName, Long intakeId, String rtuAddr, Object param, Long operator) { return this.saveComHistoryPo(rmCommandHistoryDao, comId, protocol, commandCode, commandName, intakeId, rtuAddr, param, operator) ; } /** * 添加常用取水口或更新使用信息 * @param operatorId * @param intakeId * @return */ public PrCommonIntakes addOrUpdateOftenUseIntake(Long operatorId, Long intakeId) { PrCommonIntakes po = prCommonIntakesDao.selectByOperatorAndIntake(operatorId, intakeId); if(po == null) { po = new PrCommonIntakes(); po.setOperatorId(operatorId); po.setIntakeId(intakeId); po.setLastUsedTime(new Date()); po.setUsageCount(1); prCommonIntakesDao.insert(po); }else{ po.setLastUsedTime(new Date()); po.setUsageCount(po.getUsageCount() + 1); prCommonIntakesDao.updateByPrimaryKeySelective(po); } return po ; } /** * 根据取水口ID获取该取水口未关阀参数,平台选择取水口关阀使用 * @param intakeId * @return */ public VoUnclosedParam selectUncloseParam(Long intakeId, String rtuAddr) { JSONArray jsonArr = new JSONArray(); JSONObject jsonObj = new JSONObject(); jsonObj.put("rtuAddr", rtuAddr); jsonObj.put("isOnLine", true); jsonArr.add(jsonObj); return rmCommandHistoryDao.getUncloseParam(jsonArr.toJSONString(), intakeId); } }