package com.goldenwater.slaj.ttsa.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import com.goldenwater.common.enums.BusinessType;
import com.goldenwater.common.utils.poi.ExcelUtil;
import com.goldenwater.slaj.ttsa.domain.BisTtsaPaper;
import com.goldenwater.slaj.ttsa.service.IBisTtsaPaperService;

@RestController
@RequestMapping("/ttsa/ttsapaper")
public class BisTtsaPaperController extends BaseController {
    @Autowired
    private IBisTtsaPaperService bisTtsaPaperService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaPaper bisTtsaPaper) {
        startPage();
        List<BisTtsaPaper> list = bisTtsaPaperService.selectBisTtsaPaperList(bisTtsaPaper);
        return getDataTable(list);
    }

    @GetMapping("/{guid}")
    public AjaxResult getInfo(@PathVariable String guid) {
        return AjaxResult.success(bisTtsaPaperService.selectBisTtsaPaperByGuid(guid));
    }

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaPaper bisTtsaPaper) {
        return toAjax(bisTtsaPaperService.insertBisTtsaPaper(bisTtsaPaper));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaPaper bisTtsaPaper) {
        return toAjax(bisTtsaPaperService.updateBisTtsaPaper(bisTtsaPaper));
    }

    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) {
        return toAjax(bisTtsaPaperService.deleteBisTtsaPaperByGuids(guids));
    }

    @Log(title = "试卷管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsapaper:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaPaper bisTtsaPaper) {
        List<BisTtsaPaper> list = bisTtsaPaperService.selectBisTtsaPaperList(bisTtsaPaper);
        ExcelUtil<BisTtsaPaper> util = new ExcelUtil<BisTtsaPaper>(BisTtsaPaper.class);
        util.exportExcel(response, list, "试卷管理数据");
    }
}
