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.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.PdmWorkOrgan;
import com.ruoyi.powerdistribution.service.IPdmWorkOrganService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配网作业机构Controller
 * 
 * @author ruoyi
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/powerdistribution/organ")
@Api(value = "organ", tags = "配网作业机构")
public class PdmWorkOrganController extends BaseController
{
    @Autowired
    private IPdmWorkOrganService pdmWorkOrganService;

    /**
     * 查询配网作业机构列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PdmWorkOrgan pdmWorkOrgan)
    {
        startPage();
        List<PdmWorkOrgan> list = pdmWorkOrganService.selectPdmWorkOrganList(pdmWorkOrgan);
        return getDataTable(list);
    }

    /**
     * 导出配网作业机构列表
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:organ:export')")
    @Log(title = "配网作业机构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PdmWorkOrgan pdmWorkOrgan)
    {
        List<PdmWorkOrgan> list = pdmWorkOrganService.selectPdmWorkOrganList(pdmWorkOrgan);
        ExcelUtil<PdmWorkOrgan> util = new ExcelUtil<PdmWorkOrgan>(PdmWorkOrgan.class);
        util.exportExcel(response, list, "配网作业机构数据");
    }

    /**
     * 获取配网作业机构详细信息
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:organ:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pdmWorkOrganService.selectPdmWorkOrganById(id));
    }

    /**
     * 新增配网作业机构
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:organ:add')")
    @Log(title = "配网作业机构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PdmWorkOrgan pdmWorkOrgan)
    {
        return toAjax(pdmWorkOrganService.insertPdmWorkOrgan(pdmWorkOrgan));
    }

    /**
     * 修改配网作业机构
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:organ:edit')")
    @Log(title = "配网作业机构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PdmWorkOrgan pdmWorkOrgan)
    {
        return toAjax(pdmWorkOrganService.updatePdmWorkOrgan(pdmWorkOrgan));
    }

    /**
     * 删除配网作业机构
     */
    @PreAuthorize("@ss.hasPermi('powerdistribution:organ:remove')")
    @Log(title = "配网作业机构", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pdmWorkOrganService.deletePdmWorkOrganByIds(ids));
    }

    /**
     * 查询配网作业机构列表
     */
    @ApiOperation(value = "作业机构查询", notes = "作业机构查询")
    @GetMapping("/getAll")
    public AjaxResult getAll()
    {
        List<PdmWorkOrgan> list = pdmWorkOrganService.selectPdmWorkOrganList(null);
        return AjaxResult.success(list);
    }
}
