diff --git a/API/Item.go b/API/Item.go index a2da5fa..1088eec 100644 --- a/API/Item.go +++ b/API/Item.go @@ -142,7 +142,7 @@ func UpdateItem(c *gin.Context) { ) // 更新等待时间 - allteim := DB.Redis.Get("AllItemTime") + allteim := DB.Redis.Get("AllItemTime_" + c.PostForm("ScenicId")) jsond, _ := json.Marshal(allteim) var ItemTime map[string]string @@ -151,10 +151,11 @@ func UpdateItem(c *gin.Context) { if poststate == 1 { ItemTime[c.PostForm("id")] = "--" } - if poststate == 0 { - ItemTime[c.PostForm("id")] = "0" - } - DB.Redis.Set("AllItemTime", ItemTime, time.Second*60*60*24*30) + //if poststate == 0 { + // ItemTime[c.PostForm("id")] = "0" + //} + + DB.Redis.Set("AllItemTime_" + c.PostForm("ScenicId"), ItemTime, time.Second*60*60*24*30) c.JSON(200, tools.ResponseSeccess{ 0, diff --git a/API/Operator.go b/API/Operator.go index 5ec3b24..9bd7877 100644 --- a/API/Operator.go +++ b/API/Operator.go @@ -85,6 +85,13 @@ func UpdateOperator(c *gin.Context) { }) return } + if c.PostForm("Username") == "" || c.PostForm("Password") == "" { + c.JSON(200, tools.ResponseError{ + 1, + "用户名密码不能为空", + }) + return + } var _auth []string json.Unmarshal([]byte(c.PostForm("Auth")), &_auth) diff --git a/API/OperatorLog.go b/API/OperatorLog.go new file mode 100644 index 0000000..fadb9f0 --- /dev/null +++ b/API/OperatorLog.go @@ -0,0 +1,58 @@ +package Api + +import ( + "github.com/aarongao/tools" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo/options" + "letu/DB" + "math" + "strconv" +) + +// @Title 查询所有管理员日志 +// @Description 查询所有用户行为 +// @Accept json +// @Produce json +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id" +// @Param Page 1 int true "当前第几页" +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /AllOperatorLog? [get] +func AllOperatorLog(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + total, _ := DB.COperatorLog.CountDocuments(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")}) + limit, _ := strconv.ParseInt(c.Query("Limit"), 10, 64) + if limit == 0 { + limit = 50 + } + currPage, _ := strconv.ParseInt(c.Query("Page"), 10, 64) + if currPage == 0 { + currPage = 1 + } + + skip := (currPage - 1) * limit + + var aOperatorLog []DB.SOperatorLog + cur, err := DB.COperatorLog.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}}) + defer cur.Close(tools.GetContext()) + if err == nil { + for cur.Next(tools.GetContext()) { + var e DB.SOperatorLog + cur.Decode(&e) + aOperatorLog = append(aOperatorLog, e) + } + } + + c.JSON(200, tools.Page{ + 0, + total, + currPage, + int64(math.Ceil(float64(total) / float64(limit))), + limit, + aOperatorLog, + }) + +} diff --git a/API/UserLog.go b/API/UserLog.go index 5b1d525..304d102 100644 --- a/API/UserLog.go +++ b/API/UserLog.go @@ -100,6 +100,7 @@ func UserLog(c *gin.Context) { // @Description 查询所有用户行为 // @Accept json // @Produce json +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id" // @Param Page 1 int true "当前第几页" // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" @@ -109,7 +110,7 @@ func AllUserLog(c *gin.Context) { c.Header("Access-Control-Allow-Credentials", "true") - total,_ := DB.CUserLog.CountDocuments(tools.GetContext(), bson.M{}) + total,_ := DB.CUserLog.CountDocuments(tools.GetContext(), bson.M{"ScenicId":c.Query("ScenicId")}) limit, _ := strconv.ParseInt(c.Query("Limit"),10,64) if limit == 0 { limit = 50 @@ -121,7 +122,7 @@ func AllUserLog(c *gin.Context) { skip := (currPage - 1) * limit var aUserLog []DB.SUserLog - cur, err := DB.CUserLog.Find(tools.GetContext(), bson.M{}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}}) + cur, err := DB.CUserLog.Find(tools.GetContext(), bson.M{"ScenicId":c.Query("ScenicId")}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}}) defer cur.Close(tools.GetContext()) if err == nil { for cur.Next(tools.GetContext()) { diff --git a/DB/db.go b/DB/db.go index 1669971..52cac7c 100644 --- a/DB/db.go +++ b/DB/db.go @@ -17,6 +17,7 @@ var CTags *mongo.Collection //标签 var CScenic *mongo.Collection //景区 var CLine *mongo.Collection //推荐线路 var CUserLog *mongo.Collection //用户行为记录 +var COperatorLog *mongo.Collection //操作员log var CSystemLog *mongo.Collection //操作记录 var CTrajectory *mongo.Collection //移动轨迹 var CIcons *mongo.Collection //图标信息 @@ -109,6 +110,17 @@ type SUserLog struct { Source string `bson:"Source" json:"Source"` //来源 Device SDevice `bson:"Device" json:"Device"` //设备信息 } + +type SOperatorLog struct { + ScenicId string `bson:"ScenicId" json:"ScenicId"` + UserId string `bson:"UserId" json:"UserId"` // 用户ID + UserName string `bson:"UserName" json:"UserName"` //用户名称 + DateTime int64 `bson:"DateTime" json:"DateTime"` //时间戳 + Remarks string `bson:"Remarks" json:"Remarks"` //备注 + Model SModel `bson:"Model" json:"Model"` + Api string `bson:"Api" json:"Api"` + Parames interface{} `bson:"Parames" json:"Parames"` +} type SSystemLog struct { UserId string `bson:"UserId" json:"UserId"` // 用户ID UserName string `bson:"UserName" json:"UserName"` //用户名称 diff --git a/Lib/Auth/Auth.go b/Lib/Auth/Auth.go index 32c116d..d8d2996 100644 --- a/Lib/Auth/Auth.go +++ b/Lib/Auth/Auth.go @@ -7,6 +7,8 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" "letu/DB" "letu/Lib/JWT" + "letu/Lib/LeYouTu" + "letu/Lib/OperatorLog" ) // 系统中所有模块 @@ -85,7 +87,15 @@ func CheckAuthFunc(handFunc func(c *gin.Context), auth *DB.SModel) func(c *gin.C }) } else { c.Set("UserInfo", user) + handFunc(c) + + if auth.Model != "操作员日志"{ + go func() { + ScenicId, _ := LeYouTu.GetScenicId(c) + OperatorLog.CreateOperatorLog(ScenicId, user, auth, c.Request.RequestURI, c.Request.Form) + }() + } } } } diff --git a/Lib/JWT/jwt.go b/Lib/JWT/jwt.go index 2ad3993..a1ef34c 100644 --- a/Lib/JWT/jwt.go +++ b/Lib/JWT/jwt.go @@ -13,11 +13,10 @@ import ( func CreateToken(user *DB.SMember, exp int64) (tokenss string, err error) { //自定义claim - auth, _ := json.Marshal(user.Auth) claim := jwt.MapClaims{ "id": user.Id, - //"mobile": user.Mobile, + "username": user.Username, "userType": user.UserType, "scenicId": user.ScenicId, "auth": string(auth), @@ -61,12 +60,12 @@ func ParseToken(tokenss string) (user *DB.SMember, err error) { id, _ := primitive.ObjectIDFromHex(claim["id"].(string)) user.Id = &id - //user.Mobile = claim["mobile"].(string) + user.Username = claim["username"].(string) user.UserType = claim["userType"].(string) user.ScenicId = claim["scenicId"].(string) var jsons []string - json.Unmarshal([]byte(claim["auth"].(string)),&jsons) + json.Unmarshal([]byte(claim["auth"].(string)), &jsons) user.Auth = jsons return } diff --git a/Lib/OperatorLog/operatorLog.go b/Lib/OperatorLog/operatorLog.go new file mode 100644 index 0000000..859c9f6 --- /dev/null +++ b/Lib/OperatorLog/operatorLog.go @@ -0,0 +1,21 @@ +package OperatorLog + +import ( + "github.com/aarongao/tools" + "letu/DB" + "time" +) + +func CreateOperatorLog(ScenicId string, user *DB.SMember, model *DB.SModel, api string, parames interface{}) { + + DB.COperatorLog.InsertOne(tools.GetContext(), DB.SOperatorLog{ + ScenicId, + user.Id.Hex(), + user.Username, + time.Now().Unix(), + "", + *model, + api, + parames, + }) +} diff --git a/Lib/Token/token.go b/Lib/Token/token.go deleted file mode 100644 index 7215e1a..0000000 --- a/Lib/Token/token.go +++ /dev/null @@ -1,18 +0,0 @@ -package Token - -import ( - "letu/DB" - "time" -) - -func GetToken(mobile string) string { - token := DB.Redis.Get("token_" + mobile) - if token == nil { - return "" - } - return token.(string) -} - -func SaveToken(mobile, token string) { - DB.Redis.Set("token_"+mobile, token, time.Second*3600*24*365) -} diff --git a/README.md b/README.md index e4060d1..2e64818 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ 1. [设备管理 - 查询所有游玩项目](#allitems-get) 1. [查询所有线路](#allline-get) 1. [操作员管理 - 所有操作员](#alloperator-get) +1. [查询所有用户行为](#alloperatorlog-get) 1. [所有景区基础信息](#allscenic-get) 1. [标签 - 所有标签](#alltag-get) 1. [标签 - 按照标签分组查看所有标签](#alltaggroup-get) @@ -173,6 +174,26 @@ + + +#### /AllOperatorLog (GET) + + +查询所有用户行为 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes | +| Page | 1 | int | 当前第几页 | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":} | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + #### /AllScenic (GET) @@ -234,6 +255,7 @@ | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes | | Page | 1 | int | 当前第几页 | Yes | diff --git a/Version.md b/Version.md index acc0586..b6f16e8 100644 --- a/Version.md +++ b/Version.md @@ -41,13 +41,21 @@ /TopMenus/Remove(需要携带Token) ``` - - 6. 删除【游玩项目】标签。增加【游乐设施】【演出】【餐饮】【购物】【普通】 7. 删除【location】标签组 -8. +8. 修改地图切片url地址,及切片上传方式 + + /tiles2/**5e0d504e24e03431008b4567**/18/218274/99286.jpg + + 其中5e0d504e24e03431008b4567(景区id)为新加目录 + + 通过FTP方式上传到/root/leyoutu/tiles2/(景区id)/目录下 + +9. 后台增加管理员日志功能 + + ##### 发布流程: diff --git a/main.go b/main.go index eaf2ed7..8d1aea0 100644 --- a/main.go +++ b/main.go @@ -95,6 +95,7 @@ func main() { DB.CDevice = DB.DB.Collection("Device") DB.CNotice = DB.DB.Collection("Notice") DB.CTopMenus = DB.DB.Collection("TopMenu") + DB.COperatorLog = DB.DB.Collection("OperatorLog") DelayMessage.CDelayMessage = DB.DB.Collection("DelayMessage") DelayMessage.CDelayErrorLog = DB.DB.Collection("DelayErrorLog") @@ -164,6 +165,10 @@ func main() { InitController("POST", "/LoginOperator", Api.LoginOperator, &DB.SModel{}) InitController("POST", "/UpdateOperator", Api.UpdateOperator, &DB.SModel{"操作员管理", "增加和修改"}) + + InitController("GET", "/AllOperatorLog", Api.AllOperatorLog, &DB.SModel{"操作员日志", "查看所有"}) + + InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"}) InitController("GET", "/SystemInfo", Api.SystemInfo, &DB.SModel{}) -- libgit2 0.21.0