package com.gyee.runeconomy.controller.goodness;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gyee.common.util.DateUtils;
import com.gyee.runeconomy.dto.DataVo;
import com.gyee.runeconomy.dto.R;
import com.gyee.runeconomy.dto.ResultMsg;
import com.gyee.runeconomy.model.auto.ProEconInOrOutSpeedTotal2;
import com.gyee.runeconomy.service.auto.IProEconInOrOutSpeedTotal2Service;
import com.gyee.runeconomy.util.StringUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 单机性能分析列表
 */
@Controller
@RequestMapping("/goodness")
@Api(value = "单机信息总览饼图", tags = "单机信息总览饼图")
public class WindturbineDetailPieChartAController {
    @Resource
    private IProEconInOrOutSpeedTotal2Service proEconInOrOutSpeedTotal2Service;

    /**
     * 饼图图表
     *
     * @param wtId
     * @param recorddate
     * @return
     */
    @GetMapping("/pieChart")
    @ResponseBody
    @ApiOperation(value = "查询等级评估日所有信息", notes = "查询等级评估日所有信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "wtId", value = "风机编号", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "recorddate", value = "日期", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "type", value = "类型 1:日小风切入，2：月小风切入，3：月小风切入,4:日小风停机，5：月小风停机，6：年小风停机", required = true, dataType = "string", paramType = "query")})

    public R pieChart(String wtId, String recorddate, String type) {

        List<DataVo> vos = new ArrayList<>();

        if (StringUtils.notEmp(recorddate) && StringUtils.notEmp(wtId) && StringUtils.notEmp(type)) {

            Date date = DateUtils.parseDate(recorddate);

            QueryWrapper<ProEconInOrOutSpeedTotal2> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("windturbine_id", wtId).eq("record_date", date);
            List<ProEconInOrOutSpeedTotal2> ls = proEconInOrOutSpeedTotal2Service.list(queryWrapper);
            //                    .stream().filter(i->
            //                    i.getWindturbineId().equals(wtId)
            //            && i.getRecordDate().compareTo(DateUtils.truncate(date)) ==0
            //            ).collect(Collectors.toList());

            if (!ls.isEmpty()) {

                vos = new ArrayList<DataVo>();
                ProEconInOrOutSpeedTotal2 io = ls.get(0);

                DataVo vo1 = new DataVo();
                DataVo vo2 = new DataVo();
                DataVo vo3 = new DataVo();
                DataVo vo4 = new DataVo();
                DataVo vo5 = new DataVo();
                DataVo vo6 = new DataVo();
                DataVo vo7 = new DataVo();
                switch (Integer.valueOf(type)) {
                    case 1:// 日小风切入
                        vo1.setName("日小于2风");
                        vo1.setValue1(io.getDaya1());
                        vo1.setValue2(io.getDaya8());

                        vo2.setName("日2-2.5风");
                        vo2.setValue1(io.getDaya2());
                        vo2.setValue2(io.getDaya9());

                        vo3.setName("日2.5-3风");
                        vo3.setValue1(io.getDaya3());
                        vo3.setValue2(io.getDaya10());

                        vo4.setName("日3-3.5风");
                        vo4.setValue1(io.getDaya4());
                        vo4.setValue2(io.getDaya11());

                        vo5.setName("日3.5-4风");
                        vo5.setValue1(io.getDaya5());
                        vo5.setValue2(io.getDaya12());

                        vo6.setName("日4-5风");
                        vo6.setValue1(io.getDaya6());
                        vo6.setValue2(io.getDaya13());

                        vo7.setName("日大于5风");
                        vo7.setValue1(io.getDaya7());
                        vo7.setValue2(io.getDaya14());

                        break;
                    case 2:// 月小风切入
                        vo1.setName("月小于2风");
                        vo1.setValue1(io.getMontha1());
                        vo1.setValue2(io.getMontha8());

                        vo2.setName("月2-2.5风");
                        vo2.setValue1(io.getMontha2());
                        vo2.setValue2(io.getMontha9());

                        vo3.setName("月2.5-3风");
                        vo3.setValue1(io.getMontha3());
                        vo3.setValue2(io.getMontha10());

                        vo4.setName("月3-3.5风");
                        vo4.setValue1(io.getMontha4());
                        vo4.setValue2(io.getMontha11());

                        vo5.setName("月3.5-4风");
                        vo5.setValue1(io.getMontha5());
                        vo5.setValue2(io.getMontha12());

                        vo6.setName("月4-5风");
                        vo6.setValue1(io.getMontha6());
                        vo6.setValue2(io.getMontha13());

                        vo7.setName("月大于5风");
                        vo7.setValue1(io.getMontha7());
                        vo7.setValue2(io.getMontha14());

                        break;
                    case 3: // 年小风切入
                        vo1.setName("年小于2风");
                        vo1.setValue1(io.getYeara1());
                        vo1.setValue2(io.getYeara8());

                        vo2.setName("年2-2.5风");
                        vo2.setValue1(io.getYeara2());
                        vo2.setValue2(io.getYeara9());

                        vo3.setName("年2.5-3风");
                        vo3.setValue1(io.getYeara3());
                        vo3.setValue2(io.getYeara10());

                        vo4.setName("年3-3.5风");
                        vo4.setValue1(io.getYeara4());
                        vo4.setValue2(io.getYeara11());

                        vo5.setName("年3.5-4风");
                        vo5.setValue1(io.getYeara5());
                        vo5.setValue2(io.getYeara12());

                        vo6.setName("年4-5风");
                        vo6.setValue1(io.getYeara6());
                        vo6.setValue2(io.getYeara13());

                        vo7.setName("年大于5风");
                        vo7.setValue1(io.getYeara7());
                        vo7.setValue2(io.getYeara14());

                        break;
                    case 4:// 日小风停机
                        vo1.setName("日小于2风");
                        vo1.setValue1(io.getDayb1());
                        vo1.setValue2(io.getDayb8());

                        vo2.setName("日2-2.5风");
                        vo2.setValue1(io.getDayb2());
                        vo2.setValue2(io.getDayb9());

                        vo3.setName("日2.5-3风");
                        vo3.setValue1(io.getDayb3());
                        vo3.setValue2(io.getDayb10());

                        vo4.setName("日3-3.5风");
                        vo4.setValue1(io.getDayb4());
                        vo4.setValue2(io.getDayb11());

                        vo5.setName("日3.5-4风");
                        vo5.setValue1(io.getDayb5());
                        vo5.setValue2(io.getDayb12());

                        vo6.setName("日4-5风");
                        vo6.setValue1(io.getDayb6());
                        vo6.setValue2(io.getDayb13());

                        vo7.setName("日大于5风");
                        vo7.setValue1(io.getDayb7());
                        vo7.setValue2(io.getDayb14());

                        break;
                    case 5:// 月小风停机
                        vo1.setName("月小于2风");
                        vo1.setValue1(io.getMonthb1());
                        vo1.setValue2(io.getMonthb8());

                        vo2.setName("月2-2.5风");
                        vo2.setValue1(io.getMonthb2());
                        vo2.setValue2(io.getMonthb9());

                        vo3.setName("月2.5-3风");
                        vo3.setValue1(io.getMonthb3());
                        vo3.setValue2(io.getMonthb10());

                        vo4.setName("月3-3.5风");
                        vo4.setValue1(io.getMonthb4());
                        vo4.setValue2(io.getMonthb11());

                        vo5.setName("月3.5-4风");
                        vo5.setValue1(io.getMonthb5());
                        vo5.setValue2(io.getMonthb12());

                        vo6.setName("月4-5风");
                        vo6.setValue1(io.getMonthb6());
                        vo6.setValue2(io.getMonthb13());

                        vo7.setName("月大于5风");
                        vo7.setValue1(io.getMonthb7());
                        vo7.setValue2(io.getMonthb14());

                        break;
                    case 6: // 年小风停机
                        vo1.setName("年小于2风");
                        vo1.setValue1(io.getYearb1());
                        vo1.setValue2(io.getYearb8());

                        vo2.setName("年2-2.5风");
                        vo2.setValue1(io.getYearb2());
                        vo2.setValue2(io.getYearb9());

                        vo3.setName("年2.5-3风");
                        vo3.setValue1(io.getYearb3());
                        vo3.setValue2(io.getYearb10());

                        vo4.setName("年3-3.5风");
                        vo4.setValue1(io.getYearb4());
                        vo4.setValue2(io.getYearb11());

                        vo5.setName("年3.5-4风");
                        vo5.setValue1(io.getYearb5());
                        vo5.setValue2(io.getYearb12());

                        vo6.setName("年4-5风");
                        vo6.setValue1(io.getYearb6());
                        vo6.setValue2(io.getYearb13());

                        vo7.setName("年大于5风");
                        vo7.setValue1(io.getYearb7());
                        vo7.setValue2(io.getYearb14());

                        break;
                    default:
                        break;
                }

                vos.add(vo1);
                vos.add(vo2);
                vos.add(vo3);
                vos.add(vo4);
                vos.add(vo5);
                vos.add(vo6);
                vos.add(vo7);
            }

        }

        if (null != vos) {
            return R.data(ResultMsg.ok(vos));
        } else {
            return R.data(ResultMsg.error());
        }
    }


}
