package service

import (
	"fmt"
	"nms_nbi/src/framework/constants/uploadsubpath"
	"nms_nbi/src/framework/utils/file"
	"nms_nbi/src/modules/api_rest_cxy/utils/common"
	neDataModel "nms_nbi/src/modules/network_data/model"
	neDataService "nms_nbi/src/modules/network_data/service"
)

// 实例化数据层 PerformanceImpl 结构体
var NewPerformanceImpl = &PerformanceImpl{
	perfKPIService: neDataService.NewPerfKPIImpl,
}

// 性能数据处理服务 服务层处理
type PerformanceImpl struct {
	// 统计信息服务
	perfKPIService neDataService.IPerfKPI
}

// PerformanceUploadOSS 性能数据上报
func (s *PerformanceImpl) PerformanceUploadOSS(neType string) error {
	query := neDataModel.GoldKPIQuery{
		NeType:    neType,
		StartTime: "2024-02-15 10:16:30",
		EndTime:   "2024-03-07 10:20:08",
		Interval:  900,
	}

	data := s.perfKPIService.SelectGoldKPI(query)
	dataArr := [][]string{}
	for i, v := range data {
		if i == 0 {
			dataItem := []string{}
			dataItem[0] = fmt.Sprint(v["AMF.25"])
			dataArr = append(dataArr, dataItem)
		}
		dataItem := []string{}
		dataItem[0] = fmt.Sprint(v["AMF.25"])
		dataArr = append(dataArr, dataItem)
	}

	// 文件名
	dataSaveFileName := common.DataSaveFileName{}
	fileName := dataSaveFileName.CSV()
	filePath := fmt.Sprintf("%s/%s", file.ParseUploadFileDir(uploadsubpath.EXPORT), fileName)
	err := file.WriterFileCSV(dataArr, filePath)
	if err != nil {
		return err
	}

	return common.UploadOSSByZip(filePath, neType, "PM")
}
