hikvision.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. package handler
  2. import (
  3. "city_chips/internal/model"
  4. "city_chips/internal/service"
  5. "city_chips/pkg/helper/resp"
  6. "city_chips/pkg/helper/uuid"
  7. "encoding/json"
  8. "fmt"
  9. "math/rand"
  10. "strconv"
  11. "time"
  12. "github.com/gin-gonic/gin"
  13. "github.com/spf13/viper"
  14. "github.com/tidwall/gjson"
  15. )
  16. type HikvisionHandler struct {
  17. *Handler
  18. hikvisionService service.HikvisionService
  19. conf *viper.Viper
  20. }
  21. func NewHikvisionHandler(handler *Handler, hikvisionService service.HikvisionService, conf *viper.Viper) *HikvisionHandler {
  22. return &HikvisionHandler{
  23. Handler: handler,
  24. hikvisionService: hikvisionService,
  25. conf: conf,
  26. }
  27. }
  28. // GetMonitor 获取视频监控
  29. func (h *HikvisionHandler) GetMonitor(ctx *gin.Context) {
  30. m := make(map[string]any)
  31. LicensePlateRecognition := make(map[string]any)
  32. Blacklist := make(map[string]any)
  33. var monitor []model.Monitor
  34. for i := 0; i < 7; i++ {
  35. name := fmt.Sprintf("周%v", i+1)
  36. LicensePlateRecognition[name] = rand.Intn(100)
  37. Blacklist[name] = rand.Intn(100)
  38. }
  39. for i := 0; i < 20; i++ {
  40. m2 := model.Monitor{
  41. Id: i + 1,
  42. Name: model.GetRandomItem(model.MonitorDeviceNames),
  43. }
  44. monitor = append(monitor, m2)
  45. }
  46. m["MonitorCount"] = rand.Intn(1000) //摄像头总数
  47. m["DeviceOnline"] = rand.Intn(1000) //设备在线
  48. m["DeviceOffline"] = rand.Intn(1000) //设备离线
  49. m["StorageCapacity"] = rand.Intn(1000) //存储容量
  50. m["StoreSurplus"] = rand.Intn(1000) //存储剩余
  51. m["IntrusionDetection"] = rand.Intn(1000) //入侵检测
  52. m["AbnormalBehavior"] = rand.Intn(1000) //异常行为
  53. m["LostAlarms"] = rand.Intn(1000) //丢失告警
  54. m["LicensePlateRecognition"] = LicensePlateRecognition //车牌识别
  55. m["Blacklist"] = Blacklist //黑名单
  56. m["CPU"] = rand.Intn(100) //Cpu
  57. m["RAM"] = rand.Intn(100) //RAM
  58. m["MonitorList"] = monitor //监控列表
  59. resp.HandleSuccess(ctx, m)
  60. }
  61. // GetInvade 获取入侵检测
  62. func (h *HikvisionHandler) GetInvade(ctx *gin.Context) {
  63. m := make(map[string]any)
  64. AlarmTrend24Hour := make(map[string]any)
  65. var realTime []model.Device
  66. for i := 0; i < 24; i++ {
  67. name := fmt.Sprintf("%v时", i+1)
  68. AlarmTrend24Hour[name] = rand.Intn(100)
  69. }
  70. for i := 0; i < 10; i++ {
  71. inspection := model.Device{
  72. Id: i + 1,
  73. Name: model.GetRandomItem(model.IntrusionDeviceNames),
  74. State: rand.Intn(2),
  75. Date: time.Now().Format("2006-01-02 15:04:05"),
  76. }
  77. realTime = append(realTime, inspection)
  78. }
  79. m["DeviceAlerts"] = rand.Intn(100) //设备预警
  80. m["LowRiskWarning"] = rand.Intn(100) //低危预警
  81. m["MediumRiskWarning"] = rand.Intn(100) //中危预警
  82. m["HighRiskWarning"] = rand.Intn(1000) //高危预警
  83. m["HighRiskWarning"] = rand.Intn(1000) //高危预警
  84. m["OverHazardWarning"] = rand.Intn(1000) //超危预警
  85. m["EventRisk"] = rand.Intn(100) //事件风险
  86. m["AlarmRisk"] = rand.Intn(100) //告警风险
  87. m["trend"] = rand.Intn(100) //圆环中间百分比
  88. m["realTime"] = realTime //实时巡检
  89. m["AlarmTrend24Hour"] = AlarmTrend24Hour //24小时告警趋势
  90. resp.HandleSuccess(ctx, m)
  91. }
  92. // GetElectronicInspections 电子巡查
  93. func (h *HikvisionHandler) GetElectronicInspections(ctx *gin.Context) {
  94. m := make(map[string]any)
  95. Inspect := make(map[string]any)
  96. var device []model.Device
  97. var realTime []model.RealTimeInspection
  98. for i := 0; i < 24; i++ {
  99. name := fmt.Sprintf("%v时", i+1)
  100. Inspect[name] = rand.Intn(100)
  101. }
  102. for i := 0; i < 20; i++ {
  103. m2 := model.Device{
  104. Id: i + 1,
  105. Name: model.GetRandomItem(model.RealInspectionDeviceNames),
  106. State: rand.Intn(2),
  107. Date: time.Now().Format("2006-01-02 15:04:05"),
  108. }
  109. device = append(device, m2)
  110. }
  111. for i := 0; i < 10; i++ {
  112. name := fmt.Sprintf("巡检事件%v", i+1)
  113. inspection := model.RealTimeInspection{
  114. Id: i + 1,
  115. Name: model.GetRandomItem(model.InspectionEvents),
  116. Location: model.GetRandomItem(model.InspectionLocations),
  117. Event: name,
  118. Date: time.Now().Format("2006-01-02 15:04:05"),
  119. }
  120. realTime = append(realTime, inspection)
  121. }
  122. m["TodayTotal"] = rand.Intn(100) //今日总数
  123. m["InspectionPoints"] = rand.Intn(100) //巡检点数
  124. m["InspectionPlan"] = rand.Intn(100) //巡检计划
  125. m["InspectTheLine"] = rand.Intn(1000) //巡检线路
  126. m["Inspect"] = Inspect //巡检统计
  127. m["realTime"] = realTime //实时巡检
  128. m["DeviceList"] = device //设备列表
  129. resp.HandleSuccess(ctx, m)
  130. }
  131. // GetVisitor 访客系统
  132. func (h *HikvisionHandler) GetVisitor(ctx *gin.Context) {
  133. m := make(map[string]any)
  134. PrevailingTrends := make(map[string]any)
  135. var visitor []model.Visitor
  136. for i := 0; i < 24; i++ {
  137. address := fmt.Sprintf("%v时", i+1)
  138. m2 := model.Visitor{
  139. Id: i + 1,
  140. Name: model.GetRandomItem(model.VisitorNames),
  141. State: rand.Intn(2),
  142. Phone: model.GeneratePhoneNumber(),
  143. Location: address,
  144. Date: time.Now().Format("2006-01-02 15:04:05"),
  145. }
  146. PrevailingTrends[address] = rand.Intn(100)
  147. visitor = append(visitor, m2)
  148. }
  149. m["VisitorCount"] = rand.Intn(1000) //访客总量
  150. m["SignInCount"] = rand.Intn(1000) //签到数量
  151. m["TransitCount"] = rand.Intn(1000) //通行数量
  152. m["Exit"] = rand.Intn(1000) //离场数量
  153. m["Client"] = rand.Intn(100) //客户
  154. m["Vendor"] = rand.Intn(100) //供应商
  155. m["Interviewees"] = rand.Intn(100) //面试者
  156. m["GovernmentPersonnel"] = rand.Intn(100) //政府人员
  157. m["Other"] = rand.Intn(100) //其他
  158. m["PrevailingTrends"] = PrevailingTrends //通行趋势
  159. m["VisitorRegistration"] = visitor //访客登记
  160. m["VisitorsSwipeCards"] = visitor //访客刷卡记录
  161. resp.HandleSuccess(ctx, m)
  162. }
  163. // 客流统计
  164. func (h *HikvisionHandler) GetPassenger(ctx *gin.Context) {
  165. m := make(map[string]any)
  166. Type1 := make(map[string]any)
  167. Type2 := make(map[string]any)
  168. Type3 := make(map[string]any)
  169. Type4 := make(map[string]any)
  170. rankings := make(map[string]any)
  171. customers := make(map[string]any)
  172. var event []model.RealTimeInspection
  173. for i := 0; i < 7; i++ {
  174. sprintf := fmt.Sprintf("2025-5-%v", i+1)
  175. rankings[model.GetRandomItem(model.CustomerGroups)] = rand.Intn(100)
  176. Type1[sprintf] = rand.Intn(100)
  177. Type2[sprintf] = rand.Intn(100)
  178. Type3[sprintf] = rand.Intn(100)
  179. Type4[sprintf] = rand.Intn(100)
  180. }
  181. for i := 0; i < 3; i++ {
  182. customers[model.GetRandomItem(model.CustomerGroups)] = rand.Intn(100)
  183. }
  184. for i := 0; i < 10; i++ {
  185. inspection := model.RealTimeInspection{
  186. Id: i + 1,
  187. Name: model.GetRandomItem(model.SecurityEvents),
  188. Location: model.GetRandomItem(model.LocationsADD),
  189. Event: time.Now().Format("2006-01-02 15:04:05"),
  190. }
  191. event = append(event, inspection)
  192. }
  193. m["SecurityLevel"] = rand.Intn(500) //安全等级
  194. m["NetworkEquipment"] = rand.Intn(100) //网络设备
  195. m["Normal"] = rand.Intn(100) //正常
  196. m["Fault"] = rand.Intn(100) //故障
  197. m["Offline"] = rand.Intn(100) //离线
  198. m["Type1"] = Type1 //客流监控type1
  199. m["Type2"] = Type2 //客流监控type2
  200. m["Type3"] = Type3 //客流监控type3
  201. m["Type4"] = Type4 //客流监控type4
  202. m["Rankings"] = rankings //指标区排行榜
  203. m["Customers"] = customers //客群分析统计
  204. m["Customers"] = customers //客群分析统计
  205. m["Event"] = event //安全事件列表
  206. resp.HandleSuccess(ctx, m)
  207. }
  208. // 门禁系统
  209. func (h *HikvisionHandler) GetAccess(ctx *gin.Context) {
  210. m := make(map[string]any)
  211. invasio1 := make(map[string]any)
  212. invasio2 := make(map[string]any)
  213. DailyTotal := make(map[string]any)
  214. Cumulative := make(map[string]any)
  215. var devices []model.RealTimeInspection
  216. var alarmList []model.AlarmList
  217. for i := 0; i < 7; i++ {
  218. sprintf := fmt.Sprintf("2025-5-%v", i+1)
  219. invasio1[sprintf] = rand.Intn(100)
  220. invasio2[sprintf] = rand.Intn(100)
  221. }
  222. for i := 0; i < 24; i++ {
  223. sprintf := fmt.Sprintf("%v时", i+1)
  224. DailyTotal[sprintf] = rand.Intn(100)
  225. Cumulative[sprintf] = rand.Intn(100)
  226. }
  227. for i := 0; i < 10; i++ {
  228. inspection := model.RealTimeInspection{
  229. Id: i + 1,
  230. Name: model.GetRandomItem(model.MJDeviceNames),
  231. Location: model.GetRandomItem(model.MJlocations),
  232. Event: time.Now().Format("2006-01-02 15:04:05"),
  233. }
  234. alarm := model.AlarmList{
  235. Id: i + 1,
  236. AlarmContent: model.GetRandomItem(model.MJDeviceNames),
  237. Location: model.GetRandomItem(model.MJlocations),
  238. State: rand.Intn(2),
  239. Date: time.Now().Format("2006-01-02 15:04:05"),
  240. }
  241. devices = append(devices, inspection)
  242. alarmList = append(alarmList, alarm)
  243. }
  244. m["DeviceCount"] = rand.Intn(500) //设备总数
  245. m["Online"] = rand.Intn(100) //在线
  246. m["Abnormal"] = rand.Intn(100) //异常
  247. m["Fault"] = rand.Intn(100) //故障
  248. m["Offline"] = rand.Intn(100) //离线
  249. m["Attendance"] = rand.Intn(100) //出勤率
  250. m["Invasio1"] = invasio1 //入侵事件1
  251. m["Invasio2"] = invasio2 //入侵事件2
  252. m["DailyTotal"] = DailyTotal //每日统计
  253. m["Cumulative"] = Cumulative //累计统计
  254. m["AlarmList"] = alarmList //实时告警与通知
  255. m["devices"] = devices //设备列表
  256. resp.HandleSuccess(ctx, m)
  257. }
  258. // GetHikvisionMonitoring 获取视频监控流{
  259. // "cameraIndexCode": "748d84750e3a4a5bbad3cd4af9ed5101",
  260. // "streamType": 0,
  261. // "protocol": "rtsp",
  262. // "transmode": 1,
  263. // "expand": "transcode=0",
  264. // "streamform": "ps"
  265. // }
  266. func (h *HikvisionHandler) GetHikvisionMonitoring(ctx *gin.Context) {
  267. m := make(map[string]string)
  268. cameraIndexCode := ctx.Query("cameraIndexCode")
  269. m["cameraIndexCode"] = cameraIndexCode
  270. m["streamType"] = "0"
  271. m["protocol"] = "rtsp"
  272. m["transmode"] = "1"
  273. m["expand"] = "transcode=0"
  274. m["streamform"] = "ps"
  275. if len(cameraIndexCode) <= 0 || cameraIndexCode == "" {
  276. resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
  277. return
  278. }
  279. fmt.Println(m)
  280. resp.HandleSuccess(ctx, "rtsp://10.2.145.66:655/EUrl/CLJ52BW")
  281. return
  282. hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.cameras"), m, 15)
  283. //返回结果{
  284. // "code": "0",
  285. // "msg": "success",
  286. // "data": {
  287. // "url": "rtsp://10.2.145.66:655/EUrl/CLJ52BW"
  288. // }
  289. //}
  290. if err != nil {
  291. h.logger.Error("获取获取监控点资源失败")
  292. resp.HandleError(ctx, 1201, "获取获取监控点资源失败", err)
  293. return
  294. }
  295. if hikvision.Code != "0" {
  296. atoi, _ := strconv.Atoi(hikvision.Code)
  297. resp.HandleError(ctx, atoi, hikvision.Msg, nil)
  298. return
  299. }
  300. marshalString, err := json.Marshal(hikvision)
  301. if err != nil {
  302. resp.HandleError(ctx, 1202, "json序列化失败", nil)
  303. return
  304. }
  305. url := gjson.Get(string(marshalString), "data.url")
  306. resp.HandleSuccess(ctx, url)
  307. }
  308. // 视频监控云台控制{
  309. // "cameraIndexCode": "748d84750e3a4a5bbad3cd4af9ed5101",
  310. // "action": 1, 0-开始
  311. //1-停止
  312. //注:GOTO_PRESET命令下填任意值均可转到预置点,建议填0即可
  313. // "command": "GOTO_PRESET",
  314. // "speed": 4,
  315. // "presetIndex": 20
  316. //}
  317. func (h *HikvisionHandler) Gimbalcontrol(ctx *gin.Context) {
  318. m := make(map[string]string)
  319. cameraIndexCode := ctx.Query("cameraIndexCode")
  320. command := ctx.Query("command")
  321. action := ctx.Query("action")
  322. speed := ctx.Query("speed")
  323. presetIndex := ctx.Query("presetIndex")
  324. m["cameraIndexCode"] = cameraIndexCode
  325. m["action"] = action
  326. m["command"] = command
  327. m["speed"] = speed
  328. m["presetIndex"] = presetIndex
  329. if len(cameraIndexCode) <= 0 || len(command) <= 0 || len(action) <= 0 {
  330. resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
  331. return
  332. }
  333. resp.HandleSuccess(ctx, m)
  334. return
  335. hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.controlling"), m, 15)
  336. if err != nil {
  337. h.logger.Error("控制云台失败")
  338. resp.HandleError(ctx, 1201, "控制云台失败", err)
  339. return
  340. }
  341. if hikvision.Code != "0" {
  342. atoi, _ := strconv.Atoi(hikvision.Code)
  343. resp.HandleError(ctx, atoi, hikvision.Msg, nil)
  344. return
  345. }
  346. resp.HandleSuccess(ctx, hikvision.Msg)
  347. }
  348. // VisitorInfoCount 获取今日访客信息包含:今日来访总人数(已签离人数,未签离人数),预约人数
  349. func (h *HikvisionHandler) VisitorInfoCount(c *gin.Context) {
  350. m := make(map[string]string)
  351. parkId := c.Query("parkId")
  352. m["parkId"] = parkId
  353. resp.HandleSuccess(c, "appointmentTotal: 1, notSignOutTotal: 1, signOutTotal: 1, signTotal: 1, orderCount: 1, visitCount: 1, visitCountForTemp: 1, visitCountForOrder: 1, signOutCount: 1, notSignOutCount: 1")
  354. return
  355. hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.visitorInfo"), m, 15)
  356. if err != nil {
  357. h.logger.Error("获取访客信息失败")
  358. resp.HandleError(c, 1201, "获取访客信息失败", err)
  359. return
  360. }
  361. if hikvision.Code != "0" {
  362. atoi, _ := strconv.Atoi(hikvision.Code)
  363. resp.HandleError(c, atoi, hikvision.Msg, nil)
  364. return
  365. }
  366. resp.HandleSuccess(c, hikvision.Data)
  367. }
  368. // GetDoorSearch 查询门禁点列表v2
  369. func (h *HikvisionHandler) GetDoorSearch(ctx *gin.Context) {
  370. // 设置响应头
  371. ctx.Header("Content-Type", "text/event-stream")
  372. ctx.Header("Cache-Control", "no-cache")
  373. ctx.Header("Connection", "keep-alive")
  374. // 监听客户端断开连接
  375. conn := true
  376. notify := ctx.Writer.CloseNotify()
  377. var response model.Response
  378. var doorlist []model.DoorList
  379. m := make(map[string]string)
  380. m["pageNo"] = "1"
  381. m["pageSize"] = "1"
  382. for conn {
  383. select {
  384. case <-notify:
  385. conn = false
  386. fmt.Println("断开连接")
  387. return
  388. default:
  389. //hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.visitorInfo"), m, 15)
  390. //if err != nil {
  391. // h.logger.Error("获取门禁点列表失败")
  392. // response.Code = 1203
  393. // response.Msg = "获取门禁点列表失败"
  394. // response.Data = nil
  395. // res, _ := json.Marshal(&response)
  396. // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  397. // ctx.Writer.Flush()
  398. // return
  399. //}
  400. //if hikvision.Code != "0" {
  401. // response.Code = 1203
  402. // response.Msg = "获取门禁点列表失败"
  403. // response.Data = nil
  404. // res, _ := json.Marshal(&response)
  405. // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  406. // ctx.Writer.Flush()
  407. // conn = false
  408. // return
  409. //}
  410. for i := 0; i < 3; i++ {
  411. genUUID := uuid.GenUUID()
  412. name := fmt.Sprintf("资源:%v", i+1)
  413. list := model.DoorList{
  414. IndexCode: genUUID,
  415. ResourceType: "door",
  416. Name: name,
  417. DoorNo: genUUID,
  418. ChannelNo: genUUID,
  419. ParentIndexCode: genUUID,
  420. ControlOneId: genUUID,
  421. ControlTwoId: genUUID,
  422. ReaderInId: genUUID,
  423. ReaderOutId: genUUID,
  424. DoorSerial: i + 1,
  425. TreatyType: genUUID,
  426. RegionIndexCode: genUUID,
  427. RegionPath: genUUID,
  428. CreateTime: time.Now().Format("2006-01-02 15:04:05"),
  429. UpdateTime: time.Now().Format("2006-01-02 15:04:05"),
  430. Description: genUUID,
  431. ChannelType: genUUID,
  432. RegionName: genUUID,
  433. RegionPathName: genUUID,
  434. InstallLocation: genUUID,
  435. }
  436. doorlist = append(doorlist, list)
  437. }
  438. doorResp := model.DoorResp{
  439. Code: "0",
  440. Msg: "SUCCESS",
  441. Data: struct {
  442. Total int `json:"total"`
  443. PageNo int `json:"pageNo"`
  444. PageSize int `json:"pageSize"`
  445. List []model.DoorList `json:"list"`
  446. }{Total: 3, PageNo: 1, PageSize: 1, List: doorlist},
  447. }
  448. response.Code = 200
  449. response.Msg = "获取门禁点列表成功"
  450. response.Data = doorResp.Data
  451. res, _ := json.Marshal(&response)
  452. fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  453. ctx.Writer.Flush()
  454. time.Sleep(10 * time.Second)
  455. }
  456. }
  457. }
  458. // DoControl 控制门禁
  459. func (h *HikvisionHandler) DoControl(ctx *gin.Context) {
  460. // 设置响应头
  461. ctx.Header("Content-Type", "text/event-stream")
  462. ctx.Header("Cache-Control", "no-cache")
  463. ctx.Header("Connection", "keep-alive")
  464. // 监听客户端断开连接
  465. conn := true
  466. notify := ctx.Writer.CloseNotify()
  467. doorIndexCodes := ctx.Query("doorIndexCodes")
  468. controlType := ctx.Query("controlType")
  469. if len(doorIndexCodes) <= 0 || len(controlType) <= 0 {
  470. resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
  471. return
  472. }
  473. fmt.Println("doorIndexCodes:", doorIndexCodes)
  474. m := make(map[string]string)
  475. m["doorIndexCodes"] = doorIndexCodes
  476. m["controlType"] = controlType
  477. var response model.Response
  478. for conn {
  479. select {
  480. case <-notify:
  481. conn = false
  482. fmt.Println("断开连接")
  483. return
  484. default:
  485. //hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.control"), m, 15)
  486. //if err != nil {
  487. // h.logger.Error("控制门禁失败")
  488. // response.Code = 1203
  489. // response.Msg = "控制门禁失败"
  490. // response.Data = nil
  491. // res, _ := json.Marshal(&response)
  492. // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  493. // ctx.Writer.Flush()
  494. // conn = false
  495. // return
  496. //}
  497. //if hikvision.Code != "0" {
  498. // response.Code = 1203
  499. // response.Msg = "控制门禁失败"
  500. // response.Data = nil
  501. // res, _ := json.Marshal(&response)
  502. // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  503. // ctx.Writer.Flush()
  504. // conn = false
  505. // return
  506. //}
  507. genUUID := uuid.GenUUID()
  508. doControl := model.DoControl{
  509. Code: "0",
  510. Msg: "SUCCESS",
  511. Data: []model.DoControlData{{
  512. DoorIndexCode: genUUID,
  513. ControlResultCode: 0,
  514. ControlResultDesc: "success",
  515. }},
  516. }
  517. response.Code = 200
  518. response.Msg = "控制门禁成功"
  519. response.Data = doControl.Data
  520. res, _ := json.Marshal(&response)
  521. fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
  522. ctx.Writer.Flush()
  523. time.Sleep(10 * time.Second)
  524. }
  525. }
  526. }