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,34 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/service/main/videoup/cmd:all-srcs",
"//app/service/main/videoup/conf:all-srcs",
"//app/service/main/videoup/dao/agent:all-srcs",
"//app/service/main/videoup/dao/archive:all-srcs",
"//app/service/main/videoup/dao/bgm:all-srcs",
"//app/service/main/videoup/dao/databus:all-srcs",
"//app/service/main/videoup/dao/dede:all-srcs",
"//app/service/main/videoup/dao/manager:all-srcs",
"//app/service/main/videoup/dao/monitor:all-srcs",
"//app/service/main/videoup/dao/msg:all-srcs",
"//app/service/main/videoup/dao/relation:all-srcs",
"//app/service/main/videoup/dao/ups:all-srcs",
"//app/service/main/videoup/http:all-srcs",
"//app/service/main/videoup/model/archive:all-srcs",
"//app/service/main/videoup/model/dede:all-srcs",
"//app/service/main/videoup/model/manager:all-srcs",
"//app/service/main/videoup/model/message:all-srcs",
"//app/service/main/videoup/model/prom:all-srcs",
"//app/service/main/videoup/service:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,489 @@
#### 稿件内部接口
##### Version 2.2.0
>1.添加获取稿件附加属性数据的HTTP接口
##### Version 2.1.2
>1.联合投稿更新消息
##### Version 2.1.1
>1.获取未通过审核稿件列表
##### Version 2.1.0
>1.联合投稿批量修改staff接口
>2.保障staff state 1/2
##### Version 2.0.0
>1.联合投稿
##### Version 1.33.3
>1.IPv6upgrade
##### Version 1.33.2
>1.投稿支持新功能灰度 使用方式是 需要灰度的功能块 走一下 s.checkGrayMid方法 同时在用户组21里维护清空该组就等于全量
>2.投稿支持bgm 属性位 23bit
##### Version 1.33.1
>1.投稿发动态支持投票业务
##### Version 1.33.0
>1.投稿支持bgm属性位 bit 23
##### Version 1.32.6
>1.升级并精简化自定义错误码
##### Version 1.32.5
>1.修复和基础库错误码不兼容的问题,需重新发版
##### Version 1.32.4
>1.具体到某一分P的错误统一沿用interface的VideoError
##### Version 1.32.3
>1.添加视频分辨率稿件信息接口
##### Version 1.32.2
>1.app 移动投稿支持LBS信息上报
##### Version 1.32.1
>1.videoup/ugc/edit/mission支持绑定活动tag 或者取消稿件活动
>2.videoup/flow/list/juge 支持最多200个aid查询
##### Version 1.32.0
>1.投稿支持UGC付费
##### Version 1.31.1
>1.投稿消息 add_archive 新增up_from 投稿来源信息
##### Version 1.31.0
>1.新增 流量管理接入pgc禁止项 /videoup/flow/entry/oid
>2.新增 流量管理支持批量查询禁止项明细列表 /videoup/flow/list/judge
##### Version 1.30.0
>1.新增 稿件分享动态配置查询接口 /videoup/setting/dynamic
##### Version 1.29.10
>1.dao unittest redo
##### Version 1.29.9
>1.fix 修复多p编辑超时
##### Version 1.29.8
>1.fix 修复超时
##### Version 1.29.7
>1.feature 多分p稿件编辑进行异步并行处理
##### Version 1.29.6
>1.obtain/cid 和 assiginCid 加分布式锁保证cid 与 filename 一一对应
##### Version 1.29.5
>1.升级ip获取的方式使用metadata.RemoteIP
##### Version 1.29.4
> 1.定时发布表增加软删除字段deleted_at
##### Version 1.29.3
> 1.去除代码模式
> 2.增加prom监控
> 3.增加filename过期的分p报错信息
##### Version 1.29.2
> 1.增加视频和音频绑定的异步接口
##### Version 1.29.1
> 1.videoup/views pagesize上限为50
> 2.modify_archive支持分区修改
##### Version 1.29.0
> 1.新增接口修改稿件活动信息 /ugc/edit/mission
##### Version 1.28.12
> 1.修复基础库bug
##### Version 1.28.11
> 1.移除net/http/parse
##### Version 1.28.10
> 1.移除频道回查的inner_attr/attribute重置逻辑
> 2.modify_archive新增tag变动和新增分P的参数
##### Version 1.28.9
> 1.去除dm_index同步与dede库依赖
##### Version 1.28.8
> 1.增加稿件查询简易版
##### Version 1.28.7
> 1./videoup/views 新增批量aids 查询最大值 20
##### Version 1.28.6
> 1.busSendMsg 拦截异常filename 防止进入无限重试redis 队列
##### Version 1.28.5
> 1.投稿filename 48小时错误码
> 2.去掉无意义的error日志
##### Version 1.28.4
> 1.新增投稿filename 48小时超时验证
##### Version 1.28.3
> 1.fix 私单属性判断导致的查询double
##### Version 1.28.2
> 1.换源或改变tag重置频道回查属性位
##### Version 1.28.1
> 1.fix自定义错误,兼容通用的错误码接口
##### Version 1.28.0
> 1.迁移bm
##### Version 1.27.14
> 1.去掉UGC稿件描述(desc)必传的校验
##### Version 1.27.13
> 1.移除提交稿件author字段
##### Version 1.27.12
> 1.Video结构体返回duration到json
##### Version 1.27.11
> 1.专栏推荐禁止取消操作加入完整性逻辑 禁止业务不存在情况的取消逻辑
##### Version 1.27.10
> 1.专栏推荐禁止支持取消操作
##### Version 1.27.9
> 1.fix pad filename 404 loop pad bug
##### Version 1.27.8
> 1.迁移main path
##### Version 1.27.7
> 1.fix 私单字段数据强一致性 porder official brandName bug
##### Version 1.27.6
> 1.add contributor
##### Version 1.27.5
> 1.流量禁止应用支持粉丝动态 AttrBitNoPushBplus 20
##### Version 1.27.4
> 1.去除statsd
##### Version 1.27.3
> 1.增加稿件审核"阻塞"状态
##### Version 1.27.2
> 1.支持async edit
##### Version 1.27.1
> 1.完善flow go lint
##### Version 1.27.0
> 1.提供非稿件业务流量mid入口 /videoup/flow/entry/mid
> 2.私单稿件默认设置前端展示 show_front=1
##### Version 1.26.0
> 1.删除稿件校验mid
> 2.编辑稿件针对新增分P验证必须是新投视频
##### Version 1.25.5
> 1.porder/config/list 新增rank 排序
> 2.投稿支持日文标识
##### Version 1.25.4
> 1./porder/arc/list 返回所有字段按照id倒叙
##### Version 1.25.3
> 1.pgc 增加视频云pubagent
##### Version 1.25.2
> 1.将稿件属性第13位hideclick改成limit_area
##### Version 1.25.1
> 1.修复新视频查询err
> 2.统一给成长计划的返回数据为{}而不是nil应成长计划要求
##### Version 1.25.0
> 1.私单二期业务
> 2.私单流量聚合
##### Version 1.24.2
> 1.fix bug: 如果分P没有做任何修改并且只修改稿件信息只添加稿件历史不添加分P历史
##### Version 1.24.1
> 1. update:添加和编辑的时候,批量插入视频的历史记录,提高响应速度
##### Version 1.24.0
>1.私单配置返回给videoup-interface和creative-interface
>2.私单按照时间区间查询,提供给商业产品部门的成长计划项目组
>3.添加接口查稿件打回理由关联的申诉tag_id
##### Version 1.23.1
> 1. 添加视频审核时长等级接口
##### Version 1.23.0
> 1. video相关全部切到新表
##### Version 1.22.2
> 1. ugc投稿只发送ugc_submit消息
##### Version 1.22.1
> 1. ugc投稿只发送sync_cid消息sync_cid中submit=1
##### Version 1.22.0
> 1. 支持pgc drm投稿
##### Version 1.21.2
> 1. 实验室投稿发送ugc_submit消息
##### Version 1.21.1
> 1.投稿不再自动添加海外禁止
##### Version 1.21.0
> 1.新增 pgc topic PGCVideoup2Bvc
##### Version 1.20.4
> 1.将稿件attribute中的第9位作为is_pgc字段
##### Version 1.20.3
> 1.fix 代码模式下不执行syncCid
##### Version 1.20.2
> 1.开放videoup/view 接口 src_type属性
##### Version 1.20.1
> 1.fix重试监控报警
##### Version 1.20.0
> 1.新增重试监控报警
##### Version 1.19.9
> 1.去掉稿件推荐双写的逻辑, 去除dede老库的依赖
##### Version 1.19.8
> 1.synccid异步发消息逻辑修改
##### Version 1.19.7
> 1.删除稿件动作不更新视频关联关系(-100
##### Version 1.19.6
> 1.fix pgc提交发submit消息 未注册分类
##### Version 1.19.5
> 1.pgc提交发submit消息
##### Version 1.19.4
> 1.稿件回溯编辑archive_video_relation state=0强制
##### Version 1.19.3
> 1.稿件支持 dynamic 特性
##### Version 1.19.2
>1.hot fix: 强制 archive_video 与 archive_video_relation id一致
##### Version 1.19.1
> 1.推荐表, 由于权限不足,老表操作使用创作中心的账号
##### Version 1.19.0
> 1.推荐表, 双写,双更新,查询先查老数据,再查新数据
##### Version 1.18.0
>1.新增cid查询接口 /videoup/query/cid
>2.新增流量融合的禁止项用户组聚合禁止项应用到投稿
>3.新增流量融合的禁止项用户组聚合数据查询接口 /videoup/up/forbid
##### Version 1.17.3
>1.新增查询特殊用户组接口 /videoup/up/special
##### Version 1.17.2
>1.hot fix: 同一个filename sync cid两次
##### Version 1.17.1
> 1.去除appkey参数
##### Version 1.17.0
> 1. 新增生成cid的接口
> 2. 去除老的dm_index的依赖
##### Version 1.16.3
> 1. 增加网安的md5数据导入数据库的内部接口, 接口地址:/videoup/ns/Md5
##### Version 1.16.2
> 1. 用户修改转载来源聚合稿件状态
##### Version 1.16.1
> 1. 投稿添加视频的操作日志的操作人错误修复
##### Version 1.16.0
> 1. 合入大仓库
> 2. 新增简版archive和videos接口
##### Version 1.15.3
> 1. 同步new_video的时候增加ctime字段
##### Version 1.15.2
> 1. desc_format的components改成string类型
##### Version 1.15.1
> 1. desc_format的typeid修改
##### Version 1.15.0
> 1. 天马和私单融合方案查询接口
> 2. 提供archive_desc_format的数据接口
##### Version 1.14.0
> 1. archive_video 拆表双写逻辑
##### Version 1.13.1
> 1.新增稿件投诉接口
##### Version 1.13.0
> 1.去除prepare
> 2.恢复一审理由聚合
##### Version 1.12.1
> 1.去除海外禁止特殊分区若干
##### Version 1.12.0
> 1.UGC新增简介描述功能(不含PGC)
##### Version 1.11.4
> 1.新增批量通过cid获取稿件aid列表
##### Version 1.11.3
> 1.设置保留稿件的state为-100
##### Version 1.11.2
> 1.支持内部保留aid特性
##### Version 1.11.1
> 1.根据up主的mid分页获取aids数据
##### Version 1.11.0
> 1.UGC新增私单功能模块(不含PGC)
> 2.PGC 编辑稿件删除分P发delete_video消息
##### Version 1.10.0
> 1.更新go-common,使用log-agent
##### Version 1.9.6
> 1.去掉一些海外的分区id
##### Version 1.9.5
> 1.PGC新增外链upfrom
##### Version 1.9.4
> 1.vendor add burntsushi
##### Version 1.9.3
> 1.修改重试databus的key
##### Version 1.9.2
> 1.处理分P为0的prom统计
##### Version 1.9.1
> 1.细分prom统计
##### Version 1.9.0
> 1.加入普罗米修斯监控统计日志
##### Version 1.8.3
> 1.增加机密PGC投稿接口
##### Version 1.8.2
> 1.限制30天以内的历史纪录回溯
##### Version 1.8.1
> 1.通过cid获取video信息
##### Version 1.8.0
> 1.代码模式实现方式改为通过cid
##### Version 1.7.5
> 1.打回状态非渣转完成不用发modify消息
##### Version 1.7.4
> 1.新增modify_video的databus消息
##### Version 1.7.3
> 1.启用新分区表
##### Version 1.7.2
> 1.修复删除aid老表依赖的bug
##### Version 1.7.1
> 1.删除aid老表依赖
> 2.修改活动ID、商单ID、定时发布时间聚合稿件状态
##### Version 1.7.0
> 1.接入新配置中心
##### Version 1.6.0
> 1.日志清理和修改
> 2.添加稿件回溯记录
> 3.提供稿件回溯记录查询
##### Version 1.5.1
> 1.删除track功能移到admin
> 2.更新vendor
##### Version 1.5.0
> 1.增加批量稿件信息获取
> 2.增加稿件TAG更新接口
##### Version 1.4.0
> 1.去掉没用代码挪admin中
##### Version 1.3.3
> 1.更改稿件状态赋值和日志
##### Version 1.3.2
> 1.修改暂缓状态可编辑
##### Version 1.3.1
> 1.修复attr日志bug
##### Version 1.3.0
> 1.删除稿件,同步老表状态
> 2.移除删除稿件的扣硬币和解绑活动的代码
> 3.删除稿件同步视频云删除xcode小于2的视频
> 4.修改同步删除视频云的route
##### Version 1.2.4
> 1.修复view接口rejectreason字段逻辑错误
##### Version 1.2.3
> 1.pgc外链sohu和hunan的dm_index处理
> 2.添加稿件round默认值从-1变为0
##### Version 1.2.2
> 1.修复pgc外链未插Dm_index的bug
##### Version 1.2.1
> 1.pgc外链默认二转完成
##### Version 1.2.0
> 1.增加商单ID和NO_PRINT逻辑
> 2.PGC自动过审和attr更新
> 3.商业产品attr位更新
> 4.修复默认允许添加tag
##### Version 1.1.1
> 1.支持PGC外链上传
> 2.分P的audit理由根据状态返回
##### Version 1.1.0
> 1.增加更新attr
> 2.PGC自动过审(差相关业务同步逻辑)
> 3.地区限制记录
##### Version 1.0.1
> 1.增加recover后事务回滚
##### Version 1.0.0
> 1.稿件新增编辑接口

View File

@@ -0,0 +1,15 @@
# Owner
shencen
wangzhe01
# Author
hejianbing
gaopeng
chenxi01
dengwei
liusiming
# Reviewer
chenxi01
dengwei
liusiming

View File

@@ -0,0 +1,22 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- chenxi01
- dengwei
- gaopeng
- hejianbing
- liusiming
- shencen
- wangzhe01
labels:
- main
- service
- service/main/videoup
options:
no_parent_owners: true
reviewers:
- chenxi01
- dengwei
- gaopeng
- hejianbing
- liusiming

View File

@@ -0,0 +1,13 @@
#### videoup-service
##### 项目简介
> 1.用户投稿服务
##### 编译环境
> 请只用golang v1.7.x以上版本编译执行。
##### 依赖包
> 1.公共包go-common
##### 特别说明
> 1.model目录可能会被其他项目引用请谨慎请改并通知各方。

View File

@@ -0,0 +1,45 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["videoup-service.toml"],
importpath = "go-common/app/service/main/videoup/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/http:go_default_library",
"//app/service/main/videoup/service:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/trace:go_default_library",
"//library/queue/databus/report: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,55 @@
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/service/main/videoup/conf"
"go-common/app/service/main/videoup/http"
"go-common/app/service/main/videoup/service"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
"go-common/library/queue/databus/report"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
log.Error("conf.Init() error(%v)", err)
panic(err)
}
// init log
log.Init(conf.Conf.Xlog)
trace.Init(conf.Conf.Tracer)
defer trace.Close()
defer log.Close()
ecode.Init(conf.Conf.Ecode)
report.InitUser(nil)
log.Info("go-common/app/service/videoup start")
// service init
svr := service.New(conf.Conf)
// statsd init
http.Init(conf.Conf, svr)
// init signal
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("go-common/app/service/videoup get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGSTOP, syscall.SIGINT:
svr.Close()
log.Info("go-common/app/service/videoup exit")
time.Sleep(1 * time.Second)
return
case syscall.SIGHUP:
// TODO reload
default:
return
}
}
}

View File

@@ -0,0 +1,341 @@
# This is a TOML document. Boom.
version = "1.0.0"
user = "nobody"
pid = "/tmp/videoup-service.pid"
dir = "./"
perf = "127.0.0.1:6327"
checkFile = "/data/www/videoup-service.html"
family = "videoup-service"
tick = "5m"
chanSize = 1
dmVerifyKey = "53e2fa226f5ad348"
asyncThreshold = 3
splitThreshold = 6
splitGroupCount = 2
failThreshold = 3
editTimeout = "10s"
[monitor]
env = "pro"
tels = "15871451480,18733334444"
count = 10
[app]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
[host]
mission = "http://172.16.33.104"
account = "http://account.bilibili.co"
monitor = "http://ops-mng.bilibili.co"
apiCo = "http://uat-api.bilibili.co"
msg = "http://message.bilibili.co"
[xlog]
dir = "/data/log/videoup-service/"
[xlog.elk]
project = "videoup-service"
addr = "172.18.20.17:8520"
chanSize = 10240
[statsd]
project = "videoup-service"
addr = "172.18.20.15:8200"
chanSize = 10240
[httpClient]
[httpClient.read]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
dial = "500ms"
timeout = "1s"
keepAlive = "60s"
timer = 10
[httpClient.read.breaker]
window = "10s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[httpClient.write]
key = "b8f239ca38a53308"
secret = "5460ef72fe13c10dfb53442b9111427e"
dial = "500ms"
timeout = "1s"
keepAlive = "60s"
timer = 10
[httpClient.write.breaker]
window = "10s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[bm]
addr = "0.0.0.0:6328"
maxListen = 1000
timeout = "1s"
[antispamConf]
on=true
second=1
n=2
hour=1
m=10
[antispamConf.redis]
name = "video-service/track"
proto = "tcp"
addr = "172.16.33.205:6381"
idle = 10
active = 10
dialTimeout = "500ms"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "80s"
expire = "24m"
[db]
[db.archive]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_archive?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.archive.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.archiveRead]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_archive?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.archiveRead.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.archiveSlave]
addr = "172.18.16.67:3403"
dsn = "test:test@tcp(172.18.16.67:3403)/bilibili_archive?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
active = 5
idle = 5
idleTimeout = "4h"
queryTimeout = "150ms"
execTimeout = "100ms"
tranTimeout = "200ms"
[db.archiveSlave.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.dede]
name = "172.16.33.205:3307"
dsn = "dede_test:dede_test@tcp(172.16.33.205:3307)/bilibili?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.dede.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.manager]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_manager?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.manager.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[db.oversea]
name = "172.16.33.205:3308"
dsn = "test:test@tcp(172.16.33.205:3308)/bilibili_oversea?timeout=5s&readTimeout=5s&writeTimeout=5s&parseTime=true&loc=Local&charset=utf8"
active = 5
idle = 2
idleTimeout ="4h"
queryTimeout = "5s"
execTimeout = "5s"
tranTimeout = "10s"
[db.oversea.breaker]
window = "3s"
sleep = "100ms"
bucket = 10
ratio = 0.5
request = 100
[videoupPub]
key = "0PtMsLLxWyyvoTgAyLCD"
secret = "0PtMsLLxWyyvoTgAyLCE"
group = "Videoup-Videoup2Bvc-P"
topic = "Videoup2Bvc"
action = "pub"
offset = "old"
buffer = 128
name = "videoup-service/databus"
proto = "tcp"
addr = "172.16.33.158:6205"
active = 1
idle = 1
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
[videoupPGCPub]
key = "0PtMsLLxWyyvoTgAyLCD"
secret = "0PtMsLLxWyyvoTgAyLCE"
group = "Videoup-PGCVideoup2Bvc-P"
topic = "PGCVideoup2Bvc"
action = "pub"
offset = "old"
buffer = 128
name = "videoup-service/databus"
proto = "tcp"
addr = "172.16.33.158:6205"
active = 1
idle = 1
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
[redis]
[redis.track]
name = "video-service/track"
proto = "tcp"
addr = "172.18.33.61:6807"
idle = 10
active = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "10s"
[keepArc]
aids = [16201808]
mid = 7784978
[pubAgent]
pgcSubmit = "http://172.18.33.137:9510"
pgcDRMSubmit = "http://172.18.33.137:9510"
ugcSubmit = "http://172.18.33.137:9510"
Proxy = "http://172.18.33.137:11080"
[memcache]
[memcache.archive]
name = "creative/archive"
proto = "tcp"
addr = "172.16.33.54:11213"
active = 10
idle = 5
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "80s"
tplExpire = "60s"
[property]
[[property.msg]]
to = "staff"
msgid = 1
code = "1_19_1"
title = "多人合作投稿申请"
content = 'up主%s邀请您作为%s参与稿件《%s》av%d的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article/cooperation"}'
[[property.msg]]
to = "up"
msgid = 2
code = "1_19_2"
title = "参与者同意参与多人合作投稿"
content = '参与者%s已接受您的邀请作为%s参与稿件《%s》av%d的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "up"
msgid = 3
code = "1_19_3"
title = "参与者拒绝参与多人合作投稿"
content = '参与者%s已拒绝您的邀请作为%s参与稿件《%s》av%d的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "staff"
msgid = 4
code = "1_19_4"
title = "多人合作投稿参与类型变更申请"
content = 'up主%s申请您参与稿件《%s》av%d的参与类型由%s变更为%s在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article/cooperation"}'
[[property.msg]]
to = "up"
msgid = 5
code = "1_19_5"
title = "参与者同意多人合作投稿参与类型变更"
content = '参与者%s已同意您申请其参与稿件《%s》av%d的参与类型由%s变更为%s在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "up"
msgid = 6
code = "1_19_6"
title = "参与者拒绝多人合作投稿参与类型变更"
content = '参与者%s已拒绝您申请其参与稿件《%s》av%d的参与类型由%s变更为%s在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "up"
msgid = 7
code = "1_19_7"
title = "终止多人合作投稿申请"
content = '合作者%s申请终止其作为稿件《%s》av%d的%s的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "staff"
msgid = 8
code = "1_19_8"
title = "同意终止多人合作投稿"
content = 'up主%s已终止参与者%s作为稿件《%s》av%d的%s的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article/cooperation"}'
[[property.msg]]
to = "staff"
msgid = 9
code = "1_19_9"
title = "终止多人合作投稿申请"
content = 'up主%s申请终止您作为稿件《%s》av%d的%s的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article/cooperation"}'
[[property.msg]]
to = "up"
msgid = 10
code = "1_19_10"
title = "同意终止多人合作投稿"
content = 'up主%s已终止参与者%s作为稿件《%s》av%d的%s的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "up"
msgid = 11
code = "1_19_11"
title = "拒绝终止多人合作投稿"
content = 'up主%s未能终止参与者%s作为稿件《%s》av%d的%s的多人合作在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "up"
msgid = 12
code = "1_19_12"
title = "管理员解除合作关系"
content = '管理员解除了您与参与者%s在稿件《%s》av%d中合作关系在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'
[[property.msg]]
to = "staff"
msgid = 13
code = "1_19_12"
title = "管理员解除合作关系"
content = '管理员解除了您与UP主%s在稿件《%s》av%d中合作关系在网页端创作中心查看吧#{点击查看}{"https://member.bilibili.com/v2#/upload-manager/article"}'

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["conf.go"],
importpath = "go-common/app/service/main/videoup/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/model/archive:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/conf:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/antispam:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/net/trace:go_default_library",
"//library/queue/databus:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/BurntSushi/toml: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,199 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/sql"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/antispam"
"go-common/library/net/trace"
"go-common/library/queue/databus"
"go-common/library/time"
"github.com/BurntSushi/toml"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/net/rpc/warden"
)
var (
confPath string
// Conf is global config
Conf = &Config{}
client *conf.Client
)
// Config service config
type Config struct {
// base
// host
Host *Host
// channal len
ChanSize int64
// ecode
Ecode *ecode.Config
// Xlog
Xlog *log.Config
// tracer
Tracer *trace.Config
// tick load pgc
Tick time.Duration
// db
DB *DB
// databus
VideoupPub *databus.Config
VideoupPGCPub *databus.Config
// redis
Redis *Redis
Memcache *Memcache
// http client test
HTTPClient *HTTPClient
// keep Aids
KeepArc *KeepArc
// DmVerifyKey dm_key
DmVerifyKey string
// Monitor
Monitor *Monitor
// PubAgent
PubAgent *PubAgent
// AsyncThreshold
AsyncThreshold int
SplitThreshold int
SplitGroupCount int
FailThreshold int
EditTimeout time.Duration
GrayGroup int
//BM bladermaster config
BM *bm.ServerConfig
//AntispamConf limit request
AntispamConf *antispam.Config
Property *Property
// rpc
AccRPC *warden.ClientConfig
}
// Property .
type Property struct {
MSG []*archive.MSG
}
// Memcache conf.
type Memcache struct {
Archive struct {
*memcache.Config
TplExpire time.Duration
}
}
// Monitor define sms monitor conf
type Monitor struct {
Tels string
Env string
Count int64
}
// PubAgent struct
type PubAgent struct {
Proxy string
PGCSubmit string
PGCDRMSubmit string
UGCSubmit string
UGCFirstRound string
}
// Host define host info
type Host struct {
Mission string
Account string
Monitor string
APICO string
MSG string
Manager string
}
// DB define MySQL config
type DB struct {
Archive *sql.Config
ArchiveRead *sql.Config
ArchiveSlave *sql.Config
CreativeCenter *sql.Config
Dede *sql.Config
Manager *sql.Config
Oversea *sql.Config
}
// Redis define redis config
type Redis struct {
Track *TrackRedis
}
// TrackRedis define track redis config
type TrackRedis struct {
*redis.Config
Expire time.Duration
}
// HTTPClient test
type HTTPClient struct {
Read *bm.ClientConfig
Write *bm.ClientConfig
}
// KeepArc keep archive to mid
type KeepArc struct {
Aids []int64
Mid int64
}
func init() {
flag.StringVar(&confPath, "conf", "", "default config path")
}
// Init init conf
func Init() (err error) {
if confPath != "" {
_, err = toml.DecodeFile(confPath, &Conf)
return
}
err = remote()
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}

View File

@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/videoup/dao/agent",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,85 @@
package agent
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"net"
"net/http"
"net/url"
"strconv"
"time"
"go-common/app/service/main/videoup/conf"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/log"
xhttp "go-common/library/net/http/blademaster"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
proxyClient *xhttp.Client
pgcSubmitURI string
}
// New pub agent
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
proxyClient: xhttp.NewClient(c.HTTPClient.Read),
pgcSubmitURI: c.PubAgent.PGCSubmit,
}
// add proxy
proxyURL, _ := url.Parse(c.PubAgent.Proxy)
dialer := &net.Dialer{
Timeout: time.Duration(c.HTTPClient.Write.Timeout),
KeepAlive: time.Duration(c.HTTPClient.Write.KeepAlive),
}
transport := &http.Transport{
DialContext: dialer.DialContext,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Proxy: http.ProxyURL(proxyURL),
}
d.proxyClient.SetTransport(transport)
return d
}
// AgentMsg send message to upper.
func (d *Dao) AgentMsg(c context.Context, route, filename string) (err error) {
query := "content_type=json&r=pgc_submit/msg_pgc_submit&filename=" + filename
msg := &archive.PubAgentParam{
Route: route,
Timestamp: strconv.FormatInt(time.Now().Unix(), 10),
Filename: filename,
Xcode: 0,
VideoDesign: "[]",
Submit: 1,
}
// new request
bs, err := json.Marshal(msg)
if err != nil {
log.Error("json.Marshal pubagent msg error (%v) | msg(%v)", err, msg)
return
}
req, err := http.NewRequest("POST", d.pgcSubmitURI+"?"+query, bytes.NewReader(bs))
if err != nil {
log.Error("http.NewRequest error(%v) | uri(%s) msg(%v) req(%v)", err, d.pgcSubmitURI+"?"+query, msg, req)
return
}
var res struct {
Code int `json:"code"`
Message string `json:"message"`
}
if err = d.proxyClient.Do(c, req, &res); err != nil {
log.Error("AgentMsg d.httpW.Do error(%v) | uri(%s) msg(%v) req(%v)", err, d.pgcSubmitURI+"?"+query, msg, req)
return
}
if res.Code != 0 {
log.Error("AgentMsg res(%v) | uri(%s) msg(%v) req(%v)", res, d.pgcSubmitURI+"?"+query, msg, req)
return
}
log.Info("AgentMsg success msg(%v) uri(%s)", msg, d.pgcSubmitURI+"?"+query)
return
}

View File

@@ -0,0 +1,35 @@
package agent
import (
"flag"
"go-common/app/service/main/videoup/conf"
"gopkg.in/h2non/gock.v1"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
d.proxyClient.SetTransport(gock.DefaultTransport)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,96 @@
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",
"dao_test.go",
"delay_test.go",
"desc_format_test.go",
"flow_test.go",
"history_test.go",
"netsafe_test.go",
"new_video_test.go",
"porder_test.go",
"redis_test.go",
"report_test.go",
"staff_test.go",
"type_test.go",
"video_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//library/database/sql:go_default_library",
"//library/time:go_default_library",
"//vendor/github.com/bouk/monkey:go_default_library",
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"dao.cache.go",
"dao.go",
"delay.go",
"desc_format.go",
"flow.go",
"forbid.go",
"history.go",
"mc.cache.go",
"netsafe.go",
"new_video.go",
"porder.go",
"redis.go",
"relation.go",
"report.go",
"staff.go",
"staff_apply.go",
"type.go",
"video.go",
],
importpath = "go-common/app/service/main/videoup/dao/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//library/stat/prom:go_default_library",
"//library/sync/pipeline/fanout:go_default_library",
"//library/time:go_default_library",
"//library/xstr:go_default_library",
"//vendor/github.com/dgryski/go-farm:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/golang.org/x/sync/singleflight: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,462 @@
package archive
import (
"context"
"database/sql"
"fmt"
"strconv"
"strings"
"time"
"go-common/app/service/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
// insert
_inArcSQL = "INSERT INTO archive (mid,typeid,title,author,cover,content,tag,attribute,copyright,state,round,pubtime,ctime,mtime,reject_reason) VALUES (?,?,?,?,?,?,?,?,?,-30,0,?,?,?,'')"
_inAddSQL = "INSERT INTO archive_addit (aid,mission_id,up_from,ipv6,source,order_id,flow_id,advertiser,flow_remark,description,desc_format_id,dynamic) VALUES (?,?,?,?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE mission_id=?,source=?,order_id=?,flow_id=?,advertiser=?,flow_remark=?,description=?,desc_format_id=?,dynamic=?"
_inAddRdrSQL = "INSERT INTO archive_addit (aid,redirect_url) VALUES (?,?) ON DUPLICATE KEY UPDATE redirect_url=?"
_inAddReaSQL = "INSERT INTO archive_addit (aid,recheck_reason) VALUES (?,?) ON DUPLICATE KEY UPDATE recheck_reason=?"
_inAddMissionSQL = "INSERT INTO archive_addit (aid,mission_id) VALUES (?,?) ON DUPLICATE KEY UPDATE mission_id=?"
// update
_upArcSQL = "UPDATE archive SET typeid=?,title=?,cover=?,content=?,tag=?,copyright=? WHERE id=?"
_upArcMidSQL = "UPDATE archive SET mid=?,state=? WHERE id=?"
_upArcStateSQL = "UPDATE archive SET state=? WHERE id=?"
_upArcAttrSQL = "UPDATE archive SET attribute=attribute&(~(1<<?))|(?<<?) WHERE id=?"
_upTagSQL = "UPDATE archive SET tag=? WHERE id=?"
// select
_arcSQL = "SELECT id,mid,typeid,copyright,author,title,cover,reject_reason,content,tag,duration,round,attribute,access,state,pubtime,ctime,mtime FROM archive WHERE id=?"
_arcAddSQL = "SELECT aid,mission_id,from_ip,ipv6,up_from,recheck_reason,redirect_url,source,order_id,flow_id,advertiser,flow_remark,description,desc_format_id,dynamic FROM archive_addit WHERE aid=?"
_arcMidsSQL = "SELECT id,mid FROM archive WHERE id IN (%s)"
_arcUpAllSQL = `SELECT id FROM archive WHERE mid = ? AND state != -100 ORDER BY id DESC LIMIT ?,?`
_arcUpOpenSQL = `SELECT id FROM archive WHERE mid = ? AND (state >= 0 OR state = -6) ORDER BY id DESC LIMIT ?,?`
_arcUpUnOpenSQL = `SELECT id FROM archive WHERE mid = ? AND state < 0 AND state != -100 AND state != -6 ORDER BY id DESC LIMIT ?,?`
_arcUpAllCountSQL = "SELECT count(*) FROM archive WHERE mid = ? AND state != -100"
_arcUpOpenCountSQL = "SELECT count(*) FROM archive WHERE mid = ? AND (state >= 0 OR state = -6)"
_arcUpUnOpenCountSQL = "SELECT count(*) FROM archive WHERE mid = ? AND state < 0 AND state != -100 AND state != -6"
_simpleArcSQL = "SELECT id,title,mid FROM archive WHERE id = ?"
_getRecoSQL = "SELECT reco_aid FROM archive_recommend WHERE state= 0 and aid=? ORDER BY ctime asc"
_rejectArcsSQL = "SELECT id,mid,title,reject_reason,mtime FROM archive WHERE mid = ? AND state = ? AND mtime > ? ORDER BY mtime DESC LIMIT ?,?"
_rejectArcsCountSQL = "SELECT count(*) FROM archive WHERE mid = ? AND state = ? AND mtime > ?"
_delRecoSQL = "UPDATE archive_recommend SET state=1 WHERE aid=?"
_batchAddRecoSQL = "INSERT IGNORE INTO archive_recommend (aid,reco_aid) VALUES %s on duplicate key update state=0"
//POI 元数据
_arcPOISQL = "SELECT data from archive_biz WHERE aid=? AND type= ?"
_arcVoteSQL = "SELECT data from archive_biz WHERE aid=? AND type= 2"
_inADDBizSQL = "INSERT INTO archive_biz (aid,type,data) VALUES (?,?,?) ON DUPLICATE KEY UPDATE data=?"
)
// TxAddArchive insert archive.
func (d *Dao) TxAddArchive(tx *xsql.Tx, a *archive.Archive) (aid int64, err error) {
var now = time.Now()
res, err := tx.Exec(_inArcSQL, a.Mid, a.TypeID, a.Title, a.Author, a.Cover, a.Desc, a.Tag, a.Attribute, a.Copyright, now, now, now)
if err != nil {
log.Error("d.inArc.Exec() error(%v)", err)
return
}
if aid, err = res.LastInsertId(); err != nil {
log.Error("res.LastInsertId() error(%v)", err)
return
}
if strings.Contains(xstr.JoinInts(d.c.KeepArc.Aids)+",", strconv.FormatInt(aid, 10)+",") {
keepAid := aid
aid, err = d.TxAddArchive(tx, a)
a.State = archive.StateForbidUpDelete
a.Mid = d.c.KeepArc.Mid // 内部归属mid
a.Aid = keepAid // 内部保留aid
d.TxUpArchiveMid(tx, a)
return
}
return
}
// TxUpArchive update archive.
func (d *Dao) TxUpArchive(tx *xsql.Tx, a *archive.Archive) (rows int64, err error) {
res, err := tx.Exec(_upArcSQL, a.TypeID, a.Title, a.Cover, a.Desc, a.Tag, a.Copyright, a.Aid)
if err != nil {
log.Error("d.upArc.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpArchiveMid update archive mid.
func (d *Dao) TxUpArchiveMid(tx *xsql.Tx, a *archive.Archive) (rows int64, err error) {
res, err := tx.Exec(_upArcMidSQL, a.Mid, a.State, a.Aid)
if err != nil {
log.Error("d.upArcMid.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpArchiveState update Archive state.
func (d *Dao) TxUpArchiveState(tx *xsql.Tx, aid int64, state int8) (rows int64, err error) {
res, err := tx.Exec(_upArcStateSQL, state, aid)
if err != nil {
log.Error("d.upVideoState.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAddit update archive addit.
func (d *Dao) TxUpAddit(tx *xsql.Tx, aid, missionID, orderID, flowID, descFormatID int64, ipv6 []byte, source, advertiser, flowRemark, desc, dynamic string, upFrom int8) (rows int64, err error) {
if ipv6 == nil {
ipv6 = []byte{}
}
res, err := tx.Exec(_inAddSQL, aid, missionID, upFrom, ipv6, source, orderID, flowID, advertiser, flowRemark, desc, descFormatID, dynamic, missionID, source, orderID, flowID, advertiser, flowRemark, desc, descFormatID, dynamic)
if err != nil {
log.Error("d.inArcAddit.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpArchiveBiz update archive biz.
func (d *Dao) TxUpArchiveBiz(tx *xsql.Tx, aid, bizType int64, data string) (rows int64, err error) {
res, err := tx.Exec(_inADDBizSQL, aid, bizType, data, data)
if err != nil {
log.Error("d.TxUpArchiveBiz.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAdditReason update archive recheck_reason
func (d *Dao) TxUpAdditReason(tx *xsql.Tx, aid int64, reason string) (rows int64, err error) {
res, err := tx.Exec(_inAddReaSQL, aid, reason, reason)
if err != nil {
log.Error("d.inAdditReason.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpAdditRedirect update archive redirect url.
func (d *Dao) TxUpAdditRedirect(tx *xsql.Tx, aid int64, redirectURL string) (rows int64, err error) {
res, err := tx.Exec(_inAddRdrSQL, aid, redirectURL, redirectURL)
if err != nil {
log.Error("d._inAdditRedirect.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpArcAttr update attribute by aid.
func (d *Dao) TxUpArcAttr(tx *xsql.Tx, aid int64, bit uint, val int32) (rows int64, err error) {
res, err := tx.Exec(_upArcAttrSQL, bit, val, bit, aid)
attSql := fmt.Sprintf("UPDATE archive SET attribute=attribute&(~(1<<%d))|(%d<<%d) WHERE id=%d", bit, val, bit, aid)
log.Info("aid(%d) attribute update log sql (%s)", aid, attSql)
if err != nil {
log.Error("d.upArcAttr.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpTag update tag by aid.
func (d *Dao) TxUpTag(tx *xsql.Tx, aid int64, tag string) (rows int64, err error) {
res, err := tx.Exec(_upTagSQL, tag, aid)
if err != nil {
log.Error("d.upTag.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Archive get a archive by avid.
func (d *Dao) Archive(c context.Context, aid int64) (a *archive.Archive, err error) {
var (
row = d.rddb.QueryRow(c, _arcSQL, aid)
reason, tag sql.NullString
)
a = &archive.Archive{}
if err = row.Scan(&a.Aid, &a.Mid, &a.TypeID, &a.Copyright, &a.Author, &a.Title, &a.Cover, &reason, &a.Desc, &tag, &a.Duration,
&a.Round, &a.Attribute, &a.Access, &a.State, &a.PTime, &a.CTime, &a.MTime); err != nil {
if err == xsql.ErrNoRows {
a = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
a.RejectReason = reason.String
a.Tag = tag.String
return
}
// POI get a archive POI by avid.
func (d *Dao) POI(c context.Context, aid int64) (data []byte, err error) {
var (
row = d.rddb.QueryRow(c, _arcPOISQL, aid, archive.BIZPOI)
)
if err = row.Scan(&data); err != nil {
if err == xsql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}
// Vote get a archive Vote by avid.
func (d *Dao) Vote(c context.Context, aid int64) (data []byte, err error) {
var (
row = d.rddb.QueryRow(c, _arcVoteSQL, aid)
)
if err = row.Scan(&data); err != nil {
if err == xsql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}
// Addit get a archive addit by avid.
func (d *Dao) Addit(c context.Context, aid int64) (ad *archive.Addit, err error) {
row := d.rddb.QueryRow(c, _arcAddSQL, aid)
ad = &archive.Addit{}
if err = row.Scan(&ad.Aid, &ad.MissionID, &ad.FromIP, &ad.IPv6, &ad.UpFrom, &ad.RecheckReason, &ad.RedirectURL, &ad.Source, &ad.OrderID, &ad.FlowID, &ad.Advertiser, &ad.FlowRemark, &ad.Desc, &ad.DescFormatID, &ad.Dynamic); err != nil {
if err == xsql.ErrNoRows {
err = nil
ad = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// Mids multi get archive mid by aids.
func (d *Dao) Mids(c context.Context, aids []int64) (mm map[int64]int64, err error) {
rows, err := d.rddb.Query(c, fmt.Sprintf(_arcMidsSQL, xstr.JoinInts(aids)))
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
mm = make(map[int64]int64, len(aids))
for rows.Next() {
var aid, mid int64
if err = rows.Scan(&aid, &mid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
mm[aid] = mid
}
return
}
// ArchivesUpAll get archive all aids by mid.
func (d *Dao) ArchivesUpAll(c context.Context, mid int64, offset int, ps int) (aids []int64, err error) {
rows, err := d.rddb.Query(c, _arcUpAllSQL, mid, offset, ps)
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
}
return
}
// ArchivesUpOpen get archive open aids by mid.
func (d *Dao) ArchivesUpOpen(c context.Context, mid int64, offset int, ps int) (aids []int64, err error) {
rows, err := d.rddb.Query(c, _arcUpOpenSQL, mid, offset, ps)
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
}
return
}
// ArchivesUpUnOpen get archive unopen aids by mid.
func (d *Dao) ArchivesUpUnOpen(c context.Context, mid int64, offset int, ps int) (aids []int64, err error) {
rows, err := d.rddb.Query(c, _arcUpUnOpenSQL, mid, offset, ps)
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
}
return
}
// ArchiveAllUpCount get all archive count by mid.
func (d *Dao) ArchiveAllUpCount(c context.Context, mid int64) (count int64, err error) {
row := d.rddb.QueryRow(c, _arcUpAllCountSQL, mid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// ArchiveOpenUpCount get open archive count by mid.
func (d *Dao) ArchiveOpenUpCount(c context.Context, mid int64) (count int64, err error) {
row := d.rddb.QueryRow(c, _arcUpOpenCountSQL, mid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// ArchiveUnOpenUpCount get un open archive count by mid.
func (d *Dao) ArchiveUnOpenUpCount(c context.Context, mid int64) (count int64, err error) {
row := d.rddb.QueryRow(c, _arcUpUnOpenCountSQL, mid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// SimpleArchive get a archive by avid.
func (d *Dao) SimpleArchive(c context.Context, aid int64) (a *archive.SimpleArchive, err error) {
row := d.rddb.QueryRow(c, _simpleArcSQL, aid)
a = &archive.SimpleArchive{}
if err = row.Scan(&a.Aid, &a.Title, &a.Mid); err != nil {
if err == xsql.ErrNoRows {
a = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// Recos fn
func (d *Dao) Recos(c context.Context, aid int64) (aids []int64, err error) {
rows, err := d.db.Query(c, _getRecoSQL, aid)
if err != nil {
log.Error("d.db.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
aids = append(aids, aid)
}
return
}
// RecoUpdate fn
func (d *Dao) RecoUpdate(c context.Context, aid int64, recoIDs []int64) (effCnt int64, err error) {
if len(recoIDs) == 0 {
_, err = d.db.Query(c, _delRecoSQL, aid)
if err != nil {
log.Error("d.db.Query error(%v)| aid (%d)", err, aid)
return
}
return
}
_, err = d.db.Query(c, _delRecoSQL, aid)
if err != nil {
log.Error("d.db.Query(%d) error(%v)", aid, err)
return
}
var (
batchVals = make([]string, 0, len(recoIDs))
)
for _, recoID := range recoIDs {
batchVals = append(batchVals, fmt.Sprintf("(%d,%d)", aid, recoID))
}
res, err := d.db.Exec(c, fmt.Sprintf(_batchAddRecoSQL, strings.Join(batchVals, ",")))
if err != nil {
log.Error("d.db.Exe _batchAddRecoSQL batchVals(%+v) error(%+v)", batchVals, err)
return
}
return res.RowsAffected()
}
// UpMissionID update mission_id for archive.
func (d *Dao) UpMissionID(c context.Context, aa *archive.ArcMissionParam) (rows int64, err error) {
res, err := d.db.Exec(c, _inAddMissionSQL, aa.AID, aa.MissionID, aa.MissionID)
if err != nil {
log.Error("UpMissionID.Exec error(%v)", err)
return
}
return res.RowsAffected()
}
// RejectedArchives list rejected archives
func (d *Dao) RejectedArchives(c context.Context, mid int64, state, offset, limit int32, start *time.Time) (arcs []*archive.Archive, count int32, err error) {
row := d.slaveDB.QueryRow(c, _rejectArcsCountSQL, mid, state, start)
if err = row.Scan(&count); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
if count == 0 {
return
}
rows, err := d.slaveDB.Query(c, _rejectArcsSQL, mid, state, start, offset, limit)
if err != nil {
log.Error("db.Query error(%v)", err)
return
}
for rows.Next() {
a := archive.Archive{}
if err = rows.Scan(&a.Aid, &a.Mid, &a.Title, &a.RejectReason, &a.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
arcs = append(arcs, &a)
}
return
}

View File

@@ -0,0 +1,471 @@
package archive
import (
"context"
"testing"
"time"
"database/sql"
"fmt"
"go-common/app/service/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"reflect"
"github.com/bouk/monkey"
. "github.com/smartystreets/goconvey/convey"
)
func TestDao_TxAddArchive(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
a = &archive.Archive{
Mid: 123,
TypeID: 22,
Title: "UT测试",
Author: "ut",
Desc: "UT测试UT测试",
}
)
Convey("TxUpArchiveState", t, func(ctx C) {
_, err := d.TxAddArchive(tx, a)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAUpArchive(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
a = &archive.Archive{
Aid: 10111210,
Mid: 123,
TypeID: 22,
Title: "UT测试",
Author: "ut",
Desc: "UT测试UT测试",
}
)
Convey("TxUpArchiveState", t, func(ctx C) {
_, err := d.TxUpArchive(tx, a)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAUpArchiveMid(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
a = &archive.Archive{
Aid: 10111210,
Mid: 123,
TypeID: 22,
Title: "UT测试",
Author: "ut",
Desc: "UT测试UT测试",
}
)
Convey("TxUpArchiveState", t, func(ctx C) {
_, err := d.TxUpArchiveMid(tx, a)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestArchiveTxUpArchiveState(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(233333)
state = int8(0)
)
Convey("TxUpArchiveState", t, func(ctx C) {
_, err := d.TxUpArchiveState(tx, aid, state)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAddit(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(233333)
)
Convey("TxUpAddit", t, func(ctx C) {
_, err := d.TxUpAddit(tx, aid, 0, 0, 0, 0, []byte{}, "", "", "", "", "", 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpArchiveBiz(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(233333)
)
Convey("TxUpArchiveBiz", t, func(ctx C) {
_, err := d.TxUpArchiveBiz(tx, aid, 0, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAdditReason(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(233333)
)
Convey("TxUpAdditReason", t, func(ctx C) {
_, err := d.TxUpAdditReason(tx, aid, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpAdditRedirect(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(233333)
)
Convey("TxUpAdditRedirect", t, func(ctx C) {
_, err := d.TxUpAdditRedirect(tx, aid, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
// func TestArchiveTxUpAdditReason(t *testing.T) {
// var (
// c = context.Background()
// tx, _ = d.BeginTran(c)
// aid = int64(233333)
// reason = "2333"
// )
// Convey("TxUpAdditReason", t, func(ctx C) {
// rows, err := d.TxUpAdditReason(tx, aid, reason)
// ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
// ctx.So(err, ShouldBeNil)
// ctx.So(rows, ShouldNotBeNil)
// })
// })
// }
func TestArchiveTxUpAdditRedirect(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(0)
redirectURL = "233333"
)
Convey("TxUpAdditRedirect", t, func(ctx C) {
rows, err := d.TxUpAdditRedirect(tx, aid, redirectURL)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(rows, ShouldNotBeNil)
})
})
}
func TestArchiveTxUpArcAttr(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(0)
bit = uint(0)
val = int32(0)
)
Convey("TxUpArcAttr", t, func(ctx C) {
rows, err := d.TxUpArcAttr(tx, aid, bit, val)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(rows, ShouldNotBeNil)
})
})
}
func TestArchiveTxUpTag(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
aid = int64(22333)
tag = "2333"
)
Convey("TxUpTag", t, func(ctx C) {
rows, err := d.TxUpTag(tx, aid, tag)
ctx.Convey("Then err should be nil.rows should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(rows, ShouldNotBeNil)
})
})
}
func TestArchiveArchive(t *testing.T) {
var (
c = context.Background()
aid = int64(22333)
)
Convey("Archive", t, func(ctx C) {
_, err := d.Archive(c, aid)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveAddit(t *testing.T) {
var (
c = context.Background()
aid = int64(22333)
aa = &archive.ArcMissionParam{}
)
Convey("Addit", t, func(ctx C) {
_, err := d.Addit(c, aid)
ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
Convey("Vote", t, func(ctx C) {
ad, err := d.Vote(c, aid)
ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(ad, ShouldBeNil)
})
})
Convey("Recos", t, func(ctx C) {
ad, err := d.Recos(c, aid)
ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(ad, ShouldBeNil)
})
})
Convey("UpMissionID", t, func(ctx C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.db), "Exec", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (sql.Result, error) {
return nil, sql.ErrNoRows
})
defer guard.Unpatch()
ad, err := d.UpMissionID(c, aa)
ctx.Convey("Then err should be nil.ad should not be nil.", func(ctx C) {
ctx.So(err, ShouldNotBeNil)
ctx.So(ad, ShouldBeZeroValue)
})
})
}
func TestArchiveMids(t *testing.T) {
var (
c = context.Background()
aids = []int64{222}
)
Convey("Mids", t, func(ctx C) {
mm, err := d.Mids(c, aids)
ctx.Convey("Then err should be nil.mm should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(mm, ShouldNotBeNil)
})
})
}
func TestArchiveArchivesUpAll(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
offset = int(20)
ps = int(1)
)
Convey("ArchivesUpAll", t, func(ctx C) {
_, err := d.ArchivesUpAll(c, mid, offset, ps)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveArchivesUpOpen(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
offset = int(20)
ps = int(1)
)
Convey("ArchivesUpOpen", t, func(ctx C) {
_, err := d.ArchivesUpOpen(c, mid, offset, ps)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveArchivesUpUnOpen(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
offset = int(20)
ps = int(1)
)
Convey("ArchivesUpUnOpen", t, func(ctx C) {
_, err := d.ArchivesUpUnOpen(c, mid, offset, ps)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveArchiveAllUpCount(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
)
Convey("ArchiveAllUpCount", t, func(ctx C) {
count, err := d.ArchiveAllUpCount(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(count, ShouldNotBeNil)
})
})
}
func TestArchiveArchiveOpenUpCount(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
)
Convey("ArchiveOpenUpCount", t, func(ctx C) {
count, err := d.ArchiveOpenUpCount(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(count, ShouldNotBeNil)
})
})
}
func TestArchiveArchiveUnOpenUpCount(t *testing.T) {
var (
c = context.Background()
mid = int64(223345)
)
Convey("ArchiveUnOpenUpCount", t, func(ctx C) {
count, err := d.ArchiveUnOpenUpCount(c, mid)
ctx.Convey("Then err should be nil.count should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(count, ShouldNotBeNil)
})
})
}
func TestArchiveSimpleArchive(t *testing.T) {
var (
c = context.Background()
aid = int64(222)
)
Convey("SimpleArchive", t, func(ctx C) {
_, err := d.SimpleArchive(c, aid)
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchivePOI(t *testing.T) {
var (
c = context.Background()
aid = int64(222)
)
Convey("poi", t, func(ctx C) {
data, err := d.POI(c, aid)
fmt.Println(string(data))
ctx.Convey("Then err should be nil.a should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchivePOIAdd(t *testing.T) {
var (
c = context.Background()
aid = int64(222)
tx, _ = d.BeginTran(c)
err error
)
Convey("add poi err", t, func(ctx C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
"Exec",
func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
return nil, fmt.Errorf("tx.Exec error")
})
defer guard.Unpatch()
_, err = d.TxUpArchiveBiz(tx, aid, 1, "2222")
ctx.Convey("TestArchivePOIAdd.", func(ctx C) {
ctx.So(err, ShouldNotBeNil)
})
})
}
func TestArchiverejectedArchives(t *testing.T) {
Convey("rejectedArchives", t, func(ctx C) {
var (
c = context.Background()
mid int64 = 2089809
state int32 = -4
offset int32
limit int32 = 20
start, _ = time.Parse("20060102", "20100101")
)
ctx.Convey("When everything gose positive", func(ctx C) {
arcs, count, err := d.RejectedArchives(c, mid, state, offset, limit, &start)
ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
ctx.So(arcs, ShouldNotBeNil)
ShouldNotEqual(count, 0)
})
})
ctx.Convey("When no rows found", func(ctx C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(d.slaveDB), "Query", func(_ *xsql.DB, _ context.Context, _ string, _ ...interface{}) (*xsql.Rows, error) {
return nil, xsql.ErrNoRows
})
defer guard.Unpatch()
arcs, _, err := d.RejectedArchives(c, mid, state, offset, limit, &start)
ctx.Convey("Then err should be nil.arcs should not be nil.", func(ctx C) {
ctx.So(err, ShouldNotBeNil)
ctx.So(arcs, ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,66 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/gen. DO NOT EDIT.
/*
Package archive is a generated cache proxy package.
It is generated from:
type _cache interface {
// cache: -singleflight=true -nullcache=[]*archive.Staff{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1
StaffData(c context.Context, aid int64) ([]*archive.Staff, error)
}
*/
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/net/metadata"
"go-common/library/stat/prom"
"golang.org/x/sync/singleflight"
)
var _ _cache
var cacheSingleFlights = [1]*singleflight.Group{{}}
// StaffData get data from cache if miss will call source method, then add to cache.
func (d *Dao) StaffData(c context.Context, id int64) (res []*archive.Staff, err error) {
addCache := true
res, err = d.CacheStaffData(c, id)
if err != nil {
addCache = false
err = nil
}
defer func() {
if len(res) == 1 && res[0].ID == -1 {
res = nil
}
}()
if len(res) != 0 {
prom.CacheHit.Incr("StaffData")
return
}
var rr interface{}
sf := d.cacheSFStaffData(id)
rr, err, _ = cacheSingleFlights[0].Do(sf, func() (r interface{}, e error) {
prom.CacheMiss.Incr("StaffData")
r, e = d.Staffs(c, id)
return
})
res = rr.([]*archive.Staff)
if err != nil {
return
}
miss := res
if len(miss) == 0 {
miss = []*archive.Staff{{ID: -1}}
}
if !addCache {
return
}
d.cache.Do(c, func(ctx context.Context) {
d.AddCacheStaffData(metadata.WithContext(c), id, miss)
})
return
}

View File

@@ -0,0 +1,81 @@
package archive
import (
"context"
"fmt"
"go-common/app/service/main/videoup/conf"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/database/sql"
"go-common/library/sync/pipeline/fanout"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
// db
db *sql.DB
rddb *sql.DB
slaveDB *sql.DB
redis *redis.Pool
cache *fanout.Fanout
mc *memcache.Pool
}
// New new a dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
db: sql.NewMySQL(c.DB.Archive),
rddb: sql.NewMySQL(c.DB.ArchiveRead),
slaveDB: sql.NewMySQL(c.DB.ArchiveSlave),
redis: redis.NewPool(c.Redis.Track.Config),
cache: fanout.New("cache"),
mc: memcache.NewPool(c.Memcache.Archive.Config),
}
return d
}
// BeginTran begin transcation.
func (d *Dao) BeginTran(c context.Context) (tx *sql.Tx, err error) {
return d.db.Begin(c)
}
// Close close dao.
func (d *Dao) Close() {
if d.db != nil {
d.db.Close()
}
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return d.db.Ping(c)
}
func staffKey(aid int64) string {
return fmt.Sprintf("staff_aid_%d", aid)
}
func (d *Dao) cacheSFStaffData(aid int64) string {
return fmt.Sprintf("staff_aid_sf_%d", aid)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/gen
type _cache interface {
// cache: -singleflight=true -nullcache=[]*archive.Staff{{ID:-1}} -check_null_code=len($)==1&&$[0].ID==-1
StaffData(c context.Context, aid int64) ([]*archive.Staff, error)
}
//go:generate $GOPATH/src/go-common/app/tool/cache/mc
type _mc interface {
// mc: -key=staffKey
CacheStaffData(c context.Context, key int64) ([]*archive.Staff, error)
// 这里也支持自定义注释 会替换默认的注释
// mc: -key=staffKey -expire=3 -encode=json|gzip
AddCacheStaffData(c context.Context, key int64, value []*archive.Staff) error
// mc: -key=staffKey
DelCacheStaffData(c context.Context, key int64) error
}

View File

@@ -0,0 +1,39 @@
package archive
import (
"flag"
"os"
"path/filepath"
"testing"
"go-common/app/service/main/videoup/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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 {
dir, _ := filepath.Abs("../../cmd/videoup-service.toml")
flag.Set("conf", dir)
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
//conf.Init()
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,71 @@
package archive
import (
"context"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
xtime "go-common/library/time"
)
const (
//insert
_inDelaySQL = "INSERT INTO archive_delay (mid,aid,state,type,dtime) VALUES (?,?,?,?,?)"
//update
_upDelaySQL = "INSERT INTO archive_delay (mid,aid,state,type,dtime,ctime) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE dtime=?,deleted_at='0000-00-00 00:00:00'"
//delete
_delDelaySQL = "UPDATE archive_delay SET deleted_at = ? WHERE aid=? AND type=?"
//select
_dTimeSQL = "SELECT aid,dtime,state FROM archive_delay WHERE aid=? AND type=? AND deleted_at = 0"
)
// TxAddDelay insert delay.
func (d *Dao) TxAddDelay(tx *sql.Tx, mid int64, aid int64, state, tp int8, dTime xtime.Time) (rows int64, err error) {
res, err := tx.Exec(_inDelaySQL, mid, aid, state, tp, dTime)
if err != nil {
log.Error("d.inDelay.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpDelay update delay
func (d *Dao) TxUpDelay(tx *sql.Tx, mid, aid int64, state, tp int8, dTime xtime.Time) (rows int64, err error) {
var now = time.Now()
res, err := tx.Exec(_upDelaySQL, mid, aid, state, tp, dTime, now, dTime)
if err != nil {
log.Error("d.TxUpDelay.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxDelDelay delete delay
func (d *Dao) TxDelDelay(tx *sql.Tx, aid int64, tp int8) (rows int64, err error) {
res, err := tx.Exec(_delDelaySQL, time.Now(), aid, tp)
if err != nil {
log.Error("d.TxDelDelay.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Delay get a delay time by avid.
func (d *Dao) Delay(c context.Context, aid int64, tp int8) (dl *archive.Delay, err error) {
row := d.rddb.QueryRow(c, _dTimeSQL, aid, tp)
dl = &archive.Delay{}
if err = row.Scan(&dl.Aid, &dl.DTime, &dl.State); err != nil {
if err == sql.ErrNoRows {
dl = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,56 @@
package archive
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
"go-common/library/time"
)
func TestDao_TxUpDelay(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
dt time.Time
)
Convey("TxUpArchiveState", t, func(ctx C) {
_, err := d.TxUpDelay(tx, 123, 23333, 0, 0, dt)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxDelDelay(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxDelDelay", t, func(ctx C) {
_, err := d.TxDelDelay(tx, 123, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestArchiveDelay(t *testing.T) {
var (
c = context.Background()
aid = int64(23333)
tp = int8(0)
)
Convey("Delay", t, func(ctx C) {
_, err := d.Delay(c, aid, tp)
ctx.Convey("Then err should be nil.dl should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,31 @@
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/log"
)
const (
_descFormatSQL = "SELECT id,typeid,copyright,components,lang,platform FROM archive_desc_format WHERE state=0"
)
// DescFormats get desc_format info.
func (d *Dao) DescFormats(c context.Context) (dfs []*archive.DescFormat, err error) {
rows, err := d.rddb.Query(c, _descFormatSQL)
if err != nil {
log.Error("d.db.Query error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
df := &archive.DescFormat{}
if err = rows.Scan(&df.ID, &df.TypeID, &df.Copyright, &df.Components, &df.Lang, &df.Platform); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
dfs = append(dfs, df)
}
return
}

View File

@@ -0,0 +1,20 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveDescFormats(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("DescFormats", t, func(ctx convey.C) {
_, err := d.DescFormats(c)
ctx.Convey("Then err should be nil.dfs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,334 @@
package archive
import (
"context"
"fmt"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
"github.com/pkg/errors"
)
const (
_upStateFlowSQL = "UPDATE flow_design SET state =? where id=?"
_inFlowSQL = "INSERT into flow_design(pool,oid,group_id,uid,remark) VALUES (?,?,?,?,?)"
_inFlowLogSQL = "INSERT into flow_design_log(pool,oid,group_id,uid,action,remark) VALUES (?,?,?,?,1,?)"
_flowsSQL = "SELECT id,rank,type,value,name,ctime FROM flow_group WHERE state=0 order by rank desc"
_whiteMidSQL = "SELECT oid,uid FROM flow_design WHERE pool=1 AND state=0 AND group_id=11"
_isFlowGroupIDInSQL = "SELECT id FROM flow_design WHERE pool=? AND state=0 AND group_id=? AND oid=? limit 1"
//稿件 mid 配置
_midsForbidSQL = "SELECT flow_design.id,oid,value FROM flow_design left join flow_group on flow_design.group_id=flow_group.id WHERE flow_design.pool=1 AND flow_design.state=0 AND flow_design.parent=0 AND flow_design.group_id>=12 and flow_group.type=4 "
_isActGroupIDSQL = "SELECT state FROM flow_group WHERE id=?"
_isMidIDSQL = "SELECT id,pool,oid,group_id,parent,uid,remark,ctime,mtime FROM flow_design WHERE pool=1 AND state=0 AND oid=? AND parent=?"
_findGroupIDByScopeSQL = "SELECT group_id FROM flow_scope WHERE pool= ? AND industry_id=? AND brand_id=? AND official=? AND state=0 order by id desc limit 1;"
_appFlowsSQL = "SELECT oid FROM flow_design WHERE pool=0 AND state=0 AND mtime>=? AND mtime<=? AND group_id=11"
_flowGroupPool = "SELECT id, pool FROM flow_group WHERE id IN (%s)"
_flowsByOIDSQL = "SELECT fd.id,fd.pool,fd.oid,fd.group_id,fd.parent,fd.state,fg.value FROM flow_design fd LEFT JOIN flow_group fg ON fd.group_id=fg.id WHERE fd.oid=? AND fd.state=0 AND fg.state=0"
_flowsByGIDSQL = "SELECT fd.id,fd.pool,fd.oid,fd.group_id,fd.parent,fd.state,fg.value FROM flow_design fd LEFT JOIN flow_group fg ON fd.group_id=fg.id WHERE fd.pool=? AND fd.group_id=? AND fd.state=0 AND fg.state=0 LIMIT ?,?"
_flowUniqueSQL = "SELECT id,pool,oid,group_id,parent,state FROM flow_design WHERE oid=? AND pool=? AND group_id=? LIMIT 1"
_flowCountSQL = "SELECT count(*) FROM flow_design fd LEFT JOIN flow_group fg ON fd.group_id=fg.id WHERE fd.pool=? AND fd.group_id=? AND fd.state=0 AND fg.state=0 "
_flowOidsByGidSQL = "SELECT fd.id,fd.pool,fd.oid,fd.group_id,fd.parent,fd.state,fg.value FROM flow_design fd LEFT JOIN flow_group fg ON fd.group_id=fg.id WHERE fd.pool=? AND fd.group_id=? AND fd.state=0 AND fg.state=0 AND fd.oid IN (%s) "
)
// TxAddFlow tx add flow_design.
func (d *Dao) TxAddFlow(tx *sql.Tx, old, uid, groupID int64, pool int8, remark string) (id int64, err error) {
res, err := tx.Exec(_inFlowSQL, pool, old, groupID, uid, remark)
if err != nil {
log.Error("d._inFlow.Exec() error(%v)", err)
return
}
id, err = res.LastInsertId()
return
}
// TxUpFlowState tx set flow_design.state=1.
func (d *Dao) TxUpFlowState(tx *sql.Tx, state int8, id int64) (rows int64, err error) {
res, err := tx.Exec(_upStateFlowSQL, state, id)
if err != nil {
log.Error("d.TxUpFlowState.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxAddFlowLog tx add flow_design log.
func (d *Dao) TxAddFlowLog(tx *sql.Tx, old, uid, groupID int64, pool int8, remark string) (rows int64, err error) {
res, err := tx.Exec(_inFlowLogSQL, pool, old, groupID, uid, remark)
if err != nil {
log.Error("d._inFlowLog.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Flows get flow_control id and remark.
func (d *Dao) Flows(c context.Context) (fs []*archive.Flow, err error) {
rows, err := d.db.Query(c, _flowsSQL)
if err != nil {
log.Error("d.db.Query(%s) error(%v)", _flowsSQL, err)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.Flow{}
if err = rows.Scan(&f.ID, &f.Rank, &f.Type, &f.Value, &f.Remark, &f.CTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
fs = append(fs, f)
}
return
}
// WhiteMids get white mids.
func (d *Dao) WhiteMids(c context.Context) (mids map[int64]int64, err error) {
rows, err := d.db.Query(c, _whiteMidSQL)
if err != nil {
log.Error("d.db.Query(%s) error(%v)", _whiteMidSQL, err)
return
}
defer rows.Close()
mids = make(map[int64]int64)
for rows.Next() {
var mid, uid int64
if err = rows.Scan(&mid, &uid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
mids[mid] = uid
}
return
}
// CheckActGroupID check active GroupID
func (d *Dao) CheckActGroupID(c context.Context, groupID int64) (state int8, err error) {
row := d.db.QueryRow(c, _isActGroupIDSQL, groupID)
if err = row.Scan(&state); err != nil {
if err != sql.ErrNoRows {
log.Error("row.Scan error(%v)", err)
return
}
err = nil
state = archive.FlowDelete
}
return
}
// CheckFlowGroupID check active GroupID
func (d *Dao) CheckFlowGroupID(c context.Context, pool int8, oid, groupID int64) (flowID int64, err error) {
row := d.db.QueryRow(c, _isFlowGroupIDInSQL, pool, groupID, oid)
if err = row.Scan(&flowID); err != nil {
if err != sql.ErrNoRows {
log.Error("row.Scan error(%v)", err)
return
}
err = nil
}
return
}
//CheckFlowMid 通用 mid 流量导向到flow_design
func (d *Dao) CheckFlowMid(c context.Context, pool int8, oid int64) (flows []*archive.FlowData, err error) {
rows, err := d.db.Query(c, _isMidIDSQL, oid, pool)
if err != nil {
log.Error("d.db.Query (%s)|(%d)|(%d) error(%v)", _isMidIDSQL, oid, pool, err)
return
}
defer rows.Close()
for rows.Next() {
item := &archive.FlowData{}
if err = rows.Scan(&item.ID, &item.Pool, &item.OID, &item.GroupID, &item.Parent, &item.UID, &item.Remark, &item.CTime, &item.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
flows = append(flows, item)
}
log.Info("flowDesign mids design (%+v)", flows)
return
}
// FindGroupIDByScope check active GroupID
func (d *Dao) FindGroupIDByScope(c context.Context, pool int8, IndustryID, brandID int64, official int8) (groupID int64, err error) {
row := d.db.QueryRow(c, _findGroupIDByScopeSQL, pool, IndustryID, brandID, official)
if err = row.Scan(&groupID); err != nil {
if err != sql.ErrNoRows {
log.Error("row.Scan error(%v)", err)
return
}
err = nil
groupID = 1
}
return
}
//ForbidMids 稿件 mid 禁止配置 ForbidMids get forbid mids.
func (d *Dao) ForbidMids(c context.Context) (mids map[int64][]string, err error) {
rows, err := d.db.Query(c, _midsForbidSQL)
if err != nil {
log.Error("d.db.Query(%s) error(%v)", _midsForbidSQL, err)
return
}
defer rows.Close()
mids = make(map[int64][]string)
for rows.Next() {
var (
id int64
mid int64
value string
)
if err = rows.Scan(&id, &mid, &value); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
mids[mid] = append(mids[mid], value)
}
log.Info("mids (%+v)", mids)
return
}
// AppFeedAids get aids by appFeed flow.
func (d *Dao) AppFeedAids(c context.Context, startTime, endTime time.Time) (aids []int64, err error) {
rows, err := d.db.Query(c, _appFlowsSQL, startTime, endTime)
if err != nil {
log.Error("d.db.Query(%s|%v|%v) error(%v)", _appFlowsSQL, startTime, endTime, err)
return
}
defer rows.Close()
for rows.Next() {
var aid int64
if err = rows.Scan(&aid); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
if aid == 0 {
continue
}
aids = append(aids, aid)
}
return
}
//FlowGroupPools 获取指定流量套餐的pool
func (d *Dao) FlowGroupPools(c context.Context, ids []int64) (res map[int64]int8, err error) {
var (
rows *sql.Rows
id int64
pool int8
)
res = map[int64]int8{}
idstr := xstr.JoinInts(ids)
if rows, err = d.db.Query(context.TODO(), fmt.Sprintf(_flowGroupPool, idstr)); err != nil {
log.Error("FlowGroupPools d.db.Query error(%v) ids(%s)", err, idstr)
return
}
defer rows.Close()
for rows.Next() {
if err = rows.Scan(&id, &pool); err != nil {
log.Error("FlowGroupPools rows.Scan error(%v) ids(%s)", err, idstr)
return
}
res[id] = pool
}
return
}
//FlowsByOID 获取所有命中的流量套餐记录
func (d *Dao) FlowsByOID(c context.Context, oid int64) (res []*archive.FlowData, err error) {
var (
rows *sql.Rows
)
res = []*archive.FlowData{}
if rows, err = d.db.Query(context.TODO(), _flowsByOIDSQL, oid); err != nil {
log.Error("FlowsByOID d.db.Query error(%v) oid(%d)", err, oid)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.FlowData{}
if err = rows.Scan(&f.ID, &f.Pool, &f.OID, &f.GroupID, &f.Parent, &f.State, &f.GroupValue); err != nil {
log.Error("FlowsByOID rows.Scan error(%v) oid(%d)", err, oid)
return
}
res = append(res, f)
}
return
}
//FlowUnique 获取命中 指定流量套餐的记录
func (d *Dao) FlowUnique(c context.Context, oid, groupID int64, pool int8) (f *archive.FlowData, err error) {
f = &archive.FlowData{}
if err = d.db.QueryRow(context.TODO(), _flowUniqueSQL, oid, pool, groupID).Scan(&f.ID, &f.Pool, &f.OID, &f.GroupID, &f.Parent, &f.State); err != nil {
if err == sql.ErrNoRows {
err = nil
f = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
//OidsFlowByGID 判断指定oids 是否是gid禁止的
func (d *Dao) OidsFlowByGID(c context.Context, pool, gid int64, oids string) (res []*archive.FlowData, err error) {
var (
rows *sql.Rows
)
rows, err = d.db.Query(c, fmt.Sprintf(_flowOidsByGidSQL, oids), pool, gid)
if err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.FlowData{}
if err = rows.Scan(&f.ID, &f.Pool, &f.OID, &f.GroupID, &f.Parent, &f.State, &f.GroupValue); err != nil {
log.Error("FlowsByOID rows.Scan error(%v) oid(%d)", err, gid)
return
}
res = append(res, f)
}
return
}
// CountByGID count buy state.
func (d *Dao) CountByGID(c context.Context, pool, gid int64) (count int64, err error) {
row := d.db.QueryRow(c, _flowCountSQL, pool, gid)
if err = row.Scan(&count); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
err = errors.WithStack(err)
}
}
return
}
// FlowPage page.
func (d *Dao) FlowPage(c context.Context, pool, gid, pn, ps int64) (res []*archive.FlowData, err error) {
var rows *sql.Rows
rows, err = d.db.Query(c, _flowsByGIDSQL, pool, gid, (pn-1)*ps, ps)
if err != nil {
err = errors.WithStack(err)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.FlowData{}
if err = rows.Scan(&f.ID, &f.Pool, &f.OID, &f.GroupID, &f.Parent, &f.State, &f.GroupValue); err != nil {
log.Error("FlowsByOID rows.Scan error(%v) oid(%d)", err, gid)
return
}
res = append(res, f)
}
err = rows.Err()
return
}

View File

@@ -0,0 +1,214 @@
package archive
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestDao_TxAddFlow(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxAddFlow", t, func(ctx C) {
_, err := d.TxAddFlow(tx, 123, 23333, 0, 0, "ut")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpFlowState(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpFlowState", t, func(ctx C) {
_, err := d.TxUpFlowState(tx, 0, 23333)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_CheckFlowGroupID(t *testing.T) {
var (
c = context.Background()
)
Convey("CheckFlowGroupID", t, func(ctx C) {
_, err := d.CheckFlowGroupID(c, 0, 23333, 24)
So(err, ShouldBeNil)
})
}
func TestDao_FlowPage(t *testing.T) {
var (
c = context.Background()
)
Convey("FlowPage", t, func(ctx C) {
_, err := d.FlowPage(c, 0, 23333, 1, 10)
So(err, ShouldBeNil)
})
}
func TestDao_TxAddFlowLog(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxAddFlowLog", t, func(ctx C) {
_, err := d.TxAddFlowLog(tx, 0, 123, 0, 24, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestArchiveFlows(t *testing.T) {
var (
c = context.Background()
)
Convey("Flows", t, func(ctx C) {
_, err := d.Flows(c)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestFlowsByOID(t *testing.T) {
var (
c = context.Background()
)
Convey("FlowsByOID", t, func(ctx C) {
_, err := d.FlowsByOID(c, 2880441)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestFlowUnique(t *testing.T) {
var (
c = context.Background()
)
Convey("FlowUnique", t, func(ctx C) {
_, err := d.FlowUnique(c, 2880441, 11, 0)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestFlowGroupPools(t *testing.T) {
var (
c = context.Background()
)
Convey("FlowGroupPools", t, func(ctx C) {
_, err := d.FlowGroupPools(c, []int64{0})
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestFlowPage(t *testing.T) {
var (
c = context.Background()
)
Convey("FlowPage", t, func(ctx C) {
_, err := d.FlowPage(c, 0, 11, 1, 10)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestFindGroupIDByScope(t *testing.T) {
var (
c = context.Background()
)
Convey("FindGroupIDByScope", t, func(ctx C) {
_, err := d.FindGroupIDByScope(c, 0, 11, 1, 1)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveWhiteMids(t *testing.T) {
var (
c = context.Background()
)
Convey("WhiteMids", t, func(ctx C) {
_, err := d.WhiteMids(c)
ctx.Convey("Then err should be nil.mids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveCheckActGroupID(t *testing.T) {
var (
c = context.Background()
groupID = int64(1)
)
Convey("CheckActGroupID", t, func(ctx C) {
_, err := d.CheckActGroupID(c, groupID)
ctx.Convey("Then err should be nil.state should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveCheckFlowMid(t *testing.T) {
var (
c = context.Background()
pool = int8(1)
oid = int64(2)
)
Convey("CheckFlowMid", t, func(ctx C) {
_, err := d.CheckFlowMid(c, pool, oid)
ctx.Convey("Then err should be nil.flows should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveForbidMids(t *testing.T) {
var (
c = context.Background()
)
Convey("ForbidMids", t, func(ctx C) {
_, err := d.ForbidMids(c)
ctx.Convey("Then err should be nil.mids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveAppFeedAids(t *testing.T) {
var (
c = context.Background()
startTime = time.Now()
endTime = time.Now()
)
Convey("AppFeedAids", t, func(ctx C) {
_, err := d.AppFeedAids(c, startTime, endTime)
ctx.Convey("Then err should be nil.aids should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,35 @@
package archive
import (
"go-common/app/service/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/log"
)
const (
_upFlowIDSQL = "INSERT INTO archive_forbid (aid,on_flow_id) VALUES (?,?) ON DUPLICATE KEY UPDATE on_flow_id=?"
_inForbidSQL = `INSERT INTO archive_forbid (aid,rank_attr,recommend_attr,dynamic_attr,show_attr) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE
rank_attr=?,recommend_attr=?,dynamic_attr=?,show_attr=?`
)
// TxUpForbid update archive addit.
func (d *Dao) TxUpForbid(tx *xsql.Tx, aid, flowID int64) (rows int64, err error) {
res, err := tx.Exec(_upFlowIDSQL, aid, flowID, flowID)
if err != nil {
log.Error("d.upFlowID.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpForbidAttr insert archive forbid.
func (d *Dao) TxUpForbidAttr(tx *xsql.Tx, af *archive.ForbidAttr) (rows int64, err error) {
res, err := tx.Exec(_inForbidSQL, af.Aid, af.RankV, af.RecommendV, af.DynamicV, af.ShowV, af.RankV, af.RecommendV, af.DynamicV, af.ShowV)
if err != nil {
log.Error("d.inForbid.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}

View File

@@ -0,0 +1,131 @@
package archive
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inArcHistorySQL = "INSERT INTO archive_edit_history(aid,mid,title,content,cover,tag) VALUE(?,?,?,?,?,?)"
_inVideoHistorySQL = "INSERT INTO archive_video_edit_history(aid,cid,hid,eptitle,description,filename) VALUE (?,?,?,?,?,?)"
_upVideoHistorySQL = "UPDATE archive_video_edit_history SET cid=? WHERE aid=? AND filename=? AND cid = 0"
_arcHistorySQL = "SELECT id,mid,aid,title,content,cover,tag,ctime FROM archive_edit_history WHERE id =?"
_arcHistorysSQL = "SELECT id,mid,aid,title,content,cover,tag,ctime FROM archive_edit_history WHERE aid =? and ctime >=? ORDER BY id DESC"
_videoHistorySQL = "SELECT cid,eptitle,description,filename FROM archive_video_edit_history WHERE hid =? ORDER BY id ASC"
_inVideoHistorysSQL = "INSERT INTO archive_video_edit_history(aid,cid,hid,eptitle,description,filename) VALUES %s"
)
// TxAddArcHistory insert archive_edit_history.
func (d *Dao) TxAddArcHistory(tx *sql.Tx, aid, mid int64, title, content, cover, tag string) (hid int64, err error) {
res, err := tx.Exec(_inArcHistorySQL, aid, mid, title, content, cover, tag)
if err != nil {
log.Error("d.inArcHistory.Exec() error(%v)", err)
return
}
hid, err = res.LastInsertId()
return
}
// TxAddVideoHistory insert archive_video_edit_history.
func (d *Dao) TxAddVideoHistory(tx *sql.Tx, hid int64, v *archive.Video) (rows int64, err error) {
res, err := tx.Exec(_inVideoHistorySQL, v.Aid, v.Cid, hid, v.Title, v.Desc, v.Filename)
if err != nil {
log.Error("d.inVideoHistory.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVideoHistory update cid to archive_video_edit_history
func (d *Dao) TxUpVideoHistory(tx *sql.Tx, aid, cid int64, filename string) (rows int64, err error) {
res, err := tx.Exec(_upVideoHistorySQL, cid, aid, filename)
if err != nil {
log.Error("d.upVideoHistory.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// ArcHistory select archive edit history by hid.
func (d *Dao) ArcHistory(c context.Context, hid int64) (ah *archive.ArcHistory, err error) {
row := d.rddb.QueryRow(c, _arcHistorySQL, hid)
ah = &archive.ArcHistory{}
if err = row.Scan(&ah.ID, &ah.Mid, &ah.Aid, &ah.Title, &ah.Content, &ah.Cover, &ah.Tag, &ah.CTime); err != nil {
if err == sql.ErrNoRows {
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}
// ArcHistorys select archive edit history by aid.
func (d *Dao) ArcHistorys(c context.Context, aid int64, stime time.Time) (ahs []*archive.ArcHistory, err error) {
rows, err := d.rddb.Query(c, _arcHistorysSQL, aid, stime)
if err != nil {
log.Error("d.arcHissStmt.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
ah := &archive.ArcHistory{}
if err = rows.Scan(&ah.ID, &ah.Mid, &ah.Aid, &ah.Title, &ah.Content, &ah.Cover, &ah.Tag, &ah.CTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
ahs = append(ahs, ah)
}
return
}
// VideoHistory select archive video edit history by hid.
func (d *Dao) VideoHistory(c context.Context, hid int64) (vhs []*archive.VideoHistory, err error) {
rows, err := d.rddb.Query(c, _videoHistorySQL, hid)
if err != nil {
log.Error("d.videoHisStmt.Query(%d) error(%v)", hid, err)
return
}
defer rows.Close()
for rows.Next() {
vh := &archive.VideoHistory{}
if err = rows.Scan(&vh.Cid, &vh.Title, &vh.Desc, &vh.Filename); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
vhs = append(vhs, vh)
}
return
}
// TxAddVideoHistorys batch add archive_video_history.
func (d *Dao) TxAddVideoHistorys(tx *sql.Tx, hid int64, vs []*archive.Video) (err error) {
log.Info("info TxAddVideoHistorys: hid(%d)|vs(%+v)|cntVs(%d)", hid, vs, len(vs))
l := len(vs)
vStrs := make([]string, 0, l)
vArgs := make([]interface{}, 0, l*6)
for _, v := range vs {
vStrs = append(vStrs, "(?, ?, ?, ?, ?, ?)")
vArgs = append(vArgs, strconv.FormatInt(v.Aid, 10))
vArgs = append(vArgs, strconv.FormatInt(v.Cid, 10))
vArgs = append(vArgs, strconv.FormatInt(hid, 10))
vArgs = append(vArgs, v.Title)
vArgs = append(vArgs, v.Desc)
vArgs = append(vArgs, v.Filename)
}
stmt := fmt.Sprintf(_inVideoHistorysSQL, strings.Join(vStrs, ","))
_, err = tx.Exec(stmt, vArgs...)
if err != nil {
log.Error("TxAddVideoHistorys: tx.Exec(vs(%+v))|hid(%d) error(%v)", vs, hid, err)
}
return
}

View File

@@ -0,0 +1,124 @@
package archive
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/service/main/videoup/model/archive"
)
func TestDao_TxAddArcHistory(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxAddArcHistory", t, func(ctx C) {
_, err := d.TxAddArcHistory(tx, 23333, 123, "ssss", "content", "", "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAddVideoHistory(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
)
Convey("TxAddVideoHistory", t, func(ctx C) {
_, err := d.TxAddVideoHistory(tx, 23333, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoHistory(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoHistory", t, func(ctx C) {
_, err := d.TxUpVideoHistory(tx, 23333, 1212, "")
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAddVideoHistorys(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
vs = []*archive.Video{{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}}
)
Convey("TxAddVideoHistorys", t, func(ctx C) {
err := d.TxAddVideoHistorys(tx, 23333, vs)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestArchiveArcHistory(t *testing.T) {
var (
c = context.Background()
hid = int64(23333)
)
Convey("ArcHistory", t, func(ctx C) {
_, err := d.ArcHistory(c, hid)
ctx.Convey("Then err should be nil.ah should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveArcHistorys(t *testing.T) {
var (
c = context.Background()
aid = int64(23333)
stime = time.Now()
)
Convey("ArcHistorys", t, func(ctx C) {
_, err := d.ArcHistorys(c, aid, stime)
ctx.Convey("Then err should be nil.ahs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveVideoHistory(t *testing.T) {
var (
c = context.Background()
hid = int64(23333)
)
Convey("VideoHistory", t, func(ctx C) {
_, err := d.VideoHistory(c, hid)
ctx.Convey("Then err should be nil.vhs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,88 @@
// Code generated by $GOPATH/src/go-common/app/tool/cache/mc. DO NOT EDIT.
/*
Package archive is a generated mc cache package.
It is generated from:
type _mc interface {
// mc: -key=staffKey
CacheStaffData(c context.Context, key int64) ([]*archive.Staff, error)
// 这里也支持自定义注释 会替换默认的注释
// mc: -key=staffKey -expire=3 -encode=json|gzip
AddCacheStaffData(c context.Context, key int64, value []*archive.Staff) error
// mc: -key=staffKey
DelCacheStaffData(c context.Context, key int64) error
}
*/
package archive
import (
"context"
"fmt"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/cache/memcache"
"go-common/library/log"
"go-common/library/stat/prom"
)
var _ _mc
// CacheStaffData get data from mc
func (d *Dao) CacheStaffData(c context.Context, id int64) (res []*archive.Staff, err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := staffKey(id)
reply, err := conn.Get(key)
if err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:CacheStaffData")
log.Errorv(c, log.KV("CacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
res = []*archive.Staff{}
err = conn.Scan(reply, &res)
if err != nil {
prom.BusinessErrCount.Incr("mc:CacheStaffData")
log.Errorv(c, log.KV("CacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// AddCacheStaffData 这里也支持自定义注释 会替换默认的注释
func (d *Dao) AddCacheStaffData(c context.Context, id int64, val []*archive.Staff) (err error) {
if len(val) == 0 {
return
}
conn := d.mc.Get(c)
defer conn.Close()
key := staffKey(id)
item := &memcache.Item{Key: key, Object: val, Expiration: 3, Flags: memcache.FlagJSON | memcache.FlagGzip}
if err = conn.Set(item); err != nil {
prom.BusinessErrCount.Incr("mc:AddCacheStaffData")
log.Errorv(c, log.KV("AddCacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}
// DelCacheStaffData delete data from mc
func (d *Dao) DelCacheStaffData(c context.Context, id int64) (err error) {
conn := d.mc.Get(c)
defer conn.Close()
key := staffKey(id)
if err = conn.Delete(key); err != nil {
if err == memcache.ErrNotFound {
err = nil
return
}
prom.BusinessErrCount.Incr("mc:DelCacheStaffData")
log.Errorv(c, log.KV("DelCacheStaffData", fmt.Sprintf("%+v", err)), log.KV("key", key))
return
}
return
}

View File

@@ -0,0 +1,20 @@
package archive
import (
"context"
"go-common/library/log"
)
const (
_inNetsafeSQL = "INSERT INTO netsafe (nid,md5) VALUES (?,?)"
)
// AddNetSafeMd5 fn
func (d *Dao) AddNetSafeMd5(c context.Context, nid int64, md5 string) (rows int64, err error) {
res, err := d.db.Exec(c, _inNetsafeSQL, nid, md5)
if err != nil {
log.Error("_inNetsafeSQL.Exec error(%v)", err)
return
}
return res.RowsAffected()
}

View File

@@ -0,0 +1,17 @@
package archive
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestDao_AddNetSafeMd5(t *testing.T) {
var (
c = context.Background()
)
Convey("AddNetSafeMd5", t, func(ctx C) {
_, err := d.AddNetSafeMd5(c, 23333, "ssadasdasdasd")
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,491 @@
package archive
import (
"bytes"
"context"
"fmt"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
farm "github.com/dgryski/go-farm"
)
const (
_inVideoCidSQL = `INSERT IGNORE INTO video (id,filename,src_type,resolutions,playurl,status,xcode_state,duration,filesize,attribute,failcode,hash64)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?)`
_inNewVideoSQL = `INSERT INTO video (filename,src_type,resolutions,playurl,status,xcode_state,duration,filesize,attribute,failcode,hash64)
VALUES (?,?,?,?,?,?,?,?,?,?,?)`
_inVideoRelationSQL = "INSERT IGNORE INTO archive_video_relation (id,aid,cid,title,description,index_order,ctime) VALUES (?,?,?,?,?,?,?)"
_upVideoRelationSQL = "UPDATE archive_video_relation SET title=?,description=?,index_order=? ,state=? WHERE aid=? and cid=?"
_upRelationStateSQL = "UPDATE archive_video_relation SET state=? WHERE aid=? AND cid=?"
_upVideoStatusSQL = "UPDATE video SET status=? WHERE id=?"
_upNewVideoSQL = "UPDATE video SET src_type=?,status=?,xcode_state=? WHERE id=?"
_newVideoFnSQL = "SELECT id,filename,src_type,resolutions,playurl,status,xcode_state,duration,filesize,attribute,failcode,ctime,mtime,dimensions FROM video WHERE hash64=? AND filename=?"
_newVideoByFnSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,avr.ctime,avr.mtime,v.dimensions FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE hash64=? AND filename=?`
_newVideoDataCidsFnSQL = "SELECT id,filename FROM video WHERE hash64 in (%s) AND filename in (%s)"
_newsimpleArcVideoSQL = `SELECT cid,title,index_order,state,mtime FROM archive_video_relation WHERE aid=?`
_newVideosSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime,v.dimensions FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE aid=? ORDER BY index_order`
_newvideoCidSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime,v.dimensions FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE cid=? ORDER BY id LIMIT 1`
_newVideosCidSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime,v.dimensions FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE cid IN (%s)`
_newVideosFnSQL = `SELECT avr.id,v.filename,avr.cid,avr.aid,avr.title,avr.description,v.src_type,v.duration,v.filesize,v.resolutions,v.playurl,v.failcode,
avr.index_order,v.attribute,v.xcode_state,avr.state,v.status,avr.ctime,avr.mtime,v.dimensions FROM archive_video_relation avr JOIN video v on avr.cid = v.id
WHERE hash64 in (%s) AND filename in (%s)`
_newVidReasonSQL = `SELECT ava.vid,ava.reason FROM archive_video_audit ava LEFT JOIN archive_video_relation avr ON ava.vid=avr.id WHERE ava.aid=? AND avr.state!=-100`
_newVideosTimeoutSQL = `SELECT id ,filename,ctime,mtime from video WHERE hash64 in (%s) AND filename in (%s)`
)
// TxAddVideoCid insert video to get cid.
func (d *Dao) TxAddVideoCid(tx *sql.Tx, v *archive.Video) (cid int64, err error) {
hash64 := int64(farm.Hash64([]byte(v.Filename)))
res, err := tx.Exec(_inVideoCidSQL, v.Cid, v.Filename, v.SrcType, v.Resolutions, v.Playurl, v.Status, v.XcodeState, v.Duration, v.Filesize, v.Attribute, v.FailCode, hash64)
if err != nil {
log.Error("d.inVideoCid.Exec error(%v)", err)
return
}
cid, err = res.LastInsertId()
return
}
// AddNewVideo insert new video.
func (d *Dao) AddNewVideo(c context.Context, v *archive.Video) (cid int64, err error) {
hash64 := int64(farm.Hash64([]byte(v.Filename)))
res, err := d.db.Exec(c, _inNewVideoSQL, v.Filename, v.SrcType, v.Resolutions, v.Playurl, v.Status, v.XcodeState, v.Duration, v.Filesize, v.Attribute, v.FailCode, hash64)
if err != nil {
log.Error("d.inNewVideo.Exec error(%v)", err)
return
}
cid, err = res.LastInsertId()
return
}
// TxAddNewVideo insert new video.
func (d *Dao) TxAddNewVideo(tx *sql.Tx, v *archive.Video) (cid int64, err error) {
hash64 := int64(farm.Hash64([]byte(v.Filename)))
res, err := tx.Exec(_inNewVideoSQL, v.Filename, v.SrcType, v.Resolutions, v.Playurl, v.Status, v.XcodeState, v.Duration, v.Filesize, v.Attribute, v.FailCode, hash64)
if err != nil {
log.Error("tx.inNewVideo.Exec error(%v)", err)
return
}
cid, err = res.LastInsertId()
return
}
// TxAddVideoRelation insert archive_video_relation to get vid.
func (d *Dao) TxAddVideoRelation(tx *sql.Tx, v *archive.Video) (vid int64, err error) {
res, err := tx.Exec(_inVideoRelationSQL, v.ID, v.Aid, v.Cid, v.Title, v.Desc, v.Index, v.CTime)
if err != nil {
log.Error("d.inVideoRelation.Exec error(%v)", err)
return
}
vid, err = res.LastInsertId()
return
}
// TxUpVideoRelation update archive_video_relation info by aid and cid.
func (d *Dao) TxUpVideoRelation(tx *sql.Tx, v *archive.Video) (rows int64, err error) {
res, err := tx.Exec(_upVideoRelationSQL, v.Title, v.Desc, v.Index, archive.VideoStatusOpen, v.Aid, v.Cid)
if err != nil {
log.Error("d.upVideoRelation.Exec(%v) error(%v)", v, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpRelationState update archive_video_relation state by aid and cid.
func (d *Dao) TxUpRelationState(tx *sql.Tx, aid, cid int64, state int16) (rows int64, err error) {
res, err := tx.Exec(_upRelationStateSQL, state, aid, cid)
if err != nil {
log.Error("d.upRelationState.Exec(%d,%d,%d) error(%v)", aid, cid, state, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVdoStatus update video state by cid.
func (d *Dao) TxUpVdoStatus(tx *sql.Tx, cid int64, status int16) (rows int64, err error) {
res, err := tx.Exec(_upVideoStatusSQL, status, cid)
if err != nil {
log.Error("d.upVideoStatus.Exec(%d,%d) error(%v)", cid, status, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpNewVideo update video SrcType\Status\XcodeState by cid.
func (d *Dao) TxUpNewVideo(tx *sql.Tx, v *archive.Video) (rows int64, err error) {
res, err := tx.Exec(_upNewVideoSQL, v.SrcType, v.Status, v.XcodeState, v.Cid)
if err != nil {
log.Error("d.upSimNewVideo.Exec(%s,%d,%d,%d) error(%v)", v.SrcType, v.Status, v.XcodeState, v.Cid, err)
return
}
rows, err = res.RowsAffected()
return
}
// NewVideoFn get video by filename
func (d *Dao) NewVideoFn(c context.Context, filename string) (v *archive.Video, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
row := d.rddb.QueryRow(c, _newVideoFnSQL, hash64, filename)
v = &archive.Video{}
var dimStr string
if err = row.Scan(&v.Cid, &v.Filename, &v.SrcType, &v.Resolutions, &v.Playurl, &v.Status, &v.XcodeState, &v.Duration, &v.Filesize, &v.Attribute, &v.FailCode, &v.CTime, &v.MTime, &dimStr); err != nil {
if err == sql.ErrNoRows {
err = nil
v = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
return
}
// NewVideoByFn get video by filename
func (d *Dao) NewVideoByFn(c context.Context, filename string) (v *archive.Video, err error) {
hash64 := int64(farm.Hash64([]byte(filename)))
row := d.rddb.QueryRow(c, _newVideoByFnSQL, hash64, filename)
v = &archive.Video{}
var dimStr string
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &v.Status, &v.CTime, &v.MTime, &dimStr); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
return
}
// NewCidsByFns get cids map in batches by filenames and hash64s.
func (d *Dao) NewCidsByFns(c context.Context, nvs []*archive.Video) (cids map[string]int64, err error) {
var (
buf bytes.Buffer
hash64s []int64
)
for _, v := range nvs {
buf.WriteByte('\'')
buf.WriteString(v.Filename)
buf.WriteString("',")
hash64s = append(hash64s, int64(farm.Hash64([]byte(v.Filename))))
}
buf.Truncate(buf.Len() - 1)
rows, err := d.rddb.Query(c, fmt.Sprintf(_newVideoDataCidsFnSQL, xstr.JoinInts(hash64s), buf.String()))
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
cids = make(map[string]int64)
for rows.Next() {
var (
cid int64
filename string
)
if err = rows.Scan(&cid, &filename); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
cids[filename] = cid
}
return
}
// SimpleArcVideos get simple videos from avr
func (d *Dao) SimpleArcVideos(c context.Context, aid int64) (vs []*archive.SimpleVideo, err error) {
rows, err := d.rddb.Query(c, _newsimpleArcVideoSQL, aid)
if err != nil {
log.Error("d.videosStmt.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
v := &archive.SimpleVideo{}
if err = rows.Scan(&v.Cid, &v.Title, &v.Index, &v.Status, &v.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
vs = append(vs, v)
}
return
}
// NewVideos get videos info by aid.
func (d *Dao) NewVideos(c context.Context, aid int64) (vs []*archive.Video, err error) {
rows, err := d.rddb.Query(c, _newVideosSQL, aid)
if err != nil {
log.Error("d.videosStmt.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
v := &archive.Video{}
var (
avrState, vState int16
dimStr string
)
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime, &dimStr); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
vs = append(vs, v)
}
return
}
// NewVideoMap get video map info by aid.
func (d *Dao) NewVideoMap(c context.Context, aid int64) (vm map[string]*archive.Video, cvm map[int64]*archive.Video, err error) {
rows, err := d.rddb.Query(c, _newVideosSQL, aid)
if err != nil {
log.Error("d.videosStmt.Query(%d) error(%v)", aid, err)
return
}
defer rows.Close()
vm = make(map[string]*archive.Video)
cvm = make(map[int64]*archive.Video)
for rows.Next() {
v := &archive.Video{}
var (
avrState, vState int16
dimStr string
)
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime, &dimStr); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
cvm[v.Cid] = v
vm[v.Filename] = v
}
return
}
// NewVideoByCID get video by cid.
func (d *Dao) NewVideoByCID(c context.Context, cid int64) (v *archive.Video, err error) {
row := d.rddb.QueryRow(c, _newvideoCidSQL, cid)
v = &archive.Video{}
var (
avrState, vState int16
dimStr string
)
if err = row.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime, &dimStr); err != nil {
if err == sql.ErrNoRows {
v = nil
err = nil
}
log.Error("row.Scan error(%v)", err)
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
return
}
// NewVideosByCID multi get video by cids.
func (d *Dao) NewVideosByCID(c context.Context, cids []int64) (vm map[int64]map[int64]*archive.Video, err error) {
rows, err := d.rddb.Query(c, fmt.Sprintf(_newVideosCidSQL, xstr.JoinInts(cids)))
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
vm = make(map[int64]map[int64]*archive.Video)
for rows.Next() {
var (
avrState, vState int16
dimStr string
)
v := &archive.Video{}
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime, &dimStr); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
if vv, ok := vm[v.Aid]; !ok {
vm[v.Aid] = map[int64]*archive.Video{
v.Cid: v,
}
} else {
vv[v.Cid] = v
}
}
return
}
// NewVideosByFn multi get video by filenames.
func (d *Dao) NewVideosByFn(c context.Context, fns []string) (vm map[int64]map[string]*archive.Video, err error) {
var (
buf bytes.Buffer
hash64s []int64
)
for _, fn := range fns {
buf.WriteByte('\'')
buf.WriteString(fn)
buf.WriteString("',")
hash64s = append(hash64s, int64(farm.Hash64([]byte(fn))))
}
buf.Truncate(buf.Len() - 1)
rows, err := d.rddb.Query(c, fmt.Sprintf(_newVideosFnSQL, xstr.JoinInts(hash64s), buf.String()))
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
vm = make(map[int64]map[string]*archive.Video)
for rows.Next() {
var (
avrState, vState int16
dimStr string
)
v := &archive.Video{}
if err = rows.Scan(&v.ID, &v.Filename, &v.Cid, &v.Aid, &v.Title, &v.Desc, &v.SrcType, &v.Duration, &v.Filesize, &v.Resolutions,
&v.Playurl, &v.FailCode, &v.Index, &v.Attribute, &v.XcodeState, &avrState, &vState, &v.CTime, &v.MTime, &dimStr); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
v.Dimension, _ = d.parseDimensions(dimStr)
// 2 state map to 1
if avrState == archive.VideoStatusDelete {
v.Status = archive.VideoStatusDelete
} else {
v.Status = vState
}
if vv, ok := vm[v.Aid]; !ok {
vm[v.Aid] = map[string]*archive.Video{
v.Filename: v,
}
} else {
vv[v.Filename] = v
}
}
return
}
// CheckNewVideosTimeout check 48 timeout by add filenames.
func (d *Dao) CheckNewVideosTimeout(c context.Context, fns []string) (has bool, filename string, err error) {
var (
buf bytes.Buffer
hash64s []int64
)
for _, fn := range fns {
buf.WriteByte('\'')
buf.WriteString(fn)
buf.WriteString("',")
hash64s = append(hash64s, int64(farm.Hash64([]byte(fn))))
}
buf.Truncate(buf.Len() - 1)
rows, err := d.rddb.Query(c, fmt.Sprintf(_newVideosTimeoutSQL, xstr.JoinInts(hash64s), buf.String()))
if err != nil {
log.Error("db.Query() error(%v)", err)
return
}
defer rows.Close()
now := time.Now().Unix()
for rows.Next() {
v := &archive.VideoFn{}
if err = rows.Scan(&v.Cid, &v.Filename, &v.CTime, &v.MTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
if now-v.CTime.Time().Unix() > archive.VideoFilenameTimeout {
log.Error("this video filename(%v) timeout (%+v)", v.Filename, v)
has = true
filename = v.Filename
err = nil
return
}
}
return
}
// NewVideosReason get videos audit reason.
func (d *Dao) NewVideosReason(c context.Context, aid int64) (res map[int64]string, err error) {
rows, err := d.rddb.Query(c, _newVidReasonSQL, aid)
if err != nil {
log.Error("d.vdoRsnStmt.Query(%d)|error(%v)", aid, err)
return
}
defer rows.Close()
res = make(map[int64]string)
for rows.Next() {
var (
vid int64
reason string
)
if err = rows.Scan(&vid, &reason); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
res[vid] = reason
}
return
}
// parseDimensions 解析分辨率
func (d *Dao) parseDimensions(dim string) (dimensions *archive.Dimension, err error) {
dimensions = &archive.Dimension{}
if dim == "" || dim == "0,0,0" {
return
}
dims, err := xstr.SplitInts(dim)
if err != nil {
log.Error("d.parseDimensions() xstr.SplitInts(%s) error(%v)", dim, err)
return
}
if len(dims) != 3 {
return
}
dimensions = &archive.Dimension{
Width: dims[0],
Height: dims[1],
Rotate: dims[2],
}
return
}

View File

@@ -0,0 +1,308 @@
package archive
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/service/main/videoup/model/archive"
)
func TestDao_TxAddVideoCid(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
)
Convey("TxAddVideoCid", t, func(ctx C) {
_, err := d.TxAddVideoCid(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_AddNewVideo(t *testing.T) {
var (
c = context.Background()
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
)
Convey("AddNewVideo", t, func(ctx C) {
_, err := d.AddNewVideo(c, v)
So(err, ShouldBeNil)
})
}
func TestDao_TxAddNewVideo(t *testing.T) {
var (
c = context.Background()
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
tx, _ = d.BeginTran(c)
)
Convey("TxAddNewVideo", t, func(ctx C) {
_, err := d.TxAddNewVideo(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAddVideoRelation(t *testing.T) {
var (
c = context.Background()
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
tx, _ = d.BeginTran(c)
)
Convey("TxAddVideoRelation", t, func(ctx C) {
_, err := d.TxAddVideoRelation(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoRelation(t *testing.T) {
var (
c = context.Background()
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoRelation", t, func(ctx C) {
_, err := d.TxUpVideoRelation(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpRelationState(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpRelationState", t, func(ctx C) {
_, err := d.TxUpRelationState(tx, 23333, 1212, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVdoStatus(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVdoStatus", t, func(ctx C) {
_, err := d.TxUpVdoStatus(tx, 1212, 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpNewVideo(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
v = &archive.Video{
Aid: 23333,
Cid: 12121,
Title: "sssss",
}
)
Convey("TxUpNewVideo", t, func(ctx C) {
_, err := d.TxUpNewVideo(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_NewCidsByFns(t *testing.T) {
var (
c = context.Background()
vs = []*archive.Video{{
Filename: "1212121243gf",
}}
)
Convey("NewCidsByFns", t, func(ctx C) {
_, err := d.NewCidsByFns(c, vs)
So(err, ShouldBeNil)
})
}
func TestDao_CheckNewVideosTimeout(t *testing.T) {
var (
c = context.Background()
fs = []string{"1212121243gf"}
)
Convey("CheckNewVideosTimeout", t, func(ctx C) {
_, _, err := d.CheckNewVideosTimeout(c, fs)
So(err, ShouldBeNil)
})
}
func TestDao_ParseDimensions(t *testing.T) {
Convey("CheckNewVideosTimeout", t, func(ctx C) {
_, err := d.parseDimensions("1,2,3")
So(err, ShouldBeNil)
})
}
func TestArchiveNewVideoFn(t *testing.T) {
var (
c = context.Background()
filename = "23333333333"
)
Convey("NewVideoFn", t, func(ctx C) {
_, err := d.NewVideoFn(c, filename)
ctx.Convey("Then err should be nil.v should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideoByFn(t *testing.T) {
var (
c = context.Background()
filename = "23333333333"
)
Convey("NewVideoByFn", t, func(ctx C) {
_, err := d.NewVideoByFn(c, filename)
ctx.Convey("Then err should be nil.v should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveSimpleArcVideos(t *testing.T) {
var (
c = context.Background()
aid = int64(2333333)
)
Convey("SimpleArcVideos", t, func(ctx C) {
_, err := d.SimpleArcVideos(c, aid)
ctx.Convey("Then err should be nil.vs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideos(t *testing.T) {
var (
c = context.Background()
aid = int64(2333333)
)
Convey("NewVideos", t, func(ctx C) {
_, err := d.NewVideos(c, aid)
ctx.Convey("Then err should be nil.vs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideoMap(t *testing.T) {
var (
c = context.Background()
aid = int64(23333)
)
Convey("NewVideoMap", t, func(ctx C) {
_, _, err := d.NewVideoMap(c, aid)
ctx.Convey("Then err should be nil.vm,cvm should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideoByCID(t *testing.T) {
var (
c = context.Background()
cid = int64(23333)
)
Convey("NewVideoByCID", t, func(ctx C) {
_, err := d.NewVideoByCID(c, cid)
ctx.Convey("Then err should be nil.v should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideosByCID(t *testing.T) {
var (
c = context.Background()
cids = []int64{23333}
)
Convey("NewVideosByCID", t, func(ctx C) {
_, err := d.NewVideosByCID(c, cids)
ctx.Convey("Then err should be nil.vm should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideosByFn(t *testing.T) {
var (
c = context.Background()
fns = []string{"23333"}
)
Convey("NewVideosByFn", t, func(ctx C) {
_, err := d.NewVideosByFn(c, fns)
ctx.Convey("Then err should be nil.vm should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchiveNewVideosReason(t *testing.T) {
var (
c = context.Background()
aid = int64(23333)
)
Convey("NewVideosReason", t, func(ctx C) {
_, err := d.NewVideosReason(c, aid)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,87 @@
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
"time"
)
//私单业务
const (
_inPorderSQL = `INSERT INTO archive_porder (aid,industry_id,brand_id,brand_name,official,show_type,show_front,advertiser,agent,state) VALUES (?,?,?,?,?,?,1,?,?,0) ON DUPLICATE KEY UPDATE industry_id=?,brand_id=?,brand_name=?,official=?,show_type=?,advertiser=?,agent=?`
_selPorderSQL = `select industry_id,brand_id,brand_name,official,show_type,advertiser,agent,state from archive_porder where aid=?`
_pconfigSQL = `select id, type, name from porder_config where state = 0 order by rank desc,type asc`
_parcsSQL = `select aid,industry_id,brand_id,brand_name,official,show_type,advertiser,agent,state,show_front,ctime,mtime from archive_porder WHERE ctime BETWEEN ? AND ? order by id desc`
)
// TxUpPorder add or update archive_porder
func (d *Dao) TxUpPorder(tx *sql.Tx, aid int64, ap *archive.ArcParam) (rows int64, err error) {
if ap.Porder.Official == 1 {
ap.Porder.BrandName = ""
}
res, err := tx.Exec(_inPorderSQL, aid, ap.Porder.IndustryID, ap.Porder.BrandID, ap.Porder.BrandName, ap.Porder.Official, ap.Porder.ShowType, ap.Porder.Advertiser, ap.Porder.Agent, ap.Porder.IndustryID, ap.Porder.BrandID, ap.Porder.BrandName, ap.Porder.Official, ap.Porder.ShowType, ap.Porder.Advertiser, ap.Porder.Agent)
if err != nil {
log.Error("d.TxUpPorder.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Porder get archive Proder
func (d *Dao) Porder(c context.Context, aid int64) (p *archive.Porder, err error) {
row := d.rddb.QueryRow(c, _selPorderSQL, aid)
p = &archive.Porder{}
if err = row.Scan(&p.IndustryID, &p.BrandID, &p.BrandName, &p.Official, &p.ShowType, &p.Advertiser, &p.Agent, &p.State); err != nil {
if err != sql.ErrNoRows {
log.Error("row.Scan error(%v)", err)
return
}
err = nil
}
return
}
// PorderCfgList fn
func (d *Dao) PorderCfgList(c context.Context) (pcfgs []*archive.Pconfig, err error) {
rows, err := d.rddb.Query(c, _pconfigSQL)
if err != nil {
log.Error("d.db.Query(%s)|error(%v)", _pconfigSQL, err)
return
}
defer rows.Close()
for rows.Next() {
cfg := &archive.Pconfig{}
if err = rows.Scan(&cfg.ID, &cfg.Tp, &cfg.Name); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
pcfgs = append(pcfgs, cfg)
}
return
}
// PorderArcList fn
func (d *Dao) PorderArcList(c context.Context, begin, end time.Time) (res []*archive.PorderArc, err error) {
res = []*archive.PorderArc{}
rows, err := d.rddb.Query(c, _parcsSQL, begin, end)
if err != nil {
log.Error("PorderArcList error(%v)", err)
return
}
defer rows.Close()
for rows.Next() {
r := &archive.PorderArc{}
if err = rows.Scan(&r.AID, &r.IndustryID, &r.BrandID, &r.BrandName, &r.Official, &r.ShowType, &r.Advertiser, &r.Agent, &r.State, &r.ShowFront, &r.Ctime, &r.Mtime); err != nil {
log.Error("row.Scan() error(%v)", err)
res = nil
return
}
res = append(res, r)
}
err = rows.Err()
return
}

View File

@@ -0,0 +1,68 @@
package archive
import (
"context"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/service/main/videoup/model/archive"
)
func TestDao_TxUpPorder(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
ap = &archive.ArcParam{
Porder: &archive.Porder{},
}
)
Convey("TxUpPorder", t, func(ctx C) {
_, err := d.TxUpPorder(tx, 23333, ap)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestArchivePorder(t *testing.T) {
var (
c = context.Background()
aid = int64(23333)
)
Convey("Porder", t, func(ctx C) {
_, err := d.Porder(c, aid)
ctx.Convey("Then err should be nil.p should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchivePorderCfgList(t *testing.T) {
var (
c = context.Background()
)
Convey("PorderCfgList", t, func(ctx C) {
_, err := d.PorderCfgList(c)
ctx.Convey("Then err should be nil.pcfgs should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}
func TestArchivePorderArcList(t *testing.T) {
var (
c = context.Background()
begin = time.Now()
end = time.Now()
)
Convey("PorderArcList", t, func(ctx C) {
_, err := d.PorderArcList(c, begin, end)
ctx.Convey("Then err should be nil.res should not be nil.", func(ctx C) {
ctx.So(err, ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,66 @@
package archive
import (
"context"
"fmt"
"go-common/library/cache/redis"
"go-common/library/log"
)
const (
_videoJamTime = "va_v_jam_time"
_editlock = "edit_lock_aid_%d"
)
func lockKey(aid int64) string {
return fmt.Sprintf(_editlock, aid)
}
// GetVideoJam get video traffic jam time
func (d *Dao) GetVideoJam(c context.Context) (seconds int, err error) {
var conn = d.redis.Get(c)
defer conn.Close()
if seconds, err = redis.Int(conn.Do("GET", _videoJamTime)); err != nil {
log.Error("conn.Do(GET,%s) error(%v)", _videoJamTime, err)
}
return
}
//SetNXLock redis lock.
func (d *Dao) SetNXLock(c context.Context, aid int64, times int64) (res bool, err error) {
var (
key = lockKey(aid)
conn = d.redis.Get(c)
)
defer conn.Close()
if res, err = redis.Bool(conn.Do("SETNX", key, "1")); err != nil {
if err == redis.ErrNil {
err = nil
} else {
res = true
log.Error("conn.Do(SETNX(%s)) error(%v)", key, err)
return
}
}
if res {
if _, err = redis.Bool(conn.Do("EXPIRE", key, times)); err != nil {
log.Error("conn.Do(EXPIRE, %s, %d) error(%v)", key, times, err)
return
}
}
return
}
//DelLock del lock.
func (d *Dao) DelLock(c context.Context, aid int64) (err error) {
var (
key = lockKey(aid)
conn = d.redis.Get(c)
)
defer conn.Close()
if _, err = conn.Do("DEL", key); err != nil {
log.Error("conn.Do(del,%v) err(%v)", key, err)
}
return
}

View File

@@ -0,0 +1,61 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchivelockKey(t *testing.T) {
var (
aid = int64(0)
)
convey.Convey("lockKey", t, func(ctx convey.C) {
p1 := lockKey(aid)
ctx.Convey("Then p1 should not be nil.", func(ctx convey.C) {
ctx.So(p1, convey.ShouldNotBeNil)
})
})
}
func TestArchiveGetVideoJam(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("GetVideoJam", t, func(ctx convey.C) {
seconds, err := d.GetVideoJam(c)
ctx.Convey("Then err should be nil.seconds should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(seconds, convey.ShouldNotBeNil)
})
})
}
func TestArchiveSetNXLock(t *testing.T) {
var (
c = context.Background()
aid = int64(0)
times = int64(0)
)
convey.Convey("SetNXLock", t, func(ctx convey.C) {
res, err := d.SetNXLock(c, aid, times)
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 TestArchiveDelLock(t *testing.T) {
var (
c = context.Background()
aid = int64(0)
)
convey.Convey("DelLock", t, func(ctx convey.C) {
err := d.DelLock(c, aid)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,22 @@
package archive
import (
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inRelationSQL = "INSERT INTO archive_video_relation (aid,cid,title,description,index_order) VALUES (?,?,?,?,?)"
)
// TxAddRelation insert archive_video_relation.
func (d *Dao) TxAddRelation(tx *sql.Tx, v *archive.Video) (vid int64, err error) {
res, err := tx.Exec(_inRelationSQL, v.Aid, v.Cid, v.Title, v.Desc, v.Index)
if err != nil {
log.Error("d.inRelation.Exec error(%v)", err)
return
}
vid, err = res.LastInsertId()
return
}

View File

@@ -0,0 +1,39 @@
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_inArcReportSQL = "INSERT IGNORE INTO archive_report (mid,aid,type,reason,pics,ctime,mtime) VALUES(?,?,?,?,?,?,?)"
_arcReportSQL = "SELECT aid,mid,type,reason,pics,ctime,mtime FROM archive_report WHERE aid=? AND mid=? LIMIT 1"
)
// AddArcReport insert archive_report.
func (d *Dao) AddArcReport(c context.Context, aa *archive.ArcReport) (id int64, err error) {
res, err := d.db.Exec(c, _inArcReportSQL, aa.Mid, aa.Aid, aa.Type, aa.Reason, aa.Pics, aa.CTime, aa.MTime)
if err != nil {
log.Error("_inArcReport.Exec error(%v)", err)
return
}
return res.LastInsertId()
}
// ArcReport get archive_report by aid and mid.
func (d *Dao) ArcReport(c context.Context, aid, mid int64) (aa *archive.ArcReport, err error) {
row := d.rddb.QueryRow(c, _arcReportSQL, aid, mid)
aa = &archive.ArcReport{}
if err = row.Scan(&aa.Aid, &aa.Mid, &aa.Type, &aa.Reason, &aa.Pics, &aa.CTime, &aa.MTime); err != nil {
if err == sql.ErrNoRows {
err = nil
aa = nil
} else {
log.Error("row.Scan error(%v)", err)
}
}
return
}

View File

@@ -0,0 +1,121 @@
package archive
import (
"context"
"database/sql"
"fmt"
"go-common/app/service/main/videoup/model/archive"
xsql "go-common/library/database/sql"
"go-common/library/time"
"reflect"
"testing"
"github.com/bouk/monkey"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveArcReport(t *testing.T) {
var (
c = context.Background()
aid = int64(2333)
mid = int64(23333)
)
convey.Convey("ArcReport", t, func(ctx convey.C) {
_, err := d.ArcReport(c, aid, mid)
ctx.Convey("Then err should be nil.aa should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestTxAddRelation(t *testing.T) {
var (
c = context.Background()
err error
tx, _ = d.BeginTran(c)
v = &archive.Video{
Aid: int64(10110817),
Cid: int64(10134702),
Title: "iamtitle",
Index: 1,
}
)
convey.Convey("TestTxAddRelation", t, func(ctx convey.C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
"Exec",
func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
return nil, fmt.Errorf("tx.Exec error")
})
defer guard.Unpatch()
_, err = d.TxAddRelation(tx, v)
ctx.Convey("TestArchivePOIAdd.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestTxUpForbid(t *testing.T) {
var (
c = context.Background()
err error
aid = int64(10110817)
fid = int64(1)
tx, _ = d.BeginTran(c)
)
convey.Convey("TestTxUpForbid", t, func(ctx convey.C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
"Exec",
func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
return nil, fmt.Errorf("tx.Exec error")
})
defer guard.Unpatch()
_, err = d.TxUpForbid(tx, aid, fid)
ctx.Convey("TxUpForbid.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestTxUpForbidAttr(t *testing.T) {
var (
c = context.Background()
err error
tx, _ = d.BeginTran(c)
af = &archive.ForbidAttr{}
)
convey.Convey("TestTxUpForbidAttr", t, func(ctx convey.C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
"Exec",
func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
return nil, fmt.Errorf("tx.Exec error")
})
defer guard.Unpatch()
_, err = d.TxUpForbidAttr(tx, af)
ctx.Convey("TxUpForbidAttr.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}
func TestTxAddDelay(t *testing.T) {
var (
c = context.Background()
err error
tx, _ = d.BeginTran(c)
aid = int64(2333)
mid = int64(23333)
state = int8(1)
tp = int8(2)
dtime time.Time
)
convey.Convey("TestTxAddDelay", t, func(ctx convey.C) {
guard := monkey.PatchInstanceMethod(reflect.TypeOf(tx),
"Exec",
func(_ *xsql.Tx, _ string, _ ...interface{}) (sql.Result, error) {
return nil, fmt.Errorf("tx.Exec error")
})
defer guard.Unpatch()
_, err = d.TxAddDelay(tx, mid, aid, state, tp, dtime)
ctx.Convey("TxAddDelay.", func(ctx convey.C) {
ctx.So(err, convey.ShouldNotBeNil)
})
})
}

View File

@@ -0,0 +1,90 @@
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
_upStateStaffSQL = "UPDATE archive_staff SET state =? where id=?"
_inStaffSQL = "INSERT into archive_staff(aid,mid,staff_mid,staff_title,staff_title_id,state) VALUES (?,?,?,?,?,?) ON DUPLICATE KEY UPDATE staff_title=?,staff_title_id=?,state=?"
_staffsSQL = "SELECT id,aid,mid,staff_mid,staff_title,staff_title_id,state FROM archive_staff WHERE aid=? AND state=?"
_staffByIDSQL = "SELECT id,aid,mid,staff_mid,staff_title,staff_title_id,state FROM archive_staff WHERE id=?"
_staffByAIdMIDSQL = "SELECT id,aid,mid,staff_mid,staff_title,staff_title_id,state FROM archive_staff WHERE aid=? AND staff_mid=? limit 1"
)
// TxAddStaff tx.
func (d *Dao) TxAddStaff(tx *sql.Tx, param *archive.Staff) (id int64, err error) {
res, err := tx.Exec(_inStaffSQL, param.AID, param.MID, param.StaffMID, param.StaffTitle, param.StaffTitleID, param.State, param.StaffTitle, param.StaffTitleID, param.State)
if err != nil {
log.Error("d.TxAddStaff.Exec() error(%v)", err)
return
}
id, err = res.LastInsertId()
return
}
// TxUpStaffState tx .
func (d *Dao) TxUpStaffState(tx *sql.Tx, state int8, id int64) (rows int64, err error) {
res, err := tx.Exec(_upStateStaffSQL, state, id)
if err != nil {
log.Error("d.TxUpStaffState.Exec() error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// Staffs get .
func (d *Dao) Staffs(c context.Context, AID int64) (fs []*archive.Staff, err error) {
rows, err := d.db.Query(c, _staffsSQL, AID, archive.STATEON)
if err != nil {
log.Error("d.db.Staffs aid(%d) error(%v)", AID, err)
return
}
defer rows.Close()
for rows.Next() {
f := &archive.Staff{}
if err = rows.Scan(&f.ID, &f.AID, &f.MID, &f.StaffMID, &f.StaffTitle, &f.StaffTitleID, &f.State); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
fs = append(fs, f)
}
return
}
// Staff get .
func (d *Dao) Staff(c context.Context, ID int64) (s *archive.Staff, err error) {
row := d.db.QueryRow(c, _staffByIDSQL, ID)
s = &archive.Staff{}
if err = row.Scan(&s.ID, &s.AID, &s.MID, &s.StaffMID, &s.StaffTitle, &s.StaffTitleID, &s.State); err != nil {
if err == sql.ErrNoRows {
s = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}
// StaffByAidAndMid get .
func (d *Dao) StaffByAidAndMid(c context.Context, AID, StaffMid int64) (s *archive.Staff, err error) {
row := d.db.QueryRow(c, _staffByAIdMIDSQL, AID, StaffMid)
s = &archive.Staff{}
if err = row.Scan(&s.ID, &s.AID, &s.MID, &s.StaffMID, &s.StaffTitle, &s.StaffTitleID, &s.State); err != nil {
if err == sql.ErrNoRows {
s = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
return
}

View File

@@ -0,0 +1,159 @@
package archive
import (
"context"
bsql "database/sql"
"fmt"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
"go-common/library/xstr"
)
const (
_inApplySQL = `INSERT INTO archive_staff_apply (type,as_id,apply_aid,apply_up_mid,apply_staff_mid,apply_title,apply_title_id,state,deal_state) VALUES (?,?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE type=?,apply_title=?,apply_title_id=?,state=?,deal_state=?,as_id=?`
_selApplySQL = `SELECT sa.id,sa.type,sa.as_id,sa.apply_aid,sa.apply_up_mid,sa.apply_staff_mid,sa.apply_title,sa.apply_title_id,sa.state,sa.deal_state,s.state as staff_state,s.staff_title FROM archive_staff_apply sa LEFT JOIN archive_staff s on s.id=sa.as_id where sa.id=?`
_selApplysSQL = `SELECT sa.id,sa.type,sa.as_id,sa.apply_aid,sa.apply_up_mid,sa.apply_staff_mid,sa.apply_title,sa.apply_title_id,sa.state,sa.deal_state,s.state as staff_state,s.staff_title FROM archive_staff_apply sa LEFT JOIN archive_staff s on s.id=sa.as_id where sa.id IN(%s)`
_selApplysByAIDSQL = `SELECT sa.id,sa.type,sa.as_id,sa.apply_aid,sa.apply_up_mid,sa.apply_staff_mid,sa.apply_title,sa.apply_title_id,sa.state,sa.deal_state,s.state as staff_state,s.staff_title FROM archive_staff_apply sa LEFT JOIN archive_staff s on s.id=sa.as_id where sa.apply_aid =?`
_selApplysByAIDSANDMIDSQL = `SELECT sa.id,sa.type,sa.as_id,sa.apply_aid,sa.apply_up_mid,sa.apply_staff_mid,sa.apply_title,sa.apply_title_id,sa.state,sa.deal_state,s.state as staff_state,s.staff_title FROM archive_staff_apply sa LEFT JOIN archive_staff s on s.id=sa.as_id where sa.apply_aid IN(%s) AND sa.apply_staff_mid=%d`
_selApplysByMIDSTAFFSQL = `SELECT sa.id,sa.type,sa.as_id,sa.apply_aid,sa.apply_up_mid,sa.apply_staff_mid,sa.apply_title,sa.apply_title_id,sa.state,sa.deal_state,s.state as staff_state,s.staff_title FROM archive_staff_apply sa LEFT JOIN archive_staff s on s.id=sa.as_id where sa.apply_up_mid=? AND sa.apply_staff_mid =?`
_midCountSQL = `select count(*) as count from archive_staff_apply where apply_staff_mid=?`
)
// Apply get archive Apply
func (d *Dao) Apply(c context.Context, ID int64) (p *archive.StaffApply, err error) {
row := d.rddb.QueryRow(c, _selApplySQL, ID)
p = &archive.StaffApply{}
var title bsql.NullString
var state bsql.NullInt64
if err = row.Scan(&p.ID, &p.Type, &p.ASID, &p.ApplyAID, &p.ApplyUpMID, &p.ApplyStaffMID, &p.ApplyTitle, &p.ApplyTitleID, &p.State, &p.DealState, &state, &title); err != nil {
if err == sql.ErrNoRows {
p = nil
err = nil
} else {
log.Error("row.Scan error(%v)", err)
}
return
}
p.StaffTitle = title.String
p.StaffState = int8(state.Int64)
return
}
// MidCount get
func (d *Dao) MidCount(c context.Context, ID int64) (count int64, err error) {
row := d.rddb.QueryRow(c, _midCountSQL, ID)
if err = row.Scan(&count); err != nil {
if err != sql.ErrNoRows {
log.Error("row.Scan error(%v)", err)
return
}
err = nil
}
return
}
// Applys get .
func (d *Dao) Applys(c context.Context, ids []int64) (as []*archive.StaffApply, err error) {
rows, err := d.db.Query(c, fmt.Sprintf(_selApplysSQL, xstr.JoinInts(ids)))
if err != nil {
log.Error("d.db.Applys ids(%+v) error(%v)", ids, err)
return
}
defer rows.Close()
for rows.Next() {
var title bsql.NullString
var state bsql.NullInt64
s := &archive.StaffApply{}
if err = rows.Scan(&s.ID, &s.Type, &s.ASID, &s.ApplyAID, &s.ApplyUpMID, &s.ApplyStaffMID, &s.ApplyTitle, &s.ApplyTitleID, &s.State, &s.DealState, &state, &title); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
s.StaffTitle = title.String
s.StaffState = int8(state.Int64)
as = append(as, s)
}
return
}
// FilterApplys get .
func (d *Dao) FilterApplys(c context.Context, aids []int64, mid int64) (as []*archive.StaffApply, err error) {
rows, err := d.db.Query(c, fmt.Sprintf(_selApplysByAIDSANDMIDSQL, xstr.JoinInts(aids), mid))
if err != nil {
log.Error("d.db.FilterApplys(%v,%d) error(%v)", aids, mid, err)
return
}
defer rows.Close()
for rows.Next() {
var title bsql.NullString
var state bsql.NullInt64
s := &archive.StaffApply{}
if err = rows.Scan(&s.ID, &s.Type, &s.ASID, &s.ApplyAID, &s.ApplyUpMID, &s.ApplyStaffMID, &s.ApplyTitle, &s.ApplyTitleID, &s.State, &s.DealState, &state, &title); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
s.StaffTitle = title.String
s.StaffState = int8(state.Int64)
as = append(as, s)
}
return
}
// ApplysByAID get .
func (d *Dao) ApplysByAID(c context.Context, aid int64) (as []*archive.StaffApply, err error) {
rows, err := d.db.Query(c, _selApplysByAIDSQL, aid)
if err != nil {
log.Error("d.db.ApplysByAID aid(%d) error(%v)", aid, err)
return
}
defer rows.Close()
for rows.Next() {
var title bsql.NullString
var state bsql.NullInt64
s := &archive.StaffApply{}
if err = rows.Scan(&s.ID, &s.Type, &s.ASID, &s.ApplyAID, &s.ApplyUpMID, &s.ApplyStaffMID, &s.ApplyTitle, &s.ApplyTitleID, &s.State, &s.DealState, &state, &title); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
s.StaffTitle = title.String
s.StaffState = int8(state.Int64)
as = append(as, s)
}
return
}
// ApplysByMIDAndStaff get .
func (d *Dao) ApplysByMIDAndStaff(c context.Context, upMID, staffMID int64) (as []*archive.StaffApply, err error) {
rows, err := d.db.Query(c, _selApplysByMIDSTAFFSQL, upMID, staffMID)
if err != nil {
log.Error("d.db.ApplysByAID upMID(%d) staffMID(%d) error(%v)", upMID, staffMID, err)
return
}
defer rows.Close()
for rows.Next() {
var title bsql.NullString
var state bsql.NullInt64
s := &archive.StaffApply{}
if err = rows.Scan(&s.ID, &s.Type, &s.ASID, &s.ApplyAID, &s.ApplyUpMID, &s.ApplyStaffMID, &s.ApplyTitle, &s.ApplyTitleID, &s.State, &s.DealState, &state, &title); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
s.StaffTitle = title.String
s.StaffState = int8(state.Int64)
as = append(as, s)
}
return
}
// TxAddApply tx.
func (d *Dao) TxAddApply(tx *sql.Tx, param *archive.ApplyParam) (id int64, err error) {
res, err := tx.Exec(_inApplySQL, param.Type, param.ASID, param.ApplyAID, param.ApplyUpMID, param.ApplyStaffMID, param.ApplyTitle, param.ApplyTitleID, param.State, param.DealState, param.Type, param.ApplyTitle, param.ApplyTitleID, param.State, param.DealState, param.ASID)
if err != nil {
log.Error("d.TxAddApply.Exec() error(%v)", err)
return
}
id, err = res.LastInsertId()
return
}

View File

@@ -0,0 +1,70 @@
package archive
import (
"context"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/smartystreets/goconvey/convey"
)
func TestStaffMid(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("MidCount", t, func(ctx convey.C) {
count, err := d.MidCount(c, 2880441)
spew.Dump(count)
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestApply(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("Apply", t, func(ctx convey.C) {
data, err := d.Apply(c, 1)
if err == nil {
spew.Dump(data)
}
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestApplys(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("Applys", t, func(ctx convey.C) {
data, err := d.Applys(c, []int64{1, 11})
if err == nil {
spew.Dump(data)
}
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestFilterApplys(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("FilterApplys", t, func(ctx convey.C) {
data, err := d.FilterApplys(c, []int64{23213, 4052032}, 4052032)
if err == nil {
spew.Dump(data)
}
if err != nil {
spew.Dump(err)
}
ctx.Convey("Then err should be nil.fs should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,32 @@
package archive
import (
"context"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/log"
)
const (
_tpsSQL = "SELECT id,pid,name,description FROM archive_type"
)
// TypeMapping is second types opposite first types.
func (d *Dao) TypeMapping(c context.Context) (tmap map[int16]*archive.Type, err error) {
rows, err := d.rddb.Query(c, _tpsSQL)
if err != nil {
log.Error("d.tpsStmt.Query error(%v)", err)
return
}
defer rows.Close()
tmap = make(map[int16]*archive.Type)
for rows.Next() {
t := &archive.Type{}
if err = rows.Scan(&t.ID, &t.PID, &t.Name, &t.Desc); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
tmap[t.ID] = t
}
return
}

View File

@@ -0,0 +1,20 @@
package archive
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestArchiveTypeMapping(t *testing.T) {
var (
c = context.Background()
)
convey.Convey("TypeMapping", t, func(ctx convey.C) {
_, err := d.TypeMapping(c)
ctx.Convey("Then err should be nil.tmap should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,104 @@
package archive
import (
"fmt"
"strings"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/database/sql"
"go-common/library/log"
)
const (
// insert
_inVideoSQL = `INSERT INTO archive_video (id,aid,eptitle,description,filename,src_type,cid,index_order,attribute,duration,filesize,resolutions,playurl,failinfo,xcode_state,status)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
_inAuditsSQL = "INSERT INTO archive_video_audit (vid,aid,tid,oname,reason) VALUES %s"
// update
_upVideoSQL = `UPDATE archive_video SET eptitle=?,description=?,index_order=?,status=? WHERE id=?`
_upVdoStatusSQL = "UPDATE archive_video SET status=? WHERE aid=? AND filename=?"
_upVdoXcodeSQL = "UPDATE archive_video SET xcode_state=? WHERE aid=? AND filename=?"
_upVdoAttrSQL = "UPDATE archive_video SET attribute=? WHERE aid=? AND filename=?"
_upVdoCidSQL = "UPDATE archive_video SET cid=? WHERE aid=? AND filename=?"
)
// TxAddVideo insert archive video.
func (d *Dao) TxAddVideo(tx *sql.Tx, v *archive.Video) (id int64, err error) {
res, err := tx.Exec(_inVideoSQL, v.ID, v.Aid, v.Title, v.Desc, v.Filename, v.SrcType, v.Cid, v.Index, v.Attribute, v.Duration, v.Filesize, v.Resolutions, v.Playurl, v.FailCode, v.XcodeState, v.Status)
if err != nil {
log.Error("d.inVideo.Exec error(%v)", err)
return
}
id, err = res.LastInsertId()
return
}
// TxUpVideo update video.
func (d *Dao) TxUpVideo(tx *sql.Tx, v *archive.Video) (rows int64, err error) {
res, err := tx.Exec(_upVideoSQL, v.Title, v.Desc, v.Index, v.Status, v.ID)
if err != nil {
log.Error("d.upVideo.Exec(%v) error(%v)", v, err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVideoStatus update video status.
func (d *Dao) TxUpVideoStatus(tx *sql.Tx, aid int64, filename string, status int16) (rows int64, err error) {
res, err := tx.Exec(_upVdoStatusSQL, status, aid, filename)
if err != nil {
log.Error("d.upVideoStatus.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVideoXcode update video fail_code.
func (d *Dao) TxUpVideoXcode(tx *sql.Tx, aid int64, filename string, xCodeState int8) (rows int64, err error) {
res, err := tx.Exec(_upVdoXcodeSQL, xCodeState, aid, filename)
if err != nil {
log.Error("d.upVdoXcode.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVideoAttr update video attribute.
func (d *Dao) TxUpVideoAttr(tx *sql.Tx, aid int64, filename string, attribute int32) (rows int64, err error) {
res, err := tx.Exec(_upVdoAttrSQL, attribute, aid, filename)
if err != nil {
log.Error("d.upVideoAttr.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxUpVideoCid update video attribute.
func (d *Dao) TxUpVideoCid(tx *sql.Tx, aid int64, filename string, cid int64) (rows int64, err error) {
res, err := tx.Exec(_upVdoCidSQL, cid, aid, filename)
if err != nil {
log.Error("d.upVideoCid.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}
// TxAddAudit insert video audit.
func (d *Dao) TxAddAudit(tx *sql.Tx, vs []*archive.Video) (rows int64, err error) {
var args = make([]string, 0, len(vs))
for _, v := range vs {
args = append(args, fmt.Sprintf(`(%d,%d,%d,'%s','%s')`, v.ID, v.Aid, 0, "videoup-service", ""))
}
res, err := tx.Exec(fmt.Sprintf(_inAuditsSQL, strings.Join(args, ",")))
if err != nil {
log.Error("d.inAudit.Exec error(%v)", err)
return
}
rows, err = res.RowsAffected()
return
}

View File

@@ -0,0 +1,142 @@
package archive
import (
"context"
"testing"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/service/main/videoup/model/archive"
"math/rand"
"time"
)
func TestDao_TxAddVideo(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
v = &archive.Video{
ID: 123,
Aid: 2333,
Title: "UT测试",
}
)
rand.Seed(time.Now().Unix())
v.ID = int64(rand.Intn(999999999) + 1000000000)
v.Aid = int64(rand.Intn(999999999) + 1000000000)
Convey("TxAddVideo", t, func(ctx C) {
_, err := d.TxAddVideo(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideo(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
v = &archive.Video{
ID: 123,
Aid: 2333,
Title: "UT测试",
}
)
Convey("TxUpVideo", t, func(ctx C) {
_, err := d.TxUpVideo(tx, v)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoStatus(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoStatus", t, func(ctx C) {
_, err := d.TxUpVideoStatus(tx, 2333, "sadasdadsds", 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoXcode(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoXcode", t, func(ctx C) {
_, err := d.TxUpVideoXcode(tx, 2333, "sadasdadsds", 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoAttr(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoAttr", t, func(ctx C) {
_, err := d.TxUpVideoAttr(tx, 2333, "sadasdadsds", 0)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxUpVideoCid(t *testing.T) {
var (
c = context.Background()
tx, _ = d.BeginTran(c)
)
Convey("TxUpVideoCid", t, func(ctx C) {
_, err := d.TxUpVideoCid(tx, 2333, "sadasdadsds", 1213)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}
func TestDao_TxAddAudit(t *testing.T) {
rand.Seed(time.Now().Unix())
vid := int64(rand.Intn(999999) + 1000000000)
var (
c = context.Background()
tx, _ = d.BeginTran(c)
vs = []*archive.Video{{
ID: vid,
Aid: 2333,
Title: "UT测试",
}}
)
Convey("TxAddAudit", t, func(ctx C) {
_, err := d.TxAddAudit(tx, vs)
if err != nil {
tx.Rollback()
} else {
tx.Commit()
}
So(err, ShouldBeNil)
})
}

View File

@@ -0,0 +1,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/videoup/dao/bgm",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,56 @@
package bgm
import (
"context"
"net/url"
"strconv"
"go-common/app/service/main/videoup/conf"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const (
_bgmBindURI = "/x/internal/v1/audio/song_video_relation/add"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
httpW *bm.Client
bgmBindURL string
}
// New new a dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
httpW: bm.NewClient(c.HTTPClient.Write),
bgmBindURL: c.Host.APICO + _bgmBindURI,
}
return d
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return
}
// Bind aid,sid,cid bind in one
func (d *Dao) Bind(c context.Context, aid, sid, cid int64) (err error) {
params := url.Values{}
params.Set("aid", strconv.FormatInt(aid, 10))
params.Set("sid", strconv.FormatInt(sid, 10))
params.Set("cid", strconv.FormatInt(cid, 10))
var res struct {
Code int `json:"code"`
}
if err = d.httpW.Post(c, d.bgmBindURL, "", params, &res); err != nil {
log.Error("d.httpW.Post(%s) error(%v)", d.bgmBindURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("url(%s) code(%d)", d.bgmBindURL+"?"+params.Encode(), res.Code)
}
return
}

View File

@@ -0,0 +1,48 @@
package bgm
import (
"context"
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestBgmPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,53 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"redis_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"redis.go",
],
importpath = "go-common/app/service/main/videoup/dao/databus",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/message:go_default_library",
"//library/cache/redis:go_default_library",
"//library/log: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,40 @@
package databus
import (
"context"
"go-common/app/service/main/videoup/conf"
"go-common/library/cache/redis"
"go-common/library/log"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
// redis
redis *redis.Pool
}
//New .
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
redis: redis.NewPool(c.Redis.Track.Config),
}
return d
}
// Ping ping redis.
func (d *Dao) Ping(c context.Context) (err error) {
conn := d.redis.Get(c)
if _, err = conn.Do("SET", "ping", "pong"); err != nil {
log.Error("conn.Do(SET) error(%v)", err)
}
conn.Close()
return
}
//Close .
func (d *Dao) Close() {
d.redis.Close()
}

View File

@@ -0,0 +1,33 @@
package databus
import (
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,86 @@
package databus
import (
"context"
"encoding/json"
"fmt"
"go-common/app/service/main/videoup/model/message"
"go-common/library/cache/redis"
"go-common/library/log"
)
const (
_prefixMsgInfo = "videoup_service_msg"
_preLock = "lock_"
)
func lockKey(key string) string {
return fmt.Sprintf("%s%s", _preLock, key)
}
// PopMsgCache get databus message from redis
func (d *Dao) PopMsgCache(c context.Context) (msg *message.Videoup, err error) {
var (
conn = d.redis.Get(c)
bs []byte
)
defer conn.Close()
if bs, err = redis.Bytes(conn.Do("LPOP", _prefixMsgInfo)); err != nil {
if err == redis.ErrNil {
err = nil
} else {
log.Error("conn.Do(LPOP, %s) error(%v)", _prefixMsgInfo, err)
}
return
}
msg = &message.Videoup{}
if err = json.Unmarshal(bs, msg); err != nil {
log.Error("json.Unmarshal error(%v)", err)
}
return
}
// PushMsgCache add message into redis.
func (d *Dao) PushMsgCache(c context.Context, msg *message.Videoup) (err error) {
var (
bs []byte
conn = d.redis.Get(c)
)
defer conn.Close()
if bs, err = json.Marshal(msg); err != nil {
log.Error("json.Marshal(%s) error(%v)", bs, err)
return
}
if _, err = conn.Do("RPUSH", _prefixMsgInfo, bs); err != nil {
log.Error("conn.Do(RPUSH, %s) error(%v)", bs, err)
}
return
}
//Lock .
func (d *Dao) Lock(ctx context.Context, key string, ttl int) (gotLock bool, err error) {
var lockValue = "1"
conn := d.redis.Get(ctx)
defer conn.Close()
realKey := lockKey(key)
var res interface{}
//ttl 毫秒(PX) NX 其实就是 SetNX功能
res, err = conn.Do("SET", realKey, lockValue, "PX", ttl, "NX")
if err != nil {
log.Error("redis_lock failed:%s:%s", realKey, err.Error())
return
}
if res != nil {
gotLock = true
}
return
}
//UnLock .
func (d *Dao) UnLock(ctx context.Context, key string) (err error) {
realKey := lockKey(key)
conn := d.redis.Get(ctx)
defer conn.Close()
_, err = conn.Do("DEL", realKey)
return
}

View File

@@ -0,0 +1,36 @@
package databus
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestDatabusLock(t *testing.T) {
var (
c = context.TODO()
key = ""
ttl = int(0)
)
convey.Convey("Lock", t, func(ctx convey.C) {
gotLock, err := d.Lock(c, key, ttl)
ctx.Convey("Then err should be nil.gotLock should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
ctx.So(gotLock, convey.ShouldNotBeNil)
})
})
}
func TestDatabusUnLock(t *testing.T) {
var (
c = context.TODO()
key = ""
)
convey.Convey("UnLock", t, func(ctx convey.C) {
err := d.UnLock(c, key)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/service/main/videoup/conf:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"redis.go",
],
importpath = "go-common/app/service/main/videoup/dao/dede",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/dede:go_default_library",
"//library/cache/redis:go_default_library",
"//library/log: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,22 @@
package dede
import (
"go-common/app/service/main/videoup/conf"
"go-common/library/cache/redis"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
// redis
redis *redis.Pool
}
// New new
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
redis: redis.NewPool(c.Redis.Track.Config),
}
return d
}

View File

@@ -0,0 +1,33 @@
package dede
import (
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,53 @@
package dede
import (
"context"
"encoding/json"
"go-common/app/service/main/videoup/model/dede"
"go-common/library/cache/redis"
"go-common/library/log"
)
const (
_prefixPadInfo = "padinfo"
)
// PopPadInfoCache get padinfo from redis
func (d *Dao) PopPadInfoCache(c context.Context) (pad *dede.PadInfo, err error) {
var (
conn = d.redis.Get(c)
bs []byte
)
defer conn.Close()
if bs, err = redis.Bytes(conn.Do("LPOP", _prefixPadInfo)); err != nil {
if err == redis.ErrNil {
err = nil
} else {
log.Error("conn.Do(LPOP, %s) error(%v)", _prefixPadInfo, err)
}
return
}
pad = &dede.PadInfo{}
if err = json.Unmarshal(bs, pad); err != nil {
log.Error("s.padproc json.Unmarshal error(%v)", err)
}
return
}
// PushPadCache add padinfo into redis.
func (d *Dao) PushPadCache(c context.Context, pad *dede.PadInfo) (err error) {
var (
bs []byte
conn = d.redis.Get(c)
)
defer conn.Close()
if bs, err = json.Marshal(pad); err != nil {
log.Error("json.Marshal(%s) error(%v)", bs, err)
return
}
if _, err = conn.Do("RPUSH", _prefixPadInfo, bs); err != nil {
log.Error("conn.Do(RPUSH, %s) error(%v)", bs, err)
}
return
}

View File

@@ -0,0 +1,59 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"manager_test.go",
"reason_test.go",
"up_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"manager.go",
"reason.go",
"search.go",
"up.go",
],
importpath = "go-common/app/service/main/videoup/dao/manager",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//library/database/sql:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,48 @@
package manager
import (
"context"
"go-common/app/service/main/videoup/conf"
"go-common/library/database/sql"
bm "go-common/library/net/http/blademaster"
)
const (
_searchUpdateURL = "/x/admin/search/upsert"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
managerDB *sql.DB
// select stmt
upsStmt *sql.Stmt
httpW *bm.Client
searchUpdateURL string
}
// New fn
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
managerDB: sql.NewMySQL(c.DB.Manager),
httpW: bm.NewClient(c.HTTPClient.Write),
searchUpdateURL: c.Host.Manager + _searchUpdateURL,
}
// select stmt
d.upsStmt = d.managerDB.Prepared(_upsSQL)
return d
}
// Close fn
func (d *Dao) Close() {
if d.managerDB != nil {
d.managerDB.Close()
}
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return d.managerDB.Ping(c)
}

View File

@@ -0,0 +1,33 @@
package manager
import (
"flag"
"os"
"testing"
"go-common/app/service/main/videoup/conf"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,38 @@
package manager
import (
"context"
"go-common/library/log"
)
const (
_upsSQL = "SELECT mid,type FROM ups"
)
// Uppers get uppers by type.
func (d *Dao) Uppers(c context.Context) (um map[int8]map[int64]struct{}, err error) {
rows, err := d.upsStmt.Query(c)
if err != nil {
log.Error("d.upsStmt.Query error(%v)", err)
return
}
defer rows.Close()
um = map[int8]map[int64]struct{}{}
for rows.Next() {
var (
mid int64
tp int8
)
if err = rows.Scan(&mid, &tp); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
if mm, ok := um[tp]; ok {
mm[mid] = struct{}{}
} else {
um[tp] = map[int64]struct{}{mid: struct{}{}}
}
}
return
}

View File

@@ -0,0 +1,20 @@
package manager
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUppers(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Uppers", t, func(ctx convey.C) {
_, err := d.Uppers(c)
ctx.Convey("Then err should be nil.um should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,30 @@
package manager
import (
"context"
xsql "database/sql"
"go-common/library/log"
)
const (
_reasonSQL = "SELECT reason.tag_id as tag_id from reason_log left join reason on reason_log.reason_id=reason.id where reason_log.type=1 AND reason_log.oid=? order by reason_log.id desc limit 1;"
)
// ArcReason get a archive reason tag
func (d *Dao) ArcReason(c context.Context, aid int64) (tagID int64, err error) {
var (
row = d.managerDB.QueryRow(c, _reasonSQL, aid)
tagIDI xsql.NullInt64
)
if err := row.Scan(&tagIDI); err != nil {
if err == xsql.ErrNoRows {
err = nil
} else {
log.Error("ArcReason row.Scan error(%v)", err)
}
}
log.Info("ArcReason retrun(%v)", tagIDI)
tagID = tagIDI.Int64
return
}

View File

@@ -0,0 +1,21 @@
package manager
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerArcReason(t *testing.T) {
var (
c = context.TODO()
aid = int64(2333)
)
convey.Convey("ArcReason", t, func(ctx convey.C) {
_, err := d.ArcReason(c, aid)
ctx.Convey("Then err should be nil.tagID should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,29 @@
package manager
import (
"context"
"go-common/library/log"
"net/url"
"strconv"
)
// searchUpdate .
func (d *Dao) SearchUpdate(c context.Context, business, data string, aid int64) (err error) {
params := url.Values{}
params.Set("business", business)
params.Set("data", data)
params.Set("aid", strconv.FormatInt(aid, 10))
var res struct {
Code int `json:"code"`
}
if err = d.httpW.Post(c, d.searchUpdateURL, "", params, &res); err != nil {
log.Error("searchUpdate d.httpW.Post(%s) error(%v)", d.searchUpdateURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("searchUpdate url(%s) code(%d)", d.searchUpdateURL+"?"+params.Encode(), res.Code)
}
log.Info("aid (%d) SearchUpdate url(%s) code(%d)", aid, d.searchUpdateURL+"?"+params.Encode(), res.Code)
return
}

View File

@@ -0,0 +1,34 @@
package manager
import (
"context"
"database/sql"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/log"
)
const (
_upsWithGroup = "SELECT ups.id,mid,up_group.id as group_id ,up_group.short_tag as group_tag,up_group.name as group_name,ups.note,ups.ctime FROM ups INNER JOIN up_group on ups.type=up_group.id"
)
// UpSpecial load all ups with group info
func (d *Dao) UpSpecial(c context.Context) (ups []*archive.Up, err error) {
rows, err := d.managerDB.Query(c, _upsWithGroup)
if err != nil {
log.Error("d.tpsStmt.Query error(%v)", err)
return
}
defer rows.Close()
var note sql.NullString
for rows.Next() {
up := &archive.Up{}
if err = rows.Scan(&up.ID, &up.Mid, &up.GroupID, &up.GroupTag, &up.GroupName, &note, &up.CTime); err != nil {
log.Error("rows.Scan error(%v)", err)
return
}
up.Note = note.String
ups = append(ups, up)
}
return
}

View File

@@ -0,0 +1,20 @@
package manager
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
)
func TestManagerUpSpecial(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("UpSpecial", t, func(ctx convey.C) {
_, err := d.UpSpecial(c)
ctx.Convey("Then err should be nil.ups should not be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = ["//app/service/main/videoup/conf:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/videoup/dao/monitor",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,42 @@
package monitor
import (
"context"
"fmt"
"net/url"
"go-common/app/service/main/videoup/conf"
"go-common/library/log"
xhttp "go-common/library/net/http/blademaster"
)
// Dao is message dao.
type Dao struct {
c *conf.Config
client *xhttp.Client
uri string
}
// New new a message dao.
func New(c *conf.Config) (d *Dao) {
//http://ops-mng.bilibili.co/api/sendsms&message=test&token=
d = &Dao{
c: c,
client: xhttp.NewClient(c.HTTPClient.Read),
uri: c.Host.Monitor + "/api/sendsms",
}
return
}
// Send send message to upper.
func (d *Dao) Send(c context.Context, msg string) (err error) {
params := url.Values{}
params.Set("phone", d.c.Monitor.Tels)
params.Set("message", msg)
params.Set("token", "f5a658b2-5926-4b71-96c3-7d3777b7d256")
if err = d.client.Get(c, d.uri, "", params, nil); err != nil {
log.Info("sms error(%v)", err)
fmt.Printf("sms error(%v)", err)
}
return
}

View File

@@ -0,0 +1,33 @@
package monitor
import (
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}

View File

@@ -0,0 +1,55 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"dao.go",
"msg.go",
],
importpath = "go-common/app/service/main/videoup/dao/msg",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//library/ecode:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/xstr: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"],
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"msg_test.go",
],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
"//vendor/gopkg.in/h2non/gock.v1:go_default_library",
],
)

View File

@@ -0,0 +1,28 @@
package msg
import (
"go-common/app/service/main/videoup/conf"
bm "go-common/library/net/http/blademaster"
)
const (
_msgURL = "/api/notify/send.user.notify.do"
)
// Dao .
type Dao struct {
c *conf.Config
client *bm.Client
msgURL string
}
// New new a Dao and return.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
// http client
client: bm.NewClient(c.HTTPClient.Read),
msgURL: c.Host.MSG + _msgURL,
}
return
}

View File

@@ -0,0 +1,43 @@
package msg
import (
"flag"
"os"
"strings"
"testing"
"go-common/app/service/main/videoup/conf"
"gopkg.in/h2non/gock.v1"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func httpMock(method, url string) *gock.Request {
r := gock.New(url)
r.Method = strings.ToUpper(method)
return r
}

View File

@@ -0,0 +1,58 @@
package msg
import (
"context"
"net/url"
"go-common/library/ecode"
"go-common/library/xstr"
"github.com/pkg/errors"
)
// MutliSendSysMsg Mutli send sys msg.
func (d *Dao) MutliSendSysMsg(c context.Context, allUids []int64, mc, title string, context string, ip string) (err error) {
var times int
ulen := len(allUids)
if ulen%100 == 0 {
times = ulen / 100
} else {
times = ulen/100 + 1
}
var uids []int64
for i := 0; i < times; i++ {
if i == times-1 {
uids = allUids[i*100:]
} else {
uids = allUids[i*100 : (i+1)*100]
}
if err = d.SendSysMsg(c, uids, mc, title, context, ip); err != nil {
continue
}
}
return
}
// SendSysMsg send sys msg.
func (d *Dao) SendSysMsg(c context.Context, uids []int64, mc, title string, context string, ip string) (err error) {
params := url.Values{}
params.Set("mc", mc)
params.Set("title", title)
params.Set("data_type", "4")
params.Set("context", context)
params.Set("mid_list", xstr.JoinInts(uids))
var res struct {
Code int `json:"code"`
Data *struct {
Status int8 `json:"status"`
Remark string `json:"remark"`
} `json:"data"`
}
if err = d.client.Post(c, d.msgURL, ip, params, &res); err != nil {
return
}
if res.Code != 0 {
err = errors.Wrapf(ecode.Int(res.Code), "SendSysMsg d.client.Post(%s,%d)", d.msgURL+"?"+params.Encode(), res.Code)
}
return
}

View File

@@ -0,0 +1,52 @@
package msg
import (
"context"
"testing"
"github.com/smartystreets/goconvey/convey"
"gopkg.in/h2non/gock.v1"
)
func TestMsgMutliSendSysMsg(t *testing.T) {
convey.Convey("MutliSendSysMsg", t, func(ctx convey.C) {
var (
c = context.Background()
allUids = []int64{}
mc = ""
title = ""
context = ""
ip = ""
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.msgURL).Reply(200).JSON(`{"code":0}`)
err := d.MutliSendSysMsg(c, allUids, mc, title, context, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}
func TestMsgSendSysMsg(t *testing.T) {
convey.Convey("SendSysMsg", t, func(ctx convey.C) {
var (
c = context.Background()
uids = []int64{2}
mc = "116_3_3"
title = "11"
content = "111"
ip = "111.111.111.111"
)
ctx.Convey("When everything gose positive", func(ctx convey.C) {
defer gock.OffAll()
httpMock("POST", d.msgURL).Reply(200).JSON(`{"code":0}`)
err := d.SendSysMsg(c, uids, mc, title, content, ip)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
})
}

View File

@@ -0,0 +1,47 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/davecgh/go-spew/spew:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/videoup/dao/relation",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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 relation
import (
"context"
"net/url"
"strconv"
"go-common/app/service/main/videoup/conf"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const (
_add_black = "/x/internal/relation/black/add"
_get_relation = "/x/internal/relation"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
httpW *bm.Client
addBlackURL string
getRelationURL string
}
// New new a dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
httpW: bm.NewClient(c.HTTPClient.Write),
addBlackURL: c.Host.APICO + _add_black,
getRelationURL: c.Host.APICO + _get_relation,
}
return d
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return
}
//拉黑 http://info.bilibili.co/pages/viewpage.action?pageId=1742202#id-%E5%85%B3%E7%B3%BB%E6%9C%8D%E5%8A%A1%E5%86%85%E7%BD%91%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3-%E8%8E%B7%E5%8F%96%E9%BB%91%E5%90%8D%E5%8D%95%E5%88%97%E8%A1%A8
//网关层 两者关系 http://info.bilibili.co/pages/viewpage.action?pageId=1742202#id-%E5%85%B3%E7%B3%BB%E6%9C%8D%E5%8A%A1%E5%86%85%E7%BD%91%E6%8E%A5%E5%8F%A3%E6%96%87%E6%A1%A3-%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%E4%B8%8E%E5%85%B6%E4%BB%96%E7%94%A8%E6%88%B7%E5%85%B3%E7%B3%BB
// Bind aid,sid,cid bind in one
func (d *Dao) AddBalck(c context.Context, mid, fid, aid int64) (err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("fid", strconv.FormatInt(fid, 10))
params.Set("src", strconv.Itoa(221))
var res struct {
Code int `json:"code"`
}
if err = d.httpW.Post(c, d.addBlackURL, "", params, &res); err != nil {
log.Error("d.httpW.Post(%s) error(%v)", d.addBlackURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("url(%s) code(%d)", d.addBlackURL+"?"+params.Encode(), res.Code)
}
log.Info("aid(%d) AddBalck mid(%d) url(%s) code(%d)", aid, mid, d.addBlackURL+"?"+params.Encode(), res.Code)
return
}
// Relation aid,sid,cid bind in one
func (d *Dao) Relation(c context.Context, mid, fid, aid int64) (attribute int64, err error) {
params := url.Values{}
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("fid", strconv.FormatInt(fid, 10))
var res struct {
Code int `json:"code"`
Data struct {
MID int64 `json:"mid"`
//大于等于128表示拉黑
Attribute int64 `json:"attribute"`
Mtime int64 `json:"mtime"`
}
}
if err = d.httpW.Get(c, d.getRelationURL, "", params, &res); err != nil {
log.Error("d.httpW.Get(%s) error(%v)", d.getRelationURL+"?"+params.Encode(), err)
return
}
if res.Code != 0 {
log.Error("url(%s) code(%d)", d.getRelationURL+"?"+params.Encode(), res.Code)
}
attribute = res.Data.Attribute
log.Info("aid(%d) Relation mid(%d) url(%s) code(%d) data(%+v)", aid, mid, d.getRelationURL+"?"+params.Encode(), res.Code, res)
return
}

View File

@@ -0,0 +1,79 @@
package relation
import (
"context"
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
"github.com/davecgh/go-spew/spew"
"github.com/smartystreets/goconvey/convey"
"path/filepath"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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 {
dir, _ := filepath.Abs("../../cmd/videoup-service.toml")
flag.Set("conf", dir)
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestRelationPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestRelation(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Relation", t, func(ctx convey.C) {
data, err := d.Relation(c, 27515314, 27515258, 1)
spew.Dump(data)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestAddBlack(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Relation", t, func(ctx convey.C) {
err := d.AddBalck(c, 27515260, 2089809, 1)
spew.Dump(err)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,46 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = ["dao_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = ["dao.go"],
importpath = "go-common/app/service/main/videoup/dao/ups",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster: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,68 @@
package ups
import (
"context"
"net/url"
"go-common/app/service/main/videoup/conf"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"strconv"
)
const (
_upSpecialURL = "/x/internal/uper/special"
)
// Dao is redis dao.
type Dao struct {
c *conf.Config
httpW *bm.Client
upSpecialURI string
}
// New new a dao.
func New(c *conf.Config) (d *Dao) {
d = &Dao{
c: c,
httpW: bm.NewClient(c.HTTPClient.Write),
upSpecialURI: c.Host.APICO + _upSpecialURL,
}
return d
}
// Ping ping cpdb
func (d *Dao) Ping(c context.Context) (err error) {
return
}
func (d *Dao) upSpecial(c context.Context, groupid string) (ups map[int64]int64, err error) {
params := url.Values{}
params.Set("group_id", groupid)
ups = make(map[int64]int64)
var res struct {
Code int `json:"code"`
Message string `json:"message"`
Data []struct {
Mid int64 `json:"mid"`
} `json:"data"`
}
if err = d.httpW.Get(c, d.upSpecialURI, "", params, &res); err != nil {
log.Error("upSpecial error(%v) | upSpecialURI(%s)", err, d.upSpecialURI)
return
}
log.Info("upSpecial url(%+v)|res(%+v)", d.upSpecialURI, res)
if res.Code != 0 {
log.Error("upSpecial api url(%s) res(%v);, code(%d)", d.upSpecialURI, res, res.Code)
return
}
for _, item := range res.Data {
ups[item.Mid] = item.Mid
}
return
}
// GrayCheckUps GrayCheckUps, type = 8
func (d *Dao) GrayCheckUps(c context.Context, gid int) (checkUps map[int64]int64, err error) {
return d.upSpecial(c, strconv.Itoa(gid))
}

View File

@@ -0,0 +1,72 @@
package ups
import (
"context"
"flag"
"go-common/app/service/main/videoup/conf"
"os"
"testing"
"github.com/smartystreets/goconvey/convey"
)
var (
d *Dao
)
func TestMain(m *testing.M) {
if os.Getenv("DEPLOY_ENV") != "" {
flag.Set("app_id", "main.archive.videoup-service")
flag.Set("conf_token", "4b62721602981eb3635dba3b0d866ac5")
flag.Set("tree_id", "2308")
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")
}
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
d = New(conf.Conf)
m.Run()
os.Exit(0)
}
func TestUpPing(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("Ping", t, func(ctx convey.C) {
err := d.Ping(c)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestGrayCheckUps(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("GrayCheckUps", t, func(ctx convey.C) {
_, err := d.GrayCheckUps(c, 1)
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}
func TestUpSpecial(t *testing.T) {
var (
c = context.TODO()
)
convey.Convey("upSpecial", t, func(ctx convey.C) {
_, err := d.upSpecial(c, "1")
ctx.Convey("Then err should be nil.", func(ctx convey.C) {
ctx.So(err, convey.ShouldBeNil)
})
})
}

View File

@@ -0,0 +1,53 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"flow.go",
"http.go",
"local.go",
"netsafe.go",
"pgc.go",
"porder.go",
"reco.go",
"report.go",
"staff.go",
"ugc.go",
"video.go",
],
importpath = "go-common/app/service/main/videoup/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/service/main/videoup/conf:go_default_library",
"//app/service/main/videoup/model/archive:go_default_library",
"//app/service/main/videoup/service:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/antispam:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
"//library/sync/errgroup:go_default_library",
"//library/xstr: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,450 @@
package http
import (
"encoding/json"
"io/ioutil"
"strconv"
"time"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/sync/errgroup"
"go-common/library/xstr"
)
func simpleArchive(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
modeStr := params.Get("mode")
// check params
mode, _ := strconv.Atoi(modeStr)
if mode <= 0 || mode > 2 {
mode = 0 // 0 novideo 1 open video 2 all video
}
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
av, err := vdpSvc.SimpleArchive(c, aid, mode)
if err != nil {
log.Error(" vdpSvc.SimpleArchive(%d) error(%v)", aid, err)
c.JSON(nil, err)
return
}
c.JSON(av, nil)
}
func simpleVideos(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
// check params
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
vs, err := vdpSvc.SimpleVideos(c, aid)
if err != nil {
log.Error(" vdpSvc.SimpleVideos(%d) error(%v)", aid, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(vs, nil)
}
// viewArchive get archive info.
func viewArchive(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
withPOIStr := params.Get("need_poi")
withVoteStr := params.Get("need_vote")
// check params
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
av, err := vdpSvc.Archive(c, aid)
if err != nil {
log.Error(" vdpSvc.Archive(%d) error(%v)", aid, err)
c.JSON(nil, ecode.RequestErr)
return
}
//详情页展示LBS
var poi *archive.PoiObj
eg, errCtx := errgroup.WithContext(c)
if withPOIStr == "1" {
eg.Go(func() (err error) {
poi, _ = vdpSvc.ArchivePOI(errCtx, aid)
return nil
})
}
var vote *archive.Vote
if withVoteStr == "1" {
eg.Go(func() (err error) {
vote, _ = vdpSvc.ArchiveVote(errCtx, aid)
return nil
})
}
eg.Wait()
if poi != nil {
av.Archive.POI = poi
}
if vote != nil {
av.Archive.Vote = vote
}
//详情页展示staff
var staffs []*archive.StaffApply
if staffs, err = vdpSvc.ApplysByAID(c, aid); err != nil || staffs == nil || len(staffs) == 0 {
log.Error(" vdpSvc.ApplysByAID(%d) error(%v)", aid, err)
} else {
av.Archive.Staffs = staffs
}
c.JSON(av, nil)
}
// viewArchives get archive info.
func viewArchives(c *bm.Context) {
params := c.Request.Form
aidsStr := params.Get("aids")
// check params
aids, err := xstr.SplitInts(aidsStr)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidsStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
if len(aids) > 50 {
log.Error("viewArchives aids(%s) too long, appkey(%s)", aidsStr, params.Get("appkey"))
c.JSON(nil, ecode.RequestErr)
return
}
avm, err := vdpSvc.Archives(c, aids)
if err != nil {
log.Error(" vdpSvc.Archive(%d) error(%v)", aids, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(avm, nil)
}
// archivesByMid get archive list by mid.
func archivesByMid(c *bm.Context) {
params := c.Request.Form
// check params
midStr := params.Get("mid")
pnStr := params.Get("pn")
psStr := params.Get("ps")
groupStr := params.Get("group")
mid, _ := strconv.ParseInt(midStr, 10, 64)
if mid <= 0 {
log.Error("http.archivesByMid mid(%d) <=0 ", mid)
c.JSON(nil, ecode.RequestErr)
return
}
pn, _ := strconv.Atoi(pnStr)
if pn <= 0 {
pn = 1
}
ps, _ := strconv.Atoi(psStr)
if ps <= 0 || ps > 100 {
ps = 10
}
group, _ := strconv.Atoi(groupStr)
gp := int8(group)
if gp < 0 || gp > 2 {
gp = 0
}
uav, err := vdpSvc.UpArchives(c, mid, pn, ps, gp)
if err != nil {
log.Error(" vdpSvc.Archive(%d,%d,%d,%d) error(%v)", mid, pn, ps, gp, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(uav, nil)
}
// upArchiveTag add archive.
func upArchiveTag(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
tag := params.Get("tag")
// check params
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
return
}
c.JSON(nil, vdpSvc.UpTag(c, aid, tag))
}
// delArchive del archive.
func delArchive(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http delArchive() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Aid == 0 {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(nil, vdpSvc.DelArchive(c, ap.Aid, ap.Mid))
}
// arcHistory get archive edit history.
func arcHistory(c *bm.Context) {
params := c.Request.Form
hidStr := params.Get("hid")
// check params
hid, err := strconv.ParseInt(hidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(hid(%s)) error(%v)", hidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(vdpSvc.ArcHistory(c, hid), nil)
}
// arcHistorys get archive edit history.
func arcHistorys(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
// check params
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(aid(%s)) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(vdpSvc.ArcHistorys(c, aid), nil)
}
// types get all types info
func types(c *bm.Context) {
c.JSON(vdpSvc.Types(c), nil)
}
// videoBycid get video bid cid
func videoBycid(c *bm.Context) {
params := c.Request.Form
cidStr := params.Get("cid")
// check params
cid, err := strconv.ParseInt(cidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(cid(%s)) error(%v)", cidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
v, err := vdpSvc.VideoBycid(c, cid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(v, nil)
}
// archivesByCids get archives by cids
func archivesByCids(c *bm.Context) {
params := c.Request.Form
cidsStr := params.Get("cids")
appkey := params.Get("appkey")
// check params
if appkey != config.DmVerifyKey {
log.Warn("appkey(%s) invalid", appkey)
c.JSON(nil, ecode.AppKeyInvalid)
return
}
cids, err := xstr.SplitInts(cidsStr)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", cidsStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
if len(cids) > 100 {
log.Error("cids(%d) number gt 100", len(cids))
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(vdpSvc.ArchivesByCids(c, cids), nil)
}
// flows get flow list
func flows(c *bm.Context) {
c.JSON(vdpSvc.Flows(c), nil)
}
// flows get specialUps list
func specialUps(c *bm.Context) {
params := c.Request.Form
groupStr := params.Get("group_id")
var err error
// check params
//default all groups
groupID := int64(0)
if groupStr != "" {
groupID, err = strconv.ParseInt(groupStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(groupStr(%s)) error(%v)", groupStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
}
c.JSON(vdpSvc.UpsByGroup(c, groupID), nil)
}
// arcReasonTag .
func arcReasonTag(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
var (
aid, tagID int64
err error
)
aid, err = strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(aidStr(%s)) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
tagID, err = vdpSvc.ArcTag(c, aid)
if err != nil {
log.Error("vdpSvc.ArcTag error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(map[string]interface{}{
"tag_id": tagID,
}, nil)
}
//flowForbid
func flowForbid(c *bm.Context) {
c.JSON(vdpSvc.UpsForbid(c), nil)
}
func appFeedAids(c *bm.Context) {
aids, err := vdpSvc.AppFeedAids(c)
if err != nil {
log.Error("vdpSvc.AppFeedAids() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(aids, nil)
}
func descFormats(c *bm.Context) {
dfs, err := vdpSvc.DescFormats(c)
if err != nil {
log.Error("vdpSvc.DescFormats() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(dfs, nil)
}
// videoJam video check traffic jam time
func videoJam(c *bm.Context) {
level, _ := vdpSvc.VideoJamLevel(c)
c.JSON(map[string]interface{}{
"level": level,
}, nil)
}
// archiveAddit get archive addit
func archiveAddit(c *bm.Context) {
var (
err error
addit *archive.Addit
)
params := c.Request.Form
aidStr := params.Get("aid")
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
if addit, err = vdpSvc.ArchiveAddit(c, aid); err != nil {
log.Error("vdpSvc.archiveAddit(%d) error(%v)", aid, err)
c.JSON(nil, err)
return
}
if addit == nil {
err = ecode.NothingFound
c.JSON(nil, err)
return
}
c.JSON(addit, nil)
}
func rejectedArchives(c *bm.Context) {
params := c.Request.Form
midStr := params.Get("mid")
pnStr := params.Get("pn")
psStr := params.Get("ps")
stateStr := params.Get("state")
startStr := params.Get("start")
state, _ := strconv.Atoi(stateStr)
if state >= 0 {
c.JSON(nil, ecode.RequestErr)
return
}
start, err := getTimeFromSecStr(startStr)
if err != nil || start == nil {
c.JSON(nil, ecode.RequestErr)
return
}
mid, _ := strconv.ParseInt(midStr, 10, 64)
pn, _ := strconv.Atoi(pnStr)
ps, _ := strconv.Atoi(psStr)
if pn < 1 {
pn = 1
}
if ps < 1 {
ps = 20
}
arcs, count, err := vdpSvc.RejectedArchives(c, mid, int32(state), int32(pn), int32(ps), start)
if err != nil {
c.JSON(nil, err)
return
}
data := map[string]interface{}{
"page": map[string]int{
"num": pn,
"size": ps,
"total": int(count),
},
"archives": arcs,
}
c.JSON(data, nil)
}
func getTimeFromSecStr(secStr string) (t *time.Time, err error) {
sec, err := strconv.ParseInt(secStr, 10, 64)
if err != nil || sec <= 0 {
return
}
ti := time.Unix(sec, 0)
t = &ti
return
}

View File

@@ -0,0 +1,88 @@
package http
import (
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
func addByMid(c *bm.Context) {
v := new(struct {
Business int8 `form:"business"`
Mid int64 `form:"mid" validate:"required"`
Oid int64 `form:"oid" validate:"required"`
State int8 `form:"state"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("flowDesign data(%v)", v)
c.JSON(nil, vdpSvc.AddByMid(c, v.Business, v.Mid, v.Oid, v.State))
}
func addByOid(c *bm.Context) {
v := new(struct {
Business int8 `form:"business" validate:"required"`
OID int64 `form:"oid" validate:"required"`
UID int64 `form:"uid" default:"399"`
NoTimeline int32 `form:"no_timeline" default:"-1"`
NoOtt int32 `form:"no_ott" default:"-1"`
NoRank int32 `form:"no_rank" default:"-1"`
NoRecommend int32 `form:"no_recommend" default:"-1"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("flowDesign data(%v)", v)
c.JSON(nil, vdpSvc.AddByOid(c, v.Business, v.OID, v.UID, map[string]int32{
"notimeline": v.NoTimeline,
"noott": v.NoOtt,
"norank": v.NoRank,
"norecommend": v.NoRecommend,
}))
}
func queryByOid(c *bm.Context) {
v := new(struct {
Business int8 `form:"business" validate:"required"`
Oid int64 `form:"oid" validate:"required"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("flowDesign data(%v)", v)
c.JSON(vdpSvc.HitFlowGroups(c, v.Oid, []int8{v.Business}))
}
func listJudgeFlows(c *bm.Context) {
//按照禁止项过滤 对外 一个禁止项属于一个groupId
v := new(struct {
Business int64 `form:"business" validate:"required"`
Gid int64 `form:"gid" validate:"required"`
Oids []int64 `form:"oids,split" validate:"required"`
})
if err := c.Bind(v); err != nil {
return
}
if len(v.Oids) > 200 {
c.JSON(nil, ecode.RequestErr)
return
}
log.Info("flowDesign data(%v)", v)
c.JSON(vdpSvc.TagrgetFlows(c, v.Business, v.Gid, v.Oids))
}
func listFlows(c *bm.Context) {
//按照禁止项过滤 对外 一个禁止项属于一个groupId
v := new(struct {
Business int64 `form:"business" validate:"required"`
Gid int64 `form:"gid" validate:"required"`
Pn int64 `form:"page" default:"1"`
Ps int64 `form:"pagesize" default:"100" validate:"max=1000"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("flowDesign data(%v)", v)
c.JSON(vdpSvc.FlowPage(c, v.Business, v.Gid, v.Pn, v.Ps))
}

View File

@@ -0,0 +1,138 @@
package http
import (
"go-common/app/service/main/videoup/conf"
"go-common/app/service/main/videoup/service"
"go-common/library/log"
"go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/antispam"
"go-common/library/net/http/blademaster/middleware/verify"
)
var (
vfySvc *verify.Verify
anti *antispam.Antispam
vdpSvc *service.Service
config *conf.Config
)
// Init init server.
func Init(c *conf.Config, s *service.Service) {
vfySvc = verify.New(nil)
anti = antispam.New(c.AntispamConf)
vdpSvc = s
config = c
eng := blademaster.DefaultServer(c.BM)
route(eng)
if err := eng.Start(); err != nil {
log.Error("eng.Start error(%v)", err)
panic(err)
}
}
func route(e *blademaster.Engine) {
e.Ping(ping)
vp := e.Group("/videoup", vfySvc.Verify)
{
// ugc && pgc
vp.GET("/simplearchive", simpleArchive)
vp.GET("/simplevideos", simpleVideos)
vp.GET("/view", viewArchive)
vp.GET("/views", viewArchives)
vp.GET("/up/archives", archivesByMid)
vp.GET("/cid/archives", archivesByCids)
vp.GET("/archives/rejected", rejectedArchives)
vp.GET("/history/view", arcHistory)
vp.GET("/history/list", arcHistorys)
vp.GET("/types", types)
vp.GET("/flows", flows)
vp.GET("/flow/forbid", flowForbid)
vp.GET("/query/cid", queryCid)
vp.GET("/up/special", specialUps)
vp.GET("/feed/aids", appFeedAids)
vp.GET("/desc/format", descFormats)
vp.POST("/archive/report", anti.Handler(), arcReport)
vp.GET("/archive/reason/tag", arcReasonTag)
vp.GET("/archive/addit", archiveAddit)
vp.POST("/del", delArchive)
// recommend archive
vp.GET("/recos", Recos)
vp.POST("/reco/update", RecoUpdate)
// obtain cid
vp.POST("/obtain/cid", obtainCid)
// ugc
vp.GET("/cid", videoBycid)
vp.POST("/add", addArchive)
vp.POST("/edit", editArchive)
vp.POST("/tag/up", upArchiveTag)
//setting output
setting := vp.Group("/setting")
{
setting.GET("/dynamic", queryDynamic)
}
//ugc only
ugc := vp.Group("/ugc")
{
ugc.POST("/edit/mission", editMissionByUGC)
}
// pgc
pgc := vp.Group("/pgc")
{
pgc.POST("/add", addByPGC)
pgc.POST("/edit", editByPGC)
pgc.POST("/add/secret", saddByPGC)
pgc.POST("/add/coopera", caddByPGC)
pgc.POST("/edit/coopera", ceditByPGC)
}
vp.POST("/ns/md5", nsMd5)
// Get video traffic jam level
vp.GET("/video/jam", videoJam)
//ad
porder := vp.Group("/porder")
{
porder.GET("/config/list", porderCfgList)
porder.GET("/arc/list", porderArcList)
}
flow := vp.Group("/flow")
{
flow.POST("/entry/mid", addByMid)
flow.POST("/entry/oid", addByOid)
//分页查询
flow.GET("/list", listFlows)
//指定查询
flow.GET("/list/judge", listJudgeFlows)
flow.GET("/info", queryByOid)
}
staff := vp.Group("/staff")
{
/*
1. up主申请(添加/修改) staff member edit其中涉及到 可能已经accept 变成 staffON 的case
2. 生成多个apply list
3. 受邀请者 查看 applys
4.同意 accept 拒绝 refuse
5.up主自己可以继续编辑 覆盖式
发起人维度 稿件页 是批量的
具体申请单页 是单个操作
*/
//查看apply
staff.GET("/apply", viewApply)
//mid applys 计数
staff.GET("/mid/applys", checkMid)
//管理后台
staff.POST("/apply/batch", batchApplys)
//apply申请单交互
staff.POST("/apply/submit", addApply)
//apply申请单列表
staff.GET("/apply/list", applys)
staff.GET("/apply/filter", filterApplys)
staff.GET("/archive/applys/", archiveApplys)
//staff正式列表
staff.GET("", staffs)
}
}
}

View File

@@ -0,0 +1,16 @@
package http
import (
"net/http"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
// ping check server ok.
func ping(c *bm.Context) {
if err := vdpSvc.Ping(c); err != nil {
log.Error("videoup-service ping error(%v)", err)
c.AbortWithStatus(http.StatusServiceUnavailable)
}
}

View File

@@ -0,0 +1,35 @@
package http
import (
"strconv"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
func nsMd5(c *bm.Context) {
params := c.Request.Form
nidStr := params.Get("nid")
nid, err := strconv.ParseInt(nidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", nidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
md5 := params.Get("md5")
if len(md5) != 32 {
log.Error("strconv.ParseInt(%s) error(%v)", md5, err)
c.JSON(nil, ecode.RequestErr)
return
}
err = vdpSvc.AddNetSafeMd5(c, nid, md5)
if err != nil {
log.Error(" vdpSvc.AddNetSafeMd5(%d) error(%v)|nid(%v)|md5(%v)", nid, md5, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(map[string]interface{}{
"nid": nid,
}, nil)
}

View File

@@ -0,0 +1,215 @@
package http
import (
"encoding/json"
"io/ioutil"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
// addByPGC add archive info by PGC.
func addByPGC(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
log.Error("addByPGC func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
ap.UpFrom = archive.UpFromPGC
aid, err := vdpSvc.AddByPGC(c, ap)
if err != nil {
log.Error("vdpSvc.AddByPGC() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(map[string]int64{
"aid": aid,
}, nil)
}
// saddByPGC add secret archive info by PGC.
func saddByPGC(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
log.Error("addByPGC func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
ap.UpFrom = archive.UpFromSecretPGC
aid, err := vdpSvc.AddByPGC(c, ap)
if err != nil {
log.Error("vdpSvc.AddByPGC() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(map[string]int64{
"aid": aid,
}, nil)
}
// editByPGC edit archive info by PGC.
func editByPGC(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
log.Error("editByPGC func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
ap.UpFrom = archive.UpFromPGC
c.JSON(nil, vdpSvc.EditByPGC(c, ap))
}
// caddByPGC add coopera archive info by PGC.
func caddByPGC(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http addByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" || len(ap.Videos) == 0 {
log.Error("addByPGC func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
ap.UpFrom = archive.UpFromCoopera
aid, err := vdpSvc.AddByPGC(c, ap)
if err != nil {
log.Error("vdpSvc.AddByPGC() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(map[string]int64{
"aid": aid,
}, nil)
}
// ceditByPGC edit coopera archive info by PGC.
func ceditByPGC(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http editByPGC() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || ap.Desc == "" {
log.Error("editByPGC func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
ap.UpFrom = archive.UpFromCoopera
c.JSON(nil, vdpSvc.EditByPGC(c, ap))
}

View File

@@ -0,0 +1,29 @@
package http
import (
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
func porderCfgList(c *bm.Context) {
cfgList, err := vdpSvc.PorderCfgList(c)
if err != nil {
log.Error("vdpSvc.porderCfgList() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(cfgList, nil)
}
func porderArcList(c *bm.Context) {
params := c.Request.Form
begin := params.Get("begin")
end := params.Get("end")
data, err := vdpSvc.PorderArcList(c, begin, end)
if err != nil {
log.Error("vdpSvc.PorderArcList() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(data, nil)
}

View File

@@ -0,0 +1,68 @@
package http
import (
"strconv"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/xstr"
)
// Recos fn
func Recos(c *bm.Context) {
params := c.Request.Form
aidStr := params.Get("aid")
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
recos, err := vdpSvc.Recos(c, aid)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(recos, nil)
}
// RecoUpdate fn
func RecoUpdate(c *bm.Context) {
params := c.Request.Form
recoIdsStr := params.Get("ids")
aidStr := params.Get("aid")
midStr := params.Get("mid")
mid, _ := strconv.ParseInt(midStr, 10, 64)
if mid <= 0 {
log.Error("http.archivesByMid mid(%d) <=0 ", mid)
c.JSON(nil, ecode.RequestErr)
return
}
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
recoIds := []int64{}
if len(recoIdsStr) > 0 {
recoIds, err = xstr.SplitInts(recoIdsStr)
}
if err != nil {
log.Error("idsStr splitInts error(%v) | recoIdsStr(%s)", err, recoIdsStr)
c.JSON(nil, ecode.RequestErr)
return
}
if len(recoIds) > 8 {
log.Error("length of idsStr has over Max 8, error(%v) | recoIdsStr(%s)", err, recoIdsStr)
c.JSON(nil, ecode.CreativeRecommendOverMax)
return
}
err = vdpSvc.RecoUpdate(c, mid, aid, recoIds)
if err != nil {
c.JSON(nil, err)
return
}
c.JSON(nil, nil)
}

View File

@@ -0,0 +1,52 @@
package http
import (
"strconv"
"time"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
// viewArchive get archive info.
func arcReport(c *bm.Context) {
params := c.Request.Form
midStr := params.Get("mid")
aidStr := params.Get("aid")
tpStr := params.Get("type")
reason := params.Get("reason")
pics := params.Get("pics")
// check params
mid, err := strconv.ParseInt(midStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", midStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
aid, err := strconv.ParseInt(aidStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
tp, err := strconv.ParseInt(tpStr, 10, 64)
if err != nil {
log.Error("strconv.ParseInt(%s) error(%v)", tpStr, err)
c.JSON(nil, ecode.RequestErr)
return
}
if tp < 0 || tp > 9 {
log.Error("type(%d) or question empty error(%v)", tp, err)
c.JSON(nil, ecode.RequestErr)
return
}
err = vdpSvc.ArcReport(c, mid, aid, int8(tp), reason, pics, time.Now())
if err != nil {
log.Error(" vdpSvc.ArcReport(%d,%d,%d,%s,%s) error(%v)", mid, aid, int8(tp), reason, pics, err)
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(nil, nil)
}

View File

@@ -0,0 +1,132 @@
package http
import (
"encoding/json"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"io/ioutil"
)
func addApply(c *bm.Context) {
//1.同意 拒绝 忽略
//2.申请解除
v := new(archive.ApplyParam)
if err := c.Bind(v); err != nil {
return
}
log.Info("addApply data(%v)", v)
c.JSON(vdpSvc.DoApply(c, v, "申请单"))
}
//批量修改
func batchApplys(c *bm.Context) {
var (
req = c.Request
bs []byte
err error
aps archive.StaffBatchParam
)
if bs, err = ioutil.ReadAll(req.Body); err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
if err = json.Unmarshal(bs, &aps); err != nil {
log.Error("http batchApplys() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if aps.AID == 0 {
log.Error("http batchApplys() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
//允许为空 就是删除
if ok := vdpSvc.CheckStaff(aps.Staffs); !ok {
c.JSON(nil, ecode.RequestErr)
return
}
if err = vdpSvc.HandleArchiveApplys(c, aps.AID, aps.Staffs, "admin_edit", true); err != nil {
log.Error("vdaSvc.batchApplys() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(nil, nil)
}
func viewApply(c *bm.Context) {
v := new(struct {
ID int64 `form:"id" validate:"required"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("viewApply data(%v)", v)
c.JSON(vdpSvc.Apply(c, v.ID))
}
func checkMid(c *bm.Context) {
v := new(struct {
ID int64 `form:"mid" validate:"required"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("checkMid data(%v)", v)
c.JSON(vdpSvc.MidCount(c, v.ID))
}
func applys(c *bm.Context) {
v := new(struct {
IDS []int64 `form:"ids,split" validate:"required" `
})
if err := c.Bind(v); err != nil {
return
}
if len(v.IDS) > 200 {
c.JSON(nil, ecode.RequestErr)
return
}
log.Info("applys data(%v)", v)
c.JSON(vdpSvc.Applys(c, v.IDS))
}
func filterApplys(c *bm.Context) {
v := new(struct {
ADS []int64 `form:"aids,split" validate:"required" `
MID int64 `form:"mid" validate:"required" `
})
if err := c.Bind(v); err != nil {
return
}
if len(v.ADS) > 200 {
c.JSON(nil, ecode.RequestErr)
return
}
log.Info("filterApplys data(%v)", v)
c.JSON(vdpSvc.FilterApplys(c, v.ADS, v.MID))
}
func archiveApplys(c *bm.Context) {
v := new(struct {
AID int64 `form:"aid" validate:"required" `
})
if err := c.Bind(v); err != nil {
return
}
log.Info("archiveApplys data(%v)", v)
c.JSON(vdpSvc.ApplysByAID(c, v.AID))
}
func staffs(c *bm.Context) {
v := new(struct {
AID int64 `form:"aid" validate:"required"`
})
if err := c.Bind(v); err != nil {
return
}
log.Info("staffs data(%v)", v)
c.JSON(vdpSvc.Staffs(c, v.AID))
}

View File

@@ -0,0 +1,123 @@
package http
import (
"encoding/json"
"io/ioutil"
"go-common/app/service/main/videoup/model/archive"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
// addArchive add archive.
func addArchive(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http addArchive() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" || len(ap.Videos) == 0 {
log.Error("http addArchive() func param is empty (%d)|(%d)|(%d)|(%s)|(%s)|(%s)|(%v)", ap.Mid, ap.TypeID, ap.Copyright, ap.Title, ap.Tag, ap.Desc, ap.Videos)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
aid, err := vdpSvc.AddByUGC(c, ap)
if err != nil {
log.Error("vdpSvc.AddArchive() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(map[string]int64{
"aid": aid,
}, nil)
}
// editArchive edit archive.
func editArchive(c *bm.Context) {
req := c.Request
bs, err := ioutil.ReadAll(req.Body)
if err != nil {
log.Error("ioutil.ReadAll() error(%v)", err)
c.JSON(nil, ecode.RequestErr)
return
}
req.Body.Close()
// params
var ap = &archive.ArcParam{}
if err = json.Unmarshal(bs, ap); err != nil {
log.Error("http editArchive() json.Unmarshal(%s) error(%v)", string(bs), err)
c.JSON(nil, ecode.RequestErr)
return
}
if ap.Aid == 0 || ap.Mid == 0 || ap.TypeID == 0 || ap.Copyright == 0 || ap.Title == "" || ap.Tag == "" {
log.Error("http editArchive() func param is empty (%v)", ap)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := vdpSvc.AllowType(c, ap.TypeID); !ok {
log.Error("typeId (%d) not exist", ap.TypeID)
c.JSON(nil, ecode.RequestErr)
return
}
if ok := archive.InCopyrights(ap.Copyright); !ok {
log.Error("Copyright (%d) not in (1,2)", ap.Copyright)
c.JSON(nil, ecode.RequestErr)
return
}
if err = vdpSvc.EditByUGC(c, ap); err != nil {
log.Error("vdpSvc.EditByUGC() error(%v)", err)
c.JSON(nil, err)
return
}
c.JSON(nil, nil)
}
// editMissionByUGC edit archive mission by UGC.
func editMissionByUGC(c *bm.Context) {
v := &archive.ArcMissionParam{}
if err := c.Bind(v); err != nil {
return
}
c.JSON(nil, vdpSvc.EditMissionByUGC(c, v))
}
// queryDynamic edit archive mission by UGC.
func queryDynamic(c *bm.Context) {
v := &archive.ArcDynamicParam{}
if err := c.Bind(v); err != nil {
return
}
can, err := vdpSvc.QueryDynamicSetting(c, v)
if err != nil {
c.JSON(nil, err)
return
}
var repostBanned = int8(0)
if !can {
repostBanned = 1
}
c.JSON(map[string]int8{
"repost_banned": repostBanned,
}, err)
}

View File

@@ -0,0 +1,43 @@
package http
import (
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
func obtainCid(c *bm.Context) {
params := c.Request.Form
fn := params.Get("filename")
if fn == "" {
log.Error("filename not exist")
c.JSON(nil, ecode.NothingFound)
return
}
cid, err := vdpSvc.ObtainCid(c, fn)
if err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(map[string]int64{
"cid": cid,
}, nil)
}
func queryCid(c *bm.Context) {
params := c.Request.Form
fn := params.Get("filename")
if fn == "" {
log.Error("filename not exist")
c.JSON(nil, ecode.NothingFound)
return
}
cid, err := vdpSvc.FindCidByFn(c, fn)
if err != nil {
c.JSON(nil, ecode.RequestErr)
return
}
c.JSON(map[string]int64{
"cid": cid,
}, nil)
}

View File

@@ -0,0 +1,56 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = [
"archive.go",
"archive_state.go",
"biz_poi.go",
"biz_vote.go",
"desc_format.go",
"flow.go",
"forbid.go",
"history.go",
"msg.go",
"param.go",
"porder.go",
"report.go",
"staff.go",
"video.go",
],
importpath = "go-common/app/service/main/videoup/model/archive",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//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"],
)
go_test(
name = "go_default_test",
srcs = ["video_test.go"],
embed = [":go_default_library"],
rundir = ".",
tags = ["automanaged"],
)

View File

@@ -0,0 +1,117 @@
package archive
import (
"go-common/library/time"
)
// Archive is archive model.
type Archive struct {
Aid int64 `json:"aid"`
Mid int64 `json:"mid"`
TypeID int16 `json:"tid"`
HumanRank int `json:"-"`
Title string `json:"title"`
Author string `json:"-"`
Cover string `json:"cover"`
RejectReason string `json:"reject_reason"`
Tag string `json:"tag"`
Duration int64 `json:"duration"`
Copyright int8 `json:"copyright"`
Desc string `json:"desc"`
MissionID int64 `json:"mission_id"`
Round int8 `json:"-"`
Forward int64 `json:"-"`
Attribute int32 `json:"attribute"`
Access int16 `json:"-"`
State int8 `json:"state"`
Source string `json:"source"`
NoReprint int32 `json:"no_reprint"`
UGCPay int32 `json:"ugcpay"`
OrderID int64 `json:"order_id"`
UpFrom int8 `json:"up_from"`
Dynamic string `json:"dynamic"`
DescFormatID int64 `json:"desc_format_id"`
Porder *Porder `json:"porder"`
Staffs []*StaffApply `json:"staffs"`
POI *PoiObj `json:"poi_object"`
Vote *Vote `json:"vote"`
DTime time.Time `json:"dtime"`
PTime time.Time `json:"ptime"`
CTime time.Time `json:"ctime"`
MTime time.Time `json:"mtime"`
}
// AttrSet set attribute.
func (a *Archive) AttrSet(v int32, bit uint) {
a.Attribute = a.Attribute&(^(1 << bit)) | (v << bit)
}
// AttrVal get attribute.
func (a *Archive) AttrVal(bit uint) int32 {
return (a.Attribute >> bit) & int32(1)
}
// NotAllowUp check archive is or not allow update state.
func (a *Archive) NotAllowUp() bool {
return a.State == StateForbidUpDelete || a.State == StateForbidLock || a.State == StateForbidPolice
}
// SimpleArchive str
type SimpleArchive struct {
Aid int64 `json:"aid"`
Title string `json:"title"`
Mid int64 `json:"mid"`
Videos []*Video `json:"videos,omitempty"`
}
// Addit str
type Addit struct {
Aid int64 `json:"aid"`
MissionID int64 `json:"mission_id"`
UpFrom int8 `json:"up_from"`
FromIP int64 `json:"from_ip"`
IPv6 []byte `json:"ipv6"`
Source string `json:"source"`
OrderID int64 `json:"order_id"`
RecheckReason string `json:"recheck_reason"`
RedirectURL string `json:"redirect_url"`
FlowID int64 `json:"flow_id"`
Advertiser string `json:"advertiser"`
FlowRemark string `json:"flow_remark"`
DescFormatID int64 `json:"desc_format_id"`
Desc string `json:"desc"`
Dynamic string `json:"dynamic"`
}
// Delay str
type Delay struct {
Aid int64
State int8
DTime time.Time
}
// Type info
type Type struct {
ID int16 `json:"id"`
PID int16 `json:"pid"`
Name string `json:"name"`
Desc string `json:"description"`
}
// Alert str
type Alert struct {
Key string
Value int64
Limit int64
}
// Up str
type Up struct {
ID int64 `json:"id"`
GroupID int64 `json:"group_id"`
GroupName string `json:"group_name" `
GroupTag string `json:"group_tag"`
Mid int64 `json:"mid"`
Note string `json:"note"`
CTime time.Time `json:"ctime"`
}

View File

@@ -0,0 +1,155 @@
package archive
// Const State
const (
// open state
StateOpen = int8(0)
StateOrange = int8(1)
// forbit state
StateForbidWait = int8(-1)
StateForbidRecicle = int8(-2)
StateForbidPolice = int8(-3)
StateForbidLock = int8(-4)
StateForbidFackLock = int8(-5)
StateForbidFixed = int8(-6)
StateForbidLater = int8(-7)
// StateForbidPatched = int8(-8)
StateForbidWaitXcode = int8(-9)
StateForbidAdminDelay = int8(-10)
StateForbidFixing = int8(-11)
// StateForbidStorageFail = int8(-12)
StateForbidOnlyComment = int8(-13)
// StateForbidTmpRecicle = int8(-14)
StateForbidDispatch = int8(-15)
StateForbidXcodeFail = int8(-16)
StateForbitUpLoad = int8(-20) // NOTE:spell body can judge to change state
StateForbidSubmit = int8(-30)
StateForbidUserDelay = int8(-40)
StateForbidUpDelete = int8(-100)
// attribute yes and no
AttrYes = int32(1)
AttrNo = int32(0)
// attribute bit
AttrBitNoRank = uint(0)
AttrBitNoDynamic = uint(1)
AttrBitNoWeb = uint(2)
AttrBitNoMobile = uint(3)
AttrBitNoSearch = uint(4)
AttrBitOverseaLock = uint(5)
AttrBitNoRecommend = uint(6)
AttrBitNoReprint = uint(7)
AttrBitHasHD5 = uint(8)
AttrBitIsPGC = uint(9)
AttrBitAllowBp = uint(10)
AttrBitIsBangumi = uint(11)
AttrBitIsPorder = uint(12)
AttrBitLimitArea = uint(13)
AttrBitAllowTag = uint(14)
AttrBitIsFromArcAPI = uint(15) // TODO: delete
AttrBitJumpURL = uint(16)
AttrBitIsMovie = uint(17)
AttrBitBadgepay = uint(18)
AttrBitIsJapan = uint(19) //日文稿件
AttrBitNoPushBplus = uint(20) //是否动态禁止
AttrBitParentMode = uint(21) //家长模式
AttrBitUGCPay = uint(22) //UGC付费
AttrBitHasBGM = uint(23) //稿件带有BGM
AttrBitSTAFF = uint(24) //联合投稿
// copyright state
CopyrightUnknow = int8(0)
CopyrightOriginal = int8(1)
CopyrightCopy = int8(2)
// up_from
UpFromWeb = int8(0)
UpFromPGC = int8(1)
UpFromWindows = int8(2)
UpFromAPP = int8(3)
UpFromMAC = int8(4)
UpFromSecretPGC = int8(5)
UpFromCoopera = int8(6)
UpFromCreator = int8(7) // 创作姬
// delay
DelayTypeForAdmin = int8(1)
DelayTypeForUser = int8(2)
// flow type
FlowNotLimit = int8(1)
FlowBudgeting = int8(2)
FlowCapping = int8(3)
FlowForbid = int8(4)
// flow design type
FlowDesignAppFeed = int8(0)
FlowDesignUp = int8(1)
FlowDesignPrivate = int8(2)
// oper uid
AutoOperUID = int64(399)
CMOperUID = int64(518)
// archive list type for up
UpArcAllIn = int8(0)
UpArcOpenIn = int8(1)
UpArcUnOpenIn = int8(2)
VideoFilenameTimeout = int64(48 * 60 * 60)
)
var (
_attr = map[int32]int32{
AttrNo: AttrNo,
AttrYes: AttrYes,
}
_copyright = map[int8]int8{
CopyrightUnknow: CopyrightUnknow,
CopyrightOriginal: CopyrightOriginal,
CopyrightCopy: CopyrightCopy,
}
_bits = map[uint]string{
AttrBitNoRank: "排行禁止",
AttrBitNoDynamic: "动态禁止",
AttrBitNoWeb: "禁止web端输出",
AttrBitNoMobile: "禁止移动端输出",
AttrBitNoSearch: "禁止搜索",
AttrBitOverseaLock: "海外禁止",
AttrBitNoRecommend: "推荐禁止",
AttrBitNoReprint: "禁止转载",
AttrBitHasHD5: "高清1080P",
AttrBitIsPGC: "PGC稿件",
AttrBitAllowBp: "允许承包",
AttrBitIsBangumi: "番剧",
// AttrBitAllowDownload: AttrBitAllowDownload,
// AttrBitHideClick: AttrBitHideClick,
AttrBitAllowTag: "允许操作TAG",
// AttrBitIsFromArcApi: AttrBitIsFromArcApi,
AttrBitJumpURL: "跳转",
AttrBitIsMovie: "电影",
AttrBitBadgepay: "付费",
}
// oversea forbidden typeid
_overseaTypes = map[int16]int16{
32: 32, //'完结动画'
33: 33, //'连载动画'
}
)
// InCopyrights in correct copyrights.
func InCopyrights(cp int8) (ok bool) {
_, ok = _copyright[cp]
return
}
// BitDesc return bit desc.
func BitDesc(bit uint) (desc string) {
return _bits[bit]
}
// InAttr in correct attrs.
func InAttr(attr int32) (ok bool) {
_, ok = _attr[attr]
return
}
// InOverseaType check in oversea forbid type.
func InOverseaType(typeID int16) (ok bool) {
_, ok = _overseaTypes[typeID]
return
}

View File

@@ -0,0 +1,40 @@
package archive
// BIZPOI 1
const (
BIZPOI = int64(1)
)
// PoiObj str
type PoiObj struct {
POI string `json:"poi"`
Type int32 `json:"type"`
Addr string `json:"address"`
Title string `json:"title"`
ShowTitle string `json:"show_title"`
AdInfo *AdInfo `json:"ad_info"`
Ancestors []*Ancestor `json:"ancestors"`
Distance float64 `json:"distance"`
ShowDistrance string `json:"show_distance"`
Location *Location `json:"location"`
}
// AdInfo str
type AdInfo struct {
Nation string `json:"nation"`
Provin string `json:"province"`
Distri string `json:"district"`
City string `json:"city"`
}
// Ancestor str
type Ancestor struct {
POI string `json:"poi"`
Type int32 `json:"type"`
}
// Location str
type Location struct {
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
}

Some files were not shown because too many files have changed in this diff Show More