|
|
package models
|
|
|
|
|
|
import (
|
|
|
"fmt"
|
|
|
"oppmg/common/log"
|
|
|
"time"
|
|
|
|
|
|
"github.com/astaxie/beego/orm"
|
...
|
...
|
@@ -28,9 +28,8 @@ func init() { |
|
|
|
|
|
// AddRankItem insert a new NewRankItem into database and returns
|
|
|
// last inserted Id on success.
|
|
|
func AddRankItem(m *RankItem) (id int64, err error) {
|
|
|
o := orm.NewOrm()
|
|
|
id, err = o.Insert(m)
|
|
|
func AddRankItem(m []RankItem, om orm.Ormer) (successSum int64, err error) {
|
|
|
successSum, err = om.InsertMulti(10, &m)
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
@@ -45,21 +44,6 @@ func GetRankItemById(id int64) (v *RankItem, err error) { |
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
// UpdateRankItem updates RankItem by Id and returns error if
|
|
|
// the record to be updated doesn't exist
|
|
|
func UpdateRankItemById(m *RankItem) (err error) {
|
|
|
o := orm.NewOrm()
|
|
|
v := RankItem{Id: m.Id}
|
|
|
// ascertain id exists in the database
|
|
|
if err = o.Read(&v); err == nil {
|
|
|
var num int64
|
|
|
if num, err = o.Update(m); err == nil {
|
|
|
fmt.Println("Number of records updated in database:", num)
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, error) {
|
|
|
var (
|
|
|
data []RankItem
|
...
|
...
|
@@ -75,3 +59,22 @@ func GetRankItemByCompanyid(companyid int64, rankTypeId int64) ([]RankItem, erro |
|
|
}
|
|
|
return data, err
|
|
|
}
|
|
|
|
|
|
func DeleteRanKItemByIds(ids []int64, om orm.Ormer) error {
|
|
|
_, err := om.QueryTable(&RankItem{}).Filter("id__in", ids).Delete()
|
|
|
return err
|
|
|
}
|
|
|
|
|
|
// UpdateRankItem updates RankItem by Id and returns error if
|
|
|
// the record to be updated doesn't exist
|
|
|
func UpdateRankItemById(m *RankItem, cols []string, om orm.Ormer) (err error) {
|
|
|
if len(cols) > 0 {
|
|
|
cols = append(cols, "UpdateAt")
|
|
|
}
|
|
|
m.UpdateAt = time.Now()
|
|
|
var num int64
|
|
|
if num, err = om.Update(m, cols...); err == nil {
|
|
|
log.Info("Number of records updated in database:", num)
|
|
|
}
|
|
|
return
|
|
|
} |
...
|
...
|
|