package db import ( "basic.com/valib/logger.git" "encoding/base64" "sdkCompare/util" "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 != "" { byteFeat, err := base64.StdEncoding.DecodeString(p.FaceFeature) if err != nil { logger.Errorf("Person %s feature is invalid", p.Id) continue } arr = append(arr, &FeatureCacheBase{ Id: p.Id, TableId: p.TableId, AreaId: p.AreaID, FaceFeature: util.ByteSlice2float32Slice(byteFeat), Enable: int32(p.Enable), }) } else { logger.Errorf("Person %s feature is empty %s", p.Id) } } 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 != "" { byteFeat, err := base64.StdEncoding.DecodeString(p.FaceFeature) if err != nil { return nil, err } info = &FeatureCacheBase{ Id: p.Id, TableId: p.TableId, AreaId: p.AreaID, FaceFeature: util.ByteSlice2float32Slice(byteFeat), Enable: int32(p.Enable), } } return }