log_and_fix.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "encoding/json"
  5. "go-common/app/job/main/passport-game-data/model"
  6. "go-common/library/log"
  7. )
  8. func (s *Service) fixCloudRecord(c context.Context, newRecord *model.AsoAccount, old *model.AsoAccount) {
  9. if old == nil {
  10. affected, err := s.d.AddIgnoreAsoAccount(c, newRecord)
  11. if err != nil {
  12. oldStr, _ := json.Marshal(old)
  13. newStr, _ := json.Marshal(newRecord)
  14. log.Error("failed to fix cloud record by adding, old(%s) new(%s) error(%v)", oldStr, newStr, err)
  15. return
  16. }
  17. if affected == 0 {
  18. oldStr, _ := json.Marshal(old)
  19. newStr, _ := json.Marshal(newRecord)
  20. log.Error("failed to fix cloud record by adding because of concurrent update, old(%s) new(%s)", oldStr, newStr)
  21. return
  22. }
  23. oldStr, _ := json.Marshal(old)
  24. newStr, _ := json.Marshal(newRecord)
  25. log.Info("fix cloud record by adding ok, old(%s) new(%s)", oldStr, newStr)
  26. return
  27. }
  28. affected, err := s.d.UpdateAsoAccountCloud(c, newRecord, old.Mtime)
  29. if err != nil {
  30. oldStr, _ := json.Marshal(old)
  31. newStr, _ := json.Marshal(newRecord)
  32. log.Error("failed to fix cloud record by updating, old(%s) new(%s) error(%v)", oldStr, newStr, err)
  33. return
  34. }
  35. if affected == 0 {
  36. oldStr, _ := json.Marshal(old)
  37. newStr, _ := json.Marshal(newRecord)
  38. log.Error("failed to fix cloud record by updating because of concurrent update, old(%s) new(%s)", oldStr, newStr)
  39. return
  40. }
  41. oldStr, _ := json.Marshal(old)
  42. newStr, _ := json.Marshal(newRecord)
  43. log.Info("fix cloud record by updating ok, old(%s) new(%s)", oldStr, newStr)
  44. }
  45. func (s *Service) doLog(cloud *model.AsoAccount, local *model.OriginAsoAccount, afterPending bool) {
  46. localStr := []byte("nil")
  47. localEncStr := []byte("nil")
  48. if local != nil {
  49. localStr, _ = json.Marshal(local)
  50. localEncStr, _ = json.Marshal(model.Default(local))
  51. }
  52. cloudStr := []byte("nil")
  53. if cloud != nil {
  54. cloudStr, _ = json.Marshal(cloud)
  55. }
  56. if afterPending {
  57. log.Info("failed to compare, because cloud record is not updated in time, local(%s) local_encrypted(%s) cloud(%s)", localStr, localEncStr, cloudStr)
  58. return
  59. }
  60. log.Info("compare diff, local(%s) local_encrypted(%s) cloud(%s)", localStr, localEncStr, cloudStr)
  61. }