package com.jeethink.receive.controller;

import com.jeethink.bean.domain.ArchivesMaster;
import com.jeethink.common.annotation.Log;
import com.jeethink.common.core.controller.BaseController;
import com.jeethink.common.core.domain.AjaxResult;
import com.jeethink.common.core.page.TableDataInfo;
import com.jeethink.common.enums.BusinessType;
import com.jeethink.common.utils.poi.ExcelUtil;
import com.jeethink.receive.service.IArchivesApprovalService;
import com.jeethink.bean.vo.Approval;
import com.jeethink.receive.vo.ArchivesVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 sh
 * @date 2022-11-08
 */
@Api("档案审批")
@RestController
@RequestMapping("/receive/approval")
public class ArchivesApprovalController extends BaseController
{
    @Autowired
    private IArchivesApprovalService approvalService;

    /**
     * 查询档案接收列表
     */
    @ApiOperation("档案审批页面list列表")
    @PreAuthorize("@ss.hasPermi('receive:approval:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchivesMaster archive)
    {
        startPage();
        List<ArchivesMaster> list = approvalService.selectApprovalList(archive);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('receive:approval:query')")
    @GetMapping
    public AjaxResult getInfo(@RequestParam String archivesId) {

        ArchivesVO archivesVO = approvalService.getArchives(archivesId);
        return AjaxResult.success(archivesVO);
    }

    /**
     * 审批
     *
     * @author wms
     */
    @PreAuthorize("@ss.hasPermi('receive:approval:check')")
    @Log(title = "档案接收", businessType = BusinessType.UPDATE)
    @PostMapping
    public AjaxResult edit(@RequestBody Approval approval)
    {
        approvalService.approvalArchive(approval);
        return AjaxResult.success();
    }

    /**
     * 导出档案接收列表
     */
    @PreAuthorize("@ss.hasPermi('receive:approval:export')")
    @Log(title = "档案接收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(ArchivesMaster rsArchive)
    {
        List<ArchivesMaster> list = approvalService.selectApprovalList(rsArchive);
        ExcelUtil<ArchivesMaster> util = new ExcelUtil<ArchivesMaster>(ArchivesMaster.class);
        return util.exportExcel(list, "rsReceive");
    }
}
