package com.ruoyi.ems.controller;

import com.huashe.common.domain.AjaxResult;
import com.ruoyi.common.core.web.controller.BaseController;
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.EnergyMeter;
import com.ruoyi.ems.domain.WaterMeterH;
import com.ruoyi.ems.model.QueryMeter;
import com.ruoyi.ems.service.IWaterMeterHService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用水计量-小时Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/waterMeterH")
@Api(value = "WaterMeterHController", description = "用水计量-小时")
public class WaterMeterHController extends BaseController {
    @Autowired
    private IWaterMeterHService waterMeterHService;

    /**
     * 新增用水计量-小时
     */
    @RequiresPermissions("ems:waterMeterH:add")
    @Log(title = "用水计量-小时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WaterMeterH waterMeterH) {
        return toAjax(waterMeterHService.insertWaterMeterH(waterMeterH));
    }

    /**
     * 修改用水计量-小时
     */
    @RequiresPermissions("ems:waterMeterH:edit")
    @Log(title = "用水计量-小时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WaterMeterH waterMeterH) {
        return toAjax(waterMeterHService.updateWaterMeterH(waterMeterH));
    }

    /**
     * 删除用水计量-小时
     */
    @RequiresPermissions("ems:waterMeterH:remove")
    @Log(title = "用水计量-小时", businessType = BusinessType.DELETE)
    @DeleteMapping("/delByDate")
    public AjaxResult remove(@RequestParam(name = "date") String date) {
        return toAjax(waterMeterHService.deleteWaterMeterHByDate(date));
    }


    @GetMapping("/sum/byDate/{date}")
    public AjaxResult qryWaterMeterByDate(@PathVariable(name = "date") String date, @RequestParam(name = "areaCode", required = false) String areaCode) {
        return success(waterMeterHService.qryWaterMeterByDate(date, areaCode));
    }

    @GetMapping("/sum/timeIndex/byDate/{date}/{timeIndex}")
    public AjaxResult qryTimeIndexWaterMeterByDay(@PathVariable(name = "date") String date,
                                                  @PathVariable(name = "timeIndex") Integer timeIndex) {
        return success(waterMeterHService.qryTimeIndexWaterMeterByDay(date, timeIndex));
    }

    @GetMapping("/sum/date/byDate/{date}")
    public AjaxResult qryDateWaterMeterByDay(@PathVariable(name = "date") String date) {
        return success(waterMeterHService.qryDateWaterMeterByDay(date));
    }

    @GetMapping("/sum/date/byYear/{date}")
    public AjaxResult qryDateWaterMeterByYear(@PathVariable(name = "date") String date) {
        return success(waterMeterHService.qryDateWaterMeterByYear(date));
    }

    /**
     * 计算时间范围内日平均
     *
     * @param queryMeter 支持areaCode、deviceCode、date范围筛选
     * @return ElecMeter
     */
    @GetMapping("/day/avg")
    public AjaxResult selectElecDayAvg(QueryMeter queryMeter) {
        EnergyMeter waterMeter = waterMeterHService.selectWaterDayAvg(queryMeter);
        return success(waterMeter);
    }
}
