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

@RestController
@RequestMapping("/ttsa/ttsatqueopt")
public class BisTtsaTqueOptController extends BaseController {
    @Autowired
    private IBisTtsaTqueOptService bisTtsaTqueOptService;

    @GetMapping("/list")
    public TableDataInfo list(BisTtsaTqueOpt bisTtsaTqueOpt) {
        startPage();
        List<BisTtsaTqueOpt> list = bisTtsaTqueOptService.selectBisTtsaTqueOptList(bisTtsaTqueOpt);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisTtsaTqueOpt bisTtsaTqueOpt) {
        return toAjax(bisTtsaTqueOptService.insertBisTtsaTqueOpt(bisTtsaTqueOpt));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisTtsaTqueOpt bisTtsaTqueOpt) {
        return toAjax(bisTtsaTqueOptService.updateBisTtsaTqueOpt(bisTtsaTqueOpt));
    }

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

    @Log(title = "试题选项管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ttsa:ttsatqueopt:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisTtsaTqueOpt bisTtsaTqueOpt) {
        List<BisTtsaTqueOpt> list = bisTtsaTqueOptService.selectBisTtsaTqueOptList(bisTtsaTqueOpt);
        ExcelUtil<BisTtsaTqueOpt> util = new ExcelUtil<BisTtsaTqueOpt>(BisTtsaTqueOpt.class);
        util.exportExcel(response, list, "试题选项管理数据");
    }
}
