package com.kgraph.graph.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
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.kgraph.common.annotation.Log;
import com.kgraph.common.core.controller.BaseController;
import com.kgraph.common.core.domain.AjaxResult;
import com.kgraph.common.enums.BusinessType;
import com.kgraph.graph.domain.Subtask;
import com.kgraph.graph.service.ISubtaskService;
import com.kgraph.common.utils.poi.ExcelUtil;
import com.kgraph.common.core.page.TableDataInfo;

/**
 * 子任务管理Controller
 * 
 * @author Allen
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/graph/subtask")
public class SubtaskController extends BaseController
{
    @Autowired
    private ISubtaskService subtaskService;

    /**
     * 查询子任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:list')")
    @GetMapping("/list")
    public TableDataInfo list(Subtask subtask)
    {
        startPage();
        List<Subtask> list = subtaskService.selectSubtaskList(subtask);
        return getDataTable(list);
    }

    /**
     * 导出子任务管理列表
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:export')")
    @Log(title = "子任务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subtask subtask)
    {
        List<Subtask> list = subtaskService.selectSubtaskList(subtask);
        ExcelUtil<Subtask> util = new ExcelUtil<Subtask>(Subtask.class);
        util.exportExcel(response, list, "子任务管理数据");
    }

    /**
     * 获取子任务管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(subtaskService.selectSubtaskById(id));
    }

    /**
     * 新增子任务管理
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:add')")
    @Log(title = "子任务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subtask subtask)
    {
        return toAjax(subtaskService.insertSubtask(subtask));
    }

    /**
     * 修改子任务管理
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:edit')")
    @Log(title = "子任务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subtask subtask)
    {
        return toAjax(subtaskService.updateSubtask(subtask));
    }

    /**
     * 删除子任务管理
     */
    @PreAuthorize("@ss.hasPermi('graph:subtask:remove')")
    @Log(title = "子任务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subtaskService.deleteSubtaskByIds(ids));
    }
}
