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.BisTtsaTque;
import com.goldenwater.slaj.ttsa.service.IBisTtsaTqueService;

@RestController
@RequestMapping("/ttsa/ttsatque")
public class BisTtsaTqueController extends BaseController {
    @Autowired
    private IBisTtsaTqueService bisTtsaTqueService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaTque bisTtsaTque) {
        startPage();
        List<BisTtsaTque> list = bisTtsaTqueService.selectBisTtsaTqueList(bisTtsaTque);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaTque bisTtsaTque) {
        return toAjax(bisTtsaTqueService.insertBisTtsaTque(bisTtsaTque));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaTque bisTtsaTque) {
        return toAjax(bisTtsaTqueService.updateBisTtsaTque(bisTtsaTque));
    }

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

    @Log(title = "试题管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsatque:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaTque bisTtsaTque) {
        List<BisTtsaTque> list = bisTtsaTqueService.selectBisTtsaTqueList(bisTtsaTque);
        ExcelUtil<BisTtsaTque> util = new ExcelUtil<BisTtsaTque>(BisTtsaTque.class);
        util.exportExcel(response, list, "试题管理数据");
    }
}
