package org.dromara.ems.base.controller;

import org.dromara.common.log.annotation.Log;
import org.dromara.ems.common.web.EmsBaseController;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.ems.base.domain.EmsBaseEnergyType;
import org.dromara.ems.base.service.IEmsBaseEnergyTypeService;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 能源类型信息Controller
 * 
 * @author Yinq
 * @date 2024-05-08
 */
@RestController
@RequiredArgsConstructor

@RequestMapping("/ems/base/baseEnergyType")
public class EmsBaseEnergyTypeController extends EmsBaseController
{

    private final IEmsBaseEnergyTypeService emsBaseEnergyTypeService;

    /**
     * 查询能源类型信息列表
     */
    @SaCheckPermission("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 R<?> queryEnergyNameByEnergyTypeId(int energyTypeId)
//    {
//        String energyName = emsBaseEnergyTypeService.queryEnergyNameByEnergyTypeId(energyTypeId);
//        return success(energyName);
//    }

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

    /**
     * 导出能源类型信息列表
     */
    @SaCheckPermission("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.exportExcel(list, "能源类型信息数据", EmsBaseEnergyType.class, response);
    }

    /**
     * 获取能源类型信息详细信息
     */
    @SaCheckPermission("ems/base:baseEnergyType:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsBaseEnergyTypeService.selectEmsBaseEnergyTypeByObjId(objId));
    }

    /**
     * 新增能源类型信息
     */
    @SaCheckPermission("ems/base:baseEnergyType:add")
    @Log(title = "能源类型信息", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseEnergyType emsBaseEnergyType)
    {
        return toAjax(emsBaseEnergyTypeService.insertEmsBaseEnergyType(emsBaseEnergyType));
    }

    /**
     * 修改能源类型信息
     */
    @SaCheckPermission("ems/base:baseEnergyType:edit")
    @Log(title = "能源类型信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseEnergyType emsBaseEnergyType)
    {
        return toAjax(emsBaseEnergyTypeService.updateEmsBaseEnergyType(emsBaseEnergyType));
    }

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