jury.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/job/main/credit/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _addBlockInfoSQL = `INSERT INTO blocked_info (uid,origin_title,blocked_remark,origin_url,origin_content,origin_content_modify,origin_type,
  11. punish_time,punish_type,moral_num,blocked_days,publish_status,reason_type,operator_name,blocked_forever,blocked_type,case_id,oper_id)
  12. VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
  13. _updateKPISQL = "UPDATE blocked_kpi set rate=1,rank_per=1 where id=?"
  14. _updateKPIPendentSQL = "UPDATE blocked_kpi set pendent_status=1 where id=?"
  15. _updateKPIHandlerSQL = "UPDATE blocked_kpi set handler_status=1 where id=?"
  16. _updateCaseSQL = "UPDATE blocked_case SET status=?,judge_type=? WHERE id=?"
  17. _invalidJurySQL = "UPDATE blocked_jury SET status=2,invalid_reason=? where mid=?"
  18. _updateVoteRightSQL = "UPDATE blocked_jury SET vote_total = vote_total + 1, vote_right = vote_right + 1 WHERE mid = ?"
  19. _updateVoteTotalSQL = "UPDATE blocked_jury SET vote_total = vote_total + 1 WHERE mid = ?"
  20. _updatePunishResultSQL = "UPDATE blocked_case SET punish_result=? WHERE id=?"
  21. _selKPISQL = "SELECT id,mid,rate from blocked_kpi where rate in(1,2,3) and day=?"
  22. _selKPIInfoSQL = "SELECT id,mid,handler_status from blocked_kpi where id=?"
  23. _selCaseByIDSQL = "SELECT id,mid,status,judge_type,relation_id from blocked_case where id=?"
  24. _countKPIRateSQL = "SELECT COUNT(*) AS num FROM blocked_kpi WHERE mid=? AND rate<=4"
  25. )
  26. // AddBlockInfo add user block info.
  27. func (d *Dao) AddBlockInfo(c context.Context, b *model.BlockedInfo, ts time.Time) (id int64, err error) {
  28. res, err := d.db.Exec(c, _addBlockInfoSQL, b.UID, b.OriginTitle, b.BlockedRemark, b.OriginURL, b.OriginContent, b.OriginContentModify, b.OriginType,
  29. ts, b.PunishType, b.MoralNum, b.BlockedDays, b.PublishStatus, b.ReasonType, b.OperatorName, b.BlockedForever, b.BlockedType, b.CaseID, b.OPID)
  30. if err != nil {
  31. log.Error("d.AddBlockInfo err(%v)", err)
  32. }
  33. return res.LastInsertId()
  34. }
  35. // UpdateKPI update kpi status to st.
  36. func (d *Dao) UpdateKPI(c context.Context, id int64) (err error) {
  37. if _, err = d.db.Exec(c, _updateKPISQL, id); err != nil {
  38. log.Error("d.UpdateKPI err(%v)", err)
  39. }
  40. return
  41. }
  42. // UpdateKPIPendentStatus update blocked_kpi status to st.
  43. func (d *Dao) UpdateKPIPendentStatus(c context.Context, id int64) (err error) {
  44. if _, err = d.db.Exec(c, _updateKPIPendentSQL, id); err != nil {
  45. log.Error("d.UpdatePendentStatus err(%v)", err)
  46. }
  47. return
  48. }
  49. // UpdateKPIHandlerStatus update blocked_kpi handler status.
  50. func (d *Dao) UpdateKPIHandlerStatus(c context.Context, id int64) (err error) {
  51. if _, err = d.db.Exec(c, _updateKPIHandlerSQL, id); err != nil {
  52. log.Error("d.UpdatePendentStatus err(%v)", err)
  53. }
  54. return
  55. }
  56. // UpdateCase update case status to st.
  57. func (d *Dao) UpdateCase(c context.Context, st, jt, id int64) (err error) {
  58. if _, err = d.db.Exec(c, _updateCaseSQL, st, jt, id); err != nil {
  59. log.Error("d.UpdateCase err(%v)", err)
  60. }
  61. return
  62. }
  63. // InvalidJury set jury invalid.
  64. func (d *Dao) InvalidJury(c context.Context, reason, mid int64) (err error) {
  65. if _, err = d.db.Exec(c, _invalidJurySQL, reason, mid); err != nil {
  66. log.Error("d.InvalidJury err(%v)", err)
  67. }
  68. return
  69. }
  70. // UpdateVoteRight update vote total and vote right.
  71. func (d *Dao) UpdateVoteRight(c context.Context, mid int64) (err error) {
  72. if _, err = d.db.Exec(c, _updateVoteRightSQL, mid); err != nil {
  73. log.Error("d.UpdateVoteRight err(%v)", err)
  74. }
  75. return
  76. }
  77. // UpdateVoteTotal update vote total.
  78. func (d *Dao) UpdateVoteTotal(c context.Context, mid int64) (err error) {
  79. if _, err = d.db.Exec(c, _updateVoteTotalSQL, mid); err != nil {
  80. log.Error("d.UpdateVoteTotal err(%v)", err)
  81. }
  82. return
  83. }
  84. // UpdatePunishResult update table blocked_case punish_result field =0
  85. func (d *Dao) UpdatePunishResult(c context.Context, id int64, punishResult int8) (err error) {
  86. if _, err = d.db.Exec(c, _updatePunishResultSQL, punishResult, id); err != nil {
  87. log.Error("d.UpdatePunishResult err(%v)", err)
  88. }
  89. return
  90. }
  91. // KPIList get kpi list.
  92. func (d *Dao) KPIList(c context.Context, day string) (res []model.Kpi, err error) {
  93. var rows *sql.Rows
  94. if rows, err = d.db.Query(c, _selKPISQL, day); err != nil {
  95. log.Error("dao.KPIList error(%v)", err)
  96. return
  97. }
  98. defer rows.Close()
  99. for rows.Next() {
  100. r := model.Kpi{}
  101. if err = rows.Scan(&r.ID, &r.Mid, &r.Rate); err != nil {
  102. log.Error("row.Scan() error(%v)", err)
  103. res = nil
  104. return
  105. }
  106. res = append(res, r)
  107. }
  108. err = rows.Err()
  109. return
  110. }
  111. // KPIInfo get KPI info.
  112. func (d *Dao) KPIInfo(c context.Context, id int64) (res model.Kpi, err error) {
  113. row := d.db.QueryRow(c, _selKPIInfoSQL, id)
  114. if err = row.Scan(&res.ID, &res.Mid, &res.HandlerStatus); err != nil {
  115. log.Error("d.KPIInfo err(%v)", err)
  116. }
  117. return
  118. }
  119. // CaseByID get case info by id.
  120. func (d *Dao) CaseByID(c context.Context, id int64) (res model.Case, err error) {
  121. row := d.db.QueryRow(c, _selCaseByIDSQL, id)
  122. if err = row.Scan(&res.ID, &res.Mid, &res.Status, &res.JudgeType, &res.RelationID); err != nil {
  123. log.Error("d.BlockCount err(%v)", err)
  124. }
  125. return
  126. }
  127. // CountKPIRate count KPI rate<=4(C).
  128. func (d *Dao) CountKPIRate(c context.Context, mid int64) (count int, err error) {
  129. row := d.db.QueryRow(c, _countKPIRateSQL, mid)
  130. if err = row.Scan(&count); err != nil {
  131. log.Error("d.CountKPIRate(mid:%d) err(%v)", mid, err)
  132. }
  133. return
  134. }