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.crm.vo.CrmFullCustomerListQueryVO;
import com.fs.doc.domain.Doc;
import com.fs.doc.param.DocQueryParam;
import com.fs.doc.service.IDocService;
import com.fs.doc.vo.DocListQueryVO;
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;

import static com.fs.common.constant.Constants.PAGE_SIZE;

/**
 * 档案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 R list(DocQueryParam param)
    {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        List<DocListQueryVO> list=docService.selectDocListVOQuery(param);
        PageInfo<DocListQueryVO> listPageInfo=new PageInfo<>(list);
        return R.ok().put("data",listPageInfo);
    }

    /**
     * 导出档案列表
     */
    @PreAuthorize("@ss.hasPermi('doc:doc:export')")
    @Log(title = "档案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DocQueryParam param)
    {
        List<DocListQueryVO> list=docService.selectDocListVOQuery(param);
        ExcelUtil<DocListQueryVO> util = new ExcelUtil<DocListQueryVO>(DocListQueryVO.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));
    }
}
