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

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.entity.Environment;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ResponseVO;
import com.hzbank.testteam.autotest.dependencies.monsterDependency.dto.ProjectDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.project.api.project.service.CpProjectApiService;
import net.northking.cctp.project.db.service.CpProjectService;
import net.northking.cctp.project.dto.project.CpProjectEnvOptionDto;
import net.northking.cctp.project.dto.project.CpProjectEnvQueryDto;
import net.northking.cctp.project.dto.project.ProjectSimpleInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;
import java.util.Map;


@Api(tags = "系统基本信息表")
@RequestMapping("/v1")
@RestController
public class CpProjectQueryCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(CpProjectQueryCtrl.class);

    @Autowired
    private CpProjectApiService apiService;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private CpProjectService cpProjectService;


    @ApiOperation(value = "ATS:查询租户下的所有系统")
    @GetMapping(value = "/query/all/project/tenant")
    public ResultWrapper<List<ProjectSimpleInfo>> queryAllProjectByTenant() throws ParseException {
        ResultWrapper<List<ProjectSimpleInfo>> wrapper = new ResultWrapper<>();
        List<ProjectSimpleInfo> result = apiService.queryAllProjectByTenant();

        return wrapper.success(result);
    }

    @ApiOperation(value = "查询能关联设备的系统")
    @GetMapping(value = "/query/device/software/project")
    public ResultWrapper<List<ProjectSimpleInfo>> proQueryDevice() throws ParseException {
        ResultWrapper<List<ProjectSimpleInfo>> wrapper = new ResultWrapper<>();
        List<ProjectSimpleInfo> proList = apiService.queryProByDevice();
        return wrapper.success(proList);
    }
    @ApiOperation(value = "根据系统id查关联的环境id集合")
    @PostMapping(value = "/query/selectEnvIds",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<String> selectEnvIds(@RequestParam("proId") String proId){
        return apiService.selectEnvIds(proId);
    }

    @ApiOperation(value = "查询系统关联的环境排序")
    @PostMapping(value = "/query/envListSeq",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<String> queryEnvListSeq(@RequestParam("proId") String proId){
        return apiService.queryEnvListSeq(proId);
    }

    @ApiOperation(value = "根据系统id查关联的环境信息集合")
    @RequiredPermissions("environment")
    @PostMapping(value = "/query/selectEnvInfos",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResponseVO<Object> selectEnvInfos(@RequestBody QueryByPage<CpProjectEnvQueryDto> cpProjectEnvQueryDto){
        return apiService.getATSProjectEnvVo(cpProjectEnvQueryDto);
    }

    @ApiOperation(value = "查系统下关联的环境信息")
    @GetMapping(value = "/query/selectProjectEnvs")
    public ResultWrapper<List<Environment>> selectProjectEnvs(@RequestParam("proId") String proId){
        ResultWrapper<List<Environment>> wrapper=new ResultWrapper<>();
        return wrapper.success(apiService.selectProjectEnvs(proId));
    }


    @ApiOperation(value = "查询存量雪狼项目信息")
    @PostMapping(value = "/query/queryProjectWolfProjectList",
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
            consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ResultWrapper<List<ProjectDTO>> queryProjectWolfProjectList(){
        ResultWrapper<List<ProjectDTO>> wrapper = new ResultWrapper<>();
        List<ProjectDTO> result = cpProjectService.queryProjectWolfProjectList();
        return wrapper.success(result);
    }

    @ApiOperation(value = "feign调用:查询系统内容")
    @GetMapping(value = "/feign/project/data/{proId}")
    public ResultWrapper<Map<String,String>> feignQueryProData(@PathVariable("proId") String proId){
        ResultWrapper<Map<String,String>> wrapper = new ResultWrapper<>();
        Map<String, String> result = apiService.feignQueryProData(proId);
        return wrapper.success(result);
    }

    @ApiOperation(value = "根据系统id查关联的环境下拉选项集合")
    @GetMapping(value = "/query/selectEnvOptions/{projectId}")
    public ResultWrapper<List<CpProjectEnvOptionDto>> selectEnvOptions(@PathVariable("projectId") String projectId){
        ResultWrapper<List<CpProjectEnvOptionDto>> wrapper = new ResultWrapper<>();
        List<CpProjectEnvOptionDto> result = apiService.selectEnvOptions(projectId);
        return wrapper.success(result);
    }

}
