user.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package xiangyu
  2. import (
  3. "eta/eta_bridge/controller/resp"
  4. "eta/eta_bridge/logic/xiangyu"
  5. "github.com/gin-gonic/gin"
  6. "sync"
  7. )
  8. // XiangyuController 象屿指标
  9. type XiangyuController struct{}
  10. // 同步用户锁,防止重复同步,不管是全量还是增量,都是同一时间只能一个同步
  11. var lockSyncUser sync.Mutex
  12. // SyncUser
  13. // @Description: 全量同步用户
  14. // @author: Roc
  15. // @receiver xc
  16. // @datetime 2024-01-22 15:51:25
  17. // @param c *gin.Context
  18. func (xc *XiangyuController) SyncUser(c *gin.Context) {
  19. lockSyncUser.Lock()
  20. defer func() {
  21. lockSyncUser.Unlock()
  22. }()
  23. err := xiangyu.SyncUser()
  24. if err != nil {
  25. resp.FailData("同步失败", err.Error(), c)
  26. return
  27. }
  28. resp.Ok("同步成功", c)
  29. return
  30. }
  31. // PullUser
  32. // @Description: 增量同步用户
  33. // @author: Roc
  34. // @receiver xc
  35. // @datetime 2024-01-23 17:13:07
  36. // @param c *gin.Context
  37. func (xc *XiangyuController) PullUser(c *gin.Context) {
  38. lockSyncUser.Lock()
  39. defer func() {
  40. lockSyncUser.Unlock()
  41. }()
  42. err := xiangyu.PullUser()
  43. if err != nil {
  44. resp.FailData("同步失败", err.Error(), c)
  45. return
  46. }
  47. resp.Ok("同步成功", c)
  48. return
  49. }