package com.zjty.autotest.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.zjty.autotest.pojo.sjq.EvaReport;
import com.zjty.autotest.pojo.sjq.TestChannel;
import com.zjty.autotest.pojo.sjq.TestReport;
import com.zjty.autotest.pojo.sjq.common.AppHttpCodeEnum;
import com.zjty.autotest.pojo.sjq.common.ResponseResult;
import com.zjty.autotest.service.TestReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 控制器层
 * @author Administrator
 *
 */
@RestController
@CrossOrigin
@RequestMapping("/report")
@Api(value = "报告管理接口",description = "提供输入输出查询接口")
public class TestReportController {

	@Autowired
	private TestReportService testReportService;

	
	/**
	 * 根据ID查询
	 * @param id ID
	 * @return*/
	@ApiOperation("根据AutoResultId查询输入")
	@RequestMapping(value="/in/{id}",method= RequestMethod.GET)
	public ResponseResult findByIdInData(@PathVariable String id){
		TestReport testReport = testReportService.findByResultId(id);
		if(testReport!=null) {
			String inputReport = testReport.getInputReport();
			TestChannel t = JSON.parseObject(inputReport, TestChannel.class);
			return ResponseResult.okResult(t);
		}
		return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
	}

	/**
	 * 根据ID查询
	 * @param id ID
	 * @return*/
	@ApiOperation("根据AutoResultId查询输出")
	@RequestMapping(value="/out/{id}",method= RequestMethod.GET)
	public ResponseResult findByIdOutData(@PathVariable String id){
		TestReport testReport = testReportService.findByResultId(id);
		if(testReport!=null) {
			String outReport = testReport.getOutReport();
			EvaReport evaReport = JSON.parseObject(outReport, EvaReport.class);
			return ResponseResult.okResult(evaReport);
		}
		return ResponseResult.errorResult(AppHttpCodeEnum.ERROR);
	}
	@RequestMapping(value="/status",method=RequestMethod.POST)
	public ResponseResult findStatus(@RequestBody Map searchMap){
	 	return testReportService.findStatus(searchMap);
	}
	@RequestMapping(value="/all",method= RequestMethod.GET)
	public ResponseResult findAllStatus(){
	 	return testReportService.findAllStatus();
	}
}
