package com.fs.his.controller;

import java.util.List;

import com.fs.common.utils.SecurityUtils;
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.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.enums.BusinessType;
import com.fs.his.domain.FsExportTask;
import com.fs.his.service.IFsExportTaskService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 导出任务Controller
 *
 * @author fs
 * @date 2024-11-20
 */
@RestController
@RequestMapping("/his/exportTask")
public class FsExportTaskController extends BaseController
{
    @Autowired
    private IFsExportTaskService fsExportTaskService;

    /**
     * 查询导出任务列表
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsExportTask fsExportTask)
    {
        startPage();
        fsExportTask.setUserId(SecurityUtils.getUserId());
        List<FsExportTask> list = fsExportTaskService.selectFsExportTaskList(fsExportTask);
        return getDataTable(list);
    }

    /**
     * 导出导出任务列表
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:export')")
    @Log(title = "导出任务", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsExportTask fsExportTask)
    {
        List<FsExportTask> list = fsExportTaskService.selectFsExportTaskList(fsExportTask);
        ExcelUtil<FsExportTask> util = new ExcelUtil<FsExportTask>(FsExportTask.class);
        return util.exportExcel(list, "导出任务数据");
    }

    /**
     * 获取导出任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return AjaxResult.success(fsExportTaskService.selectFsExportTaskByTaskId(taskId));
    }

    /**
     * 新增导出任务
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:add')")
    @Log(title = "导出任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsExportTask fsExportTask)
    {
        return toAjax(fsExportTaskService.insertFsExportTask(fsExportTask));
    }

    /**
     * 修改导出任务
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:edit')")
    @Log(title = "导出任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsExportTask fsExportTask)
    {
        return toAjax(fsExportTaskService.updateFsExportTask(fsExportTask));
    }

    /**
     * 删除导出任务
     */
    @PreAuthorize("@ss.hasPermi('his:exportTask:remove')")
    @Log(title = "导出任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(fsExportTaskService.deleteFsExportTaskByTaskIds(taskIds));
    }
}
