Commit 92c418d4bd550b3c7773a45c83060593668f7184

Authored by aarongao
1 parent c5791520
Exists in v1.2 and in 2 other branches master, v1.1

..

API/DealyMessage.go
... ... @@ -77,6 +77,15 @@ func RemoveDealyMessage(c *gin.Context) {
77 77 c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
78 78 c.Header("Access-Control-Allow-Credentials", "true")
79 79  
  80 +
  81 + if bson.IsObjectIdHex(c.PostForm("id")) == false {
  82 + c.JSON(200, tools.ResponseError{
  83 + 1,
  84 + "id不正确",
  85 + })
  86 + return
  87 + }
  88 +
80 89 DelayMessage.GlobalDM.DelTaskForId(c.PostForm("id"))
81 90  
82 91 c.JSON(200, tools.ResponseSeccess{
... ...
API/Item.go
... ... @@ -6,6 +6,7 @@ import (
6 6 "github.com/gin-gonic/gin"
7 7 "gopkg.in/mgo.v2/bson"
8 8 "letu/DB"
  9 + "time"
9 10 )
10 11  
11 12 // @Title 查询设备信息
... ... @@ -129,19 +130,41 @@ func UpdateItemTime(c *gin.Context) {
129 130 var ItemTime []ItemTime
130 131 json.Unmarshal([]byte(c.PostForm("items")), &ItemTime)
131 132  
  133 + var RedisData = make(map[string]string)
132 134 for _, v := range ItemTime {
133   -
134   - DB.CItem.Update(
135   - bson.M{"_id": bson.ObjectIdHex(v.Id)},
136   - bson.M{"$set": bson.M{
137   - "Time": v.Time,
138   - }},
139   - )
  135 + RedisData[v.Id] = v.Time
140 136 }
141 137  
  138 +
  139 + DB.Redis.Set("AllItemTime", RedisData, time.Second*60*60*24*7)
142 140 c.JSON(200, tools.ResponseSeccess{
143 141 0,
144 142 "ok",
145 143 })
146 144  
147 145 }
  146 +
  147 +
  148 +// @Title 获得所有设备的等待时间
  149 +// @Description 获得所有设备的等待时间
  150 +// @Accept json
  151 +// @Produce json
  152 +// @Success 200 {object} tools.ResponseSeccess "{5df864740a9ac17ac7a7feb8: '20',.....}"
  153 +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
  154 +// @Router /AllItemTime? [get]
  155 +func AllItemTime(c *gin.Context) {
  156 + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
  157 + c.Header("Access-Control-Allow-Credentials", "true")
  158 +
  159 + var ItemTime map[string]string
  160 + json.Unmarshal([]byte(c.PostForm("items")), &ItemTime)
  161 +
  162 + allteim := DB.Redis.Get("AllItemTime")
  163 + if allteim != nil{
  164 + c.JSON(200, allteim)
  165 + }else{
  166 + c.String(200, "{}")
  167 + }
  168 +
  169 +
  170 +}
... ...
README.md
... ... @@ -9,6 +9,7 @@
9 9  
10 10 ### API List
11 11 1. [查询所有商品](#allcommodity-get)
  12 +1. [获得所有设备的等待时间](#allitemtime-get)
12 13 1. [查询所有游玩项目](#allitems-get)
13 14 1. [查询所有线路](#allline-get)
14 15 1. [所有景区基础信息](#allscenic-get)
... ... @@ -51,6 +52,20 @@
51 52  
52 53  
53 54  
  55 +<a name="allitemtime-get"></a>
  56 +
  57 +#### /AllItemTime (GET)
  58 +
  59 +
  60 +获得所有设备的等待时间
  61 +
  62 +| Code | Type | Model | Message |
  63 +|-----|-----|-----|-----|
  64 +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {5df864740a9ac17ac7a7feb8: '20',.....} |
  65 +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} |
  66 +
  67 +
  68 +
54 69 <a name="allitems-get"></a>
55 70  
56 71 #### /AllItems (GET)
... ...
main.go
... ... @@ -68,6 +68,7 @@ func main() {
68 68 //r.Static("/tiles", dir+"/tiles")
69 69 r.GET("/Tiles", Api.Tiles)
70 70 r.GET("/AllItems", Api.AllItems)
  71 + r.GET("/AllItemTime", Api.AllItemTime)
71 72 r.GET("/AllCommodity", Api.AllCommodity)
72 73 r.GET("/AllLine", Api.AllLine)
73 74 r.GET("/ItemInfo", Api.ItemInfo)
... ... @@ -94,7 +95,7 @@ func main() {
94 95 r.POST("/Trajectory/Save", Api.SaveTrajectory)
95 96 r.POST("/DealyMessage/Create", Api.CreateDealyMessage)
96 97 r.GET("/DealyMessage/Info", Api.DealyMessageInfo)
97   - r.GET("/DealyMessage/Remove", Api.RemoveDealyMessage)
  98 + r.POST("/DealyMessage/Remove", Api.RemoveDealyMessage)
98 99 //r.GET("/ws", Api.WsPage)
99 100  
100 101 r.Static("/Upload", "./Upload")
... ...