1、通信中间件重构MQTT相关下行命令的逻辑;
2、remote模块完善MQTT相关下行命令解除报警、搅拌启停、注肥启停、灌溉启停功能类;
| | |
| | | if(com.protocolVersion == null){ |
| | | throw new Exception("接收到MQTT命令,但未提供协议版本号") ; |
| | | } |
| | | if(com.code != null && com.code.trim().length() != 0){ |
| | | if(com.code == null || com.code.trim().length() == 0){ |
| | | throw new Exception("接收到MQTT命令,但未提供功能码") ; |
| | | } |
| | | if(com.protocol.equals(ProtocolConstantSdV1.protocolName)){ |
| | |
| | | msg.isCacheForOffLine = false ; |
| | | msg.hasResponse = true ; |
| | | msg.cd = CodeSdV1.cd_Fault ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol, com.rtuAddr, ProtocolConstantSdV1.PubTopicFault, cvo.no) ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicFault, cvo.no) ; |
| | | msg.msg = JSON.toJSONString(new FaultClearVo(cvo.startTrueStopFalse ?(byte)1:0)) ; |
| | | return msg ; |
| | | } |
| | |
| | | msg.isCacheForOffLine = false ; |
| | | msg.hasResponse = true ; |
| | | msg.cd = CodeSdV1.cd_Fault ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol, com.rtuAddr, ProtocolConstantSdV1.PubTopicStir, cvo.no) ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicStir, cvo.no) ; |
| | | msg.msg = JSON.toJSONString(new StirStartVo(cvo.startTrueStopFalse ?(byte)1:0)) ; |
| | | return msg ; |
| | | } |
| | |
| | | msg.isCacheForOffLine = false ; |
| | | msg.hasResponse = true ; |
| | | msg.cd = CodeSdV1.cd_Fault ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol, com.rtuAddr, ProtocolConstantSdV1.PubTopicInject, cvo.no) ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicInject, cvo.no) ; |
| | | msg.msg = JSON.toJSONString(new InjectStartVo(cvo.startTrueStopFalse ?(byte)1:0)) ; |
| | | return msg ; |
| | | } |
| | |
| | | msg.isCacheForOffLine = false ; |
| | | msg.hasResponse = true ; |
| | | msg.cd = CodeSdV1.cd_Fault ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol, com.rtuAddr, ProtocolConstantSdV1.PubTopicIrr, cvo.no) ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicIrr, cvo.no) ; |
| | | msg.msg = JSON.toJSONString(new StirStartVo(cvo.startTrueStopFalse ?(byte)1:0)) ; |
| | | return msg ; |
| | | } |
| | |
| | | msg.isCacheForOffLine = false ; |
| | | msg.hasResponse = false ; |
| | | msg.cd = CodeSdV1.cd_Param ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol, com.rtuAddr, ProtocolConstantSdV1.PubTopicParam, cvo.no) ; |
| | | msg.topic = new MqttTopic(orgTag, com.protocol + com.protocolVersion, com.rtuAddr, ProtocolConstantSdV1.PubTopicParam, cvo.no) ; |
| | | msg.msg = JSON.toJSONString(new ParamSetVo(cvo.stirDuration, cvo.injectDuration)) ; |
| | | return msg ; |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 创建外部命令(发给控制器) |
| | | * @param fboxId FBox设备序列号 |
| | | * @param comId 命令ID |
| | | * @param code 命令code |
| | | * @return |
| | | */ |
| | | public Command createMQTTCommand(String fboxId, String comId, String protocol, Short protocolVer, String code) { |
| | | Command com = new Command(); |
| | | com.id = comId; |
| | | com.rtuAddr = fboxId; |
| | | com.code = code ; |
| | | com.protocol = protocol ; |
| | | com.protocolVersion = protocolVer ; |
| | | com.type = CommandType.mqttCommand; |
| | | return com ; |
| | | } |
| | | |
| | | /** |
| | | * 创建外部透传命令(发给控制器) |
| | | * @param comId 命令ID |
| | | * @param code 命令code |
| | |
| | | }else{ |
| | | mqVo.svUserPassword = mqVo.svUserPassword.trim() ; |
| | | } |
| | | mqVo.poolMaxSize = conf.getSetAttrPlusInt(doc, "config.mqtt", "poolMaxSize", null, 5, 360000, null); |
| | | if(mqVo.poolMaxSize <= 1 || mqVo.poolMaxSize > 1000){ |
| | | throw new Exception("config.mqtt.poolMaxSize配置的连接池连接最大数量不合法") ; |
| | | } |
| | | mqVo.poolMaxSize = conf.getSetAttrPlusInt(doc, "config.mqtt", "poolMaxSize", null, 1, 1000, null); |
| | | |
| | | mqVo.sendInterval = conf.getSetAttrPlusInt(doc, "config.mqtt", "sendInterval", null, 1, 3600, null) * 1000L ; |
| | | |
| | | mqVo.reSendTimesByNoResult = conf.getSetAttrPlusInt(doc, "config.mqtt", "reSendTimesByNoResult", null, 0, 100, null); |
| | | |
| | | mqVo.comCacheTimeout = conf.getSetAttrPlusInt(doc, "config.mqtt", "comCacheTimeout", null, 1, 3600, null) * 1000L ; |
| | | |
| | | mqVo.useMemoryPersistence = conf.getSetAttrBoolean(doc, "config.mqtt", "useMemoryPersistence", null, null) ; |
| | | String proAndDevIds = conf.getSetAttrTxt(doc, "config.mqtt", "protocolAndDeviceIds", null, false, null) ; |
| | | if(proAndDevIds == null || proAndDevIds.trim().equals("")){ |
| | |
| | | public MqttPubMsg result ;//下行命令 |
| | | public Long cachTime ;//缓存时刻 |
| | | public boolean onceReceivedResult ;//已经收到命令应答 |
| | | public long lastSendTime = 0 ;//上次发送时间 |
| | | public int sendTimes = 0 ;//发送次数 |
| | | |
| | | |
| | | public MqttPubMsgNode(MqttPubMsg result){ |
| | | this.result = result ; |
| | | this.cachTime = System.currentTimeMillis() ; |
| | | this.onceReceivedResult = false ; |
| | | this.lastSendTime = 0L ; |
| | | this.sendTimes = 0 ; |
| | | } |
| | | |
| | | /** |
| | |
| | | public boolean dealSelf(Long now){ |
| | | if(this.onceReceivedResult){ |
| | | //已经收到命令结果 |
| | | //记录状态 |
| | | //RtuStatusDealer.commandSuccess(this.result.rtuAddr, this.result.downCode, this.result.downCodeName); |
| | | return true ; |
| | | } |
| | | if(this.sendTimes >= (1 + MqttUnit.confVo.reSendTimesByNoResult)){ |
| | | return this.decideRemoveNodeFromCach(now, null) ; |
| | | } |
| | | if(this.lastSendTime != 0 && now - this.lastSendTime >= MqttUnit.confVo.sendInterval){ |
| | | return this.decideRemoveNodeFromCach(now, null) ; |
| | | } |
| | | boolean noConnect2MqSv = false ; |
| | | MqttManager mqttManager = MqttManager.getInstance() ; |
| | |
| | | noConnect2MqSv = mqttManager.poolIsClose() ; |
| | | if(noConnect2MqSv){ |
| | | //未曾连接MQTT服务器 |
| | | return this.decideRemoveNodeFromCach(now) ; |
| | | return this.decideRemoveNodeFromCach(now, null) ; |
| | | }else{ |
| | | try { |
| | | //如果网络不好或断网,此处用时较长 |
| | |
| | | } |
| | | if(noConnect2MqSv){ |
| | | //未曾连接MQTT服务器 |
| | | return this.decideRemoveNodeFromCach(now) ; |
| | | return this.decideRemoveNodeFromCach(now, null) ; |
| | | }else{ |
| | | if(mqttClient != null && mqttClient.isConnected()){ |
| | | try { |
| | | mqttManager.publishMsg(mqttClient, this.result.topic.longName(), this.result.msg); |
| | | this.sendTimes ++ ; |
| | | this.lastSendTime = System.currentTimeMillis() ; |
| | | DevStatusDealer.afterSendPubMessage(this.result.deviceId); |
| | | RtuLogDealer.log4Mqtt(this.result.deviceId, "发布消息 主题:" + this.result.topic + " 消息:" + this.result.msg); |
| | | log.info("发布MQTT消息(主题=" + this.result.topic + ")" + this.result.msg); |
| | | RtuLogDealer.log4Mqtt(this.result.deviceId, "发布消息 主题:" + this.result.topic.longName() + " 消息:" + this.result.msg); |
| | | log.info("发布MQTT消息(主题=" + this.result.topic.longName() + ")" + this.result.msg); |
| | | }catch (Exception e){ |
| | | log.error("MQTT发布消息失败(主题=" + this.result.topic + ")" , e); |
| | | log.error("MQTT发布消息失败(主题=" + this.result.topic.longName() + ")" , e); |
| | | }finally { |
| | | mqttManager.pushMqttClient(mqttClient); |
| | | } |
| | |
| | | } |
| | | }else{ |
| | | //未曾连接MQTT服务器 |
| | | return this.decideRemoveNodeFromCach(now) ; |
| | | return this.decideRemoveNodeFromCach(now, false) ; |
| | | } |
| | | } |
| | | } |
| | | |
| | | private boolean decideRemoveNodeFromCach(Long now){ |
| | | if(!this.result.isCacheForOffLine){ |
| | | private boolean decideRemoveNodeFromCach(Long now, Boolean isOffLine){ |
| | | if(isOffLine != null && isOffLine.booleanValue() && !this.result.isCacheForOffLine){ |
| | | //不在线命令不缓存 |
| | | return true ; |
| | | }else{ |
| | | //不在线命令缓存 |
| | | if(now - this.cachTime >= ServerProperties.offLineCacheTimeout){ |
| | | if(now - this.cachTime >= MqttUnit.confVo.comCacheTimeout){ |
| | | //缓存超时 |
| | | return true ; |
| | | } |
| | |
| | | public String svUserName ;// |
| | | public String svUserPassword ;// |
| | | public Integer poolMaxSize ;// |
| | | public Long sendInterval ;// |
| | | public Integer reSendTimesByNoResult ;// |
| | | public Long comCacheTimeout ;// |
| | | public Boolean useMemoryPersistence ; |
| | | public String[] protocolAndDeviceIds ;//设备协议与ID(FBox)id |
| | | public String[] deviceIds ;//设备(FBox)id |
| | |
| | | this.svUserName = "dyyjy" ; |
| | | this.svUserPassword = "Dyyjy2025,;.abc!@#" ; |
| | | this.poolMaxSize = 10 ; |
| | | useMemoryPersistence = true ; |
| | | this.sendInterval = 60000L ; |
| | | this.reSendTimesByNoResult = 0 ; |
| | | this.comCacheTimeout = 60000L ; |
| | | this.useMemoryPersistence = true ; |
| | | this.pubTopicQos = 1 ; |
| | | this.noSubThenOff = 10 * 60 * 10000L ; |
| | | } |
| | |
| | | # 凉州: mqtt.enable=false mqtt.protocolAndDeviceIds= mqtt.topicAndQos= |
| | | # 金川: mqtt.enable=true mqtt.protocolAndDeviceIds=? mqtt.topicAndQos=weather/1,1;soil/1,1;manure/1,1;state/1,1 |
| | | # 嘉峪关: mqtt.enable=true mqtt.protocolAndDeviceIds=? mqtt.topicAndQos=weather/1,1;soil/1,1;manure/1,1;state/1,1 |
| | | mqtt.enable=false |
| | | mqtt.ip=127.0.0.1 |
| | | mqtt.enable=true |
| | | mqtt.ip=121.199.41.121 |
| | | mqtt.port=1883 |
| | | mqtt.user=dyyjy |
| | | mqtt.password=Dyyjy2025,;.abc!@# |
| | | mqtt.protocolAndDeviceIds=sd1/2430002404000840,sd1/2430002404000840 |
| | | mqtt.protocolAndDeviceIds=sd1/123456789 |
| | | mqtt.subTopicAndQos=weather/1,1;soil/1,1;manure/1,1 |
| | | #MQtt设备在一定时间(分钟)后未发布消息,认为设备离线 |
| | | mqtt.noSubThenOff=10 |
| | |
| | | svUserName MQTT服务器用户名 |
| | | svUserPassword MQTT服务器用户密码 |
| | | poolMaxSize 连接池最大连接数 |
| | | sendInterval 命令发送间隔(单位秒),取值范围是1~3600 |
| | | reSendTimesByNoResult 未收到命令结果时,最大重复发送次数,取值范围是0~100, 0时表示不重复发送 |
| | | comCacheTimeout: 命令最大缓存时长(秒),取值范围是1~3600 |
| | | useMemoryPersistence 使用内存持久化而非默认的文件持久化(true是 false否) |
| | | protocolAndDeviceIds 在子系统(orgTag)中接入的设备(FBox)所用协议及设备id集合,多个用逗号隔开,协议与ID用正斜杠隔开,例如:sd1/338220031439,sd1/338220031440 |
| | | subTopicAndQos: 订阅主题与Qos,主题名与其Qos用逗号隔开,多个主题及Qos用分号隔开,例如:ym/topic1,1;ym/topic2,1;ym/topic3,1,如果有多个OrgTag,主题前缀用其OrgTag |
| | |
| | | svUserName="${mqtt.user}" |
| | | svUserPassword="${mqtt.password}" |
| | | poolMaxSize="10" |
| | | sendInterval="60" |
| | | reSendTimesByNoResult="0" |
| | | comCacheTimeout="30" |
| | | useMemoryPersistence="true" |
| | | protocolAndDeviceIds="${mqtt.protocolAndDeviceIds}" |
| | | subTopicAndQos="${mqtt.subTopicAndQos}" |
| | |
| | | @Data |
| | | @SuperBuilder |
| | | public class Cd4MqttParameter { |
| | | //命令功能码 |
| | | public String commandCode; |
| | | public Integer no ;//设备编号 |
| | | } |
| | |
| | | @Slf4j |
| | | @Tag(name = "远程命令", description = "清除故障") |
| | | @RestController("mqttSd1FaultCtrl") |
| | | @RequestMapping(path = "mqttSd1/faultCtrl") |
| | | @RequestMapping(path = "mqttSd1/fault") |
| | | @RequiredArgsConstructor |
| | | @Scope("prototype") //因为有对象类属性,所以采用原型模式,每次请求新建一个实例对象 |
| | | public class CdCtrl extends Com4MqttCtrl { |
| | |
| | | private static final Short ProtocolVersion = ProtocolConstantSdV1.protocolVer ; |
| | | private static final String ComCode = CodeSdV1.cd_Fault ; |
| | | |
| | | |
| | | @Autowired |
| | | private CdSv sv ; |
| | | /** |
| | |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "clear", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> send(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | BaseResponse<Object> res ; |
| | |
| | | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); |
| | | if (res == null) { |
| | | //发送命令前-3:保存命令日志 |
| | | CdParam comParam = CdParam.builder().commandCode(ComCode).build(); |
| | | CdParam comParam = CdParam.builder().no(ctrlPo.no).startTrueStopFalse(true).build(); |
| | | res = super.pre3(sv, dto.manureId, dto.getOperator(), Protocol, ProtocolVersion, ComCode, comParam); |
| | | if (res == null) { |
| | | //发送命令前-4:准备Feature |
| | | super.pre4(); |
| | | try { |
| | | //创建外部命令(发给控制器) |
| | | Command com = sv.createOuterCommand(ctrlPo.fboxId, "" + comId, ComCode); |
| | | //创建外部命令(发给MQTT->FBox) |
| | | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); |
| | | com.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | com.param = comParam ; |
| | | //发送命令 |
| | |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @SuperBuilder |
| | | public class CdParam extends Cd4MqttParameter { |
| | | //启停动作,true是,false否 |
| | | //可以执行功能码 00,01,02,03的动作 |
| | | public boolean startTrueStopFalse;// |
| | | |
| | | } |
| | |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrRemote.common.dto.Dto4MqttBase; |
| | | import com.dy.pipIrrRemote.monitor.common.Com4MqttCtrl; |
| | | import com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.validation.Valid; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "远程命令", description = "清除故障") |
| | | @Tag(name = "远程命令", description = "注肥启停") |
| | | @RestController("mqttSd1InjectCtrl") |
| | | @RequestMapping(path = "mqttSd1/injectCtrl") |
| | | @RequestMapping(path = "mqttSd1/inject") |
| | | @RequiredArgsConstructor |
| | | @Scope("prototype") //因为有对象类属性,所以采用原型模式,每次请求新建一个实例对象 |
| | | public class CdCtrl extends Com4MqttCtrl { |
| | |
| | | |
| | | @Autowired |
| | | private CdSv sv ; |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "start", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> send(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | public BaseResponse<Object> start(@RequestBody @Valid com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, true) ; |
| | | } |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "stop", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> stop(@RequestBody @Valid com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | private BaseResponse<Object> send(CdDto dto, BindingResult bindingResult, boolean startTrueStopFalse) { |
| | | BaseResponse<Object> res ; |
| | | //发送命令前-1:验证 |
| | | res = super.pre1(sv, ComCode, dto, bindingResult); |
| | |
| | | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); |
| | | if (res == null) { |
| | | //发送命令前-3:保存命令日志 |
| | | CdParam comParam = CdParam.builder().commandCode(ComCode).build(); |
| | | CdParam comParam = CdParam.builder().no(ctrlPo.no).startTrueStopFalse(true).build(); |
| | | res = super.pre3(sv, dto.manureId, dto.getOperator(), Protocol, ProtocolVersion, ComCode, comParam); |
| | | if (res == null) { |
| | | //发送命令前-4:准备Feature |
| | | super.pre4(); |
| | | try { |
| | | //创建外部命令(发给控制器) |
| | | Command com = sv.createOuterCommand(ctrlPo.fboxId, "" + comId, ComCode); |
| | | //创建外部命令(发给MQTT->FBox) |
| | | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); |
| | | com.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | com.param = comParam ; |
| | | //发送命令 |
| | |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @SuperBuilder |
| | | public class CdParam extends Cd4MqttParameter { |
| | | //启停动作,true是,false否 |
| | | //可以执行功能码 00,01,02,03的动作 |
| | | public boolean startTrueStopFalse;// |
| | | |
| | | } |
| | |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrRemote.common.dto.Dto4MqttBase; |
| | | import com.dy.pipIrrRemote.monitor.common.Com4MqttCtrl; |
| | | import com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.validation.Valid; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | * @Author: liurunyu |
| | | * @Date: 2025/6/16 17:35 |
| | | * @Description |
| | | * 大禹将水肥机应用于管灌系统,所以水肥机上未安装灌溉阀门,相应此功能也不应用了 |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "远程命令", description = "清除故障") |
| | | @Tag(name = "远程命令", description = "灌溉启停") |
| | | @RestController("mqttSd1IrrCtrl") |
| | | @RequestMapping(path = "mqttSd1/irrCtrl") |
| | | @RequestMapping(path = "mqttSd1/irr") |
| | | @RequiredArgsConstructor |
| | | @Scope("prototype") //因为有对象类属性,所以采用原型模式,每次请求新建一个实例对象 |
| | | public class CdCtrl extends Com4MqttCtrl { |
| | |
| | | |
| | | @Autowired |
| | | private CdSv sv ; |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "start", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> send(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | public BaseResponse<Object> start(@RequestBody @Valid com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, true) ; |
| | | } |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "stop", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> stop(@RequestBody @Valid com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, false) ; |
| | | } |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | private BaseResponse<Object> send(CdDto dto, BindingResult bindingResult, boolean startTrueStopFalse) { |
| | | BaseResponse<Object> res ; |
| | | //发送命令前-1:验证 |
| | | res = super.pre1(sv, ComCode, dto, bindingResult); |
| | |
| | | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); |
| | | if (res == null) { |
| | | //发送命令前-3:保存命令日志 |
| | | CdParam comParam = CdParam.builder().commandCode(ComCode).build(); |
| | | CdParam comParam = CdParam.builder().no(ctrlPo.no).startTrueStopFalse(true).build(); |
| | | res = super.pre3(sv, dto.manureId, dto.getOperator(), Protocol, ProtocolVersion, ComCode, comParam); |
| | | if (res == null) { |
| | | //发送命令前-4:准备Feature |
| | | super.pre4(); |
| | | try { |
| | | //创建外部命令(发给控制器) |
| | | Command com = sv.createOuterCommand(ctrlPo.fboxId, "" + comId, ComCode); |
| | | //创建外部命令(发给MQTT->FBox) |
| | | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); |
| | | com.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | com.param = comParam ; |
| | | //发送命令 |
| | |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @SuperBuilder |
| | | public class CdParam extends Cd4MqttParameter { |
| | | //启停动作,true是,false否 |
| | | //可以执行功能码 00,01,02,03的动作 |
| | | public boolean startTrueStopFalse;// |
| | | |
| | | } |
| | |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.pipIrrRemote.common.dto.Dto4MqttBase; |
| | | import com.dy.pipIrrRemote.monitor.common.Com4MqttCtrl; |
| | | import com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import jakarta.validation.Valid; |
| | | import lombok.RequiredArgsConstructor; |
| | |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "远程命令", description = "清除故障") |
| | | @Tag(name = "远程命令", description = "设置参数") |
| | | @RestController("mqttSd1ParamCtrl") |
| | | @RequestMapping(path = "mqttSd1/paramCtrl") |
| | | @RequestMapping(path = "mqttSd1/param") |
| | | @RequiredArgsConstructor |
| | | @Scope("prototype") //因为有对象类属性,所以采用原型模式,每次请求新建一个实例对象 |
| | | public class CdCtrl extends Com4MqttCtrl { |
| | |
| | | |
| | | @Autowired |
| | | private CdSv sv ; |
| | | |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "set", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> send(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | public BaseResponse<Object> set(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | BaseResponse<Object> res ; |
| | | //发送命令前-1:验证 |
| | | res = super.pre1(sv, ComCode, dto, bindingResult); |
| | |
| | | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); |
| | | if (res == null) { |
| | | //发送命令前-3:保存命令日志 |
| | | CdParam comParam = CdParam.builder().commandCode(ComCode).build(); |
| | | CdParam comParam = CdParam.builder().no(ctrlPo.no).injectDuration(dto.injectDuration).stirDuration(dto.stirDuration).build(); |
| | | res = super.pre3(sv, dto.manureId, dto.getOperator(), Protocol, ProtocolVersion, ComCode, comParam); |
| | | if (res == null) { |
| | | //发送命令前-4:准备Feature |
| | | super.pre4(); |
| | | try { |
| | | //创建外部命令(发给控制器) |
| | | Command com = sv.createOuterCommand(ctrlPo.fboxId, "" + comId, ComCode); |
| | | //创建外部命令(发给MQTT->FBox) |
| | | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); |
| | | com.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | com.param = comParam ; |
| | | //发送命令 |
| | |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @SuperBuilder |
| | | public class CdParam extends Cd4MqttParameter { |
| | | |
| | | // 搅拌设定时间 |
| | | public Integer stirDuration ; |
| | | |
| | | // 注肥设定时间 |
| | | public Integer injectDuration ; |
| | | } |
| | |
| | | */ |
| | | |
| | | @Slf4j |
| | | @Tag(name = "远程命令", description = "清除故障") |
| | | @Tag(name = "远程命令", description = "搅拌启停") |
| | | @RestController("mqttSd1StirCtrl") |
| | | @RequestMapping(path = "mqttSd1/stirCtrl") |
| | | @RequiredArgsConstructor |
| | |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @PostMapping(path = "start", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> send(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | public BaseResponse<Object> start(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, true) ; |
| | | } |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | @PostMapping(path = "stop", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | @SsoAop() |
| | | public BaseResponse<Object> stop(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { |
| | | return this.send(dto, bindingResult, false) ; |
| | | } |
| | | /** |
| | | * 向设备(Mqtt中间件->FBox)发送命令 |
| | | * @param dto 前端发来的值对象 |
| | | * @param bindingResult 对dto验证的结果 |
| | | * @return 返回前端 |
| | | */ |
| | | private BaseResponse<Object> send(CdDto dto, BindingResult bindingResult, boolean startTrueStopFalse) { |
| | | BaseResponse<Object> res ; |
| | | //发送命令前-1:验证 |
| | | res = super.pre1(sv, ComCode, dto, bindingResult); |
| | |
| | | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); |
| | | if (res == null) { |
| | | //发送命令前-3:保存命令日志 |
| | | CdParam comParam = CdParam.builder().commandCode(ComCode).build(); |
| | | CdParam comParam = CdParam.builder().no(ctrlPo.no).startTrueStopFalse(startTrueStopFalse).build(); |
| | | res = super.pre3(sv, dto.manureId, dto.getOperator(), Protocol, ProtocolVersion, ComCode, comParam); |
| | | if (res == null) { |
| | | //发送命令前-4:准备Feature |
| | | super.pre4(); |
| | | try { |
| | | //创建外部命令(发给控制器) |
| | | Command com = sv.createOuterCommand(ctrlPo.fboxId, "" + comId, ComCode); |
| | | //创建外部命令(发给MQTT->FBox) |
| | | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); |
| | | com.rtuResultSendWebUrl = rtuResultSendWebUrl; |
| | | com.param = comParam ; |
| | | //发送命令 |
| | |
| | | package com.dy.pipIrrRemote.monitor.mqttSd1.stir; |
| | | |
| | | import com.dy.pipIrrRemote.common.dto.Dto4MqttBase; |
| | | import jakarta.validation.constraints.NotNull; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | |
| | | @EqualsAndHashCode(callSuper=true) |
| | | public class CdDto extends Dto4MqttBase { |
| | | public static final long serialVersionUID = 202506201655001L; |
| | | |
| | | // 搅拌设定时间 单位秒 |
| | | @NotNull(message = "搅拌设定时间不能为空") |
| | | public Integer stirDuration ; |
| | | |
| | | // 注肥设定时间 单位秒 |
| | | @NotNull(message = "注肥设定时间不能为空") |
| | | public Integer injectDuration ; |
| | | } |
| | |
| | | @EqualsAndHashCode(callSuper = true) |
| | | @SuperBuilder |
| | | public class CdParam extends Cd4MqttParameter { |
| | | //启停动作,true是,false否 |
| | | //可以执行功能码 00,01,02,03的动作 |
| | | public boolean startTrueStopFalse;// |
| | | |
| | | } |