package com.zksy.electricity.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zksy.common.core.domain.Result;
import com.zksy.common.utils.SearchUtil;
import com.zksy.electricity.domain.MessageParseResult;
import com.zksy.electricity.domain.vo.MessageParseVo;
import com.zksy.electricity.domain.vo.PowerLoadDistributionVo;
import com.zksy.electricity.domain.vo.VoltageCurrentTrendVo;
import com.zksy.electricity.service.MessageParseResultService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messageParse")
@Api(tags = "电表数据信息", description = "电表数据信息")
public class MessageParseController {
    @Autowired
    private MessageParseResultService service;

    @GetMapping("/findByPage")
    @ApiOperation(value = "分页查询")
    public Result getPictureMessagePage(long pageNum, long pageSize, String conditionJson) throws Exception {
        Page<MessageParseResult> page = service.page(new Page<>(pageNum, pageSize), SearchUtil.parseWhereSql(conditionJson));
        return Result.ok(page);
    }
    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有")
    public Result getAllByConditionJson(String conditionJson) throws Exception {
        List<MessageParseResult> list = service.list(SearchUtil.parseWhereSql(conditionJson));
        return Result.ok(list);
    }


    @GetMapping("/summaryByTable")
    @ApiOperation(value = "按表号分组汇总统计")
    public Result getSummaryByTable() {
        List<MessageParseVo> vo = service.getSummaryByTableNumber();
        return Result.ok(vo);
    }

    @GetMapping("/voltageCurrentTrend")
    @ApiOperation(value = "按时间范围查询三相电压、电流趋势")
    public Result getVoltageCurrentTrend(
            @RequestParam String startTime,
            @RequestParam String endTime,
            @RequestParam(required = false) String tableNumber
    ) {
        VoltageCurrentTrendVo vo = service.getVoltageCurrentTrend(startTime, endTime, tableNumber);
        return Result.ok(vo);
    }

    @GetMapping("/powerLoadDistribution")
    @ApiOperation(value = "分时用电负荷分布")
    public Result getPowerLoadDistribution(
            @RequestParam(required = false) String tableNumber,
            @RequestParam String startTime,
            @RequestParam String endTime) {

        List<PowerLoadDistributionVo> list = service.getPowerLoadDistribution(tableNumber, startTime, endTime);

        return Result.ok(list);
    }
}