Initial qiwei secondary development handoff
This commit is contained in:
83
helper/kingdee_monitor_http.go
Normal file
83
helper/kingdee_monitor_http.go
Normal file
@@ -0,0 +1,83 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func registerKingdeeMonitorRoutes(router *http.ServeMux) {
|
||||
router.HandleFunc("/api/kingdee/monitor/config", handleKingdeeMonitorConfig)
|
||||
router.HandleFunc("/api/kingdee/monitor/status", handleKingdeeMonitorStatus)
|
||||
router.HandleFunc("/api/kingdee/monitor/test-connection", handleKingdeeMonitorTestConnection)
|
||||
router.HandleFunc("/api/kingdee/monitor/run-once", handleKingdeeMonitorRunOnce)
|
||||
}
|
||||
|
||||
func handleKingdeeMonitorConfig(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
cfg, err := readKingdeeMonitorConfig()
|
||||
if err != nil {
|
||||
sendJSONResponse(w, http.StatusInternalServerError, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
sendJSONResponse(w, http.StatusOK, map[string]interface{}{"success": true, "message": "ok", "data": maskedKingdeeConfig(cfg)})
|
||||
case http.MethodPost:
|
||||
var cfg KingdeeMonitorConfig
|
||||
if err := json.NewDecoder(r.Body).Decode(&cfg); err != nil {
|
||||
sendJSONResponse(w, http.StatusBadRequest, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := saveKingdeeMonitorConfig(cfg); err != nil {
|
||||
sendJSONResponse(w, http.StatusInternalServerError, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
state, _ := readKingdeeMonitorState()
|
||||
sendJSONResponse(w, http.StatusOK, map[string]interface{}{"success": true, "message": "saved", "data": state})
|
||||
default:
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
}
|
||||
|
||||
func handleKingdeeMonitorStatus(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodGet {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
state, err := readKingdeeMonitorState()
|
||||
if err != nil {
|
||||
sendJSONResponse(w, http.StatusInternalServerError, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
state.Running = getKingdeeMonitor().IsRunning()
|
||||
sendJSONResponse(w, http.StatusOK, map[string]interface{}{"success": true, "message": "ok", "data": state})
|
||||
}
|
||||
|
||||
func handleKingdeeMonitorTestConnection(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
var cfg KingdeeMonitorConfig
|
||||
if err := json.NewDecoder(r.Body).Decode(&cfg); err != nil {
|
||||
sendJSONResponse(w, http.StatusBadRequest, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
if err := getKingdeeMonitor().TestConnection(cfg); err != nil {
|
||||
sendJSONResponse(w, http.StatusBadRequest, map[string]interface{}{"success": false, "message": err.Error()})
|
||||
return
|
||||
}
|
||||
sendJSONResponse(w, http.StatusOK, map[string]interface{}{"success": true, "message": "金蝶连接正常"})
|
||||
}
|
||||
|
||||
func handleKingdeeMonitorRunOnce(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
result, err := getKingdeeMonitor().RunOnce(true)
|
||||
if err != nil {
|
||||
sendJSONResponse(w, http.StatusBadRequest, map[string]interface{}{"success": false, "message": err.Error(), "data": result})
|
||||
return
|
||||
}
|
||||
sendJSONResponse(w, http.StatusOK, map[string]interface{}{"success": true, "message": result.Message, "data": result})
|
||||
}
|
||||
Reference in New Issue
Block a user