package com.xinelu.manage.controller.tasktypedict;

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.tasktypedict.TaskTypeDict;
import com.xinelu.manage.service.tasktypedict.ITaskTypeDictService;
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-11
 */
@RestController
@RequestMapping("/system/taskType")
public class TaskTypeDictController extends BaseController {
    @Resource
    private ITaskTypeDictService taskTypeDictService;

    /**
     * 查询任务类型字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:taskType:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskTypeDict taskTypeDict) {
        startPage();
        List<TaskTypeDict> list = taskTypeDictService.selectTaskTypeDictList(taskTypeDict);
        return getDataTable(list);
    }

    /**
     * 查询任务类型字典列表(不分页)
     */
    @GetMapping("/selectTaskTypeList")
    public AjaxResult selectTaskTypeList(TaskTypeDict taskTypeDict) {
        return AjaxResult.success(taskTypeDictService.selectTaskTypeDictList(taskTypeDict));
    }

    /**
     * 导出任务类型字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:taskType:export')")
    @Log(title = "任务类型字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskTypeDict taskTypeDict) {
        List<TaskTypeDict> list = taskTypeDictService.selectTaskTypeDictList(taskTypeDict);
        ExcelUtil<TaskTypeDict> util = new ExcelUtil<TaskTypeDict>(TaskTypeDict.class);
        util.exportExcel(response, list, "任务类型字典数据");
    }

    /**
     * 获取任务类型字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:taskType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(taskTypeDictService.selectTaskTypeDictById(id));
    }

    /**
     * 新增任务类型字典
     */
    @PreAuthorize("@ss.hasPermi('system:taskType:add')")
    @Log(title = "任务类型字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TaskTypeDict taskTypeDict) {
        return toAjax(taskTypeDictService.insertTaskTypeDict(taskTypeDict));
    }

    /**
     * 修改任务类型字典
     */
    @PreAuthorize("@ss.hasPermi('system:taskType:edit')")
    @Log(title = "任务类型字典", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TaskTypeDict taskTypeDict) {
        return toAjax(taskTypeDictService.updateTaskTypeDict(taskTypeDict));
    }

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