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,70 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"appeal.go",
"buss_attr.go",
"chall.go",
"dao.go",
"notify.go",
"redis.go",
"search.go",
],
importpath = "go-common/app/job/main/workflow/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/admin/main/workflow/model/param:go_default_library",
"//app/job/main/workflow/conf:go_default_library",
"//app/job/main/workflow/model:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/elastic:go_default_library",
"//library/database/orm:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/queue/databus/report:go_default_library",
"//vendor/github.com/jinzhu/gorm:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = [
"appeal_test.go",
"buss_attr_test.go",
"chall_test.go",
"dao_test.go",
"notify_test.go",
"redis_test.go",
"search_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/admin/main/workflow/model/param:go_default_library",
"//app/job/main/workflow/conf:go_default_library",
"//app/job/main/workflow/model:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey: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,53 @@
package dao
import (
"context"
"time"
"go-common/app/job/main/workflow/model"
"github.com/jinzhu/gorm"
)
// consts for workflow business_state
const (
BusStCreated = int8(1) // 未处理
BusStRead = int8(2) // 已回复已读
BusStAutoClosed = int8(5) // 过期自动关闭
BusStNotRead = int8(6) // 已回复未读
)
// Appeals .
func (d *Dao) Appeals(c context.Context, ids []int64) (appeals []*model.Appeal, err error) {
err = d.ReadORM.Table("workflow_appeal").Where("id in (?)", ids).Find(&appeals).Error
return
}
// SetAppealTransferState will close expired feedback 关闭超时的申诉 (用户未评价)
func (d *Dao) SetAppealTransferState(c context.Context, ids []int64, transferState int8) (err error) {
err = d.WriteORM.Table("workflow_appeal").Where("id IN (?)", ids).Update("transfer_state", transferState).
Update("ttime", time.Now().Format("2006-01-02 15:04:05")).Error
return
}
// TxSetWeight db覆盖权重值
func (d *Dao) TxSetWeight(tx *gorm.DB, newWeight map[int64]int64) (err error) {
for id, weight := range newWeight {
if err = tx.Table("workflow_appeal").Where("id = ?", id).Update("weight", weight).Error; err != nil {
return
}
}
return
}
// SetAppealAssignState .
func (d *Dao) SetAppealAssignState(c context.Context, ids []int64, assignState int8) (err error) {
return d.WriteORM.Table("workflow_appeal").Where("id in (?)", ids).Update("assign_state", assignState).Error
}
// LastEvent return last event of appeal_id
func (d *Dao) LastEvent(id int64) (e *model.Event, err error) {
e = new(model.Event)
err = d.ReadORM.Table("workflow_event").Where("appeal_id = ?", id).Last(e).Error
return
}

View File

@@ -0,0 +1,85 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoAppeals(t *testing.T) {
convey.Convey("Appeals", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
appeals, err := d.Appeals(c, ids)
ctx.Convey("Then err should be nil.appeals should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(appeals, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoTxSetWeight(t *testing.T) {
convey.Convey("SetWeight", t, func(ctx convey.C) {
var (
newWeight map[int64]int64
tx = d.WriteORM.Begin()
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.TxSetWeight(tx, newWeight)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
tx.Rollback()
})
})
}
func TestDaoSetAppealAssignState(t *testing.T) {
convey.Convey("SetAppealAssignState", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{1}
assignState = int8(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetAppealAssignState(c, ids, assignState)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoLastEvent(t *testing.T) {
convey.Convey("LastEvent", t, func(ctx convey.C) {
var apID = int64(1)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
e, err := d.LastEvent(apID)
ctx.Convey("Then err should be nil.e should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(e, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetAppealTransferState(t *testing.T) {
convey.Convey("SetAppealTransferState", t, func(ctx convey.C) {
var (
c = context.Background()
ids = []int64{}
transferState = int8(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetAppealTransferState(c, ids, transferState)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,16 @@
package dao
import (
"context"
"go-common/app/job/main/workflow/model"
"go-common/library/log"
)
// BusinessAttr .
func (d *Dao) BusinessAttr(c context.Context) (res []*model.BusinessAttr, err error) {
if err = d.ReadORM.Table("workflow_business_attr").Select("id, bid, name, deal_type, expire_time, assign_type, assign_max, group_type").Find(&res).Error; err != nil {
log.Error("d.BusinessAttr error(%v)", err)
}
return
}

View File

@@ -0,0 +1,23 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoBusinessAttr(t *testing.T) {
convey.Convey("BusinessAttr", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.BusinessAttr(c)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}

View File

@@ -0,0 +1,35 @@
package dao
import (
"context"
"go-common/app/job/main/workflow/model"
)
// ChallByIDs get chall list by ids.
func (d *Dao) ChallByIDs(c context.Context, cids []int64) (res map[int64]*model.Chall, err error) {
if len(cids) <= 0 {
return
}
res = make(map[int64]*model.Chall)
cList := make([]*model.Chall, 0, len(cids))
if err = d.ReadORM.Table("workflow_chall").Select("id, business, dispatch_state, dispatch_time").Where("id IN (?)", cids).Find(&cList).Error; err != nil {
return
}
for _, c := range cList {
res[c.ID] = c
}
return
}
// UpDispatchStateByIDs update by ids.
func (d *Dao) UpDispatchStateByIDs(c context.Context, cids []int64, dispatchState int64) (err error) {
err = d.WriteORM.Table("workflow_chall").Where("id IN (?)", cids).Update("dispatch_state", dispatchState).Error
return
}
// UpDispatchStateAdminIDByIds .
func (d *Dao) UpDispatchStateAdminIDByIds(c context.Context, cids []int64, dispatchState, assignAdminid int64) (err error) {
err = d.WriteORM.Table("workflow_chall").Where("id IN (?)", cids).Update("dispatch_state", dispatchState).Update("assignee_adminid", assignAdminid).Error
return
}

View File

@@ -0,0 +1,57 @@
package dao
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoChallByIDs(t *testing.T) {
convey.Convey("ChallByIDs", t, func(ctx convey.C) {
var (
c = context.Background()
cids = []int64{1}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.ChallByIDs(c, cids)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoUpDispatchStateByIDs(t *testing.T) {
convey.Convey("UpDispatchStateByIDs", t, func(ctx convey.C) {
var (
c = context.Background()
cids = []int64{}
dispatchState = int64(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.UpDispatchStateByIDs(c, cids, dispatchState)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoUpDispatchStateAdminIDByIds(t *testing.T) {
convey.Convey("UpDispatchStateAdminIDByIds", t, func(ctx convey.C) {
var (
c = context.Background()
cids = []int64{}
dispatchState = int64(0)
assignAdminid = int64(0)
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.UpDispatchStateAdminIDByIds(c, cids, dispatchState, assignAdminid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,76 @@
package dao
import (
"context"
"go-common/app/job/main/workflow/conf"
"go-common/library/cache/redis"
"go-common/library/database/elastic"
"go-common/library/database/orm"
bm "go-common/library/net/http/blademaster"
"github.com/jinzhu/gorm"
)
const (
_srhURL = "/x/admin/search/workflow/common"
_notifyURL = "/api/notify/send.user.notify.do"
)
// Dao struct info of Dao.
type Dao struct {
c *conf.Config
// orm
WriteORM *gorm.DB
ReadORM *gorm.DB
// redis
redis *redis.Pool
// search
httpSearch *bm.Client
// url
searchURL string
messageURL string
// es client
es *elastic.Elastic
}
// New new a Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
WriteORM: orm.NewMySQL(c.ORM.Write),
ReadORM: orm.NewMySQL(c.ORM.Read),
redis: redis.NewPool(c.Redis),
httpSearch: bm.NewClient(c.HTTPSearch),
searchURL: c.Host.SearchURI + _srhURL,
messageURL: c.Host.MessageURI + _notifyURL,
es: elastic.NewElastic(nil),
}
d.initORM()
return
}
// Close close connections of ORM.
func (d *Dao) Close() (err error) {
if d.WriteORM != nil {
d.WriteORM.Close()
}
if d.ReadORM != nil {
d.ReadORM.Close()
}
return
}
// Ping ping health of ORM.
func (d *Dao) Ping(c context.Context) (err error) {
if err = d.WriteORM.DB().PingContext(c); err != nil {
return
}
err = d.ReadORM.DB().PingContext(c)
return
}
func (d *Dao) initORM() {
d.WriteORM.LogMode(true)
d.ReadORM.LogMode(true)
}

View File

@@ -0,0 +1,35 @@
package dao
import (
"flag"
"os"
"testing"
"go-common/app/job/main/workflow/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.manager.workflow-job")
flag.Set("conf_token", "7e96847c0bcf11e899270ab36409257a")
flag.Set("tree_id", "14082")
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/workflow-job-test.toml")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,43 @@
package dao
import (
"context"
"time"
"go-common/app/admin/main/workflow/model/param"
"go-common/app/job/main/workflow/model"
"go-common/library/ecode"
"go-common/library/queue/databus/report"
)
// SendMessage .
func (d *Dao) SendMessage(c context.Context, chs []*model.ChallRes, msg *param.MessageParam) (err error) {
params := msg.Query()
var res struct {
Code int `json:"code"`
}
if err = d.httpSearch.Post(c, d.messageURL, "", params, &res); err != nil {
return
}
if res.Code != 0 {
err = ecode.Int(res.Code)
return
}
for _, ch := range chs {
report.Manager(&report.ManagerInfo{
UID: 2233,
Uname: "",
Business: 11,
Type: 2,
Oid: ch.OID,
Ctime: time.Now(),
Action: "notify_users_received",
Content: map[string]interface{}{
"mid": ch.MID,
"message": "zhoushuguang",
},
Index: []interface{}{ch.ID, ch.GID, ch.MID},
})
}
return
}

View File

@@ -0,0 +1,27 @@
package dao
import (
"context"
"testing"
"go-common/app/admin/main/workflow/model/param"
"go-common/app/job/main/workflow/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSendMessage(t *testing.T) {
convey.Convey("SendMessage", t, func(ctx convey.C) {
var (
c = context.Background()
chs = []*model.ChallRes{}
msg = &param.MessageParam{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SendMessage(c, chs, msg)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err.Error(), convey.ShouldEqual, "-6")
})
})
})
}

View File

@@ -0,0 +1,157 @@
package dao
import (
"context"
"fmt"
"strconv"
"time"
"go-common/library/cache/redis"
"go-common/library/log"
)
const (
_keyUperWeightGroup = "platform_uper_weight_param_2" // 工作台任务权重参数(用户维度)
_prefixKeyMissionSortedSet = "platform_missions_" // 工作台任务池 有序集合(权重排序)
_prefixKeySingleExpire = "platform_single_expire_" // 单条工单的开始处理时间 有序集合
_relatedMissions = "platfrom_missions_%d_%d" // 当前认领任务
)
// SetList .
func (d *Dao) SetList(c context.Context, key string, ids []int64) (err error) {
conn := d.redis.Get(c)
defer conn.Close()
for _, id := range ids {
now := time.Now().Format("2006-01-02 15:04:05")
log.Info("enter queue id is %d time is %s", id, now)
if err = conn.Send("LPUSH", key, id); err != nil {
log.Error("d.LPUSH error(%v)", err)
return
}
}
if err = conn.Flush(); err != nil {
log.Error("conn.Flush error(%v)", err)
}
return
}
// ExistKey .
func (d *Dao) ExistKey(c context.Context, key string) (exist bool, err error) {
conn := d.redis.Get(c)
defer conn.Close()
exist, err = redis.Bool(conn.Do("EXISTS", key))
return
}
// SetString .
func (d *Dao) SetString(c context.Context, key, val string) (err error) {
var conn = d.redis.Get(c)
defer conn.Close()
_, err = conn.Do("SET", key, val)
return
}
// SetCrash .
func (d *Dao) SetCrash(c context.Context) (err error) {
key, val := "dead", "1"
err = d.SetString(c, key, val)
return
}
// IsCrash .
func (d *Dao) IsCrash(c context.Context) (exist bool, err error) {
key := "dead"
exist, err = d.ExistKey(c, key)
return
}
// UperInfoCache 读取用户维度的申诉weight计算参数
func (d *Dao) UperInfoCache(c context.Context, apIDs []int64) (params []int64, err error) {
conn := d.redis.Get(c)
defer conn.Close()
args := redis.Args{}
args = args.Add(_keyUperWeightGroup)
for _, apid := range apIDs {
args = args.Add(apid)
}
if params, err = redis.Int64s(conn.Do("HMGET", args...)); err != nil {
log.Error("HMGET %v error(%v)", args, err)
}
return
}
// DelUperInfo .
func (d *Dao) DelUperInfo(c context.Context, mids []int64) (err error) {
conn := d.redis.Get(c)
defer conn.Close()
args := redis.Args{}
args = args.Add(_keyUperWeightGroup)
for _, mid := range mids {
args = args.Add(mid)
}
if _, err = conn.Do("HDEL", args...); err != nil {
log.Error("HDEL %v error(%v)", args, err)
}
return
}
// SetWeightSortedSet 覆盖sorted set
func (d *Dao) SetWeightSortedSet(c context.Context, bid int, newWeight map[int64]int64) (err error) {
key := _prefixKeyMissionSortedSet + strconv.Itoa(bid)
conn := d.redis.Get(c)
defer conn.Close()
args := redis.Args{}
args = args.Add(key)
for id, weight := range newWeight {
args = args.Add(weight, id)
}
if _, err = conn.Do("ZADD", args...); err != nil { // ZADD key score member [[score member] [score member] ...]
log.Error("ZADD %v error(%v)", args, err)
}
return
}
// SingleExpire 获取所有的 single expire 信息
func (d *Dao) SingleExpire(c context.Context, bid int) (delIDs []int64, err error) {
key := _prefixKeySingleExpire + strconv.Itoa(bid)
conn := d.redis.Get(c)
defer conn.Close()
floorTime := time.Now().Add(-480 * time.Second).Unix()
// fixme if too hash field too many
delIDs, err = redis.Int64s(conn.Do("ZRANGEBYSCORE", key, "0", floorTime, "LIMIT", "0", "50"))
return
}
// DelSingleExpire .
func (d *Dao) DelSingleExpire(c context.Context, bid int, ids []int64) (err error) {
key := _prefixKeySingleExpire + strconv.Itoa(bid)
conn := d.redis.Get(c)
defer conn.Close()
args := redis.Args{}
args = args.Add(key)
for _, apID := range ids {
args = args.Add(apID)
}
if _, err = conn.Do("ZREM", args...); err != nil {
log.Error("ZREM %v error(%v)", args, err)
}
return
}
// DelRelatedMissions .
func (d *Dao) DelRelatedMissions(ctx context.Context, bid, transAdmin int, ids []int64) (err error) {
if len(ids) == 0 {
return
}
key := fmt.Sprintf(_relatedMissions, transAdmin, bid)
conn := d.redis.Get(ctx)
defer conn.Close()
args := redis.Args{}.Add(key)
for _, id := range ids {
args = args.Add(id)
}
_, err = conn.Do("ZREM", args...)
return
}

View File

@@ -0,0 +1,132 @@
package dao
import (
"context"
"fmt"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSetList(t *testing.T) {
convey.Convey("SetList", t, func(ctx convey.C) {
var (
c = context.Background()
key = "test_list"
ids = []int64{1}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetList(c, key, ids)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoExistKey(t *testing.T) {
convey.Convey("ExistKey", t, func(ctx convey.C) {
var (
c = context.Background()
key = ""
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
exist, err := d.ExistKey(c, key)
ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(exist, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSetString(t *testing.T) {
convey.Convey("SetString", t, func(ctx convey.C) {
var (
c = context.Background()
key = ""
val = ""
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetString(c, key, val)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoSetCrash(t *testing.T) {
convey.Convey("SetCrash", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetCrash(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoIsCrash(t *testing.T) {
convey.Convey("IsCrash", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
exist, err := d.IsCrash(c)
ctx.Convey("Then err should be nil.exist should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(exist, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoUperInfoCache(t *testing.T) {
convey.Convey("UpInfoCache", t, func(ctx convey.C) {
var (
c = context.Background()
mids = []int64{0}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
groups, err := d.UperInfoCache(c, mids)
ctx.Convey("Then err should be nil.groups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(groups, convey.ShouldNotBeNil)
fmt.Println("len groups", len(groups), groups)
})
})
})
}
func TestDaoSetWeightSortedSet(t *testing.T) {
convey.Convey("SetWeightSortedSet", t, func(ctx convey.C) {
var (
c = context.Background()
newWeigt = map[int64]int64{1: 200, 2: 1, 3: 10}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
err := d.SetWeightSortedSet(c, 1, newWeigt)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestDaoKeysSingleExpire(t *testing.T) {
convey.Convey("KeysSingleExpire", t, func(ctx convey.C) {
var (
c = context.Background()
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
_, err := d.SingleExpire(c, 1)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,57 @@
package dao
import (
"context"
"go-common/app/job/main/workflow/model"
"go-common/library/database/elastic"
"go-common/library/log"
)
const (
challBusiness = "workflow_chall_common"
challIndex = "workflow_chall_common"
appealBusiness = "workflow_appeal"
appealIndex = "workflow_appeal"
)
// SearchChall .
func (d *Dao) SearchChall(c context.Context, params *model.SearchParams) (res *model.ChallSearchCommonRes, err error) {
r := d.es.NewRequest(challBusiness).Fields("id").
Index(challIndex).
WhereEq("business", params.Business).
WhereEq("state", params.States).
WhereEq("business_state", params.BusinessStates)
if params.AssigneeAdminIDs != "" {
r = r.WhereEq("assignee_adminid", params.AssigneeAdminIDs)
}
if params.AssigneeAdminIDsNot != "" {
r = r.WhereNot("assignee_adminid", params.AssigneeAdminIDsNot)
}
if params.MtimeTo != "" {
r = r.WhereRange("mtime", "", params.MtimeTo, elastic.RangeScopeLcRo)
}
log.Info("search condition %v", r.Params())
err = r.Scan(c, &res)
return
}
// SearchAppeal .
func (d *Dao) SearchAppeal(c context.Context, cond model.AppealSearchCond) (res *model.AppealSearchRes, err error) {
r := d.es.NewRequest(appealBusiness).Index(appealIndex).Fields(cond.Fields...).WhereIn("bid", cond.Bid).
WhereIn("id", cond.IDs).WhereIn("assign_state", cond.AssignState).WhereIn("audit_state", cond.AuditState).
WhereIn("transfer_state", cond.TransferState).WhereIn("audit_adminid", cond.AuditAdmin).
WhereIn("transfer_adminid", cond.TransferAdmin).WhereRange("ctime", cond.CTimeFrom, cond.CTimeTo, elastic.RangeScopeLcRo).
WhereRange("dtime", cond.DTimeFrom, cond.DTimeTo, elastic.RangeScopeLcRo).WhereRange("ttime", cond.TTimeFrom, cond.TTimeTo, elastic.RangeScopeLcRo).
WhereRange("mtime", cond.MTimeFrom, cond.MTimeTo, elastic.RangeScopeLcRo).Order(cond.Order, cond.Sort).Pn(cond.PN).Ps(cond.PS)
log.Info("search condition (%v)", r.Params())
if err = r.Scan(c, &res); err != nil {
log.Error("r.Scan(%+v) error(%v)", &res, err)
}
if res == nil {
res = new(model.AppealSearchRes)
}
return
}

View File

@@ -0,0 +1,51 @@
package dao
import (
"context"
"testing"
"time"
"go-common/app/job/main/workflow/model"
"github.com/smartystreets/goconvey/convey"
)
func TestDaoSearchChall(t *testing.T) {
convey.Convey("SearchChall", t, func(ctx convey.C) {
var (
c = context.Background()
params = &model.SearchParams{}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.SearchChall(c, params)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}
func TestDaoSearchAppeal(t *testing.T) {
convey.Convey("SearchAppeal", t, func(ctx convey.C) {
var (
c = context.Background()
cond = model.AppealSearchCond{
Fields: []string{"id", "mid"},
Bid: []int{2, 28},
TTimeTo: time.Now().AddDate(0, 0, -3).Format("2006-01-02 15:04:05"),
PS: 1000,
PN: 1,
Order: "id",
Sort: "desc",
}
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
res, err := d.SearchAppeal(c, cond)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(res, convey.ShouldNotBeNil)
})
})
})
}