Commit f56bf95d91fed049054806f9c24df85d3e83884e

Authored by aarongao
1 parent 58ec1105
Exists in v1.2 and in 1 other branch v1.1

..

API/Item.go
... ... @@ -142,7 +142,7 @@ func UpdateItem(c *gin.Context) {
142 142 )
143 143  
144 144 // 更新等待时间
145   - allteim := DB.Redis.Get("AllItemTime")
  145 + allteim := DB.Redis.Get("AllItemTime_" + c.PostForm("ScenicId"))
146 146 jsond, _ := json.Marshal(allteim)
147 147  
148 148 var ItemTime map[string]string
... ... @@ -151,10 +151,11 @@ func UpdateItem(c *gin.Context) {
151 151 if poststate == 1 {
152 152 ItemTime[c.PostForm("id")] = "--"
153 153 }
154   - if poststate == 0 {
155   - ItemTime[c.PostForm("id")] = "0"
156   - }
157   - DB.Redis.Set("AllItemTime", ItemTime, time.Second*60*60*24*30)
  154 + //if poststate == 0 {
  155 + // ItemTime[c.PostForm("id")] = "0"
  156 + //}
  157 +
  158 + DB.Redis.Set("AllItemTime_" + c.PostForm("ScenicId"), ItemTime, time.Second*60*60*24*30)
158 159  
159 160 c.JSON(200, tools.ResponseSeccess{
160 161 0,
... ...
API/Operator.go
... ... @@ -85,6 +85,13 @@ func UpdateOperator(c *gin.Context) {
85 85 })
86 86 return
87 87 }
  88 + if c.PostForm("Username") == "" || c.PostForm("Password") == "" {
  89 + c.JSON(200, tools.ResponseError{
  90 + 1,
  91 + "用户名密码不能为空",
  92 + })
  93 + return
  94 + }
88 95  
89 96 var _auth []string
90 97 json.Unmarshal([]byte(c.PostForm("Auth")), &_auth)
... ...
API/OperatorLog.go 0 → 100644
... ... @@ -0,0 +1,58 @@
  1 +package Api
  2 +
  3 +import (
  4 + "github.com/aarongao/tools"
  5 + "github.com/gin-gonic/gin"
  6 + "go.mongodb.org/mongo-driver/bson"
  7 + "go.mongodb.org/mongo-driver/mongo/options"
  8 + "letu/DB"
  9 + "math"
  10 + "strconv"
  11 +)
  12 +
  13 +// @Title 查询所有管理员日志
  14 +// @Description 查询所有用户行为
  15 +// @Accept json
  16 +// @Produce json
  17 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
  18 +// @Param Page 1 int true "当前第几页"
  19 +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}"
  20 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  21 +// @Router /AllOperatorLog? [get]
  22 +func AllOperatorLog(c *gin.Context) {
  23 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  24 + c.Header("Access-Control-Allow-Credentials", "true")
  25 +
  26 + total, _ := DB.COperatorLog.CountDocuments(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")})
  27 + limit, _ := strconv.ParseInt(c.Query("Limit"), 10, 64)
  28 + if limit == 0 {
  29 + limit = 50
  30 + }
  31 + currPage, _ := strconv.ParseInt(c.Query("Page"), 10, 64)
  32 + if currPage == 0 {
  33 + currPage = 1
  34 + }
  35 +
  36 + skip := (currPage - 1) * limit
  37 +
  38 + var aOperatorLog []DB.SOperatorLog
  39 + cur, err := DB.COperatorLog.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}})
  40 + defer cur.Close(tools.GetContext())
  41 + if err == nil {
  42 + for cur.Next(tools.GetContext()) {
  43 + var e DB.SOperatorLog
  44 + cur.Decode(&e)
  45 + aOperatorLog = append(aOperatorLog, e)
  46 + }
  47 + }
  48 +
  49 + c.JSON(200, tools.Page{
  50 + 0,
  51 + total,
  52 + currPage,
  53 + int64(math.Ceil(float64(total) / float64(limit))),
  54 + limit,
  55 + aOperatorLog,
  56 + })
  57 +
  58 +}
... ...
API/UserLog.go
... ... @@ -100,6 +100,7 @@ func UserLog(c *gin.Context) {
100 100 // @Description 查询所有用户行为
101 101 // @Accept json
102 102 // @Produce json
  103 +// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
103 104 // @Param Page 1 int true "当前第几页"
104 105 // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}"
105 106 // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
... ... @@ -109,7 +110,7 @@ func AllUserLog(c *gin.Context) {
109 110 c.Header("Access-Control-Allow-Credentials", "true")
110 111  
111 112  
112   - total,_ := DB.CUserLog.CountDocuments(tools.GetContext(), bson.M{})
  113 + total,_ := DB.CUserLog.CountDocuments(tools.GetContext(), bson.M{"ScenicId":c.Query("ScenicId")})
113 114 limit, _ := strconv.ParseInt(c.Query("Limit"),10,64)
114 115 if limit == 0 {
115 116 limit = 50
... ... @@ -121,7 +122,7 @@ func AllUserLog(c *gin.Context) {
121 122 skip := (currPage - 1) * limit
122 123  
123 124 var aUserLog []DB.SUserLog
124   - cur, err := DB.CUserLog.Find(tools.GetContext(), bson.M{}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}})
  125 + cur, err := DB.CUserLog.Find(tools.GetContext(), bson.M{"ScenicId":c.Query("ScenicId")}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}})
125 126 defer cur.Close(tools.GetContext())
126 127 if err == nil {
127 128 for cur.Next(tools.GetContext()) {
... ...
DB/db.go
... ... @@ -17,6 +17,7 @@ var CTags *mongo.Collection //标签
17 17 var CScenic *mongo.Collection //景区
18 18 var CLine *mongo.Collection //推荐线路
19 19 var CUserLog *mongo.Collection //用户行为记录
  20 +var COperatorLog *mongo.Collection //操作员log
20 21 var CSystemLog *mongo.Collection //操作记录
21 22 var CTrajectory *mongo.Collection //移动轨迹
22 23 var CIcons *mongo.Collection //图标信息
... ... @@ -109,6 +110,17 @@ type SUserLog struct {
109 110 Source string `bson:"Source" json:"Source"` //来源
110 111 Device SDevice `bson:"Device" json:"Device"` //设备信息
111 112 }
  113 +
  114 +type SOperatorLog struct {
  115 + ScenicId string `bson:"ScenicId" json:"ScenicId"`
  116 + UserId string `bson:"UserId" json:"UserId"` // 用户ID
  117 + UserName string `bson:"UserName" json:"UserName"` //用户名称
  118 + DateTime int64 `bson:"DateTime" json:"DateTime"` //时间戳
  119 + Remarks string `bson:"Remarks" json:"Remarks"` //备注
  120 + Model SModel `bson:"Model" json:"Model"`
  121 + Api string `bson:"Api" json:"Api"`
  122 + Parames interface{} `bson:"Parames" json:"Parames"`
  123 +}
112 124 type SSystemLog struct {
113 125 UserId string `bson:"UserId" json:"UserId"` // 用户ID
114 126 UserName string `bson:"UserName" json:"UserName"` //用户名称
... ...
Lib/Auth/Auth.go
... ... @@ -7,6 +7,8 @@ import (
7 7 "go.mongodb.org/mongo-driver/bson/primitive"
8 8 "letu/DB"
9 9 "letu/Lib/JWT"
  10 + "letu/Lib/LeYouTu"
  11 + "letu/Lib/OperatorLog"
10 12 )
11 13  
12 14 // 系统中所有模块
... ... @@ -85,7 +87,15 @@ func CheckAuthFunc(handFunc func(c *gin.Context), auth *DB.SModel) func(c *gin.C
85 87 })
86 88 } else {
87 89 c.Set("UserInfo", user)
  90 +
88 91 handFunc(c)
  92 +
  93 + if auth.Model != "操作员日志"{
  94 + go func() {
  95 + ScenicId, _ := LeYouTu.GetScenicId(c)
  96 + OperatorLog.CreateOperatorLog(ScenicId, user, auth, c.Request.RequestURI, c.Request.Form)
  97 + }()
  98 + }
89 99 }
90 100 }
91 101 }
... ...
Lib/JWT/jwt.go
... ... @@ -13,11 +13,10 @@ import (
13 13 func CreateToken(user *DB.SMember, exp int64) (tokenss string, err error) {
14 14 //自定义claim
15 15  
16   -
17 16 auth, _ := json.Marshal(user.Auth)
18 17 claim := jwt.MapClaims{
19 18 "id": user.Id,
20   - //"mobile": user.Mobile,
  19 + "username": user.Username,
21 20 "userType": user.UserType,
22 21 "scenicId": user.ScenicId,
23 22 "auth": string(auth),
... ... @@ -61,12 +60,12 @@ func ParseToken(tokenss string) (user *DB.SMember, err error) {
61 60  
62 61 id, _ := primitive.ObjectIDFromHex(claim["id"].(string))
63 62 user.Id = &id
64   - //user.Mobile = claim["mobile"].(string)
  63 + user.Username = claim["username"].(string)
65 64 user.UserType = claim["userType"].(string)
66 65 user.ScenicId = claim["scenicId"].(string)
67 66  
68 67 var jsons []string
69   - json.Unmarshal([]byte(claim["auth"].(string)),&jsons)
  68 + json.Unmarshal([]byte(claim["auth"].(string)), &jsons)
70 69 user.Auth = jsons
71 70 return
72 71 }
... ...
Lib/OperatorLog/operatorLog.go 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +package OperatorLog
  2 +
  3 +import (
  4 + "github.com/aarongao/tools"
  5 + "letu/DB"
  6 + "time"
  7 +)
  8 +
  9 +func CreateOperatorLog(ScenicId string, user *DB.SMember, model *DB.SModel, api string, parames interface{}) {
  10 +
  11 + DB.COperatorLog.InsertOne(tools.GetContext(), DB.SOperatorLog{
  12 + ScenicId,
  13 + user.Id.Hex(),
  14 + user.Username,
  15 + time.Now().Unix(),
  16 + "",
  17 + *model,
  18 + api,
  19 + parames,
  20 + })
  21 +}
... ...
Lib/Token/token.go
... ... @@ -1,18 +0,0 @@
1   -package Token
2   -
3   -import (
4   - "letu/DB"
5   - "time"
6   -)
7   -
8   -func GetToken(mobile string) string {
9   - token := DB.Redis.Get("token_" + mobile)
10   - if token == nil {
11   - return ""
12   - }
13   - return token.(string)
14   -}
15   -
16   -func SaveToken(mobile, token string) {
17   - DB.Redis.Set("token_"+mobile, token, time.Second*3600*24*365)
18   -}
README.md
... ... @@ -14,6 +14,7 @@
14 14 1. [设备管理 - 查询所有游玩项目](#allitems-get)
15 15 1. [查询所有线路](#allline-get)
16 16 1. [操作员管理 - 所有操作员](#alloperator-get)
  17 +1. [查询所有用户行为](#alloperatorlog-get)
17 18 1. [所有景区基础信息](#allscenic-get)
18 19 1. [标签 - 所有标签](#alltag-get)
19 20 1. [标签 - 按照标签分组查看所有标签](#alltaggroup-get)
... ... @@ -173,6 +174,26 @@
173 174  
174 175  
175 176  
  177 +<a name="alloperatorlog-get"></a>
  178 +
  179 +#### /AllOperatorLog (GET)
  180 +
  181 +
  182 +查询所有用户行为
  183 +
  184 +| Param Name | Example | Data Type | Description | Required? |
  185 +|-----|-----|-----|-----|-----|
  186 +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes |
  187 +| Page | 1 | int | 当前第几页 | Yes |
  188 +
  189 +
  190 +| Code | Type | Model | Message |
  191 +|-----|-----|-----|-----|
  192 +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":} |
  193 +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
  194 +
  195 +
  196 +
176 197 <a name="allscenic-get"></a>
177 198  
178 199 #### /AllScenic (GET)
... ... @@ -234,6 +255,7 @@
234 255  
235 256 | Param Name | Example | Data Type | Description | Required? |
236 257 |-----|-----|-----|-----|-----|
  258 +| ScenicId | 5dfb03070a9ac17ac7a82054 | string | 景区id | Yes |
237 259 | Page | 1 | int | 当前第几页 | Yes |
238 260  
239 261  
... ...
Version.md
... ... @@ -41,13 +41,21 @@
41 41 /TopMenus/Remove(需要携带Token)
42 42 ```
43 43  
44   -
45   -
46 44 6. 删除【游玩项目】标签。增加【游乐设施】【演出】【餐饮】【购物】【普通】
47 45  
48 46 7. 删除【location】标签组
49 47  
50   -8.
  48 +8. 修改地图切片url地址,及切片上传方式
  49 +
  50 + /tiles2/**<u>5e0d504e24e03431008b4567</u>**/18/218274/99286.jpg
  51 +
  52 + 其中5e0d504e24e03431008b4567(景区id)为新加目录
  53 +
  54 + 通过FTP方式上传到/root/leyoutu/tiles2/(景区id)/目录下
  55 +
  56 +9. 后台增加管理员日志功能
  57 +
  58 +
51 59  
52 60 ##### 发布流程:
53 61  
... ...
main.go
... ... @@ -95,6 +95,7 @@ func main() {
95 95 DB.CDevice = DB.DB.Collection("Device")
96 96 DB.CNotice = DB.DB.Collection("Notice")
97 97 DB.CTopMenus = DB.DB.Collection("TopMenu")
  98 + DB.COperatorLog = DB.DB.Collection("OperatorLog")
98 99 DelayMessage.CDelayMessage = DB.DB.Collection("DelayMessage")
99 100 DelayMessage.CDelayErrorLog = DB.DB.Collection("DelayErrorLog")
100 101  
... ... @@ -164,6 +165,10 @@ func main() {
164 165  
165 166 InitController("POST", "/LoginOperator", Api.LoginOperator, &DB.SModel{})
166 167 InitController("POST", "/UpdateOperator", Api.UpdateOperator, &DB.SModel{"操作员管理", "增加和修改"})
  168 +
  169 + InitController("GET", "/AllOperatorLog", Api.AllOperatorLog, &DB.SModel{"操作员日志", "查看所有"})
  170 +
  171 +
167 172 InitController("GET", "/AllOperator", Api.AllOperator, &DB.SModel{"操作员管理", "查看所有"})
168 173 InitController("GET", "/SystemInfo", Api.SystemInfo, &DB.SModel{})
169 174  
... ...