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

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

/**
 * 
 *
 * 客户收货方接口控制层
 *
 * @className :CustomerConsigneeController
 * @author :fanzw
 * @creationTime :2023/02/02
 * @description :
 *
 * @modifier :fanzw
 * @modifyTime :2023/02/02
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "客户收货方接口控制层")
@RestController
@RequestMapping("/customerConsignee")
public class CustomerConsigneeController {

	@Autowired
	private CustomerConsigneeService service;

	@UserLog("客户收货方接口保存")
	@ApiOperation(value = "客户收货方接口保存", notes = "客户收货方接口保存")
	@PostMapping("/save")
	public RestMessage<Object> saveCustomerConsignee(@RequestBody List<IntfCustomerConsigneeSaveVO> vos) {
		try {
			log.info("======客户收货方资料接口保存开始:{}", JSONObject.toJSONString(vos));
			service.saveCustomerConsignee(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("/timer")
	public RestMessage<Object> customerConsigneeTimerTask() {
		try {
			log.info("======客户收货方定时任务开始======");
			service.customerConsigneeTimerTask();
			log.info("======客户收货方定时任务结束======");
			return RestMessage.newInstance(true, "客户收货方定时任务执行成功", null);
		} catch (Exception e) {
			e.printStackTrace();

			log.info("======客户收货方定时任务执行异常:{}", e.getMessage());

			return RestMessage.newInstance(false, "客户收货方定时任务执行失败:" + e.getMessage(), null);
		}
	}

}
