package service import ( "github.com/go-xweb/xweb" "go.mongodb.org/mongo-driver/bson" qu "qfw/util" "strings" "time" "util" ) type App struct { *xweb.Action appList xweb.Mapper `xweb:"/service/app/monitor/list"` appCreate xweb.Mapper `xweb:"/service/app/monitor/create"` appEdit xweb.Mapper `xweb:"/service/app/monitor/edit"` appDel xweb.Mapper `xweb:"/service/app/monitor/del"` } func (app *App) AppList() { if app.Method() == "POST" { identity := app.GetString("identity") start, _ := app.GetInteger("start") limit, _ := app.GetInteger("length") draw, _ := app.GetInteger("draw") q := bson.M{"name": bson.M{"$regex": identity}} q["del"] = false count := util.Mgo.Count("app_list", q) info, _ := util.Mgo.Find("app_list", q, nil, nil, false, start, limit) if len(*info) > 0 { app.ServeJson(map[string]interface{}{ "draw": draw, "rep": true, "data": *info, "recordsFiltered": count, "recordsTotal": count, }) } else { app.ServeJson(map[string]interface{}{ "rep": false, "msg": "未查询到数据", }) } } else { _ = app.Render("app/app_list.html") } } func (app *App) AppCreate() { if app.Method() == "POST" { data := util.GetPostForm(app.Request) pg := *qu.ObjToMap(data["data"]) if name := qu.ObjToString(pg["name"]); name != "" { now := time.Now().Unix() ip_port := strings.Split(qu.ObjToString(pg["ip_port"]), ":") leader := qu.ObjToString(pg["leader"]) mail := qu.ObjToString(pg["mail"]) timing := qu.ObjToString(pg["timing"]) save := bson.M{"name": name, "ip": ip_port[0], "port": qu.IntAll(ip_port[1]), "leader": leader, "mail": mail, "timing": timing} save["del"] = false save["updatetime"] = now save["status"] = 1 util.Mgo.Save("app_list", save) app.ServeJson(map[string]interface{}{ "rep": true, }) } else { app.ServeJson(map[string]interface{}{ "rep": false, }) } } } func (app *App) AppEdit() { if app.Method() == "POST" { data := util.GetPostForm(app.Request) pg := *qu.ObjToMap(data["data"]) id := qu.ObjToString(data["id"]) if name := qu.ObjToString(pg["name"]); name != "" { now := time.Now().Unix() ip_port := strings.Split(qu.ObjToString(pg["ip_port"]), ":") leader := qu.ObjToString(pg["leader"]) mail := qu.ObjToString(pg["mail"]) timing := qu.ObjToString(pg["timing"]) status := qu.IntAll(pg["status"]) save := bson.M{"name": name, "ip": ip_port[0], "port": qu.IntAll(ip_port[1]), "leader": leader, "mail": mail, "timing": timing} save["updatetime"] = now save["status"] = status util.Mgo.UpdateById("app_list", id, bson.M{"$set": save}) app.ServeJson(map[string]interface{}{ "rep": true, }) } else { app.ServeJson(map[string]interface{}{ "rep": false, }) } } } func (app *App) AppDel() { if app.Method() == "POST" { id := app.GetString("id") b := util.Mgo.UpdateById("app_list", id, bson.M{"$set": bson.M{"del": true}}) app.ServeJson(map[string]interface{}{ "rep": b, }) } }