package cn.cecep.talroad.controller;

import cn.cecep.talroad.common.core.utils.poi.ExcelUtil;
import cn.cecep.talroad.common.core.web.controller.BasesController;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.common.log.annotation.Log;
import cn.cecep.talroad.common.log.enums.BusinessType;
import cn.cecep.talroad.service.IMonElecRealService;
import cn.cecep.talroad.vo.EChartsVO;
import cn.cecep.talroad.vo.MonElecRealVo;
import cn.cecep.talroad.vo.query.MonElecRealQuery;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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


/**
 * * 开发公司：中节能天融科技有限公司
 * 分表计电设备-点位对应 设备与点位为多对多的关系Controller 控制层
 *
 * @author szhpt
 * @date 2023-01-10
 */
@Api(tags = "监测监控-分表计电设备-点位对应 设备与点位为多对多的关系")
@RestController
@RequestMapping("/monElecReal")
public class MonElecRealController extends BasesController {
    @Autowired
    private IMonElecRealService monElecRealService;


    @ApiOperation(value = "查询分表计电设备-点位对应 设备与点位为多对多的关系")
    @GetMapping("/list")
    public AjaxResults<IPage<MonElecRealVo>> list(MonElecRealQuery monElecReal) {
        Page<MonElecRealVo> page = new Page<>(monElecReal.getPageNum(), monElecReal.getPageSize());
        monElecRealService.elecRealPage(page, monElecReal);
        return AjaxResults.success(page);
    }

    @ApiOperation(value = "查询分表计电曲线图数据")
    @GetMapping("/charData")
    public AjaxResults<EChartsVO> charData(MonElecRealQuery monElecReal) {
        EChartsVO chartsVO = monElecRealService.getCharData(monElecReal);
        return AjaxResults.success(chartsVO);
    }

    @ApiOperation(value = "导出分表计电设备-点位对应 设备与点位为多对多的关系")
    @Log(title = "分表计电设备-点位对应 设备与点位为多对多的关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestBody MonElecRealQuery monElecReal) {
        Page<MonElecRealVo> page = new Page<>(monElecReal.getPageNum(), monElecReal.getPageSize());
        List<MonElecRealVo> vos = monElecRealService.elecRealPage(page, monElecReal);
        ExcelUtil<MonElecRealVo> util = new ExcelUtil<>(MonElecRealVo.class);
        util.exportExcel(response, vos, "sheet1");
    }

    @ApiOperation(value = "分表计电大屏-用电趋势总览")
    @GetMapping("/kwhChart")
    public AjaxResults<EChartsVO> kwhChartData(
            @ApiParam(name = "startTime", value = "开始日期") @RequestParam("startTime") String startTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam("endTime") String endTime
    ) {
        EChartsVO chartsVO = monElecRealService.getKwhChartData(startTime, endTime);
        return AjaxResults.success(chartsVO);
    }

    @ApiOperation(value = "分表计电大屏-用电量监控")
    @GetMapping("/kwhMonitor")
    public AjaxResults<List<MonElecRealVo.KwhMonitorVo>> kwhMonitor(
            @ApiParam(name = "type", value = "1:按区域, 2:按行业") @RequestParam("type") String type,
            @ApiParam(name = "startTime", value = "开始日期") @RequestParam("startTime") String startTime,
            @ApiParam(name = "endTime", value = "结束日期") @RequestParam("endTime") String endTime
    ) {
        List<MonElecRealVo.KwhMonitorVo> vos = monElecRealService.getKwhMonitor(type, startTime, endTime);
        return AjaxResults.success(vos);
    }

}
