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.ElecStoreH;
import com.ruoyi.ems.model.ElecStoreAnalyze;
import com.ruoyi.ems.model.QueryMeter;
import com.ruoyi.ems.service.IElecStoreService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 储能计量-小时Controller
 *
 * @author ruoyi
 * @date 2024-08-09
 */
@RestController
@RequestMapping("/ems/elec/store")
@Api(value = "ElecStoreHController", description = "能计量-小时数据接口")
public class ElecStoreController extends BaseController {
    @Autowired
    private IElecStoreService elecStoreService;

    /**
     * 查询储能计量-小时列表
     */
    @GetMapping("/hour/list")
    public TableDataInfo listHour(ElecStoreH elecStoreH) {
        startPage();
        List<ElecStoreH> list = elecStoreService.selectHourList(elecStoreH);
        return getDataTable(list);
    }

    @GetMapping("/day/list")
    public AjaxResult listByDay(QueryMeter param) {
        List<ElecStoreH> list = elecStoreService.selectDayList(param);
        return success(list);
    }

    /**
     * 查询储能计量-小时列表
     */
    @GetMapping("/day/statistics")
    public AjaxResult getDayStatistics(@RequestParam(name = "date") String date) {
        ElecStoreAnalyze analyze = elecStoreService.getDayStatistics(date);
        return success(analyze);
    }

    /**
     * 导出储能计量-小时列表
     */
    @Log(title = "储能计量-小时", businessType = BusinessType.EXPORT)
    @PostMapping("/hour/export")
    public void export(HttpServletResponse response, ElecStoreH elecStoreH) {
        List<ElecStoreH> list = elecStoreService.selectHourList(elecStoreH);
        ExcelUtil<ElecStoreH> util = new ExcelUtil<ElecStoreH>(ElecStoreH.class);
        util.exportExcel(response, list, "储能计量-小时数据");
    }

    /**
     * 获取储能计量-小时详细信息
     */
    @GetMapping(value = "/hour/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(elecStoreService.selectHourById(id));
    }

    /**
     * 新增储能计量-小时
     */
    @PreAuthorize("@ss.hasPermi('power-mgr:gs:add')")
    @Log(title = "储能计量-小时", businessType = BusinessType.INSERT)
    @PostMapping("/hour")
    public AjaxResult add(@RequestBody ElecStoreH elecStoreH) {
        return toAjax(elecStoreService.insertHour(elecStoreH));
    }

    /**
     * 修改储能计量-小时
     */
    @PreAuthorize("@ss.hasPermi('power-mgr:gs:edit')")
    @Log(title = "储能计量-小时", businessType = BusinessType.UPDATE)
    @PutMapping("/hour")
    public AjaxResult edit(@RequestBody ElecStoreH elecStoreH) {
        return toAjax(elecStoreService.updateHour(elecStoreH));
    }

    /**
     * 删除储能计量-小时
     */
    @PreAuthorize("@ss.hasPermi('power-mgr:gs:remove')")
    @Log(title = "储能计量-小时", businessType = BusinessType.DELETE)
    @DeleteMapping("/hour/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(elecStoreService.deleteHourByIds(ids));
    }
}
