admin_operate_record.go 701 B

123456789101112131415161718192021222324252627282930
  1. package services
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_eta_api/models/system"
  6. "hongze/hz_eta_api/utils"
  7. "time"
  8. )
  9. // the service for log
  10. func AutoInsertAdminOperateRecordToDB() {
  11. defer func() {
  12. if err := recover(); err != nil {
  13. fmt.Println("[AutoInsertAdminOperateRecordToDB]", err)
  14. }
  15. }()
  16. for {
  17. utils.Rc.Brpop(utils.CACHE_KEY_ADMIN_OPERATE_RECORD, func(b []byte) {
  18. record := new(system.AdminOperateRecord)
  19. if err := json.Unmarshal(b, &record); err != nil {
  20. fmt.Println("json unmarshal wrong!")
  21. }
  22. record.CreateTime = time.Now()
  23. if err := record.Insert(); err != nil {
  24. fmt.Println("AutoInsertAdminOperateRecordToDB Err:", err.Error(), record)
  25. }
  26. })
  27. }
  28. }