|
@@ -4,6 +4,7 @@ import (
|
|
|
"city_chips/internal/model"
|
|
|
"city_chips/internal/service"
|
|
|
"city_chips/pkg/helper/resp"
|
|
|
+ "city_chips/pkg/helper/uuid"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"math/rand"
|
|
@@ -141,7 +142,7 @@ func (h *HikvisionHandler) GetElectronicInspections(ctx *gin.Context) {
|
|
|
resp.HandleSuccess(ctx, m)
|
|
|
}
|
|
|
|
|
|
-// 访客系统
|
|
|
+// GetVisitor 访客系统
|
|
|
func (h *HikvisionHandler) GetVisitor(ctx *gin.Context) {
|
|
|
m := make(map[string]any)
|
|
|
PrevailingTrends := make(map[string]any)
|
|
@@ -397,3 +398,167 @@ func (h *HikvisionHandler) VisitorInfoCount(c *gin.Context) {
|
|
|
}
|
|
|
resp.HandleSuccess(c, hikvision.Data)
|
|
|
}
|
|
|
+
|
|
|
+// GetDoorSearch 查询门禁点列表v2
|
|
|
+func (h *HikvisionHandler) GetDoorSearch(ctx *gin.Context) {
|
|
|
+ // 设置响应头
|
|
|
+ ctx.Header("Content-Type", "text/event-stream")
|
|
|
+ ctx.Header("Cache-Control", "no-cache")
|
|
|
+ ctx.Header("Connection", "keep-alive")
|
|
|
+ // 监听客户端断开连接
|
|
|
+ conn := true
|
|
|
+ notify := ctx.Writer.CloseNotify()
|
|
|
+
|
|
|
+ var response model.Response
|
|
|
+ var doorlist []model.DoorList
|
|
|
+ m := make(map[string]string)
|
|
|
+ m["pageNo"] = "1"
|
|
|
+ m["pageSize"] = "1"
|
|
|
+
|
|
|
+ for conn {
|
|
|
+ select {
|
|
|
+ case <-notify:
|
|
|
+ conn = false
|
|
|
+ fmt.Println("断开连接")
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ //hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.visitorInfo"), m, 15)
|
|
|
+ //if err != nil {
|
|
|
+ // h.logger.Error("获取门禁点列表失败")
|
|
|
+ // response.Code = 1203
|
|
|
+ // response.Msg = "获取门禁点列表失败"
|
|
|
+ // response.Data = nil
|
|
|
+ // res, _ := json.Marshal(&response)
|
|
|
+ // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ // ctx.Writer.Flush()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if hikvision.Code != "0" {
|
|
|
+ // response.Code = 1203
|
|
|
+ // response.Msg = "获取门禁点列表失败"
|
|
|
+ // response.Data = nil
|
|
|
+ // res, _ := json.Marshal(&response)
|
|
|
+ // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ // ctx.Writer.Flush()
|
|
|
+ // conn = false
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ for i := 0; i < 3; i++ {
|
|
|
+ genUUID := uuid.GenUUID()
|
|
|
+ name := fmt.Sprintf("资源:%v", i+1)
|
|
|
+
|
|
|
+ list := model.DoorList{
|
|
|
+ IndexCode: genUUID,
|
|
|
+ ResourceType: "door",
|
|
|
+ Name: name,
|
|
|
+ DoorNo: genUUID,
|
|
|
+ ChannelNo: genUUID,
|
|
|
+ ParentIndexCode: genUUID,
|
|
|
+ ControlOneId: genUUID,
|
|
|
+ ControlTwoId: genUUID,
|
|
|
+ ReaderInId: genUUID,
|
|
|
+ ReaderOutId: genUUID,
|
|
|
+ DoorSerial: i + 1,
|
|
|
+ TreatyType: genUUID,
|
|
|
+ RegionIndexCode: genUUID,
|
|
|
+ RegionPath: genUUID,
|
|
|
+ CreateTime: time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ UpdateTime: time.Now().Format("2006-01-02 15:04:05"),
|
|
|
+ Description: genUUID,
|
|
|
+ ChannelType: genUUID,
|
|
|
+ RegionName: genUUID,
|
|
|
+ RegionPathName: genUUID,
|
|
|
+ InstallLocation: genUUID,
|
|
|
+ }
|
|
|
+ doorlist = append(doorlist, list)
|
|
|
+ }
|
|
|
+ doorResp := model.DoorResp{
|
|
|
+ Code: "0",
|
|
|
+ Msg: "SUCCESS",
|
|
|
+ Data: struct {
|
|
|
+ Total int `json:"total"`
|
|
|
+ PageNo int `json:"pageNo"`
|
|
|
+ PageSize int `json:"pageSize"`
|
|
|
+ List []model.DoorList `json:"list"`
|
|
|
+ }{Total: 3, PageNo: 1, PageSize: 1, List: doorlist},
|
|
|
+ }
|
|
|
+ response.Code = 200
|
|
|
+ response.Msg = "获取门禁点列表成功"
|
|
|
+ response.Data = doorResp.Data
|
|
|
+ res, _ := json.Marshal(&response)
|
|
|
+ fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ ctx.Writer.Flush()
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// DoControl 控制门禁
|
|
|
+func (h *HikvisionHandler) DoControl(ctx *gin.Context) {
|
|
|
+ // 设置响应头
|
|
|
+ ctx.Header("Content-Type", "text/event-stream")
|
|
|
+ ctx.Header("Cache-Control", "no-cache")
|
|
|
+ ctx.Header("Connection", "keep-alive")
|
|
|
+ // 监听客户端断开连接
|
|
|
+ conn := true
|
|
|
+ notify := ctx.Writer.CloseNotify()
|
|
|
+ doorIndexCodes := ctx.Query("doorIndexCodes")
|
|
|
+ controlType := ctx.Query("controlType")
|
|
|
+ if len(doorIndexCodes) <= 0 || len(controlType) <= 0 {
|
|
|
+ resp.HandleError(ctx, 1203, "设备编码不能为空", nil)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("doorIndexCodes:", doorIndexCodes)
|
|
|
+ m := make(map[string]string)
|
|
|
+ m["doorIndexCodes"] = doorIndexCodes
|
|
|
+ m["controlType"] = controlType
|
|
|
+ var response model.Response
|
|
|
+ for conn {
|
|
|
+ select {
|
|
|
+ case <-notify:
|
|
|
+ conn = false
|
|
|
+ fmt.Println("断开连接")
|
|
|
+ return
|
|
|
+ default:
|
|
|
+ //hikvision, err := h.hikvisionService.Hikvision(h.conf.GetString("hikvision.api.control"), m, 15)
|
|
|
+ //if err != nil {
|
|
|
+ // h.logger.Error("控制门禁失败")
|
|
|
+ // response.Code = 1203
|
|
|
+ // response.Msg = "控制门禁失败"
|
|
|
+ // response.Data = nil
|
|
|
+ // res, _ := json.Marshal(&response)
|
|
|
+ // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ // ctx.Writer.Flush()
|
|
|
+ // conn = false
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //if hikvision.Code != "0" {
|
|
|
+ // response.Code = 1203
|
|
|
+ // response.Msg = "控制门禁失败"
|
|
|
+ // response.Data = nil
|
|
|
+ // res, _ := json.Marshal(&response)
|
|
|
+ // fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ // ctx.Writer.Flush()
|
|
|
+ // conn = false
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ genUUID := uuid.GenUUID()
|
|
|
+ doControl := model.DoControl{
|
|
|
+ Code: "0",
|
|
|
+ Msg: "SUCCESS",
|
|
|
+ Data: []model.DoControlData{{
|
|
|
+ DoorIndexCode: genUUID,
|
|
|
+ ControlResultCode: 0,
|
|
|
+ ControlResultDesc: "success",
|
|
|
+ }},
|
|
|
+ }
|
|
|
+ response.Code = 200
|
|
|
+ response.Msg = "控制门禁成功"
|
|
|
+ response.Data = doControl.Data
|
|
|
+ res, _ := json.Marshal(&response)
|
|
|
+ fmt.Fprintf(ctx.Writer, "data: %s\n\n", string(res))
|
|
|
+ ctx.Writer.Flush()
|
|
|
+ time.Sleep(10 * time.Second)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|