package com.ruoyi.ems.base.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.ems.base.domain.EmsBaseEnergyType;
import com.ruoyi.ems.base.service.IEmsBaseEnergyTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 能源类型信息Controller
 * 
 * @author Yinq
 * @date 2024-05-08
 */
@RestController
@RequestMapping("/ems/base/baseEnergyType")
public class EmsBaseEnergyTypeController extends BaseController
{
    @Autowired
    private IEmsBaseEnergyTypeService emsBaseEnergyTypeService;

    /**
     * 查询能源类型信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseEnergyType emsBaseEnergyType)
    {
        startPage();
        List<EmsBaseEnergyType> list = emsBaseEnergyTypeService.selectEmsBaseEnergyTypeList(emsBaseEnergyType);
        return getDataTable(list);
    }

//    /**
//     * 根据能源类型id查询能源类型名称
//     * @param energyTypeId
//     * @return
//     */
//    public AjaxResult queryEnergyNameByEnergyTypeId(int energyTypeId)
//    {
//        String energyName = emsBaseEnergyTypeService.queryEnergyNameByEnergyTypeId(energyTypeId);
//        return success(energyName);
//    }

    /**
     * 查询能源类型信息下拉框列表
     */
    @GetMapping("/getBaseEnergyTypeList")
    public AjaxResult baseEnergyTypeList(EmsBaseEnergyType emsBaseEnergyType)
    {
        List<EmsBaseEnergyType> list = emsBaseEnergyTypeService.selectEmsBaseEnergyTypeList(emsBaseEnergyType);
        return success(list);
    }

    /**
     * 导出能源类型信息列表
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:export')")
    @Log(title = "能源类型信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseEnergyType emsBaseEnergyType)
    {
        List<EmsBaseEnergyType> list = emsBaseEnergyTypeService.selectEmsBaseEnergyTypeList(emsBaseEnergyType);
        ExcelUtil<EmsBaseEnergyType> util = new ExcelUtil<EmsBaseEnergyType>(EmsBaseEnergyType.class);
        util.exportExcel(response, list, "能源类型信息数据");
    }

    /**
     * 获取能源类型信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsBaseEnergyTypeService.selectEmsBaseEnergyTypeByObjId(objId));
    }

    /**
     * 新增能源类型信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:add')")
    @Log(title = "能源类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsBaseEnergyType emsBaseEnergyType)
    {
        return toAjax(emsBaseEnergyTypeService.insertEmsBaseEnergyType(emsBaseEnergyType));
    }

    /**
     * 修改能源类型信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:edit')")
    @Log(title = "能源类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsBaseEnergyType emsBaseEnergyType)
    {
        return toAjax(emsBaseEnergyTypeService.updateEmsBaseEnergyType(emsBaseEnergyType));
    }

    /**
     * 删除能源类型信息
     */
    @PreAuthorize("@ss.hasPermi('ems/base:baseEnergyType:remove')")
    @Log(title = "能源类型信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsBaseEnergyTypeService.deleteEmsBaseEnergyTypeByObjIds(objIds));
    }
}
