package com.gyee.runeconomy.controller.Application;

import com.gyee.runeconomy.dto.AjaxResult;
import com.gyee.runeconomy.model.vo.YcdlVo;
import com.gyee.runeconomy.service.Application.ApplicationService;
import com.gyee.runeconomy.service.Application.CompanylossesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("//bulletinapp")
@Api(value = "手机APP", tags = "手机APP")
public class ApplicationController {

    @Resource
    private ApplicationService applicationService;

    @Resource
    private CompanylossesService companylossesService;

    @GetMapping(value = "/bulletin")
    @ApiOperation(value = "简报", notes = "简报")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = true, dataType = "string", paramType = "query")})
    public AjaxResult getinformation(String wpId) throws Exception {

        Map<String, String> map = new HashMap<>();
        if (!wpId.isEmpty()) {
            map = applicationService.bulletin(wpId);
        }
        if (null != map) {
            return AjaxResult.successData(200, map);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping(value = "/companyelectricity")
    @ApiOperation(value = "公司电量", notes = "公司电量")

    public AjaxResult getelectricity() throws Exception {

        Map<String, String> map = new HashMap<>();

        map = applicationService.electricity();

        if (null != map) {
            return AjaxResult.successData(200, map);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping(value = "/forecast")
    @ApiOperation(value = "公司预测电量", notes = "公司预测电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })
    public AjaxResult getforecast(String type, String wpId) throws Exception {

        Map<Integer, Object> list = new HashMap<>();
        if (wpId != null) {
            list = applicationService.forecast(type, wpId);
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


    @GetMapping(value = "/czforecast")
    @ApiOperation(value = "场站预测电量", notes = "场站预测电量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "场站编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })
    public AjaxResult getczforecast(String wpId) throws Exception {

        List<YcdlVo> list = new ArrayList<>();
        if (wpId != null) {
            list = applicationService.czforecast(wpId);
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


    @GetMapping(value = "/shutdowngs")
    @ApiOperation(value = "故障次数公司", notes = "故障次数公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult getshutdowngs(String type) throws Exception {

        List<Map<String, Object>> list = new ArrayList<>();

        list = applicationService.shutdown(type);

        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping(value = "/shutdowncz")
    @ApiOperation(value = "故障次数场站", notes = "故障次数场站")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })
    public AjaxResult getshutdowncz(String type, String wpId) throws Exception {

        List<Map<String, Object>> list = new ArrayList<>();
        if (wpId != null) {
            list = applicationService.shutdowncz(type, wpId);
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


    @GetMapping(value = "/shutdowngsjx")
    @ApiOperation(value = "机型故障次数公司", notes = "机型故障次数公司")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "编号", required = true, dataType = "string", paramType = "query")
    })
    public AjaxResult getshutdownjx(String type) throws Exception {

        List<Map<String, Object>> list = new ArrayList<>();

        list = applicationService.shutdownjx(type);

        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


    @GetMapping(value = "/shutdownczjx")
    @ApiOperation(value = "机型故障次数场站", notes = "机型故障次数场站")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })
    public AjaxResult getshutdownczjx(String type, String wpId) throws Exception {

        List<Map<String, Object>> list = new ArrayList<>();
        if (wpId != null) {
            list = applicationService.shutdownczjx(type, wpId);
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }

    @GetMapping(value = "/companylosses")
    @ApiOperation(value = "公司五损", notes = "公司五损")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wpId", value = "场站编号", required = false, dataType = "string", paramType = "query")
    })
    public AjaxResult getlosses(String wpId) throws Exception {

        Map<String, Double> list = new HashMap<>();
        if (wpId != null) {
            list = companylossesService.shutdownczjx(wpId);
        }
        if (null != list) {
            return AjaxResult.successData(200, list);
        } else {
            return AjaxResult.error(500, "操作失败");
        }

    }


}
