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

/**
 * 源文件管理Controller
 * 
 * @author Allen
 * @date 2023-10-16
 */
@RestController
@RequestMapping("/graph/sourceFile")
public class SourceFileController extends BaseController
{
    @Autowired
    private ISourceFileService sourceFileService;

    /**
     * 查询源文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('graph:sourceFile:list')")
    @GetMapping("/list")
    public TableDataInfo list(SourceFile sourceFile)
    {
        startPage();
        List<SourceFile> list = sourceFileService.selectSourceFileList(sourceFile);
        return getDataTable(list);
    }

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

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

    /**
     * 新增源文件管理
     */
    @PreAuthorize("@ss.hasPermi('graph:sourceFile:add')")
    @Log(title = "源文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SourceFile sourceFile)
    {
        return toAjax(sourceFileService.insertSourceFile(sourceFile));
    }

    /**
     * 修改源文件管理
     */
    @PreAuthorize("@ss.hasPermi('graph:sourceFile:edit')")
    @Log(title = "源文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SourceFile sourceFile)
    {
        return toAjax(sourceFileService.updateSourceFile(sourceFile));
    }

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

    /**
     * 获取源文件的Option(id,name)
     */
    @GetMapping("/getOptions")
    public AjaxResult getOptions()
    {
        return success(sourceFileService.getOptions());
    }
}
