admin_operate_record.go 672 B

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