OperatorLog.go
1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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,
})
}