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

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

/**
 *
 *
 * 供应商资料接口控制层
 *
 * @className :ProviderController
 * @author :xiaoyf
 * @creationTime :2022/08/12
 * @description :
 *
 * 
 * @version :1.0.0
 *
 */
@Slf4j
@Api(tags = "供应商资料接口控制层")
@RestController
@RequestMapping("/provider")
public class ProviderController {

	@Autowired
	private ProviderService providerService;

	@UserLog("供应商资料接口保存")
	@ApiOperation(value = "供应商资料接口保存", notes = "供应商资料接口保存")
	@PostMapping("/save")
	public RestMessage<Object> saveProviderExecute(@RequestBody List<IntfProviderSaveVO> intfProviderSaveVOs) {
		try {
			log.info("======供应商资料接口保存开始:{}", JSONObject.toJSONString(intfProviderSaveVOs));
			providerService.saveProviderData(intfProviderSaveVOs);
			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> providerTimerTaskExecute() {
		try {
			log.info("======供应商资料接口定时任务开始======");
			providerService.providerTimerTask();
			log.info("======供应商资料接口定时任务结束======");
			return RestMessage.newInstance(true, "供应商资料接口定时任务执行成功", null);
		} catch (Exception e) {
			e.printStackTrace();

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

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

}
