正在显示
40 个修改的文件
包含
118 行增加
和
4530 行删除
1 | [dev] | 1 | [dev] |
2 | #数据库相关 | 2 | #数据库相关 |
3 | -data_source = "root:123456@tcp(192.168.100.102:3306)/opportunity?loc=Local" | 3 | +data_source = "root:123456@tcp(127.0.0.1:3306)/opportunity?loc=Local" |
4 | #data_source = "root:sutianxia2015@tcp(115.29.205.99:3306)/ability_display" | 4 | #data_source = "root:sutianxia2015@tcp(115.29.205.99:3306)/ability_display" |
5 | #data_source = "root:root@tcp(localhost:3306)/ability_display?loc=Local" | 5 | #data_source = "root:root@tcp(localhost:3306)/ability_display?loc=Local" |
6 | 6 | ||
7 | #redis相关配置 | 7 | #redis相关配置 |
8 | -redis_add_port = "192.168.100.102:6379" | 8 | +redis_add_port = "127.0.0.1:6379" |
9 | redis_auth = "123456" | 9 | redis_auth = "123456" |
10 | 10 | ||
11 | #sms相关配置 | 11 | #sms相关配置 |
@@ -184,7 +184,7 @@ func CheckToken(ctx *context.Context) (result bool) { | @@ -184,7 +184,7 @@ func CheckToken(ctx *context.Context) (result bool) { | ||
184 | } else { | 184 | } else { |
185 | if rsp.UserInfo != nil { | 185 | if rsp.UserInfo != nil { |
186 | //设置附加数据 | 186 | //设置附加数据 |
187 | - ctx.Request.Header.Add("uid", fmt.Sprintf("%v", rsp.UserInfo.Uuid)) | 187 | + ctx.Request.Header.Add("uid", fmt.Sprintf("%v", rsp.UserInfo.UserId)) |
188 | } | 188 | } |
189 | } | 189 | } |
190 | return | 190 | return |
@@ -3,27 +3,23 @@ package controllers | @@ -3,27 +3,23 @@ package controllers | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "log" | 5 | "log" |
6 | + "opp/protocol" | ||
6 | "reflect" | 7 | "reflect" |
7 | "testing" | 8 | "testing" |
8 | - "time" | ||
9 | - | ||
10 | - "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" | ||
11 | - "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
12 | ) | 9 | ) |
13 | 10 | ||
14 | func Test_GenMessage(t *testing.T) { | 11 | func Test_GenMessage(t *testing.T) { |
15 | input := []struct { | 12 | input := []struct { |
16 | Rsp interface{} | 13 | Rsp interface{} |
17 | Error error | 14 | Error error |
18 | - Exceprt *mybeego.Message | 15 | + Exceprt *protocol.ResponseMessage |
19 | }{ | 16 | }{ |
20 | - {Rsp: "test", Error: fmt.Errorf("test"), Exceprt: mybeego.NewMessage(1)}, | ||
21 | - {Rsp: "test-A", Error: common.NewErrorWithMsg(100, "test-A"), Exceprt: mybeego.NewErrMessage(100, "test-A")}, | 17 | + {Rsp: "test", Error: fmt.Errorf("test"), Exceprt: protocol.NewErrWithMessage(1, fmt.Errorf("test")).ParseToMessage()}, |
18 | + {Rsp: "test-A", Error: protocol.NewErrWithMessage(100, fmt.Errorf("test-A")), Exceprt: protocol.NewErrWithMessage(100, fmt.Errorf("test-A")).ParseToMessage()}, | ||
22 | } | 19 | } |
23 | - | ||
24 | for i := range input { | 20 | for i := range input { |
25 | o := input[i] | 21 | o := input[i] |
26 | - out := DefaultController.GenMessage(o.Rsp, o.Error) | 22 | + out := protocol.NewReturnResponse(o.Rsp, o.Error) |
27 | if !reflect.DeepEqual(out, o.Exceprt) { | 23 | if !reflect.DeepEqual(out, o.Exceprt) { |
28 | log.Fatal("not equal ", out, o.Exceprt) | 24 | log.Fatal("not equal ", out, o.Exceprt) |
29 | } | 25 | } |
@@ -34,16 +30,12 @@ func Benchmark_GenMessage(b *testing.B) { | @@ -34,16 +30,12 @@ func Benchmark_GenMessage(b *testing.B) { | ||
34 | o := struct { | 30 | o := struct { |
35 | Rsp interface{} | 31 | Rsp interface{} |
36 | Error error | 32 | Error error |
37 | - Exceprt *mybeego.Message | ||
38 | - }{Rsp: "test", Error: fmt.Errorf("test"), Exceprt: mybeego.NewMessage(1)} | 33 | + Exceprt *protocol.ResponseMessage |
34 | + }{Rsp: "test", Error: fmt.Errorf("test"), Exceprt: protocol.NewErrWithMessage(1, fmt.Errorf("test-A")).ParseToMessage()} | ||
39 | for i := 0; i < b.N; i++ { | 35 | for i := 0; i < b.N; i++ { |
40 | - out := DefaultController.GenMessage(o.Rsp, o.Error) | 36 | + out := protocol.NewReturnResponse(o.Rsp, o.Error) |
41 | if out.Errmsg != o.Exceprt.Errmsg || out.Errno != o.Exceprt.Errno { | 37 | if out.Errmsg != o.Exceprt.Errmsg || out.Errno != o.Exceprt.Errno { |
42 | log.Fatal("not equal ", out, o.Exceprt) | 38 | log.Fatal("not equal ", out, o.Exceprt) |
43 | } | 39 | } |
44 | } | 40 | } |
45 | } | 41 | } |
46 | - | ||
47 | -func TestXXX(t *testing.T) { | ||
48 | - t.Log(time.Now()) | ||
49 | -} |
internal/repository/config.go
已删除
100755 → 0
1 | -package repository | ||
2 | - | ||
3 | -import "opp/models" | ||
4 | - | ||
5 | -type IConfigRepository interface { | ||
6 | - GetCfgClient(clintId, clientSecret string) (v *models.CfgClient, err error) | ||
7 | -} | ||
8 | - | ||
9 | -type ConfigRepository struct{} | ||
10 | - | ||
11 | -func (r *ConfigRepository) GetCfgClient(clintId, clientSecret string) (v *models.CfgClient, err error) { | ||
12 | - return models.GetCfgClient(clintId, clientSecret) | ||
13 | -} |
internal/repository/config_mock.go
已删除
100755 → 0
@@ -2,34 +2,25 @@ package repository | @@ -2,34 +2,25 @@ package repository | ||
2 | 2 | ||
3 | import "sync" | 3 | import "sync" |
4 | 4 | ||
5 | -var( | ||
6 | - mutex sync.RWMutex | ||
7 | - DefaultUserRepository IUserRepository | ||
8 | - DefaultConfigRepository IConfigRepository | 5 | +//全局 |
6 | +var ( | ||
7 | + once sync.Once | ||
8 | + User IUserRepository | ||
9 | + UserAuth IUserAuthRepository | ||
9 | ) | 10 | ) |
10 | 11 | ||
11 | -func init(){ | ||
12 | - DefaultUserRepository = UserRepositoryFactory() | 12 | +func init() { |
13 | + InitRepository() | ||
13 | } | 14 | } |
14 | 15 | ||
15 | -func UserRepositoryFactory()IUserRepository{ | ||
16 | - if DefaultUserRepository==nil{ | ||
17 | - mutex.Lock() | ||
18 | - defer mutex.Unlock() | ||
19 | - if DefaultUserRepository==nil{ | ||
20 | - DefaultUserRepository = &UserRepository{} | ||
21 | - } | ||
22 | - } | ||
23 | - return DefaultUserRepository | 16 | +func InitRepository() { |
17 | + User = &UserRepository{} | ||
18 | + UserAuth = &UserAuthRepository{} | ||
24 | } | 19 | } |
25 | 20 | ||
26 | -func ConfigRepositoryFactory()IConfigRepository{ | ||
27 | - if DefaultConfigRepository==nil{ | ||
28 | - mutex.Lock() | ||
29 | - defer mutex.Unlock() | ||
30 | - if DefaultConfigRepository==nil{ | ||
31 | - DefaultConfigRepository = &ConfigRepository{} | ||
32 | - } | ||
33 | - } | ||
34 | - return DefaultConfigRepository | ||
35 | -} | ||
21 | +func InitRepositoryMock() { | ||
22 | + once.Do(func() { | ||
23 | + User = &UserMockRepository{} | ||
24 | + UserAuth = &UserAuthMockRepository{} | ||
25 | + }) | ||
26 | +} |
@@ -3,35 +3,23 @@ package repository | @@ -3,35 +3,23 @@ package repository | ||
3 | import "opp/models" | 3 | import "opp/models" |
4 | 4 | ||
5 | type IUserRepository interface { | 5 | type IUserRepository interface { |
6 | - GetUsersByMobile(mobile string) (v *models.Users, err error) | ||
7 | - GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error) | ||
8 | - UpdateUserInfoById(m *models.UserInfo) (err error) | ||
9 | - GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error) | ||
10 | - GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error) | 6 | + GetUsersById(uid int64) (v *models.User, err error) |
7 | + GetUsersByMobile(mobile string) (v *models.User, err error) | ||
8 | + UpdateUserInfo(m *models.User) (err error) | ||
11 | } | 9 | } |
12 | 10 | ||
13 | -func assertImplement() { | ||
14 | - var _ IUserRepository = (*UserRepository)(nil) | ||
15 | -} | 11 | +var _ IUserRepository = (*UserRepository)(nil) |
16 | 12 | ||
17 | type UserRepository struct{} | 13 | type UserRepository struct{} |
18 | 14 | ||
19 | -func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.Users, err error) { | ||
20 | - return models.GetUsersByMobile(mobile) | ||
21 | -} | ||
22 | - | ||
23 | -func (r *UserRepository) GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error) { | ||
24 | - return models.GetUserInfoByMobile(mobile) | 15 | +func (r *UserRepository) GetUsersById(uid int64) (v *models.User, err error) { |
16 | + return models.GetUsersById(uid) | ||
25 | } | 17 | } |
26 | 18 | ||
27 | -func (r *UserRepository) UpdateUserInfoById(m *models.UserInfo) (err error) { | ||
28 | - return models.UpdateUserInfoById(m) | ||
29 | -} | ||
30 | - | ||
31 | -func (r *UserRepository) GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error) { | ||
32 | - return models.GetUserInfoByAuthCode(authCode) | 19 | +func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { |
20 | + return models.GetUsersByMobile(mobile) | ||
33 | } | 21 | } |
34 | 22 | ||
35 | -func (r *UserRepository) GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error) { | ||
36 | - return models.GetUserInfoByRefreshToken(refreshToken) | 23 | +func (r *UserRepository) UpdateUserInfo(m *models.User) (err error) { |
24 | + return models.UpdateUsersById(m) | ||
37 | } | 25 | } |
internal/repository/user_auth.go
0 → 100644
1 | +package repository | ||
2 | + | ||
3 | +import "opp/models" | ||
4 | + | ||
5 | +type IUserAuthRepository interface { | ||
6 | + GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) | ||
7 | + UpdateUserAuthById(m *models.UserAuth) (err error) | ||
8 | + GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) | ||
9 | + GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) | ||
10 | + GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) | ||
11 | +} | ||
12 | + | ||
13 | +var _ IUserAuthRepository = (*UserAuthRepository)(nil) | ||
14 | + | ||
15 | +type UserAuthRepository struct{} | ||
16 | + | ||
17 | +func (r *UserAuthRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) { | ||
18 | + return models.GetUserAuthByUserId(uid) | ||
19 | +} | ||
20 | + | ||
21 | +func (r *UserAuthRepository) UpdateUserAuthById(m *models.UserAuth) (err error) { | ||
22 | + return models.UpdateUserAuthById(m) | ||
23 | +} | ||
24 | + | ||
25 | +func (r *UserAuthRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | ||
26 | + return models.GetUserByAuthCode(authCode) | ||
27 | +} | ||
28 | + | ||
29 | +func (r *UserAuthRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) { | ||
30 | + return models.GetUserAuthByRefreshToken(refreshToken) | ||
31 | +} | ||
32 | + | ||
33 | +func (r *UserAuthRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) { | ||
34 | + return models.GetUserAuthByToken(refreshToken) | ||
35 | +} |
internal/repository/user_auth_mock.go
0 → 100644
1 | +package repository | ||
2 | + | ||
3 | +import "opp/models" | ||
4 | + | ||
5 | +var userAuth = &models.UserAuth{ | ||
6 | + AuthCode: "897ca746f46b11e98771000c29ad8d6d", | ||
7 | + AccessToken: "897ca746f46b11e98771000c29ad8d7d", | ||
8 | + RefreshToken: "897ca746f46b11e98771000c29ad8d8d", | ||
9 | +} | ||
10 | + | ||
11 | +type UserAuthMockRepository struct{} | ||
12 | + | ||
13 | +func (r *UserAuthMockRepository) GetUserAuthByUserId(uid int64) (v *models.UserAuth, err error) { | ||
14 | + v = userAuth | ||
15 | + return | ||
16 | +} | ||
17 | + | ||
18 | +func (r *UserAuthMockRepository) UpdateUserAuthById(m *models.UserAuth) (err error) { | ||
19 | + return | ||
20 | +} | ||
21 | + | ||
22 | +func (r *UserAuthMockRepository) GetUserAuthByAuthCode(authCode string) (v *models.UserAuth, err error) { | ||
23 | + v = userAuth | ||
24 | + return | ||
25 | +} | ||
26 | + | ||
27 | +func (r *UserAuthMockRepository) GetUserAuthByRefreshToken(refreshToken string) (v *models.UserAuth, err error) { | ||
28 | + v = userAuth | ||
29 | + return | ||
30 | +} | ||
31 | + | ||
32 | +func (r *UserAuthMockRepository) GetUserAuthByToken(refreshToken string) (v *models.UserAuth, err error) { | ||
33 | + v = userAuth | ||
34 | + return | ||
35 | +} |
@@ -4,35 +4,27 @@ import "opp/models" | @@ -4,35 +4,27 @@ import "opp/models" | ||
4 | 4 | ||
5 | type UserMockRepository struct{} | 5 | type UserMockRepository struct{} |
6 | 6 | ||
7 | -var userInfo = &models.UserInfo{ | ||
8 | - Auth: "897ca746f46b11e98771000c29ad8d6d", | 7 | +var userInfo = &models.UserAuth{ |
8 | + AuthCode: "897ca746f46b11e98771000c29ad8d6d", | ||
9 | AccessToken: "897ca746f46b11e98771000c29ad8d7d", | 9 | AccessToken: "897ca746f46b11e98771000c29ad8d7d", |
10 | RefreshToken: "897ca746f46b11e98771000c29ad8d8d", | 10 | RefreshToken: "897ca746f46b11e98771000c29ad8d8d", |
11 | } | 11 | } |
12 | 12 | ||
13 | -func (r *UserMockRepository) GetUsersByMobile(mobile string) (v *models.Users, err error) { | ||
14 | - v = &models.Users{ | ||
15 | - Username: "18065048389", | ||
16 | - Password: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy", | ||
17 | - } | ||
18 | - return | ||
19 | -} | ||
20 | - | ||
21 | -func (r *UserMockRepository) GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error) { | ||
22 | - v = userInfo | ||
23 | - return | 13 | +var user = &models.User{ |
14 | + Phone: "18065048389", | ||
15 | + Passwd: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy", | ||
24 | } | 16 | } |
25 | 17 | ||
26 | -func (r *UserMockRepository) UpdateUserInfoById(m *models.UserInfo) (err error) { | 18 | +func (r *UserMockRepository) GetUsersById(uid int64) (v *models.User, err error) { |
19 | + v = user | ||
27 | return | 20 | return |
28 | } | 21 | } |
29 | 22 | ||
30 | -func (r *UserMockRepository) GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error) { | ||
31 | - v = userInfo | 23 | +func (r *UserMockRepository) GetUsersByMobile(mobile string) (v *models.User, err error) { |
24 | + v = user | ||
32 | return | 25 | return |
33 | } | 26 | } |
34 | 27 | ||
35 | -func (r *UserMockRepository) GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error) { | ||
36 | - v = userInfo | 28 | +func (r *UserMockRepository) UpdateUserInfo(m *models.User) (err error) { |
37 | return | 29 | return |
38 | } | 30 | } |
@@ -34,7 +34,7 @@ func init() { | @@ -34,7 +34,7 @@ func init() { | ||
34 | //panic(err) | 34 | //panic(err) |
35 | } | 35 | } |
36 | orm.NewBeeormEngine(config.Mysql{ | 36 | orm.NewBeeormEngine(config.Mysql{ |
37 | - AliasName: "default", | 37 | + //AliasName: "default", |
38 | DataSource: beego.AppConfig.String("data_source"), | 38 | DataSource: beego.AppConfig.String("data_source"), |
39 | MaxIdle: 100, | 39 | MaxIdle: 100, |
40 | MaxOpen: 100, | 40 | MaxOpen: 100, |
models/announcement.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Announcement struct { | ||
14 | - Id int `orm:"column(id);pk" description:"主键ID"` | ||
15 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
16 | - Content string `orm:"column(content);size(500)" description:"消息标题"` | ||
17 | - CompanyId int64 `orm:"column(company_id);null"` | ||
18 | - Day string `orm:"column(day);size(20)" description:"日期"` | ||
19 | -} | ||
20 | - | ||
21 | -func (t *Announcement) TableName() string { | ||
22 | - return "announcement" | ||
23 | -} | ||
24 | - | ||
25 | -func init() { | ||
26 | - orm.RegisterModel(new(Announcement)) | ||
27 | -} | ||
28 | - | ||
29 | -// AddAnnouncement insert a new Announcement into database and returns | ||
30 | -// last inserted Id on success. | ||
31 | -func AddAnnouncement(m *Announcement) (id int64, err error) { | ||
32 | - o := orm.NewOrm() | ||
33 | - id, err = o.Insert(m) | ||
34 | - return | ||
35 | -} | ||
36 | - | ||
37 | -// GetAnnouncementById retrieves Announcement by Id. Returns error if | ||
38 | -// Id doesn't exist | ||
39 | -func GetAnnouncementById(id int) (v *Announcement, err error) { | ||
40 | - o := orm.NewOrm() | ||
41 | - v = &Announcement{Id: id} | ||
42 | - if err = o.Read(v); err == nil { | ||
43 | - return v, nil | ||
44 | - } | ||
45 | - return nil, err | ||
46 | -} | ||
47 | - | ||
48 | -// GetAllAnnouncement retrieves all Announcement matches certain condition. Returns empty list if | ||
49 | -// no records exist | ||
50 | -func GetAllAnnouncement(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | - o := orm.NewOrm() | ||
53 | - qs := o.QueryTable(new(Announcement)) | ||
54 | - // query k=v | ||
55 | - for k, v := range query { | ||
56 | - // rewrite dot-notation to Object__Attribute | ||
57 | - k = strings.Replace(k, ".", "__", -1) | ||
58 | - if strings.Contains(k, "isnull") { | ||
59 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | - } else { | ||
61 | - qs = qs.Filter(k, v) | ||
62 | - } | ||
63 | - } | ||
64 | - // order by: | ||
65 | - var sortFields []string | ||
66 | - if len(sortby) != 0 { | ||
67 | - if len(sortby) == len(order) { | ||
68 | - // 1) for each sort field, there is an associated order | ||
69 | - for i, v := range sortby { | ||
70 | - orderby := "" | ||
71 | - if order[i] == "desc" { | ||
72 | - orderby = "-" + v | ||
73 | - } else if order[i] == "asc" { | ||
74 | - orderby = v | ||
75 | - } else { | ||
76 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | - } | ||
78 | - sortFields = append(sortFields, orderby) | ||
79 | - } | ||
80 | - qs = qs.OrderBy(sortFields...) | ||
81 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | - for _, v := range sortby { | ||
84 | - orderby := "" | ||
85 | - if order[0] == "desc" { | ||
86 | - orderby = "-" + v | ||
87 | - } else if order[0] == "asc" { | ||
88 | - orderby = v | ||
89 | - } else { | ||
90 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | - } | ||
92 | - sortFields = append(sortFields, orderby) | ||
93 | - } | ||
94 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | - } | ||
97 | - } else { | ||
98 | - if len(order) != 0 { | ||
99 | - return nil, errors.New("Error: unused 'order' fields") | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - var l []Announcement | ||
104 | - qs = qs.OrderBy(sortFields...) | ||
105 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | - if len(fields) == 0 { | ||
107 | - for _, v := range l { | ||
108 | - ml = append(ml, v) | ||
109 | - } | ||
110 | - } else { | ||
111 | - // trim unused fields | ||
112 | - for _, v := range l { | ||
113 | - m := make(map[string]interface{}) | ||
114 | - val := reflect.ValueOf(v) | ||
115 | - for _, fname := range fields { | ||
116 | - m[fname] = val.FieldByName(fname).Interface() | ||
117 | - } | ||
118 | - ml = append(ml, m) | ||
119 | - } | ||
120 | - } | ||
121 | - return ml, nil | ||
122 | - } | ||
123 | - return nil, err | ||
124 | -} | ||
125 | - | ||
126 | -// UpdateAnnouncement updates Announcement by Id and returns error if | ||
127 | -// the record to be updated doesn't exist | ||
128 | -func UpdateAnnouncementById(m *Announcement) (err error) { | ||
129 | - o := orm.NewOrm() | ||
130 | - v := Announcement{Id: m.Id} | ||
131 | - // ascertain id exists in the database | ||
132 | - if err = o.Read(&v); err == nil { | ||
133 | - var num int64 | ||
134 | - if num, err = o.Update(m); err == nil { | ||
135 | - fmt.Println("Number of records updated in database:", num) | ||
136 | - } | ||
137 | - } | ||
138 | - return | ||
139 | -} | ||
140 | - | ||
141 | -// DeleteAnnouncement deletes Announcement by Id and returns error if | ||
142 | -// the record to be deleted doesn't exist | ||
143 | -func DeleteAnnouncement(id int) (err error) { | ||
144 | - o := orm.NewOrm() | ||
145 | - v := Announcement{Id: id} | ||
146 | - // ascertain id exists in the database | ||
147 | - if err = o.Read(&v); err == nil { | ||
148 | - var num int64 | ||
149 | - if num, err = o.Delete(&Announcement{Id: id}); err == nil { | ||
150 | - fmt.Println("Number of records deleted in database:", num) | ||
151 | - } | ||
152 | - } | ||
153 | - return | ||
154 | -} |
models/bonus_point.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type BonusPoint struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - CompanyId int `orm:"column(company_id)" description:"公司ID"` | ||
16 | - Type int8 `orm:"column(type)" description:"加分类型 0发现 1分析 2解决"` | ||
17 | - Uid int64 `orm:"column(uid)" description:"被加分人"` | ||
18 | - Score int `orm:"column(score)" description:"加分数值"` | ||
19 | - JoinDate time.Time `orm:"column(join_date);type(date)" description:"加入年月"` | ||
20 | - OperatorId int64 `orm:"column(operator_id)" description:"加分人(操作者id)"` | ||
21 | - Reason string `orm:"column(reason);size(500);null" description:"加分理由"` | ||
22 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
23 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);auto_now_add"` | ||
24 | -} | ||
25 | - | ||
26 | -func (t *BonusPoint) TableName() string { | ||
27 | - return "bonus_point" | ||
28 | -} | ||
29 | - | ||
30 | -func init() { | ||
31 | - orm.RegisterModel(new(BonusPoint)) | ||
32 | -} | ||
33 | - | ||
34 | -// AddBonusPoint insert a new BonusPoint into database and returns | ||
35 | -// last inserted Id on success. | ||
36 | -func AddBonusPoint(m *BonusPoint) (id int64, err error) { | ||
37 | - o := orm.NewOrm() | ||
38 | - id, err = o.Insert(m) | ||
39 | - return | ||
40 | -} | ||
41 | - | ||
42 | -// GetBonusPointById retrieves BonusPoint by Id. Returns error if | ||
43 | -// Id doesn't exist | ||
44 | -func GetBonusPointById(id int) (v *BonusPoint, err error) { | ||
45 | - o := orm.NewOrm() | ||
46 | - v = &BonusPoint{Id: id} | ||
47 | - if err = o.Read(v); err == nil { | ||
48 | - return v, nil | ||
49 | - } | ||
50 | - return nil, err | ||
51 | -} | ||
52 | - | ||
53 | -// GetAllBonusPoint retrieves all BonusPoint matches certain condition. Returns empty list if | ||
54 | -// no records exist | ||
55 | -func GetAllBonusPoint(query map[string]string, fields []string, sortby []string, order []string, | ||
56 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
57 | - o := orm.NewOrm() | ||
58 | - qs := o.QueryTable(new(BonusPoint)) | ||
59 | - // query k=v | ||
60 | - for k, v := range query { | ||
61 | - // rewrite dot-notation to Object__Attribute | ||
62 | - k = strings.Replace(k, ".", "__", -1) | ||
63 | - if strings.Contains(k, "isnull") { | ||
64 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
65 | - } else { | ||
66 | - qs = qs.Filter(k, v) | ||
67 | - } | ||
68 | - } | ||
69 | - // order by: | ||
70 | - var sortFields []string | ||
71 | - if len(sortby) != 0 { | ||
72 | - if len(sortby) == len(order) { | ||
73 | - // 1) for each sort field, there is an associated order | ||
74 | - for i, v := range sortby { | ||
75 | - orderby := "" | ||
76 | - if order[i] == "desc" { | ||
77 | - orderby = "-" + v | ||
78 | - } else if order[i] == "asc" { | ||
79 | - orderby = v | ||
80 | - } else { | ||
81 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
82 | - } | ||
83 | - sortFields = append(sortFields, orderby) | ||
84 | - } | ||
85 | - qs = qs.OrderBy(sortFields...) | ||
86 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
87 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
88 | - for _, v := range sortby { | ||
89 | - orderby := "" | ||
90 | - if order[0] == "desc" { | ||
91 | - orderby = "-" + v | ||
92 | - } else if order[0] == "asc" { | ||
93 | - orderby = v | ||
94 | - } else { | ||
95 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
96 | - } | ||
97 | - sortFields = append(sortFields, orderby) | ||
98 | - } | ||
99 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
100 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
101 | - } | ||
102 | - } else { | ||
103 | - if len(order) != 0 { | ||
104 | - return nil, errors.New("Error: unused 'order' fields") | ||
105 | - } | ||
106 | - } | ||
107 | - | ||
108 | - var l []BonusPoint | ||
109 | - qs = qs.OrderBy(sortFields...) | ||
110 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
111 | - if len(fields) == 0 { | ||
112 | - for _, v := range l { | ||
113 | - ml = append(ml, v) | ||
114 | - } | ||
115 | - } else { | ||
116 | - // trim unused fields | ||
117 | - for _, v := range l { | ||
118 | - m := make(map[string]interface{}) | ||
119 | - val := reflect.ValueOf(v) | ||
120 | - for _, fname := range fields { | ||
121 | - m[fname] = val.FieldByName(fname).Interface() | ||
122 | - } | ||
123 | - ml = append(ml, m) | ||
124 | - } | ||
125 | - } | ||
126 | - return ml, nil | ||
127 | - } | ||
128 | - return nil, err | ||
129 | -} | ||
130 | - | ||
131 | -// UpdateBonusPoint updates BonusPoint by Id and returns error if | ||
132 | -// the record to be updated doesn't exist | ||
133 | -func UpdateBonusPointById(m *BonusPoint) (err error) { | ||
134 | - o := orm.NewOrm() | ||
135 | - v := BonusPoint{Id: m.Id} | ||
136 | - // ascertain id exists in the database | ||
137 | - if err = o.Read(&v); err == nil { | ||
138 | - var num int64 | ||
139 | - if num, err = o.Update(m); err == nil { | ||
140 | - fmt.Println("Number of records updated in database:", num) | ||
141 | - } | ||
142 | - } | ||
143 | - return | ||
144 | -} | ||
145 | - | ||
146 | -// DeleteBonusPoint deletes BonusPoint by Id and returns error if | ||
147 | -// the record to be deleted doesn't exist | ||
148 | -func DeleteBonusPoint(id int) (err error) { | ||
149 | - o := orm.NewOrm() | ||
150 | - v := BonusPoint{Id: id} | ||
151 | - // ascertain id exists in the database | ||
152 | - if err = o.Read(&v); err == nil { | ||
153 | - var num int64 | ||
154 | - if num, err = o.Delete(&BonusPoint{Id: id}); err == nil { | ||
155 | - fmt.Println("Number of records deleted in database:", num) | ||
156 | - } | ||
157 | - } | ||
158 | - return | ||
159 | -} |
models/bulletin.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Bulletin struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - Title string `orm:"column(title);size(2000);null" description:"标题"` | ||
16 | - Content string `orm:"column(content);null" description:"内容"` | ||
17 | - Cover string `orm:"column(cover);size(255);null" description:"封面地址"` | ||
18 | - W int `orm:"column(w);null" description:"宽"` | ||
19 | - H int `orm:"column(h);null" description:"高"` | ||
20 | - Type int8 `orm:"column(type);null" description:"公告类型(0图+跳转链接、1链接)"` | ||
21 | - Receiver string `orm:"column(receiver);null" description:"接收者"` | ||
22 | - QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关"` | ||
23 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
24 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
25 | - AllowClose int8 `orm:"column(allowClose);null" description:"允许关闭公告(0允许,1禁止)"` | ||
26 | - CompanyId int `orm:"column(company_id);null" description:"公司Id"` | ||
27 | - Status uint8 `orm:"column(status)" description:"状态 0-下架 1- 上架"` | ||
28 | -} | ||
29 | - | ||
30 | -func (t *Bulletin) TableName() string { | ||
31 | - return "bulletin" | ||
32 | -} | ||
33 | - | ||
34 | -func init() { | ||
35 | - orm.RegisterModel(new(Bulletin)) | ||
36 | -} | ||
37 | - | ||
38 | -// AddBulletin insert a new Bulletin into database and returns | ||
39 | -// last inserted Id on success. | ||
40 | -func AddBulletin(m *Bulletin) (id int64, err error) { | ||
41 | - o := orm.NewOrm() | ||
42 | - id, err = o.Insert(m) | ||
43 | - return | ||
44 | -} | ||
45 | - | ||
46 | -// GetBulletinById retrieves Bulletin by Id. Returns error if | ||
47 | -// Id doesn't exist | ||
48 | -func GetBulletinById(id int) (v *Bulletin, err error) { | ||
49 | - o := orm.NewOrm() | ||
50 | - v = &Bulletin{Id: id} | ||
51 | - if err = o.Read(v); err == nil { | ||
52 | - return v, nil | ||
53 | - } | ||
54 | - return nil, err | ||
55 | -} | ||
56 | - | ||
57 | -// GetAllBulletin retrieves all Bulletin matches certain condition. Returns empty list if | ||
58 | -// no records exist | ||
59 | -func GetAllBulletin(query map[string]string, fields []string, sortby []string, order []string, | ||
60 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
61 | - o := orm.NewOrm() | ||
62 | - qs := o.QueryTable(new(Bulletin)) | ||
63 | - // query k=v | ||
64 | - for k, v := range query { | ||
65 | - // rewrite dot-notation to Object__Attribute | ||
66 | - k = strings.Replace(k, ".", "__", -1) | ||
67 | - if strings.Contains(k, "isnull") { | ||
68 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
69 | - } else { | ||
70 | - qs = qs.Filter(k, v) | ||
71 | - } | ||
72 | - } | ||
73 | - // order by: | ||
74 | - var sortFields []string | ||
75 | - if len(sortby) != 0 { | ||
76 | - if len(sortby) == len(order) { | ||
77 | - // 1) for each sort field, there is an associated order | ||
78 | - for i, v := range sortby { | ||
79 | - orderby := "" | ||
80 | - if order[i] == "desc" { | ||
81 | - orderby = "-" + v | ||
82 | - } else if order[i] == "asc" { | ||
83 | - orderby = v | ||
84 | - } else { | ||
85 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
86 | - } | ||
87 | - sortFields = append(sortFields, orderby) | ||
88 | - } | ||
89 | - qs = qs.OrderBy(sortFields...) | ||
90 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
91 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
92 | - for _, v := range sortby { | ||
93 | - orderby := "" | ||
94 | - if order[0] == "desc" { | ||
95 | - orderby = "-" + v | ||
96 | - } else if order[0] == "asc" { | ||
97 | - orderby = v | ||
98 | - } else { | ||
99 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
100 | - } | ||
101 | - sortFields = append(sortFields, orderby) | ||
102 | - } | ||
103 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
104 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
105 | - } | ||
106 | - } else { | ||
107 | - if len(order) != 0 { | ||
108 | - return nil, errors.New("Error: unused 'order' fields") | ||
109 | - } | ||
110 | - } | ||
111 | - | ||
112 | - var l []Bulletin | ||
113 | - qs = qs.OrderBy(sortFields...) | ||
114 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
115 | - if len(fields) == 0 { | ||
116 | - for _, v := range l { | ||
117 | - ml = append(ml, v) | ||
118 | - } | ||
119 | - } else { | ||
120 | - // trim unused fields | ||
121 | - for _, v := range l { | ||
122 | - m := make(map[string]interface{}) | ||
123 | - val := reflect.ValueOf(v) | ||
124 | - for _, fname := range fields { | ||
125 | - m[fname] = val.FieldByName(fname).Interface() | ||
126 | - } | ||
127 | - ml = append(ml, m) | ||
128 | - } | ||
129 | - } | ||
130 | - return ml, nil | ||
131 | - } | ||
132 | - return nil, err | ||
133 | -} | ||
134 | - | ||
135 | -// UpdateBulletin updates Bulletin by Id and returns error if | ||
136 | -// the record to be updated doesn't exist | ||
137 | -func UpdateBulletinById(m *Bulletin) (err error) { | ||
138 | - o := orm.NewOrm() | ||
139 | - v := Bulletin{Id: m.Id} | ||
140 | - // ascertain id exists in the database | ||
141 | - if err = o.Read(&v); err == nil { | ||
142 | - var num int64 | ||
143 | - if num, err = o.Update(m); err == nil { | ||
144 | - fmt.Println("Number of records updated in database:", num) | ||
145 | - } | ||
146 | - } | ||
147 | - return | ||
148 | -} | ||
149 | - | ||
150 | -// DeleteBulletin deletes Bulletin by Id and returns error if | ||
151 | -// the record to be deleted doesn't exist | ||
152 | -func DeleteBulletin(id int) (err error) { | ||
153 | - o := orm.NewOrm() | ||
154 | - v := Bulletin{Id: id} | ||
155 | - // ascertain id exists in the database | ||
156 | - if err = o.Read(&v); err == nil { | ||
157 | - var num int64 | ||
158 | - if num, err = o.Delete(&Bulletin{Id: id}); err == nil { | ||
159 | - fmt.Println("Number of records deleted in database:", num) | ||
160 | - } | ||
161 | - } | ||
162 | - return | ||
163 | -} |
models/bulletin_question.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type BulletinQuestion struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - BulletinId int `orm:"column(bulletin_id);null" description:"公告id"` | ||
16 | - Type int8 `orm:"column(type);null" description:"类型:0-单选,1-多选"` | ||
17 | - Title string `orm:"column(title);size(2000);null" description:"标题"` | ||
18 | - Content string `orm:"column(content);size(2000);null" description:"内容"` | ||
19 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
20 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *BulletinQuestion) TableName() string { | ||
24 | - return "bulletin_question" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(BulletinQuestion)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddBulletinQuestion insert a new BulletinQuestion into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddBulletinQuestion(m *BulletinQuestion) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetBulletinQuestionById retrieves BulletinQuestion by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &BulletinQuestion{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllBulletinQuestion retrieves all BulletinQuestion matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllBulletinQuestion(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(BulletinQuestion)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []BulletinQuestion | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := BulletinQuestion{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteBulletinQuestion deletes BulletinQuestion by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteBulletinQuestion(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := BulletinQuestion{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&BulletinQuestion{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
models/bulletin_question_answer.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type BulletinQuestionAnswer struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - Answer string `orm:"column(answer);null" description:"答案"` | ||
16 | - BulletinId int `orm:"column(bulletin_id);null" description:"公告id"` | ||
17 | - BulletinQuestionId int `orm:"column(bulletin_question_id);null" description:"公告问题id"` | ||
18 | - Uid int64 `orm:"column(uid);null" description:"用户id"` | ||
19 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
20 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *BulletinQuestionAnswer) TableName() string { | ||
24 | - return "bulletin_question_answer" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(BulletinQuestionAnswer)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddBulletinQuestionAnswer insert a new BulletinQuestionAnswer into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddBulletinQuestionAnswer(m *BulletinQuestionAnswer) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetBulletinQuestionAnswerById retrieves BulletinQuestionAnswer by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetBulletinQuestionAnswerById(id int) (v *BulletinQuestionAnswer, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &BulletinQuestionAnswer{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllBulletinQuestionAnswer retrieves all BulletinQuestionAnswer matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllBulletinQuestionAnswer(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(BulletinQuestionAnswer)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []BulletinQuestionAnswer | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateBulletinQuestionAnswer updates BulletinQuestionAnswer by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateBulletinQuestionAnswerById(m *BulletinQuestionAnswer) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := BulletinQuestionAnswer{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteBulletinQuestionAnswer deletes BulletinQuestionAnswer by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteBulletinQuestionAnswer(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := BulletinQuestionAnswer{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&BulletinQuestionAnswer{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
models/cfg_app_version.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type CfgAppVersion struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - DeviceType int8 `orm:"column(device_type);null" description:"设备类型 (0 ios 1android)"` | ||
16 | - VersionName string `orm:"column(version_name);size(255)" description:"版本名"` | ||
17 | - VersionNo int `orm:"column(version_no)" description:"版本号"` | ||
18 | - VersionState int8 `orm:"column(version_state)" description:"版本状态(0正常 1危险)"` | ||
19 | - Title string `orm:"column(title);size(255)" description:"版本标题"` | ||
20 | - Content string `orm:"column(content);size(500)" description:"更新的内容"` | ||
21 | - DownloadPage string `orm:"column(download_page);size(255);null" description:"下载页"` | ||
22 | - DownloadFile string `orm:"column(download_file);size(255)" description:"文件下载页"` | ||
23 | - CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now"` | ||
24 | - Enabled int8 `orm:"column(enabled);null" description:"是否有效"` | ||
25 | - AdminId int `orm:"column(admin_id)" description:"操作人员"` | ||
26 | - UpdateTime time.Time `orm:"column(update_time);type(timestamp);auto_now_add" description:"更新时间"` | ||
27 | - Channel string `orm:"column(channel);size(255)" description:"当前渠道 0_AppStore、1_fir平台、2_华为、3_小米、4_魅族、5_oppo、6_vivo、7_360、8_百度、9_应用宝、10_其他(使用应用宝地址)"` | ||
28 | - Type int8 `orm:"column(type);null" description:"0为手机 1为平板 终端类型"` | ||
29 | -} | ||
30 | - | ||
31 | -func (t *CfgAppVersion) TableName() string { | ||
32 | - return "cfg_app_version" | ||
33 | -} | ||
34 | - | ||
35 | -func init() { | ||
36 | - orm.RegisterModel(new(CfgAppVersion)) | ||
37 | -} | ||
38 | - | ||
39 | -// AddCfgAppVersion insert a new CfgAppVersion into database and returns | ||
40 | -// last inserted Id on success. | ||
41 | -func AddCfgAppVersion(m *CfgAppVersion) (id int64, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - id, err = o.Insert(m) | ||
44 | - return | ||
45 | -} | ||
46 | - | ||
47 | -// GetCfgAppVersionById retrieves CfgAppVersion by Id. Returns error if | ||
48 | -// Id doesn't exist | ||
49 | -func GetCfgAppVersionById(id int) (v *CfgAppVersion, err error) { | ||
50 | - o := orm.NewOrm() | ||
51 | - v = &CfgAppVersion{Id: id} | ||
52 | - if err = o.Read(v); err == nil { | ||
53 | - return v, nil | ||
54 | - } | ||
55 | - return nil, err | ||
56 | -} | ||
57 | - | ||
58 | -// GetAllCfgAppVersion retrieves all CfgAppVersion matches certain condition. Returns empty list if | ||
59 | -// no records exist | ||
60 | -func GetAllCfgAppVersion(query map[string]string, fields []string, sortby []string, order []string, | ||
61 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
62 | - o := orm.NewOrm() | ||
63 | - qs := o.QueryTable(new(CfgAppVersion)) | ||
64 | - // query k=v | ||
65 | - for k, v := range query { | ||
66 | - // rewrite dot-notation to Object__Attribute | ||
67 | - k = strings.Replace(k, ".", "__", -1) | ||
68 | - if strings.Contains(k, "isnull") { | ||
69 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
70 | - } else { | ||
71 | - qs = qs.Filter(k, v) | ||
72 | - } | ||
73 | - } | ||
74 | - // order by: | ||
75 | - var sortFields []string | ||
76 | - if len(sortby) != 0 { | ||
77 | - if len(sortby) == len(order) { | ||
78 | - // 1) for each sort field, there is an associated order | ||
79 | - for i, v := range sortby { | ||
80 | - orderby := "" | ||
81 | - if order[i] == "desc" { | ||
82 | - orderby = "-" + v | ||
83 | - } else if order[i] == "asc" { | ||
84 | - orderby = v | ||
85 | - } else { | ||
86 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
87 | - } | ||
88 | - sortFields = append(sortFields, orderby) | ||
89 | - } | ||
90 | - qs = qs.OrderBy(sortFields...) | ||
91 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
92 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
93 | - for _, v := range sortby { | ||
94 | - orderby := "" | ||
95 | - if order[0] == "desc" { | ||
96 | - orderby = "-" + v | ||
97 | - } else if order[0] == "asc" { | ||
98 | - orderby = v | ||
99 | - } else { | ||
100 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
101 | - } | ||
102 | - sortFields = append(sortFields, orderby) | ||
103 | - } | ||
104 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
105 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
106 | - } | ||
107 | - } else { | ||
108 | - if len(order) != 0 { | ||
109 | - return nil, errors.New("Error: unused 'order' fields") | ||
110 | - } | ||
111 | - } | ||
112 | - | ||
113 | - var l []CfgAppVersion | ||
114 | - qs = qs.OrderBy(sortFields...) | ||
115 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
116 | - if len(fields) == 0 { | ||
117 | - for _, v := range l { | ||
118 | - ml = append(ml, v) | ||
119 | - } | ||
120 | - } else { | ||
121 | - // trim unused fields | ||
122 | - for _, v := range l { | ||
123 | - m := make(map[string]interface{}) | ||
124 | - val := reflect.ValueOf(v) | ||
125 | - for _, fname := range fields { | ||
126 | - m[fname] = val.FieldByName(fname).Interface() | ||
127 | - } | ||
128 | - ml = append(ml, m) | ||
129 | - } | ||
130 | - } | ||
131 | - return ml, nil | ||
132 | - } | ||
133 | - return nil, err | ||
134 | -} | ||
135 | - | ||
136 | -// UpdateCfgAppVersion updates CfgAppVersion by Id and returns error if | ||
137 | -// the record to be updated doesn't exist | ||
138 | -func UpdateCfgAppVersionById(m *CfgAppVersion) (err error) { | ||
139 | - o := orm.NewOrm() | ||
140 | - v := CfgAppVersion{Id: m.Id} | ||
141 | - // ascertain id exists in the database | ||
142 | - if err = o.Read(&v); err == nil { | ||
143 | - var num int64 | ||
144 | - if num, err = o.Update(m); err == nil { | ||
145 | - fmt.Println("Number of records updated in database:", num) | ||
146 | - } | ||
147 | - } | ||
148 | - return | ||
149 | -} | ||
150 | - | ||
151 | -// DeleteCfgAppVersion deletes CfgAppVersion by Id and returns error if | ||
152 | -// the record to be deleted doesn't exist | ||
153 | -func DeleteCfgAppVersion(id int) (err error) { | ||
154 | - o := orm.NewOrm() | ||
155 | - v := CfgAppVersion{Id: id} | ||
156 | - // ascertain id exists in the database | ||
157 | - if err = o.Read(&v); err == nil { | ||
158 | - var num int64 | ||
159 | - if num, err = o.Delete(&CfgAppVersion{Id: id}); err == nil { | ||
160 | - fmt.Println("Number of records deleted in database:", num) | ||
161 | - } | ||
162 | - } | ||
163 | - return | ||
164 | -} | ||
165 | - | ||
166 | -func GetCfgAppVersion(versionNo, channel int) (v *CfgAppVersion, err error) { | ||
167 | - o := orm.NewOrm() | ||
168 | - sql := `select * from cfg_app_version where version_no =? and channel =? and enabled=1` | ||
169 | - if err = o.Raw(sql, versionNo, channel).QueryRow(&v); err == nil { | ||
170 | - return v, nil | ||
171 | - } | ||
172 | - return nil, err | ||
173 | -} |
models/cfg_attr.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type CfgAttr struct { | ||
14 | - Id int `orm:"column(id);auto" description:"主键ID"` | ||
15 | - CompanyId int `orm:"column(company_id)" description:"公司Id"` | ||
16 | - Name string `orm:"column(name);size(200)" description:"名称"` | ||
17 | - Sort uint `orm:"column(sort)" description:"排序"` | ||
18 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
19 | - Enabled int `orm:"column(enabled)"` | ||
20 | -} | ||
21 | - | ||
22 | -func (t *CfgAttr) TableName() string { | ||
23 | - return "cfg_attr" | ||
24 | -} | ||
25 | - | ||
26 | -func init() { | ||
27 | - orm.RegisterModel(new(CfgAttr)) | ||
28 | -} | ||
29 | - | ||
30 | -// AddCfgAttr insert a new CfgAttr into database and returns | ||
31 | -// last inserted Id on success. | ||
32 | -func AddCfgAttr(m *CfgAttr) (id int64, err error) { | ||
33 | - o := orm.NewOrm() | ||
34 | - id, err = o.Insert(m) | ||
35 | - return | ||
36 | -} | ||
37 | - | ||
38 | -// GetCfgAttrById retrieves CfgAttr by Id. Returns error if | ||
39 | -// Id doesn't exist | ||
40 | -func GetCfgAttrById(id int) (v *CfgAttr, err error) { | ||
41 | - o := orm.NewOrm() | ||
42 | - v = &CfgAttr{Id: id} | ||
43 | - if err = o.Read(v); err == nil { | ||
44 | - return v, nil | ||
45 | - } | ||
46 | - return nil, err | ||
47 | -} | ||
48 | - | ||
49 | -// GetAllCfgAttr retrieves all CfgAttr matches certain condition. Returns empty list if | ||
50 | -// no records exist | ||
51 | -func GetAllCfgAttr(query map[string]string, fields []string, sortby []string, order []string, | ||
52 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
53 | - o := orm.NewOrm() | ||
54 | - qs := o.QueryTable(new(CfgAttr)) | ||
55 | - // query k=v | ||
56 | - for k, v := range query { | ||
57 | - // rewrite dot-notation to Object__Attribute | ||
58 | - k = strings.Replace(k, ".", "__", -1) | ||
59 | - if strings.Contains(k, "isnull") { | ||
60 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
61 | - } else { | ||
62 | - qs = qs.Filter(k, v) | ||
63 | - } | ||
64 | - } | ||
65 | - // order by: | ||
66 | - var sortFields []string | ||
67 | - if len(sortby) != 0 { | ||
68 | - if len(sortby) == len(order) { | ||
69 | - // 1) for each sort field, there is an associated order | ||
70 | - for i, v := range sortby { | ||
71 | - orderby := "" | ||
72 | - if order[i] == "desc" { | ||
73 | - orderby = "-" + v | ||
74 | - } else if order[i] == "asc" { | ||
75 | - orderby = v | ||
76 | - } else { | ||
77 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
78 | - } | ||
79 | - sortFields = append(sortFields, orderby) | ||
80 | - } | ||
81 | - qs = qs.OrderBy(sortFields...) | ||
82 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
83 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
84 | - for _, v := range sortby { | ||
85 | - orderby := "" | ||
86 | - if order[0] == "desc" { | ||
87 | - orderby = "-" + v | ||
88 | - } else if order[0] == "asc" { | ||
89 | - orderby = v | ||
90 | - } else { | ||
91 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
92 | - } | ||
93 | - sortFields = append(sortFields, orderby) | ||
94 | - } | ||
95 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
96 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
97 | - } | ||
98 | - } else { | ||
99 | - if len(order) != 0 { | ||
100 | - return nil, errors.New("Error: unused 'order' fields") | ||
101 | - } | ||
102 | - } | ||
103 | - | ||
104 | - var l []CfgAttr | ||
105 | - qs = qs.OrderBy(sortFields...) | ||
106 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
107 | - if len(fields) == 0 { | ||
108 | - for _, v := range l { | ||
109 | - ml = append(ml, v) | ||
110 | - } | ||
111 | - } else { | ||
112 | - // trim unused fields | ||
113 | - for _, v := range l { | ||
114 | - m := make(map[string]interface{}) | ||
115 | - val := reflect.ValueOf(v) | ||
116 | - for _, fname := range fields { | ||
117 | - m[fname] = val.FieldByName(fname).Interface() | ||
118 | - } | ||
119 | - ml = append(ml, m) | ||
120 | - } | ||
121 | - } | ||
122 | - return ml, nil | ||
123 | - } | ||
124 | - return nil, err | ||
125 | -} | ||
126 | - | ||
127 | -// UpdateCfgAttr updates CfgAttr by Id and returns error if | ||
128 | -// the record to be updated doesn't exist | ||
129 | -func UpdateCfgAttrById(m *CfgAttr) (err error) { | ||
130 | - o := orm.NewOrm() | ||
131 | - v := CfgAttr{Id: m.Id} | ||
132 | - // ascertain id exists in the database | ||
133 | - if err = o.Read(&v); err == nil { | ||
134 | - var num int64 | ||
135 | - if num, err = o.Update(m); err == nil { | ||
136 | - fmt.Println("Number of records updated in database:", num) | ||
137 | - } | ||
138 | - } | ||
139 | - return | ||
140 | -} | ||
141 | - | ||
142 | -// DeleteCfgAttr deletes CfgAttr by Id and returns error if | ||
143 | -// the record to be deleted doesn't exist | ||
144 | -func DeleteCfgAttr(id int) (err error) { | ||
145 | - o := orm.NewOrm() | ||
146 | - v := CfgAttr{Id: id} | ||
147 | - // ascertain id exists in the database | ||
148 | - if err = o.Read(&v); err == nil { | ||
149 | - var num int64 | ||
150 | - if num, err = o.Delete(&CfgAttr{Id: id}); err == nil { | ||
151 | - fmt.Println("Number of records deleted in database:", num) | ||
152 | - } | ||
153 | - } | ||
154 | - return | ||
155 | -} |
models/cfg_client.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type CfgClient struct { | ||
14 | - Id int `orm:"column(id);auto" description:"主键ID"` | ||
15 | - ClientId string `orm:"column(client_id);size(32)" description:"客户端ID"` | ||
16 | - ClientSecret string `orm:"column(client_secret);size(128);null" description:"客户端密钥"` | ||
17 | - CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now" description:"创建时间"` | ||
18 | - Enabled int8 `orm:"column(enabled)" description:"是否有效"` | ||
19 | -} | ||
20 | - | ||
21 | -func (t *CfgClient) TableName() string { | ||
22 | - return "cfg_client" | ||
23 | -} | ||
24 | - | ||
25 | -func init() { | ||
26 | - orm.RegisterModel(new(CfgClient)) | ||
27 | -} | ||
28 | - | ||
29 | -// AddCfgClient insert a new CfgClient into database and returns | ||
30 | -// last inserted Id on success. | ||
31 | -func AddCfgClient(m *CfgClient) (id int64, err error) { | ||
32 | - o := orm.NewOrm() | ||
33 | - id, err = o.Insert(m) | ||
34 | - return | ||
35 | -} | ||
36 | - | ||
37 | -// GetCfgClientById retrieves CfgClient by Id. Returns error if | ||
38 | -// Id doesn't exist | ||
39 | -func GetCfgClientById(id int) (v *CfgClient, err error) { | ||
40 | - o := orm.NewOrm() | ||
41 | - v = &CfgClient{Id: id} | ||
42 | - if err = o.Read(v); err == nil { | ||
43 | - return v, nil | ||
44 | - } | ||
45 | - return nil, err | ||
46 | -} | ||
47 | - | ||
48 | -// GetAllCfgClient retrieves all CfgClient matches certain condition. Returns empty list if | ||
49 | -// no records exist | ||
50 | -func GetAllCfgClient(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | - o := orm.NewOrm() | ||
53 | - qs := o.QueryTable(new(CfgClient)) | ||
54 | - // query k=v | ||
55 | - for k, v := range query { | ||
56 | - // rewrite dot-notation to Object__Attribute | ||
57 | - k = strings.Replace(k, ".", "__", -1) | ||
58 | - if strings.Contains(k, "isnull") { | ||
59 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | - } else { | ||
61 | - qs = qs.Filter(k, v) | ||
62 | - } | ||
63 | - } | ||
64 | - // order by: | ||
65 | - var sortFields []string | ||
66 | - if len(sortby) != 0 { | ||
67 | - if len(sortby) == len(order) { | ||
68 | - // 1) for each sort field, there is an associated order | ||
69 | - for i, v := range sortby { | ||
70 | - orderby := "" | ||
71 | - if order[i] == "desc" { | ||
72 | - orderby = "-" + v | ||
73 | - } else if order[i] == "asc" { | ||
74 | - orderby = v | ||
75 | - } else { | ||
76 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | - } | ||
78 | - sortFields = append(sortFields, orderby) | ||
79 | - } | ||
80 | - qs = qs.OrderBy(sortFields...) | ||
81 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | - for _, v := range sortby { | ||
84 | - orderby := "" | ||
85 | - if order[0] == "desc" { | ||
86 | - orderby = "-" + v | ||
87 | - } else if order[0] == "asc" { | ||
88 | - orderby = v | ||
89 | - } else { | ||
90 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | - } | ||
92 | - sortFields = append(sortFields, orderby) | ||
93 | - } | ||
94 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | - } | ||
97 | - } else { | ||
98 | - if len(order) != 0 { | ||
99 | - return nil, errors.New("Error: unused 'order' fields") | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - var l []CfgClient | ||
104 | - qs = qs.OrderBy(sortFields...) | ||
105 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | - if len(fields) == 0 { | ||
107 | - for _, v := range l { | ||
108 | - ml = append(ml, v) | ||
109 | - } | ||
110 | - } else { | ||
111 | - // trim unused fields | ||
112 | - for _, v := range l { | ||
113 | - m := make(map[string]interface{}) | ||
114 | - val := reflect.ValueOf(v) | ||
115 | - for _, fname := range fields { | ||
116 | - m[fname] = val.FieldByName(fname).Interface() | ||
117 | - } | ||
118 | - ml = append(ml, m) | ||
119 | - } | ||
120 | - } | ||
121 | - return ml, nil | ||
122 | - } | ||
123 | - return nil, err | ||
124 | -} | ||
125 | - | ||
126 | -// UpdateCfgClient updates CfgClient by Id and returns error if | ||
127 | -// the record to be updated doesn't exist | ||
128 | -func UpdateCfgClientById(m *CfgClient) (err error) { | ||
129 | - o := orm.NewOrm() | ||
130 | - v := CfgClient{Id: m.Id} | ||
131 | - // ascertain id exists in the database | ||
132 | - if err = o.Read(&v); err == nil { | ||
133 | - var num int64 | ||
134 | - if num, err = o.Update(m); err == nil { | ||
135 | - fmt.Println("Number of records updated in database:", num) | ||
136 | - } | ||
137 | - } | ||
138 | - return | ||
139 | -} | ||
140 | - | ||
141 | -// DeleteCfgClient deletes CfgClient by Id and returns error if | ||
142 | -// the record to be deleted doesn't exist | ||
143 | -func DeleteCfgClient(id int) (err error) { | ||
144 | - o := orm.NewOrm() | ||
145 | - v := CfgClient{Id: id} | ||
146 | - // ascertain id exists in the database | ||
147 | - if err = o.Read(&v); err == nil { | ||
148 | - var num int64 | ||
149 | - if num, err = o.Delete(&CfgClient{Id: id}); err == nil { | ||
150 | - fmt.Println("Number of records deleted in database:", num) | ||
151 | - } | ||
152 | - } | ||
153 | - return | ||
154 | -} | ||
155 | - | ||
156 | -func GetCfgClient(clintId, clientSecret string) (v *CfgClient, err error) { | ||
157 | - o := orm.NewOrm() | ||
158 | - sql := "select * from cfg_client where enabled=1 and client_id=? and client_secret=?" | ||
159 | - if err = o.Raw(sql, clintId, clientSecret).QueryRow(&v); err == nil { | ||
160 | - return v, nil | ||
161 | - } | ||
162 | - return nil, err | ||
163 | -} |
models/cfg_msg.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type CfgMsg struct { | ||
14 | - Id int `orm:"column(id);pk" description:"主键ID"` | ||
15 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
16 | - Title string `orm:"column(title);size(100)" description:"消息标题"` | ||
17 | - Type int `orm:"column(type)" description:"1为某某某代表解决 2为某某某提出 3为某某某申请解决"` | ||
18 | -} | ||
19 | - | ||
20 | -func (t *CfgMsg) TableName() string { | ||
21 | - return "cfg_msg" | ||
22 | -} | ||
23 | - | ||
24 | -func init() { | ||
25 | - orm.RegisterModel(new(CfgMsg)) | ||
26 | -} | ||
27 | - | ||
28 | -// AddCfgMsg insert a new CfgMsg into database and returns | ||
29 | -// last inserted Id on success. | ||
30 | -func AddCfgMsg(m *CfgMsg) (id int64, err error) { | ||
31 | - o := orm.NewOrm() | ||
32 | - id, err = o.Insert(m) | ||
33 | - return | ||
34 | -} | ||
35 | - | ||
36 | -// GetCfgMsgById retrieves CfgMsg by Id. Returns error if | ||
37 | -// Id doesn't exist | ||
38 | -func GetCfgMsgById(id int) (v *CfgMsg, err error) { | ||
39 | - o := orm.NewOrm() | ||
40 | - v = &CfgMsg{Id: id} | ||
41 | - if err = o.Read(v); err == nil { | ||
42 | - return v, nil | ||
43 | - } | ||
44 | - return nil, err | ||
45 | -} | ||
46 | - | ||
47 | -// GetAllCfgMsg retrieves all CfgMsg matches certain condition. Returns empty list if | ||
48 | -// no records exist | ||
49 | -func GetAllCfgMsg(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | - o := orm.NewOrm() | ||
52 | - qs := o.QueryTable(new(CfgMsg)) | ||
53 | - // query k=v | ||
54 | - for k, v := range query { | ||
55 | - // rewrite dot-notation to Object__Attribute | ||
56 | - k = strings.Replace(k, ".", "__", -1) | ||
57 | - if strings.Contains(k, "isnull") { | ||
58 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | - } else { | ||
60 | - qs = qs.Filter(k, v) | ||
61 | - } | ||
62 | - } | ||
63 | - // order by: | ||
64 | - var sortFields []string | ||
65 | - if len(sortby) != 0 { | ||
66 | - if len(sortby) == len(order) { | ||
67 | - // 1) for each sort field, there is an associated order | ||
68 | - for i, v := range sortby { | ||
69 | - orderby := "" | ||
70 | - if order[i] == "desc" { | ||
71 | - orderby = "-" + v | ||
72 | - } else if order[i] == "asc" { | ||
73 | - orderby = v | ||
74 | - } else { | ||
75 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | - } | ||
77 | - sortFields = append(sortFields, orderby) | ||
78 | - } | ||
79 | - qs = qs.OrderBy(sortFields...) | ||
80 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | - for _, v := range sortby { | ||
83 | - orderby := "" | ||
84 | - if order[0] == "desc" { | ||
85 | - orderby = "-" + v | ||
86 | - } else if order[0] == "asc" { | ||
87 | - orderby = v | ||
88 | - } else { | ||
89 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | - } | ||
91 | - sortFields = append(sortFields, orderby) | ||
92 | - } | ||
93 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | - } | ||
96 | - } else { | ||
97 | - if len(order) != 0 { | ||
98 | - return nil, errors.New("Error: unused 'order' fields") | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - var l []CfgMsg | ||
103 | - qs = qs.OrderBy(sortFields...) | ||
104 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | - if len(fields) == 0 { | ||
106 | - for _, v := range l { | ||
107 | - ml = append(ml, v) | ||
108 | - } | ||
109 | - } else { | ||
110 | - // trim unused fields | ||
111 | - for _, v := range l { | ||
112 | - m := make(map[string]interface{}) | ||
113 | - val := reflect.ValueOf(v) | ||
114 | - for _, fname := range fields { | ||
115 | - m[fname] = val.FieldByName(fname).Interface() | ||
116 | - } | ||
117 | - ml = append(ml, m) | ||
118 | - } | ||
119 | - } | ||
120 | - return ml, nil | ||
121 | - } | ||
122 | - return nil, err | ||
123 | -} | ||
124 | - | ||
125 | -// UpdateCfgMsg updates CfgMsg by Id and returns error if | ||
126 | -// the record to be updated doesn't exist | ||
127 | -func UpdateCfgMsgById(m *CfgMsg) (err error) { | ||
128 | - o := orm.NewOrm() | ||
129 | - v := CfgMsg{Id: m.Id} | ||
130 | - // ascertain id exists in the database | ||
131 | - if err = o.Read(&v); err == nil { | ||
132 | - var num int64 | ||
133 | - if num, err = o.Update(m); err == nil { | ||
134 | - fmt.Println("Number of records updated in database:", num) | ||
135 | - } | ||
136 | - } | ||
137 | - return | ||
138 | -} | ||
139 | - | ||
140 | -// DeleteCfgMsg deletes CfgMsg by Id and returns error if | ||
141 | -// the record to be deleted doesn't exist | ||
142 | -func DeleteCfgMsg(id int) (err error) { | ||
143 | - o := orm.NewOrm() | ||
144 | - v := CfgMsg{Id: id} | ||
145 | - // ascertain id exists in the database | ||
146 | - if err = o.Read(&v); err == nil { | ||
147 | - var num int64 | ||
148 | - if num, err = o.Delete(&CfgMsg{Id: id}); err == nil { | ||
149 | - fmt.Println("Number of records deleted in database:", num) | ||
150 | - } | ||
151 | - } | ||
152 | - return | ||
153 | -} |
models/commend.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Commend struct { | ||
14 | - Id int `orm:"column(cid);pk" description:"主键ID"` | ||
15 | - Uid int64 `orm:"column(uid)" description:"用户ID"` | ||
16 | - Username string `orm:"column(username);size(255)" description:"用户名"` | ||
17 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
18 | - QuestionTitle string `orm:"column(questionTitle);size(100)" description:"标题"` | ||
19 | - QuestionId int64 `orm:"column(questionId);null"` | ||
20 | - Way int `orm:"column(way)" description:"0提出问题、1参与解决问题"` | ||
21 | - Company string `orm:"column(company);size(50)" description:"是否已读 0未读,1已读"` | ||
22 | - CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
23 | - Status int8 `orm:"column(status)" description:"状态 1可见 2不可见"` | ||
24 | - CommendationTime time.Time `orm:"column(commendation_time);type(date)" description:"表彰时间"` | ||
25 | -} | ||
26 | - | ||
27 | -func (t *Commend) TableName() string { | ||
28 | - return "commend" | ||
29 | -} | ||
30 | - | ||
31 | -func init() { | ||
32 | - orm.RegisterModel(new(Commend)) | ||
33 | -} | ||
34 | - | ||
35 | -// AddCommend insert a new Commend into database and returns | ||
36 | -// last inserted Id on success. | ||
37 | -func AddCommend(m *Commend) (id int64, err error) { | ||
38 | - o := orm.NewOrm() | ||
39 | - id, err = o.Insert(m) | ||
40 | - return | ||
41 | -} | ||
42 | - | ||
43 | -// GetCommendById retrieves Commend by Id. Returns error if | ||
44 | -// Id doesn't exist | ||
45 | -func GetCommendById(id int) (v *Commend, err error) { | ||
46 | - o := orm.NewOrm() | ||
47 | - v = &Commend{Id: id} | ||
48 | - if err = o.Read(v); err == nil { | ||
49 | - return v, nil | ||
50 | - } | ||
51 | - return nil, err | ||
52 | -} | ||
53 | - | ||
54 | -// GetAllCommend retrieves all Commend matches certain condition. Returns empty list if | ||
55 | -// no records exist | ||
56 | -func GetAllCommend(query map[string]string, fields []string, sortby []string, order []string, | ||
57 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
58 | - o := orm.NewOrm() | ||
59 | - qs := o.QueryTable(new(Commend)) | ||
60 | - // query k=v | ||
61 | - for k, v := range query { | ||
62 | - // rewrite dot-notation to Object__Attribute | ||
63 | - k = strings.Replace(k, ".", "__", -1) | ||
64 | - if strings.Contains(k, "isnull") { | ||
65 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
66 | - } else { | ||
67 | - qs = qs.Filter(k, v) | ||
68 | - } | ||
69 | - } | ||
70 | - // order by: | ||
71 | - var sortFields []string | ||
72 | - if len(sortby) != 0 { | ||
73 | - if len(sortby) == len(order) { | ||
74 | - // 1) for each sort field, there is an associated order | ||
75 | - for i, v := range sortby { | ||
76 | - orderby := "" | ||
77 | - if order[i] == "desc" { | ||
78 | - orderby = "-" + v | ||
79 | - } else if order[i] == "asc" { | ||
80 | - orderby = v | ||
81 | - } else { | ||
82 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
83 | - } | ||
84 | - sortFields = append(sortFields, orderby) | ||
85 | - } | ||
86 | - qs = qs.OrderBy(sortFields...) | ||
87 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
88 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
89 | - for _, v := range sortby { | ||
90 | - orderby := "" | ||
91 | - if order[0] == "desc" { | ||
92 | - orderby = "-" + v | ||
93 | - } else if order[0] == "asc" { | ||
94 | - orderby = v | ||
95 | - } else { | ||
96 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
97 | - } | ||
98 | - sortFields = append(sortFields, orderby) | ||
99 | - } | ||
100 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
101 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
102 | - } | ||
103 | - } else { | ||
104 | - if len(order) != 0 { | ||
105 | - return nil, errors.New("Error: unused 'order' fields") | ||
106 | - } | ||
107 | - } | ||
108 | - | ||
109 | - var l []Commend | ||
110 | - qs = qs.OrderBy(sortFields...) | ||
111 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
112 | - if len(fields) == 0 { | ||
113 | - for _, v := range l { | ||
114 | - ml = append(ml, v) | ||
115 | - } | ||
116 | - } else { | ||
117 | - // trim unused fields | ||
118 | - for _, v := range l { | ||
119 | - m := make(map[string]interface{}) | ||
120 | - val := reflect.ValueOf(v) | ||
121 | - for _, fname := range fields { | ||
122 | - m[fname] = val.FieldByName(fname).Interface() | ||
123 | - } | ||
124 | - ml = append(ml, m) | ||
125 | - } | ||
126 | - } | ||
127 | - return ml, nil | ||
128 | - } | ||
129 | - return nil, err | ||
130 | -} | ||
131 | - | ||
132 | -// UpdateCommend updates Commend by Id and returns error if | ||
133 | -// the record to be updated doesn't exist | ||
134 | -func UpdateCommendById(m *Commend) (err error) { | ||
135 | - o := orm.NewOrm() | ||
136 | - v := Commend{Id: m.Id} | ||
137 | - // ascertain id exists in the database | ||
138 | - if err = o.Read(&v); err == nil { | ||
139 | - var num int64 | ||
140 | - if num, err = o.Update(m); err == nil { | ||
141 | - fmt.Println("Number of records updated in database:", num) | ||
142 | - } | ||
143 | - } | ||
144 | - return | ||
145 | -} | ||
146 | - | ||
147 | -// DeleteCommend deletes Commend by Id and returns error if | ||
148 | -// the record to be deleted doesn't exist | ||
149 | -func DeleteCommend(id int) (err error) { | ||
150 | - o := orm.NewOrm() | ||
151 | - v := Commend{Id: id} | ||
152 | - // ascertain id exists in the database | ||
153 | - if err = o.Read(&v); err == nil { | ||
154 | - var num int64 | ||
155 | - if num, err = o.Delete(&Commend{Id: id}); err == nil { | ||
156 | - fmt.Println("Number of records deleted in database:", num) | ||
157 | - } | ||
158 | - } | ||
159 | - return | ||
160 | -} |
models/comment.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Comment struct { | ||
14 | - Id int `orm:"column(cid);pk"` | ||
15 | - Uid int64 `orm:"column(uid);null"` | ||
16 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
17 | - Content string `orm:"column(content)"` | ||
18 | - PageView int `orm:"column(pageView);null" description:"浏览总数"` | ||
19 | - CommentTotal int `orm:"column(commentTotal);null" description:"评论总数"` | ||
20 | - SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"` | ||
21 | - Type int `orm:"column(type);null" description:"0问题、1评论、2方案"` | ||
22 | - Id_RENAME int64 `orm:"column(id);null" description:"对应的ID"` | ||
23 | -} | ||
24 | - | ||
25 | -func (t *Comment) TableName() string { | ||
26 | - return "comment" | ||
27 | -} | ||
28 | - | ||
29 | -func init() { | ||
30 | - orm.RegisterModel(new(Comment)) | ||
31 | -} | ||
32 | - | ||
33 | -// AddComment insert a new Comment into database and returns | ||
34 | -// last inserted Id on success. | ||
35 | -func AddComment(m *Comment) (id int64, err error) { | ||
36 | - o := orm.NewOrm() | ||
37 | - id, err = o.Insert(m) | ||
38 | - return | ||
39 | -} | ||
40 | - | ||
41 | -// GetCommentById retrieves Comment by Id. Returns error if | ||
42 | -// Id doesn't exist | ||
43 | -func GetCommentById(id int) (v *Comment, err error) { | ||
44 | - o := orm.NewOrm() | ||
45 | - v = &Comment{Id: id} | ||
46 | - if err = o.Read(v); err == nil { | ||
47 | - return v, nil | ||
48 | - } | ||
49 | - return nil, err | ||
50 | -} | ||
51 | - | ||
52 | -// GetAllComment retrieves all Comment matches certain condition. Returns empty list if | ||
53 | -// no records exist | ||
54 | -func GetAllComment(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | - o := orm.NewOrm() | ||
57 | - qs := o.QueryTable(new(Comment)) | ||
58 | - // query k=v | ||
59 | - for k, v := range query { | ||
60 | - // rewrite dot-notation to Object__Attribute | ||
61 | - k = strings.Replace(k, ".", "__", -1) | ||
62 | - if strings.Contains(k, "isnull") { | ||
63 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | - } else { | ||
65 | - qs = qs.Filter(k, v) | ||
66 | - } | ||
67 | - } | ||
68 | - // order by: | ||
69 | - var sortFields []string | ||
70 | - if len(sortby) != 0 { | ||
71 | - if len(sortby) == len(order) { | ||
72 | - // 1) for each sort field, there is an associated order | ||
73 | - for i, v := range sortby { | ||
74 | - orderby := "" | ||
75 | - if order[i] == "desc" { | ||
76 | - orderby = "-" + v | ||
77 | - } else if order[i] == "asc" { | ||
78 | - orderby = v | ||
79 | - } else { | ||
80 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | - } | ||
82 | - sortFields = append(sortFields, orderby) | ||
83 | - } | ||
84 | - qs = qs.OrderBy(sortFields...) | ||
85 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | - for _, v := range sortby { | ||
88 | - orderby := "" | ||
89 | - if order[0] == "desc" { | ||
90 | - orderby = "-" + v | ||
91 | - } else if order[0] == "asc" { | ||
92 | - orderby = v | ||
93 | - } else { | ||
94 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | - } | ||
96 | - sortFields = append(sortFields, orderby) | ||
97 | - } | ||
98 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | - } | ||
101 | - } else { | ||
102 | - if len(order) != 0 { | ||
103 | - return nil, errors.New("Error: unused 'order' fields") | ||
104 | - } | ||
105 | - } | ||
106 | - | ||
107 | - var l []Comment | ||
108 | - qs = qs.OrderBy(sortFields...) | ||
109 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | - if len(fields) == 0 { | ||
111 | - for _, v := range l { | ||
112 | - ml = append(ml, v) | ||
113 | - } | ||
114 | - } else { | ||
115 | - // trim unused fields | ||
116 | - for _, v := range l { | ||
117 | - m := make(map[string]interface{}) | ||
118 | - val := reflect.ValueOf(v) | ||
119 | - for _, fname := range fields { | ||
120 | - m[fname] = val.FieldByName(fname).Interface() | ||
121 | - } | ||
122 | - ml = append(ml, m) | ||
123 | - } | ||
124 | - } | ||
125 | - return ml, nil | ||
126 | - } | ||
127 | - return nil, err | ||
128 | -} | ||
129 | - | ||
130 | -// UpdateComment updates Comment by Id and returns error if | ||
131 | -// the record to be updated doesn't exist | ||
132 | -func UpdateCommentById(m *Comment) (err error) { | ||
133 | - o := orm.NewOrm() | ||
134 | - v := Comment{Id: m.Id} | ||
135 | - // ascertain id exists in the database | ||
136 | - if err = o.Read(&v); err == nil { | ||
137 | - var num int64 | ||
138 | - if num, err = o.Update(m); err == nil { | ||
139 | - fmt.Println("Number of records updated in database:", num) | ||
140 | - } | ||
141 | - } | ||
142 | - return | ||
143 | -} | ||
144 | - | ||
145 | -// DeleteComment deletes Comment by Id and returns error if | ||
146 | -// the record to be deleted doesn't exist | ||
147 | -func DeleteComment(id int) (err error) { | ||
148 | - o := orm.NewOrm() | ||
149 | - v := Comment{Id: id} | ||
150 | - // ascertain id exists in the database | ||
151 | - if err = o.Read(&v); err == nil { | ||
152 | - var num int64 | ||
153 | - if num, err = o.Delete(&Comment{Id: id}); err == nil { | ||
154 | - fmt.Println("Number of records deleted in database:", num) | ||
155 | - } | ||
156 | - } | ||
157 | - return | ||
158 | -} |
models/companies.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Companies struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - Name string `orm:"column(name);size(255)"` | ||
16 | - Username string `orm:"column(username);size(255)"` | ||
17 | - Phone string `orm:"column(phone);size(255)"` | ||
18 | - Status uint8 `orm:"column(status)" description:"状态 1启用 2禁用"` | ||
19 | - CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
20 | -} | ||
21 | - | ||
22 | -func (t *Companies) TableName() string { | ||
23 | - return "companies" | ||
24 | -} | ||
25 | - | ||
26 | -func init() { | ||
27 | - orm.RegisterModel(new(Companies)) | ||
28 | -} | ||
29 | - | ||
30 | -// AddCompanies insert a new Companies into database and returns | ||
31 | -// last inserted Id on success. | ||
32 | -func AddCompanies(m *Companies) (id int64, err error) { | ||
33 | - o := orm.NewOrm() | ||
34 | - id, err = o.Insert(m) | ||
35 | - return | ||
36 | -} | ||
37 | - | ||
38 | -// GetCompaniesById retrieves Companies by Id. Returns error if | ||
39 | -// Id doesn't exist | ||
40 | -func GetCompaniesById(id int) (v *Companies, err error) { | ||
41 | - o := orm.NewOrm() | ||
42 | - v = &Companies{Id: id} | ||
43 | - if err = o.Read(v); err == nil { | ||
44 | - return v, nil | ||
45 | - } | ||
46 | - return nil, err | ||
47 | -} | ||
48 | - | ||
49 | -// GetAllCompanies retrieves all Companies matches certain condition. Returns empty list if | ||
50 | -// no records exist | ||
51 | -func GetAllCompanies(query map[string]string, fields []string, sortby []string, order []string, | ||
52 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
53 | - o := orm.NewOrm() | ||
54 | - qs := o.QueryTable(new(Companies)) | ||
55 | - // query k=v | ||
56 | - for k, v := range query { | ||
57 | - // rewrite dot-notation to Object__Attribute | ||
58 | - k = strings.Replace(k, ".", "__", -1) | ||
59 | - if strings.Contains(k, "isnull") { | ||
60 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
61 | - } else { | ||
62 | - qs = qs.Filter(k, v) | ||
63 | - } | ||
64 | - } | ||
65 | - // order by: | ||
66 | - var sortFields []string | ||
67 | - if len(sortby) != 0 { | ||
68 | - if len(sortby) == len(order) { | ||
69 | - // 1) for each sort field, there is an associated order | ||
70 | - for i, v := range sortby { | ||
71 | - orderby := "" | ||
72 | - if order[i] == "desc" { | ||
73 | - orderby = "-" + v | ||
74 | - } else if order[i] == "asc" { | ||
75 | - orderby = v | ||
76 | - } else { | ||
77 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
78 | - } | ||
79 | - sortFields = append(sortFields, orderby) | ||
80 | - } | ||
81 | - qs = qs.OrderBy(sortFields...) | ||
82 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
83 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
84 | - for _, v := range sortby { | ||
85 | - orderby := "" | ||
86 | - if order[0] == "desc" { | ||
87 | - orderby = "-" + v | ||
88 | - } else if order[0] == "asc" { | ||
89 | - orderby = v | ||
90 | - } else { | ||
91 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
92 | - } | ||
93 | - sortFields = append(sortFields, orderby) | ||
94 | - } | ||
95 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
96 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
97 | - } | ||
98 | - } else { | ||
99 | - if len(order) != 0 { | ||
100 | - return nil, errors.New("Error: unused 'order' fields") | ||
101 | - } | ||
102 | - } | ||
103 | - | ||
104 | - var l []Companies | ||
105 | - qs = qs.OrderBy(sortFields...) | ||
106 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
107 | - if len(fields) == 0 { | ||
108 | - for _, v := range l { | ||
109 | - ml = append(ml, v) | ||
110 | - } | ||
111 | - } else { | ||
112 | - // trim unused fields | ||
113 | - for _, v := range l { | ||
114 | - m := make(map[string]interface{}) | ||
115 | - val := reflect.ValueOf(v) | ||
116 | - for _, fname := range fields { | ||
117 | - m[fname] = val.FieldByName(fname).Interface() | ||
118 | - } | ||
119 | - ml = append(ml, m) | ||
120 | - } | ||
121 | - } | ||
122 | - return ml, nil | ||
123 | - } | ||
124 | - return nil, err | ||
125 | -} | ||
126 | - | ||
127 | -// UpdateCompanies updates Companies by Id and returns error if | ||
128 | -// the record to be updated doesn't exist | ||
129 | -func UpdateCompaniesById(m *Companies) (err error) { | ||
130 | - o := orm.NewOrm() | ||
131 | - v := Companies{Id: m.Id} | ||
132 | - // ascertain id exists in the database | ||
133 | - if err = o.Read(&v); err == nil { | ||
134 | - var num int64 | ||
135 | - if num, err = o.Update(m); err == nil { | ||
136 | - fmt.Println("Number of records updated in database:", num) | ||
137 | - } | ||
138 | - } | ||
139 | - return | ||
140 | -} | ||
141 | - | ||
142 | -// DeleteCompanies deletes Companies by Id and returns error if | ||
143 | -// the record to be deleted doesn't exist | ||
144 | -func DeleteCompanies(id int) (err error) { | ||
145 | - o := orm.NewOrm() | ||
146 | - v := Companies{Id: id} | ||
147 | - // ascertain id exists in the database | ||
148 | - if err = o.Read(&v); err == nil { | ||
149 | - var num int64 | ||
150 | - if num, err = o.Delete(&Companies{Id: id}); err == nil { | ||
151 | - fmt.Println("Number of records deleted in database:", num) | ||
152 | - } | ||
153 | - } | ||
154 | - return | ||
155 | -} |
models/departments.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Departments struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - CompanyId int `orm:"column(company_id)"` | ||
16 | - Name string `orm:"column(name);size(255)"` | ||
17 | - Username string `orm:"column(username);size(255)"` | ||
18 | - Number int `orm:"column(number)"` | ||
19 | - CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
20 | - Enabled uint8 `orm:"column(enabled)" description:"状态 1启用 0禁用"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *Departments) TableName() string { | ||
24 | - return "departments" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(Departments)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddDepartments insert a new Departments into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddDepartments(m *Departments) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetDepartmentsById retrieves Departments by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetDepartmentsById(id int) (v *Departments, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &Departments{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllDepartments retrieves all Departments matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllDepartments(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(Departments)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []Departments | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateDepartments updates Departments by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateDepartmentsById(m *Departments) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := Departments{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteDepartments deletes Departments by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteDepartments(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := Departments{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&Departments{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
models/log_uuid.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type LogUuid struct { | ||
13 | - Id int64 `orm:"column(id);auto" description:"主键ID"` | ||
14 | - Uuid string `orm:"column(uuid);size(128)"` | ||
15 | -} | ||
16 | - | ||
17 | -func (t *LogUuid) TableName() string { | ||
18 | - return "log_uuid" | ||
19 | -} | ||
20 | - | ||
21 | -func init() { | ||
22 | - orm.RegisterModel(new(LogUuid)) | ||
23 | -} | ||
24 | - | ||
25 | -// AddLogUuid insert a new LogUuid into database and returns | ||
26 | -// last inserted Id on success. | ||
27 | -func AddLogUuid(m *LogUuid) (id int64, err error) { | ||
28 | - o := orm.NewOrm() | ||
29 | - id, err = o.Insert(m) | ||
30 | - return | ||
31 | -} | ||
32 | - | ||
33 | -// GetLogUuidById retrieves LogUuid by Id. Returns error if | ||
34 | -// Id doesn't exist | ||
35 | -func GetLogUuidById(id int64) (v *LogUuid, err error) { | ||
36 | - o := orm.NewOrm() | ||
37 | - v = &LogUuid{Id: id} | ||
38 | - if err = o.Read(v); err == nil { | ||
39 | - return v, nil | ||
40 | - } | ||
41 | - return nil, err | ||
42 | -} | ||
43 | - | ||
44 | -// GetAllLogUuid retrieves all LogUuid matches certain condition. Returns empty list if | ||
45 | -// no records exist | ||
46 | -func GetAllLogUuid(query map[string]string, fields []string, sortby []string, order []string, | ||
47 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
48 | - o := orm.NewOrm() | ||
49 | - qs := o.QueryTable(new(LogUuid)) | ||
50 | - // query k=v | ||
51 | - for k, v := range query { | ||
52 | - // rewrite dot-notation to Object__Attribute | ||
53 | - k = strings.Replace(k, ".", "__", -1) | ||
54 | - if strings.Contains(k, "isnull") { | ||
55 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
56 | - } else { | ||
57 | - qs = qs.Filter(k, v) | ||
58 | - } | ||
59 | - } | ||
60 | - // order by: | ||
61 | - var sortFields []string | ||
62 | - if len(sortby) != 0 { | ||
63 | - if len(sortby) == len(order) { | ||
64 | - // 1) for each sort field, there is an associated order | ||
65 | - for i, v := range sortby { | ||
66 | - orderby := "" | ||
67 | - if order[i] == "desc" { | ||
68 | - orderby = "-" + v | ||
69 | - } else if order[i] == "asc" { | ||
70 | - orderby = v | ||
71 | - } else { | ||
72 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
73 | - } | ||
74 | - sortFields = append(sortFields, orderby) | ||
75 | - } | ||
76 | - qs = qs.OrderBy(sortFields...) | ||
77 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
78 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
79 | - for _, v := range sortby { | ||
80 | - orderby := "" | ||
81 | - if order[0] == "desc" { | ||
82 | - orderby = "-" + v | ||
83 | - } else if order[0] == "asc" { | ||
84 | - orderby = v | ||
85 | - } else { | ||
86 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
87 | - } | ||
88 | - sortFields = append(sortFields, orderby) | ||
89 | - } | ||
90 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
91 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
92 | - } | ||
93 | - } else { | ||
94 | - if len(order) != 0 { | ||
95 | - return nil, errors.New("Error: unused 'order' fields") | ||
96 | - } | ||
97 | - } | ||
98 | - | ||
99 | - var l []LogUuid | ||
100 | - qs = qs.OrderBy(sortFields...) | ||
101 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
102 | - if len(fields) == 0 { | ||
103 | - for _, v := range l { | ||
104 | - ml = append(ml, v) | ||
105 | - } | ||
106 | - } else { | ||
107 | - // trim unused fields | ||
108 | - for _, v := range l { | ||
109 | - m := make(map[string]interface{}) | ||
110 | - val := reflect.ValueOf(v) | ||
111 | - for _, fname := range fields { | ||
112 | - m[fname] = val.FieldByName(fname).Interface() | ||
113 | - } | ||
114 | - ml = append(ml, m) | ||
115 | - } | ||
116 | - } | ||
117 | - return ml, nil | ||
118 | - } | ||
119 | - return nil, err | ||
120 | -} | ||
121 | - | ||
122 | -// UpdateLogUuid updates LogUuid by Id and returns error if | ||
123 | -// the record to be updated doesn't exist | ||
124 | -func UpdateLogUuidById(m *LogUuid) (err error) { | ||
125 | - o := orm.NewOrm() | ||
126 | - v := LogUuid{Id: m.Id} | ||
127 | - // ascertain id exists in the database | ||
128 | - if err = o.Read(&v); err == nil { | ||
129 | - var num int64 | ||
130 | - if num, err = o.Update(m); err == nil { | ||
131 | - fmt.Println("Number of records updated in database:", num) | ||
132 | - } | ||
133 | - } | ||
134 | - return | ||
135 | -} | ||
136 | - | ||
137 | -// DeleteLogUuid deletes LogUuid by Id and returns error if | ||
138 | -// the record to be deleted doesn't exist | ||
139 | -func DeleteLogUuid(id int64) (err error) { | ||
140 | - o := orm.NewOrm() | ||
141 | - v := LogUuid{Id: id} | ||
142 | - // ascertain id exists in the database | ||
143 | - if err = o.Read(&v); err == nil { | ||
144 | - var num int64 | ||
145 | - if num, err = o.Delete(&LogUuid{Id: id}); err == nil { | ||
146 | - fmt.Println("Number of records deleted in database:", num) | ||
147 | - } | ||
148 | - } | ||
149 | - return | ||
150 | -} | ||
151 | - | ||
152 | -func GetLogUuidByUuid(uuid string) (v *LogUuid, err error) { | ||
153 | - o := orm.NewOrm() | ||
154 | - sql := "select * from log_uuid where uuid=?" | ||
155 | - if err = o.Raw(sql, uuid).QueryRow(&v); err == nil { | ||
156 | - return v, nil | ||
157 | - } | ||
158 | - return nil, err | ||
159 | -} |
models/logic.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type Logic struct { | ||
13 | - Id int `orm:"column(id);auto"` | ||
14 | - Data string `orm:"column(data);null"` | ||
15 | - Db string `orm:"column(db);size(50);null"` | ||
16 | - Datatype string `orm:"column(datatype);size(50);null"` | ||
17 | - Type string `orm:"column(type);size(100);null"` | ||
18 | - Defaultparam string `orm:"column(defaultparam);size(200);null"` | ||
19 | -} | ||
20 | - | ||
21 | -func (t *Logic) TableName() string { | ||
22 | - return "logic" | ||
23 | -} | ||
24 | - | ||
25 | -func init() { | ||
26 | - orm.RegisterModel(new(Logic)) | ||
27 | -} | ||
28 | - | ||
29 | -// AddLogic insert a new Logic into database and returns | ||
30 | -// last inserted Id on success. | ||
31 | -func AddLogic(m *Logic) (id int64, err error) { | ||
32 | - o := orm.NewOrm() | ||
33 | - id, err = o.Insert(m) | ||
34 | - return | ||
35 | -} | ||
36 | - | ||
37 | -// GetLogicById retrieves Logic by Id. Returns error if | ||
38 | -// Id doesn't exist | ||
39 | -func GetLogicById(id int) (v *Logic, err error) { | ||
40 | - o := orm.NewOrm() | ||
41 | - v = &Logic{Id: id} | ||
42 | - if err = o.Read(v); err == nil { | ||
43 | - return v, nil | ||
44 | - } | ||
45 | - return nil, err | ||
46 | -} | ||
47 | - | ||
48 | -// GetAllLogic retrieves all Logic matches certain condition. Returns empty list if | ||
49 | -// no records exist | ||
50 | -func GetAllLogic(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | - o := orm.NewOrm() | ||
53 | - qs := o.QueryTable(new(Logic)) | ||
54 | - // query k=v | ||
55 | - for k, v := range query { | ||
56 | - // rewrite dot-notation to Object__Attribute | ||
57 | - k = strings.Replace(k, ".", "__", -1) | ||
58 | - if strings.Contains(k, "isnull") { | ||
59 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | - } else { | ||
61 | - qs = qs.Filter(k, v) | ||
62 | - } | ||
63 | - } | ||
64 | - // order by: | ||
65 | - var sortFields []string | ||
66 | - if len(sortby) != 0 { | ||
67 | - if len(sortby) == len(order) { | ||
68 | - // 1) for each sort field, there is an associated order | ||
69 | - for i, v := range sortby { | ||
70 | - orderby := "" | ||
71 | - if order[i] == "desc" { | ||
72 | - orderby = "-" + v | ||
73 | - } else if order[i] == "asc" { | ||
74 | - orderby = v | ||
75 | - } else { | ||
76 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | - } | ||
78 | - sortFields = append(sortFields, orderby) | ||
79 | - } | ||
80 | - qs = qs.OrderBy(sortFields...) | ||
81 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | - for _, v := range sortby { | ||
84 | - orderby := "" | ||
85 | - if order[0] == "desc" { | ||
86 | - orderby = "-" + v | ||
87 | - } else if order[0] == "asc" { | ||
88 | - orderby = v | ||
89 | - } else { | ||
90 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | - } | ||
92 | - sortFields = append(sortFields, orderby) | ||
93 | - } | ||
94 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | - } | ||
97 | - } else { | ||
98 | - if len(order) != 0 { | ||
99 | - return nil, errors.New("Error: unused 'order' fields") | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - var l []Logic | ||
104 | - qs = qs.OrderBy(sortFields...) | ||
105 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | - if len(fields) == 0 { | ||
107 | - for _, v := range l { | ||
108 | - ml = append(ml, v) | ||
109 | - } | ||
110 | - } else { | ||
111 | - // trim unused fields | ||
112 | - for _, v := range l { | ||
113 | - m := make(map[string]interface{}) | ||
114 | - val := reflect.ValueOf(v) | ||
115 | - for _, fname := range fields { | ||
116 | - m[fname] = val.FieldByName(fname).Interface() | ||
117 | - } | ||
118 | - ml = append(ml, m) | ||
119 | - } | ||
120 | - } | ||
121 | - return ml, nil | ||
122 | - } | ||
123 | - return nil, err | ||
124 | -} | ||
125 | - | ||
126 | -// UpdateLogic updates Logic by Id and returns error if | ||
127 | -// the record to be updated doesn't exist | ||
128 | -func UpdateLogicById(m *Logic) (err error) { | ||
129 | - o := orm.NewOrm() | ||
130 | - v := Logic{Id: m.Id} | ||
131 | - // ascertain id exists in the database | ||
132 | - if err = o.Read(&v); err == nil { | ||
133 | - var num int64 | ||
134 | - if num, err = o.Update(m); err == nil { | ||
135 | - fmt.Println("Number of records updated in database:", num) | ||
136 | - } | ||
137 | - } | ||
138 | - return | ||
139 | -} | ||
140 | - | ||
141 | -// DeleteLogic deletes Logic by Id and returns error if | ||
142 | -// the record to be deleted doesn't exist | ||
143 | -func DeleteLogic(id int) (err error) { | ||
144 | - o := orm.NewOrm() | ||
145 | - v := Logic{Id: id} | ||
146 | - // ascertain id exists in the database | ||
147 | - if err = o.Read(&v); err == nil { | ||
148 | - var num int64 | ||
149 | - if num, err = o.Delete(&Logic{Id: id}); err == nil { | ||
150 | - fmt.Println("Number of records deleted in database:", num) | ||
151 | - } | ||
152 | - } | ||
153 | - return | ||
154 | -} |
models/permissions.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type Permissions struct { | ||
13 | - Id int `orm:"column(id);auto"` | ||
14 | - Name string `orm:"column(name);size(255)"` | ||
15 | - Value int8 `orm:"column(value)"` | ||
16 | -} | ||
17 | - | ||
18 | -func (t *Permissions) TableName() string { | ||
19 | - return "permissions" | ||
20 | -} | ||
21 | - | ||
22 | -func init() { | ||
23 | - orm.RegisterModel(new(Permissions)) | ||
24 | -} | ||
25 | - | ||
26 | -// AddPermissions insert a new Permissions into database and returns | ||
27 | -// last inserted Id on success. | ||
28 | -func AddPermissions(m *Permissions) (id int64, err error) { | ||
29 | - o := orm.NewOrm() | ||
30 | - id, err = o.Insert(m) | ||
31 | - return | ||
32 | -} | ||
33 | - | ||
34 | -// GetPermissionsById retrieves Permissions by Id. Returns error if | ||
35 | -// Id doesn't exist | ||
36 | -func GetPermissionsById(id int) (v *Permissions, err error) { | ||
37 | - o := orm.NewOrm() | ||
38 | - v = &Permissions{Id: id} | ||
39 | - if err = o.Read(v); err == nil { | ||
40 | - return v, nil | ||
41 | - } | ||
42 | - return nil, err | ||
43 | -} | ||
44 | - | ||
45 | -// GetAllPermissions retrieves all Permissions matches certain condition. Returns empty list if | ||
46 | -// no records exist | ||
47 | -func GetAllPermissions(query map[string]string, fields []string, sortby []string, order []string, | ||
48 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
49 | - o := orm.NewOrm() | ||
50 | - qs := o.QueryTable(new(Permissions)) | ||
51 | - // query k=v | ||
52 | - for k, v := range query { | ||
53 | - // rewrite dot-notation to Object__Attribute | ||
54 | - k = strings.Replace(k, ".", "__", -1) | ||
55 | - if strings.Contains(k, "isnull") { | ||
56 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
57 | - } else { | ||
58 | - qs = qs.Filter(k, v) | ||
59 | - } | ||
60 | - } | ||
61 | - // order by: | ||
62 | - var sortFields []string | ||
63 | - if len(sortby) != 0 { | ||
64 | - if len(sortby) == len(order) { | ||
65 | - // 1) for each sort field, there is an associated order | ||
66 | - for i, v := range sortby { | ||
67 | - orderby := "" | ||
68 | - if order[i] == "desc" { | ||
69 | - orderby = "-" + v | ||
70 | - } else if order[i] == "asc" { | ||
71 | - orderby = v | ||
72 | - } else { | ||
73 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
74 | - } | ||
75 | - sortFields = append(sortFields, orderby) | ||
76 | - } | ||
77 | - qs = qs.OrderBy(sortFields...) | ||
78 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
79 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
80 | - for _, v := range sortby { | ||
81 | - orderby := "" | ||
82 | - if order[0] == "desc" { | ||
83 | - orderby = "-" + v | ||
84 | - } else if order[0] == "asc" { | ||
85 | - orderby = v | ||
86 | - } else { | ||
87 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
88 | - } | ||
89 | - sortFields = append(sortFields, orderby) | ||
90 | - } | ||
91 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
92 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
93 | - } | ||
94 | - } else { | ||
95 | - if len(order) != 0 { | ||
96 | - return nil, errors.New("Error: unused 'order' fields") | ||
97 | - } | ||
98 | - } | ||
99 | - | ||
100 | - var l []Permissions | ||
101 | - qs = qs.OrderBy(sortFields...) | ||
102 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
103 | - if len(fields) == 0 { | ||
104 | - for _, v := range l { | ||
105 | - ml = append(ml, v) | ||
106 | - } | ||
107 | - } else { | ||
108 | - // trim unused fields | ||
109 | - for _, v := range l { | ||
110 | - m := make(map[string]interface{}) | ||
111 | - val := reflect.ValueOf(v) | ||
112 | - for _, fname := range fields { | ||
113 | - m[fname] = val.FieldByName(fname).Interface() | ||
114 | - } | ||
115 | - ml = append(ml, m) | ||
116 | - } | ||
117 | - } | ||
118 | - return ml, nil | ||
119 | - } | ||
120 | - return nil, err | ||
121 | -} | ||
122 | - | ||
123 | -// UpdatePermissions updates Permissions by Id and returns error if | ||
124 | -// the record to be updated doesn't exist | ||
125 | -func UpdatePermissionsById(m *Permissions) (err error) { | ||
126 | - o := orm.NewOrm() | ||
127 | - v := Permissions{Id: m.Id} | ||
128 | - // ascertain id exists in the database | ||
129 | - if err = o.Read(&v); err == nil { | ||
130 | - var num int64 | ||
131 | - if num, err = o.Update(m); err == nil { | ||
132 | - fmt.Println("Number of records updated in database:", num) | ||
133 | - } | ||
134 | - } | ||
135 | - return | ||
136 | -} | ||
137 | - | ||
138 | -// DeletePermissions deletes Permissions by Id and returns error if | ||
139 | -// the record to be deleted doesn't exist | ||
140 | -func DeletePermissions(id int) (err error) { | ||
141 | - o := orm.NewOrm() | ||
142 | - v := Permissions{Id: id} | ||
143 | - // ascertain id exists in the database | ||
144 | - if err = o.Read(&v); err == nil { | ||
145 | - var num int64 | ||
146 | - if num, err = o.Delete(&Permissions{Id: id}); err == nil { | ||
147 | - fmt.Println("Number of records deleted in database:", num) | ||
148 | - } | ||
149 | - } | ||
150 | - return | ||
151 | -} |
models/pics_log.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type PicsLog struct { | ||
13 | - Id int `orm:"column(id);auto" description:"主键ID"` | ||
14 | - Url string `orm:"column(url);size(128)"` | ||
15 | - Thumbnail string `orm:"column(thumbnail);size(128)" description:"缩略图"` | ||
16 | - Width int `orm:"column(width)" description:"宽度"` | ||
17 | - Length int `orm:"column(length)" description:"长度"` | ||
18 | -} | ||
19 | - | ||
20 | -func (t *PicsLog) TableName() string { | ||
21 | - return "pics_log" | ||
22 | -} | ||
23 | - | ||
24 | -func init() { | ||
25 | - orm.RegisterModel(new(PicsLog)) | ||
26 | -} | ||
27 | - | ||
28 | -// AddPicsLog insert a new PicsLog into database and returns | ||
29 | -// last inserted Id on success. | ||
30 | -func AddPicsLog(m *PicsLog) (id int64, err error) { | ||
31 | - o := orm.NewOrm() | ||
32 | - id, err = o.Insert(m) | ||
33 | - return | ||
34 | -} | ||
35 | - | ||
36 | -// GetPicsLogById retrieves PicsLog by Id. Returns error if | ||
37 | -// Id doesn't exist | ||
38 | -func GetPicsLogById(id int) (v *PicsLog, err error) { | ||
39 | - o := orm.NewOrm() | ||
40 | - v = &PicsLog{Id: id} | ||
41 | - if err = o.Read(v); err == nil { | ||
42 | - return v, nil | ||
43 | - } | ||
44 | - return nil, err | ||
45 | -} | ||
46 | - | ||
47 | -// GetAllPicsLog retrieves all PicsLog matches certain condition. Returns empty list if | ||
48 | -// no records exist | ||
49 | -func GetAllPicsLog(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | - o := orm.NewOrm() | ||
52 | - qs := o.QueryTable(new(PicsLog)) | ||
53 | - // query k=v | ||
54 | - for k, v := range query { | ||
55 | - // rewrite dot-notation to Object__Attribute | ||
56 | - k = strings.Replace(k, ".", "__", -1) | ||
57 | - if strings.Contains(k, "isnull") { | ||
58 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | - } else { | ||
60 | - qs = qs.Filter(k, v) | ||
61 | - } | ||
62 | - } | ||
63 | - // order by: | ||
64 | - var sortFields []string | ||
65 | - if len(sortby) != 0 { | ||
66 | - if len(sortby) == len(order) { | ||
67 | - // 1) for each sort field, there is an associated order | ||
68 | - for i, v := range sortby { | ||
69 | - orderby := "" | ||
70 | - if order[i] == "desc" { | ||
71 | - orderby = "-" + v | ||
72 | - } else if order[i] == "asc" { | ||
73 | - orderby = v | ||
74 | - } else { | ||
75 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | - } | ||
77 | - sortFields = append(sortFields, orderby) | ||
78 | - } | ||
79 | - qs = qs.OrderBy(sortFields...) | ||
80 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | - for _, v := range sortby { | ||
83 | - orderby := "" | ||
84 | - if order[0] == "desc" { | ||
85 | - orderby = "-" + v | ||
86 | - } else if order[0] == "asc" { | ||
87 | - orderby = v | ||
88 | - } else { | ||
89 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | - } | ||
91 | - sortFields = append(sortFields, orderby) | ||
92 | - } | ||
93 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | - } | ||
96 | - } else { | ||
97 | - if len(order) != 0 { | ||
98 | - return nil, errors.New("Error: unused 'order' fields") | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - var l []PicsLog | ||
103 | - qs = qs.OrderBy(sortFields...) | ||
104 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | - if len(fields) == 0 { | ||
106 | - for _, v := range l { | ||
107 | - ml = append(ml, v) | ||
108 | - } | ||
109 | - } else { | ||
110 | - // trim unused fields | ||
111 | - for _, v := range l { | ||
112 | - m := make(map[string]interface{}) | ||
113 | - val := reflect.ValueOf(v) | ||
114 | - for _, fname := range fields { | ||
115 | - m[fname] = val.FieldByName(fname).Interface() | ||
116 | - } | ||
117 | - ml = append(ml, m) | ||
118 | - } | ||
119 | - } | ||
120 | - return ml, nil | ||
121 | - } | ||
122 | - return nil, err | ||
123 | -} | ||
124 | - | ||
125 | -// UpdatePicsLog updates PicsLog by Id and returns error if | ||
126 | -// the record to be updated doesn't exist | ||
127 | -func UpdatePicsLogById(m *PicsLog) (err error) { | ||
128 | - o := orm.NewOrm() | ||
129 | - v := PicsLog{Id: m.Id} | ||
130 | - // ascertain id exists in the database | ||
131 | - if err = o.Read(&v); err == nil { | ||
132 | - var num int64 | ||
133 | - if num, err = o.Update(m); err == nil { | ||
134 | - fmt.Println("Number of records updated in database:", num) | ||
135 | - } | ||
136 | - } | ||
137 | - return | ||
138 | -} | ||
139 | - | ||
140 | -// DeletePicsLog deletes PicsLog by Id and returns error if | ||
141 | -// the record to be deleted doesn't exist | ||
142 | -func DeletePicsLog(id int) (err error) { | ||
143 | - o := orm.NewOrm() | ||
144 | - v := PicsLog{Id: id} | ||
145 | - // ascertain id exists in the database | ||
146 | - if err = o.Read(&v); err == nil { | ||
147 | - var num int64 | ||
148 | - if num, err = o.Delete(&PicsLog{Id: id}); err == nil { | ||
149 | - fmt.Println("Number of records deleted in database:", num) | ||
150 | - } | ||
151 | - } | ||
152 | - return | ||
153 | -} |
models/positions.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Positions struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - CompanyId int `orm:"column(company_id)"` | ||
16 | - Name string `orm:"column(name);size(255)"` | ||
17 | - Pid string `orm:"column(pid);size(255)"` | ||
18 | - Path string `orm:"column(path);size(1000)"` | ||
19 | - Level int8 `orm:"column(level)" description:"级别"` | ||
20 | - CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
21 | - Enabled int8 `orm:"column(enabled)"` | ||
22 | -} | ||
23 | - | ||
24 | -func (t *Positions) TableName() string { | ||
25 | - return "positions" | ||
26 | -} | ||
27 | - | ||
28 | -func init() { | ||
29 | - orm.RegisterModel(new(Positions)) | ||
30 | -} | ||
31 | - | ||
32 | -// AddPositions insert a new Positions into database and returns | ||
33 | -// last inserted Id on success. | ||
34 | -func AddPositions(m *Positions) (id int64, err error) { | ||
35 | - o := orm.NewOrm() | ||
36 | - id, err = o.Insert(m) | ||
37 | - return | ||
38 | -} | ||
39 | - | ||
40 | -// GetPositionsById retrieves Positions by Id. Returns error if | ||
41 | -// Id doesn't exist | ||
42 | -func GetPositionsById(id int) (v *Positions, err error) { | ||
43 | - o := orm.NewOrm() | ||
44 | - v = &Positions{Id: id} | ||
45 | - if err = o.Read(v); err == nil { | ||
46 | - return v, nil | ||
47 | - } | ||
48 | - return nil, err | ||
49 | -} | ||
50 | - | ||
51 | -// GetAllPositions retrieves all Positions matches certain condition. Returns empty list if | ||
52 | -// no records exist | ||
53 | -func GetAllPositions(query map[string]string, fields []string, sortby []string, order []string, | ||
54 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
55 | - o := orm.NewOrm() | ||
56 | - qs := o.QueryTable(new(Positions)) | ||
57 | - // query k=v | ||
58 | - for k, v := range query { | ||
59 | - // rewrite dot-notation to Object__Attribute | ||
60 | - k = strings.Replace(k, ".", "__", -1) | ||
61 | - if strings.Contains(k, "isnull") { | ||
62 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
63 | - } else { | ||
64 | - qs = qs.Filter(k, v) | ||
65 | - } | ||
66 | - } | ||
67 | - // order by: | ||
68 | - var sortFields []string | ||
69 | - if len(sortby) != 0 { | ||
70 | - if len(sortby) == len(order) { | ||
71 | - // 1) for each sort field, there is an associated order | ||
72 | - for i, v := range sortby { | ||
73 | - orderby := "" | ||
74 | - if order[i] == "desc" { | ||
75 | - orderby = "-" + v | ||
76 | - } else if order[i] == "asc" { | ||
77 | - orderby = v | ||
78 | - } else { | ||
79 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
80 | - } | ||
81 | - sortFields = append(sortFields, orderby) | ||
82 | - } | ||
83 | - qs = qs.OrderBy(sortFields...) | ||
84 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
85 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
86 | - for _, v := range sortby { | ||
87 | - orderby := "" | ||
88 | - if order[0] == "desc" { | ||
89 | - orderby = "-" + v | ||
90 | - } else if order[0] == "asc" { | ||
91 | - orderby = v | ||
92 | - } else { | ||
93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
94 | - } | ||
95 | - sortFields = append(sortFields, orderby) | ||
96 | - } | ||
97 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
98 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
99 | - } | ||
100 | - } else { | ||
101 | - if len(order) != 0 { | ||
102 | - return nil, errors.New("Error: unused 'order' fields") | ||
103 | - } | ||
104 | - } | ||
105 | - | ||
106 | - var l []Positions | ||
107 | - qs = qs.OrderBy(sortFields...) | ||
108 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
109 | - if len(fields) == 0 { | ||
110 | - for _, v := range l { | ||
111 | - ml = append(ml, v) | ||
112 | - } | ||
113 | - } else { | ||
114 | - // trim unused fields | ||
115 | - for _, v := range l { | ||
116 | - m := make(map[string]interface{}) | ||
117 | - val := reflect.ValueOf(v) | ||
118 | - for _, fname := range fields { | ||
119 | - m[fname] = val.FieldByName(fname).Interface() | ||
120 | - } | ||
121 | - ml = append(ml, m) | ||
122 | - } | ||
123 | - } | ||
124 | - return ml, nil | ||
125 | - } | ||
126 | - return nil, err | ||
127 | -} | ||
128 | - | ||
129 | -// UpdatePositions updates Positions by Id and returns error if | ||
130 | -// the record to be updated doesn't exist | ||
131 | -func UpdatePositionsById(m *Positions) (err error) { | ||
132 | - o := orm.NewOrm() | ||
133 | - v := Positions{Id: m.Id} | ||
134 | - // ascertain id exists in the database | ||
135 | - if err = o.Read(&v); err == nil { | ||
136 | - var num int64 | ||
137 | - if num, err = o.Update(m); err == nil { | ||
138 | - fmt.Println("Number of records updated in database:", num) | ||
139 | - } | ||
140 | - } | ||
141 | - return | ||
142 | -} | ||
143 | - | ||
144 | -// DeletePositions deletes Positions by Id and returns error if | ||
145 | -// the record to be deleted doesn't exist | ||
146 | -func DeletePositions(id int) (err error) { | ||
147 | - o := orm.NewOrm() | ||
148 | - v := Positions{Id: id} | ||
149 | - // ascertain id exists in the database | ||
150 | - if err = o.Read(&v); err == nil { | ||
151 | - var num int64 | ||
152 | - if num, err = o.Delete(&Positions{Id: id}); err == nil { | ||
153 | - fmt.Println("Number of records deleted in database:", num) | ||
154 | - } | ||
155 | - } | ||
156 | - return | ||
157 | -} |
models/question.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Question struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - Title string `orm:"column(title);size(30)" description:"标题"` | ||
16 | - Content string `orm:"column(content)" description:"内容"` | ||
17 | - Uid int64 `orm:"column(uid)" description:"用户ID"` | ||
18 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
19 | - Way int `orm:"column(way)" description:"提问方式(0语音,1图文)"` | ||
20 | - PageView int `orm:"column(pageView)" description:"浏览总数"` | ||
21 | - CommentTotal int `orm:"column(commentTotal)" description:"评论总数"` | ||
22 | - SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"` | ||
23 | - Review int `orm:"column(review)" description:"0 待审核 1已审核"` | ||
24 | - Status int `orm:"column(status);null" description:"状态 0 未解决 1已解决"` | ||
25 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null"` | ||
26 | - ScoreAnalyze int `orm:"column(scoreAnalyze);null" description:"分析评分"` | ||
27 | - ScoreAsk int `orm:"column(scoreAsk);null" description:"提问评分"` | ||
28 | - ScoreScheme int `orm:"column(scoreScheme);null" description:"方案评分"` | ||
29 | - Published int `orm:"column(published);null" description:"公开状态 0未公开、1本部门公开、2本公司公开"` | ||
30 | - Level int `orm:"column(level)" description:"最后评分或审核人的级别"` | ||
31 | - CheckUid int64 `orm:"column(checkUid);null" description:"审核人ID"` | ||
32 | - Enabled int `orm:"column(enabled);null" description:"1有效 0删除"` | ||
33 | - Tlevel int `orm:"column(tlevel)" description:"公开操作权限"` | ||
34 | - PfUid int64 `orm:"column(pfUid)"` | ||
35 | - QType int `orm:"column(qType)"` | ||
36 | - SoluteTime time.Time `orm:"column(soluteTime);type(timestamp);auto_now_add"` | ||
37 | - ResolverTime time.Time `orm:"column(resolverTime);type(timestamp);auto_now_add"` | ||
38 | - Resolver int64 `orm:"column(resolver)"` | ||
39 | - RelevantDepartmentId int `orm:"column(relevantDepartmentId)" description:"相关部门id"` | ||
40 | - ReceiveStatus int8 `orm:"column(receiveStatus)" description:"领取状态 0未领取 1已领取"` | ||
41 | -} | ||
42 | - | ||
43 | -func (t *Question) TableName() string { | ||
44 | - return "question" | ||
45 | -} | ||
46 | - | ||
47 | -func init() { | ||
48 | - orm.RegisterModel(new(Question)) | ||
49 | -} | ||
50 | - | ||
51 | -// AddQuestion insert a new Question into database and returns | ||
52 | -// last inserted Id on success. | ||
53 | -func AddQuestion(m *Question) (id int64, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - id, err = o.Insert(m) | ||
56 | - return | ||
57 | -} | ||
58 | - | ||
59 | -// GetQuestionById retrieves Question by Id. Returns error if | ||
60 | -// Id doesn't exist | ||
61 | -func GetQuestionById(id int) (v *Question, err error) { | ||
62 | - o := orm.NewOrm() | ||
63 | - v = &Question{Id: id} | ||
64 | - if err = o.Read(v); err == nil { | ||
65 | - return v, nil | ||
66 | - } | ||
67 | - return nil, err | ||
68 | -} | ||
69 | - | ||
70 | -// GetAllQuestion retrieves all Question matches certain condition. Returns empty list if | ||
71 | -// no records exist | ||
72 | -func GetAllQuestion(query map[string]string, fields []string, sortby []string, order []string, | ||
73 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
74 | - o := orm.NewOrm() | ||
75 | - qs := o.QueryTable(new(Question)) | ||
76 | - // query k=v | ||
77 | - for k, v := range query { | ||
78 | - // rewrite dot-notation to Object__Attribute | ||
79 | - k = strings.Replace(k, ".", "__", -1) | ||
80 | - if strings.Contains(k, "isnull") { | ||
81 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
82 | - } else { | ||
83 | - qs = qs.Filter(k, v) | ||
84 | - } | ||
85 | - } | ||
86 | - // order by: | ||
87 | - var sortFields []string | ||
88 | - if len(sortby) != 0 { | ||
89 | - if len(sortby) == len(order) { | ||
90 | - // 1) for each sort field, there is an associated order | ||
91 | - for i, v := range sortby { | ||
92 | - orderby := "" | ||
93 | - if order[i] == "desc" { | ||
94 | - orderby = "-" + v | ||
95 | - } else if order[i] == "asc" { | ||
96 | - orderby = v | ||
97 | - } else { | ||
98 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
99 | - } | ||
100 | - sortFields = append(sortFields, orderby) | ||
101 | - } | ||
102 | - qs = qs.OrderBy(sortFields...) | ||
103 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
104 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
105 | - for _, v := range sortby { | ||
106 | - orderby := "" | ||
107 | - if order[0] == "desc" { | ||
108 | - orderby = "-" + v | ||
109 | - } else if order[0] == "asc" { | ||
110 | - orderby = v | ||
111 | - } else { | ||
112 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
113 | - } | ||
114 | - sortFields = append(sortFields, orderby) | ||
115 | - } | ||
116 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
117 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
118 | - } | ||
119 | - } else { | ||
120 | - if len(order) != 0 { | ||
121 | - return nil, errors.New("Error: unused 'order' fields") | ||
122 | - } | ||
123 | - } | ||
124 | - | ||
125 | - var l []Question | ||
126 | - qs = qs.OrderBy(sortFields...) | ||
127 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
128 | - if len(fields) == 0 { | ||
129 | - for _, v := range l { | ||
130 | - ml = append(ml, v) | ||
131 | - } | ||
132 | - } else { | ||
133 | - // trim unused fields | ||
134 | - for _, v := range l { | ||
135 | - m := make(map[string]interface{}) | ||
136 | - val := reflect.ValueOf(v) | ||
137 | - for _, fname := range fields { | ||
138 | - m[fname] = val.FieldByName(fname).Interface() | ||
139 | - } | ||
140 | - ml = append(ml, m) | ||
141 | - } | ||
142 | - } | ||
143 | - return ml, nil | ||
144 | - } | ||
145 | - return nil, err | ||
146 | -} | ||
147 | - | ||
148 | -// UpdateQuestion updates Question by Id and returns error if | ||
149 | -// the record to be updated doesn't exist | ||
150 | -func UpdateQuestionById(m *Question) (err error) { | ||
151 | - o := orm.NewOrm() | ||
152 | - v := Question{Id: m.Id} | ||
153 | - // ascertain id exists in the database | ||
154 | - if err = o.Read(&v); err == nil { | ||
155 | - var num int64 | ||
156 | - if num, err = o.Update(m); err == nil { | ||
157 | - fmt.Println("Number of records updated in database:", num) | ||
158 | - } | ||
159 | - } | ||
160 | - return | ||
161 | -} | ||
162 | - | ||
163 | -// DeleteQuestion deletes Question by Id and returns error if | ||
164 | -// the record to be deleted doesn't exist | ||
165 | -func DeleteQuestion(id int) (err error) { | ||
166 | - o := orm.NewOrm() | ||
167 | - v := Question{Id: id} | ||
168 | - // ascertain id exists in the database | ||
169 | - if err = o.Read(&v); err == nil { | ||
170 | - var num int64 | ||
171 | - if num, err = o.Delete(&Question{Id: id}); err == nil { | ||
172 | - fmt.Println("Number of records deleted in database:", num) | ||
173 | - } | ||
174 | - } | ||
175 | - return | ||
176 | -} |
models/question_department.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type QuestionDepartment struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - Qid int64 `orm:"column(qid)" description:"所属的问题ID"` | ||
16 | - DepartmentId int `orm:"column(department_id)" description:"语音路径"` | ||
17 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
18 | -} | ||
19 | - | ||
20 | -func (t *QuestionDepartment) TableName() string { | ||
21 | - return "question_department" | ||
22 | -} | ||
23 | - | ||
24 | -func init() { | ||
25 | - orm.RegisterModel(new(QuestionDepartment)) | ||
26 | -} | ||
27 | - | ||
28 | -// AddQuestionDepartment insert a new QuestionDepartment into database and returns | ||
29 | -// last inserted Id on success. | ||
30 | -func AddQuestionDepartment(m *QuestionDepartment) (id int64, err error) { | ||
31 | - o := orm.NewOrm() | ||
32 | - id, err = o.Insert(m) | ||
33 | - return | ||
34 | -} | ||
35 | - | ||
36 | -// GetQuestionDepartmentById retrieves QuestionDepartment by Id. Returns error if | ||
37 | -// Id doesn't exist | ||
38 | -func GetQuestionDepartmentById(id int) (v *QuestionDepartment, err error) { | ||
39 | - o := orm.NewOrm() | ||
40 | - v = &QuestionDepartment{Id: id} | ||
41 | - if err = o.Read(v); err == nil { | ||
42 | - return v, nil | ||
43 | - } | ||
44 | - return nil, err | ||
45 | -} | ||
46 | - | ||
47 | -// GetAllQuestionDepartment retrieves all QuestionDepartment matches certain condition. Returns empty list if | ||
48 | -// no records exist | ||
49 | -func GetAllQuestionDepartment(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | - o := orm.NewOrm() | ||
52 | - qs := o.QueryTable(new(QuestionDepartment)) | ||
53 | - // query k=v | ||
54 | - for k, v := range query { | ||
55 | - // rewrite dot-notation to Object__Attribute | ||
56 | - k = strings.Replace(k, ".", "__", -1) | ||
57 | - if strings.Contains(k, "isnull") { | ||
58 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | - } else { | ||
60 | - qs = qs.Filter(k, v) | ||
61 | - } | ||
62 | - } | ||
63 | - // order by: | ||
64 | - var sortFields []string | ||
65 | - if len(sortby) != 0 { | ||
66 | - if len(sortby) == len(order) { | ||
67 | - // 1) for each sort field, there is an associated order | ||
68 | - for i, v := range sortby { | ||
69 | - orderby := "" | ||
70 | - if order[i] == "desc" { | ||
71 | - orderby = "-" + v | ||
72 | - } else if order[i] == "asc" { | ||
73 | - orderby = v | ||
74 | - } else { | ||
75 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | - } | ||
77 | - sortFields = append(sortFields, orderby) | ||
78 | - } | ||
79 | - qs = qs.OrderBy(sortFields...) | ||
80 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | - for _, v := range sortby { | ||
83 | - orderby := "" | ||
84 | - if order[0] == "desc" { | ||
85 | - orderby = "-" + v | ||
86 | - } else if order[0] == "asc" { | ||
87 | - orderby = v | ||
88 | - } else { | ||
89 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | - } | ||
91 | - sortFields = append(sortFields, orderby) | ||
92 | - } | ||
93 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | - } | ||
96 | - } else { | ||
97 | - if len(order) != 0 { | ||
98 | - return nil, errors.New("Error: unused 'order' fields") | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - var l []QuestionDepartment | ||
103 | - qs = qs.OrderBy(sortFields...) | ||
104 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | - if len(fields) == 0 { | ||
106 | - for _, v := range l { | ||
107 | - ml = append(ml, v) | ||
108 | - } | ||
109 | - } else { | ||
110 | - // trim unused fields | ||
111 | - for _, v := range l { | ||
112 | - m := make(map[string]interface{}) | ||
113 | - val := reflect.ValueOf(v) | ||
114 | - for _, fname := range fields { | ||
115 | - m[fname] = val.FieldByName(fname).Interface() | ||
116 | - } | ||
117 | - ml = append(ml, m) | ||
118 | - } | ||
119 | - } | ||
120 | - return ml, nil | ||
121 | - } | ||
122 | - return nil, err | ||
123 | -} | ||
124 | - | ||
125 | -// UpdateQuestionDepartment updates QuestionDepartment by Id and returns error if | ||
126 | -// the record to be updated doesn't exist | ||
127 | -func UpdateQuestionDepartmentById(m *QuestionDepartment) (err error) { | ||
128 | - o := orm.NewOrm() | ||
129 | - v := QuestionDepartment{Id: m.Id} | ||
130 | - // ascertain id exists in the database | ||
131 | - if err = o.Read(&v); err == nil { | ||
132 | - var num int64 | ||
133 | - if num, err = o.Update(m); err == nil { | ||
134 | - fmt.Println("Number of records updated in database:", num) | ||
135 | - } | ||
136 | - } | ||
137 | - return | ||
138 | -} | ||
139 | - | ||
140 | -// DeleteQuestionDepartment deletes QuestionDepartment by Id and returns error if | ||
141 | -// the record to be deleted doesn't exist | ||
142 | -func DeleteQuestionDepartment(id int) (err error) { | ||
143 | - o := orm.NewOrm() | ||
144 | - v := QuestionDepartment{Id: id} | ||
145 | - // ascertain id exists in the database | ||
146 | - if err = o.Read(&v); err == nil { | ||
147 | - var num int64 | ||
148 | - if num, err = o.Delete(&QuestionDepartment{Id: id}); err == nil { | ||
149 | - fmt.Println("Number of records deleted in database:", num) | ||
150 | - } | ||
151 | - } | ||
152 | - return | ||
153 | -} |
models/question_department_log.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type QuestionDepartmentLog struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - Qid int64 `orm:"column(qid)" description:"所属的问题ID"` | ||
16 | - DepartmentId int `orm:"column(department_id)" description:"相关部门id"` | ||
17 | - OperatorId int64 `orm:"column(operator_id)" description:"操作者id"` | ||
18 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
19 | -} | ||
20 | - | ||
21 | -func (t *QuestionDepartmentLog) TableName() string { | ||
22 | - return "question_department_log" | ||
23 | -} | ||
24 | - | ||
25 | -func init() { | ||
26 | - orm.RegisterModel(new(QuestionDepartmentLog)) | ||
27 | -} | ||
28 | - | ||
29 | -// AddQuestionDepartmentLog insert a new QuestionDepartmentLog into database and returns | ||
30 | -// last inserted Id on success. | ||
31 | -func AddQuestionDepartmentLog(m *QuestionDepartmentLog) (id int64, err error) { | ||
32 | - o := orm.NewOrm() | ||
33 | - id, err = o.Insert(m) | ||
34 | - return | ||
35 | -} | ||
36 | - | ||
37 | -// GetQuestionDepartmentLogById retrieves QuestionDepartmentLog by Id. Returns error if | ||
38 | -// Id doesn't exist | ||
39 | -func GetQuestionDepartmentLogById(id int) (v *QuestionDepartmentLog, err error) { | ||
40 | - o := orm.NewOrm() | ||
41 | - v = &QuestionDepartmentLog{Id: id} | ||
42 | - if err = o.Read(v); err == nil { | ||
43 | - return v, nil | ||
44 | - } | ||
45 | - return nil, err | ||
46 | -} | ||
47 | - | ||
48 | -// GetAllQuestionDepartmentLog retrieves all QuestionDepartmentLog matches certain condition. Returns empty list if | ||
49 | -// no records exist | ||
50 | -func GetAllQuestionDepartmentLog(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | - o := orm.NewOrm() | ||
53 | - qs := o.QueryTable(new(QuestionDepartmentLog)) | ||
54 | - // query k=v | ||
55 | - for k, v := range query { | ||
56 | - // rewrite dot-notation to Object__Attribute | ||
57 | - k = strings.Replace(k, ".", "__", -1) | ||
58 | - if strings.Contains(k, "isnull") { | ||
59 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | - } else { | ||
61 | - qs = qs.Filter(k, v) | ||
62 | - } | ||
63 | - } | ||
64 | - // order by: | ||
65 | - var sortFields []string | ||
66 | - if len(sortby) != 0 { | ||
67 | - if len(sortby) == len(order) { | ||
68 | - // 1) for each sort field, there is an associated order | ||
69 | - for i, v := range sortby { | ||
70 | - orderby := "" | ||
71 | - if order[i] == "desc" { | ||
72 | - orderby = "-" + v | ||
73 | - } else if order[i] == "asc" { | ||
74 | - orderby = v | ||
75 | - } else { | ||
76 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | - } | ||
78 | - sortFields = append(sortFields, orderby) | ||
79 | - } | ||
80 | - qs = qs.OrderBy(sortFields...) | ||
81 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | - for _, v := range sortby { | ||
84 | - orderby := "" | ||
85 | - if order[0] == "desc" { | ||
86 | - orderby = "-" + v | ||
87 | - } else if order[0] == "asc" { | ||
88 | - orderby = v | ||
89 | - } else { | ||
90 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | - } | ||
92 | - sortFields = append(sortFields, orderby) | ||
93 | - } | ||
94 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | - } | ||
97 | - } else { | ||
98 | - if len(order) != 0 { | ||
99 | - return nil, errors.New("Error: unused 'order' fields") | ||
100 | - } | ||
101 | - } | ||
102 | - | ||
103 | - var l []QuestionDepartmentLog | ||
104 | - qs = qs.OrderBy(sortFields...) | ||
105 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | - if len(fields) == 0 { | ||
107 | - for _, v := range l { | ||
108 | - ml = append(ml, v) | ||
109 | - } | ||
110 | - } else { | ||
111 | - // trim unused fields | ||
112 | - for _, v := range l { | ||
113 | - m := make(map[string]interface{}) | ||
114 | - val := reflect.ValueOf(v) | ||
115 | - for _, fname := range fields { | ||
116 | - m[fname] = val.FieldByName(fname).Interface() | ||
117 | - } | ||
118 | - ml = append(ml, m) | ||
119 | - } | ||
120 | - } | ||
121 | - return ml, nil | ||
122 | - } | ||
123 | - return nil, err | ||
124 | -} | ||
125 | - | ||
126 | -// UpdateQuestionDepartmentLog updates QuestionDepartmentLog by Id and returns error if | ||
127 | -// the record to be updated doesn't exist | ||
128 | -func UpdateQuestionDepartmentLogById(m *QuestionDepartmentLog) (err error) { | ||
129 | - o := orm.NewOrm() | ||
130 | - v := QuestionDepartmentLog{Id: m.Id} | ||
131 | - // ascertain id exists in the database | ||
132 | - if err = o.Read(&v); err == nil { | ||
133 | - var num int64 | ||
134 | - if num, err = o.Update(m); err == nil { | ||
135 | - fmt.Println("Number of records updated in database:", num) | ||
136 | - } | ||
137 | - } | ||
138 | - return | ||
139 | -} | ||
140 | - | ||
141 | -// DeleteQuestionDepartmentLog deletes QuestionDepartmentLog by Id and returns error if | ||
142 | -// the record to be deleted doesn't exist | ||
143 | -func DeleteQuestionDepartmentLog(id int) (err error) { | ||
144 | - o := orm.NewOrm() | ||
145 | - v := QuestionDepartmentLog{Id: id} | ||
146 | - // ascertain id exists in the database | ||
147 | - if err = o.Read(&v); err == nil { | ||
148 | - var num int64 | ||
149 | - if num, err = o.Delete(&QuestionDepartmentLog{Id: id}); err == nil { | ||
150 | - fmt.Println("Number of records deleted in database:", num) | ||
151 | - } | ||
152 | - } | ||
153 | - return | ||
154 | -} |
models/question_image.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type QuestionImage struct { | ||
13 | - Id int `orm:"column(id);pk"` | ||
14 | - Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
15 | - Path string `orm:"column(path);size(500);null" description:"语音路径"` | ||
16 | - W int `orm:"column(w)"` | ||
17 | - H int `orm:"column(h)"` | ||
18 | -} | ||
19 | - | ||
20 | -func (t *QuestionImage) TableName() string { | ||
21 | - return "question_image" | ||
22 | -} | ||
23 | - | ||
24 | -func init() { | ||
25 | - orm.RegisterModel(new(QuestionImage)) | ||
26 | -} | ||
27 | - | ||
28 | -// AddQuestionImage insert a new QuestionImage into database and returns | ||
29 | -// last inserted Id on success. | ||
30 | -func AddQuestionImage(m *QuestionImage) (id int64, err error) { | ||
31 | - o := orm.NewOrm() | ||
32 | - id, err = o.Insert(m) | ||
33 | - return | ||
34 | -} | ||
35 | - | ||
36 | -// GetQuestionImageById retrieves QuestionImage by Id. Returns error if | ||
37 | -// Id doesn't exist | ||
38 | -func GetQuestionImageById(id int) (v *QuestionImage, err error) { | ||
39 | - o := orm.NewOrm() | ||
40 | - v = &QuestionImage{Id: id} | ||
41 | - if err = o.Read(v); err == nil { | ||
42 | - return v, nil | ||
43 | - } | ||
44 | - return nil, err | ||
45 | -} | ||
46 | - | ||
47 | -// GetAllQuestionImage retrieves all QuestionImage matches certain condition. Returns empty list if | ||
48 | -// no records exist | ||
49 | -func GetAllQuestionImage(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | - o := orm.NewOrm() | ||
52 | - qs := o.QueryTable(new(QuestionImage)) | ||
53 | - // query k=v | ||
54 | - for k, v := range query { | ||
55 | - // rewrite dot-notation to Object__Attribute | ||
56 | - k = strings.Replace(k, ".", "__", -1) | ||
57 | - if strings.Contains(k, "isnull") { | ||
58 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | - } else { | ||
60 | - qs = qs.Filter(k, v) | ||
61 | - } | ||
62 | - } | ||
63 | - // order by: | ||
64 | - var sortFields []string | ||
65 | - if len(sortby) != 0 { | ||
66 | - if len(sortby) == len(order) { | ||
67 | - // 1) for each sort field, there is an associated order | ||
68 | - for i, v := range sortby { | ||
69 | - orderby := "" | ||
70 | - if order[i] == "desc" { | ||
71 | - orderby = "-" + v | ||
72 | - } else if order[i] == "asc" { | ||
73 | - orderby = v | ||
74 | - } else { | ||
75 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | - } | ||
77 | - sortFields = append(sortFields, orderby) | ||
78 | - } | ||
79 | - qs = qs.OrderBy(sortFields...) | ||
80 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | - for _, v := range sortby { | ||
83 | - orderby := "" | ||
84 | - if order[0] == "desc" { | ||
85 | - orderby = "-" + v | ||
86 | - } else if order[0] == "asc" { | ||
87 | - orderby = v | ||
88 | - } else { | ||
89 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | - } | ||
91 | - sortFields = append(sortFields, orderby) | ||
92 | - } | ||
93 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | - } | ||
96 | - } else { | ||
97 | - if len(order) != 0 { | ||
98 | - return nil, errors.New("Error: unused 'order' fields") | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - var l []QuestionImage | ||
103 | - qs = qs.OrderBy(sortFields...) | ||
104 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | - if len(fields) == 0 { | ||
106 | - for _, v := range l { | ||
107 | - ml = append(ml, v) | ||
108 | - } | ||
109 | - } else { | ||
110 | - // trim unused fields | ||
111 | - for _, v := range l { | ||
112 | - m := make(map[string]interface{}) | ||
113 | - val := reflect.ValueOf(v) | ||
114 | - for _, fname := range fields { | ||
115 | - m[fname] = val.FieldByName(fname).Interface() | ||
116 | - } | ||
117 | - ml = append(ml, m) | ||
118 | - } | ||
119 | - } | ||
120 | - return ml, nil | ||
121 | - } | ||
122 | - return nil, err | ||
123 | -} | ||
124 | - | ||
125 | -// UpdateQuestionImage updates QuestionImage by Id and returns error if | ||
126 | -// the record to be updated doesn't exist | ||
127 | -func UpdateQuestionImageById(m *QuestionImage) (err error) { | ||
128 | - o := orm.NewOrm() | ||
129 | - v := QuestionImage{Id: m.Id} | ||
130 | - // ascertain id exists in the database | ||
131 | - if err = o.Read(&v); err == nil { | ||
132 | - var num int64 | ||
133 | - if num, err = o.Update(m); err == nil { | ||
134 | - fmt.Println("Number of records updated in database:", num) | ||
135 | - } | ||
136 | - } | ||
137 | - return | ||
138 | -} | ||
139 | - | ||
140 | -// DeleteQuestionImage deletes QuestionImage by Id and returns error if | ||
141 | -// the record to be deleted doesn't exist | ||
142 | -func DeleteQuestionImage(id int) (err error) { | ||
143 | - o := orm.NewOrm() | ||
144 | - v := QuestionImage{Id: id} | ||
145 | - // ascertain id exists in the database | ||
146 | - if err = o.Read(&v); err == nil { | ||
147 | - var num int64 | ||
148 | - if num, err = o.Delete(&QuestionImage{Id: id}); err == nil { | ||
149 | - fmt.Println("Number of records deleted in database:", num) | ||
150 | - } | ||
151 | - } | ||
152 | - return | ||
153 | -} |
models/question_score.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type QuestionScore struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - Uid int64 `orm:"column(uid);null" description:"评分用户ID"` | ||
16 | - Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
17 | - ScoreAnalyze int `orm:"column(scoreAnalyze);null"` | ||
18 | - ScoreAsk int `orm:"column(scoreAsk);null"` | ||
19 | - ScoreScheme int `orm:"column(scoreScheme);null"` | ||
20 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);null;auto_now_add" description:"评分时间"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *QuestionScore) TableName() string { | ||
24 | - return "question_score" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(QuestionScore)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddQuestionScore insert a new QuestionScore into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddQuestionScore(m *QuestionScore) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetQuestionScoreById retrieves QuestionScore by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetQuestionScoreById(id int) (v *QuestionScore, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &QuestionScore{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllQuestionScore retrieves all QuestionScore matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllQuestionScore(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(QuestionScore)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []QuestionScore | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateQuestionScore updates QuestionScore by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateQuestionScoreById(m *QuestionScore) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := QuestionScore{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteQuestionScore deletes QuestionScore by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteQuestionScore(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := QuestionScore{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&QuestionScore{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
models/question_speech.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type QuestionSpeech struct { | ||
13 | - Id int `orm:"column(id);pk"` | ||
14 | - Duration int `orm:"column(duration);null" description:"秒数"` | ||
15 | - Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
16 | - Path string `orm:"column(path);size(500);null" description:"语音路径"` | ||
17 | -} | ||
18 | - | ||
19 | -func (t *QuestionSpeech) TableName() string { | ||
20 | - return "question_speech" | ||
21 | -} | ||
22 | - | ||
23 | -func init() { | ||
24 | - orm.RegisterModel(new(QuestionSpeech)) | ||
25 | -} | ||
26 | - | ||
27 | -// AddQuestionSpeech insert a new QuestionSpeech into database and returns | ||
28 | -// last inserted Id on success. | ||
29 | -func AddQuestionSpeech(m *QuestionSpeech) (id int64, err error) { | ||
30 | - o := orm.NewOrm() | ||
31 | - id, err = o.Insert(m) | ||
32 | - return | ||
33 | -} | ||
34 | - | ||
35 | -// GetQuestionSpeechById retrieves QuestionSpeech by Id. Returns error if | ||
36 | -// Id doesn't exist | ||
37 | -func GetQuestionSpeechById(id int) (v *QuestionSpeech, err error) { | ||
38 | - o := orm.NewOrm() | ||
39 | - v = &QuestionSpeech{Id: id} | ||
40 | - if err = o.Read(v); err == nil { | ||
41 | - return v, nil | ||
42 | - } | ||
43 | - return nil, err | ||
44 | -} | ||
45 | - | ||
46 | -// GetAllQuestionSpeech retrieves all QuestionSpeech matches certain condition. Returns empty list if | ||
47 | -// no records exist | ||
48 | -func GetAllQuestionSpeech(query map[string]string, fields []string, sortby []string, order []string, | ||
49 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
50 | - o := orm.NewOrm() | ||
51 | - qs := o.QueryTable(new(QuestionSpeech)) | ||
52 | - // query k=v | ||
53 | - for k, v := range query { | ||
54 | - // rewrite dot-notation to Object__Attribute | ||
55 | - k = strings.Replace(k, ".", "__", -1) | ||
56 | - if strings.Contains(k, "isnull") { | ||
57 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
58 | - } else { | ||
59 | - qs = qs.Filter(k, v) | ||
60 | - } | ||
61 | - } | ||
62 | - // order by: | ||
63 | - var sortFields []string | ||
64 | - if len(sortby) != 0 { | ||
65 | - if len(sortby) == len(order) { | ||
66 | - // 1) for each sort field, there is an associated order | ||
67 | - for i, v := range sortby { | ||
68 | - orderby := "" | ||
69 | - if order[i] == "desc" { | ||
70 | - orderby = "-" + v | ||
71 | - } else if order[i] == "asc" { | ||
72 | - orderby = v | ||
73 | - } else { | ||
74 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
75 | - } | ||
76 | - sortFields = append(sortFields, orderby) | ||
77 | - } | ||
78 | - qs = qs.OrderBy(sortFields...) | ||
79 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
80 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
81 | - for _, v := range sortby { | ||
82 | - orderby := "" | ||
83 | - if order[0] == "desc" { | ||
84 | - orderby = "-" + v | ||
85 | - } else if order[0] == "asc" { | ||
86 | - orderby = v | ||
87 | - } else { | ||
88 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
89 | - } | ||
90 | - sortFields = append(sortFields, orderby) | ||
91 | - } | ||
92 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
93 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
94 | - } | ||
95 | - } else { | ||
96 | - if len(order) != 0 { | ||
97 | - return nil, errors.New("Error: unused 'order' fields") | ||
98 | - } | ||
99 | - } | ||
100 | - | ||
101 | - var l []QuestionSpeech | ||
102 | - qs = qs.OrderBy(sortFields...) | ||
103 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
104 | - if len(fields) == 0 { | ||
105 | - for _, v := range l { | ||
106 | - ml = append(ml, v) | ||
107 | - } | ||
108 | - } else { | ||
109 | - // trim unused fields | ||
110 | - for _, v := range l { | ||
111 | - m := make(map[string]interface{}) | ||
112 | - val := reflect.ValueOf(v) | ||
113 | - for _, fname := range fields { | ||
114 | - m[fname] = val.FieldByName(fname).Interface() | ||
115 | - } | ||
116 | - ml = append(ml, m) | ||
117 | - } | ||
118 | - } | ||
119 | - return ml, nil | ||
120 | - } | ||
121 | - return nil, err | ||
122 | -} | ||
123 | - | ||
124 | -// UpdateQuestionSpeech updates QuestionSpeech by Id and returns error if | ||
125 | -// the record to be updated doesn't exist | ||
126 | -func UpdateQuestionSpeechById(m *QuestionSpeech) (err error) { | ||
127 | - o := orm.NewOrm() | ||
128 | - v := QuestionSpeech{Id: m.Id} | ||
129 | - // ascertain id exists in the database | ||
130 | - if err = o.Read(&v); err == nil { | ||
131 | - var num int64 | ||
132 | - if num, err = o.Update(m); err == nil { | ||
133 | - fmt.Println("Number of records updated in database:", num) | ||
134 | - } | ||
135 | - } | ||
136 | - return | ||
137 | -} | ||
138 | - | ||
139 | -// DeleteQuestionSpeech deletes QuestionSpeech by Id and returns error if | ||
140 | -// the record to be deleted doesn't exist | ||
141 | -func DeleteQuestionSpeech(id int) (err error) { | ||
142 | - o := orm.NewOrm() | ||
143 | - v := QuestionSpeech{Id: id} | ||
144 | - // ascertain id exists in the database | ||
145 | - if err = o.Read(&v); err == nil { | ||
146 | - var num int64 | ||
147 | - if num, err = o.Delete(&QuestionSpeech{Id: id}); err == nil { | ||
148 | - fmt.Println("Number of records deleted in database:", num) | ||
149 | - } | ||
150 | - } | ||
151 | - return | ||
152 | -} |
models/roles.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type Roles struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - Name string `orm:"column(name);size(191)"` | ||
16 | - GuardName string `orm:"column(guard_name);size(191)"` | ||
17 | - CreatedAt time.Time `orm:"column(created_at);type(timestamp);null"` | ||
18 | - UpdatedAt time.Time `orm:"column(updated_at);type(timestamp);null"` | ||
19 | - ShowName string `orm:"column(show_name);size(191)"` | ||
20 | - Description string `orm:"column(description);size(191);null"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *Roles) TableName() string { | ||
24 | - return "roles" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(Roles)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddRoles insert a new Roles into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddRoles(m *Roles) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetRolesById retrieves Roles by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetRolesById(id int) (v *Roles, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &Roles{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllRoles retrieves all Roles matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllRoles(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(Roles)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []Roles | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateRoles updates Roles by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateRolesById(m *Roles) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := Roles{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteRoles deletes Roles by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteRoles(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := Roles{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&Roles{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
models/solution.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import "time" | ||
4 | - | ||
5 | -type Solution struct { | ||
6 | - Id_RENAME int64 `orm:"column(id)" description:"方案ID"` | ||
7 | - QuestionTitle string `orm:"column(questionTitle);size(500);null" description:"问题标题"` | ||
8 | - Uid int64 `orm:"column(uid)" description:"方案提供者"` | ||
9 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"方案创建时间"` | ||
10 | - Content string `orm:"column(content);null" description:"方案内容"` | ||
11 | - ScoreAnalyze int `orm:"column(scoreAnalyze);null" description:"分析评分(0-5对应分数)"` | ||
12 | - ScoreSolution int `orm:"column(scoreSolution);null" description:"解决评分(0-5对应分数)"` | ||
13 | - ScoreScheme int `orm:"column(scoreScheme);null" description:"方案评分(0-5对应分数)"` | ||
14 | - PageView int `orm:"column(pageView);null" description:"浏览总数"` | ||
15 | - CommentTotal int `orm:"column(commentTotal);null" description:"评论总数"` | ||
16 | - SympathyTotal int `orm:"column(sympathyTotal);null" description:"同感总数"` | ||
17 | - Qid int64 `orm:"column(qid);null" description:"问题ID"` | ||
18 | - Plevel int `orm:"column(plevel);null" description:"最新评分人等级"` | ||
19 | - Stype int `orm:"column(stype);null" description:"0备选方案 1解决方案"` | ||
20 | - SpfUid int64 `orm:"column(spfUid)"` | ||
21 | - UpdateTime time.Time `orm:"column(updateTime);type(timestamp);auto_now_add" description:"方案编辑更新时间"` | ||
22 | -} |
models/solution_image.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - | ||
9 | - "github.com/astaxie/beego/orm" | ||
10 | -) | ||
11 | - | ||
12 | -type SolutionImage struct { | ||
13 | - Id int `orm:"column(id);auto" description:"方案ID"` | ||
14 | - SolutionId int64 `orm:"column(solution_id)" description:"解决方案ID"` | ||
15 | - Path string `orm:"column(path);size(255)" description:"图片路径"` | ||
16 | - H int `orm:"column(h)"` | ||
17 | - W int `orm:"column(w)"` | ||
18 | -} | ||
19 | - | ||
20 | -func (t *SolutionImage) TableName() string { | ||
21 | - return "solution_image" | ||
22 | -} | ||
23 | - | ||
24 | -func init() { | ||
25 | - orm.RegisterModel(new(SolutionImage)) | ||
26 | -} | ||
27 | - | ||
28 | -// AddSolutionImage insert a new SolutionImage into database and returns | ||
29 | -// last inserted Id on success. | ||
30 | -func AddSolutionImage(m *SolutionImage) (id int64, err error) { | ||
31 | - o := orm.NewOrm() | ||
32 | - id, err = o.Insert(m) | ||
33 | - return | ||
34 | -} | ||
35 | - | ||
36 | -// GetSolutionImageById retrieves SolutionImage by Id. Returns error if | ||
37 | -// Id doesn't exist | ||
38 | -func GetSolutionImageById(id int) (v *SolutionImage, err error) { | ||
39 | - o := orm.NewOrm() | ||
40 | - v = &SolutionImage{Id: id} | ||
41 | - if err = o.Read(v); err == nil { | ||
42 | - return v, nil | ||
43 | - } | ||
44 | - return nil, err | ||
45 | -} | ||
46 | - | ||
47 | -// GetAllSolutionImage retrieves all SolutionImage matches certain condition. Returns empty list if | ||
48 | -// no records exist | ||
49 | -func GetAllSolutionImage(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | - o := orm.NewOrm() | ||
52 | - qs := o.QueryTable(new(SolutionImage)) | ||
53 | - // query k=v | ||
54 | - for k, v := range query { | ||
55 | - // rewrite dot-notation to Object__Attribute | ||
56 | - k = strings.Replace(k, ".", "__", -1) | ||
57 | - if strings.Contains(k, "isnull") { | ||
58 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | - } else { | ||
60 | - qs = qs.Filter(k, v) | ||
61 | - } | ||
62 | - } | ||
63 | - // order by: | ||
64 | - var sortFields []string | ||
65 | - if len(sortby) != 0 { | ||
66 | - if len(sortby) == len(order) { | ||
67 | - // 1) for each sort field, there is an associated order | ||
68 | - for i, v := range sortby { | ||
69 | - orderby := "" | ||
70 | - if order[i] == "desc" { | ||
71 | - orderby = "-" + v | ||
72 | - } else if order[i] == "asc" { | ||
73 | - orderby = v | ||
74 | - } else { | ||
75 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | - } | ||
77 | - sortFields = append(sortFields, orderby) | ||
78 | - } | ||
79 | - qs = qs.OrderBy(sortFields...) | ||
80 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | - for _, v := range sortby { | ||
83 | - orderby := "" | ||
84 | - if order[0] == "desc" { | ||
85 | - orderby = "-" + v | ||
86 | - } else if order[0] == "asc" { | ||
87 | - orderby = v | ||
88 | - } else { | ||
89 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | - } | ||
91 | - sortFields = append(sortFields, orderby) | ||
92 | - } | ||
93 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | - } | ||
96 | - } else { | ||
97 | - if len(order) != 0 { | ||
98 | - return nil, errors.New("Error: unused 'order' fields") | ||
99 | - } | ||
100 | - } | ||
101 | - | ||
102 | - var l []SolutionImage | ||
103 | - qs = qs.OrderBy(sortFields...) | ||
104 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | - if len(fields) == 0 { | ||
106 | - for _, v := range l { | ||
107 | - ml = append(ml, v) | ||
108 | - } | ||
109 | - } else { | ||
110 | - // trim unused fields | ||
111 | - for _, v := range l { | ||
112 | - m := make(map[string]interface{}) | ||
113 | - val := reflect.ValueOf(v) | ||
114 | - for _, fname := range fields { | ||
115 | - m[fname] = val.FieldByName(fname).Interface() | ||
116 | - } | ||
117 | - ml = append(ml, m) | ||
118 | - } | ||
119 | - } | ||
120 | - return ml, nil | ||
121 | - } | ||
122 | - return nil, err | ||
123 | -} | ||
124 | - | ||
125 | -// UpdateSolutionImage updates SolutionImage by Id and returns error if | ||
126 | -// the record to be updated doesn't exist | ||
127 | -func UpdateSolutionImageById(m *SolutionImage) (err error) { | ||
128 | - o := orm.NewOrm() | ||
129 | - v := SolutionImage{Id: m.Id} | ||
130 | - // ascertain id exists in the database | ||
131 | - if err = o.Read(&v); err == nil { | ||
132 | - var num int64 | ||
133 | - if num, err = o.Update(m); err == nil { | ||
134 | - fmt.Println("Number of records updated in database:", num) | ||
135 | - } | ||
136 | - } | ||
137 | - return | ||
138 | -} | ||
139 | - | ||
140 | -// DeleteSolutionImage deletes SolutionImage by Id and returns error if | ||
141 | -// the record to be deleted doesn't exist | ||
142 | -func DeleteSolutionImage(id int) (err error) { | ||
143 | - o := orm.NewOrm() | ||
144 | - v := SolutionImage{Id: id} | ||
145 | - // ascertain id exists in the database | ||
146 | - if err = o.Read(&v); err == nil { | ||
147 | - var num int64 | ||
148 | - if num, err = o.Delete(&SolutionImage{Id: id}); err == nil { | ||
149 | - fmt.Println("Number of records deleted in database:", num) | ||
150 | - } | ||
151 | - } | ||
152 | - return | ||
153 | -} |
models/solution_partner.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type SolutionPartner struct { | ||
14 | - Id int `orm:"column(id);auto"` | ||
15 | - Uid int64 `orm:"column(uid);null" description:"参与者用户ID"` | ||
16 | - Sid int64 `orm:"column(sid);null" description:"解决方案ID"` | ||
17 | - ScoreSolution int `orm:"column(scoreSolution);null"` | ||
18 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"评分时间"` | ||
19 | - Puid int64 `orm:"column(puid);null" description:"评分人用户ID"` | ||
20 | - Enabled int `orm:"column(enabled);null" description:"有效1 失效0"` | ||
21 | - Sort int `orm:"column(sort)" description:"排序字段"` | ||
22 | -} | ||
23 | - | ||
24 | -func (t *SolutionPartner) TableName() string { | ||
25 | - return "solution_partner" | ||
26 | -} | ||
27 | - | ||
28 | -func init() { | ||
29 | - orm.RegisterModel(new(SolutionPartner)) | ||
30 | -} | ||
31 | - | ||
32 | -// AddSolutionPartner insert a new SolutionPartner into database and returns | ||
33 | -// last inserted Id on success. | ||
34 | -func AddSolutionPartner(m *SolutionPartner) (id int64, err error) { | ||
35 | - o := orm.NewOrm() | ||
36 | - id, err = o.Insert(m) | ||
37 | - return | ||
38 | -} | ||
39 | - | ||
40 | -// GetSolutionPartnerById retrieves SolutionPartner by Id. Returns error if | ||
41 | -// Id doesn't exist | ||
42 | -func GetSolutionPartnerById(id int) (v *SolutionPartner, err error) { | ||
43 | - o := orm.NewOrm() | ||
44 | - v = &SolutionPartner{Id: id} | ||
45 | - if err = o.Read(v); err == nil { | ||
46 | - return v, nil | ||
47 | - } | ||
48 | - return nil, err | ||
49 | -} | ||
50 | - | ||
51 | -// GetAllSolutionPartner retrieves all SolutionPartner matches certain condition. Returns empty list if | ||
52 | -// no records exist | ||
53 | -func GetAllSolutionPartner(query map[string]string, fields []string, sortby []string, order []string, | ||
54 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
55 | - o := orm.NewOrm() | ||
56 | - qs := o.QueryTable(new(SolutionPartner)) | ||
57 | - // query k=v | ||
58 | - for k, v := range query { | ||
59 | - // rewrite dot-notation to Object__Attribute | ||
60 | - k = strings.Replace(k, ".", "__", -1) | ||
61 | - if strings.Contains(k, "isnull") { | ||
62 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
63 | - } else { | ||
64 | - qs = qs.Filter(k, v) | ||
65 | - } | ||
66 | - } | ||
67 | - // order by: | ||
68 | - var sortFields []string | ||
69 | - if len(sortby) != 0 { | ||
70 | - if len(sortby) == len(order) { | ||
71 | - // 1) for each sort field, there is an associated order | ||
72 | - for i, v := range sortby { | ||
73 | - orderby := "" | ||
74 | - if order[i] == "desc" { | ||
75 | - orderby = "-" + v | ||
76 | - } else if order[i] == "asc" { | ||
77 | - orderby = v | ||
78 | - } else { | ||
79 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
80 | - } | ||
81 | - sortFields = append(sortFields, orderby) | ||
82 | - } | ||
83 | - qs = qs.OrderBy(sortFields...) | ||
84 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
85 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
86 | - for _, v := range sortby { | ||
87 | - orderby := "" | ||
88 | - if order[0] == "desc" { | ||
89 | - orderby = "-" + v | ||
90 | - } else if order[0] == "asc" { | ||
91 | - orderby = v | ||
92 | - } else { | ||
93 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
94 | - } | ||
95 | - sortFields = append(sortFields, orderby) | ||
96 | - } | ||
97 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
98 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
99 | - } | ||
100 | - } else { | ||
101 | - if len(order) != 0 { | ||
102 | - return nil, errors.New("Error: unused 'order' fields") | ||
103 | - } | ||
104 | - } | ||
105 | - | ||
106 | - var l []SolutionPartner | ||
107 | - qs = qs.OrderBy(sortFields...) | ||
108 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
109 | - if len(fields) == 0 { | ||
110 | - for _, v := range l { | ||
111 | - ml = append(ml, v) | ||
112 | - } | ||
113 | - } else { | ||
114 | - // trim unused fields | ||
115 | - for _, v := range l { | ||
116 | - m := make(map[string]interface{}) | ||
117 | - val := reflect.ValueOf(v) | ||
118 | - for _, fname := range fields { | ||
119 | - m[fname] = val.FieldByName(fname).Interface() | ||
120 | - } | ||
121 | - ml = append(ml, m) | ||
122 | - } | ||
123 | - } | ||
124 | - return ml, nil | ||
125 | - } | ||
126 | - return nil, err | ||
127 | -} | ||
128 | - | ||
129 | -// UpdateSolutionPartner updates SolutionPartner by Id and returns error if | ||
130 | -// the record to be updated doesn't exist | ||
131 | -func UpdateSolutionPartnerById(m *SolutionPartner) (err error) { | ||
132 | - o := orm.NewOrm() | ||
133 | - v := SolutionPartner{Id: m.Id} | ||
134 | - // ascertain id exists in the database | ||
135 | - if err = o.Read(&v); err == nil { | ||
136 | - var num int64 | ||
137 | - if num, err = o.Update(m); err == nil { | ||
138 | - fmt.Println("Number of records updated in database:", num) | ||
139 | - } | ||
140 | - } | ||
141 | - return | ||
142 | -} | ||
143 | - | ||
144 | -// DeleteSolutionPartner deletes SolutionPartner by Id and returns error if | ||
145 | -// the record to be deleted doesn't exist | ||
146 | -func DeleteSolutionPartner(id int) (err error) { | ||
147 | - o := orm.NewOrm() | ||
148 | - v := SolutionPartner{Id: id} | ||
149 | - // ascertain id exists in the database | ||
150 | - if err = o.Read(&v); err == nil { | ||
151 | - var num int64 | ||
152 | - if num, err = o.Delete(&SolutionPartner{Id: id}); err == nil { | ||
153 | - fmt.Println("Number of records deleted in database:", num) | ||
154 | - } | ||
155 | - } | ||
156 | - return | ||
157 | -} |
models/solution_score.go
已删除
100755 → 0
1 | -package models | ||
2 | - | ||
3 | -import ( | ||
4 | - "errors" | ||
5 | - "fmt" | ||
6 | - "reflect" | ||
7 | - "strings" | ||
8 | - "time" | ||
9 | - | ||
10 | - "github.com/astaxie/beego/orm" | ||
11 | -) | ||
12 | - | ||
13 | -type SolutionScore struct { | ||
14 | - Id int `orm:"column(id);pk"` | ||
15 | - Uid int64 `orm:"column(uid);null" description:"评分用户ID"` | ||
16 | - Sid int64 `orm:"column(sid);null" description:"所属的问题ID"` | ||
17 | - ScoreAnalyze int `orm:"column(scoreAnalyze);null"` | ||
18 | - ScoreScheme int `orm:"column(scoreScheme);null"` | ||
19 | - ScoreSolution int `orm:"column(scoreSolution);null"` | ||
20 | - CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now" description:"评分时间"` | ||
21 | -} | ||
22 | - | ||
23 | -func (t *SolutionScore) TableName() string { | ||
24 | - return "solution_score" | ||
25 | -} | ||
26 | - | ||
27 | -func init() { | ||
28 | - orm.RegisterModel(new(SolutionScore)) | ||
29 | -} | ||
30 | - | ||
31 | -// AddSolutionScore insert a new SolutionScore into database and returns | ||
32 | -// last inserted Id on success. | ||
33 | -func AddSolutionScore(m *SolutionScore) (id int64, err error) { | ||
34 | - o := orm.NewOrm() | ||
35 | - id, err = o.Insert(m) | ||
36 | - return | ||
37 | -} | ||
38 | - | ||
39 | -// GetSolutionScoreById retrieves SolutionScore by Id. Returns error if | ||
40 | -// Id doesn't exist | ||
41 | -func GetSolutionScoreById(id int) (v *SolutionScore, err error) { | ||
42 | - o := orm.NewOrm() | ||
43 | - v = &SolutionScore{Id: id} | ||
44 | - if err = o.Read(v); err == nil { | ||
45 | - return v, nil | ||
46 | - } | ||
47 | - return nil, err | ||
48 | -} | ||
49 | - | ||
50 | -// GetAllSolutionScore retrieves all SolutionScore matches certain condition. Returns empty list if | ||
51 | -// no records exist | ||
52 | -func GetAllSolutionScore(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | - offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | - o := orm.NewOrm() | ||
55 | - qs := o.QueryTable(new(SolutionScore)) | ||
56 | - // query k=v | ||
57 | - for k, v := range query { | ||
58 | - // rewrite dot-notation to Object__Attribute | ||
59 | - k = strings.Replace(k, ".", "__", -1) | ||
60 | - if strings.Contains(k, "isnull") { | ||
61 | - qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | - } else { | ||
63 | - qs = qs.Filter(k, v) | ||
64 | - } | ||
65 | - } | ||
66 | - // order by: | ||
67 | - var sortFields []string | ||
68 | - if len(sortby) != 0 { | ||
69 | - if len(sortby) == len(order) { | ||
70 | - // 1) for each sort field, there is an associated order | ||
71 | - for i, v := range sortby { | ||
72 | - orderby := "" | ||
73 | - if order[i] == "desc" { | ||
74 | - orderby = "-" + v | ||
75 | - } else if order[i] == "asc" { | ||
76 | - orderby = v | ||
77 | - } else { | ||
78 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | - } | ||
80 | - sortFields = append(sortFields, orderby) | ||
81 | - } | ||
82 | - qs = qs.OrderBy(sortFields...) | ||
83 | - } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | - // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | - for _, v := range sortby { | ||
86 | - orderby := "" | ||
87 | - if order[0] == "desc" { | ||
88 | - orderby = "-" + v | ||
89 | - } else if order[0] == "asc" { | ||
90 | - orderby = v | ||
91 | - } else { | ||
92 | - return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | - } | ||
94 | - sortFields = append(sortFields, orderby) | ||
95 | - } | ||
96 | - } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | - return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | - } | ||
99 | - } else { | ||
100 | - if len(order) != 0 { | ||
101 | - return nil, errors.New("Error: unused 'order' fields") | ||
102 | - } | ||
103 | - } | ||
104 | - | ||
105 | - var l []SolutionScore | ||
106 | - qs = qs.OrderBy(sortFields...) | ||
107 | - if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | - if len(fields) == 0 { | ||
109 | - for _, v := range l { | ||
110 | - ml = append(ml, v) | ||
111 | - } | ||
112 | - } else { | ||
113 | - // trim unused fields | ||
114 | - for _, v := range l { | ||
115 | - m := make(map[string]interface{}) | ||
116 | - val := reflect.ValueOf(v) | ||
117 | - for _, fname := range fields { | ||
118 | - m[fname] = val.FieldByName(fname).Interface() | ||
119 | - } | ||
120 | - ml = append(ml, m) | ||
121 | - } | ||
122 | - } | ||
123 | - return ml, nil | ||
124 | - } | ||
125 | - return nil, err | ||
126 | -} | ||
127 | - | ||
128 | -// UpdateSolutionScore updates SolutionScore by Id and returns error if | ||
129 | -// the record to be updated doesn't exist | ||
130 | -func UpdateSolutionScoreById(m *SolutionScore) (err error) { | ||
131 | - o := orm.NewOrm() | ||
132 | - v := SolutionScore{Id: m.Id} | ||
133 | - // ascertain id exists in the database | ||
134 | - if err = o.Read(&v); err == nil { | ||
135 | - var num int64 | ||
136 | - if num, err = o.Update(m); err == nil { | ||
137 | - fmt.Println("Number of records updated in database:", num) | ||
138 | - } | ||
139 | - } | ||
140 | - return | ||
141 | -} | ||
142 | - | ||
143 | -// DeleteSolutionScore deletes SolutionScore by Id and returns error if | ||
144 | -// the record to be deleted doesn't exist | ||
145 | -func DeleteSolutionScore(id int) (err error) { | ||
146 | - o := orm.NewOrm() | ||
147 | - v := SolutionScore{Id: id} | ||
148 | - // ascertain id exists in the database | ||
149 | - if err = o.Read(&v); err == nil { | ||
150 | - var num int64 | ||
151 | - if num, err = o.Delete(&SolutionScore{Id: id}); err == nil { | ||
152 | - fmt.Println("Number of records deleted in database:", num) | ||
153 | - } | ||
154 | - } | ||
155 | - return | ||
156 | -} |
-
请 注册 或 登录 后发表评论