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,48 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"creditlog.go",
"score_section_history.go",
"up_base_info.go",
"up_score_history.go",
],
importmap = "go-common/app/service/main/upcredit/model/upcrmmodel",
importpath = "go-common/app/service/main/upcredit/model/upcrmmodel",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//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"],
)
go_test(
name = "go_default_test",
srcs = ["creditlog_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//library/time:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)

View File

@ -0,0 +1,122 @@
package upcrmmodel
import (
"encoding/json"
"fmt"
"go-common/library/time"
systime "time"
)
const (
//BusinessTypeArticleAudit 1
BusinessTypeArticleAudit = 1
)
const (
//DateStr date format
DateStr = "2006-01-02"
//CreditLogTableCount all credit log table count
CreditLogTableCount = 100
)
//ArgCreditLogAdd arg
type ArgCreditLogAdd struct {
Type int `form:"type" json:"type"` // 日志类型,具体与业务方确定
OpType int `form:"op_type" json:"optype"` // 操作类型,具体与业务方确定
Reason int `form:"reason" json:"reason"` // 原因类型,具体与业务方确定
BusinessType int `form:"bussiness_type" json:"business_type"` // 业务类型
Mid int64 `form:"mid" validate:"required" json:"mid"` // 用户id
Oid int64 `form:"oid" json:"oid"` // 对象类型如aid
UID int `form:"uid" json:"uid"` // 管理员id
Content string `form:"content" json:"content"` // 日志内容描述
CTime time.Time `form:"ctime" json:"ctime"` // 创建时间
Extra json.RawMessage `form:"extra" json:"extra,omitempty"` // 额外字段,与业务方确定
}
//ArgMidDate arg
type ArgMidDate struct {
Mid int64 `form:"mid" validate:"required"`
Days int `form:"days"` // 最近n天内的数据1表示最近1天今天2表示最近2天默认为0
FromDate string `form:"from_date"` // 2006-01-02
ToDate string `form:"to_date"` // 2006-01-02
ScoreType int `form:"score_type" default:"3"` // 分数类型, 1,2,3参见ScoreTypeCredit
}
//GetScoreParam arg
type GetScoreParam struct {
Mid int64
FromDate systime.Time
ToDate systime.Time
ScoreType int
}
//ArgGetLogHistory arg
type ArgGetLogHistory struct {
Mid int64 `form:"mid" validate:"required"`
FromDate systime.Time `form:"from_date"`
ToDate systime.Time `form:"to_date"`
Limit int `form:"limit" default:"20"`
}
//CreditLog db struct
type CreditLog struct {
ID uint `gorm:"primary_key" json:"-"`
Type int
OpType int
Reason int
BusinessType int
Mid int64
Oid int64
UID int `gorm:"column:uid"`
Content string
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
Extra string `sql:"type:text;" json:"-"`
}
//TableName table name
func (c *CreditLog) TableName() string {
return getTableName(c.Mid)
}
func getTableName(mid int64) string {
return fmt.Sprintf("credit_log_%02d", mid%CreditLogTableCount)
}
//CopyFrom copy
func (c *CreditLog) CopyFrom(arg *ArgCreditLogAdd) *CreditLog {
c.Type = arg.Type
c.OpType = arg.OpType
c.BusinessType = arg.BusinessType
c.Reason = arg.Reason
c.Mid = arg.Mid
c.Oid = arg.Oid
c.UID = arg.UID
c.Content = arg.Content
c.CTime = arg.CTime
c.MTime = arg.CTime
c.Extra = string(arg.Extra)
return c
}
//SimpleCreditLog db struct
type SimpleCreditLog struct {
ID uint `gorm:"primary_key" json:"-"`
Type int `json:"type"`
OpType int `json:"op_type"`
Reason int `json:"reason"`
BusinessType int `json:"business_type"`
Mid int64 `json:"mid"`
Oid int64 `json:"oid"`
CTime time.Time `gorm:"column:ctime" json:"ctime"`
}
//TableName table name
func (c *SimpleCreditLog) TableName() string {
return getTableName(c.Mid)
}
//SimpleCreditLogWithContent log with content
type SimpleCreditLogWithContent struct {
SimpleCreditLog
Content string `form:"content" json:"content"` // 日志内容描述
}

View File

@ -0,0 +1,32 @@
package upcrmmodel
import (
"encoding/json"
. "github.com/smartystreets/goconvey/convey"
"go-common/library/time"
"testing"
xtime "time"
)
func Test_Orm(t *testing.T) {
var (
arg = ArgCreditLogAdd{
BusinessType: 1,
Type: 1,
OpType: 2,
Reason: 101,
Mid: 12345,
Oid: 13021,
UID: 1,
Content: "稿件打回",
CTime: time.Time(xtime.Now().Unix()),
Extra: []byte("{ \"key\" : \"value\"}"),
}
)
Convey("orm", t, func() {
Convey("connect", func() {
var js, _ = json.Marshal(arg)
t.Log(string(js))
})
})
}

View File

@ -0,0 +1,22 @@
package upcrmmodel
import "go-common/library/time"
//ScoreSectionHistory score section db
type ScoreSectionHistory struct {
ID uint32
GenerateDate time.Time `gorm:"column:generate_date"`
ScoreType int `gorm:"column:score_type"`
Section0 int `gorm:"column:section_0"`
Section1 int `gorm:"column:section_1"`
Section2 int `gorm:"column:section_2"`
Section3 int `gorm:"column:section_3"`
Section4 int `gorm:"column:section_4"`
Section5 int `gorm:"column:section_5"`
Section6 int `gorm:"column:section_6"`
Section7 int `gorm:"column:section_7"`
Section8 int `gorm:"column:section_8"`
Section9 int `gorm:"column:section_9"`
CTime time.Time `gorm:"column:ctime"`
MTime time.Time `gorm:"column:mtime"`
}

View File

@ -0,0 +1,28 @@
package upcrmmodel
import "go-common/library/time"
//UpBaseInfo db struct
type UpBaseInfo struct {
ID int32
Mid int32
Name string
Sex int8
JoinTime time.Time
FirstUpTime time.Time
Level int16
FansCount int
AccountState int
Activity int
ArticleCount30day int `gorm:"article_count_30day"`
ArticleCountAccumulate int
VerifyType int8
CTime time.Time `gorm:"ctime"`
MTime time.Time `gorm:"mtim"`
BusinessType int8
CreditScore int
PrScore int
QualityScore int
ActiveTid int16
Attr int
}

View File

@ -0,0 +1,38 @@
package upcrmmodel
import (
"fmt"
"go-common/library/time"
)
const (
//ScoreTypeQuality 1
ScoreTypeQuality = 1 // 质量分
//ScoreTypePr 2
ScoreTypePr = 2 // 影响力分
//ScoreTypeCredit 3
ScoreTypeCredit = 3 // 信用分
//UpScoreHistoryTableCount table count
UpScoreHistoryTableCount = 100
)
//UpScoreHistory db struct
type UpScoreHistory struct {
ID uint `gorm:"primary_key" json:"-"`
Mid int64 `json:"mid"`
ScoreType int `json:"-"`
Score int ` json:"score"`
GenerateDate time.Time `json:"date"`
CTime time.Time `gorm:"column:ctime" json:"-"`
MTime time.Time `gorm:"column:mtime" json:"-"`
}
func getTableNameUpScoreHistory(mid int64) string {
return fmt.Sprintf("up_scores_history_%02d", mid%UpScoreHistoryTableCount)
}
//TableName table name
func (u *UpScoreHistory) TableName() string {
return getTableNameUpScoreHistory(u.Mid)
}