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
| package models
|
| import "github.com/astaxie/beego/orm"
|
| type UserCar struct {
| Id string `orm:"pk;size(50);column(id)" json:"id"`
| UserId string `orm:"column(userId)" json:"userId"` //人员id
| PlateNo string `orm:"column(plateNo)" json:"plateNo"` //车牌号
| }
|
| func (uc *UserCar) TableName() string {
| return "user_car"
| }
|
| func (uc *UserCar) Insert() (int64,error) {
| o := orm.NewOrm()
| return o.Insert(uc)
| }
|
| func (uc *UserCar) GetByUserId(userId string) (all []UserCar,err error) {
| o := orm.NewOrm()
| _, err = o.Raw("select * from ? where userId=?", uc.TableName(), userId).QueryRows(&all)
| if err != nil {
| return nil, err
| }
| return all,nil
| }
|
| func (uc *UserCar) Exist(userId string, plateNo string) bool {
| var list []UserCar
| o := orm.NewOrm()
| i,_ := o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list)
| if i > 0 && len(list) >0 {
| return true
| }
| return false
| }
|
| func (uc *UserCar) DeleteByUserId(userId string) (int64, error) {
| o := orm.NewOrm()
| result, err := o.Raw("delete from ? where userId=?", uc.TableName(), userId).Exec()
| if err != nil {
| return 0, err
| }
| return result.RowsAffected()
| }
|
|