blacklist.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package income
  2. import (
  3. "bytes"
  4. "context"
  5. "strconv"
  6. model "go-common/app/admin/main/growup/model/income"
  7. "go-common/library/database/sql"
  8. "go-common/library/log"
  9. )
  10. // ArchiveBlack stop archives income, add archive into av_black_list
  11. func (s *Service) ArchiveBlack(c context.Context, typ int, aIDs []int64, mid int64) (err error) {
  12. if len(aIDs) == 0 {
  13. return
  14. }
  15. tx, err := s.dao.BeginTran(c)
  16. if err != nil {
  17. log.Error("s.dao.BeginTran error(%v)", err)
  18. return
  19. }
  20. if err = s.TxInsertAvBlacklist(c, tx, typ, aIDs, mid, _avBlack, len(aIDs)); err != nil {
  21. log.Error("s.InsertAvBlacklist error(%v)", err)
  22. return
  23. }
  24. if err = tx.Commit(); err != nil {
  25. log.Error("tx.Commit error")
  26. }
  27. return
  28. }
  29. // GetAvBlackListByAvIds get av_black_list by av_id and ctype
  30. func (s *Service) GetAvBlackListByAvIds(c context.Context, avs []*model.ArchiveIncome, ctype int) (avBMap map[int64]struct{}, err error) {
  31. avIDMap := make(map[int64]struct{})
  32. for _, av := range avs {
  33. avIDMap[av.AvID] = struct{}{}
  34. }
  35. avIDList := []int64{}
  36. for avID := range avIDMap {
  37. avIDList = append(avIDList, avID)
  38. }
  39. avBMap = make(map[int64]struct{})
  40. if len(avIDList) > 0 {
  41. avBMap, err = s.dao.ListAvBlackList(c, avIDList, ctype)
  42. if err != nil {
  43. log.Error("s.dao.ListAvBlackList error(%v)", err)
  44. return
  45. }
  46. }
  47. return
  48. }
  49. // TxInsertAvBlacklist insert av_black_list
  50. func (s *Service) TxInsertAvBlacklist(c context.Context, tx *sql.Tx, ctype int, aIDs []int64, mid int64, reason int, count int) (err error) {
  51. nickname, err := s.dao.GetUpInfoNicknameByMID(c, mid, getUpInfoTable(ctype))
  52. if err != nil {
  53. log.Error("s.dao.GetUpInfoNicknameByMID error(%v)", err)
  54. return
  55. }
  56. isDeleted, hasSigned := 0, 0
  57. if nickname != "" {
  58. hasSigned = 1
  59. }
  60. var buf bytes.Buffer
  61. for _, id := range aIDs {
  62. buf.WriteString("(")
  63. buf.WriteString(strconv.FormatInt(id, 10))
  64. buf.WriteByte(',')
  65. buf.WriteString(strconv.FormatInt(mid, 10))
  66. buf.WriteByte(',')
  67. buf.WriteString(strconv.Itoa(ctype))
  68. buf.WriteByte(',')
  69. buf.WriteString(strconv.Itoa(reason))
  70. buf.WriteByte(',')
  71. buf.WriteString("\"" + nickname + "\"")
  72. buf.WriteByte(',')
  73. buf.WriteString(strconv.Itoa(hasSigned))
  74. buf.WriteByte(',')
  75. buf.WriteString(strconv.Itoa(isDeleted))
  76. buf.WriteString(")")
  77. buf.WriteByte(',')
  78. }
  79. if buf.Len() > 0 {
  80. buf.Truncate(buf.Len() - 1)
  81. }
  82. vals := buf.String()
  83. buf.Reset()
  84. rows, err := s.dao.TxInsertAvBlackList(tx, vals)
  85. if err != nil {
  86. tx.Rollback()
  87. return
  88. }
  89. if rows < int64(count) {
  90. log.Info("TxInsertAvBlackList(%v) rows(%d) < count(%d) error", vals, rows, count)
  91. }
  92. return
  93. }