user_conf.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/kvo/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _getUserConf = "SELECT mid,module_key,check_sum,timestamp FROM user_conf WHERE mid=? AND module_key=?"
  11. _upUserConf = "INSERT INTO user_conf(mid,module_key,check_sum,timestamp,ctime,mtime) VALUES(?,?,?,?,?,?) ON DUPLICATE KEY UPDATE check_sum=?, timestamp=?"
  12. )
  13. // UserConf get userconf
  14. func (d *Dao) UserConf(ctx context.Context, mid int64, moduleKey int) (userConf *model.UserConf, err error) {
  15. row := d.getUserConf.QueryRow(ctx, mid, moduleKey)
  16. userConf = &model.UserConf{}
  17. err = row.Scan(&userConf.Mid, &userConf.ModuleKey, &userConf.CheckSum, &userConf.Timestamp)
  18. if err != nil {
  19. if err == sql.ErrNoRows {
  20. userConf = nil
  21. err = nil
  22. return
  23. }
  24. log.Error("row.Scan err:%v", err)
  25. }
  26. return
  27. }
  28. // TxUpUserConf add or update user conf
  29. func (d *Dao) TxUpUserConf(ctx context.Context, tx *sql.Tx, mid int64, moduleKey int, checkSum int64, now time.Time) (err error) {
  30. _, err = tx.Exec(_upUserConf, mid, moduleKey, checkSum, now.Unix(), now, now, checkSum, now.Unix())
  31. if err != nil {
  32. log.Error("db.exec err:%v", err)
  33. }
  34. return
  35. }