package com.prolog.rdc.tms.controller;

import java.util.List;

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.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.model.dto.ShipbillNodeTrackingDTO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingListVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingRollbackVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveNewVO;
import com.prolog.rdc.tms.model.vo.ShipbillNodeTrackingSaveVO;
import com.prolog.rdc.tms.service.ShipbillNodeTrackingService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 运单节点跟踪控制层
 *
 * @author zhangsj
 * @since 2022-03-31 14:48:32
 */
@RestController
@Api(tags = "运单节点跟踪控制层")
@RequestMapping("/nodeTracking")
public class ShipbillNodeTrackingController {

	@Autowired
	private ShipbillNodeTrackingService service;

	@PostMapping("/list")
	@UserLog("运单节点查看")
	@ApiOperation(value = "运单节点查看", notes = "运单节点查看")
	public RestMessage<List<ShipbillNodeTrackingDTO>> listShipbillNodeTrackingExecute(@RequestBody ShipbillNodeTrackingListVO shipbillNodeTrackingListVO) {
		try {
			List<ShipbillNodeTrackingDTO> list = service.listShipbillNodeTrackingData(shipbillNodeTrackingListVO);
			return RestMessage.newInstance(true, "查询成功", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/add")
	@UserLog("运单节点新增")
	@ApiOperation(value = "运单节点新增", notes = "运单节点新增")
	public RestMessage<Object> addShipbillNodeTrackingExecute(@RequestBody ShipbillNodeTrackingSaveVO vo) {
		try {
			service.addShipbillNodeTrackingData(vo);
			return RestMessage.newInstance(true, "新增成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/add_new")
	@UserLog("运单节点新增(新)")
	@ApiOperation(value = "运单节点新增(新)", notes = "运单节点新增(新)")
	public RestMessage<Object> addShipbillNodeTrackingNewExecute(@RequestBody ShipbillNodeTrackingSaveNewVO vo) {
		try {
			service.addShipbillNodeTrackingNewData(vo);
			return RestMessage.newInstance(true, "新增成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/rollback")
	@UserLog("运单节点回退")
	@ApiOperation(value = "运单节点回退", notes = "运单节点回退")
	public RestMessage<Object> rollbackShipbillNodeTrackingExecute(@RequestBody ShipbillNodeTrackingRollbackVO vo) {
		try {
			service.rollbackShipbillNodeTracking(vo);
			return RestMessage.newInstance(true, "回退成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
