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.BisEutrPlan;
import com.goldenwater.slaj.eutr.service.IBisEutrPlanService;

@RestController
@RequestMapping("/eutr/plan")
public class BisEutrPlanController extends BaseController {
    @Autowired
    private IBisEutrPlanService bisEutrPlanService;

    @GetMapping("/list")
    public TableDataInfo list(BisEutrPlan bisEutrPlan) {
        startPage();
        List<BisEutrPlan> list = bisEutrPlanService.selectBisEutrPlanList(bisEutrPlan);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BisEutrPlan bisEutrPlan) {
        return toAjax(bisEutrPlanService.insertBisEutrPlan(bisEutrPlan));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BisEutrPlan bisEutrPlan) {
        return toAjax(bisEutrPlanService.updateBisEutrPlan(bisEutrPlan));
    }

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

    @Log(title = "培训计划管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eutr:plan:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BisEutrPlan bisEutrPlan) {
        List<BisEutrPlan> list = bisEutrPlanService.selectBisEutrPlanList(bisEutrPlan);
        ExcelUtil<BisEutrPlan> util = new ExcelUtil<BisEutrPlan>(BisEutrPlan.class);
        util.exportExcel(response, list, "培训计划数据");
    }
}
