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,58 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["report_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = [
"action.go",
"admin.go",
"business.go",
"common.go",
"config.go",
"csv.go",
"emoji.go",
"monitor.go",
"moral.go",
"notice.go",
"reply.go",
"report.go",
"sql.go",
"subject.go",
],
importpath = "go-common/app/admin/main/reply/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/relation/model:go_default_library",
"//library/ecode:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/pkg/errors: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,21 @@
package model
import (
xtime "go-common/library/time"
)
// Action 点赞或踩
const (
ActionNormal int32 = 0 // 未踩赞
ActionLike int32 = 1 // 赞
ActionHate int32 = 2 // 踩
)
// Action reply action info
type Action struct {
ID int64 `json:"-"`
RpID int64 `json:"rpid"`
Action int8 `json:"action"`
Mid int64 `json:"mid"`
CTime xtime.Time `json:"-"`
}

View File

@@ -0,0 +1,99 @@
package model
const (
// AdminIsNotReport 不是举报记录
AdminIsNotReport int32 = 0
// AdminIsReport 是举报记录
AdminIsReport = 1
// AdminIsNotNew 不是该评论最新的
AdminIsNotNew int32 = 0
// AdminIsNew 是该评论最新的
AdminIsNew = 1
// AdminOperDelete 管理员删除评论
AdminOperDelete int32 = 0
// AdminOperDeleteByReport 管理员通过举报删除 NOTE Deprecated
AdminOperDeleteByReport = 1
// AdminOperIgnoreReport 管理员忽略举报 NOTE Deprecated
AdminOperIgnoreReport = 2
// AdminOperRecover 管理员恢复评论
AdminOperRecover = 3
// AdminOperEdit 管理员编辑内容
AdminOperEdit = 4
// AdminOperPass 管理通过待审
AdminOperPass = 5
// AdminOperSubState 修改主题的状态
AdminOperSubState = 6
// AdminOperSubTop 置顶评论
AdminOperSubTop = 7
// AdminOperSubMid 修改主题的mid
AdminOperSubMid = 8
// AdminOperRptIgnore1 举报一审忽略
AdminOperRptIgnore1 = 9
// AdminOperRptIgnore2 举报二审忽略
AdminOperRptIgnore2 = 10
// AdminOperRptDel1 举报一审删除
AdminOperRptDel1 = 11
// AdminOperRptDel2 举报二审删除
AdminOperRptDel2 = 12
// AdminOperRptRecover1 举报一审恢复
AdminOperRptRecover1 = 13
// AdminOperRptRecover2 举报二审恢复
AdminOperRptRecover2 = 14
// AdminOperActionSet 对点赞点踩设置
AdminOperActionSet = 15
// AdminOperDeleteUp up主删除评论
AdminOperDeleteUp = 16
// AdminOperDeleteUser 用户删除评论
AdminOperDeleteUser = 17
// AdminOperDeleteAssist 协管删除评论
AdminOperDeleteAssist = 18
// AdminOperSubMonitor 设置监控状态
AdminOperSubMonitor = 19
// AdminOperRptTransfer1 转一审
AdminOperRptTransfer1 = 20
// AdminOperRptTransfer2 转二审
AdminOperRptTransfer2 = 21
// AdminOperRptTransferArbitration 移交仲裁
AdminOperRptTransferArbitration = 22
// AdminOperRptStateSet 设置举报状态
AdminOperRptStateSet = 23
// AdminOperSubMonitorOpen 先发后审打开
AdminOperSubMonitorOpen = 24
// AdminOperSubMonitorClose 先发后审关闭
AdminOperSubMonitorClose = 25
// AdminOperSubAuditOpen 先审后发打开
AdminOperSubAuditOpen = 26
// AdminOperSubAuditClose 先审后发关闭
AdminOperSubAuditClose = 27
// AdminOperMarkSpam 标记为垃圾
AdminOperMarkSpam = 28
)
// AdminLog log.
type AdminLog struct {
ID int64 `json:"id"`
Type int8 `json:"type"`
Oid int64 `json:"oid"`
ReplyID int64 `json:"reply_id"`
AdminID int64 `json:"admin_id"`
Result string `json:"result"`
Remark string `json:"remark"`
IsNew int8 `json:"is_new"`
IsReport int8 `json:"is_report"`
State int8 `json:"state"`
CTime string `json:"ctime"`
MTime string `json:"mtime"`
}
// SearchAdminLog log.
type SearchAdminLog struct {
Type int8 `json:"type"`
Oid int64 `json:"oid"`
ReplyID int64 `json:"rpid"`
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Result string `json:"opresult"`
Remark string `json:"opremark"`
State int8 `json:"state"`
CTime string `json:"opctime"`
}

View File

@@ -0,0 +1,10 @@
package model
// Business Business
type Business struct {
Type int32 `json:"type"`
Name string `json:"name"`
Appkey string `json:"app_key"`
Remark string `json:"remark"`
Alias string `json:"alias"`
}

View File

@@ -0,0 +1,49 @@
package model
import "errors"
var (
// ErrSearchReport search report error
ErrSearchReport = errors.New("search report error")
// ErrSearchReply search reply error
ErrSearchReply = errors.New("search reply error")
// ErrSearchMonitor search monitor error
ErrSearchMonitor = errors.New("search monitor error")
// ErrMsgSend send message error
ErrMsgSend = errors.New("send message error")
// AttrNo attribute no
AttrNo = uint32(0)
// AttrYes attribute yes
AttrYes = uint32(1)
// EventReportAdd event add a report
EventReportAdd = "report_add"
// EventReportDel event del a report
EventReportDel = "report_del"
// EventReportIgnore event ignore a report
EventReportIgnore = "report_ignore"
// EventReportRecover event recover a report
EventReportRecover = "report_recover"
)
const (
// WeightLike like sort weight
WeightLike = 2
// WeightHate hate sort weight
WeightHate = 4
)
// Pager page info.
type Pager struct {
Page int64 `json:"page"`
PageSize int64 `json:"pagesize"`
Total int64 `json:"total"`
}
// NewPager NewPager
type NewPager struct {
Num int64 `json:"num"`
Size int64 `json:"size"`
Total int64 `json:"total"`
}

View File

@@ -0,0 +1,21 @@
package model
const (
// ConfigCategoryLogDel ConfigCategoryLogDel
ConfigCategoryLogDel int32 = 1
)
// Config reply config info.
type Config struct {
ID int64 `json:"id"`
Type int32 `json:"type"`
Oid int64 `json:"oid"`
AdminID int64 `json:"adminid"`
Operator string `json:"operator"`
Category int32 `json:"category"`
Config string `json:"config"`
ShowEntry int32 `json:"showentry"`
ShowAdmin int32 `json:"showadmin"`
CTime string `json:"ctime"`
MTime string `json:"mtime"`
}

View File

@@ -0,0 +1,45 @@
package model
import (
"encoding/csv"
"fmt"
"net/http"
"github.com/pkg/errors"
)
// CSV Comma-Separated Values struct.
type CSV struct {
Data [][]string
Title string
}
var csvContentType = []string{"text/csv; charset=utf-8"}
// Render (CSV) writes data with CSV ContentType.
func (c CSV) Render(w http.ResponseWriter) (err error) {
c.WriteContentType(w)
writer := csv.NewWriter(w)
bomUtf8 := []byte{0xEF, 0xBB, 0xBF}
writer.Write([]string{string(bomUtf8[:])})
writer.WriteAll(c.Data)
if err = writer.Error(); err != nil {
err = errors.WithStack(err)
}
return
}
func writeContentType(w http.ResponseWriter, value []string, title string) {
header := w.Header()
if val := header["Content-Type"]; len(val) == 0 {
header["Content-Type"] = value
}
if title != "" {
header["Content-Disposition"] = append(header["Content-Disposition"], fmt.Sprintf("attachment; filename=%s.csv", title))
}
}
// WriteContentType write CSV ContentType.
func (c CSV) WriteContentType(w http.ResponseWriter) {
writeContentType(w, csvContentType, c.Title)
}

View File

@@ -0,0 +1,23 @@
package model
// Emoji Emoji
type Emoji struct {
ID int64 `json:"id"`
PackageID int64 `json:"package_id"`
Name string `json:"name"`
URL string `json:"url"`
State int32 `json:"state"`
Sort int32 `json:"sort"`
Remark string `json:"remark"`
}
// EmojiPackage emoji package
type EmojiPackage struct {
ID int64 `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
State int32 `json:"state"`
Sort int32 `json:"sort"`
Remark string `json:"remark"`
Emojis []*Emoji `json:"emojis"`
}

View File

@@ -0,0 +1,113 @@
package model
const (
// MonitorClose 取消监控
MonitorClose = int32(0)
// MonitorOpen 打开监控
MonitorOpen = int32(1)
// MonitorAudit 先审后发
MonitorAudit = int32(2)
// MonitorStatsAll all
MonitorStatsAll = 1
// MonitorStatsUser all
MonitorStatsUser = 2
)
// SearchMonitorParams search params.
type SearchMonitorParams struct {
Mode int8
Type int8
Oid int64
UID int64
NickName string
Keyword string
Sort string
Order string
}
// SearchMonitor search monitor.
type SearchMonitor struct {
ID int64 `json:"id"`
Oid int64 `json:"oid"`
OidStr string `json:"oid_str"`
Type int8 `json:"type"`
Mid int64 `json:"mid"`
State int8 `json:"state"`
Attr int32 `json:"attr"`
Ctime string `json:"ctime"`
Mtime string `json:"mtime"`
Title string `json:"title"`
Uname string `json:"uname"`
UnverifyNmu int `json:"unverify_num"`
MCount int32 `json:"mcount"`
DocID string `json:"doc_id"`
Remark string `json:"remark"`
}
// SearchMonitorResult search result.
type SearchMonitorResult struct {
Code int `json:"code,omitempty"`
Page int64 `json:"page"`
PageSize int64 `json:"pagesize"`
PageCount int64 `json:"pagecount"`
Total int64 `json:"total"`
Order string `json:"order"`
Result []*SearchMonitor `json:"result"`
Message string `json:"msg,omitempty"`
}
// StatsMonitor stats monitor.
type StatsMonitor struct {
Date string `json:"date"`
AdminID int64 `json:"adminid"`
MonitorTotal int64 `json:"monitor_total"`
MonitorPending int64 `json:"monitor_pending"`
MonitorPass int64 `json:"monitor_pass"`
MonitorDel int64 `json:"monitor_del"`
MonitorAvgCost string `json:"monitor_avg_cost"`
}
// StatsMonitorResult search result.
type StatsMonitorResult struct {
Code int `json:"code,omitempty"`
Page int `json:"page"`
PageSize int `json:"pagesize"`
PageCount int `json:"pagecount"`
Total int `json:"total"`
Order string `json:"order"`
Message string `json:"msg,omitempty"`
Result []*StatsMonitor `json:"result"`
}
// MonitorLogResult MonitorLogResult
type MonitorLogResult struct {
Logs []*MonitorLog `json:"logs"`
Page Page `json:"page"`
Order string `json:"order"`
Sort string `json:"sort"`
}
// Page Page
type Page struct {
Num int64 `json:"num"`
Size int64 `json:"size"`
Total int64 `json:"total"`
}
// MonitorLog MonitorLog
type MonitorLog struct {
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Oid int64 `json:"oid"`
OidStr string `json:"oid_str"`
Type int32 `json:"type"`
Title string `json:"title"`
RedirectURL string `json:"redirect_url"`
Remark string `json:"remark"`
UserName string `json:"username"`
Mid int64 `json:"mid"`
CTime string `json:"ctime"`
LogState int64 `json:"log_state"`
State int64 `json:"state"`
}

View File

@@ -0,0 +1,120 @@
package model
import "fmt"
const (
// ReportReasonOther 其他
ReportReasonOther = int32(0)
// ReportReasonAd 广告
ReportReasonAd = int32(1)
// ReportReasonPorn 色情
ReportReasonPorn = int32(2)
// ReportReasonMeaningless 刷屏
ReportReasonMeaningless = int32(3)
// ReportReasonProvoke 引站
ReportReasonProvoke = int32(4)
// ReportReasonSpoiler 剧透
ReportReasonSpoiler = int32(5)
// ReportReasonPolitic 政治
ReportReasonPolitic = int32(6)
// ReportReasonAttack 人身攻击
ReportReasonAttack = int32(7)
// ReportReasonUnrelated 视频不相关
ReportReasonUnrelated = int32(8)
// ReportReasonProhibited 违禁
ReportReasonProhibited = int32(9)
// ReportReasonVulgar 低俗
ReportReasonVulgar = int32(10)
// ReportReasonIllegalWebsite 非法网站
ReportReasonIllegalWebsite = int32(11)
// ReportReasonGamblingFraud 赌博诈骗
ReportReasonGamblingFraud = int32(12)
// ReportReasonRumor 传播不实信息
ReportReasonRumor = int32(13)
// ReportReasonAbetting 怂恿教唆信息
ReportReasonAbetting = int32(14)
// ReportReasonPrivacyInvasion 侵犯隐私
ReportReasonPrivacyInvasion = int32(15)
// ReportReasonUnlimitedSign 抢楼
ReportReasonUnlimitedSign = int32(16)
// ForbidReasonSpoiler 发布剧透信息
ForbidReasonSpoiler = int32(10)
// ForbidReasonAd 发布垃圾广告信息
ForbidReasonAd = int32(6)
// ForbidReasonUnlimitedSign 抢楼
ForbidReasonUnlimitedSign = int32(2)
// ForbidReasonMeaningless 刷屏
ForbidReasonMeaningless = int32(1)
// ForbidReasonProvoke 发布引战言论
ForbidReasonProvoke = int32(9)
// ForbidReasonVulgar 发布低俗信息
ForbidReasonVulgar = int32(14)
// ForbidReasonGamblingFraud 发布赌博诈骗信息
ForbidReasonGamblingFraud = int32(4)
// ForbidReasonPorn 发布色情信息
ForbidReasonPorn = int32(13)
// ForbidReasonRumor 发布传播不实信息
ForbidReasonRumor = int32(18)
// ForbidReasonIllegalWebsite 发布非法网站信息
ForbidReasonIllegalWebsite = int32(17)
// ForbidReasonAbetting 发布怂恿教唆信息
ForbidReasonAbetting = int32(19)
// ForbidReasonProhibited 发布违禁信息
ForbidReasonProhibited = int32(5)
// ForbidReasonPrivacyInvasion 涉及侵犯他人隐私
ForbidReasonPrivacyInvasion = int32(8)
// ForbidReasonAttack 发布人身攻击言论
ForbidReasonAttack = int32(7)
// ForbidReasonInaptitude 发布不适宜内容
ForbidReasonInaptitude = int32(28)
)
var (
// NotifyComRules 社区规则
NotifyComRules = fmt.Sprintf(`评论区是公众场所,而非私人场所,具体规范烦请参阅#{《社区规则》}{"%s"},良好的社区氛围需要大家一起维护!`, "http://www.bilibili.com/blackboard/blackroom.html")
// NotifyComRulesReport 举报
NotifyComRulesReport = "感谢您对bilibili社区秩序的维护哔哩哔哩 (゜-゜)つロ 干杯~"
// NotifyComUnrelated NotifyComUnrelated
NotifyComUnrelated = "bilibili倡导发送与视频相关的评论希望大家尊重作品尊重UP主。良好的社区氛围需要大家一起维护"
// NotifyComProvoke NotifyComProvoke
NotifyComProvoke = "bilibili倡导平等友善的交流。良好的社区氛围需要大家一起维护"
// NofityComProhibited NofityComProhibited
NofityComProhibited = fmt.Sprintf(`请自觉遵守国家相关法律法规及#{《社区规则》}{"%s"}bilibili良好的社区氛围需要大家一起维护`, "http://www.bilibili.com/blackboard/blackroom.html")
// ReportReason 举报理由类型
ReportReason = map[int32]string{
ReportReasonAd: "内容涉及垃圾广告",
ReportReasonPorn: "内容涉及色情",
ReportReasonMeaningless: "刷屏",
ReportReasonProvoke: "内容涉及引战",
ReportReasonSpoiler: "内容涉及视频剧透",
ReportReasonPolitic: "内容涉及政治相关",
ReportReasonAttack: "内容涉及人身攻击",
ReportReasonUnrelated: "视频不相关",
ReportReasonProhibited: "内容涉及违禁相关",
ReportReasonVulgar: "内容涉及低俗信息",
ReportReasonIllegalWebsite: "内容涉及非法网站信息",
ReportReasonGamblingFraud: "内容涉及赌博诈骗信息",
ReportReasonRumor: "内容涉及传播不实信息",
ReportReasonAbetting: "内容不适宜",
ReportReasonPrivacyInvasion: "内容涉及侵犯他人隐私",
ReportReasonUnlimitedSign: "抢楼",
}
// ForbidReason 封禁理由类型
ForbidReason = map[int32]string{
ForbidReasonSpoiler: "发布剧透信息",
ForbidReasonAd: "发布垃圾广告信息",
ForbidReasonUnlimitedSign: "抢楼",
ForbidReasonMeaningless: "刷屏",
ForbidReasonProvoke: "发布引战言论",
ForbidReasonVulgar: "发布低俗信息",
ForbidReasonGamblingFraud: "发布赌博诈骗信息",
ForbidReasonPorn: "发布色情信息",
ForbidReasonRumor: "发布传播不实信息",
ForbidReasonIllegalWebsite: "发布非法网站信息",
ForbidReasonAbetting: "发布怂恿教唆信息",
ForbidReasonProhibited: "发布违禁信息",
ForbidReasonPrivacyInvasion: "涉及侵犯他人隐私",
ForbidReasonAttack: "发布人身攻击言论",
ForbidReasonInaptitude: "发布不适宜内容",
}
)

View File

@@ -0,0 +1,68 @@
package model
import (
xtime "go-common/library/time"
)
// NoticeCondition NoticeCondition
type NoticeCondition uint8
// NoticeStatus NoticeStatus
type NoticeStatus uint8
// NoticePlat NoticePlat
type NoticePlat uint8
const (
// PlatUnknow PlatUnknow
PlatUnknow NoticePlat = 0
// PlatWeb PlatUnknow
PlatWeb NoticePlat = 1
// PlatAndroid PlatAndroid
PlatAndroid NoticePlat = 2
// PlatIPhone PlatIPhone
PlatIPhone NoticePlat = 3
// PlatWpM wp mobile
PlatWpM NoticePlat = 4
// PlatIPad PlatIPad
PlatIPad NoticePlat = 5
// PlatPadHd ipad hd
PlatPadHd NoticePlat = 6
// PlatWpPc win10
PlatWpPc NoticePlat = 7
)
const (
// StatusOffline StatusOffline
StatusOffline NoticeStatus = 0
// StatusOnline StatusOnline
StatusOnline NoticeStatus = 1
)
const (
// ConditionEQ ConditionEQ
ConditionEQ NoticeCondition = 0 // condition equal
// ConditionGT ConditionGT
ConditionGT NoticeCondition = 1 // greater
// ConditionLT ConditionLT
ConditionLT NoticeCondition = 2 // less
)
// Notice reply's public notice
type Notice struct {
ID uint32 `json:"id"`
Plat NoticePlat `json:"plat"`
Version string `json:"version"`
Condition NoticeCondition `json:"condi"`
Build uint32 `json:"build"`
Title string `json:"title"`
Content string `json:"content"`
Link string `json:"link"`
StartTime xtime.Time `json:"stime"`
EndTime xtime.Time `json:"etime"`
Status NoticeStatus `json:"status"`
CreateTime xtime.Time `json:"ctime"`
ModifyTime xtime.Time `json:"mtime"`
//client's program type
ClientType string `json:"client_type"`
}

View File

@@ -0,0 +1,363 @@
package model
import (
"encoding/binary"
"encoding/json"
"net"
"strconv"
"strings"
"time"
rl "go-common/app/service/main/relation/model"
xtime "go-common/library/time"
)
// State 评论状态
const (
StateNormal int32 = 0 // 正常
StateHidden int32 = 1 // up主隐藏
StateFiltered int32 = 2 // 敏感词过滤 @Deprecated to use attr 3
StateDelAdmin int32 = 3 // 管理员删除
StateDelUser int32 = 4 // 用户删除
StateMonitor int32 = 5 // 监控中
StateGarbage int32 = 6 // 大数据过虑 @Deprecated to use attr 2
StateTopAdmin int32 = 7 // 管理员置顶 @Deprecated to use attr 1
StateDelUpper int32 = 8 // up主删除
StateBlacklist int32 = 9 // 黑名单屏蔽
StateDelAssist int32 = 10 // 协管删除
StatePending int32 = 11 // 先审后发
StateFolded int32 = 12 // 被折叠
)
// Attr 评论属性
const (
AttrTopAdmin uint32 = 0 // 管理员置顶
AttrTopUpper uint32 = 1 // up主置顶
AttrGarbage uint32 = 2 // 大数据过滤
AttrFiltered uint32 = 3 // 敏感词过滤
// 有子评论被折叠
AttrFolded uint32 = 7
)
// SortBy 排序方式
const (
SortByFloor int32 = 0 // 按楼层排序
SortByCount int32 = 1 // 按评论数排序
SortByLike int32 = 2 // 按点赞数排序
)
// 折叠评论类型
const (
FolderKindSub = "s"
FolderKindRoot = "r"
)
// SearchParams reply params.
type SearchParams struct {
Type int32
Oid int64
TypeIds string
Keyword string
KeywordHigh string
UID int64
Uname string
AdminID int64
AdminName string
Begin time.Time
End time.Time
States string
IP int64
Attr string
Sort string
Order string
}
// ReplySearchResponse ReplySearchResponse
type ReplySearchResponse struct {
SearchResult
Pager Pager `json:"pager"`
}
// SearchResult search result.
type SearchResult struct {
Code int `json:"code"`
Message string `json:"msg,omitempty"`
Order string `json:"order"`
Page int64 `json:"page"`
PageSize int64 `json:"pagesize"`
PageCount int64 `json:"pagecount"`
Total int64 `json:"total"`
Result []*SearchReply `json:"result"`
}
// SearchReply search reply.
type SearchReply struct {
// 评论基础信息
ID int64 `json:"id"`
Type int8 `json:"type"`
Oid int64 `json:"oid"`
OidStr string `json:"oid_str"`
State int8 `json:"state"`
Floor int64 `json:"floor"`
Ctime string `json:"ctime"`
Mtime string `json:"mtime"`
Attr Attr `json:"attr"`
Title string `json:"title"`
// 评论人的相关信息
Mid int64 `json:"mid"`
Stat *rl.Stat `json:"stat"`
Replier string `json:"replier"`
IP IP `json:"ip"`
Message string `json:"message"`
Typeid int `json:"typeid"`
Root int `json:"root"`
// 后台操作信息
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Opremark string `json:"opremark"`
Opresult string `json:"opresult"`
OpCtime string `json:"opctime"`
RedirectURL string `json:"redirect_url"`
// 搜索返回的额外数据
DocID string `json:"doc_id"`
}
type IP int64
func (ip *IP) UnmarshalJSON(b []byte) error {
if string(b) == "" {
return nil
}
str := strings.Trim(string(b), `"`)
ipI := net.ParseIP(str).To4()
if ipI == nil {
return nil
}
*ip = IP(int64(binary.BigEndian.Uint32(ipI)))
return nil
}
type Attr []int32
func (a *Attr) UnmarshalJSON(b []byte) error {
var s []int32
err := json.Unmarshal(b, &s)
if err != nil {
attr, err := strconv.ParseInt(string(b), 10, 64)
if err != nil {
return err
}
var i int32 = 1
for attr != 0 && i < 64 {
if attr&1 == 1 {
*a = append(*a, i)
}
attr = attr >> 1
i++
}
} else {
*a = s
}
return nil
}
// Reply info.b
type ReplyEx struct {
Reply
IsUp bool `json:"is_up"`
RootFloor int32 `json:"root_floor"`
}
// Reply info.
type Reply struct {
ID int64 `json:"rpid"`
Oid int64 `json:"oid"`
Type int32 `json:"type"`
Mid int64 `json:"mid"`
Root int64 `json:"root"`
Parent int64 `json:"parent"`
Dialog int64 `json:"dialog"`
Count int32 `json:"count"`
MCount int32 `json:"mcount"`
RCount int32 `json:"rcount"`
Floor int32 `json:"floor"`
State int32 `json:"state"`
Attr uint32 `json:"attr"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"-"`
// action info
Like int32 `json:"like"`
Hate int32 `json:"hate"`
Action int32 `json:"action"`
Content *ReplyContent `json:"content"`
}
// HasFolded ...
func (r *Reply) HasFolded() bool {
return r.AttrVal(AttrFolded) == AttrYes
}
// MarkHasFolded ...
func (r *Reply) MarkHasFolded() {
r.AttrSet(AttrYes, AttrFolded)
}
// UnmarkHasFolded ...
func (r *Reply) UnmarkHasFolded() {
r.AttrSet(AttrNo, AttrFolded)
}
// DenyFolded ...
func (r *Reply) DenyFolded() bool {
return r.IsTop() || !r.AllowFoldState() || r.Type == SubTypeArticle
}
// AllowFoldState ...
func (r *Reply) AllowFoldState() bool {
return r.State == StateNormal || r.State == StateHidden || r.State == StateFiltered || r.State == StateGarbage
}
// IsFolded .
func (r *Reply) IsFolded() bool {
return r.State == StateFolded
}
// IsRoot root.
func (r *Reply) IsRoot() bool {
return r.Root == 0
}
// IsTop top.
func (r *Reply) IsTop() bool {
if r.Attr != 0 && (r.AttrVal(AttrTopAdmin) == 1 || r.AttrVal(AttrTopUpper) == 1) {
return true
}
return false
}
// IsDeleted deleted.
func (r *Reply) IsDeleted() bool {
return r.State == StateDelUser || r.State == StateDelUpper || r.State == StateDelAdmin
}
// AttrVal return val of reply'attr
func (r *Reply) AttrVal(bit uint32) uint32 {
if r.Attr == 0 {
return uint32(0)
}
return (r.Attr >> bit) & uint32(1)
}
// AttrSet set attr of reply'attr
func (r *Reply) AttrSet(v uint32, bit uint32) {
r.Attr = r.Attr&(^(1 << bit)) | (v << bit)
}
// IsNormal IsNormal
func (r *Reply) IsNormal() bool {
return r.State == StateNormal || r.State == StateHidden || r.State == StateFiltered || r.State == StateMonitor || r.State == StateGarbage || r.State == StateTopAdmin || r.State == StateFolded
}
func (r *Reply) IsPending() bool {
return r.State == StatePending
}
// LegalSubjectType LegalSubjectType
func LegalSubjectType(tp int32) bool {
return SubTypeArchive <= tp && tp <= SubTypeComicEpisode
}
// ReplyContent define reply content
type ReplyContent struct {
ID int64 `json:"-"`
Message string `json:"message"`
Ats Int64Bytes `json:"ats,omitempty"`
IP uint32 `json:"ipi,omitempty"`
Plat int8 `json:"plat"`
Device string `json:"device"`
Version string `json:"version,omitempty"`
CTime xtime.Time `json:"-"`
MTime xtime.Time `json:"-"`
}
// LogSearchParam LogSearchParam
type LogSearchParam struct {
Oid int64
Type int32
Mid int64
CtimeFrom string
CtimeTo string
Action string
Pn int64
Ps int64
Other int64
Sort string
Order string
Group string
Appid string
}
// ReplyTopLogResult ReplyTopLogResult
type ReplyTopLogResult struct {
Logs []*ReplyTopLog `json:"logs"`
Page Page `json:"page"`
Order string `json:"order"`
Sort string `json:"sort"`
}
// ReplyTopLog ReplyTopLog
type ReplyTopLog struct {
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Oid int64 `json:"oid"`
Type int32 `json:"type"`
Title string `json:"title"`
RedirectURL string `json:"redirect_url"`
Remark string `json:"remark"`
UserName string `json:"username"`
Mid int64 `json:"mid"`
CTime string `json:"ctime"`
RpID int64 `json:"rpid"`
Action int64 `json:"action"`
}
// ExportedReply exported reply struct
type ExportedReply struct {
ID int64 `json:"rpid"`
Oid int64 `json:"oid"`
Type int32 `json:"type"`
Mid int64 `json:"mid"`
Root int64 `json:"root"`
Parent int64 `json:"parent"`
Count int32 `json:"count"`
RCount int32 `json:"rcount"`
Like int32 `json:"like"`
Hate int32 `json:"hate"`
Floor int32 `json:"floor"`
State int32 `json:"state"`
Attr int32 `json:"attr"`
CTime time.Time `json:"ctime"`
Message string `json:"message"`
}
// String convert ExportedReply to string
func (e *ExportedReply) String() (s []string) {
s = append(s, strconv.FormatInt(e.ID, 10))
s = append(s, strconv.FormatInt(e.Oid, 10))
s = append(s, strconv.FormatInt(int64(e.Type), 10))
s = append(s, strconv.FormatInt(e.Mid, 10))
s = append(s, strconv.FormatInt(e.Root, 10))
s = append(s, strconv.FormatInt(e.Parent, 10))
s = append(s, strconv.FormatInt(int64(e.Count), 10))
s = append(s, strconv.FormatInt(int64(e.RCount), 10))
s = append(s, strconv.FormatInt(int64(e.Like), 10))
s = append(s, strconv.FormatInt(int64(e.Hate), 10))
s = append(s, strconv.FormatInt(int64(e.Floor), 10))
s = append(s, strconv.FormatInt(int64(e.State), 10))
s = append(s, strconv.FormatInt(int64(e.Attr), 10))
s = append(s, e.CTime.String())
s = append(s, e.Message)
return
}

View File

@@ -0,0 +1,183 @@
package model
import xtime "go-common/library/time"
var (
// DateFormat date time format
DateFormat = "2006-01-02 15:04:05"
// DateSimpleFormat date simple format
DateSimpleFormat = "2006-01-02"
)
const (
// ReportStateNew 待一审
ReportStateNew = int32(0)
// ReportStateDelete 移除
ReportStateDelete = int32(1)
// ReportStateIgnore 忽略
ReportStateIgnore = int32(2)
// ReportStateDelete1 一审移除
ReportStateDelete1 = int32(3)
// ReportStateNew2 待二审
ReportStateNew2 = int32(4)
// ReportStateDelete2 二审移除
ReportStateDelete2 = int32(5)
// ReportStateIgnore2 二审忽略
ReportStateIgnore2 = int32(6)
// ReportStateIgnore1 一审忽略
ReportStateIgnore1 = int32(7)
// ReportStateTransferred 举报转移风纪委
ReportStateTransferred = int32(8)
// ReportUserStateNew 新增
ReportUserStateNew = int32(0)
// ReportUserStateReported 已反馈
ReportUserStateReported = int32(1)
// ReportAttrTransferred 是否从待一审\二审转换成待二审\一审
ReportAttrTransferred = uint32(0)
// AuditTypeFirst 一审
AuditTypeFirst = int32(1)
// AuditTypeSecond 二审
AuditTypeSecond = int32(2)
// ReportActionReplyPass action reply_pass
ReportActionReplyPass = "reply_pass"
// ReportActionReplyDel action reply_del
ReportActionReplyDel = "reply_del"
// ReportActionReplyEdit action reply_edit
ReportActionReplyEdit = "reply_edit"
// ReportActionReplyRecover action reply_recover
ReportActionReplyRecover = "reply_recover"
// ReportActionReplyTop action 置顶
ReportActionReplyTop = "top"
// ReportActionReplyMonitor action 监控
ReportActionReplyMonitor = "monitor"
// ReportActionReplyGarbage action reply_garbage
ReportActionReplyGarbage = "reply_garbage"
// ReportActionReportIgnore1 action report_ignore_1
ReportActionReportIgnore1 = "report_ignore_1"
// ReportActionReportIgnore2 action report_ignore_2
ReportActionReportIgnore2 = "report_ignore_2"
// ReportActionReportDel1 action report_del_1
ReportActionReportDel1 = "report_del_1"
// ReportActionReportDel2 action report_del_2
ReportActionReportDel2 = "report_del_2"
// ReportActionReport1To2 action report_1to2
ReportActionReport1To2 = "report_1to2"
// ReportActionReport2To1 action report_2to1
ReportActionReport2To1 = "report_2to1"
// ReportActionReportArbitration action 众裁
ReportActionReportArbitration = "report_arbitration"
)
// Report report info.
type Report struct {
ID int64 `json:"id"`
RpID int64 `json:"rpid"`
Oid int64 `json:"oid"`
Type int32 `json:"type"`
Mid int64 `json:"mid"`
Reason int32 `json:"reason"`
Content string `json:"content"`
Count int32 `json:"count"`
Score int `json:"score"`
State int32 `json:"state"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
Attr uint32 `json:"attr"`
ReplyCtime xtime.Time `json:"-"`
}
// AttrVal return attr val.
func (r *Report) AttrVal(bit uint32) uint32 {
return (r.Attr >> bit) & uint32(1)
}
// AttrSet set attr of ReplyReport'attr
func (r *Report) AttrSet(v uint32, bit uint32) {
r.Attr = r.Attr&(^(1 << bit)) | (v << bit)
}
// SearchReportParams search params.
type SearchReportParams struct {
Type int32
Oid int64
UID int64
StartTime string
EndTime string
Reason string
Typeids string
Keyword string
Nickname string
States string
Order string
Sort string
}
// ReportUser report user.
type ReportUser struct {
ID int64 `json:"id"`
Oid int64 `json:"oid"`
Type int8 `json:"type"`
RpID int64 `json:"rpid"`
Mid int64 `json:"mid"`
Reason int32 `json:"reason"`
Content string `json:"content"`
State int32 `json:"state"`
CTime xtime.Time `json:"ctime"`
MTime xtime.Time `json:"mtime"`
}
// SearchReport search report.
type SearchReport struct {
ID int64 `json:"id"`
Oid int64 `json:"oid"`
OidStr string `json:"oid_str"`
Type int8 `json:"type"`
RpID int64 `json:"rpid"`
Mid int64 `json:"mid"`
Reason int8 `json:"reason"`
Content string `json:"content"`
State int8 `json:"state"`
CTime string `json:"ctime"`
MTime string `json:"mtime"`
Parent int64 `json:"parent"`
Like int64 `json:"like"`
ReplyState int64 `json:"reply_state"`
Opremark string `json:"opremark"`
Count int64 `json:"count"`
Message string `json:"message"`
Title string `json:"title"`
Opresult string `json:"opresult"`
ReplyMid int64 `json:"reply_mid"`
Floor int64 `json:"floor"`
Root int64 `json:"root"`
ReportMid int64 `json:"report_mid"`
ArcMid int64 `json:"arc_mid"`
Reporter string `json:"reporter"`
Replier string `json:"replier"`
IsUp int64 `json:"is_up"`
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Opctime string `json:"opctime"`
DocID string `json:"doc_id"`
Score int64 `json:"score"`
Attr []int8 `json:"attr"`
RedirectURL string `json:"redirect_url"`
}
// SearchReportResult search result.
type SearchReportResult struct {
Code int `json:"code,omitempty"`
Page int64 `json:"page"`
PageSize int64 `json:"pagesize"`
PageCount int `json:"pagecount"`
Total int64 `json:"total"`
Order string `json:"order"`
Result []*SearchReport `json:"result"`
Message string `json:"msg,omitempty"`
}
// ReportSearchResponse search result.
type ReportSearchResponse struct {
SearchReportResult
Pager Pager `json:"pager"`
}

View File

@@ -0,0 +1,17 @@
package model
import (
"encoding/json"
"fmt"
"testing"
)
func TestReport(t *testing.T) {
s := `{"code":0,"order":"[{\"ctime\":{\"order\":\"asc\"}}]","page":1,"pagesize":50,"pagecount":1,"total":1,"result":[{"id":121002129,"oid":10098721,"type":1,"report_mid":27515245,"reason":8,"content":"","count":1,"state":0,"score":0,"ctime":"2017-12-14 10:22:03","mtime":"2017-12-14 10:22:03","adminid":null,"opresult":null,"opremark":null,"opctime":null,"reply_mid":27515232,"root":0,"parent":0,"floor":2,"like":0,"reply_state":0,"message":"(=\u30fb\u03c9\u30fb=)","typeid":76,"arc_mid":27515615,"reporter":"Test000011","replier":"\u53ee\u5f53\u732b3333777","doc_id":"121002129_10098721_1"}]}`
var data SearchReportResult
err := json.Unmarshal([]byte(s), &data)
if err != nil {
panic(err)
}
fmt.Println(data)
}

View File

@@ -0,0 +1,64 @@
package model
import (
"database/sql/driver"
"encoding/binary"
)
// Int64Bytes implements the Scanner interface.
type Int64Bytes []int64
// Scan parse the data into int64 slice
func (is *Int64Bytes) Scan(src interface{}) (err error) {
switch sc := src.(type) {
case []byte:
var res []int64
for i := 0; i < len(sc) && i+8 <= len(sc); i += 8 {
ui := binary.BigEndian.Uint64(sc[i : i+8])
res = append(res, int64(ui))
}
*is = res
}
return
}
// Value marshal int64 slice to driver.Value,each int64 will occupy Fixed 8 bytes
func (is Int64Bytes) Value() (driver.Value, error) {
return is.Bytes(), nil
}
// Bytes marshal int64 slice to bytes,each int64 will occupy Fixed 8 bytes
func (is Int64Bytes) Bytes() []byte {
res := make([]byte, 0, 8*len(is))
for _, i := range is {
bs := make([]byte, 8)
binary.BigEndian.PutUint64(bs, uint64(i))
res = append(res, bs...)
}
return res
}
// Evict get rid of the sepcified num from the slice
func (is *Int64Bytes) Evict(e int64) (ok bool) {
res := make([]int64, len(*is)-1)
for _, v := range *is {
if v != e {
res = append(res, v)
} else {
ok = true
}
}
*is = res
return
}
// Exist judge the sepcified num is in the slice or not
func (is Int64Bytes) Exist(i int64) (e bool) {
for _, v := range is {
if v == i {
e = true
return
}
}
return
}

View File

@@ -0,0 +1,197 @@
package model
import (
"encoding/json"
"fmt"
"go-common/library/ecode"
"go-common/library/time"
)
const (
// SubTypeArchive 稿件
SubTypeArchive int32 = 1
// SubTypeTopic 话题
SubTypeTopic = 2
// SubTypeDrawyoo 画站 NOTE Deprecated
SubTypeDrawyoo = 3
// SubTypeActivity 活动
SubTypeActivity = 4
// SubTypeLiveVideo 直播小视频
SubTypeLiveVideo = 5
// SubTypeForbiden 封禁信息
SubTypeForbiden = 6
// SubTypeNotice 公告信息
SubTypeNotice = 7
// SubTypeLiveAct 直播活动
SubTypeLiveAct = 8
// SubTypeActArc 活动稿件
SubTypeActArc = 9
// SubTypeLiveNotice 直播公告
SubTypeLiveNotice = 10
// SubTypeLivePicture 直播有文画
SubTypeLivePicture = 11
// SubTypeArticle 文章
SubTypeArticle = 12
// SubTypeTicket 票务
SubTypeTicket = 13
// SubTypeMusic 音乐
SubTypeMusic = 14
// SubTypeCredit 风纪委
SubTypeCredit = 15
// SubTypePgcCmt 点评
SubTypePgcCmt = 16
// SubTypeDynamic 动态
SubTypeDynamic = 17
// SubTypePlaylist 播单
SubTypePlaylist = 18
// SubTypeMusicList 音乐播单
SubTypeMusicList = 19
// SubTypeComicSeason 漫画部评论
SubTypeComicSeason = 20
// SubTypeComicEpisode 漫画话评论
SubTypeComicEpisode = 21
// SubStateNormal 正常
SubStateNormal int32 = 0
// SubStateForbid 关闭
SubStateForbid = 1
// SubStateMonitor 监控中 NOTE Deprecated to use attr 2
SubStateMonitor = 2
// SubAttrTopAdmin 管理员置顶
SubAttrTopAdmin uint32 = 0
// SubAttrTopUpper up主置顶
SubAttrTopUpper = 1
// SubAttrMonitor 监控中
SubAttrMonitor = 2
// SubAttrConfig 存在配置
SubAttrConfig = 3
// SubAttrAudit 先审后发
SubAttrAudit = 4
// SubAttrFrozen 冻结评论
SubAttrFrozen = 5
// SubAttrFolded 有折叠的根评论
SubAttrFolded = 7
// SujectAllow subject_allow
SujectAllow = "subject_allow"
// SujectForbid SujectForbid
SujectForbid = "subject_forbid"
// SujectFrozen SujectFrozen
SujectFrozen = "subject_frozen"
// SujectUnfrozenAllow SujectUnfrozenAllow
SujectUnfrozenAllow = "subject_unfrozen_allow"
// SujectUnfrozenForbid SujectUnfrozenForbid
SujectUnfrozenForbid = "subject_unfrozen_forbid"
)
// Subject reply subject.
type Subject struct {
ID int64 `json:"-"`
Oid int64 `json:"oid"`
Type int32 `json:"type"`
Mid int64 `json:"mid"`
Count int32 `json:"count"`
RCount int32 `json:"rcount"`
ACount int32 `json:"acount"`
State int32 `json:"state"`
Attr uint32 `json:"attr"`
CTime time.Time `json:"ctime"`
MTime time.Time `json:"-"`
Meta string `json:"meta"`
}
// HasFolded ...
func (s *Subject) HasFolded() bool {
return s.AttrVal(AttrFolded) == AttrYes
}
// MarkHasFolded ...
func (s *Subject) MarkHasFolded() {
s.AttrSet(AttrYes, AttrFolded)
}
// UnmarkHasFolded ...
func (s *Subject) UnmarkHasFolded() {
s.AttrSet(AttrNo, AttrFolded)
}
// SubjectMeta SubjectMeta
type SubjectMeta struct {
AdminTop int64 `json:"atop,omitempty"`
UpperTop int64 `json:"utop,omitempty"`
}
// TopSet TopSet
func (s *Subject) TopSet(top int64, typ uint, act uint32) (err error) {
var meta SubjectMeta
if s.Meta != "" {
err = json.Unmarshal([]byte(s.Meta), &meta)
if err != nil {
return
}
}
if act == 1 {
if typ == 0 {
if meta.AdminTop == top {
return fmt.Errorf("subject already have the same top")
}
meta.AdminTop = top
} else {
if meta.UpperTop == top {
return fmt.Errorf("subject already have the same top")
}
meta.UpperTop = top
}
} else {
if typ == 0 {
meta.AdminTop = 0
} else {
meta.UpperTop = 0
}
}
var content []byte
content, err = json.Marshal(meta)
if err != nil {
return err
}
s.Meta = string(content)
return
}
// AttrVal return val of subject'attr.
func (s *Subject) AttrVal(bit uint32) uint32 {
return (s.Attr >> bit) & uint32(1)
}
// AttrSet set val of subject'attr.
func (s *Subject) AttrSet(v uint32, bit uint32) {
s.Attr = s.Attr&(^(1 << bit)) | (v << bit)
}
// CheckSubState check subject state is ok.
func CheckSubState(state int32) (err error) {
if state < SubStateNormal || state > SubStateForbid {
err = ecode.ReplyIllegalSubState
}
return
}
// SubjectLog info
type SubjectLog struct {
AdminID int64 `json:"adminid"`
AdminName string `json:"admin_name"`
Oid string `json:"oid"`
Type int32 `json:"type"`
Remark string `json:"remark"`
Action string `json:"action"`
CTime string `json:"ctime"`
State int32 `json:"state"`
}
// SubjectLogRes format
type SubjectLogRes struct {
Logs []*SubjectLog `json:"logs"`
Page Page `json:"page"`
Order string `json:"order"`
Sort string `json:"sort"`
}