package com.prolog.rdc.tms.controller;

import com.alibaba.fastjson.JSONObject;
import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.*;
import com.prolog.rdc.tms.model.dto.g7.CurrentGpsLocationDTO;
import com.prolog.rdc.tms.model.dto.g7.CurrentTemperatureDTO;
import com.prolog.rdc.tms.model.vo.*;
import com.prolog.rdc.tms.model.vo.g7.CurrentTemperatureVO;
import com.prolog.rdc.tms.model.vo.g7.HistoryLocationByGpsnoVO;
import com.prolog.rdc.tms.service.G7Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
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 java.util.List;

/**
 * 
 *
 * 运单接口控制层
 *
 * @className :ShipbillController
 * @author :fanzw
 * @creationTime :2022/11/08
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/11/08
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "G7设备调用")
@RestController
@RequestMapping("/g7")
public class G7Controller {

	@Autowired
	private G7Service g7Service;

	@UserLog("车辆当前定位V1.0")
	@ApiOperation(value = "车辆当前定位V1.0", notes = "车辆当前定位V1.0")
	@PostMapping("/current_location")
	public RestMessage<List<CurrentLocationDTO>> currentLocationExecute(@RequestBody List<CurrentLocationVO> vos) {
		try {
			log.info("======车辆当前定位查询开始:{}", JSONObject.toJSONString(vos));
			List<CurrentLocationDTO> dtos = g7Service.currentLocationCall(vos);
			log.info("======车辆当前定位查询结束======");
			return RestMessage.newInstance(true, "车辆当前定位查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======车辆当前定位查询异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "车辆当前定位查询失败:" + e.getMessage(), null);
		}
	}

	@UserLog("设备车辆当前温度查询接口")
	@ApiOperation(value = "设备车辆当前温度查询接口", notes = "设备车辆当前温度查询接口")
	@PostMapping("/current_temperature")
	public RestMessage<List<CurrentTemperatureDTO>> currentTemperatureExecute(@RequestBody CurrentTemperatureVO vo) {
		try {
			log.info("======设备车辆当前温度查询开始:{}", JSONObject.toJSONString(vo));
			List<CurrentTemperatureDTO> dtos = g7Service.currentTemperatureCall(vo);
			log.info("======设备车辆当前温度查询结束======");
			return RestMessage.newInstance(true, "设备车辆当前温度查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======设备车辆当前温度查询异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "设备车辆当前温度查询失败:" + e.getMessage(), null);
		}
	}

	@UserLog("设备历史轨迹查询接口")
	@ApiOperation(value = "设备历史轨迹查询接口", notes = "设备历史轨迹查询接口")
	@PostMapping("/history_location_by_gpsno")
	public RestMessage<List<HistoryLocationByGpsnoDTO>> historyLocationByGpsnoExecute(@RequestBody HistoryLocationByGpsnoVO vo) {
		try {
			log.info("======设备历史轨迹查询开始:{}", JSONObject.toJSONString(vo));
			List<HistoryLocationByGpsnoDTO> dtos = g7Service.historyLocationByGpsnoCall(vo);
			log.info("======设备历史轨迹查询结束======");
			return RestMessage.newInstance(true, "设备历史轨迹查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======设备车辆当前温度查询异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "设备历史轨迹查询失败:" + e.getMessage(), null);
		}
	}

	@UserLog("车辆历史轨迹查询接口")
	@ApiOperation(value = "车辆历史轨迹查询接口", notes = "车辆历史轨迹查询接口")
	@PostMapping("/history_location_by_vehicle")
	public RestMessage<List<HistoryLocationByGpsnoDTO>> historyLocationByVehExecute(@RequestBody HistoryLocationByGpsnoVO vo) {
		try {
			log.info("======车辆历史轨迹查询开始:{}", JSONObject.toJSONString(vo));
			List<HistoryLocationByGpsnoDTO> dtos = g7Service.historyLocationByVehCall(vo);
			log.info("======车辆历史轨迹查询结束======");
			return RestMessage.newInstance(true, "车辆历史轨迹查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======车辆车辆当前温度查询异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "车辆历史轨迹查询失败:" + e.getMessage(), null);
		}
	}

	@UserLog("查询车辆事件报表接口")
	@ApiOperation(value = "查询车辆事件报表接口", notes = "查询车辆事件报表接口")
	@PostMapping("/truck_event")
	public RestMessage<List<TruckEventDTO>> truckEventExecute(@RequestBody TruckEventVO vo) {
		try {
			log.info("======查询车辆事件报表开始:{}", JSONObject.toJSONString(vo));
			List<TruckEventDTO> dtos = g7Service.truckEventCall(vo);
			log.info("======查询车辆事件报表结束======");
			return RestMessage.newInstance(true, "查询车辆事件报表成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======查询车辆事件报表异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "查询车辆事件报表失败:" + e.getMessage(), null);
		}
	}

	@UserLog("冷链报警列表接口")
	@ApiOperation(value = "冷链报警列表接口", notes = "冷链报警列表接口")
	@PostMapping("/coldchain_alarm")
	public RestMessage<List<ColdchainAlarmDTO>> coldchainAlarmExecute(@RequestBody ColdchainAlarmVO vo) {
		try {
			log.info("======查询冷链报警列表开始:{}", JSONObject.toJSONString(vo));
			List<ColdchainAlarmDTO> dtos = g7Service.coldchainAlarmCall(vo);
			log.info("======查询冷链报警列表结束======");
			return RestMessage.newInstance(true, "查询冷链报警列表成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======查询冷链报警列表异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "查询冷链报警列表失败:" + e.getMessage(), null);
		}
	}

	@UserLog("设备位置和状态查询")
	@ApiOperation(value = "设备位置和状态查询", notes = "设备位置和状态查询")
	@PostMapping("/simpleCurrentsByGpsnos")
	public RestMessage<List<CurrentGpsLocationDTO>> simpleCurrentsByGpsnos(@RequestBody CurrentTemperatureVO vo) {
		try {
			log.info("======设备位置和状态查询开始:{}", JSONObject.toJSONString(vo));
			List<CurrentGpsLocationDTO> dtos = g7Service.simpleCurrentsByGpsnos(vo);
			log.info("======设备位置和状态查询结束======");
			return RestMessage.newInstance(true, "设备位置和状态查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======设备位置和状态查询异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "设备位置和状态查询失败:" + e.getMessage(), null);
		}
	}
}
