admin.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package service
  2. import (
  3. "go-common/app/admin/main/reply/model"
  4. "go-common/library/log"
  5. "context"
  6. "time"
  7. )
  8. func (s *Service) addAdminLog(c context.Context, oid, rpID, adminID int64, typ, isNew, isReport, state int32, result, remark string, now time.Time) (err error) {
  9. rpMap := map[int64]*model.Reply{rpID: &model.Reply{
  10. Oid: oid,
  11. ID: rpID,
  12. }}
  13. return s.addAdminLogs(c, rpMap, adminID, typ, isNew, isReport, state, result, remark, now)
  14. }
  15. func (s *Service) addAdminIDLogs(c context.Context, oids []int64, rpIDs []int64, adminID int64, typ, isNew, isReport, state int32, result, remark string, now time.Time) (err error) {
  16. if _, err = s.dao.UpAdminNotNew(c, rpIDs, now); err != nil {
  17. log.Error("s.dao.UpAdminNotNew(%v) error(%v)", rpIDs, err)
  18. }
  19. if _, err = s.dao.AddAdminLog(c, oids, rpIDs, adminID, typ, isNew, isReport, state, result, remark, now); err != nil {
  20. log.Error("s.dao.AddAdminLog(admin:%d, oid:%v rpID:%v type:%d result:%s remark:%s isReport:%d state:%d) error(%v)", adminID, oids, rpIDs, typ, result, remark, isReport, state, err)
  21. }
  22. return
  23. }
  24. func (s *Service) addAdminLogs(c context.Context, rps map[int64]*model.Reply, adminID int64, typ, isNew, isReport, state int32, result, remark string, now time.Time) (err error) {
  25. if len(rps) == 0 {
  26. return
  27. }
  28. rpIDs := make([]int64, 0, len(rps))
  29. oids := make([]int64, 0, len(rps))
  30. for _, rp := range rps {
  31. rpIDs = append(rpIDs, rp.ID)
  32. oids = append(oids, rp.Oid)
  33. }
  34. if _, err = s.dao.UpAdminNotNew(c, rpIDs, now); err != nil {
  35. log.Error("s.dao.UpAdminNotNew(%v) error(%v)", rpIDs, err)
  36. }
  37. if _, err = s.dao.AddAdminLog(c, oids, rpIDs, adminID, typ, isNew, isReport, state, result, remark, now); err != nil {
  38. log.Error("s.dao.AddAdminLog(admin:%d, oid:%v rpID:%v type:%d result:%s remark:%s isReport:%d state:%d) error(%v)", adminID, oids, rpIDs, typ, result, remark, isReport, state, err)
  39. }
  40. return
  41. }
  42. // ReplyAdminLog ReplyAdminLog
  43. type ReplyAdminLog struct {
  44. model.AdminLog
  45. AdminName string `json:"admin_name"`
  46. }
  47. // LogsByRpID get log by reply id.
  48. func (s *Service) LogsByRpID(c context.Context, rpID int64) (res []ReplyAdminLog, err error) {
  49. var resDao []*model.AdminLog
  50. res = []ReplyAdminLog{}
  51. if resDao, err = s.dao.AdminLogsByRpID(c, rpID); err != nil {
  52. log.Error("s.dao.AdminLogsByRpID(%d) error(%v)", rpID, err)
  53. return
  54. }
  55. admins := map[int64]string{}
  56. for _, data := range resDao {
  57. admins[data.AdminID] = ""
  58. res = append(res, ReplyAdminLog{*data, ""})
  59. }
  60. s.dao.AdminName(c, admins)
  61. for i := range res {
  62. res[i].AdminName = admins[res[i].AdminID]
  63. }
  64. return
  65. }