package com.fs.doc.controller;

import java.util.List;

import com.fs.doc.param.DocRecordParam;
import com.fs.doc.vo.DocRecordVO;
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.DocRecord;
import com.fs.doc.service.IDocRecordService;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.common.core.page.TableDataInfo;

/**
 * 记录Controller
 * 
 * @author fs
 * @date 2023-01-09
 */
@RestController
@RequestMapping("/doc/docRecord")
public class DocRecordController extends BaseController
{
    @Autowired
    private IDocRecordService docRecordService;

    /**
     * 查询记录列表
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocRecordParam docRecord)
    {
        startPage();
        List<DocRecordVO> list = docRecordService.selectDocRecordListVO(docRecord);
        return getDataTable(list);
    }

    /**
     * 导出记录列表
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:export')")
    @Log(title = "记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DocRecordParam docRecord)
    {
        List<DocRecordVO> list = docRecordService.selectDocRecordListVO(docRecord);
        ExcelUtil<DocRecordVO> util = new ExcelUtil<DocRecordVO>(DocRecordVO.class);
        return util.exportExcel(list, "docRecord");
    }

    /**
     * 获取记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return AjaxResult.success(docRecordService.selectDocRecordById(recordId));
    }

    /**
     * 新增记录
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:add')")
    @Log(title = "记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocRecord docRecord)
    {
        return toAjax(docRecordService.insertDocRecord(docRecord));
    }

    /**
     * 修改记录
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:edit')")
    @Log(title = "记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocRecord docRecord)
    {
        return toAjax(docRecordService.updateDocRecord(docRecord));
    }

    /**
     * 删除记录
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:remove')")
    @Log(title = "记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(docRecordService.deleteDocRecordByIds(recordIds));
    }
}
