You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package crontask
import (
"autogo/cli"
"autogo/dbsql"
"autogo/models"
"fmt"
)
func CheckIOSDevices() {
m := cli.GetIOSDevices()
db, err := dbsql.GetConn(dbsql.DSN)
if err != nil {
fmt.Println("[Crontab] 数据库连接失败")
return
}
defer dbsql.Close(db)
var list []models.Device
db.Model(models.Device{}).Where("platform = ? AND is_del = 0", "ios").Find(&list)
for _, v := range list {
if vv, ok := m[v.Udid]; ok {
// 数据表中的设备sib有获取到
if vv.Status != "online" && v.Status != vv.Status {
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", vv.Status)
fmt.Println("[Crontab]", v.Udid, "连接状态异常:", v.Status)
} else if v.Status == "offline" && vv.Status == "online" {
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", "online")
fmt.Println("[Crontab]", v.Udid, "已连接")
}
switch v.Status {
case "online":
// 保持亮屏
// monkey.KeepiOSDevice(v.Udid)
}
} else {
// 数据表中的设备sib没有获取到
if v.Status == "online" || v.Status == "busy" {
db.Model(models.Device{}).Where("udid = ?", v.Udid).Update("status", "offline")
fmt.Println("[Crontab]", v.Udid, "已离线")
}
}
}
}