package net.northking.cctp.dw.api;

import com.github.pagehelper.util.StringUtil;
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.common.db.Pagination;
import net.northking.cctp.common.http.QueryByPage;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.dw.api.service.UIDwAtuPlanExecutionApiService;
import net.northking.cctp.dw.api.service.UIDwAtuScriptExecutionApiService;
import net.northking.cctp.dw.api.service.UIDwAtuStatisticsApiService;
import net.northking.cctp.dw.db.entity.DwAtuPlanInfo;
import net.northking.cctp.dw.dto.UIDwAtuPlanQueryDto;
import net.northking.cctp.dw.dto.UIDwAtuScriptInfoQueryDto;
import net.northking.cctp.dw.dto.ValidScriptDTO;
import net.northking.cctp.dw.dto.atu.DwAtuPlanExecutionDataDto;
import net.northking.cctp.dw.dto.atu.DwAtuScriptExecutionDataDto;
import net.northking.cctp.dw.dto.atu.DwAtuScriptInfoDto;
import net.northking.cctp.dw.dto.atu.DwOptionDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "UI自动化脚本情况查询")
@RequestMapping("/pub/script")
@RestController
public class DwScriptQueryForHzBankCtrl {
    @Autowired
    private UIDwAtuStatisticsApiService uiDwAtuStatisticsApiService;

    @Autowired
    private UIDwAtuPlanExecutionApiService uiDwAtuPlanExecutionApiService;
    @Autowired
    private UIDwAtuScriptExecutionApiService dwAtuScriptExecutionApiService;


    @ApiOperation("查询UI自动化脚本编写明细信息")
    @PostMapping("/queryScript")
    public ResultWrapper<Pagination<DwAtuScriptInfoDto>> listQuery(@RequestBody QueryByPage<UIDwAtuScriptInfoQueryDto> queryByPage) {
        ResultWrapper<Pagination<DwAtuScriptInfoDto>> wrapper = new ResultWrapper<>();
        Pagination<DwAtuScriptInfoDto> page = uiDwAtuStatisticsApiService.pagingQuery(queryByPage);
        return wrapper.success(page);
    }


    @ApiOperation("查询UI测试计划执行情况统计信息")
    @RequestMapping(value = "/executionTestPlan", method = RequestMethod.POST)
    public ResultWrapper<Pagination<DwAtuPlanExecutionDataDto>> getTestPlanExecution(@RequestBody QueryByPage<UIDwAtuPlanQueryDto> queryByPage) {

        ResultWrapper<Pagination<DwAtuPlanExecutionDataDto>> wrapper = new ResultWrapper<>();
        Pagination<DwAtuPlanExecutionDataDto> page = uiDwAtuPlanExecutionApiService.pagingQuery(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation("查询UI脚本执行情况汇总信息")
    @RequestMapping(value = "/executionScript", method = RequestMethod.POST)
    public ResultWrapper<Pagination<DwAtuScriptExecutionDataDto>> getExecutionScript(@RequestBody QueryByPage<UIDwAtuScriptInfoQueryDto> queryByPage) {

        ResultWrapper<Pagination<DwAtuScriptExecutionDataDto>> wrapper = new ResultWrapper<>();
        Pagination<DwAtuScriptExecutionDataDto> page = dwAtuScriptExecutionApiService.pagingQuery(queryByPage);
        return wrapper.success(page);
    }

    @ApiOperation("查询UI计划信息")
    @RequestMapping(value = "/getPlanList", method = RequestMethod.GET)
    public ResultWrapper<List<DwOptionDto>> getPlanList() {
        ResultWrapper<List<DwOptionDto>> wrapper = new ResultWrapper<>();
        List<DwOptionDto> list = uiDwAtuPlanExecutionApiService.getPlanList();
        return wrapper.success(list);
    }

    @ApiOperation("根据计划id查询计划名")
    @RequestMapping(value = "/getNameByPlanId/{planId}", method = RequestMethod.GET)
    public String getPlanName(@RequestParam("planId") String planId) {

        DwAtuPlanInfo planInfo = uiDwAtuPlanExecutionApiService.getNameByPlanId(planId);
        if (planInfo != null && StringUtil.isNotEmpty(planInfo.getPlanName())) {
            return planInfo.getPlanName();
        }
        return null;
    }


    @ApiOperation("ATS获取UI自动化脚本编写明细信息")
    @PostMapping("/queryScriptDetail")
    public ResponseVO<List<ValidScriptDTO>> queryScriptDetail(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime) {
        ResponseVO<List<ValidScriptDTO>> responseVO = new ResponseVO<>();
        List<ValidScriptDTO> page = uiDwAtuStatisticsApiService.queryScriptDetail(startTime, endTime);
        responseVO.setData(page);
        responseVO.setCode(BaseDefineDependencyConstants.SYSTEM_RESPONSE_CODE_SUCCESS);
        return responseVO;
    }
}
