package com.ruoyi.web.controller.ems;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.domain.EmissionFactor;
import com.ruoyi.ems.service.IEmissionFactorService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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-11
 */
@RestController
@RequestMapping("/ems/basecfg/cacfg")
@Api(value = "CaConfigController", description = "排放因子管理")
public class CaConfigController extends BaseController
{
    @Autowired
    private IEmissionFactorService emissionFactorService;

    /**
     * 查询排放因子维列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:list')")
    @GetMapping("/emissionFactor/list")
    public TableDataInfo listEmissionFactor(EmissionFactor emissionFactor)
    {
        startPage();
        List<EmissionFactor> list = emissionFactorService.selectEmissionFactorList(emissionFactor);
        return getDataTable(list);
    }

    /**
     * 导出排放因子维列表
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:export')")
    @Log(title = "排放因子", businessType = BusinessType.EXPORT)
    @PostMapping("/emissionFactor/export")
    public void export(HttpServletResponse response, EmissionFactor emissionFactor)
    {
        List<EmissionFactor> list = emissionFactorService.selectEmissionFactorList(emissionFactor);
        ExcelUtil<EmissionFactor> util = new ExcelUtil<EmissionFactor>(EmissionFactor.class);
        util.exportExcel(response, list, "排放因子维数据");
    }

    /**
     * 获取排放因子维详细信息
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:query')")
    @GetMapping(value = "/emissionFactor/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emissionFactorService.selectEmissionFactorById(id));
    }

    /**
     * 新增排放因子维
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:add')")
    @Log(title = "排放因子", businessType = BusinessType.INSERT)
    @PostMapping(value = "/emissionFactor")
    public AjaxResult add(@RequestBody EmissionFactor emissionFactor)
    {
        return toAjax(emissionFactorService.insertEmissionFactor(emissionFactor));
    }

    /**
     * 修改排放因子维
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:edit')")
    @Log(title = "排放因子", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/emissionFactor")
    public AjaxResult edit(@RequestBody EmissionFactor emissionFactor)
    {
        return toAjax(emissionFactorService.updateEmissionFactor(emissionFactor));
    }

    /**
     * 删除排放因子维
     */
    @PreAuthorize("@ss.hasPermi('basecfg:cacfg:remove')")
    @Log(title = "排放因子", businessType = BusinessType.DELETE)
	@DeleteMapping("/emissionFactor/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emissionFactorService.deleteEmissionFactorByIds(ids));
    }
}
