package net.northking.cctp.executePlan.api;

import cn.hutool.json.JSONUtil;
import com.hzbank.testteam.autotest.dependencies.baseDefineDependency.vo.ResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.executePlan.api.service.AtuPlanBatchApiService;
import net.northking.cctp.executePlan.api.service.AtuPlanInfoApiService;
import net.northking.cctp.executePlan.api.service.AtuPlanTaskApiService;
import net.northking.cctp.executePlan.dto.planBatch.AtuExceptionCase;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>Title: AtuPlanInfoPubCtrl</p>
 * <p>Description: </p>
 *
 * @Author chenjianfeng
 * @Version V1.0
 * @Date 2022/12/27
 * <p>Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.</p>
 */
@Api(tags = "执行计划表")
@RequestMapping("/pub")
@RestController
public class AtuPlanInfoPubCtrl {

    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(AtuPlanInfoPubCtrl.class);

    @Autowired
    private AtuPlanTaskApiService taskApiService;

    @Autowired
    private AtuPlanInfoApiService planInfoApiService;

    @Autowired
    private AtuPlanBatchApiService planBatchApiService;

    /**
     * 更新任务执行结果文件
     * @param params 参数 {“taskId”:"", "filePath": ""}
     * @return 结果
     */
    @ApiOperation(value = "更新任务执行结果文件")
    @PostMapping(value = "/execPlan/updateTaskExecFile")
    public ResultWrapper<Boolean> updateTaskExecFile(@RequestBody Map<String, String> params){
        logger.info("start updateTaskExecFile: params =======> " + JSONUtil.toJsonStr(params));

        ResultWrapper<Boolean> wrapper = new ResultWrapper<>();
        Boolean result = taskApiService.updateTaskExecFile(params);

        logger.info("end updateTaskExecFile ");

        return wrapper.success(result);
    }

    /**
     * 判断用例集是否被执行计划引用
     * @param params 用例集id集合
     * @return 结果
     */
    @ApiOperation(value = "判断用例集是否被执行计划引用")
    @PostMapping(value = "/execPlan/isUse")
    public Boolean isUse(@RequestBody List<String> params){
        logger.info("start isUse: params =======> " + JSONUtil.toJsonStr(params));
        Boolean result = planInfoApiService.isUse(params);
        logger.info("end isUse ");
        return result;
    }

    /**
     * 批次用例推送通知
     * @param exceptionCaseList 异常用例数据
     * @return 结果
     */
    @ApiOperation(value = "批次用例推送通知")
    @PostMapping(value = "/execPlan/casePushNotice")
    public ResultWrapper<Boolean> casePushNotice(@Validated @RequestBody List<AtuExceptionCase> exceptionCaseList){

        logger.info("start casePushNotice: params =======> " + JSONUtil.toJsonStr(exceptionCaseList));

        ResultWrapper<Boolean> wrapper = new ResultWrapper<>();
        Boolean result = planBatchApiService.casePushNotice(exceptionCaseList);

        logger.info("end casePushNotice ");

        return wrapper.success(result);
    }
    @ApiOperation(value = "执行计划报告清除")
    @GetMapping("/execPlan/clearPlanReport")
    public ResponseVO<String> clearPlanReport(){
        logger.info("start clearPlanReport ");
        ResponseVO<String> responseVO = planBatchApiService.clearPlanReport();
        logger.info("end clearPlanReport ");
        return responseVO;
    }

}
