package com.ruoyi.powerdistribution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.powerdistribution.domain.PdmStopRecords;
import com.ruoyi.powerdistribution.service.IPdmStopRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 可靠性停电记录Controller
 *
 * @author ruoyi
 * @date 2024-12-11
 */
@RestController
@Api(value = "PdmStopRecordsController", tags = "停电记录")
@RequestMapping("/power/stopRecords")
public class PdmStopRecordsController extends BaseController
{
    @Autowired
    private IPdmStopRecordsService pdmStopRecordsService;

    /**
     * 查询可靠性停电记录列表
     */
    @ApiOperation(value = "查询可靠性停电记录列表")
    @PreAuthorize("@ss.hasPermi('system:records:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmStopRecords pdmStopRecords)
    {
        startPage();
        List<PdmStopRecords> list = pdmStopRecordsService.selectPdmStopRecordsList(pdmStopRecords);
        return getDataTable(list);
    }

    /**
     * 导出可靠性停电记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:records:export')")
    @Log(title = "可靠性停电记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmStopRecords pdmStopRecords)
    {
        List<PdmStopRecords> list = pdmStopRecordsService.selectPdmStopRecordsList(pdmStopRecords);
        ExcelUtil<PdmStopRecords> util = new ExcelUtil<PdmStopRecords>(PdmStopRecords.class);
        util.exportExcel(response, list, "可靠性停电记录数据");
    }

    /**
     * 获取可靠性停电记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:records:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmStopRecordsService.selectPdmStopRecordsById(id));
    }

    /**
     * 新增可靠性停电记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:add')")
    @Log(title = "可靠性停电记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody PdmStopRecords pdmStopRecords)
    {
        return toAjax(pdmStopRecordsService.insertPdmStopRecords(pdmStopRecords));
    }

    /**
     * 修改可靠性停电记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:edit')")
    @Log(title = "可靠性停电记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody PdmStopRecords pdmStopRecords)
    {
        return toAjax(pdmStopRecordsService.updatePdmStopRecords(pdmStopRecords));
    }

    /**
     * 删除可靠性停电记录
     */
    @PreAuthorize("@ss.hasPermi('system:records:remove')")
    @Log(title = "可靠性停电记录", businessType = BusinessType.DELETE)
	@GetMapping("delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmStopRecordsService.deletePdmStopRecordsByIds(ids));
    }
}
