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

/**
 * 预案信息公开
 */
@RestController
@RequestMapping("/eme/plandisclosure")
public class BusiPlanDisclosureController extends BaseController {
    @Autowired
    private IBusiPlanDisclosureService busiPlanDisclosureService;

    @GetMapping("/list")
    public TableDataInfo list(BusiPlanDisclosure busiPlanDisclosure) {
        startPage();
        List<BusiPlanDisclosure> list = busiPlanDisclosureService.selectBusiPlanDisclosureList(busiPlanDisclosure);
        return getDataTable(list);
    }

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

    @PostMapping
    public AjaxResult add(@RequestBody BusiPlanDisclosure busiPlanDisclosure) {
        return toAjax(busiPlanDisclosureService.insertBusiPlanDisclosure(busiPlanDisclosure));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody BusiPlanDisclosure busiPlanDisclosure) {
        return toAjax(busiPlanDisclosureService.updateBusiPlanDisclosure(busiPlanDisclosure));
    }

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

    @Log(title = "预案信息公开管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('eme:plandisclosure:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusiPlanDisclosure busiPlanDisclosure) {
        List<BusiPlanDisclosure> list = busiPlanDisclosureService.selectBusiPlanDisclosureList(busiPlanDisclosure);
        ExcelUtil<BusiPlanDisclosure> util = new ExcelUtil<BusiPlanDisclosure>(BusiPlanDisclosure.class);
        util.exportExcel(response, list, "预案信息公开数据");
    }
}
