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.EmsBaseEnergyPrice;
import org.dromara.ems.base.service.IEmsBaseEnergyPriceService;
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/baseEnergyPrice")
public class EmsBaseEnergyPriceController extends EmsBaseController
{

    private final IEmsBaseEnergyPriceService emsBaseEnergyPriceService;

    /**
     * 查询能源月份单价列表
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsBaseEnergyPrice emsBaseEnergyPrice)
    {
        startPage();
        List<EmsBaseEnergyPrice> list = emsBaseEnergyPriceService.selectEmsBaseEnergyPriceList(emsBaseEnergyPrice);
        return getDataTable(list);
    }

    /**
     * 导出能源月份单价列表
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:export")
    @Log(title = "能源月份单价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsBaseEnergyPrice emsBaseEnergyPrice)
    {
        List<EmsBaseEnergyPrice> list = emsBaseEnergyPriceService.selectEmsBaseEnergyPriceList(emsBaseEnergyPrice);
        ExcelUtil.exportExcel(list, "能源月份单价数据", EmsBaseEnergyPrice.class, response);
    }

    /**
     * 获取能源月份单价详细信息
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:query")
    @GetMapping(value = "/{objId}")
    public R<?> getInfo(@PathVariable("objId") Long objId)
    {
        return success(emsBaseEnergyPriceService.selectEmsBaseEnergyPriceByObjId(objId));
    }

    /**
     * 新增能源月份单价
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:add")
    @Log(title = "能源月份单价", businessType = BusinessType.INSERT)
    @PostMapping
    public R<?> add(@RequestBody EmsBaseEnergyPrice emsBaseEnergyPrice)
    {
        return toAjax(emsBaseEnergyPriceService.insertEmsBaseEnergyPrice(emsBaseEnergyPrice));
    }

    /**
     * 修改能源月份单价
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:edit")
    @Log(title = "能源月份单价", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<?> edit(@RequestBody EmsBaseEnergyPrice emsBaseEnergyPrice)
    {
        return toAjax(emsBaseEnergyPriceService.updateEmsBaseEnergyPrice(emsBaseEnergyPrice));
    }

    /**
     * 删除能源月份单价
     */
    @SaCheckPermission("ems/base:baseEnergyPrice:remove")
    @Log(title = "能源月份单价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public R<?> remove(@PathVariable Long[] objIds)
    {
        return toAjax(emsBaseEnergyPriceService.deleteEmsBaseEnergyPriceByObjIds(objIds));
    }
}
