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.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.BillDownloadVO;
import com.prolog.rdc.tms.model.vo.IntfShipbillHeaderVO;
import com.prolog.rdc.tms.service.ShipbillService;

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

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

	@Autowired
	private ShipbillService shipbillService;

	@UserLog("运单接口保存")
	@ApiOperation(value = "运单接口保存", notes = "运单接口保存")
	@PostMapping("/save")
	public RestMessage<Object> saveShipbillExecute(@RequestBody IntfShipbillHeaderVO intfShipbillHeaderVO) {
		try {
			log.info("======运单接口保存开始:{}", JSONObject.toJSONString(intfShipbillHeaderVO));
			String results = shipbillService.saveShipbillData(intfShipbillHeaderVO);
			log.info("======运单接口保存结束======");

			if (results == null) {
				return RestMessage.newInstance(true, "运单保存成功", null);
			} else {
				return RestMessage.newInstance(false, results, null);
			}
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======运单接口保存异常:{}", e.getMessage());

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

	@UserLog("TMS运单同步BMS接口")
	@ApiOperation(value = "TMS运单同步BMS接口", notes = "TMS运单同步BMS接口")
	@PostMapping("/bms/save")
	public RestMessage<Object> saveShipbillBmsExecute(@RequestBody List<BillDownloadVO> billDownloadVO) {
		try {
			log.info("======TMS运单同步BMS接口开始======");
			shipbillService.saveShipbillBmsData(billDownloadVO);
			log.info("======TMS运单同步BMS接口结束======");

			return RestMessage.newInstance(true, "同步BMS成功", null);
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======TMS运单同步BMS接口异常======" + e.getMessage());

			return RestMessage.newInstance(false, "TMS运单同步BMS接口失败：" + e.getMessage(), null);
		}
	}

}
