package com.ruoyi.web;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.ReviewStandard;
import com.ruoyi.service.ReviewStandardService;
import com.ruoyi.web.request.*;
import com.ruoyi.web.response.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * 检验内容库(标准)Controller层
 * @author gxk
 */
@Api(tags = "检验内容库")
@RestController
@RequestMapping("/review/standard")
public class ReviewStandardController extends BaseController {

    @Autowired
    private ReviewStandardService reviewStandardService;

    /**
     * 分页查询标准(检验内容库)
     * @return
     */
    @Anonymous
    @ApiOperation("分页查询标准(检验内容库)")
    @PostMapping("/list")
    public TableDataInfo<ReviewStandardResponse> listByPage(@Validated @RequestBody ReviewStandardListByPageRequest request) {
        startPage(request);
        List<ReviewStandardResponse> list = reviewStandardService.listByPage(request);
        return getDataTable(list);
    }
    /**
     * 根据标准主键ID查询树状结构
     * @param request
     * @return
     */
    @ApiOperation("查询标准的检验内容")
    @PostMapping("/getInspectionContent")
    public R<ReviewStandardInspectionContentResponse> getInspectionContent(@Validated @RequestBody ReviewStandardInspectionContentRequest request) {
        ReviewStandardInspectionContentResponse response = reviewStandardService.selectInspectionContent(request.getId());
        return R.ok(response);
    }

    /**
     * 根据标准主键ID查询车型试验的检验内容
     * @param request
     * @return
     */
    @ApiOperation("车型试验的检验内容详情")
    @PostMapping("/test/getInspectionContent")
    public R<List<ReviewStandardTestInspectionContentResponse>> getTestInspectionContent(@Validated @RequestBody ReviewStandardTestInspectionContentRequest request) {
        List<ReviewStandardTestInspectionContentResponse> response = reviewStandardService.selectTestInspectionContent(request.getId());
        return R.ok(response);
    }

    /**
     * 查询 标准-检验内容-用例
     * @param request
     * @return
     */
    @Anonymous
    @ApiOperation("查询 标准-检验内容-用例")
    @PostMapping("/test/getStandardUsecase")
    public R<ReviewStandardStandardUsecaseResponse> getStandardUsecase(@Validated @RequestBody ReviewStandardStandardUsecaseRequest request) {
        ReviewStandardStandardUsecaseResponse response = reviewStandardService.selectStandardUsecase(request.getStandardId());
        return R.ok(response);
    }

    /**
     * 保存 标准-检验内容-用例
     * @param request
     * @return
     */
    @Anonymous
    @ApiOperation("保存 标准-检验内容-用例")
    @PostMapping("/test/saveStandardUsecase")
    public R<Boolean> saveStandardUsecase(@Validated @RequestBody ReviewStandardSaveStandardUsecaseRequest request) {
        reviewStandardService.saveStandardUsecase(request);
        return R.ok(true);
    }

    @ApiOperation("查询标注要求列表")
    @Trace
    @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
    @RequestMapping(method = RequestMethod.POST, value = "/findReviewStandardList")
    public TableDataInfo<ReviewStandardListResponse> findReviewStandardList(@Validated @RequestBody ReviewStandardListRequest request) {
        return getDataTable(reviewStandardService.findReviewStandardList(request));
    }

    // 标准-要点
    @ApiOperation("查询审查要点列表")
    @Trace
    @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
    @RequestMapping(method = RequestMethod.POST, value = "/findKeyPointList")
    public TableDataInfo<ReviewStandard> findKeyPointList(@Validated @RequestBody ReviewFindListRequest request) {
        return getDataTable(reviewStandardService.findKeyPointList(request));
    }

    // 标准-要点-细则
    @ApiOperation("查询审查细则列表")
    @Trace
    @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
    @RequestMapping(method = RequestMethod.POST, value = "/findDetailsList")
    public TableDataInfo<ReviewStandard> findDetailsList(@Validated @RequestBody ReviewFindListRequest request) {
        return getDataTable(reviewStandardService.findDetailsList(request));
    }

    /**
     * 检验内容库科恩获取车型试验
     * @param request
     * @return
     * @throws IOException
     */
    @ApiOperation("检验内容库查询车型试验(科恩)")
    @Trace
    @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
    @RequestMapping(method = RequestMethod.POST, value = "/getList", produces="application/json;charset=UTF-8")
    public R<InspectionContentResponse> getList(@Validated @RequestBody String request) throws IOException {

        return R.ok(reviewStandardService.getList(request));

    }

    /**
     * 检验内容库查询标准下测试用例(科恩)
     * @param request
     * @return
     * @throws IOException
     */
    @ApiOperation("检验内容库查询标准下测试用例(科恩)")
    @Trace
    @Tags({@Tag(key = "param", value = "arg[0]"), @Tag(key = "result", value = "returnedObj")})
    @RequestMapping(method = RequestMethod.POST, value = "/getUseCaseList", produces="application/json;charset=UTF-8")
    public TableDataInfo<UseCaseListResponse> getUseCaseList(@Validated @RequestBody String request) throws IOException {

        return getDataTable(reviewStandardService.getUseCaseList(request));

    }
}