package net.vtstar.zhongtong.avi.report.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.utils.domain.Return;
import net.vtstar.zhongtong.avi.monitoring.domain.Warning;
import net.vtstar.zhongtong.avi.report.domain.vo.EquStatePercent;
import net.vtstar.zhongtong.avi.report.domain.vo.TrendVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@Api(description = "中控室监控页面")
@RestController

@RequestMapping("/area")
public class ReportController {

    @ApiOperation(value = "设备利用率")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/oeu")
    private Return getOeu(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                          @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {

        return Return.success(new BigDecimal(53.2));
    }

    @ApiOperation(value = "设备故障率")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/efr")
    private Return getOeuTrend(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                               @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {

        return Return.success(new BigDecimal(5.2));
    }

    @ApiOperation(value = "设备利用率趋势图", response = TrendVO.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/oeuTrend")
    private Return getEfr(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                          @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {
        List<TrendVO> trendVOS = new ArrayList<>();
        for (int i = 1; i < 5; i++) {
            TrendVO trendVO = new TrendVO();
            trendVO.setDate("20190" + i);
            trendVO.setPercent(new BigDecimal(i));
            trendVOS.add(trendVO);

        }
        return Return.success(trendVOS);
    }

    @ApiOperation(value = "设备故障率趋势图")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/efrTrend")
    private Return getEfrTrend(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                               @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {
        List<TrendVO> trendVOS = new ArrayList<>();
        for (int i = 1; i < 5; i++) {
            TrendVO trendVO = new TrendVO();
            trendVO.setDate("20190" + i);
            trendVO.setPercent(new BigDecimal(i));
            trendVOS.add(trendVO);
        }
        return Return.success(trendVOS);
    }


    @ApiOperation(value = "设备运行状态")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/equState")
    private Return getEquState(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                               @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {
        ArrayList<EquStatePercent> percents = new ArrayList<>();
        EquStatePercent percent = new EquStatePercent();
        percent.setName("故障");
        percent.setValue(BigDecimal.valueOf(8));
        EquStatePercent percent2 = new EquStatePercent();
        percent2.setName("运行");
        percent2.setValue(BigDecimal.valueOf(70));
        EquStatePercent percent3 = new EquStatePercent();
        percent3.setName("待机");
        percent3.setValue(BigDecimal.valueOf(22));
        percents.add(percent);
        percents.add(percent2);
        percents.add(percent3);
        return Return.success(percents);
    }

    @ApiOperation(value = "设备状态趋势图", response = TrendVO.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "beginTime", value = "起始日期", dataType = "date", paramType = "query", example = "2019-01-23T07:26:06.742Z"),
            @ApiImplicitParam(name = "endTime", value = "截止日期", dataType = "date", paramType = "query", example = "2019-03-23T07:26:06.742Z")
    })
    @GetMapping("/stateTrend")
    private Return getEquStateTrend(@RequestParam(value = "beginTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date beginTime,
                                    @RequestParam(value = "endTime", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endTime) {
        ArrayList<TrendVO> percents = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            TrendVO trendVO = new TrendVO();
            trendVO.setDate("20190" + i);
            trendVO.setRunStatePercent(BigDecimal.valueOf(30));
            trendVO.setErrorStatePercent(BigDecimal.valueOf(10));
            trendVO.setLoadStatePercent(BigDecimal.valueOf(60));
            percents.add(trendVO);
        }
        return Return.success(percents);
    }

    @ApiOperation("设备异常列表")
    @GetMapping("/warningList")
    private Return getWarningList(){

        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("HH:mm");
        String time = format.format(date);
        List<Warning> warnings = new ArrayList<>();
        Warning warning = new Warning();
        warning.setTime(time);
        warning.setInfo("设备停止运动");
        warning.setEquipName("旋转棍床");
        warning.setTime(time);
        Warning warning1 = new Warning();
        warning1.setEquipName("前处理");
        warning1.setTime(time);
        warning1.setInfo("设备发生异常");
        warnings.add(warning);
        warnings.add(warning1);
        return Return.success(warnings);
    }
}
