zhangzengfei
2024-03-30 0a5b44e9d50a554244fab038b8bc539c31313d71
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
package db
 
import (
    "strconv"
)
 
type DbPersons struct {
    BaseEntity
    TableId            string   `gorm:"column:tableId" json:"tableId" example:"库表id"`
    FaceFeature        string   `gorm:"column:faceFeature" json:"faceFeature" example:"人脸特征值(车主特征)"`
    PersonPicUrl       string   `gorm:"column:personPicUrl" json:"personPicUrl" example:"图片路径,(车主照片)"`
    PersonName         string   `gorm:"column:personName" json:"personName" example:"人员姓名,(车主姓名)"`
    Age                string   `gorm:"column:age" json:"age"  example:"年龄"`
    Sex                string   `gorm:"column:sex" json:"sex" example:"性别 男 女(车主性别)"`
    IdCard             string   `gorm:"column:idCard" json:"idCard" example:"身份证(车主身份证)"`
    PhoneNum           string   `gorm:"column:phoneNum" json:"phoneNum" example:"手机号码"`
    MonitorLevel       string   `gorm:"column:monitorLevel" json:"monitorLevel" example:"等级"`
    PicDesc            string   `gorm:"column:picDesc" json:"picDesc" example:"照片标识"`
    Reserved           string   `gorm:"column:reserved" json:"reserved" example:"其他"`
    FromServerId       string   `gorm:"column:fromServerId" json:"fromServerId,omitempty" example:"入库serverId"`
    ResidentialArea    string   `gorm:"column:residential_area;type:varchar(255)" json:"residentialArea" example:"小区"`
    Community          string   `gorm:"column:community;type:varchar(255)" json:"community" example:"社区"`
    LastAppearanceTime int64    `gorm:"column:last_appearance_time;type:int;not null;default:0" json:"lastAppearanceTime" example:"123456789"`
    SnapshotCount      int      `gorm:"column:snapshot_count;type:varchar(255)" json:"snapshotCount" example:"10" comment:"抓拍次数"`
    DaysAppeared       int      `gorm:"column:days_appeared;type:int(11);not null;default:0" json:"daysAppeared" example:"5" comment:"出现天数"`
    Location           string   `gorm:"column:location;type:varchar(255)" json:"location" example:"建档地点" comment:"建档地点"`
    LastLocation       string   `gorm:"column:last_location;type:varchar(255)" json:"lastLocation" example:"最后出现地点" comment:"最后出现地点"`
    FaceAngleYaw       int      `gorm:"column:face_angle_yaw;type:int(11)" json:"faceAngleYaw" example:"15" comment:"人脸角度偏航角"`
    FaceAngleRoll      int      `gorm:"column:face_angle_roll;type:int(11)" json:"faceAngleRoll" example:"16" comment:"人脸角度滚转角"`
    FaceAnglePitch     int      `gorm:"column:face_angle_pitch;type:int(11)" json:"faceAnglePitch" example:"15" comment:"人脸角度俯仰角"`
    PersonalStatusName string   `gorm:"column:personal_status;type:varchar(31);comment:AI标签" json:"-"` //AI标签
    PersonalStatus     string   `gorm:"-" json:"personalStatus"`                                       //AI标签对应名称
    Labels             []string `gorm:"-" json:"labels"`                                               //手动添加的标签对应名称
    AreaID             string   `json:"areaID" gorm:"index;column:communityID;type:varchar(299);"`     //常驻小区 domain unit ID
    OrgID              string   `json:"orgID" gorm:"index;column:org_id;type:varchar(299);"`           //常驻派出所 domain unit ID
}
 
func (dbp *DbPersons) GetPersonTotal(tableId string) (total int64, err error) {
    sql := "select count(1) as total from dbtablepersons where isDelete=0 and tableId in (select id from dbtables where isDelete=0)"
    if tableId != "" {
        sql += " and tableId='" + tableId + "'"
    }
    err = db.Raw(sql).Count(&total).Error
    return
}
 
func (dbp *DbPersons) GetPersonsCompareCacheBase(from int, size int) (arr []*FeatureCacheBase, err error) {
    var persons []DbPersons
    sql := "select id, tableId, faceFeature, communityID, enable from dbtablepersons where isDelete=0 and tableId in (select id from dbtables where isDelete=0)"
    sql += " order by id asc limit " + strconv.Itoa(from) + "," + strconv.Itoa(size)
    err = db.Raw(sql).Find(&persons).Error
    if err != nil {
        return nil, err
    }
 
    for _, p := range persons {
        if p.FaceFeature != "" {
            arr = append(arr, &FeatureCacheBase{
                Id:          p.Id,
                TableId:     p.TableId,
                AreaId:      p.AreaID,
                FaceFeature: p.FaceFeature,
                Enable:      int32(p.Enable),
            })
        }
    }
    return
}
 
func (dbp *DbPersons) GetPersonsCompareCacheById(id string) (info *FeatureCacheBase, err error) {
    sql := "select id, tableId, faceFeature, communityID, enable from dbtablepersons where id = \"" + id + "\""
    var p DbPersons
    err = db.Raw(sql).First(&p).Error
    if err != nil {
        return nil, err
    }
    if p.FaceFeature != "" {
        info = &FeatureCacheBase{
            Id:          p.Id,
            TableId:     p.TableId,
            AreaId:      p.AreaID,
            FaceFeature: p.FaceFeature,
            Enable:      int32(p.Enable),
        }
    }
    return
}