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.BusiPlanCount;
import com.goldenwater.slaj.eme.service.IBusiPlanCountService;

/**
 * 应急预案统计
 */
@RestController
@RequestMapping("/eme/plancount")
public class BusiPlanCountController extends BaseController {
    @Autowired
    private IBusiPlanCountService busiPlanCountService;

    @GetMapping("/list")
    public TableDataInfo list(BusiPlanCount busiPlanCount) {
        startPage();
        List<BusiPlanCount> list = busiPlanCountService.selectBusiPlanCountList(busiPlanCount);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BusiPlanCount busiPlanCount) {
        return toAjax(busiPlanCountService.insertBusiPlanCount(busiPlanCount));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusiPlanCount busiPlanCount) {
        return toAjax(busiPlanCountService.updateBusiPlanCount(busiPlanCount));
    }

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

    @Log(title = "应急预案统计管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eme:plancount:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiPlanCount busiPlanCount) {
        List<BusiPlanCount> list = busiPlanCountService.selectBusiPlanCountList(busiPlanCount);
        ExcelUtil<BusiPlanCount> util = new ExcelUtil<BusiPlanCount>(BusiPlanCount.class);
        util.exportExcel(response, list, "应急预案统计数据");
    }
}
