|  |  |  | 
|---|
|  |  |  | package com.dy.pipIrrRemote.monitor.mqttSd1.inject; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.dy.common.aop.SsoAop; | 
|---|
|  |  |  | import com.dy.common.mw.protocol.Command; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.MqttSubMsg; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.CodeSdV1; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.ProtocolConstantSdV1; | 
|---|
|  |  |  | import com.dy.common.mw.protocol4Mqtt.pSdV1.upVos.ManureVo; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.lang.reflect.InvocationHandler; | 
|---|
|  |  |  | import java.lang.reflect.Proxy; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @PostMapping(path = "start", consumes = MediaType.APPLICATION_JSON_VALUE) | 
|---|
|  |  |  | @SsoAop() | 
|---|
|  |  |  | public BaseResponse<Object> start(@RequestBody @Valid com.dy.pipIrrRemote.monitor.mqttSd1.stir.CdDto dto, BindingResult bindingResult) { | 
|---|
|  |  |  | public BaseResponse<Object> start(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { | 
|---|
|  |  |  | return this.send(dto, bindingResult, true) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | public BaseResponse<Object> stop(@RequestBody @Valid CdDto dto, BindingResult bindingResult) { | 
|---|
|  |  |  | return this.send(dto, bindingResult, false) ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | res = super.pre2(sv, Protocol, ProtocolVersion, ComCode, dto, bindingResult); | 
|---|
|  |  |  | if (res == null) { | 
|---|
|  |  |  | //发送命令前-3:保存命令日志 | 
|---|
|  |  |  | CdParam comParam = CdParam.builder().no(ctrlPo.no).startTrueStopFalse(true).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 | 
|---|
|  |  |  | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | //创建外部命令(发给MQTT->FBox) | 
|---|
|  |  |  | Command com = sv.createMQTTCommand(ctrlPo.fboxId, "" + comId, Protocol, ProtocolVersion, ComCode); | 
|---|
|  |  |  | com.rtuResultSendWebUrl = rtuResultSendWebUrl; | 
|---|
|  |  |  | com.rtuResultSendWebUrl = mqttResultSendWebUrl; | 
|---|
|  |  |  | com.param = comParam ; | 
|---|
|  |  |  | //发送命令 | 
|---|
|  |  |  | res = super.doSend(sv, com); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected String dealComResult(String code, JSONObject resultData, Callback callback){ | 
|---|
|  |  |  | protected String dealComResult(String code, MqttSubMsg subMsg, Callback callback){ | 
|---|
|  |  |  | String msg; | 
|---|
|  |  |  | if(resultData != null){ | 
|---|
|  |  |  | log.info(resultData.toString()); | 
|---|
|  |  |  | JSONObject codeData = resultData.getJSONObject("data") ; | 
|---|
|  |  |  | if(codeData == null){ | 
|---|
|  |  |  | if(subMsg != null){ | 
|---|
|  |  |  | if(subMsg.vo4Up != null && Proxy.isProxyClass(subMsg.vo4Up.getClass())){ | 
|---|
|  |  |  | // 获取代理的 InvocationHandler | 
|---|
|  |  |  | InvocationHandler handler = Proxy.getInvocationHandler(subMsg.vo4Up); | 
|---|
|  |  |  | String json = JSON.toJSONString(handler) ; | 
|---|
|  |  |  | ManureVo vo = JSON.parseObject(json, ManureVo.class); | 
|---|
|  |  |  | msg = vo.toString() ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | msg = RtuSuccessMsg ; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | String json = codeData.toJSONString(); | 
|---|
|  |  |  | ManureVo cvo = JSON.parseObject(json, ManureVo.class) ; | 
|---|
|  |  |  | if(cvo != null){ | 
|---|
|  |  |  | msg = cvo.toString() ; | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | msg = RtuSuccessMsg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | msg = RtuSuccessMsg ; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return msg; | 
|---|
|  |  |  | }} | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|