From d6a714e9b1f02854fbc75694b91453fc30067906 Mon Sep 17 00:00:00 2001 From: aarongao Date: Wed, 15 Jan 2020 15:41:17 +0800 Subject: [PATCH] 增加移动轨迹接口 --- API/Investigation.go | 2 +- API/Trajectory.go | 37 +++++++++++++++++++++++++++++++++++++ DB/db.go | 7 ++++++- README.md | 21 +++++++++++++++++++++ main.go | 4 +++- 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 API/Trajectory.go diff --git a/API/Investigation.go b/API/Investigation.go index 41335da..44240d4 100644 --- a/API/Investigation.go +++ b/API/Investigation.go @@ -17,7 +17,7 @@ import ( // @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /Investigation/Save? [post] -func Save(c *gin.Context) { +func SaveInvestigation(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") diff --git a/API/Trajectory.go b/API/Trajectory.go new file mode 100644 index 0000000..1f54704 --- /dev/null +++ b/API/Trajectory.go @@ -0,0 +1,37 @@ +package Api + +import ( + "encoding/json" + "github.com/aarongao/tools" + "github.com/gin-gonic/gin" + "letu/DB" + "time" +) + +// @Title 保存用户移动轨迹 +// @Description 保存用户移动轨迹 +// @Accept json +// @Produce json +// @Param UserId 5dfb03070a9ac17ac7a82054 string true "用户id" +// @Param Location {"Latitude": 119, "Longitude": 39} string true "经纬度" +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Trajectory/Save? [post] +func SaveTrajectory(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + var Location DB.SLocation + json.Unmarshal([]byte(c.PostForm("Location")), &Location) + + DB.CTrajectory.Insert(DB.STrajectory{ + c.PostForm("UserId"), + Location, + time.Now().Unix(), + }) + + c.JSON(200, tools.ResponseSeccess{ + 0, + "ok", + }) +} diff --git a/DB/db.go b/DB/db.go index 87c46d0..26860b5 100644 --- a/DB/db.go +++ b/DB/db.go @@ -19,9 +19,9 @@ var CScenic *mgo.Collection //景区 var CLine *mgo.Collection //推荐线路 var CAccessLog *mgo.Collection //访问记录 var CActionLog *mgo.Collection //行为记录 +var CTrajectory *mgo.Collection //移动轨迹 var DB *mgo.Database - type SItem struct { Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` Name string `bson:"Name" json:"Name"` @@ -39,6 +39,11 @@ type SItem struct { Menu string `bson:"Menu" json:"Menu"` //菜单 Time string `bson:"Time" json:"Time"` } +type STrajectory struct { + UserId string `bson:"UserId" json:"UserId"` // 用户ID + Location SLocation `bson:"Location" json:"Location"` + Time int64 `bson:"Time" json:"Time"` +} type SLocation struct { Latitude float64 `bson:"Latitude" json:"Latitude"` //纬度 Longitude float64 `bson:"Longitude" json:"Longitude"` //经度 diff --git a/README.md b/README.md index 9afac3f..7df5831 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ 1. [返回景区基础信息](#scenicinfo-get) 1. [发送短信验证码](#sms-send-post) 1. [标签列表](#tags-get) +1. [保存用户移动轨迹](#trajectory-save-post) 1. [更新商品](#updatecommodity-post) 1. [更新设施](#updateitem-post) 1. [更新等待时间](#updateitemtime-post) @@ -330,6 +331,26 @@ + + +#### /Trajectory/Save (POST) + + +保存用户移动轨迹 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| UserId | 5dfb03070a9ac17ac7a82054 | string | 用户id | Yes | +| Location | {"Latitude": 119, "Longitude": 39} | string | 经纬度 | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":"ok"} | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + #### /UpdateCommodity (POST) diff --git a/main.go b/main.go index da43690..ba89dd7 100644 --- a/main.go +++ b/main.go @@ -59,6 +59,7 @@ func main() { DB.CAccessLog = DB.DB.C("AccessLog") DB.CActionLog = DB.DB.C("ActionLog") DB.CInvestigation = DB.DB.C("Investigation") + DB.CTrajectory = DB.DB.C("Trajectory") DelayMessage.CDelayMessage = DB.DB.C("DelayMessage") DelayMessage.CDelayErrorLog = DB.DB.C("DelayErrorLog") @@ -88,7 +89,8 @@ func main() { r.POST("/AccessLog", Api.AccessLog) r.GET("/AccessLog", Api.AccessLog) r.POST("/Sms/Send", Api.Send) - r.POST("/Investigation/Save", Api.Save) + r.POST("/Investigation/Save", Api.SaveInvestigation) + r.POST("/Trajectory/Save", Api.SaveTrajectory) r.POST("/DealyMessage/Create", Api.CreateDealyMessage) r.GET("/DealyMessage/Info", Api.DealyMessageInfo) //r.GET("/ws", Api.WsPage) -- libgit2 0.21.0