Create & Init Project...

This commit is contained in:
2019-04-22 18:49:16 +08:00
commit fc4fa37393
25440 changed files with 4054998 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"archive_test.go",
"av_charge_statis_test.go",
"av_charge_test.go",
"av_income_stat_test.go",
"av_income_test.go",
"bgm_income_stat_test.go",
"bgm_income_test.go",
"bgm_test.go",
"blacklist_test.go",
"business_order_test.go",
"charge_ratio_test.go",
"column_charge_test.go",
"column_income_stat_test.go",
"column_income_test.go",
"dao_test.go",
"income_date_statis_test.go",
"lottery_test.go",
"up_account_test.go",
"up_charge_test.go",
"up_income_date_test.go",
"up_income_stat_test.go",
"up_income_test.go",
"up_info_video_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/job/main/growup/conf:go_default_library",
"//app/job/main/growup/model/income:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"av_charge.go",
"av_charge_statis.go",
"av_income.go",
"av_income_stat.go",
"bgm.go",
"bgm_income.go",
"bgm_income_stat.go",
"blacklist.go",
"business_order.go",
"charge_ratio.go",
"column_charge.go",
"column_income.go",
"column_income_stat.go",
"dao.go",
"income_date_statis.go",
"lottery.go",
"up_account.go",
"up_charge.go",
"up_income.go",
"up_income_date.go",
"up_income_stat.go",
"up_info_video.go",
],
importpath = "go-common/app/job/main/growup/dao/income",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/job/main/growup/conf:go_default_library",
"//app/job/main/growup/model/income:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/time:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,58 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_getArchiveByDateSQL = "SELECT id, %s, mid, tag_id, income, date FROM %s WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
_getBgmIncomeByDateSQL = "SELECT id, sid, mid, income, date FROM bgm_income WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
)
// GetArchiveByDate get archive by date
func (d *Dao) GetArchiveByDate(c context.Context, aid, table, date string, id int64, limit int) (archives []*model.ArchiveIncome, err error) {
archives = make([]*model.ArchiveIncome, 0)
rows, err := d.db.Query(c, fmt.Sprintf(_getArchiveByDateSQL, aid, table), id, date, limit)
if err != nil {
log.Error("GetArchiveByDate d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
archive := &model.ArchiveIncome{}
err = rows.Scan(&archive.ID, &archive.AID, &archive.MID, &archive.TagID, &archive.Income, &archive.Date)
if err != nil {
log.Error("GetArchiveByDate rows.Scan error(%v)", err)
return
}
archives = append(archives, archive)
}
return
}
// GetBgmIncomeByDate get bgm income by date
func (d *Dao) GetBgmIncomeByDate(c context.Context, date string, id int64, limit int) (archives []*model.ArchiveIncome, err error) {
archives = make([]*model.ArchiveIncome, 0)
rows, err := d.db.Query(c, _getBgmIncomeByDateSQL, id, date, limit)
if err != nil {
log.Error("GetArchiveByDate d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
archive := &model.ArchiveIncome{}
err = rows.Scan(&archive.ID, &archive.AID, &archive.MID, &archive.Income, &archive.Date)
if err != nil {
log.Error("GetArchiveByDate rows.Scan error(%v)", err)
return
}
archives = append(archives, archive)
}
return
}

View File

@@ -0,0 +1,46 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeGetArchiveByDate(t *testing.T) {
convey.Convey("GetArchiveByDate", t, func(ctx convey.C) {
var (
c = context.Background()
aid = "av_id"
table = "av_income"
date = "2018-06-24"
id = int64(0)
limit = int(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
archives, err := d.GetArchiveByDate(c, aid, table, date, id, limit)
ctx.Convey("Then err should be nil.archives should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(archives, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeGetBgmIncomeByDate(t *testing.T) {
convey.Convey("GetBgmIncomeByDate", t, func(ctx convey.C) {
var (
c = context.Background()
date = "2018-06-24"
id = int64(0)
limit = int(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
archives, err := d.GetBgmIncomeByDate(c, date, id, limit)
ctx.Convey("Then err should be nil.archives should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(archives, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,94 @@
package income
import (
"context"
"fmt"
"strconv"
"time"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_layout = "2006-01-02"
_avDailyChargeSQL = "SELECT id,av_id,mid,tag_id,is_original,upload_time,danmaku_count,comment_count,collect_count,coin_count,share_count,elec_pay_count,total_play_count,web_play_count,app_play_count,h5_play_count,lv_unknown,lv_0,lv_1,lv_2,lv_3,lv_4,lv_5,lv_6,v_score,inc_charge,total_charge,date,is_deleted,ctime,mtime FROM av_daily_charge_%s WHERE id > ? AND date = ? AND inc_charge > 0 ORDER BY id LIMIT ?"
_avWeeklyChargeSQL = "SELECT id,av_id,mid,tag_id,is_original,upload_time,danmaku_count,comment_count,collect_count,coin_count,share_count,elec_pay_count,total_play_count,web_play_count,app_play_count,h5_play_count,lv_unknown,lv_0,lv_1,lv_2,lv_3,lv_4,lv_5,lv_6,v_score,inc_charge,total_charge,date,is_deleted,ctime,mtime FROM av_weekly_charge WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
_avMonthlyChargeSQL = "SELECT id,av_id,mid,tag_id,is_original,upload_time,danmaku_count,comment_count,collect_count,coin_count,share_count,elec_pay_count,total_play_count,web_play_count,app_play_count,h5_play_count,lv_unknown,lv_0,lv_1,lv_2,lv_3,lv_4,lv_5,lv_6,v_score,inc_charge,total_charge,date,is_deleted,ctime,mtime FROM av_monthly_charge WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
_inAvChargeTableSQL = "INSERT INTO %s(av_id,mid,tag_id,is_original,danmaku_count,comment_count,collect_count,coin_count,share_count,elec_pay_count,total_play_count,web_play_count,app_play_count,h5_play_count,lv_unknown,lv_0,lv_1,lv_2,lv_3,lv_4,lv_5,lv_6,v_score,inc_charge,total_charge,date,upload_time) VALUES %s ON DUPLICATE KEY UPDATE danmaku_count=VALUES(danmaku_count),comment_count=VALUES(comment_count),collect_count=VALUES(collect_count),coin_count=VALUES(coin_count),share_count=VALUES(share_count),elec_pay_count=VALUES(elec_pay_count),total_play_count=VALUES(total_play_count),web_play_count=VALUES(web_play_count),app_play_count=VALUES(app_play_count),h5_play_count=VALUES(h5_play_count),lv_unknown=VALUES(lv_unknown),lv_0=VALUES(lv_0),lv_1=VALUES(lv_1),lv_2=VALUES(lv_2),lv_3=VALUES(lv_3),lv_4=VALUES(lv_4),lv_5=VALUES(lv_5),lv_6=VALUES(lv_6),v_score=VALUES(v_score),inc_charge=VALUES(inc_charge),total_charge=VALUES(total_charge)"
_inColumnChargeTableSQL = "INSERT INTO %s(aid,title,mid,tag_id,inc_charge,date,upload_time) VALUES %s"
)
// IAvCharge av charge func
type IAvCharge func(c context.Context, date time.Time, id int64, limit int) (data []*model.AvCharge, err error)
// AvDailyCharge get av daily charge by date
func (d *Dao) AvDailyCharge(c context.Context, date time.Time, id int64, limit int) (data []*model.AvCharge, err error) {
month := date.Month()
monthStr := strconv.Itoa(int(month))
if month < 10 {
monthStr = "0" + monthStr
}
return d.GetAvCharge(c, fmt.Sprintf(_avDailyChargeSQL, monthStr), date.Format(_layout), id, limit)
}
// AvWeeklyCharge get av weekly charge
func (d *Dao) AvWeeklyCharge(c context.Context, date time.Time, id int64, limit int) (data []*model.AvCharge, err error) {
return d.GetAvCharge(c, _avWeeklyChargeSQL, date.Format(_layout), id, limit)
}
// AvMonthlyCharge get av monthly charge
func (d *Dao) AvMonthlyCharge(c context.Context, date time.Time, id int64, limit int) (data []*model.AvCharge, err error) {
return d.GetAvCharge(c, _avMonthlyChargeSQL, date.Format(_layout), id, limit)
}
// GetAvCharge get av charge by sql required
func (d *Dao) GetAvCharge(c context.Context, sql string, date string, id int64, limit int) (data []*model.AvCharge, err error) {
rows, err := d.db.Query(c, sql, id, date, limit)
if err != nil {
log.Error("d.Query av_charge(%s) error(%v)", sql, err)
return
}
defer rows.Close()
for rows.Next() {
adc := &model.AvCharge{}
err = rows.Scan(&adc.ID, &adc.AvID, &adc.MID, &adc.TagID, &adc.IsOriginal, &adc.UploadTime, &adc.DanmakuCount, &adc.CommentCount, &adc.CollectCount, &adc.CoinCount, &adc.ShareCount, &adc.ElecPayCount, &adc.TotalPlayCount, &adc.WebPlayCount, &adc.AppPlayCount, &adc.H5PlayCount, &adc.LvUnknown, &adc.Lv0, &adc.Lv1, &adc.Lv2, &adc.Lv3, &adc.Lv4, &adc.Lv5, &adc.Lv6, &adc.VScore, &adc.IncCharge, &adc.TotalCharge, &adc.Date, &adc.IsDeleted, &adc.CTime, &adc.MTime)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
data = append(data, adc)
}
return
}
// InsertAvChargeTable add av charge batch
func (d *Dao) InsertAvChargeTable(c context.Context, vals, table string) (rows int64, err error) {
if vals == "" {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_inAvChargeTableSQL, table, vals))
if err != nil {
log.Error("InsertAvChargeTable(%s) tx.Exec error(%v)", table, err)
return
}
return res.RowsAffected()
}
// InsertColumnChargeTable add av charge batch
func (d *Dao) InsertColumnChargeTable(c context.Context, vals, table string) (rows int64, err error) {
if vals == "" {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_inColumnChargeTableSQL, table, vals))
if err != nil {
log.Error("InsertColumnChargeTable(%s) tx.Exec error(%v)", table, err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,49 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_avChargeStatisSQL = "SELECT id,av_id,mid,total_charge FROM av_charge_statis WHERE id > ? ORDER BY id LIMIT ?"
_inAvChargeStatisSQL = "INSERT INTO av_charge_statis(av_id,mid,tag_id,is_original,total_charge,upload_time) VALUES %s ON DUPLICATE KEY UPDATE total_charge=VALUES(total_charge)"
)
// AvChargeStatis get av_charge_statis
func (d *Dao) AvChargeStatis(c context.Context, id int64, limit int) (data []*model.AvChargeStatis, err error) {
rows, err := d.db.Query(c, _avChargeStatisSQL, id, limit)
if err != nil {
log.Error("d.Query av_charge_statis error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
ads := &model.AvChargeStatis{}
err = rows.Scan(&ads.ID, &ads.AvID, &ads.MID, &ads.TotalCharge)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
data = append(data, ads)
}
return
}
// InsertAvChargeStatisBatch add av charge statis batch
func (d *Dao) InsertAvChargeStatisBatch(c context.Context, vals string) (count int64, err error) {
if vals == "" {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_inAvChargeStatisSQL, vals))
if err != nil {
log.Error("InsertAvChargeStatisBatch d.db.Exec error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,96 @@
package income
import (
"bytes"
"context"
"strconv"
"testing"
"time"
model "go-common/app/job/main/growup/model/income"
xtime "go-common/library/time"
. "github.com/smartystreets/goconvey/convey"
)
func Test_AvChargeStatis(t *testing.T) {
Convey("AvChargeStatis", t, func() {
_, err := d.AvChargeStatis(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_InsertAvChargeStatisBatch(t *testing.T) {
Convey("InsertAvChargeStatisBatch", t, func() {
c := context.Background()
d.db.Exec(c, "DELETE FROM av_charge_statis where av_id = 11")
avChargeStatis := []*model.AvChargeStatis{}
value := &model.AvChargeStatis{
AvID: 11,
MID: 11,
TagID: 11,
}
avChargeStatis = append(avChargeStatis, value)
vals := assembleAvChargeStatis(avChargeStatis)
count, err := d.InsertAvChargeStatisBatch(c, vals)
So(err, ShouldBeNil)
So(count, ShouldEqual, 1)
d.db.Exec(c, "DELETE FROM av_charge_statis where av_id = 11")
})
}
func benchmarkInsertAvChargeStatisBatch(size int64, b *testing.B) {
avChargeStatis := make([]*model.AvChargeStatis, size)
var i int64
for i = 0; i < size; i++ {
avChargeStatis[i] = &model.AvChargeStatis{
AvID: i,
MID: i,
TagID: i,
IsOriginal: int(i),
UploadTime: xtime.Time(time.Now().Unix()),
TotalCharge: i,
}
}
vals := assembleAvChargeStatis(avChargeStatis)
for n := 0; n < b.N; n++ {
d.InsertAvChargeStatisBatch(context.Background(), vals)
}
}
func BenchmarkInsertAvChargeStatisBatch100(b *testing.B) { benchmarkInsertAvChargeStatisBatch(100, b) }
func BenchmarkInsertAvChargeStatisBatch1000(b *testing.B) { benchmarkInsertAvChargeStatisBatch(1000, b) }
func BenchmarkInsertAvChargeStatisBatch10000(b *testing.B) {
benchmarkInsertAvChargeStatisBatch(10000, b)
}
func assembleAvChargeStatis(avChargeStatis []*model.AvChargeStatis) (vals string) {
var buf bytes.Buffer
for _, row := range avChargeStatis {
buf.WriteString("(")
buf.WriteString(strconv.FormatInt(row.AvID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.MID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.TagID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.Itoa(row.IsOriginal))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.TotalCharge, 10))
buf.WriteByte(',')
buf.WriteString(row.UploadTime.Time().Format(_layout))
buf.WriteString(")")
buf.WriteByte(',')
}
if buf.Len() > 0 {
buf.Truncate(buf.Len() - 1)
}
vals = buf.String()
buf.Reset()
return
}

View File

@@ -0,0 +1,129 @@
package income
import (
"bytes"
"context"
"strconv"
"testing"
"time"
model "go-common/app/job/main/growup/model/income"
//xtime "go-common/library/time"
. "github.com/smartystreets/goconvey/convey"
)
func Test_AvDailyCharge(t *testing.T) {
Convey("AvDailyCharge", t, func() {
_, err := d.AvDailyCharge(context.Background(), time.Now(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_AvWeeklyCharge(t *testing.T) {
Convey("AvWeeklyCharge", t, func() {
_, err := d.AvWeeklyCharge(context.Background(), time.Now(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_AvMonthlyCharge(t *testing.T) {
Convey("AvMonthlyCharge", t, func() {
_, err := d.AvMonthlyCharge(context.Background(), time.Now(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_InsertAvChargeTable(t *testing.T) {
Convey("InsertAvChargeTable", t, func() {
c := context.Background()
d.db.Exec(c, "DELETE FROM av_weekly_charge where av_id = 11")
avCharge := []*model.AvCharge{}
value := &model.AvCharge{
AvID: 11,
MID: 11,
TagID: 11,
}
avCharge = append(avCharge, value)
vals := assembleAvCharge(avCharge)
count, err := d.InsertAvChargeTable(c, vals, "av_weekly_charge")
So(err, ShouldBeNil)
So(count, ShouldEqual, 1)
d.db.Exec(c, "DELETE FROM av_weekly_charge where av_id = 11")
})
}
func assembleAvCharge(avCharge []*model.AvCharge) (vals string) {
var buf bytes.Buffer
for _, row := range avCharge {
buf.WriteString("(")
buf.WriteString(strconv.FormatInt(row.AvID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.MID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.TagID, 10))
buf.WriteByte(',')
buf.WriteString(strconv.Itoa(row.IsOriginal))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.DanmakuCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.CommentCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.CollectCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.CoinCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.ShareCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.ElecPayCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.TotalPlayCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.WebPlayCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.AppPlayCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.H5PlayCount, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.LvUnknown, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv0, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv1, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv2, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv3, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv4, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv5, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.Lv6, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.VScore, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.IncCharge, 10))
buf.WriteByte(',')
buf.WriteString(strconv.FormatInt(row.TotalCharge, 10))
buf.WriteByte(',')
buf.WriteByte('\'')
buf.WriteString(row.Date.Time().Format(_layout))
buf.WriteByte('\'')
buf.WriteByte(',')
buf.WriteByte('\'')
buf.WriteString(row.UploadTime.Time().Format(_layout))
buf.WriteByte('\'')
buf.WriteString(")")
buf.WriteByte(',')
}
if buf.Len() > 0 {
buf.Truncate(buf.Len() - 1)
}
vals = buf.String()
buf.Reset()
return
}

View File

@@ -0,0 +1,19 @@
package income
import (
"context"
"fmt"
)
const (
_inAvIncomeSQL = "INSERT INTO av_income(av_id,mid,tag_id,is_original,upload_time,play_count,total_income,income,tax_money,date,base_income) VALUES %s ON DUPLICATE KEY UPDATE av_id=VALUES(av_id),mid=VALUES(mid),tag_id=VALUES(tag_id),is_original=VALUES(is_original),upload_time=VALUES(upload_time),play_count=VALUES(play_count),total_income=VALUES(total_income),income=VALUES(income),tax_money=VALUES(tax_money),date=VALUES(date),base_income=VALUES(base_income)"
)
// InsertAvIncome batch insert av income
func (d *Dao) InsertAvIncome(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inAvIncomeSQL, values))
if err != nil {
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,45 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_avIncomeStatSQL = "SELECT id,av_id,mid,tag_id,is_original,upload_time,total_income,ctime FROM av_income_statis WHERE id > ? ORDER BY id LIMIT ?"
_inAvIncomeStatSQL = "INSERT INTO av_income_statis(av_id,mid,tag_id,is_original,upload_time,total_income) VALUES %s ON DUPLICATE KEY UPDATE av_id=VALUES(av_id),mid=VALUES(mid),tag_id=VALUES(tag_id),is_original=VALUES(is_original),upload_time=VALUES(upload_time),total_income=VALUES(total_income)"
)
// AvIncomeStat key: av_id
func (d *Dao) AvIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.AvIncomeStat, last int64, err error) {
rows, err := d.db.Query(c, _avIncomeStatSQL, id, limit)
if err != nil {
log.Error("d.db.Query AvIncomeStat error(%v)", err)
return
}
defer rows.Close()
m = make(map[int64]*model.AvIncomeStat)
for rows.Next() {
a := &model.AvIncomeStat{}
err = rows.Scan(&last, &a.AvID, &a.MID, &a.TagID, &a.IsOriginal, &a.UploadTime, &a.TotalIncome, &a.CTime)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
m[a.AvID] = a
}
return
}
// InsertAvIncomeStat batch insert av income stat
func (d *Dao) InsertAvIncomeStat(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inAvIncomeStatSQL, values))
if err != nil {
log.Error("d.db.Exec InsertAvIncomeStat error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,22 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_AvIncomeStat(t *testing.T) {
Convey("AvIncomeStat", t, func() {
_, _, err := d.AvIncomeStat(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_InsertAvIncomeStat(t *testing.T) {
Convey("InsertAvIncomeStat", t, func() {
_, err := d.InsertAvIncomeStat(context.Background(), "(123,2,6,1,'2018-06-01',100)")
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,17 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_InsertAvIncome(t *testing.T) {
Convey("InsertAvIncome", t, func() {
c := context.Background()
d.db.Exec(c, "DELETE FROM av_income WHERE date='2018-06-01'")
_, err := d.InsertAvIncome(c, "(123,2,6,1,'2018-06-01',100,100,100,50,'2018-06-01',100)")
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,53 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_insertBGMSQL = "INSERT INTO background_music(mid,sid,aid,cid,join_at,title) VALUES %s"
_getBGMSQL = "SELECT id,mid,sid,aid,cid,join_at FROM background_music WHERE id > ? ORDER BY id LIMIT ?"
_delBGMSQL = "DELETE FROM background_music LIMIT ?"
)
// InsertBGM insert bgm from data platform
func (d *Dao) InsertBGM(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_insertBGMSQL, values))
if err != nil {
log.Error("insert bgm error(%v)", err)
return
}
return res.RowsAffected()
}
// GetBGM get bgms
func (d *Dao) GetBGM(c context.Context, id int64, limit int64) (bs []*model.BGM, last int64, err error) {
rows, err := d.db.Query(c, _getBGMSQL, id, limit)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
b := &model.BGM{}
err = rows.Scan(&last, &b.MID, &b.SID, &b.AID, &b.CID, &b.JoinAt)
if err != nil {
return
}
bs = append(bs, b)
}
return
}
// DelBGM del bgm
func (d *Dao) DelBGM(c context.Context, limit int64) (rows int64, err error) {
res, err := d.db.Exec(c, _delBGMSQL, limit)
if err != nil {
log.Error("del bgm error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,19 @@
package income
import (
"context"
"fmt"
)
const (
_inBGMIncomeSQL = "INSERT INTO bgm_income(aid,sid,mid,cid,income,total_income,tax_money,date,base_income,daily_total_income) VALUES %s ON DUPLICATE KEY UPDATE income=VALUES(income),total_income=VALUES(total_income),tax_money=VALUES(tax_money),base_income=VALUES(base_income),daily_total_income=VALUES(daily_total_income)"
)
// InsertBgmIncome batch insert bgm income
func (d *Dao) InsertBgmIncome(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inBGMIncomeSQL, values))
if err != nil {
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,45 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_bgmIncomeStatSQL = "SELECT id,sid,total_income FROM bgm_income_statis WHERE id > ? ORDER BY id LIMIT ?"
_inBgmIncomeStatSQL = "INSERT INTO bgm_income_statis(sid,total_income) VALUES %s ON DUPLICATE KEY UPDATE sid=VALUES(sid),total_income=VALUES(total_income)"
)
// BgmIncomeStat key: sid
func (d *Dao) BgmIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.BgmIncomeStat, last int64, err error) {
rows, err := d.db.Query(c, _bgmIncomeStatSQL, id, limit)
if err != nil {
log.Error("d.db.Query BgmIncomeStat error(%v)", err)
return
}
defer rows.Close()
m = make(map[int64]*model.BgmIncomeStat)
for rows.Next() {
b := &model.BgmIncomeStat{}
err = rows.Scan(&last, &b.SID, &b.TotalIncome)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
m[b.SID] = b
}
return
}
// InsertBgmIncomeStat batch insert bgm income stat
func (d *Dao) InsertBgmIncomeStat(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inBgmIncomeStatSQL, values))
if err != nil {
log.Error("d.db.Exec InsertBgmIncomeStat error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,42 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeBgmIncomeStat(t *testing.T) {
convey.Convey("BgmIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
m, last, err := d.BgmIncomeStat(c, id, limit)
ctx.Convey("Then err should be nil.m,last should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(last, convey.ShouldNotBeNil)
ctx.So(m, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeInsertBgmIncomeStat(t *testing.T) {
convey.Convey("InsertBgmIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(100,200)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertBgmIncomeStat(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,24 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeInsertBgmIncome(t *testing.T) {
convey.Convey("InsertBgmIncome", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,2,3,4,5,6,7,'2018-06-24',100,100)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertBgmIncome(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,58 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeInsertBGM(t *testing.T) {
convey.Convey("InsertBGM", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,2,3,4,'2018-06-24','test')"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertBGM(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeGetBGM(t *testing.T) {
convey.Convey("GetBGM", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
bs, last, err := d.GetBGM(c, id, limit)
ctx.Convey("Then err should be nil.bs,last should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(last, convey.ShouldNotBeNil)
ctx.So(bs, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeDelBGM(t *testing.T) {
convey.Convey("DelBGM", t, func(ctx convey.C) {
var (
c = context.Background()
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.DelBGM(c, limit)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,37 @@
package income
import (
"context"
"go-common/library/log"
)
const (
_blacklistSQL = "SELECT id,av_id,ctype,is_delete FROM av_black_list WHERE id > ? ORDER BY id LIMIT ?"
)
// Blacklist map[ctype][]id
func (d *Dao) Blacklist(c context.Context, id int64, limit int64) (m map[int][]int64, last int64, err error) {
rows, err := d.db.Query(c, _blacklistSQL, id, limit)
if err != nil {
return
}
m = make(map[int][]int64)
for rows.Next() {
var ctype, isDeleted int
var avID int64
err = rows.Scan(&last, &avID, &ctype, &isDeleted)
if err != nil {
log.Error("Rows Scan error(%v)", err)
return
}
if isDeleted == 0 {
if _, ok := m[ctype]; ok {
m[ctype] = append(m[ctype], avID)
} else {
m[ctype] = []int64{avID}
}
}
}
return
}

View File

@@ -0,0 +1,15 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_Blacklist(t *testing.T) {
Convey("Blacklist", t, func() {
_, _, err := d.Blacklist(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,32 @@
package income
import (
"context"
"go-common/library/log"
)
const (
_businessOrderSQL = "SELECT id,av_id FROM business_order_sheet WHERE id > ? ORDER BY id LIMIT ?"
)
// BusinessOrders get business order
func (d *Dao) BusinessOrders(c context.Context, offset, limit int64) (last int64, m map[int64]bool, err error) {
rows, err := d.rddb.Query(c, _businessOrderSQL, offset, limit)
if err != nil {
log.Error("d.rddb.Query BusinessOrders error(%v)", err)
return
}
defer rows.Close()
m = make(map[int64]bool)
for rows.Next() {
var avID int64
err = rows.Scan(&last, &avID)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
m[avID] = true
}
return
}

View File

@@ -0,0 +1,26 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeBusinessOrders(t *testing.T) {
convey.Convey("BusinessOrders", t, func(ctx convey.C) {
var (
c = context.Background()
offset = int64(0)
limit = int64(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
last, m, err := d.BusinessOrders(c, offset, limit)
ctx.Convey("Then err should not be nil.last,m should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(m, convey.ShouldNotBeNil)
ctx.So(last, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,68 @@
package income
import (
"context"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_avChargeRatioSQL = "SELECT id,av_id,ratio,adjust_type,ctype FROM av_charge_ratio WHERE id > ? ORDER BY id LIMIT ?"
_upChargeRatioSQL = "SELECT id,mid,ratio,adjust_type,ctype FROM up_charge_ratio WHERE id > ? ORDER BY id LIMIT ?"
)
// ArchiveChargeRatio map[ctype]map[archive_id]*archiveChargeRatio
func (d *Dao) ArchiveChargeRatio(c context.Context, id int64, limit int64) (m map[int]map[int64]*model.ArchiveChargeRatio, last int64, err error) {
rows, err := d.db.Query(c, _avChargeRatioSQL, id, limit)
if err != nil {
log.Error("d.db.Query AvChargeRatio error(%v)", err)
return
}
m = make(map[int]map[int64]*model.ArchiveChargeRatio)
defer rows.Close()
for rows.Next() {
ratio := &model.ArchiveChargeRatio{}
err = rows.Scan(&last, &ratio.ArchiveID, &ratio.Ratio, &ratio.AdjustType, &ratio.CType)
if err != nil {
log.Error("AvChargeRatio scan error(%v)", err)
return
}
if ac, ok := m[ratio.CType]; ok {
ac[ratio.ArchiveID] = ratio
} else {
m[ratio.CType] = map[int64]*model.ArchiveChargeRatio{
ratio.ArchiveID: ratio,
}
}
}
return
}
// UpChargeRatio get every day up charge ratio
func (d *Dao) UpChargeRatio(c context.Context, id int64, limit int64) (m map[int]map[int64]*model.UpChargeRatio, last int64, err error) {
rows, err := d.db.Query(c, _upChargeRatioSQL, id, limit)
if err != nil {
log.Error("d.db.Query UpChargeRatio error(%v)", err)
return
}
m = make(map[int]map[int64]*model.UpChargeRatio)
defer rows.Close()
for rows.Next() {
ratio := &model.UpChargeRatio{}
err = rows.Scan(&last, &ratio.MID, &ratio.Ratio, &ratio.AdjustType, &ratio.CType)
if err != nil {
log.Error("UpChargeRatio scan error(%v)", err)
return
}
if ur, ok := m[ratio.CType]; ok {
ur[ratio.MID] = ratio
} else {
m[ratio.CType] = map[int64]*model.UpChargeRatio{
ratio.MID: ratio,
}
}
}
return
}

View File

@@ -0,0 +1,22 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_AvChargeRatio(t *testing.T) {
Convey("AvChargeRatio", t, func() {
_, _, err := d.ArchiveChargeRatio(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_UpChargeRatio(t *testing.T) {
Convey("UpChargeRatio", t, func() {
_, _, err := d.UpChargeRatio(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,38 @@
package income
import (
"context"
"time"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
xtime "go-common/library/time"
)
const (
_columnChargeSQL = "SELECT id,aid,title,mid,tag_id,upload_time,inc_charge,view_c,date FROM column_daily_charge WHERE id > ? AND date = ? AND inc_charge > 0 ORDER BY id LIMIT ?"
)
// ColumnDailyCharge get column daily charge by date
func (d *Dao) ColumnDailyCharge(c context.Context, date time.Time, id int64, limit int) (columns []*model.ColumnCharge, err error) {
columns = make([]*model.ColumnCharge, 0)
rows, err := d.db.Query(c, _columnChargeSQL, id, date, limit)
if err != nil {
log.Error("ColumnDailyCharge d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
column := &model.ColumnCharge{}
var uploadTime int64
err = rows.Scan(&column.ID, &column.ArticleID, &column.Title, &column.MID, &column.TagID, &uploadTime, &column.IncCharge, &column.IncViewCount, &column.Date)
if err != nil {
log.Error("ColumnDailyCharge rows.Scan error(%v)", err)
return
}
column.UploadTime = xtime.Time(uploadTime)
columns = append(columns, column)
}
return
}

View File

@@ -0,0 +1,27 @@
package income
import (
"context"
"testing"
"time"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeColumnDailyCharge(t *testing.T) {
convey.Convey("ColumnDailyCharge", t, func(ctx convey.C) {
var (
c = context.Background()
date = time.Now()
id = int64(0)
limit = int(0)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
columns, err := d.ColumnDailyCharge(c, date, id, limit)
ctx.Convey("Then err should be nil.columns should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(columns, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,19 @@
package income
import (
"context"
"fmt"
)
const (
_inColumnIncomeSQL = "INSERT INTO column_income(aid,mid,tag_id,upload_time,view_count,income,total_income,tax_money,date,base_income) VALUES %s ON DUPLICATE KEY UPDATE income=VALUES(income),total_income=VALUES(total_income),base_income=VALUES(base_income)"
)
// InsertColumnIncome batch insert column income
func (d *Dao) InsertColumnIncome(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inColumnIncomeSQL, values))
if err != nil {
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,45 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_columnIncomeStatSQL = "SELECT id,aid,mid,upload_time,total_income,title FROM column_income_statis WHERE id > ? ORDER BY id LIMIT ?"
_inColumnIncomeStatSQL = "INSERT INTO column_income_statis(aid,title,mid,tag_id,upload_time,total_income) VALUES %s ON DUPLICATE KEY UPDATE aid=VALUES(aid),title=VALUES(title),mid=VALUES(mid),upload_time=VALUES(upload_time),total_income=VALUES(total_income)"
)
// ColumnIncomeStat key: av_id
func (d *Dao) ColumnIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.ColumnIncomeStat, last int64, err error) {
rows, err := d.db.Query(c, _columnIncomeStatSQL, id, limit)
if err != nil {
log.Error("d.db.Query AvIncomeStat error(%v)", err)
return
}
defer rows.Close()
m = make(map[int64]*model.ColumnIncomeStat)
for rows.Next() {
c := &model.ColumnIncomeStat{}
err = rows.Scan(&last, &c.ArticleID, &c.MID, &c.UploadTime, &c.TotalIncome, &c.Title)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
m[c.ArticleID] = c
}
return
}
// InsertColumnIncomeStat batch insert column income stat
func (d *Dao) InsertColumnIncomeStat(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inColumnIncomeStatSQL, values))
if err != nil {
log.Error("d.db.Exec InsertColumnIncomeStat error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,42 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeColumnIncomeStat(t *testing.T) {
convey.Convey("ColumnIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
m, last, err := d.ColumnIncomeStat(c, id, limit)
ctx.Convey("Then err should be nil.m,last should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(last, convey.ShouldNotBeNil)
ctx.So(m, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeInsertColumnIncomeStat(t *testing.T) {
convey.Convey("InsertColumnIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,'test',12,2,'2018-06-24',100)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertColumnIncomeStat(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,24 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeInsertColumnIncome(t *testing.T) {
convey.Convey("InsertColumnIncome", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,2,3,'2018-06-24',100,10,100,10,'2018-06-24',100)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertColumnIncome(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,68 @@
package income
import (
"context"
"go-common/app/job/main/growup/conf"
"go-common/library/database/sql"
"go-common/library/log"
)
// Dao dao
type Dao struct {
c *conf.Config
db *sql.DB
rddb *sql.DB
Tx *sql.Tx
}
// New fn
func New(c *conf.Config) (d *Dao) {
log.Info("dao start")
d = &Dao{
c: c,
db: sql.NewMySQL(c.Mysql.Growup),
rddb: sql.NewMySQL(c.Mysql.Allowance),
}
d.Tx, _ = d.BeginTran(context.TODO())
//d.db.State = prom.LibClient
return d
}
// Ping ping health.
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}
// Close close connections of mc, redis, db.
func (d *Dao) Close() {
if d.db != nil {
d.db.Close()
}
}
// BeginTran begin transcation
func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
return d.db.Begin(c)
}
// Exec exec sql
func (d *Dao) Exec(c context.Context, sql string) (err error) {
_, err = d.db.Exec(c, sql)
return
}
// QueryRow query row
func (d *Dao) QueryRow(c context.Context, sql string) (rows *sql.Row) {
return d.db.QueryRow(c, sql)
}
// Query query
func (d *Dao) Query(c context.Context, sql string) (rows *sql.Rows, err error) {
return d.db.Query(c, sql)
}
// test
// func (d *Dao) Truncate(c context.Context, table string) {
// d.db.Exec(c, fmt.Sprintf("truncate %s", table))
// }

View File

@@ -0,0 +1,35 @@
package income
import (
"flag"
"os"
"testing"
"go-common/app/job/main/growup/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "mobile.studio.growup-job")
flag.Set("conf_token", "8781e02680f40996bc01eb1248ac2ac9")
flag.Set("tree_id", "14716")
flag.Set("conf_version", "docker-1")
flag.Set("deploy_env", "uat")
flag.Set("conf_host", "config.bilibili.co")
flag.Set("conf_path", "/tmp")
flag.Set("region", "sh")
flag.Set("zone", "sh001")
} else {
flag.Set("conf", "../../cmd/growup-job.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,61 @@
package income
import (
"context"
"fmt"
"go-common/library/log"
)
const (
_inIncomeStatisTableSQL = "INSERT INTO %s(avs, money_section, money_tips, income, category_id, cdate) VALUES %s ON DUPLICATE KEY UPDATE avs=VALUES(avs),income=VALUES(income),cdate=VALUES(cdate)"
_delIncomeStatisTableSQL = "DELETE FROM %s WHERE cdate = ?"
_inUpIncomeDailyStatisSQL = "INSERT INTO %s(ups, money_section, money_tips, income, cdate) VALUES %s ON DUPLICATE KEY UPDATE ups=VALUES(ups),income=VALUES(income),cdate=VALUES(cdate)"
)
// InsertIncomeStatisTable add av_income_date_statis batch
func (d *Dao) InsertIncomeStatisTable(c context.Context, table, vals string) (rows int64, err error) {
if table == "" {
err = fmt.Errorf("InsertIncomeStatisTable table(%s) val(%s) error", table, vals)
return
}
if vals == "" {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_inIncomeStatisTableSQL, table, vals))
if err != nil {
log.Error("incomeStatisTableBatch d.db.Exec error(%v)", err)
return
}
return res.RowsAffected()
}
// InsertUpIncomeDailyStatis add up_income_daily_statis batch
func (d *Dao) InsertUpIncomeDailyStatis(c context.Context, table string, vals string) (rows int64, err error) {
if vals == "" {
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeDailyStatisSQL, table, vals))
if err != nil {
log.Error("InsertUpIncomeDailyStatis d.db.Exec error(%v)", err)
return
}
return res.RowsAffected()
}
// DelIncomeStatisTable del income statis by table
func (d *Dao) DelIncomeStatisTable(c context.Context, table, date string) (rows int64, err error) {
if table == "" || date == "" {
err = fmt.Errorf("DelIncomeStatisTable table(%s) date(%s) error", table, date)
return
}
res, err := d.db.Exec(c, fmt.Sprintf(_delIncomeStatisTableSQL, table), date)
if err != nil {
log.Error("DelIncomeStatisTable d.db.Exec error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,59 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeInsertIncomeStatisTable(t *testing.T) {
convey.Convey("InsertIncomeStatisTable", t, func(ctx convey.C) {
var (
c = context.Background()
table = "av_income_daily_statis"
vals = "(1,2,'100-200',100,1,'2018-06-24')"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertIncomeStatisTable(c, table, vals)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeInsertUpIncomeDailyStatis(t *testing.T) {
convey.Convey("InsertUpIncomeDailyStatis", t, func(ctx convey.C) {
var (
c = context.Background()
table = "up_income_daily_statis"
vals = "(10,1,'100-200',1,'2018-06-24')"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertUpIncomeDailyStatis(c, table, vals)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeDelIncomeStatisTable(t *testing.T) {
convey.Convey("DelIncomeStatisTable", t, func(ctx convey.C) {
var (
c = context.Background()
table = "av_income_daily_statis"
date = "2018-06-24"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.DelIncomeStatisTable(c, table, date)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,31 @@
package income
import (
"context"
)
const (
_getBubbleMetaSQL = "SELECT id,av_id,b_type FROM lottery_av_info WHERE id > ? ORDER BY id LIMIT ?"
)
// GetBubbleMeta get bubble meta
func (d *Dao) GetBubbleMeta(c context.Context, id int64, limit int64) (data map[int64][]int, last int64, err error) {
data = make(map[int64][]int)
rows, err := d.db.Query(c, _getBubbleMetaSQL, id, limit)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
var (
avID int64
bType int
)
err = rows.Scan(&last, &avID, &bType)
if err != nil {
return
}
data[avID] = append(data[avID], bType)
}
return
}

View File

@@ -0,0 +1,26 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeGetBubbleMeta(t *testing.T) {
convey.Convey("GetBubbleMeta", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
limit = int64(20)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
data, last, err := d.GetBubbleMeta(c, id, limit)
ctx.Convey("Then err should be nil.data,last should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(last, convey.ShouldNotBeNil)
ctx.So(data, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,77 @@
package income
import (
"context"
"database/sql"
"fmt"
"go-common/library/log"
model "go-common/app/job/main/growup/model/income"
)
const (
// select
_upAccountsSQL = "SELECT id,mid,has_sign_contract,state,total_income,total_unwithdraw_income,total_withdraw_income,last_withdraw_time,version,allowance_state,nick_name,withdraw_date_version,is_deleted FROM up_account WHERE id > ? ORDER BY id LIMIT ?"
_upAccountSQL = "SELECT total_income,total_unwithdraw_income,version,withdraw_date_version FROM up_account WHERE mid=?"
// for batch insert
_insertUpAccountSQL = "INSERT INTO up_account(mid,has_sign_contract,total_income,total_unwithdraw_income,withdraw_date_version,version) VALUES %s ON DUPLICATE KEY UPDATE total_income=VALUES(total_income),total_unwithdraw_income=VALUES(total_unwithdraw_income),version=VALUES(version)"
_updateUpAccountSQL = "UPDATE up_account SET total_income=?,total_unwithdraw_income=?,version=? WHERE mid=? AND version=?"
)
// UpAccounts batch read up account
func (d *Dao) UpAccounts(c context.Context, id int64, limit int64) (m map[int64]*model.UpAccount, last int64, err error) {
rows, err := d.db.Query(c, _upAccountsSQL, id, limit)
if err != nil {
log.Error("d.db.UpAccounts error(%v)", err)
return
}
m = make(map[int64]*model.UpAccount)
defer rows.Close()
for rows.Next() {
ua := &model.UpAccount{}
err = rows.Scan(&last, &ua.MID, &ua.HasSignContract, &ua.State, &ua.TotalIncome, &ua.TotalUnwithdrawIncome, &ua.TotalWithdrawIncome, &ua.LastWithdrawTime, &ua.Version, &ua.AllowanceState, &ua.Nickname, &ua.WithdrawDateVersion, &ua.IsDeleted)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
m[ua.MID] = ua
}
return
}
// UpAccount get up account by mid
func (d *Dao) UpAccount(c context.Context, mid int64) (a *model.UpAccount, err error) {
row := d.db.QueryRow(c, _upAccountSQL, mid)
a = &model.UpAccount{}
if err = row.Scan(&a.TotalIncome, &a.TotalUnwithdrawIncome, &a.Version, &a.WithdrawDateVersion); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("dao.UpAccount error(%v)", err)
}
}
return
}
// InsertUpAccount batch insert up account
func (d *Dao) InsertUpAccount(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_insertUpAccountSQL, values))
if err != nil {
log.Error("d.db.Exec InsertUpAccount error(%v)", err)
return
}
return res.RowsAffected()
}
// UpdateUpAccount update up account by mid and version instead batch update
func (d *Dao) UpdateUpAccount(c context.Context, mid, ver, totalIncome, totalUnwithdrawIncome int64) (rows int64, err error) {
res, err := d.db.Exec(c, _updateUpAccountSQL, totalIncome, totalUnwithdrawIncome, ver+1, mid, ver)
if err != nil {
log.Error("d.db.Exec UpdateUpAccount error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,36 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_UpAccounts(t *testing.T) {
Convey("UpAccounts", t, func() {
_, _, err := d.UpAccounts(context.Background(), 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_UpAccount(t *testing.T) {
Convey("UpAccount", t, func() {
_, err := d.UpAccount(context.Background(), 123)
So(err, ShouldBeNil)
})
}
func Test_InsertUpAccount(t *testing.T) {
Convey("InsertUpAccount", t, func() {
_, err := d.InsertUpAccount(context.Background(), "(123,1,100,300,2018-05,22)")
So(err, ShouldBeNil)
})
}
func Test_UpdateUpAccount(t *testing.T) {
Convey("UpdateUpAccount", t, func() {
_, err := d.UpdateUpAccount(context.Background(), int64(100), int64(22), int64(123), int64(100))
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,46 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_insertUpChargeSQL = "INSERT INTO %s (mid,inc_charge,total_charge,date) VALUES %s ON DUPLICATE KEY UPDATE inc_charge=VALUES(inc_charge),total_charge=VALUES(total_charge)"
_upChargeSQL = "SELECT id,mid,inc_charge,total_charge,date FROM %s WHERE date=? AND id > ? ORDER BY id LIMIT ?"
)
// GetUpCharges get up charges
func (d *Dao) GetUpCharges(c context.Context, table string, date string, offset, limit int64) (last int64, charges map[int64]*model.UpCharge, err error) {
rows, err := d.db.Query(c, fmt.Sprintf(_upChargeSQL, table), date, offset, limit)
if err != nil {
log.Error("d.db.Query GetUpCharges error(%v)", err)
return
}
charges = make(map[int64]*model.UpCharge)
defer rows.Close()
for rows.Next() {
c := &model.UpCharge{}
err = rows.Scan(&last, &c.MID, &c.IncCharge, &c.TotalCharge, &c.Date)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
charges[c.MID] = c
}
return
}
// InsertUpCharge batch insert up charge
func (d *Dao) InsertUpCharge(c context.Context, table string, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_insertUpChargeSQL, table, values))
if err != nil {
log.Error("d.db.Exec InsertUpCharge error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,46 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeGetUpCharges(t *testing.T) {
convey.Convey("GetUpCharges", t, func(ctx convey.C) {
var (
c = context.Background()
table = "up_daily_charge"
date = "2018-06-24"
offset = int64(0)
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
d.db.Exec(c, "INSERT INTO up_daily_charge(mid,date) VALUES(1,'2018-06-24') ON DUPLICATE KEY UPDATE date=VALUES(date)")
last, charges, err := d.GetUpCharges(c, table, date, offset, limit)
ctx.Convey("Then err should be nil.last,charges should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(charges, convey.ShouldNotBeNil)
ctx.So(last, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeInsertUpCharge(t *testing.T) {
convey.Convey("InsertUpCharge", t, func(ctx convey.C) {
var (
c = context.Background()
table = "up_daily_charge"
values = "(1,2,3,'2018-06-24')"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertUpCharge(c, table, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,57 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_inUpIncomeSQL = "INSERT INTO up_income(mid,av_count,play_count,av_income,audio_income,column_count,column_income,tax_money,income,total_income,av_base_income,av_tax,column_base_income,column_tax,bgm_base_income,bgm_tax,date,base_income,bgm_income,bgm_count,av_total_income,column_total_income,bgm_total_income) VALUES %s ON DUPLICATE KEY UPDATE mid=VALUES(mid),av_count=VALUES(av_count),play_count=VALUES(play_count),av_income=VALUES(av_income),audio_income=VALUES(audio_income),column_count=VALUES(column_count),column_income=VALUES(column_income),tax_money=VALUES(tax_money),income=VALUES(income),total_income=VALUES(total_income),av_base_income=VALUES(av_base_income),av_tax=VALUES(av_tax),column_base_income=VALUES(column_base_income),column_tax=VALUES(column_tax),bgm_base_income=VALUES(bgm_base_income),bgm_tax=VALUES(bgm_tax),date=VALUES(date),base_income=VALUES(base_income),bgm_income=VALUES(bgm_income),bgm_count=VALUES(bgm_count),av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
_upIncomeSQL = "SELECT id,mid,av_income,audio_income,column_income,bgm_income,date FROM up_income WHERE id > ? ORDER BY id LIMIT ?"
_fixInUpIncomeSQL = "INSERT INTO up_income(mid,av_total_income,column_total_income,bgm_total_income,date) VALUES %s ON DUPLICATE KEY UPDATE av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
)
// UpIncomes up incomes
func (d *Dao) UpIncomes(c context.Context, id int64, limit int64) (last int64, us []*model.UpIncome, err error) {
rows, err := d.db.Query(c, _upIncomeSQL, id, limit)
if err != nil {
log.Error("d.db.Query UpIncomes error (%v)", err)
return
}
defer rows.Close()
for rows.Next() {
u := &model.UpIncome{}
err = rows.Scan(&last, &u.MID, &u.AvIncome, &u.AudioIncome, &u.ColumnIncome, &u.BgmIncome, &u.Date)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
us = append(us, u)
}
return
}
// InsertUpIncome batch insert up income
func (d *Dao) InsertUpIncome(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeSQL, values))
if err != nil {
log.Error("d.db.Exec InsertUpIncome error (%v)", err)
return
}
return res.RowsAffected()
}
// FixInsertUpIncome batch insert up income
func (d *Dao) FixInsertUpIncome(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_fixInUpIncomeSQL, values))
if err != nil {
log.Error("d.db.Exec InsertUpIncome error (%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,47 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_getUpIncomeTableSQL = "SELECT id,mid,av_count,play_count,av_income,audio_income,column_count,column_income,bgm_income,av_tax,column_tax,bgm_tax,tax_money,income,total_income,av_base_income,column_base_income,bgm_base_income,base_income,av_total_income,column_total_income,bgm_total_income,date FROM %s WHERE id > ? AND date = ? ORDER BY id LIMIT ?"
_inUpIncomeTableSQL = "INSERT INTO %s(mid,av_count,play_count,av_income,audio_income,column_count,column_income,bgm_count,bgm_income,tax_money,income,total_income,av_base_income,av_tax,column_base_income,column_tax,bgm_base_income,bgm_tax,date,base_income,av_total_income,column_total_income,bgm_total_income) VALUES %s ON DUPLICATE KEY UPDATE mid=VALUES(mid),av_count=VALUES(av_count),play_count=VALUES(play_count),av_income=VALUES(av_income),audio_income=VALUES(audio_income),column_count=VALUES(column_count),column_income=VALUES(column_income),bgm_count=VALUES(bgm_count),bgm_income=VALUES(bgm_income),tax_money=VALUES(tax_money),income=VALUES(income),total_income=VALUES(total_income),av_base_income=VALUES(av_base_income),av_tax=VALUES(av_tax),column_base_income=VALUES(column_base_income),column_tax=VALUES(column_tax),bgm_base_income=VALUES(bgm_base_income),bgm_tax=VALUES(bgm_tax),date=VALUES(date),base_income=VALUES(base_income),av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
)
// GetUpIncomeTable get up_income up_income_weekly up_income_monthly
func (d *Dao) GetUpIncomeTable(c context.Context, table, date string, id int64, limit int) (ups []*model.UpIncome, err error) {
ups = make([]*model.UpIncome, 0)
rows, err := d.db.Query(c, fmt.Sprintf(_getUpIncomeTableSQL, table), id, date, limit)
if err != nil {
log.Error("GetUpIncomeTable d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
up := &model.UpIncome{}
err = rows.Scan(&up.ID, &up.MID, &up.AvCount, &up.PlayCount, &up.AvIncome, &up.AudioIncome, &up.ColumnCount, &up.ColumnIncome, &up.BgmIncome, &up.AvTax, &up.ColumnTax, &up.BgmTax, &up.TaxMoney, &up.Income, &up.TotalIncome, &up.AvBaseIncome, &up.ColumnBaseIncome, &up.BgmBaseIncome, &up.BaseIncome, &up.AvTotalIncome, &up.ColumnTotalIncome, &up.BgmTotalIncome, &up.Date)
if err != nil {
log.Error("GetUpIncomeTable rows.Scan error(%v)", err)
return
}
ups = append(ups, up)
}
return
}
// InsertUpIncomeTable insert up_income up_income_weekly up_income_monthly
func (d *Dao) InsertUpIncomeTable(c context.Context, table, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeTableSQL, table, values))
if err != nil {
log.Error("InsertUpIncome error (%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,22 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_GetUpIncomeTable(t *testing.T) {
Convey("GetUpIncomeTable", t, func() {
_, err := d.GetUpIncomeTable(context.Background(), "up_income_weekly", "2018-06-01", 0, 2000)
So(err, ShouldBeNil)
})
}
func Test_InsertUpIncomeTable(t *testing.T) {
Convey("InsertUpIncomeTable", t, func() {
_, err := d.InsertUpIncomeTable(context.Background(), "up_income_weekly", "(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,'2018-06-24',1,2,3,4)")
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,60 @@
package income
import (
"context"
"fmt"
"go-common/library/log"
model "go-common/app/job/main/growup/model/income"
)
const (
_upIncomeStatSQL = "SELECT id,mid,total_income,av_total_income,column_total_income,bgm_total_income FROM up_income_statis WHERE id > ? ORDER BY id LIMIT ?"
_inUpIncomeStatSQL = "INSERT INTO up_income_statis(mid,total_income,av_total_income,column_total_income,bgm_total_income) VALUES %s ON DUPLICATE KEY UPDATE mid=VALUES(mid),total_income=VALUES(total_income),av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
_fixUpIncomeStatSQL = "INSERT INTO up_income_statis(mid,av_total_income,column_total_income,bgm_total_income) VALUES %s ON DUPLICATE KEY UPDATE mid=VALUES(mid),av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
)
// UpIncomeStat return m key: mid, value: total_income
func (d *Dao) UpIncomeStat(c context.Context, id int64, limit int64) (m map[int64]*model.UpIncomeStat, last int64, err error) {
rows, err := d.db.Query(c, _upIncomeStatSQL, id, limit)
if err != nil {
log.Error("UpIncomeStat Query (%s, %d, %d) error(%v)", _upIncomeStatSQL, id, limit, err)
return
}
defer rows.Close()
m = make(map[int64]*model.UpIncomeStat)
for rows.Next() {
u := &model.UpIncomeStat{}
err = rows.Scan(&last, &u.MID, &u.TotalIncome, &u.AvTotalIncome, &u.ColumnTotalIncome, &u.BgmTotalIncome)
if err != nil {
log.Error("UpIncomeStat rows scan error(%v)", err)
return
}
m[u.MID] = u
}
return
}
// InsertUpIncomeStat batch insert up income stat
func (d *Dao) InsertUpIncomeStat(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeStatSQL, values))
if err != nil {
log.Error("d.db.Exec InsertUpIncomeStat error(%v)", err)
return
}
return res.RowsAffected()
}
// FixInsertUpIncomeStat fix insert up income stat
func (d *Dao) FixInsertUpIncomeStat(c context.Context, values string) (rows int64, err error) {
res, err := d.db.Exec(c, fmt.Sprintf(_fixUpIncomeStatSQL, values))
if err != nil {
log.Error("d.db.Exec InsertUpIncomeStat error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,59 @@
package income
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestIncomeUpIncomeStat(t *testing.T) {
convey.Convey("UpIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
id = int64(0)
limit = int64(100)
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
d.db.Exec(c, "INSERT INTO up_income(mid,date) VALUES(1,'2018-06-24') ON DUPLICATE KEY UPDATE date=VALUES(date)")
m, last, err := d.UpIncomeStat(c, id, limit)
ctx.Convey("Then err should be nil.m,last should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(last, convey.ShouldNotBeNil)
ctx.So(m, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeInsertUpIncomeStat(t *testing.T) {
convey.Convey("InsertUpIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,2,3,4,5)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.InsertUpIncomeStat(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}
func TestIncomeFixInsertUpIncomeStat(t *testing.T) {
convey.Convey("FixInsertUpIncomeStat", t, func(ctx convey.C) {
var (
c = context.Background()
values = "(1,2,3,4)"
)
ctx.Convey("When everything goes positive", func(ctx convey.C) {
rows, err := d.FixInsertUpIncomeStat(c, values)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(rows, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,15 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_InsertUpIncome(t *testing.T) {
Convey("InsertUpIncome", t, func() {
_, err := d.InsertUpIncome(context.Background(), "(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,'2018-06-24',1,2,3,4,5,6)")
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,36 @@
package income
import (
"context"
"fmt"
model "go-common/app/job/main/growup/model/income"
"go-common/library/log"
)
const (
_signedSQL = "SELECT id,mid,signed_at,quit_at,account_state,is_deleted FROM up_info_%s WHERE id > ? ORDER BY id LIMIT ?"
)
// Ups get ups by business type
func (d *Dao) Ups(c context.Context, business string, offset int64, limit int64) (last int64, ups map[int64]*model.Signed, err error) {
ups = make(map[int64]*model.Signed)
rows, err := d.db.Query(c, fmt.Sprintf(_signedSQL, business), offset, limit)
if err != nil {
log.Error("db Query Signed up Info error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
up := &model.Signed{}
err = rows.Scan(&last, &up.MID, &up.SignedAt, &up.QuitAt, &up.AccountState, &up.IsDeleted)
if err != nil {
log.Error("rows scan error(%v)", err)
return
}
if up.IsDeleted == 0 {
ups[up.MID] = up
}
}
return
}

View File

@@ -0,0 +1,15 @@
package income
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func Test_Ups(t *testing.T) {
Convey("Ups", t, func() {
_, _, err := d.Ups(context.Background(), "video", 0, 2000)
So(err, ShouldBeNil)
})
}