wx_refresh_logic_backup.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package WorkPhone
  2. //
  3. //import (
  4. // "context"
  5. // "fmt"
  6. // "github.com/imroc/req/v3"
  7. // "github.com/suyuan32/simple-admin-common/msg/errormsg"
  8. // "strconv"
  9. // "time"
  10. // "wechat-api/ent"
  11. // "wechat-api/ent/wx"
  12. // "wechat-api/internal/utils/dberrorhandler"
  13. //
  14. // "wechat-api/internal/svc"
  15. // "wechat-api/internal/types"
  16. //
  17. // "github.com/zeromicro/go-zero/core/logx"
  18. //)
  19. //
  20. //type WxRefreshLogic struct {
  21. // logx.Logger
  22. // ctx context.Context
  23. // svcCtx *svc.ServiceContext
  24. //}
  25. //
  26. //func NewWxRefreshLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WxRefreshLogic {
  27. // return &WxRefreshLogic{
  28. // Logger: logx.WithContext(ctx),
  29. // ctx: ctx,
  30. // svcCtx: svcCtx}
  31. //}
  32. //
  33. //func (l *WxRefreshLogic) WxRefresh() (resp *types.BaseMsgResp, err error) {
  34. // var result types.WorkPhoneGetWeChatsResp
  35. // client := req.C().DevMode()
  36. // client.SetCommonRetryCount(2).
  37. // SetCommonRetryBackoffInterval(1*time.Second, 5*time.Second).
  38. // SetCommonRetryFixedInterval(2 * time.Second).SetTimeout(30 * time.Second)
  39. // res, err := client.R().SetSuccessResult(&result).Post("http://chat.gkscrm.com:13086/pc/GetWeChatsReq?id=13")
  40. //
  41. // if err != nil {
  42. // return
  43. // }
  44. // if !res.IsSuccessState() {
  45. // err = fmt.Errorf("GetWeChats failed with status code %d", res.StatusCode)
  46. // return
  47. // }
  48. //
  49. // for _, account := range result.Data {
  50. // if account.Wechatid == "" {
  51. // continue
  52. // }
  53. // wxinfo, err := l.svcCtx.DB.Wx.Query().
  54. // Where(
  55. // wx.And(
  56. // wx.Or(
  57. // wx.WxidEQ(account.Wechatid),
  58. // wx.PortEQ(account.Deviceid),
  59. // ),
  60. // wx.CtypeEQ(1),
  61. // ),
  62. // ).
  63. // Only(l.ctx)
  64. //
  65. // if err != nil && !ent.IsNotFound(err) {
  66. // return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
  67. // }
  68. // var status uint8
  69. // if account.Isonline == 0 {
  70. // status = 1
  71. // } else {
  72. // status = 0
  73. // }
  74. // if wxinfo != nil {
  75. // err = l.svcCtx.DB.Wx.UpdateOneID(wxinfo.ID).
  76. // SetServerID(0).
  77. // SetPort(account.Deviceid).
  78. // SetProcessID(strconv.FormatInt(account.Cid, 10)).
  79. // SetAccount(account.Wechatno).
  80. // SetNickname(account.Wechatnick).
  81. // SetHeadBig(account.Avatar).
  82. // SetStatus(status).
  83. // Exec(l.ctx)
  84. //
  85. // if err != nil {
  86. // return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
  87. // }
  88. // } else {
  89. // l.Debug("wxinfo is nil")
  90. // _, err := l.svcCtx.DB.Wx.Create().
  91. // SetServerID(0).
  92. // SetPort(account.Deviceid).
  93. // SetProcessID(strconv.FormatInt(account.Cid, 10)).
  94. // SetWxid(account.Wechatid).
  95. // SetAccount(account.Wechatno).
  96. // SetHeadBig(account.Avatar).
  97. // SetNickname(account.Wechatnick).
  98. // SetStatus(status).
  99. // SetAllowList([]string{}).SetBlockList([]string{}).SetGroupAllowList([]string{}).SetGroupBlockList([]string{}).
  100. // Save(l.ctx)
  101. // l.Error("wxinfo save", err)
  102. // if err != nil {
  103. // return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
  104. // }
  105. // }
  106. // }
  107. //
  108. // l.svcCtx.Rds.Del(l.ctx, "crontask_wx_server_info")
  109. //
  110. // return &types.BaseMsgResp{Msg: errormsg.Success}, nil
  111. //
  112. // return
  113. //}