/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.youchain.report_data.rest;

import cn.hutool.json.JSONUtil;
import com.youchain.annotation.Log;
import com.youchain.annotation.rest.AnonymousGetMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.icepear.echarts.Gauge;
import org.icepear.echarts.Line;
import org.icepear.echarts.charts.gauge.*;
import org.icepear.echarts.charts.line.LineAreaStyle;
import org.icepear.echarts.charts.line.LineSeries;
import org.icepear.echarts.components.coord.cartesian.CategoryAxis;
import org.icepear.echarts.components.series.ItemStyle;
import org.icepear.echarts.components.series.LineStyle;
import org.icepear.echarts.liuxue.*;
import org.icepear.echarts.origin.coord.AxisTickOption;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
* @website https://eladmin.vip
* @author liuxue
* @date 2023-11-24
**/
@Slf4j
@RestController
@RequiredArgsConstructor
@Api(tags = "data_report管理")
@RequestMapping("/api/report_api")
public class ReportDemoController {




    @AnonymousGetMapping(value = "/line/{index}")
    @Log("查询data_report")
    @ApiOperation("根据Index查询data_report")
    public ResponseEntity<Object> queryReportList(@PathVariable int index){

        log.error("查询所有报表Demo："+index);
        Line line=null;
        switch (index){
            case 1:
                 line = new Line()
                         .addXAxis(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" })
                         .addYAxis()
                         .addSeries(new Number[] { 150, 230, 224, 218, 135, 147, 260 });

                return new ResponseEntity<>( line.getOption(),HttpStatus.OK);
            case 2:
                 line = new Line()
                         .addXAxis(new CategoryAxis()
                                 .setBoundaryGap(false)
                                 .setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }))
                         .addYAxis()
                         .addSeries(new LineSeries()
                                 .setData(new Number[] { 820, 932, 901, 934, 1290, 1330, 1320 })
                                 .setAreaStyle(new LineAreaStyle()));

                return new ResponseEntity<>( line.getOption(),HttpStatus.OK);
            case 3:
                line=new Line()
                        .setTitle("Stacked Line")
                        .setTooltip("axis")
                        .setLegend()
                        .addXAxis(new CategoryAxis()
                                .setBoundaryGap(false)
                                .setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }))
                        .addYAxis()
                        .addSeries(new LineSeries().setName("Email").setStack("Total")
                                .setData(new Number[] { 120, 132, 101, 134, 90, 230, 210 }))
                        .addSeries(new LineSeries().setName("Union Ads").setStack("Total")
                                .setData(new Number[] { 220, 182, 191, 234, 290, 330, 310 }))
                        .addSeries(new LineSeries().setName("Video Ads").setStack("Total")
                                .setData(new Number[] { 150, 232, 201, 154, 190, 330, 410 }))
                        .addSeries(new LineSeries().setName("Direct").setStack("Total")
                                .setData(new Number[] { 320, 332, 301, 334, 390, 330, 320 }))
                        .addSeries(new LineSeries().setName("Search Engine").setStack("Total")
                                .setData(new Number[] { 820, 932, 901, 934, 1290, 1330, 1320 }));

                return new ResponseEntity<>( line.getOption(),HttpStatus.OK);

            case 4:
                line=new Line()
                        .addXAxis(new CategoryAxis()
                                .setBoundaryGap(false)
                                .setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }))
                        .addYAxis()
                        .addSeries(new LineSeries()
                                .setData(new Number[] { 820, 932, 901, 934, 1290, 1330, 1320 })
                                .setAreaStyle(new LineAreaStyle()));

                return new ResponseEntity<>( line.getOption(),HttpStatus.OK);

            case 5:
                line = new Line()
                        .setTitle("Stacked Area")
                        .setBackgroundColor("#ffffff50")
                        .setTooltip("axis")
                        .setLegend()
                        .addXAxis(new CategoryAxis().setBoundaryGap(false)
                                .setData(new String[] { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }))
                        .addYAxis()
                        .addSeries(createSeries("Line 1", new Number[] { 140, 232, 101, 264, 90, 340, 250 }))
                        .addSeries(createSeries("Line 2", new Number[] { 120, 282, 111, 234, 220, 340, 310 }))
                        .addSeries(createSeries("Line 3", new Number[] { 320, 132, 201, 334, 190, 130, 220 }))
                        .addSeries(createSeries("Line 4", new Number[] { 220, 402, 231, 134, 190, 230, 120 }))
                        .addSeries(createSeries("Line 5", new Number[] { 220, 302, 181, 234, 210, 290, 150 }));

                return new ResponseEntity<>( line.getOption(),HttpStatus.OK);
            case 6:

                int max_i=20;
                int max_j=30;

                kuWeiInfo kuWeiInfo=new kuWeiInfo();
                kuWeiInfo.setMovieName("就是这样");
                //kuWeiInfo.setWidth(2.0);
                //kuWeiInfo.setHeight(2.0);
                kuWeiInfo.setMg_top(0.0);
                kuWeiInfo.setMg_left(0.0);
                //kuWeiInfo.setPositionDistin(2.1);
                List<kuWei_seat> seatList=new ArrayList<>();
                for (int i=1;i<max_i;i++) {
                    for (int j=1;j<max_j;j++) {
                        kuWei_seat kuWeiSeat=new kuWei_seat();
                        kuWeiSeat.setId(i+""+j);
                        kuWeiSeat.setGRow(i);
                        kuWeiSeat.setGCol(j);
                        Random r1 = new Random();

                        kuWeiSeat.setType(""+r1.nextInt(3));
                        seatList.add(kuWeiSeat);
                    }
                }
                kuWeiInfo.setSeatList(seatList);
                return new ResponseEntity<>( kuWeiInfo,HttpStatus.OK);

            case 7:
                List<ColorStops> colorStops=new ArrayList<>();
                colorStops.add(new ColorStops(0,"#000000"));
                colorStops.add(new ColorStops(1,"#FF0000"));
                JianBianColor jianBianColor=new JianBianColor("linear",0.8,0,0,1,colorStops,false);

                Gauge gauge = new Gauge()


                        .setTooltip("item")
                        .addSeries(new GaugeSeries().setName("Pressure")
                                .setStartAngle(90)
                                .setEndAngle(-270)
                                .setMin(0)
                                .setMax(100)
                                .setItemStyle(new ItemStyle().setColor("#FDFF00"))
                                .setProgress(new GaugeProgress().setShow(true).setRoundCap(false).setWidth(20).setItemStyle(new ItemStyle().setColor(jianBianColor).setBorderWidth(0)))
                                .setPointer(new GaugePointer().setShow(false))
                                .setAxisLine(new AxisLine().setLineStyle(new LineStyle().setWidth(20)))
                                .setSplitLine(new SplitLine(-62,0,new LineStyle().setWidth(3).setColor("#ff0000")))
                                .setAxisTick(new AxisTick(-45,5,new LineStyle().setWidth(3).setColor("#ff0000")))
                                .setAxisLabel(new AxisLabel())
                                .setAnchor(new GaugeAnchor().setShow(false))
                                .setTitle(new GaugeTitle().setShow(false))
                                .setDetail(new GaugeDetail().setValueAnimation(true).setWidth("100%").setBorderRadius(8).setOffsetCenter(new String[]{"0","0%"}).setFontSize(60).setColor("#f0f0ff"))
                                .setData(new GaugeDataItem[] { new GaugeDataItem().setValue(80).setName("SCORE") }));
                log.error(""+ JSONUtil.toJsonStr( gauge.getOption()));
                return new ResponseEntity<>( gauge.getOption(),HttpStatus.OK);
        }
        return new ResponseEntity<>("",HttpStatus.OK);
    }

    LineSeries createSeries(String name, Object[] data) {
        return new LineSeries()
                .setName(name)
                .setStack("Total")
                .setSmooth(true)
                .setLineStyle(new LineStyle().setWidth(0))
                .setShowSymbol(false)
                .setAreaStyle(new LineAreaStyle())
                .setData(data);
    }



}