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.IntfProviderShipperSaveVO;
import com.prolog.rdc.tms.service.ProviderShipperService;

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

/**
 * 
 *
 * 供应商发货方接口控制层
 *
 * @className :ProviderShipperController
 * @author :fanzw
 * @creationTime :2022/11/14
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2022/11/14
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "供应商发货方接口控制层")
@RestController
@RequestMapping("/providerShipper")
public class ProviderShipperController {

	@Autowired
	private ProviderShipperService providerShipperService;

	@UserLog("供应商发货方接口保存")
	@ApiOperation(value = "供应商发货方接口保存", notes = "供应商发货方接口保存")
	@PostMapping("/save")
	public RestMessage<Object> saveProviderShipperExecute(@RequestBody List<IntfProviderShipperSaveVO> intfProviderShipperSaveVOs) {
		try {
			log.info("======供应商发货方接口保存开始:{}", JSONObject.toJSONString(intfProviderShipperSaveVOs));
			providerShipperService.saveProviderShipperData(intfProviderShipperSaveVOs);
			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("/timer")
	public RestMessage<Object> providerShipperTimerTaskExecute() {
		try {
			log.info("======供应商发货方接口定时任务开始======");
			providerShipperService.providerShipperTimerTask();
			log.info("======供应商发货方接口定时任务结束======");
			return RestMessage.newInstance(true, "供应商发货方接口定时任务执行成功", null);
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======供应商发货方接口定时任务执行异常:{}", e.getMessage());

			return RestMessage.newInstance(false, "供应商发货方接口定时任务执行失败:" + e.getMessage(), null);
		}
	}

}
