package com.xinelu.manage.controller.taskstatusdict;

import com.xinelu.common.annotation.Log;
import com.xinelu.common.core.controller.BaseController;
import com.xinelu.common.core.domain.AjaxResult;
import com.xinelu.common.core.page.TableDataInfo;
import com.xinelu.common.enums.BusinessType;
import com.xinelu.common.utils.poi.ExcelUtil;
import com.xinelu.manage.domain.taskstatusdict.TaskStatusDict;
import com.xinelu.manage.service.taskstatusdict.ITaskStatusDictService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 任务状态字典Controller
 *
 * @author xinelu
 * @date 2024-03-13
 */
@RestController
@RequestMapping("/system/taskStatus")
public class TaskStatusDictController extends BaseController {
    @Resource
    private ITaskStatusDictService taskStatusDictService;

    /**
     * 查询任务状态字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskStatusDict taskStatusDict) {
        startPage();
        List<TaskStatusDict> list = taskStatusDictService.selectTaskStatusDictList(taskStatusDict);
        return getDataTable(list);
    }

    @GetMapping("/taskStatusDictList")
    public AjaxResult taskStatusDictList(TaskStatusDict taskStatusDict) {
        return AjaxResult.success(taskStatusDictService.selectTaskStatusDictList(taskStatusDict));
    }

    /**
     * 导出任务状态字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:export')")
    @Log(title = "任务状态字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskStatusDict taskStatusDict) {
        List<TaskStatusDict> list = taskStatusDictService.selectTaskStatusDictList(taskStatusDict);
        ExcelUtil<TaskStatusDict> util = new ExcelUtil<TaskStatusDict>(TaskStatusDict.class);
        util.exportExcel(response, list, "任务状态字典数据");
    }

    /**
     * 获取任务状态字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(taskStatusDictService.selectTaskStatusDictById(id));
    }

    /**
     * 新增任务状态字典
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:add')")
    @Log(title = "任务状态字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TaskStatusDict taskStatusDict) {
        return toAjax(taskStatusDictService.insertTaskStatusDict(taskStatusDict));
    }

    /**
     * 修改任务状态字典
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:edit')")
    @Log(title = "任务状态字典", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TaskStatusDict taskStatusDict) {
        return toAjax(taskStatusDictService.updateTaskStatusDict(taskStatusDict));
    }

    /**
     * 删除任务状态字典
     */
    @PreAuthorize("@ss.hasPermi('system:taskStatus:remove')")
    @Log(title = "任务状态字典", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(taskStatusDictService.deleteTaskStatusDictByIds(ids));
    }
}