package com.gyee.runeconomy.controller;


import com.alibaba.fastjson.JSONObject;
import com.gyee.runeconomy.dto.fitting.Alarm;
import com.gyee.runeconomy.dto.fitting.AlarmDataVo;
import com.gyee.runeconomy.dto.fitting.AlarmRequest;
import com.gyee.runeconomy.dto.result.JsonResult;
import com.gyee.runeconomy.dto.result.PowerPointData;
import com.gyee.runeconomy.dto.result.ResultCode;
import com.gyee.runeconomy.model.auto.ProEconPowerFittingAnalySis;
import com.gyee.runeconomy.model.vo.NewDataFittingVo;
import com.gyee.runeconomy.service.auto.impl.NewDataFittingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/new/power/fitting")
public class NewDataFittingController {



    @Autowired
    private NewDataFittingService newDataFittingService;

    /**
     * 功率曲线拟合
     * @param
     * @return
     */
    @GetMapping("/data")
    public JSONObject dataFitting(@RequestParam(value = "station",  required = false) String station,
                                  @RequestParam(value = "wtIds",  required = false) String wtIds,
                                  @RequestParam(value = "st",  required = false) Long st,
                                  @RequestParam(value = "et",  required = false) Long et,
                                  @RequestParam(value = "interval",  required = false) Integer interval,
                                  @RequestParam(value = "isbw",  required = false) Boolean isbw,
                                  @RequestParam(value = "isfbw",  required = false) Boolean isfbw,
                                  @RequestParam(value = "isfhl",  required = false) Boolean isfhl,
                                  @RequestParam(value = "istj",  required = false) Boolean istj,
                                  @RequestParam(value = "isglpc",  required = false) Boolean isglpc,
                                  @RequestParam(value = "maxp",  required = false) double maxp,
                                  @RequestParam(value = "maxs",  required = false) double maxs,
                                  @RequestParam(value = "mins",  required = false) double mins,
                                  @RequestParam(value = "minp",  required = false) double minp,
                                  @RequestParam(value = "mode",  required = false) Integer mode,
                                  @RequestParam(value = "dimension",  required = false) Integer dimension
    ) {

        ProEconPowerFittingAnalySis obj = newDataFittingService.newDataFitting(station,wtIds,st,et,interval,isbw,isfbw,isfhl,istj,isglpc,maxp,maxs,mins,minp,mode,dimension);
        return JsonResult.successData(ResultCode.SUCCESS, obj);

    }

    /**
     * 读取曲线，散点等数据
     * @param id  拟合好的数据ID
     * @return
     */
    @GetMapping("curve")
    public JSONObject dataFittingCurve(String id){
        Map<String, Object> result = newDataFittingService.dataFittingCurve(id);
        return JsonResult.successData(ResultCode.SUCCESS, result);
    }



    /**
     * 通过key获取原始数据
     * 对应前端的圈选功能
     * @param yk  有用点的key
     * @param wk  无用点的key
     * @return
     */
    @GetMapping("filter")
    public JSONObject dataFittingFilter(String yk, String wk){
        List<PowerPointData> list = newDataFittingService.dataOrigin(yk, wk);
        return JsonResult.successData(ResultCode.SUCCESS, list);
    }


    /**
     * file 文件数据展示
     * @param id
     * @return
     */
    @GetMapping("/show")
    public JSONObject dataFittingShow(String id){
        Map<String, Object> result = newDataFittingService.dataFittingShow(id);
        return JsonResult.successData(ResultCode.SUCCESS, result);
    }
    /**
     * 获取故障或预警数据
     //     * @param table
     //     * @param only
     * @return
     */
    @PostMapping("alarms")
    public JSONObject getDataAlarms(@RequestBody AlarmRequest request) {
        String table = request.getTable();
        List<Alarm> alarmList = request.getAlarmList();
        List<AlarmDataVo> list = newDataFittingService.getDataAlarms(table, alarmList);
        return JsonResult.successData(ResultCode.SUCCESS, list);
    }
}
