package com.fs.doc.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.domain.R;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.doc.domain.DocRecord;
import com.fs.doc.param.DocRecordQueryParam;
import com.fs.doc.service.IDocRecordService;
import com.fs.doc.vo.DocRecordListQueryVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 记录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 R list(DocRecordQueryParam param)
    {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<DocRecordListQueryVO> list=docRecordService.selectDocRecordListVOQuery(param);
        PageInfo<DocRecordListQueryVO> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    /**
     * 导出记录列表
     */
    @PreAuthorize("@ss.hasPermi('doc:docRecord:export')")
    @Log(title = "记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DocRecordQueryParam param)
    {
        List<DocRecordListQueryVO> list=docRecordService.selectDocRecordListVOQuery(param);
        ExcelUtil<DocRecordListQueryVO> util = new ExcelUtil<DocRecordListQueryVO>(DocRecordListQueryVO.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));
    }
}
