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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import com.hzbank.testteam.autotest.dependencies.authDependency.constants.AuthDependencyConstants;
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 io.swagger.annotations.ApiParam;
import net.northking.cctp.common.db.Pagination;
import net.northking.cctp.common.dto.AdvancedQueryOptions;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.scriptcase.api.component.service.MdBusComponentInfoApiService;
import net.northking.cctp.scriptcase.dto.component.MdBusComponentInfoDetailDto;
import net.northking.cctp.scriptcase.dto.component.MdBusComponentInfoQueryDto;
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;
import java.util.Map;

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

  @Autowired
  private MdBusComponentInfoApiService apiService;

  /**
   * 分页查询 业务组件表_发布 列表
   *
   * @param queryByPage  查询条件
   * @return 数据列表
   */
  @ApiOperation(value = "分页查询列表：业务组件表_发布")
  @RequiredPermissions("busCompMange")
  @PostMapping(value = "/paging/query/MdBusComponentInfos",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
      consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Pagination<MdBusComponentInfoDetailDto>> pagingQuery(
      @RequestBody @Validated QueryByPage<MdBusComponentInfoQueryDto> queryByPage)
  {
    ResultWrapper<Pagination<MdBusComponentInfoDetailDto>> wrapper = new ResultWrapper<>();
    Pagination<MdBusComponentInfoDetailDto> page = apiService.pagingQuery(queryByPage);

    return wrapper.success(page);
  }

  @ApiOperation(value = "feign调用:查询业务组件名称")
  @PostMapping(value = "/query/busComNameMap")
  public ResultWrapper<Map<String, String>> queryBusComNameMap(@RequestBody List<String> comIdList){
    ResultWrapper<Map<String, String>> wrapper = new ResultWrapper<>();
    Map<String, String> map = apiService.queryComNameByIdList(comIdList);

    return wrapper.success(map);
  }

    @ApiOperation(value = "获取高级查询相关配置数据:创建人，更新人，责任人")
    @GetMapping(value = "/MdBusComponentInfos/advancedQueryOptions")
    public ResponseVO<AdvancedQueryOptions> advancedQueryOptions(
            @ApiParam(value = "系统ID", required = true, example = "36602691803153920")
            @RequestHeader(AuthDependencyConstants.REQUEST_HEADER_PROJECT_ID) String projectId) {
      logger.debug("start advancedQueryOptions");
      ResponseVO<AdvancedQueryOptions> responseVO = new ResponseVO<>();
      AdvancedQueryOptions result = apiService.advancedQueryOptions(projectId);
      responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
      responseVO.setData(result);
      responseVO.setMessage("获取成功");
      logger.debug("end advancedQueryOptions");
      return responseVO;
    }
}


