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,36 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"log.go",
"model.go",
"page.go",
"params.go",
],
importpath = "go-common/app/admin/main/relation/model",
tags = ["automanaged"],
deps = [
"//app/service/main/relation/model: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,89 @@
package model
import (
"sort"
"strconv"
"time"
xtime "go-common/library/time"
)
// RelationLog is
type RelationLog struct {
Mid int64 `json:"mid"`
Fid int64 `json:"fid"`
MemberName string `json:"member_name"`
FollowingName string `json:"following_name"`
Source int32 `json:"source"`
MTime xtime.Time `json:"mtime"`
Attention int32 `json:"attention"`
Black int32 `json:"black"`
Whisper int32 `json:"whisper"`
AttrField string `json:"attr_field"`
AttrChange string `json:"attr_change"`
}
// FillAttrField is
func (l *RelationLog) FillAttrField() {
if l.Attention > 0 {
l.AttrField = "attention"
return
}
if l.Black > 0 {
l.AttrField = "black"
return
}
if l.Whisper > 0 {
l.AttrField = "whisper"
return
}
}
// RelationLogList is
type RelationLogList []*RelationLog
// Len is
func (rl RelationLogList) Len() int {
return len(rl)
}
// Swap is
func (rl RelationLogList) Swap(i, j int) {
rl[i], rl[j] = rl[j], rl[i]
}
// Less is
func (rl RelationLogList) Less(i, j int) bool {
return rl[i].MTime < rl[j].MTime
}
// OrderByMTime is
func (rl RelationLogList) OrderByMTime(desc bool) {
sort.Sort(rl)
}
// ParseAction is
func ParseAction(act string) int32 {
i, _ := strconv.ParseInt(act, 10, 32)
return int32(i)
}
// ParseSource is
func ParseSource(src string) int32 {
i, _ := strconv.ParseInt(src, 10, 64)
return int32(i)
}
// ParseLogTime is
func ParseLogTime(ts string) (xt xtime.Time, err error) {
var (
t time.Time
)
if t, err = time.ParseInLocation("2006-01-02 15:04:05", ts, time.Local); err != nil {
return
}
xt.Scan(t)
return
}

View File

@@ -0,0 +1,136 @@
package model
import (
smodel "go-common/app/service/main/relation/model"
"go-common/library/time"
"sort"
)
// Relation is
type Relation struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Fid int64 `json:"fid" gorm:"column:fid"`
Attribute uint32 `json:"attribute" gorm:"column:attribute"`
Status int8 `json:"status" gorm:"column:status"`
Source int8 `json:"source" gorm:"column:source"`
CTime time.Time `json:"ctime" gorm:"column:ctime"`
MTime time.Time `json:"mtime" gorm:"column:mtime"`
Relation uint32 `json:"relation"`
}
// Stat is
type Stat struct {
ID int64 `json:"id" gorm:"column:id"`
Mid int64 `json:"mid" gorm:"column:mid"`
Following int64 `json:"following" gorm:"column:following"`
Whisper int64 `json:"whisper" gorm:"column:whisper"`
Black int64 `json:"black" gorm:"column:black"`
Follower int64 `json:"follower" gorm:"column:follower"`
CTime time.Time `json:"ctime" gorm:"column:ctime"`
MTime time.Time `json:"mtime" gorm:"column:mtime"`
}
// ParseRelation is
func (r *Relation) ParseRelation() {
r.Relation = smodel.Attr(r.Attribute)
}
// Follower is
type Follower struct {
*Relation
MemberName string `json:"member_name"`
FollowerName string `json:"follower_name"`
}
// Following is
type Following struct {
*Relation
MemberName string `json:"member_name"`
FollowingName string `json:"following_name"`
}
// RelationList is
type RelationList []*Relation
// FollowersList is
type FollowersList []*Follower
// FollowingsList is
type FollowingsList []*Following
func (rl RelationList) Len() int {
return len(rl)
}
func (rl RelationList) Swap(i, j int) {
rl[i], rl[j] = rl[j], rl[i]
}
func (rl RelationList) Less(i, j int) bool {
return rl[i].MTime < rl[j].MTime
}
// Paginate is
func (rl RelationList) Paginate(skip int, size int) RelationList {
if skip > len(rl) {
skip = len(rl)
}
end := skip + size
if end > len(rl) {
end = len(rl)
}
return rl[skip:end]
}
// FilterMTimeFrom is
func (rl RelationList) FilterMTimeFrom(from time.Time) RelationList {
res := make(RelationList, 0)
for _, r := range rl {
if r.MTime >= from {
res = append(res, r)
}
}
return res
}
// FilterMTimeTo is
func (rl RelationList) FilterMTimeTo(to time.Time) RelationList {
res := make(RelationList, 0)
for _, r := range rl {
if r.MTime <= to {
res = append(res, r)
}
}
return res
}
// OrderByMTime is
func (rl RelationList) OrderByMTime(desc bool) {
sort.Sort(rl)
}
// FollowersList is
func (rl RelationList) FollowersList() FollowersList {
res := make(FollowersList, 0, len(rl))
for _, r := range rl {
res = append(res, &Follower{
Relation: r,
})
}
return res
}
// FollowingsList is
func (rl RelationList) FollowingsList() FollowingsList {
res := make(FollowingsList, 0, len(rl))
for _, r := range rl {
res = append(res, &Following{
Relation: r,
})
}
return res
}

View File

@@ -0,0 +1,23 @@
package model
// FollowersListPage is the model for followers list result
type FollowersListPage struct {
TotalCount int `json:"total_count"`
PN int `json:"pn"`
PS int `json:"ps"`
List FollowersList `json:"list"`
Order string `json:"order"`
Sort string `json:"sort"`
}
// FollowingsListPage is the model for followings list result
type FollowingsListPage struct {
TotalCount int `json:"total_count"`
PN int `json:"pn"`
PS int `json:"ps"`
List FollowingsList `json:"list"`
Order string `json:"order"`
Sort string `json:"sort"`
}

View File

@@ -0,0 +1,63 @@
package model
import (
xtime "go-common/library/time"
"time"
)
// Pagination is
type Pagination struct {
Sort string `form:"sort"`
Order string `form:"order"`
PS int `form:"ps" validate:"min=0,max=50"`
PN int `form:"pn" validate:"min=0"`
MTimeFrom string `form:"mtime_from"`
MTimeTo string `form:"mtime_to"`
}
// FollowersParam is
type FollowersParam struct {
Pagination
Fid int64 `form:"fid" validate:"min=1,required"`
Mid int64 `form:"mid" validate:"min=0"`
}
// FollowingsParam is
type FollowingsParam struct {
Pagination
Mid int64 `form:"mid" validate:"min=1,required"`
Fid int64 `form:"fid" validate:"min=0"`
}
// LogsParam is
type LogsParam struct {
Mid int64 `form:"mid" validate:"min=1,required"`
Fid int64 `form:"fid" validate:"min=1,required"`
}
// ParseTime is
func ParseTime(ts string) (xt xtime.Time, err error) {
var (
t time.Time
)
if t, err = time.Parse("2006-01-02 15:04:05", ts); err != nil {
return
}
xt.Scan(t)
return
}
// Desc is
func (p Pagination) Desc() bool {
return p.Sort == "desc"
}
// ArgMid is
type ArgMid struct {
Mid int64 `form:"mid" validate:"min=1,required"`
}
// ArgMids is
type ArgMids struct {
Mids []int64 `form:"mids,split" validate:"dive,gt=0"`
}