|
@@ -4,7 +4,11 @@ import (
|
|
|
"context"
|
|
|
"fmt"
|
|
|
"github.com/imroc/req/v3"
|
|
|
+ "strconv"
|
|
|
"time"
|
|
|
+ "wechat-api/ent"
|
|
|
+ "wechat-api/ent/wx"
|
|
|
+ "wechat-api/internal/utils/dberrorhandler"
|
|
|
|
|
|
"wechat-api/internal/svc"
|
|
|
"wechat-api/internal/types"
|
|
@@ -41,5 +45,61 @@ func (l *QwRefreshLogic) QwRefresh() (resp *types.BaseMsgResp, err error) {
|
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
+ for _, account := range result.Data {
|
|
|
+ if account.Wechatid == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ wxinfo, err := l.svcCtx.DB.Wx.Query().
|
|
|
+ Where(
|
|
|
+ wx.WxidEQ(account.Wechatid),
|
|
|
+ wx.Ctype(3),
|
|
|
+ ).
|
|
|
+ Only(l.ctx)
|
|
|
+
|
|
|
+ if err != nil && !ent.IsNotFound(err) {
|
|
|
+ return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
|
|
|
+ }
|
|
|
+ var status uint8
|
|
|
+ if account.Isonline == 0 {
|
|
|
+ status = 1
|
|
|
+ } else {
|
|
|
+ status = 0
|
|
|
+ }
|
|
|
+ if wxinfo != nil {
|
|
|
+ err = l.svcCtx.DB.Wx.UpdateOneID(wxinfo.ID).
|
|
|
+ SetServerID(0).
|
|
|
+ SetPort(account.Deviceid).
|
|
|
+ SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
|
+ SetAccount(account.Wechatno).
|
|
|
+ SetNickname(account.Wechatnick).
|
|
|
+ SetHeadBig(account.Avatar).
|
|
|
+ SetStatus(status).
|
|
|
+ Exec(l.ctx)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ l.Debug("wxinfo is nil")
|
|
|
+ _, err := l.svcCtx.DB.Wx.Create().
|
|
|
+ SetServerID(0).
|
|
|
+ SetPort(account.Deviceid).
|
|
|
+ SetProcessID(strconv.FormatInt(account.Cid, 10)).
|
|
|
+ SetWxid(account.Wechatid).
|
|
|
+ SetAccount(account.Wechatno).
|
|
|
+ SetHeadBig(account.Avatar).
|
|
|
+ SetNickname(account.Wechatnick).
|
|
|
+ SetStatus(status).
|
|
|
+ SetAllowList([]string{}).SetBlockList([]string{}).SetGroupAllowList([]string{}).SetGroupBlockList([]string{}).
|
|
|
+ Save(l.ctx)
|
|
|
+ l.Error("wxinfo save", err)
|
|
|
+ if err != nil {
|
|
|
+ return nil, dberrorhandler.DefaultEntError(l.Logger, err, account)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ l.svcCtx.Rds.Del(l.ctx, "crontask_wx_server_info")
|
|
|
+
|
|
|
return resp, nil
|
|
|
}
|