package com.ruoyi.powerdistribution.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.PdmPar;
import com.ruoyi.powerdistribution.service.IPdmParService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配网参数配置Controller
 * 
 * @author ruoyi
 * @date 2024-12-04
 */
@RestController
@RequestMapping("/powerdistribution/par")
public class PdmParController extends BaseController
{
    @Autowired
    private IPdmParService pdmParService;

    /**
     * 查询配网参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmPar pdmPar)
    {
        startPage();
        List<PdmPar> list = pdmParService.selectPdmParList(pdmPar);
        return getDataTable(list);
    }

    /**
     * 导出配网参数配置列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:export')")
    @Log(title = "配网参数配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmPar pdmPar)
    {
        List<PdmPar> list = pdmParService.selectPdmParList(pdmPar);
        ExcelUtil<PdmPar> util = new ExcelUtil<PdmPar>(PdmPar.class);
        util.exportExcel(response, list, "配网参数配置数据");
    }

    /**
     * 获取配网参数配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmParService.selectPdmParById(id));
    }

    /**
     * 新增配网参数配置
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:add')")
    @Log(title = "配网参数配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmPar pdmPar)
    {
        return toAjax(pdmParService.insertPdmPar(pdmPar));
    }

    /**
     * 修改配网参数配置
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:edit')")
    @Log(title = "配网参数配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmPar pdmPar)
    {
        return toAjax(pdmParService.updatePdmPar(pdmPar));
    }

    /**
     * 删除配网参数配置
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:par:remove')")
    @Log(title = "配网参数配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmParService.deletePdmParByIds(ids));
    }

    /**
     * 查询配网参数配置列表
     */
    @GetMapping("/listByParType")
    public AjaxResult listByParType(PdmPar pdmPar)
    {
        List<PdmPar> list = pdmParService.selectPdmParList(pdmPar);
        return AjaxResult.success(list);
    }

}
