package com.chushang.task.controller;

import com.chushang.common.core.web.AjaxResult;
import com.chushang.common.mybatis.page.CommonParam;
import com.chushang.common.mybatis.utils.PageResult;
import com.chushang.security.annotation.RequiresPermissions;
import com.chushang.task.entity.TaskInfo;
import com.chushang.task.service.TaskInfoService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @auther: zhao
 * @date: 2024/6/11 9:11
 */
@RestController
@RequestMapping(value = "/")
public class TaskController {

    @Resource
    TaskInfoService taskInfoService;

    @RequiresPermissions("system:task:list")
    @GetMapping("/list")
    public AjaxResult page(TaskInfo taskInfo){
        CommonParam commonParam = CommonParam.buildPageRequest();
        PageResult pageResult = taskInfoService.pagePostList(taskInfo, commonParam);
        return AjaxResult.success(pageResult);
    }

    /**
     * 获取 后台任务信息
     */
    @GetMapping(value = "/{taskId}")
    @RequiresPermissions("system:task:info")
    public AjaxResult info(@PathVariable Long taskId){
        return AjaxResult.success(taskInfoService.getById(taskId));
    }

}
