package com.muyu.controller; import com.muyu.common.Config; import com.muyu.common.Response; import com.muyu.netty.log.NettyClientLogQueue; import com.muyu.netty.operate.NettyClientMsg; import com.muyu.pojo.Vehicle; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; /** * @author 牧鱼 * @Classname VehicleController * @Description 车辆状态controller方法 * @Date 2021/12/8 16:45 */ @RestController @RequestMapping("/vehicle") public class VehicleController { /** * 查看状态 * @return */ @GetMapping public Response getVehicle(){ return Response.success(Config.VEHICLE); } /** * 开启 * @return */ @GetMapping("/start") public Response startVehicle(){ if (Config.ctx == null){ return Response.error("未连接netty服务器"); } Config.VEHICLE.setStatus(1); NettyClientMsg.sendMsg(Config.VEHICLE_START_SUF+Config.VIN); NettyClientLogQueue.add("
发送车辆启动报文:"+Config.VEHICLE_START_SUF+Config.VIN+"
"); return Response.success(Config.VEHICLE); } /** * 停止 * @return */ @GetMapping("/stop") public Response stopVehicle(){ if (Config.ctx == null){ return Response.error("未连接netty服务器"); } Config.VEHICLE.setStatus(0); NettyClientMsg.sendMsg(Config.VEHICLE_STOP_SUF+Config.VIN); NettyClientLogQueue.add("发送车辆停止报文:"+Config.VEHICLE_STOP_SUF+Config.VIN+"
"); return Response.success(Config.VEHICLE); } }