| | |
| | | package com.dy.aceMw.web.com; |
| | | |
| | | import com.dy.aceMw.server.ServerProperties; |
| | | import com.dy.aceMw.server.forTcp.TcpSessionCache; |
| | | import com.dy.aceMw.server.local.CommandInnerDeaLer; |
| | | import com.dy.aceMw.server.local.ReturnCommand; |
| | |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | |
| | | /** |
| | |
| | | @RequestMapping(path="com") |
| | | @SuppressWarnings("unchecked")//java版本越高,对泛型约束越严,所以配置SuppressWarnings("unchecked") |
| | | public class CommandCtrl { |
| | | |
| | | @GetMapping(path = "test") |
| | | public BaseResponse<String> test(){ |
| | | return BaseResponseUtils.buildSuccess("ok"); |
| | | } |
| | | |
| | | @PostMapping(path = "send", consumes = MediaType.APPLICATION_JSON_VALUE) |
| | | public BaseResponse<Command> send(@RequestBody Command com) { |
| | |
| | | if(onLine == null){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")未上线!", command.getId(), command.getCode())) ; |
| | | }else if(!onLine.booleanValue()){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")离线!", command.getId(), command.getCode())) ; |
| | | if(!ServerProperties.isLowPower){ |
| | | return BaseResponseUtils.buildError(ReturnCommand.errored("出错,RTU(地址=" + rtuAddr + ")离线!", command.getId(), command.getCode())) ; |
| | | } |
| | | } |
| | | |
| | | //生成异步任务 |
| | |
| | | return BaseResponseUtils.buildSuccess(ReturnCommand.successed("命令已接受,即将构造并下发命令。", command.getId(), command.getCode())); |
| | | } |
| | | |
| | | /** |
| | | * 收到命令结果 |
| | | * @param command |
| | | private void dealCommandResult(String jgSenderName, Command command){ |
| | | Object obj = command.getParam() ; |
| | | if(obj != null){ |
| | | CommandBackParam p = (CommandBackParam)obj ; |
| | | if(p.getSuccess()){ |
| | | log.info("命令" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "执行成功" |
| | | + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("," + p.getMessage())))); |
| | | }else{ |
| | | log.error("命令" + (command.getId().equals(Command.defaultId)?"":("(id=" + command.getId() + ")")) + "执行失败" |
| | | + (p.getMessage() == null?"":(p.getMessage().equals("")?"":("," + p.getMessage())))); |
| | | } |
| | | } |
| | | } |
| | | */ |
| | | } |