package com.zcxk.charge.web.controller;

import com.zcxk.charge.api.dto.AppSmsDataDto;
import com.zcxk.charge.api.dto.SceneDataForAppDto;
import com.zcxk.charge.api.dto.generalview.WaterSupplyChart;
import com.zcxk.charge.core.entity.SceneEntity;
import com.zcxk.charge.web.service.AppDataService;
import com.zcxk.charge.web.service.MonitorDataReportService;
import com.zcxk.charge.web.service.SceneService;
import com.zcxk.core.common.pojo.AjaxMessage;
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 java.util.List;

/**
 * App数据
 * @author yjy
 * @since 2020-11-17
 */
@RestController
@RequestMapping("/appData")
@Api(tags = "App数据")
public class AppDataController {
    @Autowired
    private AppDataService appDataService;
    @Autowired
    private SceneService sceneService;
    @Autowired
    private MonitorDataReportService monitorDataReportService;

    @RequestMapping(value = "getProductionDataForSameMonth", method = RequestMethod.GET)
    @ApiOperation(value = "综合调度——本月供水情况")
    public AjaxMessage<AppSmsDataDto> getMonthWaterSupply(@ApiParam(value = "类型名称(水源、水厂、泵站、售水)") @RequestParam String typeName) {
        AppSmsDataDto appSmsDataDto = appDataService.getProductionDataForSameMonth(typeName);
        return AjaxMessage.success(appSmsDataDto);
    }

    @RequestMapping(value = "/findByParentId", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "综合调度——工艺场景")
    public AjaxMessage<List<SceneEntity>> findByParentId(@ApiParam(value = "父级场景ID") @RequestParam(required = false) Long id) {
        List<SceneEntity> sceneEntities = sceneService.findByParentIdForApp(id);
        return AjaxMessage.success(sceneEntities);
    }


    @ApiOperation(value = "综合调度——工艺场景(详情)")
    @RequestMapping(value = "/findBySceneId", method = RequestMethod.GET)
    @ResponseBody
    public AjaxMessage<SceneDataForAppDto> findBySceneId(
            @ApiParam(value = "类型名称(水源、水厂、泵站)") @RequestParam String typeName,
            @ApiParam(value = "场景ID", required = true) @RequestParam Long id) {
        SceneDataForAppDto returnInfo = appDataService.getSceneDataForApp(typeName, id);
        return AjaxMessage.success(returnInfo);
    }

    @ApiOperation(value = "综合调度——供水制水电耗(曲线)")
    @RequestMapping(value = "/findwaterSupplyChartsForCurrentMonth", method = RequestMethod.GET)
    @ResponseBody
    public AjaxMessage<List<WaterSupplyChart>> waterSupplyChartsForCurrentMonth(
            @ApiParam(value = "类型名称(水源、水厂、泵站)") @RequestParam String typeName,
            @ApiParam(value = "场景ID", required = true) @RequestParam Long id) {
        List<WaterSupplyChart> waterSupplyCharts = monitorDataReportService.waterSupplyChartsForCurrentMonth(typeName, id);
        return AjaxMessage.success(waterSupplyCharts);
    }

}
