package com.stylefeng.guns.modular.api; import com.stylefeng.guns.modular.system.model.OrderPosition; import com.stylefeng.guns.modular.system.service.IDriverService; import com.stylefeng.guns.modular.system.service.INettyService; import com.stylefeng.guns.modular.system.util.PushUtil; import com.stylefeng.guns.modular.system.util.ResultUtil; import com.stylefeng.guns.modular.system.warpper.OrderStatusWarpper; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.List; /** * 替换socket无法正常连接的备选方案 * 通过前端主动调用接口上传数据或者获取需要下发的数据 */ @RestController @RequestMapping("") public class NettyController { @Autowired private INettyService nettyService; @Autowired private IDriverService driverService; @Autowired private PushUtil pushUtil; /** * 司机端主动调用该接口上传位置信息 * @param request * @return */ @ResponseBody @PostMapping("/api/netty/positionSocket") @ApiOperation(value = "司机端主动调用该接口上传位置信息", tags = {"司机端-仿socket接口"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(value = "订单id", name = "orderId", required = false, dataType = "int"), @ApiImplicitParam(value = "订单类型(1=专车,2=快车,3=城际,4=小件物流-同城,5=小件物流-跨城)", name = "orderType", required = false, dataType = "int"), @ApiImplicitParam(value = "经度", name = "lon", required = true, dataType = "string"), @ApiImplicitParam(value = "纬度", name = "lat", required = true, dataType = "string"), @ApiImplicitParam(value = "方向角", name = "directionAngle", required = true, dataType = "string"), @ApiImplicitParam(value = "海拔", name = "altitude", required = true, dataType = "string"), @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil positionSocket(OrderPosition orderPosition, HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return nettyService.positionSocket(orderPosition, uid); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 删除服务中的定时任务 * @param orderId * @param orderType * @return */ @ResponseBody @PostMapping("/base/netty/deleteTask") public ResultUtil deleteTask(Integer orderId, Integer orderType){ try { pushUtil.removeTask(orderId, orderType); return ResultUtil.success(); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } /** * 主动调用获取订单状态 * @param request * @return */ @ResponseBody @PostMapping("/api/netty/orderStateSocket") @ApiOperation(value = "主动调用获取订单状态", tags = {"司机端-仿socket接口"}, notes = "") @ApiImplicitParams({ @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") }) public ResultUtil> orderStateSocket(HttpServletRequest request){ try { Integer uid = driverService.getUserIdFormRedis(request); if(null == uid){ return ResultUtil.tokenErr(); } return nettyService.orderStateSocket(uid); }catch (Exception e){ e.printStackTrace(); return ResultUtil.runErr(); } } }