wangbin 4 days ago
parent bd85502368
commit d15a4b40c5

@ -1029,20 +1029,20 @@ func GetAvailableEndpoint() string {
primaryIP := LoadConfig().SeverData.ServerIP primaryIP := LoadConfig().SeverData.ServerIP
backupIP := LoadConfig().SeverData.BackUpServerIP // 替换为实际备选IP backupIP := LoadConfig().SeverData.BackUpServerIP // 替换为实际备选IP
if IsIPReachable(primaryIP) { if IsIPReachable(primaryIP, "9800") {
return primaryIP return primaryIP
} }
if IsIPReachable(backupIP) { if IsIPReachable(backupIP, "9800") {
return backupIP return backupIP
} }
return "" return ""
} }
func IsIPReachable(ip string) bool { func IsIPReachable(ip string, port string) bool {
conn, err := net.DialTimeout("ip4:icmp", ip, 10*time.Millisecond) conn, err := net.DialTimeout("tcp", ip+":"+port, 10*time.Millisecond)
if err != nil { if err != nil {
return false return false
} }
conn.Close() defer conn.Close()
return true return true
} }

@ -104,8 +104,15 @@ func GetAllStaffInfoAllCPCS() []Model.T_Staff {
} }
}() }()
targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return nil
}
// 示例:发送 JSON 数据 // 示例:发送 JSON 数据
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/tstaffinfo/getStaffViewNoPage" url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/tstaffinfo/getStaffViewNoPage"
jsonData := `{}` jsonData := `{}`
body, statusCode, err := Common.SendPostRequest(url, jsonData, "application/json") body, statusCode, err := Common.SendPostRequest(url, jsonData, "application/json")
if err != nil { if err != nil {
@ -208,7 +215,14 @@ func UpdateStaffInfo(para *Model.T_Staff) bool {
} }
}() }()
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/tstaffinfo/clearCardNum" targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return false
}
url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/tstaffinfo/clearCardNum"
data := map[string]interface{}{ data := map[string]interface{}{
"id": para.ID, "id": para.ID,
"st_vicecardnum": para.St_ViceCardNum, "st_vicecardnum": para.St_ViceCardNum,

@ -85,7 +85,15 @@ func APDefaultLayout() fyne.CanvasObject {
dialog.ShowError(errors.New("已经报到"), CardWindow) dialog.ShowError(errors.New("已经报到"), CardWindow)
return return
} }
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/checkinBatch"
targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return
}
url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/checkinBatch"
data := map[string]interface{}{ data := map[string]interface{}{
"updatebatchobj": []map[string]interface{}{ "updatebatchobj": []map[string]interface{}{
{"perid": &(localcache.AllPerson[CurrentAPID.Row].AP_ID)}, {"perid": &(localcache.AllPerson[CurrentAPID.Row].AP_ID)},
@ -125,7 +133,15 @@ func APDefaultLayout() fyne.CanvasObject {
dialog.ShowError(errors.New("已经销报"), CardWindow) dialog.ShowError(errors.New("已经销报"), CardWindow)
return return
} }
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/checkoutBatch"
targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return
}
url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/checkoutBatch"
data := map[string]interface{}{ data := map[string]interface{}{
"updatebatchobj": []map[string]interface{}{ "updatebatchobj": []map[string]interface{}{
{"perid": &(localcache.AllPerson[CurrentAPID.Row].AP_ID)}, {"perid": &(localcache.AllPerson[CurrentAPID.Row].AP_ID)},

@ -4677,8 +4677,15 @@ func GetNowTimeCPCS() time.Time {
} }
}() }()
targetIP := Common.GetAvailableEndpoint()
if targetIP == "" {
log.Error("所有IP均不可达")
log.Println("所有IP均不可达")
return time.Time{}
}
// 示例:发送 JSON 数据 // 示例:发送 JSON 数据
url := "http://" + Common.LoadConfig().SeverData.ServerIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/getnowtime" url := "http://" + targetIP + ":9800/vhwcapi/v1/web/api/service/congresscontrol/getnowtime"
jsonData := `{}` jsonData := `{}`
body, statusCode, err := Common.SendPostRequest(url, jsonData, "application/json") body, statusCode, err := Common.SendPostRequest(url, jsonData, "application/json")
if err != nil { if err != nil {

Loading…
Cancel
Save