/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
*
*/
package net.northking.cctp.executePlan.api;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.executePlan.api.service.AtuPlanInfoApiService;
import net.northking.cctp.executePlan.api.service.AtuPlanTaskApiService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 执行计划表 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "执行计划表")
@RequestMapping("/v1/batch/execPlan")
@RestController
public class AtuPlanInfoBatchCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(AtuPlanInfoBatchCtrl.class);

  @Autowired
  private AtuPlanInfoApiService apiService;

  @Autowired
  private AtuPlanTaskApiService taskApiService;

  /**
   * Restful接口-post： 批量克隆执行计划表
   *
   * @param batch 集合
   * @return 成功的数量
   */
  @RequiredPermissions("ui-clonePlan")
  @ApiOperation(value = "批量克隆：执行计划表")
  @PostMapping(
      value = "/clone",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> clonePlan(
      @RequestBody @Validated List<String> batch)
  {
    logger.info("start clonePlan: params =======> " + JSONUtil.toJsonStr(batch));

    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = this.apiService.clonePlan(batch);

    logger.info("end clonePlan ");

    return wrapper.success(count);
  }

}
