package com.xinelu.manage.controller.taskpartitiondict;

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.taskpartitiondict.TaskPartitionDict;
import com.xinelu.manage.service.taskpartitiondict.ITaskPartitionDictService;
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/partition")
public class TaskPartitionDictController extends BaseController {
    @Resource
    private ITaskPartitionDictService taskPartitionDictService;

    /**
     * 查询任务细分字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:partition:list')")
    @GetMapping("/list")
    public TableDataInfo list(TaskPartitionDict taskPartitionDict) {
        startPage();
        List<TaskPartitionDict> list = taskPartitionDictService.selectTaskPartitionDictList(taskPartitionDict);
        return getDataTable(list);
    }


    /**
     * 查询任务细分字典列表 - 不分页
     */
    @GetMapping("/taskPartitionList")
    public AjaxResult taskPartitionList(TaskPartitionDict taskPartitionDict) {
        return AjaxResult.success(taskPartitionDictService.selectTaskPartitionDictList(taskPartitionDict));
    }

    /**
     * 导出任务细分字典列表
     */
    @PreAuthorize("@ss.hasPermi('system:partition:export')")
    @Log(title = "任务细分字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TaskPartitionDict taskPartitionDict) {
        List<TaskPartitionDict> list = taskPartitionDictService.selectTaskPartitionDictList(taskPartitionDict);
        ExcelUtil<TaskPartitionDict> util = new ExcelUtil<TaskPartitionDict>(TaskPartitionDict.class);
        util.exportExcel(response, list, "任务细分字典数据");
    }

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

    /**
     * 新增任务细分字典
     */
    @PreAuthorize("@ss.hasPermi('system:partition:add')")
    @Log(title = "任务细分字典", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TaskPartitionDict taskPartitionDict) {
        return toAjax(taskPartitionDictService.insertTaskPartitionDict(taskPartitionDict));
    }

    /**
     * 修改任务细分字典
     */
    @PreAuthorize("@ss.hasPermi('system:partition:edit')")
    @Log(title = "任务细分字典", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TaskPartitionDict taskPartitionDict) {
        return toAjax(taskPartitionDictService.updateTaskPartitionDict(taskPartitionDict));
    }

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