package com.test.test.controller;

import com.test.common.annotation.Log;
import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.common.utils.DateUtils;
import com.test.test.domain.TestCase;
import com.test.test.domain.TestTask;
import com.test.test.domain.qo.GroupIdQO;
import com.test.test.domain.qo.IDQO;
import com.test.test.service.ITestTaskService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 定时任务Controller
 */
@RestController
@RequestMapping("/test/task")
public class TestTaskController extends BaseController {
    @Resource
    private ITestTaskService testTaskService;

    /**
     * 查询定时任务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(@Validated GroupIdQO qo) {
        startPage();
        List<TestTask> list = testTaskService.selectTestTaskList(qo);
        return getDataTable(list);
    }

    /**
     * 获取定时任务详细信息
     */
    @PostMapping(value = "/detail")
    public AjaxResult getInfo(@RequestBody IDQO qo) {
        return success(testTaskService.selectTestTaskById(qo.getId()));
    }

    /**
     * 新增定时任务
     */
    @Log(title = "定时任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TestTask testTask) {
        testTask.setCreateBy(getLoginUser().getUsername());
        testTask.setCreateTime(DateUtils.getNowDate());
        return toAjax(testTaskService.insertTestTask(testTask));
    }

    /**
     * 修改定时任务
     */
    @Log(title = "定时任务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody TestTask testTask) {
        return toAjax(testTaskService.updateTestTask(testTask));
    }

    /**
     * 删除定时任务
     */
    @Log(title = "定时任务", businessType = BusinessType.DELETE)
    @PostMapping("/del")
    public AjaxResult remove(@RequestBody IDQO qo) {
        return toAjax(testTaskService.deleteTestTaskById(qo.getId()));
    }


}
