package com.ruoyi.web.controller.kaoqin;

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.system.domain.CardReplacementRecord;
import com.ruoyi.system.service.ICardReplacementRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 补卡记录Controller
 * 
 * @author ruoyi
 * @date 2023-02-08
 */
@RestController
@RequestMapping("/system/record")
public class CardReplacementRecordController extends BaseController
{
    @Autowired
    private ICardReplacementRecordService cardReplacementRecordService;

    /**
     * 查询补卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardReplacementRecord cardReplacementRecord)
    {
        startPage();
        List<CardReplacementRecord> list = cardReplacementRecordService.selectCardReplacementRecordList(cardReplacementRecord);
        return getDataTable(list);
    }

    /**
     * 导出补卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "补卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardReplacementRecord cardReplacementRecord)
    {
        List<CardReplacementRecord> list = cardReplacementRecordService.selectCardReplacementRecordList(cardReplacementRecord);
        ExcelUtil<CardReplacementRecord> util = new ExcelUtil<CardReplacementRecord>(CardReplacementRecord.class);
        util.exportExcel(response, list, "补卡记录数据");
    }

    /**
     * 获取补卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cardReplacementRecordService.selectCardReplacementRecordById(id));
    }

    /**
     * 新增补卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "补卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardReplacementRecord cardReplacementRecord)
    {
        return toAjax(cardReplacementRecordService.insertCardReplacementRecord(cardReplacementRecord));
    }

    /**
     * 修改补卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "补卡记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody CardReplacementRecord cardReplacementRecord)
    {
        return toAjax(cardReplacementRecordService.updateCardReplacementRecord(cardReplacementRecord));
    }

    /**
     * 删除补卡记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "补卡记录", businessType = BusinessType.DELETE)
    @GetMapping(value = "/delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cardReplacementRecordService.deleteCardReplacementRecordByIds(ids));
    }

    /***
     * 补卡审核
     * @param id 数据id
     * @param isPass 是否通过 1：不通过，2：通过'
     * @return
     */
    @PostMapping(value = "/putPass")
    @PreAuthorize("@ss.hasPermi('system:record:putPass')")
    public AjaxResult putPass(@RequestBody CardReplacementRecord cardReplacementRecord)
    {
        return toAjax(cardReplacementRecordService.putPass(cardReplacementRecord));
    }

    /**
     * 获取当前账号下的补卡列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:presentList')")
    @GetMapping("/presentList")
    public TableDataInfo presentList(CardReplacementRecord cardReplacementRecord)
    {
        startPage();
        List<CardReplacementRecord> list = cardReplacementRecordService.presentList(cardReplacementRecord);
        return getDataTable(list);
    }

}
