1
|
package models
|
1
|
package models
|
2
|
|
2
|
|
3
|
import (
|
3
|
import (
|
4
|
- "fmt"
|
4
|
+ "oppmg/common/log"
|
5
|
"time"
|
5
|
"time"
|
6
|
|
6
|
|
7
|
"github.com/astaxie/beego/orm"
|
7
|
"github.com/astaxie/beego/orm"
|
|
@@ -28,9 +28,8 @@ func init() { |
|
@@ -28,9 +28,8 @@ func init() { |
28
|
|
28
|
|
29
|
// AddRankItem insert a new NewRankItem into database and returns
|
29
|
// AddRankItem insert a new NewRankItem into database and returns
|
30
|
// last inserted Id on success.
|
30
|
// last inserted Id on success.
|
31
|
-func AddRankItem(m *RankItem) (id int64, err error) {
|
|
|
32
|
- o := orm.NewOrm()
|
|
|
33
|
- id, err = o.Insert(m)
|
31
|
+func AddRankItem(m []RankItem, om orm.Ormer) (successSum int64, err error) {
|
|
|
32
|
+ successSum, err = om.InsertMulti(10, &m)
|
34
|
return
|
33
|
return
|
35
|
}
|
34
|
}
|
36
|
|
35
|
|
|
@@ -45,21 +44,6 @@ func GetRankItemById(id int64) (v *RankItem, err error) { |
|
@@ -45,21 +44,6 @@ func GetRankItemById(id int64) (v *RankItem, err error) { |
45
|
return nil, err
|
44
|
return nil, err
|
46
|
}
|
45
|
}
|
47
|
|
46
|
|
48
|
-// UpdateRankItem updates RankItem by Id and returns error if
|
|
|
49
|
-// the record to be updated doesn't exist
|
|
|
50
|
-func UpdateRankItemById(m *RankItem) (err error) {
|
|
|
51
|
- o := orm.NewOrm()
|
|
|
52
|
- v := RankItem{Id: m.Id}
|
|
|
53
|
- // ascertain id exists in the database
|
|
|
54
|
- if err = o.Read(&v); err == nil {
|
|
|
55
|
- var num int64
|
|
|
56
|
- if num, err = o.Update(m); err == nil {
|
|
|
57
|
- fmt.Println("Number of records updated in database:", num)
|
|
|
58
|
- }
|
|
|
59
|
- }
|
|
|
60
|
- return
|
|
|
61
|
-}
|
|
|
62
|
-
|
|
|
63
|
func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, error) {
|
47
|
func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, error) {
|
64
|
var (
|
48
|
var (
|
65
|
data []RankItem
|
49
|
data []RankItem
|
|
@@ -75,3 +59,22 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro |
|
@@ -75,3 +59,22 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro |
75
|
}
|
59
|
}
|
76
|
return data, err
|
60
|
return data, err
|
77
|
}
|
61
|
}
|
|
|
62
|
+
|
|
|
63
|
+func DeleteRanKItemByIds(ids []int64, om orm.Ormer) error {
|
|
|
64
|
+ _, err := om.QueryTable(&RankItem{}).Filter("id__in", ids).Delete()
|
|
|
65
|
+ return err
|
|
|
66
|
+}
|
|
|
67
|
+
|
|
|
68
|
+// UpdateRankItem updates RankItem by Id and returns error if
|
|
|
69
|
+// the record to be updated doesn't exist
|
|
|
70
|
+func UpdateRankItemById(m *RankItem, cols []string, om orm.Ormer) (err error) {
|
|
|
71
|
+ if len(cols) > 0 {
|
|
|
72
|
+ cols = append(cols, "UpdateAt")
|
|
|
73
|
+ }
|
|
|
74
|
+ m.UpdateAt = time.Now()
|
|
|
75
|
+ var num int64
|
|
|
76
|
+ if num, err = om.Update(m, cols...); err == nil {
|
|
|
77
|
+ log.Info("Number of records updated in database:", num)
|
|
|
78
|
+ }
|
|
|
79
|
+ return
|
|
|
80
|
+} |