package com.ruoyi.powerdistribution.controller;

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

import com.ruoyi.common.utils.uuid.IdUtils;
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.PdmDic;
import com.ruoyi.powerdistribution.service.IPdmDicService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配网字典Controller
 * 
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/powerdistribution/dic")
public class PdmDicController extends BaseController
{
    @Autowired
    private IPdmDicService pdmDicService;

    /**
     * 查询配网字典列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:list')")
    @GetMapping("/list")
    public TableDataInfo list(PdmDic pdmDic)
    {
        startPage();
        List<PdmDic> list = pdmDicService.selectPdmDicList(pdmDic);
        return getDataTable(list);
    }

    /**
     * 导出配网字典列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:export')")
    @Log(title = "配网字典", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmDic pdmDic)
    {
        List<PdmDic> list = pdmDicService.selectPdmDicList(pdmDic);
        ExcelUtil<PdmDic> util = new ExcelUtil<PdmDic>(PdmDic.class);
        util.exportExcel(response, list, "配网字典数据");
    }

    /**
     * 获取配网字典详细信息
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmDicService.selectPdmDicById(id));
    }

    /**
     * 新增配网字典
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:add')")
    @Log(title = "配网字典", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmDic pdmDic)
    {
        pdmDic.setDicId(IdUtils.fastSimpleUUID());
        return toAjax(pdmDicService.insertPdmDic(pdmDic));
    }

    /**
     * 修改配网字典
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:edit')")
    @Log(title = "配网字典", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmDic pdmDic)
    {
        return toAjax(pdmDicService.updatePdmDic(pdmDic));
    }

    /**
     * 删除配网字典
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:dic:remove')")
    @Log(title = "配网字典", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmDicService.deletePdmDicByIds(ids));
    }


    /**
     * 获取字典数
     *
     * @return 消息结构
     */
    @GetMapping(value = "/getPdmDicTree")
    public AjaxResult getPdmDicTree() {
        return  AjaxResult.success(pdmDicService.getPdmDicTree());
    }
}
