search.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. package service
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "go-common/app/admin/main/videoup/model/archive"
  6. "go-common/app/admin/main/videoup/model/manager"
  7. "go-common/app/admin/main/videoup/model/search"
  8. accApi "go-common/app/service/main/account/api"
  9. "go-common/library/database/elastic"
  10. "go-common/library/ecode"
  11. "go-common/library/log"
  12. bm "go-common/library/net/http/blademaster"
  13. "go-common/library/xstr"
  14. "strconv"
  15. "strings"
  16. "sync"
  17. )
  18. // SearchVideo search video
  19. func (s *Service) SearchVideo(c context.Context, p *search.VideoParams) (result *search.VideoResultData, err error) {
  20. var (
  21. aids, cids,
  22. vids, mids,
  23. tids, tagIds,
  24. xcodes []int64
  25. fNames []string
  26. ps = 30
  27. sort string
  28. order string
  29. isMonitor bool //是否查看监控列表
  30. moniTotal int //监控列表的总数量
  31. moniMap map[int64]int //监控列表的视频id map。键:vid;值:time(进入监控的时间)
  32. tags map[int64]string
  33. aStates, vStates map[int64]int
  34. members map[int64]*accApi.Info
  35. eReq *elastic.Request
  36. wg sync.WaitGroup
  37. )
  38. es := elastic.NewElastic(nil)
  39. //Page
  40. if p.Ps != 0 {
  41. ps = p.Ps
  42. }
  43. if p.Pn == 0 {
  44. p.Pn = 1
  45. }
  46. if p.OrderType == "1" {
  47. eReq = es.NewRequest("archive_video_score")
  48. } else {
  49. eReq = es.NewRequest("archive_video")
  50. }
  51. eReq.Index("archive_video")
  52. if p.Keywords != "" {
  53. eReq.WhereLike([]string{"arc_title", "arc_author"}, []string{p.Keywords}, true, elastic.LikeLevelLow)
  54. }
  55. if p.ArcTitle != "" {
  56. eReq.WhereLike([]string{"arc_title"}, []string{p.ArcTitle}, false, elastic.LikeLevelLow)
  57. }
  58. if p.Aids != "" {
  59. p.Aids = strings.Join(Slice2String(SliceUnique(Slice2Interface(strings.Split(p.Aids, ",")))), ",")
  60. if aids, err = s.SplitInts(p.Aids); err != nil {
  61. err = ecode.RequestErr
  62. return
  63. }
  64. if len(aids) > ps {
  65. ps = len(aids)
  66. }
  67. eReq.WhereIn("aid", aids)
  68. }
  69. //监控结果列表逻辑
  70. if p.MonitorList != "" {
  71. isMonitor = true
  72. var (
  73. rid int
  74. )
  75. moniP := strings.Split(p.MonitorList, "_")
  76. if len(moniP) != 3 {
  77. err = errors.New("监控列表标识字段格式错误")
  78. return
  79. }
  80. if rid, err = strconv.Atoi(moniP[2]); err != nil {
  81. return
  82. }
  83. if moniMap, err = s.MonitorStayOids(c, int64(rid)); err != nil {
  84. return
  85. }
  86. moniTotal = len(moniMap)
  87. for vid := range moniMap {
  88. vids = append(vids, vid)
  89. }
  90. if len(vids) == 0 {
  91. result = &search.VideoResultData{
  92. Result: []*search.Video{},
  93. }
  94. return
  95. }
  96. if len(vids) > ps {
  97. ps = len(vids)
  98. }
  99. eReq.WhereIn("vid", vids)
  100. }
  101. if p.Cids != "" {
  102. p.Cids = strings.Join(Slice2String(SliceUnique(Slice2Interface(strings.Split(p.Cids, ",")))), ",")
  103. if cids, err = s.SplitInts(p.Cids); err != nil {
  104. err = ecode.RequestErr
  105. return
  106. }
  107. if len(cids) > ps {
  108. ps = len(cids)
  109. }
  110. eReq.WhereIn("cid", cids)
  111. }
  112. if p.Vids != "" {
  113. if vids, err = s.SplitInts(p.Vids); err != nil {
  114. err = ecode.RequestErr
  115. return
  116. }
  117. if len(vids) > ps {
  118. ps = len(vids)
  119. }
  120. eReq.WhereIn("vid", vids)
  121. }
  122. if p.ArcMids != "" {
  123. if mids, err = s.SplitInts(p.ArcMids); err != nil {
  124. err = ecode.RequestErr
  125. return
  126. }
  127. if len(mids) > ps {
  128. ps = len(mids)
  129. }
  130. eReq.WhereIn("arc_mid", mids)
  131. }
  132. if p.Xcode != "" {
  133. if xcodes, err = s.SplitInts(p.Xcode); err != nil {
  134. err = ecode.RequestErr
  135. return
  136. }
  137. eReq.WhereIn("xcode_state", xcodes)
  138. }
  139. if p.TypeID != "" {
  140. if tids, err = s.SplitInts(p.TypeID); err != nil {
  141. err = ecode.RequestErr
  142. return
  143. }
  144. for _, tid := range tids {
  145. if ids, ok := s.typeCache2[int16(tid)]; ok {
  146. tids = append(tids, ids...)
  147. }
  148. }
  149. eReq.WhereIn("arc_typeid", tids)
  150. }
  151. if p.Filename != "" {
  152. if fNames = strings.Split(p.Filename, ","); err != nil {
  153. err = ecode.RequestErr
  154. return
  155. }
  156. eReq.WhereIn("filename", fNames)
  157. }
  158. if p.TagID != "" {
  159. eReq.WhereEq("tag_id", p.TagID)
  160. }
  161. if p.Status != "" {
  162. if p.Status == "-100" {
  163. eReq.WhereEq("relation_state", "-100")
  164. p.Status = ""
  165. } else {
  166. eReq.WhereEq("relation_state", "0")
  167. eReq.WhereEq("status", p.Status)
  168. }
  169. }
  170. if p.UserType != "" {
  171. eReq.WhereEq("user_type", p.UserType)
  172. }
  173. if p.DurationFrom != "" && p.DurationTo != "" {
  174. eReq.WhereRange("duration", p.DurationFrom, p.DurationTo, elastic.RangeScopeLcRc)
  175. } else if p.DurationFrom != "" && p.DurationTo == "" {
  176. eReq.WhereRange("duration", p.DurationFrom, "", elastic.RangeScopeLcRc)
  177. } else if p.DurationFrom == "" && p.DurationTo != "" {
  178. eReq.WhereRange("duration", "", p.DurationTo, elastic.RangeScopeLcRc)
  179. }
  180. //Order by
  181. if p.Order != "" {
  182. order = p.Order
  183. } else if p.Action == "trash" {
  184. order = "v_mtime"
  185. } else {
  186. order = "arc_senddate"
  187. }
  188. if p.Sort == 1 {
  189. sort = "asc"
  190. } else {
  191. sort = "desc"
  192. }
  193. eReq.Order(order, sort)
  194. //Page
  195. eReq.Ps(ps)
  196. eReq.Pn(p.Pn)
  197. //Execute
  198. log.Info("s.SearchVideo(%+v) SearchVideoQuery(%s)", p, eReq.Params())
  199. if err = eReq.Scan(c, &result); err != nil {
  200. log.Error("SearchVideoScan() error(%v)", err)
  201. return
  202. }
  203. if result == nil {
  204. log.Error("s.SearchVideo(%+v) search return nil result", p)
  205. result = &search.VideoResultData{
  206. Result: []*search.Video{},
  207. }
  208. return
  209. }
  210. if result.Result == nil {
  211. log.Error("s.SearchVideo(%+v) search return nil video", p)
  212. result.Result = []*search.Video{}
  213. return
  214. }
  215. if len(result.Result) == 0 {
  216. return
  217. }
  218. if isMonitor {
  219. result.Page.Total = moniTotal
  220. }
  221. aids = []int64{}
  222. vids = []int64{}
  223. mids = []int64{}
  224. for _, v := range result.Result {
  225. if v.TagID != 0 {
  226. tagIds = append(tagIds, v.TagID)
  227. }
  228. aids = append(aids, v.Aid)
  229. vids = append(vids, v.Vid)
  230. if v.ArcMid != 0 {
  231. mids = append(mids, v.ArcMid)
  232. }
  233. }
  234. //获取Tag名称
  235. wg.Add(1)
  236. go func(tags *map[int64]string) {
  237. defer wg.Done()
  238. if *tags, err = s.arc.TagNameMap(c, tagIds); err != nil {
  239. log.Error("s.arc.TagNameMap(%v) error(%v)", tagIds, err)
  240. err = nil
  241. }
  242. log.Info("s.arc.TagNameMap(%v) result(%v)", tagIds, tags)
  243. }(&tags)
  244. //获取数据库中的稿件状态
  245. wg.Add(1)
  246. go func(aStates *map[int64]int) {
  247. defer wg.Done()
  248. if *aStates, err = s.arc.ArcStateMap(c, aids); err != nil {
  249. log.Error("s.arc.ArcStateMap(%v) error(%v)", aids, err)
  250. err = nil
  251. }
  252. }(&aStates)
  253. //获取数据库中视频的状态
  254. wg.Add(1)
  255. go func(vStates *map[int64]int) {
  256. defer wg.Done()
  257. if *vStates, err = s.arc.VideoStateMap(c, vids); err != nil {
  258. log.Error("s.arc.VideoStateMap(%v) error(%v)", vids, err)
  259. err = nil
  260. }
  261. }(&vStates)
  262. //获取UP主信息
  263. wg.Add(1)
  264. go func(members *map[int64]*accApi.Info) {
  265. defer wg.Done()
  266. var infosReply *accApi.InfosReply
  267. if infosReply, err = s.accRPC.Infos3(c, &accApi.MidsReq{Mids: mids}); err != nil {
  268. log.Error("s.accRPC.Infos3(%v) error(%v)", mids, err)
  269. err = nil
  270. return
  271. }
  272. *members = infosReply.Infos
  273. }(&members)
  274. wg.Wait()
  275. sInt, _ := strconv.Atoi(p.Status)
  276. for i := 0; i < len(result.Result); i++ {
  277. v := result.Result[i]
  278. result.Result[i].ID = v.Vid
  279. if vs, ok := vStates[v.Vid]; ok {
  280. result.Result[i].Status = vs
  281. }
  282. //需要将status与查询条件中status不一致的视频剔除
  283. if p.Status != "" && v.Status != sInt {
  284. result.Result = append(result.Result[:i], result.Result[i+1:]...)
  285. i--
  286. continue
  287. }
  288. if tn, ok := tags[v.TagID]; ok {
  289. result.Result[i].TagName = tn
  290. }
  291. if as, ok := aStates[v.Aid]; ok {
  292. result.Result[i].ArcState = as
  293. }
  294. if m, ok := members[v.ArcMid]; ok {
  295. result.Result[i].ArcAuthor = m.Name
  296. }
  297. if v.UserType == nil {
  298. v.UserType = []int64{}
  299. }
  300. if v.UserGroup == nil {
  301. v.UserGroup = []*manager.UpGroup{}
  302. }
  303. for _, tp := range v.UserType {
  304. if up, ok := s.allUpGroupCache[tp]; ok {
  305. result.Result[i].UserGroup = append(result.Result[i].UserGroup, up)
  306. }
  307. }
  308. }
  309. return
  310. }
  311. // SearchCopyright search video copyright
  312. func (s *Service) SearchCopyright(c context.Context, kw string) (result *search.CopyrightResultData, err error) {
  313. return s.search.SearchCopyright(c, kw)
  314. }
  315. // SearchArchive 稿件搜索列表
  316. func (s *Service) SearchArchive(c *bm.Context, p *search.ArchiveParams) (result *search.ArchiveResultData, err error) {
  317. var (
  318. round int
  319. aids []int64
  320. froms []int8
  321. forbid string
  322. tids []int64
  323. pn = 1
  324. ps = 30
  325. isMonitor bool //是否查看监控列表
  326. moniMap map[int64]int //监控列表的视频id map。键:vid;值:time(进入监控的时间)
  327. nPGCAids, sPGCAids, cPGCAids, misAids []int64
  328. additMap map[int64]*archive.Addit
  329. tips string
  330. orders = map[string]string{
  331. "mtime": "",
  332. "pubtime": "",
  333. "ctime": "",
  334. "dm_count": "",
  335. "fav_count": "",
  336. }
  337. eReq *elastic.Request
  338. )
  339. es := elastic.NewElastic(nil)
  340. if p.OrderType != "" {
  341. eReq = es.NewRequest("archive_score")
  342. } else {
  343. eReq = es.NewRequest("archive")
  344. }
  345. eReq.Index("archive")
  346. if p.Ps != 0 {
  347. ps = p.Ps
  348. }
  349. if ps > 1000 {
  350. ps = 1000
  351. }
  352. //分区 逻辑
  353. if p.TypeID != "" {
  354. if tids, err = s.SplitInts(p.TypeID); err != nil {
  355. return
  356. }
  357. for _, tid := range tids {
  358. if ids, ok := s.typeCache2[int16(tid)]; ok {
  359. tids = append(tids, ids...)
  360. }
  361. }
  362. }
  363. //特殊分区逻辑
  364. if p.SpecialType != "" {
  365. for i := 0; i < len(tids); i++ { //剔除特殊/普通分区id
  366. _, ok := s.adtTpsCache[int16(tids[i])]
  367. if (ok && p.SpecialType == "0") || (!ok && p.SpecialType == "1") {
  368. tids = append(tids, tids...)
  369. i--
  370. continue
  371. }
  372. }
  373. }
  374. if len(tids) > 0 {
  375. eReq.WhereIn("typeid", tids)
  376. if len(tids) > ps {
  377. ps = len(tids)
  378. }
  379. }
  380. if p.UserType != "" && p.UserType != "0" {
  381. eReq.WhereEq("user_type", p.UserType)
  382. }
  383. //up_from 逻辑
  384. if p.UpFroms != "" {
  385. var upFroms []int64
  386. if upFroms, err = s.SplitInts(p.UpFroms); err != nil {
  387. return
  388. }
  389. eReq.WhereIn("up_from", upFroms)
  390. } else { //默认去除PGC稿件
  391. eReq.WhereIn("up_from", []int8{archive.UpFromPGC, archive.UpFromSecretPGC, archive.UpFromCoopera})
  392. eReq.WhereNot(elastic.NotTypeIn, "up_from")
  393. }
  394. //Round 逻辑
  395. if p.Round != "" {
  396. if round, err = strconv.Atoi(p.Round); err != nil {
  397. log.Warn("http.searchArchive() http.PGCListLogic() err(%v)", err)
  398. return
  399. }
  400. if round == 1 {
  401. eReq.WhereIn("round", []int8{1, archive.RoundReviewSecond})
  402. } else if round == 2 {
  403. eReq.WhereIn("round", []int8{2, archive.RoundEnd})
  404. } else {
  405. eReq.WhereIn("round", []int{round})
  406. }
  407. }
  408. //Aid 逻辑
  409. if p.Aids != "" {
  410. p.Aids = strings.Replace(p.Aids, "\n", ",", -1)
  411. p.Aids = strings.Join(Slice2String(SliceUnique(Slice2Interface(strings.Split(p.Aids, ",")))), ",")
  412. if aids, err = s.SplitInts(p.Aids); err != nil {
  413. return
  414. }
  415. eReq.WhereIn("id", aids)
  416. }
  417. //Mid 逻辑
  418. if p.Mids != "" {
  419. var mids []int64
  420. p.Mids = strings.Replace(p.Mids, "\n", ",", -1)
  421. if mids, err = s.SplitInts(p.Mids); err != nil {
  422. return
  423. }
  424. eReq.WhereIn("mid", mids)
  425. if len(mids) > ps {
  426. ps = len(mids)
  427. }
  428. }
  429. if p.State != "" {
  430. states := strings.Split(p.State, ",")
  431. eReq.WhereIn("state", states)
  432. }
  433. if p.Access != "" {
  434. eReq.WhereEq("access", p.Access)
  435. }
  436. if p.Copyright != "" {
  437. eReq.WhereEq("copyright", p.Copyright)
  438. }
  439. if p.IsFirst != "" {
  440. eReq.WhereEq("is_first", p.IsFirst)
  441. }
  442. //PGC 列表逻辑
  443. if p.PGCList != "" {
  444. if err = s.PGCListLogic(c, p.PGCList, p.State, froms, eReq); err != nil {
  445. return
  446. }
  447. if c.IsAborted() { //检查鉴权
  448. return
  449. }
  450. }
  451. //搜索关键字逻辑
  452. if p.Keywords != "" {
  453. fields := []string{"title", "content", "tag"}
  454. if p.KwFields != "" {
  455. fields = strings.Split(p.KwFields, ",")
  456. for i := 0; i < len(fields); i++ {
  457. if fields[i] == "channel" {
  458. fields[i] = "tid_names"
  459. break
  460. }
  461. }
  462. }
  463. eReq.WhereLike(fields, []string{p.Keywords}, true, elastic.LikeLevelLow)
  464. }
  465. if p.NoMission == "" { //默认去掉活动稿件
  466. p.NoMission = "1"
  467. }
  468. //禁止项逻辑
  469. if p.Attr == strconv.Itoa(archive.ForbidAttrChannel) {
  470. forbid = "channel"
  471. eReq.WhereEq("channel_group_id", archive.FlowGroupNoChannel)
  472. eReq.WhereEq("channel_pool", archive.PoolArcForbid)
  473. eReq.WhereEq("channel_state", archive.FlowOpen)
  474. } else if p.Attr == strconv.Itoa(archive.ForbidAttrHot) {
  475. forbid = "hot"
  476. eReq.WhereEq("hot_group_id", archive.FlowGroupNoHot)
  477. eReq.WhereEq("hot_pool", archive.PoolArcForbid)
  478. eReq.WhereEq("hot_state", archive.FlowOpen)
  479. } else if p.Attr != "" {
  480. attr := 0
  481. attr, err = strconv.Atoi(p.Attr)
  482. if err != nil {
  483. return
  484. }
  485. if (uint(attr-1) == archive.AttrBitIsPorder) && int8(round) != archive.RoundReviewFlow {
  486. s.auth.Permit("PRIVATE_ORDER_ALL")(c) //鉴权
  487. if c.IsAborted() {
  488. return
  489. }
  490. p.NoMission = "" //不做活动稿件剔除
  491. }
  492. eReq.WhereEq("attribute", attr)
  493. }
  494. //回查列表逻辑
  495. if p.Review != "" {
  496. if p.ReviewState == "" {
  497. p.ReviewState = strconv.Itoa(archive.RecheckStateWait)
  498. }
  499. switch p.Review {
  500. case strconv.Itoa(archive.TypeChannelRecheck):
  501. s.auth.Permit("CHANNEL_REVIEW")(c)
  502. eReq.WhereEq("recheck_ch_type", p.Review)
  503. eReq.WhereEq("recheck_ch_staten", p.ReviewState)
  504. case strconv.Itoa(archive.TypeHotRecheck):
  505. p.NoMission = ""
  506. s.auth.Permit("ARC_HOT_REVIEW")(c)
  507. eReq.WhereEq("recheck_hot_type", p.Review)
  508. eReq.WhereEq("recheck_hot_staten", p.ReviewState)
  509. case strconv.Itoa(archive.TypeInspireRecheck):
  510. p.NoMission = ""
  511. s.auth.Permit("ARC_INSPIRE_REVIEW")(c)
  512. eReq.WhereEq("recheck_inspire_type", p.Review)
  513. eReq.WhereEq("recheck_inspire_staten", p.ReviewState)
  514. }
  515. if c.IsAborted() {
  516. return
  517. }
  518. p.IsOrder = 0
  519. } else if p.Round == strconv.Itoa(int(archive.RoundAuditUGCPayFlow)) { //付费列表需要展示活动稿件
  520. p.NoMission = ""
  521. }
  522. //活动逻辑
  523. if p.MissionID != "" {
  524. eReq.WhereEq("mission_id", p.MissionID)
  525. }
  526. if p.MissionID != "" || p.NoMission == "0" { //需要活动稿件
  527. eReq.WhereRange("mission_id", 1, nil, elastic.RangeScopeLcRo)
  528. } else if p.NoMission == "1" { //不需要活动稿件
  529. eReq.WhereRange("mission_id", 0, nil, elastic.RangeScopeLoRo)
  530. eReq.WhereNot(elastic.NotTypeRange, "mission_id")
  531. }
  532. //商单逻辑
  533. if p.IsOrder == 1 { //商单 order_id 大于0
  534. eReq.WhereRange("order_id", 0, nil, elastic.RangeScopeLoRo)
  535. if p.OrderId != "" {
  536. eReq.WhereEq("order_id", p.OrderId)
  537. }
  538. } else if forbid == "" && p.Review == "" { //除了禁止列表和回查列表,都要去除商单order_id <= 0
  539. eReq.WhereRange("order_id", 0, nil, elastic.RangeScopeLoRo)
  540. eReq.WhereNot(elastic.NotTypeRange, "order_id")
  541. }
  542. //监控结果列表逻辑
  543. if p.MonitorList != "" {
  544. eReq = es.NewRequest("archive_score") //去掉其它条件
  545. eReq.Index("archive")
  546. isMonitor = true
  547. var (
  548. rid int
  549. )
  550. moniP := strings.Split(p.MonitorList, "_")
  551. if len(moniP) != 3 {
  552. err = errors.New("监控列表标识字段格式错误")
  553. return
  554. }
  555. if rid, err = strconv.Atoi(moniP[2]); err != nil {
  556. return
  557. }
  558. if moniMap, err = s.MonitorStayOids(c, int64(rid)); err != nil {
  559. return
  560. }
  561. for aid := range moniMap {
  562. aids = append(aids, aid)
  563. }
  564. if len(aids) == 0 {
  565. result = &search.ArchiveResultData{
  566. Result: []*search.Archive{},
  567. }
  568. return
  569. }
  570. /*if len(aids) > ps {
  571. ps = len(aids)
  572. }*/
  573. eReq.WhereIn("id", aids)
  574. }
  575. //分页、排序
  576. if p.Pn > 0 {
  577. pn = p.Pn
  578. }
  579. if _, ok := orders[p.Order]; !ok {
  580. p.Order = "ctime"
  581. }
  582. if p.Order == "" {
  583. p.Order = "ctime"
  584. }
  585. eReq.OrderScoreFirst(p.ScoreFirst != "0")
  586. if p.Sort == "" {
  587. p.Sort = "desc"
  588. }
  589. eReq.Order(p.Order, p.Sort)
  590. eReq.Pn(pn)
  591. eReq.Ps(ps)
  592. log.Info("SearchArchiveQuery(%s)", eReq.Params())
  593. if err = eReq.Scan(c, &result); err != nil {
  594. log.Error("SearchArchiveQuery() error(%v)", err)
  595. return
  596. }
  597. if isMonitor {
  598. result.MoniAids = moniMap
  599. }
  600. if len(aids) > 0 && !isMonitor {
  601. //获取稿件addit
  602. if additMap, err = s.arc.AdditBatch(c, aids); err != nil {
  603. log.Error("s.arc.AdditBatch(%v) error(%v) additMap(%v)", aids, err, additMap)
  604. err = nil
  605. }
  606. for _, v := range aids {
  607. if _, ok := additMap[v]; ok {
  608. switch additMap[v].UpFrom {
  609. case archive.UpFromPGC:
  610. nPGCAids = append(nPGCAids, v)
  611. case archive.UpFromSecretPGC:
  612. sPGCAids = append(sPGCAids, v)
  613. case archive.UpFromCoopera:
  614. cPGCAids = append(cPGCAids, v)
  615. }
  616. if additMap[v].MissionID > 0 {
  617. misAids = append(misAids, v)
  618. }
  619. }
  620. }
  621. if len(nPGCAids) > 0 {
  622. tips += "PGC稿件:" + xstr.JoinInts(nPGCAids)
  623. }
  624. if len(sPGCAids) > 0 {
  625. tips += "PGC机密:" + xstr.JoinInts(sPGCAids)
  626. }
  627. if len(cPGCAids) > 0 {
  628. tips += "PGC嵌套:" + xstr.JoinInts(cPGCAids)
  629. }
  630. if len(misAids) > 0 {
  631. tips += "活动稿件:" + xstr.JoinInts(misAids)
  632. }
  633. result.Tips = tips
  634. }
  635. if err = s.KneadArchiveResult(c, result, p, additMap); err != nil {
  636. return
  637. }
  638. return
  639. }
  640. // PGCListLogic PGC列表查询相关逻辑
  641. func (s *Service) PGCListLogic(c *bm.Context, lnStr string, pState string, froms []int8, eReq *elastic.Request) (err error) {
  642. var (
  643. state int ////临时存储PGC列表中查询的state状态,需要和pState字符串配合使用!
  644. lni int
  645. ln int8
  646. pgcConfig map[int8]*search.ArcPGCConfig
  647. )
  648. if lni, err = strconv.Atoi(lnStr); err != nil {
  649. log.Warn("s.PGCListLogic() err(%v)", err)
  650. return
  651. }
  652. ln = int8(lni)
  653. if state, err = strconv.Atoi(pState); err != nil {
  654. err = errors.New("PGC列表中的state参数错误")
  655. return
  656. }
  657. if len(froms) != 0 {
  658. for _, v := range froms {
  659. if v != archive.UpFromPGC && v != archive.UpFromSecretPGC && v != archive.UpFromCoopera {
  660. err = errors.New("PGC列表中的from参数错误")
  661. break
  662. }
  663. }
  664. }
  665. pgcConfig = make(map[int8]*search.ArcPGCConfig)
  666. //PGC常规二审列表 round=10 state=-1,-30,-40,-6 upfrom=1
  667. pgcConfig[1] = &search.ArcPGCConfig{
  668. UPFrom: []int8{archive.UpFromPGC},
  669. Rounds: []int8{
  670. archive.RoundBegin,
  671. archive.RoundAuditSecond,
  672. },
  673. States: []int8{
  674. archive.RecheckStateWait,
  675. archive.StateForbidSubmit,
  676. archive.StateForbidUserDelay,
  677. archive.StateForbidFixed,
  678. },
  679. InState: pState != "" && state < 0,
  680. Auth: "PGC_NORMAL_2",
  681. }
  682. //PGC常规三审列表 round=20 state=-1,-30,-40,-6 upfrom=1
  683. pgcConfig[2] = &search.ArcPGCConfig{
  684. UPFrom: []int8{archive.UpFromPGC},
  685. Rounds: []int8{archive.RoundAuditThird},
  686. States: []int8{
  687. archive.RecheckStateWait,
  688. archive.StateForbidSubmit,
  689. archive.StateForbidUserDelay,
  690. archive.StateForbidFixed,
  691. },
  692. InState: pState != "" && state < 0,
  693. Auth: "PGC_NORMAL_3",
  694. }
  695. //PGC机密待审列表 state=-1,-30,-40,-6 upfrom=5
  696. pgcConfig[3] = &search.ArcPGCConfig{
  697. UPFrom: []int8{archive.UpFromSecretPGC},
  698. Rounds: []int8{},
  699. States: []int8{
  700. archive.RecheckStateWait,
  701. archive.StateForbidSubmit,
  702. archive.StateForbidUserDelay,
  703. archive.StateForbidFixed,
  704. },
  705. InState: pState != "" && state < 0,
  706. Auth: "PGC_SECRET_WAIT",
  707. }
  708. //PGC机密回查列表 round=90 state≥0 upfrom=5
  709. pgcConfig[4] = &search.ArcPGCConfig{
  710. UPFrom: []int8{archive.UpFromSecretPGC},
  711. Rounds: []int8{archive.RoundTriggerClick},
  712. States: []int8{
  713. archive.StateOpen,
  714. archive.StateOrange,
  715. },
  716. InState: pState != "" && state >= 0,
  717. Auth: "PGC_SECRET_RECHECK",
  718. }
  719. //PGC全部已过审 round=99 state≥0 upfrom=1,5,6
  720. pgcConfig[5] = &search.ArcPGCConfig{
  721. UPFrom: []int8{archive.UpFromPGC, archive.UpFromSecretPGC, archive.UpFromCoopera},
  722. Rounds: []int8{archive.RoundEnd},
  723. States: []int8{
  724. archive.StateOpen,
  725. archive.StateOrange,
  726. },
  727. InState: pState != "" && state >= 0,
  728. Auth: "PGC_OPEN",
  729. }
  730. //全部打回列表 state=-2,-3,-4,-7,-11,-16,-100 up_from=1,5,6
  731. pgcConfig[6] = &search.ArcPGCConfig{
  732. UPFrom: []int8{archive.UpFromPGC, archive.UpFromSecretPGC, archive.UpFromCoopera},
  733. Rounds: []int8{},
  734. States: []int8{
  735. archive.StateForbidRecycle,
  736. archive.StateForbidPolice,
  737. archive.StateForbidLock,
  738. archive.StateForbidLater,
  739. archive.StateForbidFixing,
  740. archive.StateForbidXcodeFail,
  741. archive.StateForbidUpDelete,
  742. },
  743. InState: pState != "" && state < 0,
  744. Auth: "PGC_RECICLE",
  745. }
  746. //合作方嵌套列表 state=-1,-30,-6,-40 up_from=6
  747. pgcConfig[7] = &search.ArcPGCConfig{
  748. UPFrom: []int8{archive.UpFromCoopera},
  749. Rounds: []int8{},
  750. States: []int8{
  751. archive.StateForbidWait,
  752. archive.StateForbidSubmit,
  753. archive.StateForbidFixed,
  754. archive.StateForbidUserDelay,
  755. },
  756. InState: pState != "" && state < 0,
  757. Auth: "PGC_PARTNER",
  758. }
  759. if _, ok := pgcConfig[ln]; !ok || pgcConfig[ln] == nil {
  760. err = errors.New("PGC列表不存在")
  761. return
  762. }
  763. if !pgcConfig[ln].InState { //如果前端传了合法的state,则加上state条件
  764. pgcConfig[ln].States = []int8{int8(state)}
  765. }
  766. if len(froms) != 0 { //如果前端传了up_from,则加上up_from条件
  767. pgcConfig[ln].UPFrom = froms
  768. }
  769. if len(pgcConfig[ln].UPFrom) == 0 {
  770. err = errors.New("PGC列表中的UPFrom不能设置为空")
  771. return
  772. }
  773. s.auth.Permit(pgcConfig[ln].Auth)(c) //鉴权
  774. eReq.WhereIn("up_from", pgcConfig[ln].UPFrom)
  775. eReq.WhereIn("state", pgcConfig[ln].States)
  776. eReq.WhereIn("round", pgcConfig[ln].Rounds)
  777. return
  778. }
  779. // KneadArchiveResult 拼接稿件数据
  780. func (s *Service) KneadArchiveResult(c *bm.Context, result *search.ArchiveResultData, p *search.ArchiveParams, additMap map[int64]*archive.Addit) (err error) {
  781. var (
  782. mids, aids []int64
  783. ups map[int64]*accApi.Card
  784. rStates map[int64]int8
  785. chNames map[int64][]string
  786. archives = result.Result
  787. dbArchives map[int64]*archive.Archive
  788. wg sync.WaitGroup
  789. )
  790. for _, v := range archives {
  791. if v.Mid != 0 {
  792. mids = append(mids, v.Mid)
  793. }
  794. aids = append(aids, v.ID)
  795. }
  796. //获取频道信息
  797. wg.Add(1)
  798. go func(chNames *map[int64][]string) {
  799. defer wg.Done()
  800. *chNames = s.ChannelNamesByAids(c, aids)
  801. }(&chNames)
  802. wg.Add(1)
  803. go func(dbArchives *map[int64]*archive.Archive) {
  804. defer wg.Done()
  805. if *dbArchives, err = s.arc.Archives(c, aids); err != nil || dbArchives == nil {
  806. log.Error("s.arc.Archives(%v) error(%v) archives(%v)", mids, err, dbArchives)
  807. err = nil
  808. }
  809. }(&dbArchives)
  810. //获取UP主信息
  811. wg.Add(1)
  812. go func(ups *map[int64]*accApi.Card) {
  813. defer wg.Done()
  814. if *ups, err = s.upCards(c, mids); err != nil || ups == nil {
  815. log.Error("s.upCards(%v) error(%v) ups(%v)", mids, err, ups)
  816. err = nil
  817. *ups = make(map[int64]*accApi.Card)
  818. }
  819. }(&ups)
  820. //获取回查稿件实时状态
  821. if p.Review != "" && p.ReviewState != "" {
  822. wg.Add(1)
  823. go func(rStates *map[int64]int8) {
  824. defer wg.Done()
  825. tp, _ := strconv.Atoi(p.Review)
  826. if *rStates, err = s.arc.RecheckStateMap(c, tp, aids); err != nil || rStates == nil {
  827. log.Error("s.arc.RecheckStateMap(%v,%v) error(%v) rStates(%v)", tp, aids, err, rStates)
  828. err = nil
  829. }
  830. }(&rStates)
  831. }
  832. wg.Wait()
  833. for i := 0; i < len(archives); i++ {
  834. v := archives[i]
  835. if a, ok := dbArchives[v.ID]; ok && a.Cover != "" {
  836. archives[i].Cover = coverURL(a.Cover)
  837. }
  838. if m, ok := ups[v.Mid]; ok {
  839. archives[i].Official = m.Official
  840. archives[i].Author = m.Name
  841. }
  842. if p.Review != "" && p.ReviewState != "" {
  843. if state, ok := rStates[v.ID]; ok { //将与查询条件中回查状态不一致的稿件剔除
  844. rState, err := strconv.Atoi(p.ReviewState)
  845. if err != nil {
  846. log.Error("s.KneadArchive() error(%v) reviewState(%v)", err, p.ReviewState)
  847. err = nil
  848. continue
  849. }
  850. if state != int8(rState) {
  851. archives = append(archives[:i], archives[i+1:]...)
  852. i--
  853. continue
  854. }
  855. }
  856. }
  857. if _, ok := additMap[v.ID]; ok {
  858. archives[i].UpFrom = additMap[v.ID].UpFrom
  859. if additMap[v.ID].MissionID > 0 {
  860. archives[i].MissionID = additMap[v.ID].MissionID
  861. }
  862. }
  863. if names, ok := chNames[v.ID]; ok {
  864. archives[i].TagNames = names
  865. }
  866. if archives[i].TagNames == nil {
  867. archives[i].TagNames = []string{}
  868. }
  869. if archives[i].UserType == nil {
  870. archives[i].UserType = []int64{}
  871. }
  872. if v.UserGroup == nil {
  873. v.UserGroup = []*manager.UpGroup2{}
  874. }
  875. if v.Attribute == nil {
  876. v.Attribute = []int{}
  877. }
  878. v.Attrs = v.Attribute
  879. for _, tp := range v.UserType {
  880. if up, ok := s.allUpGroupCache[tp]; ok {
  881. //因为前端希望稿件列表返回的up_group与任务质检结构一致,所以在这做一次转换
  882. gp := &manager.UpGroup2{
  883. GroupID: up.ID,
  884. GroupName: up.Name,
  885. GroupTag: up.ShortTag,
  886. }
  887. result.Result[i].UserGroup = append(result.Result[i].UserGroup, gp)
  888. }
  889. }
  890. }
  891. result.Result = archives
  892. return
  893. }