/*
* 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.BusComponentTreeApiService;
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;

/**
 * 业务组件目录树 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "业务组件目录树")
@RequestMapping("/v1/BusComTrees")
@RestController
public class BusComponentTreeRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(BusComponentTreeRestfulCtrl.class);

  @Autowired
  private BusComponentTreeApiService apiService;

  /**
   * Restful接口-post： 新增业务组件目录树
   *
   * @param inputDto         接口数据传输对象
   * @return 主键
   */
  @ApiOperation(value = "新增：业务组件目录树")
  @RequiredPermissions("ui-saveComTrees")
  @PostMapping(
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<String> add(
      @RequestBody @Validated BusComponentTreeAddDto inputDto)
  {
    ResultWrapper<String> wrapper = new ResultWrapper<>();
    String uuid = apiService.add(inputDto);
    return wrapper.success(uuid);
  }

  /**
   * Restful接口-put： 更新业务组件目录树
   *
   * @param inputDto         接口数据传输对象
   * @return 修改的记录数量
   */
  @ApiOperation(value = "更新：业务组件目录树")
  @RequiredPermissions("ui-updateComTrees")
  @PutMapping(
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> update(
          @RequestBody @Validated BusComponentTreeUpdateDto inputDto) throws IllegalAccessException
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.updateByPK(inputDto);
    return wrapper.success(count);
  }

  /**
   * Restful接口-delete： 删除业务组件目录树
   *
   * @param uuid       主键
   * @return 删除的记录数量
   */
  @ApiOperation(value = "删除：业务组件目录树")
  @RequiredPermissions("ui-deleteComTrees")
  @DeleteMapping(
          value = "/{uuid}",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteByPK(
          @PathVariable("uuid") String uuid)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.deleteByPK(uuid);
    return wrapper.success(count);
  }

  /**
   * 获取业务组件树子级目录
   *
   * @param inputDto       主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "获取业务组件树子级目录")
  @PostMapping(
          value = "/findChildTreeList",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<BusComponentTreeDetailDto>> findChildTreeList(
          @RequestBody @Validated BusComponentTreeQueryDto inputDto)
  {
    ResultWrapper<List<BusComponentTreeDetailDto>> wrapper = new ResultWrapper<>();
    List<BusComponentTreeDetailDto> dto = apiService.findChildTreeList(inputDto);
    return wrapper.success(dto);
  }

  /**
   * 模糊搜索目录列表
   *
   * @param inputDto       主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "模糊查询所有子目录")
  @PostMapping(
          value = "/findChildTreeListLike",
          produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
          consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<List<BusComponentTreeDetailDto>> findChildTreeListLike(
          @RequestBody @Validated BusComponentTreeQueryDto inputDto)
  {
    ResultWrapper<List<BusComponentTreeDetailDto>> wrapper = new ResultWrapper<>();
    List<BusComponentTreeDetailDto> dto = apiService.findChildTreeListLike(inputDto);
    return wrapper.success(dto);
  }

}
