package com.ruoyi.web.controller.system;

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.ss.checkoff.domain.CheckoffRecords;
import com.ruoyi.ss.checkoff.domain.CheckoffRecordsVO;
import com.ruoyi.ss.checkoff.domain.CheckoffRecordsQuery;
import com.ruoyi.ss.checkoff.service.ICheckoffRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 核销记录Controller
 *
 * @author qzz
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/system/records")
public class CheckoffRecordsController extends BaseController
{
    @Autowired
    private ICheckoffRecordsService checkoffRecordsService;

    /**
     * 查询核销记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(CheckoffRecordsQuery query)
    {
        startPage();
        startOrderBy();
        List<CheckoffRecordsVO> list = checkoffRecordsService.selectCheckoffRecordsList(query);
        return getDataTable(list);
    }

    /**
     * 导出核销记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "核销记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CheckoffRecordsQuery query)
    {
        List<CheckoffRecordsVO> list = checkoffRecordsService.selectCheckoffRecordsList(query);
        ExcelUtil<CheckoffRecordsVO> util = new ExcelUtil<CheckoffRecordsVO>(CheckoffRecordsVO.class);
        util.exportExcel(response, list, "核销记录数据");
    }

    /**
     * 获取核销记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{checkoffId}")
    public AjaxResult getInfo(@PathVariable("checkoffId") Long checkoffId)
    {
        return success(checkoffRecordsService.selectCheckoffRecordsByCheckoffId(checkoffId));
    }

    /**
     * 新增核销记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "核销记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CheckoffRecords checkoffRecords)
    {
        return toAjax(checkoffRecordsService.insertCheckoffRecords(checkoffRecords));
    }

    /**
     * 修改核销记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "核销记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CheckoffRecords checkoffRecords)
    {
        return toAjax(checkoffRecordsService.updateCheckoffRecords(checkoffRecords));
    }

    /**
     * 删除核销记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "核销记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{checkoffIds}")
    public AjaxResult remove(@PathVariable Long[] checkoffIds)
    {
        return toAjax(checkoffRecordsService.deleteCheckoffRecordsByCheckoffIds(checkoffIds));
    }
}
