package com.bonus.sgzb.material.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.bonus.sgzb.material.domain.TmTask;
import com.bonus.sgzb.material.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bonus.sgzb.common.log.annotation.Log;
import com.bonus.sgzb.common.log.enums.BusinessType;
import com.bonus.sgzb.common.security.annotation.RequiresPermissions;
import com.bonus.sgzb.common.core.web.controller.BaseController;
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
import com.bonus.sgzb.common.core.utils.poi.ExcelUtil;
import com.bonus.sgzb.common.core.web.page.TableDataInfo;

/**
 * 任务tm_taskController
 * 
 * @author bonus
 * @date 2023-12-13
 */
@RestController
@RequestMapping("/task")
public class TaskController extends BaseController
{
    @Autowired
    private TaskService tmTaskService;

    /**
     * 查询任务tm_task列表
     */
    @RequiresPermissions("system:task:list")
    @GetMapping("/list")
    public TableDataInfo list(TmTask tmTask)
    {
        startPage();
        List<TmTask> list = tmTaskService.selectTmTaskList(tmTask);
        return getDataTable(list);
    }

    /**
     * 导出任务tm_task列表
     */
    @RequiresPermissions("system:task:export")
    @Log(title = "任务tm_task", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TmTask tmTask)
    {
        List<TmTask> list = tmTaskService.selectTmTaskList(tmTask);
        ExcelUtil<TmTask> util = new ExcelUtil<TmTask>(TmTask.class);
        util.exportExcel(response, list, "任务tm_task数据");
    }

    /**
     * 获取任务tm_task详细信息
     */
    @RequiresPermissions("system:task:query")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return success(tmTaskService.selectTmTaskByTaskId(taskId));
    }

    /**
     * 新增任务tm_task
     */
    @RequiresPermissions("system:task:add")
    @Log(title = "任务tm_task", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TmTask tmTask)
    {
        return toAjax(tmTaskService.insertTmTask(tmTask));
    }

    /**
     * 修改任务tm_task
     */
    @RequiresPermissions("system:task:edit")
    @Log(title = "任务tm_task", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TmTask tmTask)
    {
        return toAjax(tmTaskService.updateTmTask(tmTask));
    }

    /**
     * 删除任务tm_task
     */
    @RequiresPermissions("system:task:remove")
    @Log(title = "任务tm_task", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(tmTaskService.deleteTmTaskByTaskIds(taskIds));
    }
}
