package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
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.CaEmissionForecast;
import com.ruoyi.ems.service.ICaEmissionForecastService;
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-08-12
 */
@RestController
@RequestMapping("/forecastCa")
@Api(value = "CaEmissionForecastController", description = "碳排放预测数据接口")
public class CaEmissionForecastController extends BaseController
{
    @Autowired
    private ICaEmissionForecastService caEmissionForecastService;

    /**
     * 查询碳排放预测列表
     */
    @RequiresPermissions("prediction:ca:list")
    @GetMapping("/list")
    public TableDataInfo list(CaEmissionForecast emissionForecast)
    {
        startPage();
        List<CaEmissionForecast> list = caEmissionForecastService.selectCaEmissionForecastList(emissionForecast);
        return getDataTable(list);
    }

    /**
     * 导出碳排放预测列表
     */
    @RequiresPermissions("prediction:ca:export")
    @Log(title = "碳排放预测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CaEmissionForecast emissionForecast)
    {
        List<CaEmissionForecast> list = caEmissionForecastService.selectCaEmissionForecastList(emissionForecast);
        ExcelUtil<CaEmissionForecast> util = new ExcelUtil<CaEmissionForecast>(CaEmissionForecast.class);
        util.exportExcel(response, list, "碳排放预测数据");
    }

    /**
     * 获取碳排放预测详细信息
     */
    @RequiresPermissions("prediction:ca:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(caEmissionForecastService.selectCaEmissionForecastById(id));
    }

    /**
     * 新增碳排放预测
     */
    @RequiresPermissions("prediction:ca:add")
    @Log(title = "碳排放预测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CaEmissionForecast emissionForecast)
    {
        return toAjax(caEmissionForecastService.insertCaEmissionForecast(emissionForecast));
    }

    /**
     * 修改碳排放预测
     */
    @RequiresPermissions("prediction:ca:edit")
    @Log(title = "碳排放预测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CaEmissionForecast CaEmissionForecast)
    {
        return toAjax(caEmissionForecastService.updateCaEmissionForecast(CaEmissionForecast));
    }

    /**
     * 删除碳排放预测
     */
    @RequiresPermissions("prediction:ca:remove")
    @Log(title = "碳排放预测", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(caEmissionForecastService.deleteCaEmissionForecastByIds(ids));
    }
}
