package com.prolog.rdc.tms.controller;

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 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.vo.GpsDataStrVO;
import com.prolog.rdc.tms.service.GpsDataWritingService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 *
 * GPS数据接口控制层 畅行北斗GPS
 * 
 * @className :GpsDataWritingController
 * @author :fanzw
 * @creationTime :2022/12/29
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/12/29
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "GPS数据接口控制层")
@RestController
@RequestMapping("/gpsData")
public class GpsDataWritingController {

	@Autowired
	private GpsDataWritingService gpsDataWritingService;

	@UserLog("GPS数据保存")
	@ApiOperation(value = "GPS数据保存", notes = "GPS数据保存")
	@PostMapping("/save")
	public RestMessage<Object> saveGpsDataWritingExecute(@RequestBody GpsDataStrVO gpsDataStrVO) {
		try {
			log.info("======GPS数据保存开始:{}", JSONObject.toJSONString(gpsDataStrVO));
			gpsDataWritingService.saveGpsDataWritingData(gpsDataStrVO);
			log.info("======GPS数据保存结束======");
			return RestMessage.newInstance(true, "GPS数据保存成功", null);
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======GPS数据保存异常:{}", e.getMessage());

			return RestMessage.newInstance(false, "GPS数据保存失败:" + e.getMessage(), null);
		}
	}

	@UserLog("GPS数据处理定时任务")
	@ApiOperation(value = "GPS数据处理定时任务", notes = "GPS数据处理定时任务")
	@PostMapping("/timer")
	public RestMessage<Object> timerTaskExecute() {
		try {
			log.info("======GPS数据处理定时任务开始======");
			gpsDataWritingService.timerTaskData();
			log.info("======GPS数据处理定时任务结束======");
			return RestMessage.newInstance(true, "GPS数据处理定时任务执行成功", null);
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======GPS数据处理定时任务执行异常:{}", e.getMessage());

			return RestMessage.newInstance(false, "GPS数据处理定时任务执行失败:" + e.getMessage(), null);
		}
	}

}
