package util

import (
	"fmt"
	"go.uber.org/zap"
	"log"
	"ydMonitoring/config"
)

func SendModel(phone string, msg []string, lenght int) error {
	ss := NewSMS(config.Config.GetString("submail.appid"), config.Config.GetString("submail.signature"))
	if lenght > 10 {
		sprintf := fmt.Sprintf("【数据预警提示】当前出现%d条异常数据，请及时处理！", lenght)
		res, err := ss.Send(phone, sprintf)
		if err != nil || res.Status != SUCCESS {
			log.Println("发送短信验证码出现异常", zap.Any("res", res), zap.Error(err))
			return err
		}
		log.Println("发送短信验证码成功", zap.Any("res", res))
	} else if lenght > 0 {
		content := fmt.Sprintf("【数据预警提示】以下数据出现异常\n：%s\n共有%d条异常数据", msg, lenght)
		res, err := ss.Send(phone, content)
		if err != nil || res.Status != SUCCESS {
			log.Println("发送短信验证码出现异常", zap.Any("res", res), zap.Error(err))
			return err
		}
		log.Println("发送短信验证码成功", zap.Any("res", res))
	}
	return nil
}
