package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.CsApprovalRecord;
import com.ruoyi.cs.service.ICsApprovalRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核记录Controller
 *
 * @author cc
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/cs/csApprovalRecord")
public class CsApprovalRecordController extends BaseController
{
    @Autowired
    private ICsApprovalRecordService csApprovalRecordService;

    /**
     * 查询审核记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(CsApprovalRecord csApprovalRecord)
    {
        startPage();
        List<CsApprovalRecord> list = csApprovalRecordService.selectCsApprovalRecordList(csApprovalRecord);
        return getDataTable(list);
    }

    /**
     * 导出审核记录列表
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:export')")
    @Log(title = "审核记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CsApprovalRecord csApprovalRecord)
    {
        List<CsApprovalRecord> list = csApprovalRecordService.selectCsApprovalRecordList(csApprovalRecord);
        ExcelUtil<CsApprovalRecord> util = new ExcelUtil<CsApprovalRecord>(CsApprovalRecord.class);
        util.exportExcel(response, list, "审核记录数据");
    }

    /**
     * 获取审核记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:query')")
    @GetMapping(value = "/{approvalRecordId}")
    public AjaxResult getInfo(@PathVariable("approvalRecordId") String approvalRecordId)
    {
        return AjaxResult.success(csApprovalRecordService.selectCsApprovalRecordByApprovalRecordId(approvalRecordId));
    }

    /**
     * 新增审核记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:add')")
    @Log(title = "审核记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CsApprovalRecord csApprovalRecord)
    {
        return toAjax(csApprovalRecordService.insertCsApprovalRecord(csApprovalRecord));
    }

    /**
     * 修改审核记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:edit')")
    @Log(title = "审核记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CsApprovalRecord csApprovalRecord)
    {
        return toAjax(csApprovalRecordService.updateCsApprovalRecord(csApprovalRecord));
    }

    /**
     * 删除审核记录
     */
    @PreAuthorize("@ss.hasPermi('cs:csApprovalRecord:remove')")
    @Log(title = "审核记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{approvalRecordIds}")
    public AjaxResult remove(@PathVariable String[] approvalRecordIds)
    {
        return toAjax(csApprovalRecordService.deleteCsApprovalRecordByApprovalRecordIds(approvalRecordIds));
    }

    /**
     * 查询最后一条审核记录
     */
    @GetMapping("/selectEndCsApprovalRecordByFormId")
    public AjaxResult selectEndCsApprovalRecordByFormId(String formId)
    {
        return AjaxResult.success(csApprovalRecordService.selectEndCsApprovalRecordByFormId(formId));
    }
}
