qixiaoning
2025-08-22 0f97177f258c67397b206b70e5aea2b24a4868c1
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
package controllers
 
import (
    "basic.com/fileServer/WeedFSClient.git"
    esApi "basic.com/pubsub/esutil.git"
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/bhomeclient.git"
    "basic.com/valib/bhomedbapi.git"
    "basic.com/valib/logger.git"
    "github.com/satori/go.uuid"
    "sort"
    "strconv"
    "strings"
    "time"
    "vamicro/compTable-service/models"
    "vamicro/compTable-service/service"
    "vamicro/compTable-service/vo"
    "vamicro/config"
    "vamicro/extend/util"
    cc "vamicro/gb28181-service/cache"
    searchM "vamicro/search-service/models"
)
 
type DbPersonController struct {
}
 
// @Summary 添加底库人员
// @Description 添加底库人员
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param obj body models.Dbtablepersons true "底库人员数据"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/addDbPerson [PUT]
func (dbp DbPersonController) AddDbPerson(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var dbperson models.Dbtablepersons
    err := c.BindJSON(&dbperson)
    if err != nil || dbperson.TableId == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    b := false
    var sv service.DbTablePersonService
    if dbperson.Id == "" { //新增
        dbperson.Id = uuid.NewV4().String()
        dbperson.FromServerId = config.Server.AnalyServerId //入库serverId
        dbperson.PriInsert()
        b, _ = sv.Add(dbperson)
    } else { //更新
        dbperson.PriUpdate()
        b, _ = sv.Update(dbperson)
    }
 
    if b {
        return &bhomeclient.Reply{Success: true, Data: dbperson}
    } else {
        return &bhomeclient.Reply{Msg: "新增失败"}
    }
}
 
type DbtSearch struct {
    TableId      string `json:"tableId"`
    OrderName    string `json:"orderName"`
    OrderType    string `json:"orderType"`
    ContentValue string `json:"contentValue"`
    Page         int    `json:"page"`
    Size         int    `json:"size"`
}
 
// @Summary 查询底库人员列表
// @Description 查询库人员列表
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param argBody body controllers.DbtSearch false "{"tableId":"","orderName":"uuid","orderType":"desc","contentValue":"","page":1,"size":8}"
// @Success 200 {string} json "{code:200, msg:"", success:true, data:""}"
// @Failure 500 {string} json "{code:500, msg:"", success:false, data:""}"
// @Router /data/api-v/dbperson/queryDbPersonsByTbId [POST]
func (dbp DbPersonController) QueryDbPersonsByTbId(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody DbtSearch
    c.BindJSON(&reqBody)
    tableId := ""
    if reqBody.TableId != "" {
        tableId = reqBody.TableId
    }
    if tableId == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    orderName := "id" // 列名
    if reqBody.OrderName != "" {
        orderName = reqBody.OrderName
    }
    orderType := "desc" // 排序类型
    if reqBody.OrderType != "" {
        orderType = reqBody.OrderType
    }
    contentValue := "" //输入框内容
    if reqBody.ContentValue != "" {
        contentValue = reqBody.ContentValue
    }
    page := 1 // 页码
    if reqBody.Page > 1 {
        page = reqBody.Page
    }
    size := 8 // 条数
    if reqBody.Size > 8 {
        size = reqBody.Size
    }
    from := (page - 1) * size
    var sv service.DbTablePersonService
 
    arr, err := sv.FindPersons(tableId, orderName, orderType, contentValue, from, size)
    total, _ := sv.GetPersonTotal(tableId)
 
    if err == nil {
        var m = map[string]interface{}{
            "total":    total,
            "datalist": arr,
        }
        return &bhomeclient.Reply{Success: true, Data: m}
    } else {
        var m = map[string]interface{}{
            "total":    total,
            "datalist": []interface{}{},
        }
        return &bhomeclient.Reply{Data: m}
    }
}
 
// @Summary 修改底库人员
// @Description 修改底库人员
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param person body models.Dbtablepersons true "底库人员数据"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Router /data/api-v/dbperson/updateDbPerson [POST]
func (dbp DbPersonController) UpdateDbPerson(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var dbperson models.Dbtablepersons
    err := c.BindJSON(&dbperson)
    if err != nil || dbperson.Id == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    dbperson.PriUpdate()
    var sv service.DbTablePersonService
    b, _ := sv.Update(dbperson)
    if b {
        return &bhomeclient.Reply{Success: true, Data: dbperson}
    } else {
        return &bhomeclient.Reply{Msg: "更新失败"}
    }
}
 
type MultiCarNo struct {
    TableId string   `json:"tableId" binding:"required"`
    CarNos  []string `json:"carNos" binding:"required"`
}
 
// @Security ApiKeyAuth
// @Summary 批量添加底库车辆
// @Description 批量添加底库车辆
// @Accept  json
// @Produce json
// @Tags dbperson 底库人员
// @Param reqBody body controllers.MultiCarNo true "批量车牌号"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/dbperson/multiUploadCarNo [post]
func (dbp DbPersonController) MultiUploadCarNo(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody MultiCarNo
    err := c.BindJSON(&reqBody)
    if err != nil {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    logger.Debug("multiUploadCarNo reqBody:", reqBody)
    var sv service.DbTablePersonService
    if sv.MultiUploadCardNo(reqBody.TableId, reqBody.CarNos) {
        return &bhomeclient.Reply{Success: true, Msg: "上传成功"}
    } else {
        return &bhomeclient.Reply{Msg: "上传失败"}
    }
}
 
// @Summary 更新底库人脸照片
// @Description 更新底库人脸照片
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param person body vo.FaceUpdateVo true "人脸更新参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/dbperson/updateFace [POST]
func (dbp DbPersonController) UpdateFace(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var arg vo.FaceUpdateVo
    err := c.BindJSON(&arg)
    if err != nil || arg.Id == "" || arg.FaceFeature == "" || arg.PersonPicUrl == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    b, _ := sv.UpdateFace(&arg)
    if b {
        return &bhomeclient.Reply{Success: true, Msg: "更新成功"}
    } else {
        return &bhomeclient.Reply{Msg: "更新失败"}
    }
}
 
// @Summary 删除底库人员
// @Description 删除库人员
// @Accept  x-www-form-urlencoded
// @Produce json
// @Tags 底库人员
// @Param id path string true "底库人员id "
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/deleteDbPersonById [POST]
func (dbp DbPersonController) DeleteDbPerson(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    id := c.Query("id")
    if id == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    b, _ := sv.DeleteById(id)
    if b {
        return &bhomeclient.Reply{Success: true, Msg: "删除成功"}
    } else {
        return &bhomeclient.Reply{Msg: "删除失败"}
    }
}
 
type DelMultiPersons struct {
    Ids []string `json:"ids"`
}
 
// @Summary 删除底库人员
// @Description 删除库人员
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param ids body controllers.DelMultiPersons true "底库人员ids,字符串数组"
// @Success 200 {string} json "{code:200, msg:"", success:true}"
// @Failure 500 {string} json "{code:500, msg:"", success:false}"
// @Router /data/api-v/dbperson/deleteMoreDbPerson [POST]
func (dbp DbPersonController) DeleteMoreDbPerson(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var ids DelMultiPersons
    err := c.BindJSON(&ids)
    logger.Debug("DeleteMoreDbPerson ids:", ids)
    if err != nil || len(ids.Ids) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    b, _ := sv.DeleteByPersonIds(ids.Ids)
    if b {
        return &bhomeclient.Reply{Success: true, Msg: "删除成功"}
    } else {
        return &bhomeclient.Reply{Msg: "删除失败"}
    }
}
 
// @Summary 根据底库id删除底库人员
// @Description 根据底库id删除库人员
// @Accept  x-www-form-urlencoded
// @Produce json
// @Tags 底库人员
// @Param tableId path string true "底库id "
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/deletePersonsByTbId [POST]
func (dbp DbPersonController) DeletePersonsByTbId(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    tableId := c.Query("tableId")
    if tableId == "" {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    b, _ := sv.DeletePersonsByTbId(tableId)
    if b {
        return &bhomeclient.Reply{Success: true, Msg: "删除成功"}
    } else {
        return &bhomeclient.Reply{Msg: "删除失败"}
    }
}
 
// @Summary 根据多个人员id查询详情
// @Description 根据多个人员id查询详情
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param ids body controllers.IdsArr true "人员ids"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/dbPersonInfoByIds [POST]
func (dbp DbPersonController) DbPersonInfoByIds(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var idsArr IdsArr
    err := c.BindJSON(&idsArr)
    if err != nil || len(idsArr.Ids) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    arr, e := sv.FindByPersonIds(idsArr.Ids)
    if e != nil {
        return &bhomeclient.Reply{Msg: "查询失败", Data: []interface{}{}}
    } else {
        return &bhomeclient.Reply{Success: true, Data: arr}
    }
}
 
// @Summary 获取人员总数
// @Description 获取人员总数
// @Accept  x-www-form-urlencoded
// @Produce json
// @Tags 底库人员
// @Param tableId query string false "底库id"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/getPersonTotal [GET]
func (dbp DbPersonController) GetPersonTotal(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    tableId := c.Query("tableId")
    logger.Debug("GetPersonTotal tableId:", tableId)
    var sv service.DbTablePersonService
    total, err := sv.GetPersonTotal(tableId)
    if err != nil {
        return &bhomeclient.Reply{Msg: "查询失败"}
    } else {
        return &bhomeclient.Reply{Success: true, Data: total}
    }
}
 
// @Summary 根据所有底库人员的id和faceFeature,给缓存比对使用
// @Description 根据所有底库人员的id和faceFeature,给缓存比对使用
// @Accept  x-www-form-urlencoded
// @Produce json
// @Tags 底库人员
// @Param from query int true "from"
// @Param size query int true "size"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/getPersonsCompareCacheBase [GET]
func (dbp DbPersonController) GetPersonsCompareCacheBase(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var sv service.DbTablePersonService
    fromStr := c.Query("from")
    sizeStr := c.Query("size")
    logger.Debug("from:", fromStr, ",size:", sizeStr)
    from, e1 := strconv.Atoi(fromStr)
    size, e2 := strconv.Atoi(sizeStr)
    if e1 != nil || e2 != nil {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    arr, err := sv.GetPersonsCompareCacheBase(from, size)
    if err != nil {
        return &bhomeclient.Reply{Msg: "查询失败"}
    } else {
        return &bhomeclient.Reply{Success: true, Data: arr}
    }
}
 
type JoinDbTArg struct {
    CaptureId string   `json:"captureId"`
    TableIds  []string `json:"tableIds"`
}
 
// @Summary 抓拍人脸加入底库
// @Description 抓拍人脸加入底库
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param obj body controllers.JoinDbTArg true "加入底库参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/joinDbTable [POST]
func (dbp DbPersonController) JoinDbTable(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody JoinDbTArg
    c.BindJSON(&reqBody)
    if reqBody.CaptureId == "" || len(reqBody.TableIds) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sApi bhomedbapi.SysSetApi
    flag, localConf := sApi.GetServerInfo()
    if !flag || localConf.AlarmIp == "" || localConf.AlarmPort == 0 {
        logger.Debug("localConf err")
        return &bhomeclient.Reply{Success: false, Msg: "报警设置有误"}
    }
    logger.Debug("call joinDb")
    aiOceans, e := esApi.AIOceaninfosbyid([]string{reqBody.CaptureId}, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
    logger.Debug("e:", e, "len(aiOceans):", len(aiOceans))
    if e == nil && aiOceans != nil && len(aiOceans) == 1 {
        var personPicUrl = "" //人脸图片
        var feature = ""      //特征
        if aiOceans[0].TargetInfo != nil && len(aiOceans[0].TargetInfo) > 0 {
            personPicUrl = aiOceans[0].TargetInfo[0].PicSmUrl
        }
        fea, e2 := esApi.GetVideoPersonFaceFeatureById(reqBody.CaptureId, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
        logger.Debug("e2:", e2)
        if e2 == nil && fea != "" {
            feature = fea
        }
        if personPicUrl != "" && feature != "" {
            //将这张抓拍的照片下载下来上传到collection=persistent的集合中,防止被清理掉
            logger.Debug("personPicUrl:", personPicUrl)
            if !strings.HasPrefix(personPicUrl, "http://") {
                personPicUrl = "http://" + personPicUrl
            }
            picB, e3 := util.DownLoad(personPicUrl)
            logger.Debug("e3:", e3)
            if e3 == nil {
                weedfsUri := "http://" + localConf.WebPicIp + ":" + strconv.Itoa(int(localConf.WebPicPort)) + "/submit?collection=" + localConf.ServerId + "-persistent"
                newPersonPicUrl, e4 := WeedFSClient.UploadFile(weedfsUri, "capturePerson", picB, 5*time.Second)
                logger.Debug("e4:", e4, "newPersonPicUrl:", newPersonPicUrl)
                if e4 == nil {
                    var sv service.DbTablePersonService
                    if b := sv.JoinDbTable(reqBody.TableIds, feature, newPersonPicUrl); b {
                        return &bhomeclient.Reply{Success: true, Msg: "加入成功"}
                    } else {
                        return &bhomeclient.Reply{Msg: "加入失败"}
                    }
                } else {
                    logger.Debug("upload faceImg err:", e4)
                }
            } else {
                logger.Debug("download personPic ERR:", e3)
            }
        } else {
            logger.Debug("personPicUrl or feature is empty!!!")
        }
    }
    return &bhomeclient.Reply{Msg: "加入失败"}
}
 
type LikeCondition struct {
    TableIds   []string `json:"tableIds"` //底库id集合
    InputValue string   `json:"inputValue"`
}
 
// @Summary 根据条件查底库人员id
// @Description 根据条件查底库人员id
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"", success:false}"
// @Router /data/api-v/dbperson/findLikePersonIds [POST]
func (dbp DbPersonController) FindLikePersonIds(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var condition LikeCondition
    c.BindJSON(&condition)
    var dbpE models.Dbtablepersons
    personIds, err := dbpE.FindLikePersonIds(condition.TableIds, condition.InputValue)
    if err == nil {
        return &bhomeclient.Reply{Success: true, Data: personIds}
    } else {
        return &bhomeclient.Reply{Msg: "查询失败"}
    }
}
 
type DbPersonMove struct {
    PersonId string   `json:"personId"`
    TableIds []string `json:"tableIds"`
}
 
// @Security ApiKeyAuth
// @Summary 人员移动
// @Description 人员移动
// @Accept  json
// @Produce json
// @Tags dbperson 底库人员
// @Param obj body controllers.DbPersonMove true "移动参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/dbperson/move [POST]
func (dbp *DbPersonController) Move(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody DbPersonMove
    c.BindJSON(&reqBody)
    if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    if sv.Move(reqBody.PersonId, reqBody.TableIds) {
        return &bhomeclient.Reply{Success: true, Msg: "移动成功"}
    } else {
        return &bhomeclient.Reply{Msg: "移动失败"}
    }
}
 
// @Security ApiKeyAuth
// @Summary 人员复制
// @Description 人员复制
// @Accept  json
// @Produce json
// @Tags dbperson 底库人员
// @Param obj body controllers.DbPersonMove true "复制参数"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/dbperson/copy [POST]
func (dbp *DbPersonController) Copy(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var reqBody DbPersonMove
    c.BindJSON(&reqBody)
    if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var sv service.DbTablePersonService
    if sv.Copy(reqBody.PersonId, reqBody.TableIds) {
        return &bhomeclient.Reply{Success: true, Msg: "复制成功"}
    } else {
        return &bhomeclient.Reply{Msg: "复制失败"}
    }
}
 
type FaceExtract struct {
    Url       string `json:"url"`
    FaceBytes []byte `json:"faceBytes"`
}
 
var faceExtractedMap = make(map[string]FaceExtract, 0)
 
// @Security ApiKeyAuth
// @Summary 人脸提取
// @Description  人脸提取
// @Accept multipart/form-data
// @Produce json
// @Tags 以图搜图
// @Param file formData file true "人员图片"
// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}"
// @Router /data/api-v/dbperson/extract [POST]
func (dbp *DbPersonController) FaceExtract(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    file, err := c.FormFile() //image这个是uplaodify参数定义中的   'fileObjName':'image'
    if err != nil {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
 
    _, weedfsUri, err2 := cc.GetWeedfsUri()
    if err2 != nil {
        logger.Debug("localConfig is wrong!!!")
        return &bhomeclient.Reply{Msg: err.Error()}
    }
    logger.Debug("weedfsUri:", weedfsUri)
    resultMap := make(map[string]interface{}, 0)
    //将上传的图片交人脸检测和人脸提取,获得特征
    faceArr, err, pI := service.GetFaceFeaFromSdk(file.Bytes, time.Second*60)
    if err == nil && len(faceArr) > 0 {
        //1.提取每一张人脸小图
        urlArr := make([]string, 0)
        for _, r := range faceArr {
            logger.Debug("faceExtract confidence:", r.Pos.FAngle.Confidence, "Width:", r.Pos.RcFace.Right-r.Pos.RcFace.Left, "Pitch:", r.Pos.FAngle.Pitch, "Roll:", r.Pos.FAngle.Roll, "Yaw:", r.Pos.FAngle.Yaw)
            rcFace := r.Pos.RcFace
            cutFaceImgData, cutErr := util.SubCutImg(pI, rcFace, 20)
            if cutErr != nil {
                logger.Debug("util.SubCutImg err:", cutErr)
                continue
            }
            weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", cutFaceImgData, 5*time.Second)
            if e == nil {
                faceExtractedMap[weedFilePath] = FaceExtract{
                    Url:       weedFilePath,
                    FaceBytes: r.Feats,
                }
                urlArr = append(urlArr, weedFilePath)
            }
        }
        //2.大图画框,标识人脸位置
        drawedB, _ := drawPolygonOnImg(pI, &faceArr)
 
        originFilePath, _ := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", *drawedB, 5*time.Second)
        resultMap["uploadImage"] = originFilePath
        resultMap["smImage"] = urlArr
        return &bhomeclient.Reply{Success: true, Data: resultMap}
    } else {
        return &bhomeclient.Reply{Msg: "未提取到人脸"}
    }
}
 
func (dbp *DbPersonController) QueryDbPersonsByCompare(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    var searchBody searchM.EsSearch
    err := c.BindJSON(&searchBody)
    if err != nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 {
        return &bhomeclient.Reply{Msg: "参数有误"}
    }
    var faceB []byte
    if face, ok := faceExtractedMap[searchBody.PicUrl]; !ok {
        return &bhomeclient.Reply{Msg: "请重新上传图片"}
    } else {
        faceB = face.FaceBytes
    }
 
    analyServerId := ""
 
    conf, err := cc.GetServerInfo()
    if err != nil && conf.ServerId != "" {
        analyServerId = conf.ServerId
    } else {
        return &bhomeclient.Reply{Msg: "analyServerId为空,配置有误"}
    }
 
    arg := protomsg.CompareArgs{
        FaceFeature:      faceB,
        CompareThreshold: searchBody.Threshold,
    }
    arg.TableIds = searchBody.DataBases
    arg.AnalyServerId = analyServerId
    compareService := service.NewFaceCompareService(arg)
    var totalData service.CompareList
 
    dbPersonTargets, _ := compareService.CompareDbPersons()
    if dbPersonTargets != nil {
        totalData = append(totalData, *dbPersonTargets...)
    }
 
    service.SetCompResultByNum(&service.CompareOnce{
        CompareNum:  compareService.CompareNum,
        CompareData: &totalData,
    })
 
    m := make(map[string]interface{}, 3)
    if totalData != nil && totalData.Len() > 0 {
        sort.Sort(totalData)
        total := totalData.Len()
 
        m["compareNum"] = compareService.CompareNum
        m["total"] = total
        var sCompResult protomsg.SdkCompareResult
        if total <= searchBody.Size {
            sCompResult.CompareResult = totalData
        } else {
            sCompResult.CompareResult = totalData[0:searchBody.Size]
        }
        resultList := FillDbPersonDataToCompareResult(&sCompResult)
        m["totalList"] = resultList
    } else {
        m["total"] = 0
        m["compareNum"] = compareService.CompareNum
        m["totalList"] = []CompareResult{}
    }
    return &bhomeclient.Reply{Success: true, Data: m}
}
 
//填充向前端返回的数据
func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []models.DbPersonsCompVo {
 
    var resultList = make([]models.DbPersonsCompVo, len(compResult.CompareResult))
    dbPersonM := make(map[string]ScoreIndex, 0)
    personIds := make([]string, 0)
 
    for idx, v := range compResult.CompareResult {
        dbPersonM[v.Id] = ScoreIndex{
            Index:        idx,
            CompareScore: float64(v.CompareScore),
        }
        personIds = append(personIds, v.Id)
    }
    logger.Debug("comp len(personIds):", len(personIds))
 
    var dbpersons []models.Dbtablepersons
    if len(personIds) > 0 {
        sv := service.DbTablePersonService{}
        dbpersons, _ = sv.FindByPersonIds(personIds)
    }
 
    if len(dbpersons) > 0 {
        //var dtApi dbapi.DbTableApi
        for _, p := range dbpersons {
            var dbP models.DbPersonsCompVo
 
            dbP.Id = p.Id
            dbP.TableId = p.TableId
            dbP.FaceFeature = p.FaceFeature
            dbP.PersonPicUrl = p.PersonPicUrl
            dbP.PersonName = p.PersonName
            dbP.Age = p.Age
            dbP.Sex = p.Sex
            dbP.IdCard = p.IdCard
            dbP.PhoneNum = p.PhoneNum
            dbP.MonitorLevel = p.MonitorLevel
            dbP.Reserved = p.Reserved
            dbP.IsDelete = int(p.IsDelete)
            dbP.Enable = int(p.Enable)
            dbP.CreateTime = p.CreateTime
            dbP.UpdateTime = p.UpdateTime
            dbP.CreateBy = p.CreateBy
            dbP.CompareScore = dbPersonM[p.Id].CompareScore
            //dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId })
            //if dbTableInfos !=nil{
            //    dbP.BwType = dbTableInfos[0].BwType
            //    dbP.TableName = dbTableInfos[0].TableName
            //}
            resultList[dbPersonM[p.Id].Index] = dbP
        }
    }
 
    return resultList
}
 
func (dbp *DbPersonController) FindDicByType(h *bhomeclient.WrapperHandler, c *bhomeclient.Request) *bhomeclient.Reply {
    resMap := make(map[string][]models.Dictionary, 0)
 
    var dic models.Dictionary
    cts, _ := dic.FindByType(models.TYPE_VEHICLE_TYPE) //车辆类型
    resMap[models.TYPE_VEHICLE_TYPE] = cts
 
    cbs, _ := dic.FindByType(models.TYPE_VEHICLE_BRAND) //车辆品牌
    resMap[models.TYPE_VEHICLE_BRAND] = cbs
 
    ccs, _ := dic.FindByType(models.TYPE_VEHICLE_COLOR) //车身颜色
    resMap[models.TYPE_VEHICLE_COLOR] = ccs
 
    return &bhomeclient.Reply{Success: true, Data: resMap}
}