package info.aspirecn.iov.sjjh.action; import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject; import info.aspirecn.iov.sjjh.commons.lang.Constant; import info.aspirecn.iov.sjjh.constant.Constants; import info.aspirecn.iov.sjjh.service.VehicleService; import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.codec.binary.Base64; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import javax.servlet.http.HttpServletRequest; /** * @author xusonglin * @version V1.0 **/ @Slf4j @RestController public class VehicleAction { @Autowired private VehicleService vehicleService; @ApiOperation(value = "车辆历史轨迹接口", notes = "") @PostMapping(value = "/vehicleHistoryPositionQuery.do") public ChannelTypeHandleResponseObject vehicleHistoryPositionQuery( @ApiParam(value="通道ID")@RequestHeader(name="channelId") String channelId, @ApiParam(value="超时时间,单位:毫秒",example = "10000")@RequestParam(name = "outTime", required = true) int outTime, @ApiParam(value="请求参数JSON串")@RequestParam(name = "customBody", required = true) String customBody) { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); //调用service ChannelTypeHandleResponseObject ret = vehicleService.vehicleHistoryPositionQuery(request, customBody, outTime); //把接口参数、调用结果和是否收费放入访问日志中 if(ret.getCode() != Constant.SUCCESS) { request.setAttribute(Constants.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_ERROR_CODE); } else { request.setAttribute(Constants.Charge_Log_ResponseCode, Constant.CHANNEL_LOG_SUCCESS_CODE); } request.setAttribute(Constants.Charge_Log_Key, ret.getIsCharge()); try { request.setAttribute(Constant.CHANNEL_LOG_QUERY, Base64.encodeBase64String(customBody.getBytes(Constants.ENCODING))); } catch (Exception ex) { ErrorUtils.captureException(ex); log.error("vehicleHistoryPositionQuery.encodeBase64String.Exception={}", ex); } request.setAttribute(Constant.CHANNEL_TYPE_KEY,Constant.CHANNEL_TYPE_SYNC); return ret; } }