package com.cmvr.web.controller.test;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.test.model.vo.TeQueryTaskOrchestraItemVO;
import com.cmvr.test.model.vo.TeTaskOrchestraVO;
import com.cmvr.test.service.ITeTaskOrchestrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Api(tags = "测试--任务编排")
@RestController
@RequestMapping("/test/orchestration")
@RequiredArgsConstructor
class TeTaskOrchestrationController extends BaseController {

    private final ITeTaskOrchestrationService teTaskOrchestrationService;

    @ApiOperation("根据任务ID查询检查项编排")
    @PreAuthorize("@ss.hasPermi('test:orchestration:query')")
    @GetMapping
    public TableDataInfo query(
            @NotEmpty(message = "任务ID不能为空")
            @RequestParam("taskId") String taskId
    ) {
        startPage();
        List<TeQueryTaskOrchestraItemVO> list = teTaskOrchestrationService.queryByTaskId(taskId);
        return getDataTable(list);
    }

    @ApiOperation("新增任务编排")
    @PreAuthorize("@ss.hasPermi('test:orchestration:add')")
    @Log(title = "任务编排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody TeTaskOrchestraVO taskOrchestraVO) {
        return toAjax(teTaskOrchestrationService.insertTeTaskOrchestration(taskOrchestraVO));
    }
}
