package com.bocloud.ims.booter.controller.scheduler;

import com.bocloud.cmp.model.CloudVendorBean;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.interfaces.scheduler.CloudVendorTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * 定时任务 cron
 *
 * @author ymh
 * @时间 2019年4月8日
 */
@RestController
@RequestMapping("/v1/timedtask")
@Api(value = "定时任务管理", tags = "定时任务管理")
public class CloudVendorTaskController {

	@Autowired
	private CloudVendorTaskService cloudVendorTaskService;

	/**
	 * 添加定时任务
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@PostMapping
	@ApiOperation(tags = { "CMC", "CSC" }, value = "新增定时任务管理")
	public BocloudResult create(@RequestParam(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return cloudVendorTaskService.create(id, context);
	}

	/**
	 * 取消平台定时任务
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@DeleteMapping(value = "/{id}")
	@ApiOperation(tags = { "CMC", "CSC" }, value = "取消定时任务")
	public BocloudResult remove(@PathVariable(value = Common.ID) Long id,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return cloudVendorTaskService.remove(id, context);
	}

	/**
	 * 更新平台定时任务
	 *
	 * @param id
	 * @param context
	 * @return
	 */
	@ApiOperation(tags = { "CMC", "CSC" }, value = "更新平台同步评率")
	@PutMapping(value = "/{id}")
	public BocloudResult modify(@PathVariable(value = Common.ID) Long id, @RequestBody CloudVendorBean cloudVendorBean,
			@Value(Common.REQ_CONTEXT) RequestContext context) {
		return cloudVendorTaskService.modify(cloudVendorBean, context);
	}

}
