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.EmsEcoD;
import com.ruoyi.ems.service.IEmsEcoDService;
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 2025-04-22
 */
@RestController
@RequestMapping("/EmsEcoD")
public class EmsEcoDController extends BaseController {
    @Autowired
    private IEmsEcoDService emsEcoDService;

    /**
     * 查询节能计量日列表
     */
    @RequiresPermissions("ems:EmsEcoD:list")
    @GetMapping("/list")
    public TableDataInfo list(EmsEcoD admEmsEcoD) {
        startPage();
        List<EmsEcoD> list = emsEcoDService.selectEmsEcoDList(admEmsEcoD);
        return getDataTable(list);
    }

    /**
     * 导出节能计量日列表
     */
    @RequiresPermissions("ems:EmsEcoD:export")
    @Log(title = "节能计量日", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsEcoD admEmsEcoD) {
        List<EmsEcoD> list = emsEcoDService.selectEmsEcoDList(admEmsEcoD);
        ExcelUtil<EmsEcoD> util = new ExcelUtil<EmsEcoD>(EmsEcoD.class);
        util.exportExcel(response, list, "节能计量日数据");
    }

    /**
     * 获取节能计量日详细信息
     */
    @RequiresPermissions("ems:EmsEcoD:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(emsEcoDService.selectEmsEcoDById(id));
    }

    /**
     * 新增节能计量日
     */
    @RequiresPermissions("ems:EmsEcoD:add")
    @Log(title = "节能计量日", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsEcoD admEmsEcoD) {
        return toAjax(emsEcoDService.insertEmsEcoD(admEmsEcoD));
    }

    /**
     * 修改节能计量日
     */
    @RequiresPermissions("ems:EmsEcoD:edit")
    @Log(title = "节能计量日", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsEcoD admEmsEcoD) {
        return toAjax(emsEcoDService.updateEmsEcoD(admEmsEcoD));
    }

    /**
     * 删除节能计量日
     */
    @RequiresPermissions("ems:EmsEcoD:remove")
    @Log(title = "节能计量日", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(emsEcoDService.deleteEmsEcoDByIds(ids));
    }

    @GetMapping(value = "/date/range")
    public AjaxResult calcAdmEmsEcoDateRange(EmsEcoD admEmsEcoD) {
        return success(emsEcoDService.calcEmsEcoDateRange(admEmsEcoD));
    }
}
