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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.component.service.MdBusComponentInfoApiService;
import net.northking.cctp.scriptcase.dto.component.*;
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;

@Api(tags = "业务组件表_草稿")
@RequestMapping("/v1/MdBusComInfos")
@RestController
public class MdBusComInfoRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(MdBusComInfoRestfulCtrl.class);

  @Autowired
  private MdBusComponentInfoApiService apiService;

  /**
   * 根据业务组件id查询组件发布信息
   * @param uuid       主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "根据组件id获取详情")
  @GetMapping(
          value = "/{uuid}",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<MdBusComponentInfoDetailDto> findByPK(
          @PathVariable("uuid") String uuid)
  {
    ResultWrapper<MdBusComponentInfoDetailDto> wrapper = new ResultWrapper<>();
    MdBusComponentInfoDetailDto dto = apiService.findByPK(uuid);
    return wrapper.success(dto);
  }

  /**
   * Restful接口-put： 修改业务组件表内容
   *
   * @param inputDto         接口数据传输对象
   * @return 修改业务组件表内容
   */
  @ApiOperation(value = "更新：业务组件内容")
  @RequiredPermissions({"ui-updateComInfos","busScriptRecord"})
  @PutMapping(
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> update(
          @RequestBody @Validated MdBusComponentInfoUpdateDto inputDto) throws IllegalAccessException
  {
    logger.debug("更新：业务组件内容 start");
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.updateByPK(inputDto);
    logger.debug("更新：业务组件内容 end");
    return wrapper.success(count);
  }

  /**
   * 批量删除业务组件
   */
  @ApiOperation(value = "批量删除业务组件")
  @RequiredPermissions({"ui-deleteComInfos","ui-busCompBatchDel"})
  @PostMapping(
          value = "/deleteByIds",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteByIds(
          @RequestBody @Validated List<String> ids)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int dto = apiService.deleteByIds(ids);
    return wrapper.success(dto);
  }


  /**
   * 批量克隆业务组件
   */
  @ApiOperation(value = "批量克隆业务组件")
  @RequiredPermissions("ui-copyComInfos")
  @PostMapping(
          value = "/copyByIds",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> copyByIds(
          @RequestBody @Validated MdBusComCopyDto target)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int num =  apiService.copyById(target);
    return wrapper.success(num);
  }

  /**
   * 业务组件入组件库
   */
  @ApiOperation(value = "业务组件共享")
  @RequiredPermissions("ui-busComListToLib")
  @PostMapping(
          value = "/busComListToLib",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> busComListToLib(
          @RequestBody @Validated MdBusComCopyDto dto)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int num = apiService.busComListToLib(dto);
    return wrapper.success(num);
  }

  /**
   * 业务组件入组件库
   */
  @ApiOperation(value = "批量修改业务组件库")
  @RequiredPermissions("ui-updateComInfosByBatch")
  @PostMapping(
          value = "/updateByBatch",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> updateByBatch(
          @RequestBody @Validated MdBusComCopyDto dto)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int num = apiService.updateByBatch(dto);
    return wrapper.success(num);
  }

  /**
   * 业务组件入组件库
   */
  @ApiOperation(value = "取消业务组件共享")
  @RequiredPermissions("ui-busComCancelShared")
  @PostMapping(
          value = "/busComCancelShared",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> busComCancelShared(
          @RequestBody @Validated MdBusComCopyDto dto)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    int num = apiService.busComCancelShared(dto);
    return wrapper.success(num);
  }

}


