123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- 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,
- })
- }
- }
|