package com.goldenwater.slaj.eme.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.eme.domain.BusiSuppliesReserve;
import com.goldenwater.slaj.eme.service.IBusiSuppliesReserveService;

/**
 * 应急物资储备
 */
@RestController
@RequestMapping("/eme/suppliesreserve")
public class BusiSuppliesReserveController extends BaseController {
    @Autowired
    private IBusiSuppliesReserveService busiSuppliesReserveService;

    @GetMapping("/list")
    public TableDataInfo list(BusiSuppliesReserve busiSuppliesReserve) {
        startPage();
        List<BusiSuppliesReserve> list = busiSuppliesReserveService.selectBusiSuppliesReserveList(busiSuppliesReserve);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BusiSuppliesReserve busiSuppliesReserve) {
        return toAjax(busiSuppliesReserveService.insertBusiSuppliesReserve(busiSuppliesReserve));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusiSuppliesReserve busiSuppliesReserve) {
        return toAjax(busiSuppliesReserveService.updateBusiSuppliesReserve(busiSuppliesReserve));
    }

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

    @Log(title = "应急物资储备管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eme:suppliesreserve:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiSuppliesReserve busiSuppliesReserve) {
        List<BusiSuppliesReserve> list = busiSuppliesReserveService.selectBusiSuppliesReserveList(busiSuppliesReserve);
        ExcelUtil<BusiSuppliesReserve> util = new ExcelUtil<BusiSuppliesReserve>(BusiSuppliesReserve.class);
        util.exportExcel(response, list, "应急物资储备数据");
    }
}
