qixiaoning
2025-07-08 fe724b50b3f1b3dfe2219eb9af4bcca96c89a158
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
package service
 
import (
    "basic.com/pubsub/protomsg.git"
    "errors"
    "github.com/satori/go.uuid"
    "strconv"
    "vamicro/compTable-service/models"
    "vamicro/compTable-service/vo"
    "vamicro/config"
)
 
type DbTablePersonService struct {
}
 
func (sv DbTablePersonService) Add(dbp models.Dbtablepersons) (bool, error) {
    //车牌号不能重复
    var dt models.Dbtables
    rows, _ := dt.SelectById(dbp.TableId)
    if rows == 0 {
        return false, errors.New("所属底库已不存在")
    }
    if dt.TableType == "car" {
        var tmp models.Dbtablepersons
        i, _ := tmp.SelectByCarNo(dbp.TableId, dbp.CarNo)
        if i > 0 {
            return false, errors.New("车牌号不允许重复")
        }
    }
    return dbp.Add()
}
 
func (sv DbTablePersonService) Update(dbp models.Dbtablepersons) (bool, error) {
    //车牌号不能重复
    var dt models.Dbtables
    rows, _ := dt.SelectById(dbp.TableId)
    if rows == 0 {
        return false, errors.New("所属底库已不存在")
    }
    if dt.TableType == "car" {
        var tmp models.Dbtablepersons
        i, _ := tmp.SelectByCarNo(dbp.TableId, dbp.CarNo)
        if i > 0 && tmp.Id != dbp.Id {
            return false, errors.New("车牌号不允许重复")
        }
    }
    return dbp.Update()
}
 
func (sv DbTablePersonService) DeleteById(id string) (bool, error) {
    var dbp models.Dbtablepersons
    return dbp.DeleteById(id)
}
 
func (sv DbTablePersonService) UpdateFace(arg *vo.FaceUpdateVo) (bool, error) {
    var dbp models.Dbtablepersons
    return dbp.UpdateFace(arg.Id, arg.FaceFeature, arg.PersonPicUrl)
}
 
func (sv DbTablePersonService) SelectById(id string) (dbp models.Dbtablepersons, err error) {
    var dbpE models.Dbtablepersons
    rows, err := dbpE.SelectById(id)
    if rows > 0 && err == nil {
        return dbpE, nil
    }
    return dbp, errors.New("dbtableperson not found")
}
 
func (sv DbTablePersonService) FindByPersonIds(ids []string) (arr []models.Dbtablepersons, err error) {
    var dbp models.Dbtablepersons
    return dbp.FindByPersonIds(ids)
}
 
func (sv DbTablePersonService) DeleteByPersonIds(ids []string) (b bool, err error) {
    n := len(ids)
    k := 0
    for _, id := range ids {
        b, _ := sv.DeleteById(id)
        if b {
            k++
        }
    }
    if n == k {
        return true, nil
    } else {
        return false, errors.New("delete persons err")
    }
    //return dbp.DeleteByPersonIds(ids)
}
 
func (sv DbTablePersonService) DeletePersonsByTbId(tableId string) (bool, error) {
    var dbp models.Dbtablepersons
    return dbp.DeletePersonsByTbId(tableId)
}
 
func (sv DbTablePersonService) FindPersons(tableId string, orderName string, orderType string, contentValue string, from int, size int) ([]models.Dbtablepersons, error) {
    var dbp models.Dbtablepersons
    return dbp.FindPersons(tableId, orderName, orderType, contentValue, from, size)
}
 
func (sv DbTablePersonService) GetPersonTotal(tableId string) (total int64, err error) {
    var dbp models.Dbtablepersons
    return dbp.GetPersonTotal(tableId)
}
 
func (sv DbTablePersonService) GetPersonsCompareCacheBase(from int, size int) (arr []vo.FeatureCacheBase, err error) {
    var persons []models.Dbtablepersons
    sql := "select id,faceFeature,tableId,enable,carNo 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 = models.GetDB().Raw(sql).Find(&persons).Error
    if err != nil {
        return nil, err
    }
    for _, p := range persons {
        if p.FaceFeature != "" {
            arr = append(arr, vo.FeatureCacheBase{
                Id:          p.Id,
                TableId:     p.TableId,
                FaceFeature: p.FaceFeature,
                Enable:      int32(p.Enable),
 
                CarNo: p.CarNo,
            })
        }
    }
    return
}
 
func (sv DbTablePersonService) JoinDbTable(tableIds []string, faceFeature string, pic string) bool {
    var flag = false
    for _, tableId := range tableIds {
        var dbp = new(models.Dbtablepersons)
        dbp.Id = uuid.NewV4().String()
        dbp.TableId = tableId
        dbp.FaceFeature = faceFeature
        dbp.PersonPicUrl = pic
        dbp.Enable = 1
        dbp.PriInsert()
        dbp.FromServerId = config.Server.AnalyServerId //入库位置
        b, _ := dbp.Add()
        if b {
            flag = true
        }
    }
    return flag
}
 
func (sv DbTablePersonService) Move(personId string, tableIds []string) bool {
    if len(tableIds) != 1 {
        return false
    }
    tableId := tableIds[0]
 
    var dtTmp models.Dbtables
    var dbpTmp models.Dbtablepersons
    r0, _ := dbpTmp.SelectById(personId)
    r1, _ := dtTmp.SelectById(tableId)
 
    if r0 > 0 && r1 > 0 {
        if dbpTmp.TableId == tableId { //本库移动不做操作
            return true
        }
        var oldDt models.Dbtables
        r2, _ := oldDt.SelectById(dbpTmp.TableId)
        if r2 > 0 {
            //移动到其他底库
            dbpTmp.TableId = tableId
            if b, _ := dbpTmp.Update(); b {
                go models.SyncSdkCompareCache(oldDt.AnalyServerId, protomsg.EsCacheChanged_T_DbTablePerson, oldDt.Id, personId, "", protomsg.DbAction_Delete, 0, "")
                return true
            }
        }
 
    }
    return false
}
 
func (sv DbTablePersonService) Copy(personId string, tableIds []string) bool {
    var dbpTmp models.Dbtablepersons
    r, _ := dbpTmp.SelectById(personId)
    if r > 0 {
        for _, tableId := range tableIds {
            dbpTmp.Id = uuid.NewV4().String()
            dbpTmp.TableId = tableId
            dbpTmp.Add()
        }
        return true
    }
    return false
}
 
func (sv DbTablePersonService) MultiUploadCardNo(tableId string, carNos []string) bool {
    var dbpTmp models.Dbtablepersons
    b := false
    for _, no := range carNos {
        rows, err := dbpTmp.SelectByCarNo(tableId, no)
        if err == nil && rows == 0 {
            if dbpTmp.InsertCarNo(tableId, no) {
                b = true
            }
        }
    }
 
    return b
}