package com.ruoyi.ems.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.ems.domain.EmsFacsFlowRel;
import com.ruoyi.ems.service.IEmsFacsFlowRelService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * 能源设施能流关系Controller
 * 
 * @author ruoyi
 * @date 2024-07-10
 */
@RestController
@RequestMapping("/basecfg/flowrel")
@Api(value = "FacsFlowRelController", description = "能流关系管理")
public class FacsFlowRelController extends BaseController
{
    @Autowired
    private IEmsFacsFlowRelService facsFlowRelService;

    /**
     * 查询能源设施能流关系列表
     */
    @RequiresPermissions("basecfg:flowrel:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsFacsFlowRel emsFacsFlowRel)
    {
        startPage();
        List<EmsFacsFlowRel> list = facsFlowRelService.selectEmsFacsFlowRelList(emsFacsFlowRel);
        return getDataTable(list);
    }

    /**
     * 导出能源设施能流关系列表
     */
    @RequiresPermissions("basecfg:flowrel:export")
    @Log(title = "能源设施能流关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsFacsFlowRel emsFacsFlowRel)
    {
        List<EmsFacsFlowRel> list = facsFlowRelService.selectEmsFacsFlowRelList(emsFacsFlowRel);
        ExcelUtil<EmsFacsFlowRel> util = new ExcelUtil<EmsFacsFlowRel>(EmsFacsFlowRel.class);
        util.exportExcel(response, list, "能源设施能流关系数据");
    }

    /**
     * 获取能源设施能流关系详细信息
     */
    @RequiresPermissions("basecfg:flowrel:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(facsFlowRelService.selectEmsFacsFlowRelById(id));
    }

    /**
     * 新增能源设施能流关系
     */
    @RequiresPermissions("basecfg:flowrel:add")
    @Log(title = "能源设施能流关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsFacsFlowRel emsFacsFlowRel)
    {
        return toAjax(facsFlowRelService.insertEmsFacsFlowRel(emsFacsFlowRel));
    }

    /**
     * 修改能源设施能流关系
     */
    @RequiresPermissions("basecfg:flowrel:edit")
    @Log(title = "能源设施能流关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsFacsFlowRel emsFacsFlowRel)
    {
        return toAjax(facsFlowRelService.updateEmsFacsFlowRel(emsFacsFlowRel));
    }

    /**
     * 删除能源设施能流关系
     */
    @RequiresPermissions("basecfg:flowrel:remove")
    @Log(title = "能源设施能流关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(facsFlowRelService.deleteEmsFacsFlowRelByIds(ids));
    }
}
