package cn.wise.sc.energy.power.plant.business.controller;

import cn.wise.sc.energy.power.plant.business.bean.DataPower;
import cn.wise.sc.energy.power.plant.business.domain.TendencyQuery;
import cn.wise.sc.energy.power.plant.business.domain.vo.EntityVo;
import cn.wise.sc.energy.power.plant.business.service.ICharacterParamService;
import cn.wise.sc.energy.power.plant.common.core.bean.BaseResponse;
import com.spring4all.spring.boot.starter.hbase.api.HbaseTemplate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.constraints.NotEmpty;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description: 测点特征controller
 * @author: qh
 * @create: 2020-07-20 18:12
 **/
@CrossOrigin
@Validated
@RestController
@RequestMapping("characterParam/")
@Api(tags = "测点特征api")
public class CharacterParamController {

    final
    ICharacterParamService iCharacterParamService;
    final
    HbaseTemplate hbaseTemplate;

    public CharacterParamController(ICharacterParamService iCharacterParamService,
                                    HbaseTemplate hbaseTemplate) {
        this.iCharacterParamService = iCharacterParamService;
        this.hbaseTemplate = hbaseTemplate;
    }

    @ApiOperation(value = "获取机组所有特征值")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "unitNo",value = "机组编号",paramType = "query", dataType = "String")
    })
    @GetMapping("{unitNo}")
    public BaseResponse<List<EntityVo>> getUnitAllCharacterParams(
            @PathVariable("unitNo") @NotEmpty(message = "unitNo不能为空!") String unitNo) {
        return BaseResponse.okData(iCharacterParamService.getUnitAllCharacterParams(unitNo));
    }

    @ApiOperation(value = "获取3d组件特征")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "deviceId",value="设备编号",paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "fileName",value="部件名称",paramType = "query", dataType = "String"),
    })
    @GetMapping("/3d")
    public BaseResponse<Map<String, Map<String, HashMap<Long, Number>>>> get3DCharacter(String deviceId,
                                                                                        String fileName) {
        return iCharacterParamService.get3DCharacter(deviceId, fileName);
    }

    @ApiOperation(value = "获取趋势图")
    @PostMapping("/tendency")
    //todo 加kks
    public BaseResponse<DataPower> getTendency(@RequestBody TendencyQuery tendencyQuery) {
        return iCharacterParamService.getTendency(tendencyQuery.getKeys(),
                tendencyQuery.getTimeModelQuery(), tendencyQuery.getStatus());
    }

    @PostMapping("/oscillogram")
    public BaseResponse<Map<String, String>> oscillogram(@RequestBody List<String> kksCodes) throws IOException {

        return BaseResponse.okData(iCharacterParamService.getOscillogram(kksCodes));
    }

    @PostMapping("/upload")
    public BaseResponse<String> uploadFile(MultipartFile file) {
        return BaseResponse.okData(iCharacterParamService.getFrequencyByUpload(file));
    }

}
