audit_result.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. package service
  2. import (
  3. "net/url"
  4. "context"
  5. "fmt"
  6. "go-common/app/admin/main/tv/model"
  7. "go-common/library/log"
  8. "go-common/library/time"
  9. "go-common/library/xstr"
  10. )
  11. // order const
  12. const (
  13. newOrder = 1
  14. )
  15. // EpResult gives the result of ep audit
  16. func (s *Service) EpResult(req url.Values, page int, order int) (pager *model.EPResultPager, err error) {
  17. var (
  18. count int64
  19. size = s.c.Cfg.AuditRSize
  20. items []*model.EPResDB
  21. db = s.DB.Model(&model.Content{}).
  22. Where("tv_content.is_deleted=?", 0).
  23. Joins("LEFT JOIN tv_ep_season ON tv_content.season_id=tv_ep_season.id").
  24. Select("tv_content.*,tv_ep_season.title as stitle,tv_ep_season.category")
  25. )
  26. // order treatment
  27. if order == newOrder {
  28. db = db.Order("tv_content.inject_time DESC")
  29. } else {
  30. db = db.Order("tv_content.inject_time ASC")
  31. }
  32. // category treatment
  33. if category := req.Get("category"); category != "" {
  34. db = db.Where("tv_ep_season.category=?", category)
  35. }
  36. // audit status treatment
  37. if state := req.Get("state"); state != "" {
  38. switch state {
  39. case "1": // passed
  40. db = db.Where("tv_content.`state` = ?", 3)
  41. case "2": // reject
  42. db = db.Where("tv_content.`state` = ?", 4)
  43. default: // waiting result
  44. db = db.Where("tv_content.`state` NOT IN (3,4)")
  45. }
  46. }
  47. // season_id treatment
  48. if sid := req.Get("season_id"); sid != "" {
  49. db = db.Where("tv_content.season_id=?", sid)
  50. }
  51. // epid treatment
  52. if epid := req.Get("epid"); epid != "" {
  53. db = db.Where("tv_content.epid=?", epid)
  54. }
  55. if err = db.Count(&count).Error; err != nil {
  56. log.Error("Count Err %v", err)
  57. return
  58. }
  59. pager = &model.EPResultPager{
  60. Page: &model.Page{
  61. Num: page,
  62. Size: size,
  63. Total: int(count),
  64. },
  65. }
  66. if err = db.Offset((page - 1) * size).Limit(size).Find(&items).Error; err != nil {
  67. return
  68. }
  69. // use time in string format to replace the time in number format
  70. for _, v := range items {
  71. pager.Items = append(pager.Items, v.ToItem())
  72. }
  73. return
  74. }
  75. //TimeFormat is used for format time
  76. func (s *Service) TimeFormat(time time.Time) (format string) {
  77. if time < 0 {
  78. return ""
  79. }
  80. return time.Time().Format("2006-01-02 15:04:05")
  81. }
  82. // SeasonResult gives the result of ep audit
  83. func (s *Service) SeasonResult(req url.Values, page int, order int) (pager *model.SeasonResultPager, err error) {
  84. var (
  85. count int64
  86. size = s.c.Cfg.AuditRSize
  87. dbTerms []*model.SeasonResDB
  88. db = s.DB.Model(&model.TVEpSeason{}).Where("is_deleted=?", 0)
  89. )
  90. // order treatment
  91. if order == newOrder {
  92. db = db.Order("inject_time DESC")
  93. } else {
  94. db = db.Order("inject_time ASC")
  95. }
  96. // category treatment
  97. if category := req.Get("category"); category != "" {
  98. db = db.Where("tv_ep_season.category=?", category)
  99. }
  100. // audit status treatment
  101. if state := req.Get("check"); state != "" {
  102. switch state {
  103. case "1": // passed
  104. db = db.Where("tv_ep_season.`check` = ?", 1)
  105. case "2": // reject
  106. db = db.Where("tv_ep_season.`check` = ?", 0)
  107. default: // waiting result
  108. db = db.Where("tv_ep_season.`check` NOT IN (0,1)")
  109. }
  110. }
  111. // season_id treatment
  112. if sid := req.Get("season_id"); sid != "" {
  113. db = db.Where("id=?", sid)
  114. }
  115. // title treatment
  116. if title := req.Get("title"); title != "" {
  117. db = db.Where("title LIKE ?", "%"+title+"%")
  118. }
  119. if err = db.Count(&count).Error; err != nil {
  120. log.Error("db Count Err %v", err)
  121. return
  122. }
  123. pager = &model.SeasonResultPager{
  124. Page: &model.Page{
  125. Num: page,
  126. Size: size,
  127. Total: int(count),
  128. },
  129. }
  130. if err = db.Offset((page - 1) * size).Limit(size).Find(&dbTerms).Error; err != nil {
  131. return
  132. }
  133. for _, v := range dbTerms {
  134. pager.Items = append(pager.Items, v.ToItem())
  135. }
  136. return
  137. }
  138. func (s *Service) typeidsTreat(secondCat int32, firstCat int32) (typeids []int32) {
  139. if secondCat != 0 { // typeid logic
  140. typeids = []int32{secondCat}
  141. } else if firstCat != 0 {
  142. if secondCats, ok := s.arcPTids[firstCat]; ok && len(secondCats) > 0 {
  143. typeids = secondCats
  144. }
  145. }
  146. return
  147. }
  148. // ArcResult picks archive result data
  149. func (s *Service) ArcResult(c context.Context, req *model.ReqArcCons) (data *model.ArcResPager, err error) {
  150. if data, err = s.arcByES(req, s.typeidsTreat(req.SecondCat, req.FirstCat)); err != nil {
  151. log.Error("arcByEs Err %v", err)
  152. return
  153. }
  154. return
  155. }
  156. func (s *Service) arcByES(req *model.ReqArcCons, typeids []int32) (data *model.ArcResPager, err error) {
  157. var (
  158. esRes *model.EsUgcResult
  159. aids []int64
  160. arcs []*model.Archive
  161. arcsMap = make(map[int64]*model.ArcRes)
  162. reqES = new(model.ReqArcES)
  163. )
  164. reqES.FromAuditConsult(req, typeids)
  165. if esRes, err = s.dao.ArcES(ctx, reqES); err != nil {
  166. log.Error("UgcConsult Err %v", err)
  167. return
  168. }
  169. data = &model.ArcResPager{
  170. Page: esRes.Page,
  171. }
  172. if len(esRes.Result) == 0 {
  173. return
  174. }
  175. for _, v := range esRes.Result {
  176. aids = append(aids, v.AID)
  177. }
  178. if err = s.DB.Where(fmt.Sprintf("aid IN (%s)", xstr.JoinInts(aids))).Find(&arcs).Error; err != nil {
  179. log.Error("arcByES DB Aids %v Err %v", aids, err)
  180. return
  181. }
  182. if len(arcs) == 0 {
  183. return
  184. }
  185. for _, v := range arcs {
  186. arcsMap[v.AID] = v.ConsultRes(s.ArcTypes)
  187. }
  188. for _, v := range aids {
  189. if arc, ok := arcsMap[v]; ok {
  190. data.Items = append(data.Items, arc)
  191. }
  192. }
  193. return
  194. }
  195. // VideoResult picks video audit consult result
  196. func (s *Service) VideoResult(c context.Context, req *model.ReqVideoCons) (data *model.VideoResPager, err error) {
  197. var (
  198. videos []*model.Video
  199. )
  200. data = &model.VideoResPager{
  201. Page: &model.Page{
  202. Num: req.Pn,
  203. Size: _pagesize,
  204. },
  205. }
  206. db := s.DB.Model(&model.Video{}).Where("aid = ?", req.AVID).Where("deleted = 0")
  207. if req.Status != "" {
  208. db = db.Where("result = ?", req.Status)
  209. }
  210. if req.Title != "" {
  211. db = db.Where("eptitle LIKE ?", "%"+req.Title+"%")
  212. }
  213. if req.CID != 0 {
  214. db = db.Where("cid = ?", req.CID)
  215. }
  216. if err = db.Count(&data.Page.Total).Error; err != nil {
  217. log.Error("VideoResult Count Err %v", err)
  218. return
  219. }
  220. if req.Order != 1 {
  221. db = db.Order("index_order ASC")
  222. } else {
  223. db = db.Order("index_order DESC")
  224. }
  225. if err = db.Offset((req.Pn - 1) * _pagesize).Limit(_pagesize).Find(&videos).Error; err != nil {
  226. log.Error("arcByDB Err %v", err)
  227. }
  228. if len(videos) == 0 {
  229. return
  230. }
  231. for _, v := range videos {
  232. data.Items = append(data.Items, v.ConsultRes())
  233. }
  234. return
  235. }