Item.go
7.59 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package Api
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
"letu/Lib/Auth"
"strconv"
"time"
)
// @Title 查询设备信息
// @Description 设备管理 - 查询设备信息
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "设备id"
// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /ItemInfo? [get]
func ItemInfo(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
if c.Query("id") == "" {
c.JSON(200, tools.ResponseError{
1,
"空",
})
return
}
var SItem DB.SItem
objID, _ := primitive.ObjectIDFromHex(c.Query("id"))
DB.CItem.FindOne(tools.GetContext(), bson.M{"_id": objID}).Decode(&SItem)
c.JSON(200, tools.ResponseSeccess{
0,
SItem,
})
}
// @Title 查询所有游玩项目
// @Description 设备管理 - 查询所有游玩项目
// @Accept json
// @Produce json
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /AllItems? [get]
func AllItems(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
var aItems = []DB.SItem{}
cur, err := DB.CItem.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SItem
cur.Decode(&e)
aItems = append(aItems, e)
}
}
c.JSON(200, aItems)
}
// @Title 更新设施
// @Description 设备管理 - 更新设施
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "设备id"
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateItem? [post]
func UpdateItem(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
_user, _ := c.Get("UserInfo")
user := _user.(*DB.SMember)
err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
if err != nil {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
var Location DB.SLocation
json.Unmarshal([]byte(c.PostForm("Location")), &Location)
var Tags []DB.STag
json.Unmarshal([]byte(c.PostForm("Tags")), &Tags)
var Picture []string
json.Unmarshal([]byte(c.PostForm("Picture")), &Picture)
var id primitive.ObjectID
if pid := c.PostForm("id"); pid == "null" {
id = primitive.NewObjectID()
} else {
id, _ = primitive.ObjectIDFromHex(pid)
}
poststate, _ := strconv.Atoi(c.PostForm("State"))
upsert := true
DB.CItem.FindOneAndUpdate(tools.GetContext(),
bson.M{"_id": id},
bson.M{"$set": bson.M{
"Name": c.PostForm("Name"),
"SubName": c.PostForm("SubName"),
"ScenicId": c.PostForm("ScenicId"),
"Location": Location,
"Icon": c.PostForm("Icon"),
"LimitHeight": c.PostForm("LimitHeight"),
"PlayDuration": c.PostForm("PlayDuration"),
"SceneTime": c.PostForm("SceneTime"),
"Picture": Picture,
"Voice": c.PostForm("Voice"),
"Tel": c.PostForm("Tel"),
"AverageConsumption": c.PostForm("AverageConsumption"),
"Menu": c.PostForm("Menu"),
"Tags": Tags,
"OpenHours": c.PostForm("OpenHours"),
"LocationDescription": c.PostForm("LocationDescription"),
"Reminder": c.PostForm("Reminder"),
"State": poststate,
}}, &options.FindOneAndUpdateOptions{
Upsert: &upsert,
},
)
// 更新等待时间
allteim := DB.Redis.Get("AllItemTime_" + c.PostForm("ScenicId"))
jsond, _ := json.Marshal(allteim)
var ItemTime map[string]string
json.Unmarshal([]byte(jsond), &ItemTime)
if poststate == 1 {
ItemTime[c.PostForm("id")] = "--"
}
//if poststate == 0 {
// ItemTime[c.PostForm("id")] = "0"
//}
DB.Redis.Set("AllItemTime_" + c.PostForm("ScenicId"), ItemTime, time.Second*60*60*24*30)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
type ItemTime struct {
Id string `json:"id"`
Time string `json:"time"`
}
// @Title 更新等待时间
// @Description 设备管理 - 更新等待时间
// @Accept json
// @Produce json
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Param Token wgergejfwe string true "用户token"
// @Param item [{"id":"5df864740a9ac17ac7a7feb8","time":"20"},{"id":"5df8660924e03417008b4567","time":"33"}] string true "设备列表"
// @Success 200 {object} tools.ResponseSeccess "{errcode: 0, result: "ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /UpdateItemTime? [post]
func UpdateItemTime(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
_user, _ := c.Get("UserInfo")
user := _user.(*DB.SMember)
err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
if err != nil {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
var ItemTime []ItemTime
json.Unmarshal([]byte(c.PostForm("items")), &ItemTime)
var RedisData = make(map[string]string)
for _, v := range ItemTime {
RedisData[v.Id] = v.Time
}
DB.Redis.Set("AllItemTime_"+c.PostForm("ScenicId"), RedisData, time.Second*60*60*24*30)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
// @Title 获得所有设备的等待时间
// @Description 设备管理 - 获得所有设备的等待时间
// @Accept json
// @Produce json
// @Param ScenicId 5dfb03070a9ac17ac7a82054 string true "景区id"
// @Success 200 {object} tools.ResponseSeccess "{5df864740a9ac17ac7a7feb8: '20',.....}"
// @Failure 500 {object} tools.ResponseError "{}"
// @Router /AllItemTime? [get]
func AllItemTime(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
allteim := DB.Redis.Get("AllItemTime_" + c.Query("ScenicId"))
if allteim != nil {
c.JSON(200, allteim)
} else {
c.String(200, "{}")
}
}