task_review.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. "encoding/json"
  6. "fmt"
  7. "strings"
  8. "time"
  9. "go-common/app/admin/main/videoup-task/model"
  10. "go-common/library/database/sql"
  11. "go-common/library/log"
  12. "go-common/library/xstr"
  13. )
  14. const (
  15. _reviewCfg = 3
  16. _countSQL = "SELECT COUNT(*) FROM task_json_config"
  17. _listConfsSQL = "SELECT id,conf_json,conf_type,btime,etime,state,uid,uname,description,mtime FROM task_json_config WHERE conf_type=3"
  18. _reConfsSQL = "SELECT id,conf_json,conf_type,btime,etime,state,uid,uname,description,mtime FROM task_json_config WHERE conf_type=3"
  19. _inConfSQL = "INSERT INTO task_json_config(conf_json,conf_type,btime,etime,state,uid,uname,description) VALUE (?,?,?,?,?,?,?,?)"
  20. _upConfSQL = "UPDATE task_json_config SET conf_json=?,conf_type=?,btime=?,etime=?,state=?,uid=?,uname=?,description=? WHERE id=?"
  21. _delConfSQL = "DELETE FROM task_json_config WHERE id=?"
  22. _reviewSQL = "SELECT review_form FROM task_review WHERE task_id=?"
  23. _inReviewSQL = "INSERT INTO task_review(task_id,review_form,uid,uname) VALUE (?,?,?,?)"
  24. )
  25. // ListConfs 配置列表
  26. func (d *Dao) ListConfs(c context.Context, uids []int64, bt, et, sort string, pn, ps int64) (rcs []*model.ReviewConf, count int64, err error) {
  27. var (
  28. rows *sql.Rows
  29. countstring, sqlstring, params string
  30. wherecases []string
  31. )
  32. if len(uids) > 0 {
  33. wherecases = append(wherecases, fmt.Sprintf("uid IN (%s)", xstr.JoinInts(uids)))
  34. }
  35. if len(bt) > 0 && len(et) > 0 {
  36. wherecases = append(wherecases, fmt.Sprintf("mtime>='%s' AND mtime<='%s'", bt, et))
  37. }
  38. if len(wherecases) > 0 {
  39. params = " AND " + strings.Join(wherecases, " AND ")
  40. }
  41. countstring = _countSQL + " WHERE conf_type=3" + params
  42. sqlstring = _listConfsSQL + params + fmt.Sprintf(" ORDER BY mtime %s LIMIT %d,%d", sort, (pn-1)*ps, pn*ps)
  43. if err = d.arcDB.QueryRow(c, countstring).Scan(&count); err != nil {
  44. log.Error("d.arcDB.QueryRow(%s) error(%v)", countstring, err)
  45. return
  46. }
  47. if count == 0 {
  48. return
  49. }
  50. if rows, err = d.arcDB.Query(c, sqlstring); err != nil {
  51. log.Error("d.arcDB.Query(%s) error(%v)", sqlstring, err)
  52. return
  53. }
  54. defer rows.Close()
  55. for rows.Next() {
  56. var (
  57. jsonCfg []byte
  58. cfgType int8
  59. )
  60. trc := &model.ReviewConf{}
  61. if err = rows.Scan(&trc.ID, &jsonCfg, &cfgType, &trc.Bt, &trc.Et, &trc.State, &trc.UID, &trc.Uname, &trc.Desc, &trc.Mt); err != nil {
  62. log.Error("rows.Scan error(%v)", err)
  63. continue
  64. }
  65. if err = json.Unmarshal(jsonCfg, trc); err != nil {
  66. log.Error("json.Unmarshal error(%v)", err)
  67. continue
  68. }
  69. trc.Refresh()
  70. rcs = append(rcs, trc)
  71. }
  72. return
  73. }
  74. // ReviewConfs 复审配置
  75. func (d *Dao) ReviewConfs(c context.Context) (rcs []*model.ReviewConf, err error) {
  76. var rows *sql.Rows
  77. if rows, err = d.arcDB.Query(c, _reConfsSQL); err != nil {
  78. log.Error("d.arcDB.Query(%s, %d) error(%v)", _reConfsSQL, err)
  79. return
  80. }
  81. defer rows.Close()
  82. for rows.Next() {
  83. var (
  84. jsonCfg []byte
  85. cfgType int8
  86. )
  87. trc := &model.ReviewConf{}
  88. if err = rows.Scan(&trc.ID, &jsonCfg, &cfgType, &trc.Bt, &trc.Et, &trc.State, &trc.UID, &trc.Uname, &trc.Desc, &trc.Mt); err != nil {
  89. log.Error("rows.Scan error(%v)", err)
  90. continue
  91. }
  92. if err = json.Unmarshal(jsonCfg, trc); err != nil {
  93. log.Error("json.Unmarshal error(%v)", err)
  94. continue
  95. }
  96. trc.Refresh()
  97. rcs = append(rcs, trc)
  98. }
  99. return
  100. }
  101. // InReviewConf 插入配置
  102. func (d *Dao) InReviewConf(c context.Context, rc *model.ReviewConf) (lastid int64, err error) {
  103. var (
  104. res xsql.Result
  105. jsonCfg []byte
  106. )
  107. v := new(struct {
  108. Types []int64 `json:"types" params:"types"` // 分区
  109. UpFroms []int64 `json:"upfroms" params:"upfroms"` // 投稿来源
  110. UpGroups []int64 `json:"upgroups" params:"upgroups"` // 用户组
  111. Uids []int64 `json:"uids" params:"uids"` // 指定uid
  112. FansLow int64 `json:"fanslow" params:"fanslow"` // 粉丝数最低值
  113. FansHigh int64 `json:"fanshigh" params:"fanshigh"` // 粉丝数最高
  114. })
  115. v.Types = rc.Types
  116. v.UpFroms = rc.UpFroms
  117. v.UpGroups = rc.UpGroups
  118. v.Uids = rc.Uids
  119. v.FansLow = rc.FansLow
  120. v.FansHigh = rc.FansHigh
  121. if rc.Bt.TimeValue().IsZero() {
  122. rc.Bt = model.NewFormatTime(time.Now())
  123. }
  124. if jsonCfg, err = json.Marshal(v); err != nil {
  125. log.Error("json.Marshal(%+v) error(%v)", rc, err)
  126. return
  127. }
  128. if res, err = d.arcDB.Exec(c, _inConfSQL, jsonCfg, _reviewCfg, rc.Bt, rc.Et, 0, rc.UID, rc.Uname, rc.Desc); err != nil {
  129. log.Error("d.arcDB.Exec(%+v) error(%s, %v)", _inConfSQL, rc, err)
  130. return
  131. }
  132. return res.LastInsertId()
  133. }
  134. // UpReviewConf 更新指定配置
  135. func (d *Dao) UpReviewConf(c context.Context, rc *model.ReviewConf) (lastid int64, err error) {
  136. var (
  137. res xsql.Result
  138. jsonCfg []byte
  139. )
  140. v := new(struct {
  141. Types []int64 `json:"types" params:"types"` // 分区
  142. UpFroms []int64 `json:"upfroms" params:"upfroms"` // 投稿来源
  143. UpGroups []int64 `json:"upgroups" params:"upgroups"` // 用户组
  144. Uids []int64 `json:"uids" params:"uids"` // 指定uid
  145. FansLow int64 `json:"fanslow" params:"fanslow"` // 粉丝数最低值
  146. FansHigh int64 `json:"fanshigh" params:"fanshigh"` // 粉丝数最高
  147. })
  148. v.Types = rc.Types
  149. v.UpFroms = rc.UpFroms
  150. v.UpGroups = rc.UpGroups
  151. v.Uids = rc.Uids
  152. v.FansLow = rc.FansLow
  153. v.FansHigh = rc.FansHigh
  154. if rc.Bt.TimeValue().IsZero() {
  155. rc.Bt = model.NewFormatTime(time.Now())
  156. }
  157. if jsonCfg, err = json.Marshal(v); err != nil {
  158. log.Error("json.Marshal(%+v) error(%v)", rc, err)
  159. return
  160. }
  161. if res, err = d.arcDB.Exec(c, _upConfSQL, jsonCfg, _reviewCfg, rc.Bt, rc.Et, rc.State, rc.UID, rc.Uname, rc.Desc, rc.ID); err != nil {
  162. log.Error("d.arcDB.Exec(%s %+v) error(%v)", _upConfSQL, rc, err)
  163. return
  164. }
  165. return res.RowsAffected()
  166. }
  167. // DelReviewConf 删除指定配置
  168. func (d *Dao) DelReviewConf(c context.Context, id int) (lastid int64, err error) {
  169. var res xsql.Result
  170. if res, err = d.arcDB.Exec(c, _delConfSQL, id); err != nil {
  171. log.Error("d.arcDB.Exec(%s %d) error(%v)", _delConfSQL, id, err)
  172. return
  173. }
  174. return res.RowsAffected()
  175. }
  176. // ReviewForm 复审表单
  177. func (d *Dao) ReviewForm(c context.Context, tid int64) (tsf *model.SubmitForm, err error) {
  178. var form []byte
  179. if err = d.arcDB.QueryRow(c, _reviewSQL, tid).Scan(&form); err != nil {
  180. if err == sql.ErrNoRows {
  181. log.Info("ReviewForm QueryRow empty(%d)", tid)
  182. err = nil
  183. return
  184. }
  185. log.Error("d.arcDB.QueryRow(%s, %d) error(%v)", _reviewSQL, tid, err)
  186. return
  187. }
  188. tsf = &model.SubmitForm{}
  189. if err = json.Unmarshal(form, tsf); err != nil {
  190. log.Error("json.Unmarshal error(%v)", err)
  191. tsf = nil
  192. }
  193. return
  194. }
  195. // InReviewForm insert submit form
  196. func (d *Dao) InReviewForm(c context.Context, sf *model.SubmitForm, uid int64, uname string) (lastid int64, err error) {
  197. var (
  198. res xsql.Result
  199. bsf []byte
  200. )
  201. if bsf, err = json.Marshal(sf); err != nil {
  202. log.Error("json.Marshal error(%v)", err)
  203. return
  204. }
  205. if res, err = d.arcDB.Exec(c, _inReviewSQL, sf.TaskID, bsf, uid, uname); err != nil {
  206. log.Error("d.arcDB.Exec(%s,%d,%v,%d,%s) error(%v)", _inReviewSQL, sf.TaskID, bsf, uid, uname, err)
  207. return
  208. }
  209. return res.LastInsertId()
  210. }