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.kuaidi100.dto.SubscribeResp;
import com.prolog.rdc.tms.model.vo.KD100VO;
import com.prolog.rdc.tms.service.KD100Service;
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 javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 
 *
 * 快递100接口控制层
 *
 * @className :ShipbillController
 * @author :fanzw
 * @creationTime :2022/11/08
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/11/08
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "快递100接口调用")
@RestController
@RequestMapping("/kuaiDi100")
public class KD100Controller {

	@Autowired
	private KD100Service service;

	@UserLog("启运登记订阅")
	@ApiOperation(value = "启运登记订阅", notes = "启运登记订阅")
	@PostMapping("/pickUpSubscribe")
	public RestMessage<Object> pickUpSubscribeExecute(@RequestBody List<KD100VO> vos) {
		try {
			log.info("======启运登记订阅接口调用开始:{}", JSONObject.toJSONString(vos));
			service.pickUpSubscribe(vos);
			log.info("======启运登记订阅接口调用结束======");
			return RestMessage.newInstance(true, "启运登记订阅成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======启运登记订阅异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "启运登记订阅失败:" + e.getMessage(), null);
		}
	}

	@UserLog("运单路由接收")
	@ApiOperation(value = "运单路由接收", notes = "运单路由接收")
	@PostMapping("/shipBillRouteReceive")
	public RestMessage<SubscribeResp> shipBillRouteReceiveExecute(HttpServletRequest request) {
		try {
			log.info("======运单路由接收开始:{}", request);
			SubscribeResp resp = service.shipBillRouteReceive(request);
			log.info("======运单路由接收结束======");
			return RestMessage.newInstance(true, "运单路由接收成功", resp);
		} catch (Exception e) {
			e.printStackTrace();
			log.info("======运单路由接收异常:{}", e.getMessage());
			return RestMessage.newInstance(false, "运单路由接收失败:" + e.getMessage(), null);
		}
	}

}
