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
| package models
|
| import (
| "fmt"
| "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.QueryTable(uc.TableName()).Filter("userId", userId).All(&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()
| o.Raw("select * from ? where userId=? and plateNo=?", uc.TableName(), userId, plateNo).QueryRows(&list)
| if len(list) >0 {
| return true
| }
| return false
| }
|
| func (uc *UserCar) Delete(userId string, plateNo string) (int64, error) {
| o := orm.NewOrm()
| sql := fmt.Sprintf("delete from "+uc.TableName()+" where userId=%s and plateNo=%s", userId, plateNo)
| fmt.Println("sql:", sql)
| result, err := o.Raw(sql).Exec()
| if err != nil {
| return 0, err
| }
| return result.RowsAffected()
| }
|
|