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.ProcessedFile;
import com.kgraph.graph.service.IProcessedFileService;
import com.kgraph.common.utils.poi.ExcelUtil;
import com.kgraph.common.core.page.TableDataInfo;

/**
 * 处理文件管理Controller
 * 
 * @author Allen
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/graph/processedFile")
public class ProcessedFileController extends BaseController
{
    @Autowired
    private IProcessedFileService processedFileService;

    /**
     * 查询处理文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProcessedFile processedFile)
    {
        startPage();
        List<ProcessedFile> list = processedFileService.selectProcessedFileList(processedFile);
        return getDataTable(list);
    }

    /**
     * 导出处理文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:export')")
    @Log(title = "处理文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProcessedFile processedFile)
    {
        List<ProcessedFile> list = processedFileService.selectProcessedFileList(processedFile);
        ExcelUtil<ProcessedFile> util = new ExcelUtil<ProcessedFile>(ProcessedFile.class);
        util.exportExcel(response, list, "处理文件管理数据");
    }

    /**
     * 获取处理文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(processedFileService.selectProcessedFileById(id));
    }

    /**
     * 新增处理文件管理
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:add')")
    @Log(title = "处理文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProcessedFile processedFile)
    {
        return toAjax(processedFileService.insertProcessedFile(processedFile));
    }

    /**
     * 修改处理文件管理
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:edit')")
    @Log(title = "处理文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProcessedFile processedFile)
    {
        return toAjax(processedFileService.updateProcessedFile(processedFile));
    }

    /**
     * 删除处理文件管理
     */
    @PreAuthorize("@ss.hasPermi('graph:processedFile:remove')")
    @Log(title = "处理文件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(processedFileService.deleteProcessedFileByIds(ids));
    }

    @GetMapping("/getOptionsBySourceFileId/{id}")
    public AjaxResult getOptionsBySourceFileId(@PathVariable Long id)
    {
        return success(processedFileService.getOptionsBySourceFileId(id));
    }
}
