Commit d6a714e9b1f02854fbc75694b91453fc30067906
1 parent
e5fd5aea
Exists in
v1.2
and in
2 other branches
增加移动轨迹接口
Showing
5 changed files
with
68 additions
and
3 deletions
Show diff stats
API/Investigation.go
... | ... | @@ -17,7 +17,7 @@ import ( |
17 | 17 | // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" |
18 | 18 | // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" |
19 | 19 | // @Router /Investigation/Save? [post] |
20 | -func Save(c *gin.Context) { | |
20 | +func SaveInvestigation(c *gin.Context) { | |
21 | 21 | c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) |
22 | 22 | c.Header("Access-Control-Allow-Credentials", "true") |
23 | 23 | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +package Api | |
2 | + | |
3 | +import ( | |
4 | + "encoding/json" | |
5 | + "github.com/aarongao/tools" | |
6 | + "github.com/gin-gonic/gin" | |
7 | + "letu/DB" | |
8 | + "time" | |
9 | +) | |
10 | + | |
11 | +// @Title 保存用户移动轨迹 | |
12 | +// @Description 保存用户移动轨迹 | |
13 | +// @Accept json | |
14 | +// @Produce json | |
15 | +// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id" | |
16 | +// @Param Location {"Latitude": 119, "Longitude": 39} string true "经纬度" | |
17 | +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" | |
18 | +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" | |
19 | +// @Router /Trajectory/Save? [post] | |
20 | +func SaveTrajectory(c *gin.Context) { | |
21 | + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) | |
22 | + c.Header("Access-Control-Allow-Credentials", "true") | |
23 | + | |
24 | + var Location DB.SLocation | |
25 | + json.Unmarshal([]byte(c.PostForm("Location")), &Location) | |
26 | + | |
27 | + DB.CTrajectory.Insert(DB.STrajectory{ | |
28 | + c.PostForm("UserId"), | |
29 | + Location, | |
30 | + time.Now().Unix(), | |
31 | + }) | |
32 | + | |
33 | + c.JSON(200, tools.ResponseSeccess{ | |
34 | + 0, | |
35 | + "ok", | |
36 | + }) | |
37 | +} | ... | ... |
DB/db.go
... | ... | @@ -19,9 +19,9 @@ var CScenic *mgo.Collection //景区 |
19 | 19 | var CLine *mgo.Collection //推荐线路 |
20 | 20 | var CAccessLog *mgo.Collection //访问记录 |
21 | 21 | var CActionLog *mgo.Collection //行为记录 |
22 | +var CTrajectory *mgo.Collection //移动轨迹 | |
22 | 23 | var DB *mgo.Database |
23 | 24 | |
24 | - | |
25 | 25 | type SItem struct { |
26 | 26 | Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` |
27 | 27 | Name string `bson:"Name" json:"Name"` |
... | ... | @@ -39,6 +39,11 @@ type SItem struct { |
39 | 39 | Menu string `bson:"Menu" json:"Menu"` //菜单 |
40 | 40 | Time string `bson:"Time" json:"Time"` |
41 | 41 | } |
42 | +type STrajectory struct { | |
43 | + UserId string `bson:"UserId" json:"UserId"` // 用户ID | |
44 | + Location SLocation `bson:"Location" json:"Location"` | |
45 | + Time int64 `bson:"Time" json:"Time"` | |
46 | +} | |
42 | 47 | type SLocation struct { |
43 | 48 | Latitude float64 `bson:"Latitude" json:"Latitude"` //纬度 |
44 | 49 | Longitude float64 `bson:"Longitude" json:"Longitude"` //经度 | ... | ... |
README.md
... | ... | @@ -24,6 +24,7 @@ |
24 | 24 | 1. [返回景区基础信息](#scenicinfo-get) |
25 | 25 | 1. [发送短信验证码](#sms-send-post) |
26 | 26 | 1. [标签列表](#tags-get) |
27 | +1. [保存用户移动轨迹](#trajectory-save-post) | |
27 | 28 | 1. [更新商品](#updatecommodity-post) |
28 | 29 | 1. [更新设施](#updateitem-post) |
29 | 30 | 1. [更新等待时间](#updateitemtime-post) |
... | ... | @@ -330,6 +331,26 @@ |
330 | 331 | |
331 | 332 | |
332 | 333 | |
334 | +<a name="trajectory-save-post"></a> | |
335 | + | |
336 | +#### /Trajectory/Save (POST) | |
337 | + | |
338 | + | |
339 | +保存用户移动轨迹 | |
340 | + | |
341 | +| Param Name | Example | Data Type | Description | Required? | | |
342 | +|-----|-----|-----|-----|-----| | |
343 | +| UserId | 5dfb03070a9ac17ac7a82054 | string | 用户id | Yes | | |
344 | +| Location | {"Latitude": 119, "Longitude": 39} | string | 经纬度 | Yes | | |
345 | + | |
346 | + | |
347 | +| Code | Type | Model | Message | | |
348 | +|-----|-----|-----|-----| | |
349 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":"ok"} | | |
350 | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | | |
351 | + | |
352 | + | |
353 | + | |
333 | 354 | <a name="updatecommodity-post"></a> |
334 | 355 | |
335 | 356 | #### /UpdateCommodity (POST) | ... | ... |
main.go
... | ... | @@ -59,6 +59,7 @@ func main() { |
59 | 59 | DB.CAccessLog = DB.DB.C("AccessLog") |
60 | 60 | DB.CActionLog = DB.DB.C("ActionLog") |
61 | 61 | DB.CInvestigation = DB.DB.C("Investigation") |
62 | + DB.CTrajectory = DB.DB.C("Trajectory") | |
62 | 63 | DelayMessage.CDelayMessage = DB.DB.C("DelayMessage") |
63 | 64 | DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog") |
64 | 65 | |
... | ... | @@ -88,7 +89,8 @@ func main() { |
88 | 89 | r.POST("/AccessLog", Api.AccessLog) |
89 | 90 | r.GET("/AccessLog", Api.AccessLog) |
90 | 91 | r.POST("/Sms/Send", Api.Send) |
91 | - r.POST("/Investigation/Save", Api.Save) | |
92 | + r.POST("/Investigation/Save", Api.SaveInvestigation) | |
93 | + r.POST("/Trajectory/Save", Api.SaveTrajectory) | |
92 | 94 | r.POST("/DealyMessage/Create", Api.CreateDealyMessage) |
93 | 95 | r.GET("/DealyMessage/Info", Api.DealyMessageInfo) |
94 | 96 | //r.GET("/ws", Api.WsPage) | ... | ... |