package com.goldenwater.slaj.eutr.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.eutr.domain.BisEutrEqAnsw;
import com.goldenwater.slaj.eutr.service.IBisEutrEqAnswService;

@RestController
@RequestMapping("/eutr/eqansw")
public class BisEutrEqAnswController extends BaseController {
    @Autowired
    private IBisEutrEqAnswService bisEutrEqAnswService;

    @GetMapping("/list")
    public TableDataInfo list(BisEutrEqAnsw bisEutrEqAnsw) {
        startPage();
        List<BisEutrEqAnsw> list = bisEutrEqAnswService.selectBisEutrEqAnswList(bisEutrEqAnsw);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisEutrEqAnsw bisEutrEqAnsw) {
        return toAjax(bisEutrEqAnswService.insertBisEutrEqAnsw(bisEutrEqAnsw));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisEutrEqAnsw bisEutrEqAnsw) {
        return toAjax(bisEutrEqAnswService.updateBisEutrEqAnsw(bisEutrEqAnsw));
    }

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

    @Log(title = "答题记录管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eutr:eqansw:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisEutrEqAnsw bisEutrEqAnsw) {
        List<BisEutrEqAnsw> list = bisEutrEqAnswService.selectBisEutrEqAnswList(bisEutrEqAnsw);
        ExcelUtil<BisEutrEqAnsw> util = new ExcelUtil<BisEutrEqAnsw>(BisEutrEqAnsw.class);
        util.exportExcel(response, list, "答题记录数据");
    }
}
