package com.goldenwater.slaj.acci.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.acci.domain.MwrCredAcci;
import com.goldenwater.slaj.acci.service.IMwrCredAcciService;

/**
 * 水利信用事故
 */
@RestController
@RequestMapping("/acci/mwrcredacci")
public class MwrCredAcciController extends BaseController {
    @Autowired
    private IMwrCredAcciService mwrCredAcciService;

    @GetMapping("/list")
    public TableDataInfo list(MwrCredAcci mwrCredAcci) {
        startPage();
        List<MwrCredAcci> list = mwrCredAcciService.selectMwrCredAcciList(mwrCredAcci);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody MwrCredAcci mwrCredAcci) {
        return toAjax(mwrCredAcciService.insertMwrCredAcci(mwrCredAcci));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody MwrCredAcci mwrCredAcci) {
        return toAjax(mwrCredAcciService.updateMwrCredAcci(mwrCredAcci));
    }

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

    @Log(title = "水利信用事故管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('acci:mwrcredacci:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MwrCredAcci mwrCredAcci) {
        List<MwrCredAcci> list = mwrCredAcciService.selectMwrCredAcciList(mwrCredAcci);
        ExcelUtil<MwrCredAcci> util = new ExcelUtil<MwrCredAcci>(MwrCredAcci.class);
        util.exportExcel(response, list, "水利信用事故数据");
    }
}
