VehicleAction.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package info.aspirecn.iov.sjjh.action;
  2. import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
  3. import info.aspirecn.iov.sjjh.commons.lang.Constant;
  4. import info.aspirecn.iov.sjjh.constant.Constants;
  5. import info.aspirecn.iov.sjjh.service.VehicleService;
  6. import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
  7. import io.swagger.annotations.ApiOperation;
  8. import io.swagger.annotations.ApiParam;
  9. import lombok.extern.slf4j.Slf4j;
  10. import org.apache.tomcat.util.codec.binary.Base64;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestHeader;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import org.springframework.web.context.request.RequestContextHolder;
  17. import org.springframework.web.context.request.ServletRequestAttributes;
  18. import javax.servlet.http.HttpServletRequest;
  19. /**
  20. * @author xusonglin
  21. * @version V1.0
  22. **/
  23. @Slf4j
  24. @RestController
  25. public class VehicleAction {
  26. @Autowired
  27. private VehicleService vehicleService;
  28. @ApiOperation(value = "车辆历史轨迹接口", notes = "")
  29. @PostMapping(value = "/vehicleHistoryPositionQuery.do")
  30. public ChannelTypeHandleResponseObject vehicleHistoryPositionQuery(
  31. @ApiParam(value="通道ID")@RequestHeader(name="channelId") String channelId,
  32. @ApiParam(value="超时时间,单位:毫秒",example = "10000")@RequestParam(name = "outTime", required = true) int outTime,
  33. @ApiParam(value="请求参数JSON串")@RequestParam(name = "customBody", required = true) String customBody) {
  34. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes())
  35. .getRequest();
  36. //调用service
  37. ChannelTypeHandleResponseObject ret = vehicleService.vehicleHistoryPositionQuery(request, customBody, outTime);
  38. //把接口参数、调用结果和是否收费放入访问日志中
  39. if(ret.getCode() != Constant.SUCCESS) {
  40. request.setAttribute(Constants.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_ERROR_CODE);
  41. } else {
  42. request.setAttribute(Constants.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_SUCCESS_CODE);
  43. }
  44. request.setAttribute(Constants.Charge_Log_Key, ret.getIsCharge());
  45. try {
  46. request.setAttribute(Constant.CHANNEL_LOG_QUERY,
  47. Base64.encodeBase64String(customBody.getBytes(Constants.ENCODING)));
  48. } catch (Exception ex) {
  49. ErrorUtils.captureException(ex);
  50. log.error("vehicleHistoryPositionQuery.encodeBase64String.Exception={}", ex);
  51. }
  52. request.setAttribute(Constant.CHANNEL_TYPE_KEY,Constant.CHANNEL_TYPE_SYNC);
  53. return ret;
  54. }
  55. }