package com.fs.doc.controller;

import java.util.List;
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.doc.domain.Doc;
import com.fs.doc.service.IDocService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 档案Controller
 * 
 * @author fs
 * @date 2023-01-09
 */
@RestController
@RequestMapping("/doc/doc")
public class DocController extends BaseController
{
    @Autowired
    private IDocService docService;

    /**
     * 查询档案列表
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:list')")
    @GetMapping("/list")
    public TableDataInfo list(Doc doc)
    {
        startPage();
        List<Doc> list = docService.selectDocList(doc);
        return getDataTable(list);
    }

    /**
     * 导出档案列表
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:export')")
    @Log(title = "档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Doc doc)
    {
        List<Doc> list = docService.selectDocList(doc);
        ExcelUtil<Doc> util = new ExcelUtil<Doc>(Doc.class);
        return util.exportExcel(list, "doc");
    }

    /**
     * 获取档案详细信息
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:query')")
    @GetMapping(value = "/{docId}")
    public AjaxResult getInfo(@PathVariable("docId") Long docId)
    {
        return AjaxResult.success(docService.selectDocById(docId));
    }

    /**
     * 新增档案
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:add')")
    @Log(title = "档案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Doc doc)
    {
        return toAjax(docService.insertDoc(doc));
    }

    /**
     * 修改档案
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:edit')")
    @Log(title = "档案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Doc doc)
    {
        return toAjax(docService.updateDoc(doc));
    }

    /**
     * 删除档案
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:remove')")
    @Log(title = "档案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{docIds}")
    public AjaxResult remove(@PathVariable Long[] docIds)
    {
        return toAjax(docService.deleteDocByIds(docIds));
    }
}
