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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import com.alibaba.fastjson.JSONObject;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.constants.BaseDefineDependencyConstants;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.executePlan.api.execplanTag.service.AtuExecplanTagApiService;
import net.northking.cctp.executePlan.dto.execplanTag.AtuExecplanTagAddDto;
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.*;

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

  @Autowired
  private AtuExecplanTagApiService apiService;

  /**
   * 给执行计划批量打标签
   * @param addDto
   * @return
   */
  @RequiredPermissions("ui-addPlanTagList")
  @ApiOperation(value = "给执行计划批量打标签")
  @PostMapping(value = "/addExecplanTagList",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResponseVO<Integer> addExecplanTagList(@RequestBody @Validated AtuExecplanTagAddDto addDto)
  {
    logger.debug("start addExecplanTagList, param:{}", JSONObject.toJSONString(addDto));

    ResponseVO<Integer> responseVO = apiService.addExecplanTagList(addDto);
    logger.debug("end addExecplanTagList, count:{}", responseVO.getData());
    return responseVO;
  }

  /**
   * Restful接口-delete： 删除执行计划标签
   *
   * @param execplanId 执行计划Id
   * @param tagId 标签Id
   * @return
   */
  @ApiOperation(value = "删除：执行计划标签表")
  @DeleteMapping(
          value = "/deleteByExecplanIdAndTagId",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResponseVO<Integer> deleteByExecplanIdAndTagId(
          @RequestParam String execplanId, @RequestParam Long tagId)
  {
    logger.debug("start deleteByExecplanIdAndTagId, execplanId:{}, tagId:{}", execplanId, tagId);
    ResponseVO<Integer> responseVO = new ResponseVO<>();
    Integer count = apiService.deleteByExecplanIdAndTagId(execplanId,tagId);
    logger.debug("end deleteByExecplanIdAndTagId, count:{}", count);
    responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
    responseVO.setData(count);
    return responseVO;
  }
}
