update
This commit is contained in:
parent
5bc08a830a
commit
c3d20a9d5f
2
go.mod
2
go.mod
@ -10,7 +10,7 @@ require (
|
||||
github.com/stretchr/testify v1.8.4
|
||||
go.uber.org/zap v1.27.0
|
||||
google.golang.org/protobuf v1.33.0
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af
|
||||
)
|
||||
|
||||
|
2
go.sum
2
go.sum
@ -149,5 +149,7 @@ penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3
|
||||
penahub.gitlab.yandexcloud.net/backend/penahub_common v0.0.0-20240223054633-6cb3d5ce45b6/go.mod h1:lTmpjry+8evVkXWbEC+WMOELcFkRD1lFMc7J09mOndM=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae h1:FaV/RbCQaMZg48bzvMhNzzC4RtI3wQIPrMA0ZDl3jDA=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240419144125-64e45ebed8ae/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb h1:INNnspSaEyKlfhQ+E279sNcIzDrwvRfEFmYTuk7bdZw=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/common.git v0.0.0-20240420091424-34628bcc93eb/go.mod h1:oRyhT55ctjqp/7ZxIzkR7OsQ7T/NLibsfrbb7Ytns64=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af h1:jQ7HaXSutDX5iepU7VRImxhikK7lV/lBKkiloOZ4Emo=
|
||||
penahub.gitlab.yandexcloud.net/backend/quiz/core.git v0.0.0-20240219174804-d78fd38511af/go.mod h1:5S5YwjSXWmnEKjBjG6MtyGtFmljjukDRS8CwHk/CF/I=
|
||||
|
@ -69,6 +69,8 @@ func (c *Controller) ConnectAccount(ctx *fiber.Ctx) error {
|
||||
return ctx.Status(fiber.StatusUnauthorized).SendString("account id is required")
|
||||
}
|
||||
|
||||
//accountID := "64f2cd7a7047f28fdabf6d9e"
|
||||
|
||||
response, err := c.service.ConnectAccount(ctx.Context(), accountID)
|
||||
if err != nil {
|
||||
c.logger.Error("error connect account", zap.Error(err))
|
||||
|
@ -6,11 +6,11 @@ type RequestGetListUsers struct {
|
||||
}
|
||||
|
||||
type ResponseGetListUsers struct {
|
||||
TotalItems int `json:"_total_items"`
|
||||
Page int `json:"_page"`
|
||||
PageCount int `json:"_page_count"`
|
||||
Links LinksSelf `json:"_links"`
|
||||
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
||||
TotalItems int `json:"_total_items"`
|
||||
//Page int `json:"_page"`
|
||||
//PageCount int `json:"_page_count"`
|
||||
Links LinksSelf `json:"_links"`
|
||||
Embedded EmbeddedGetListUsers `json:"_embedded"`
|
||||
}
|
||||
|
||||
type EmbeddedGetListUsers struct {
|
||||
@ -26,11 +26,16 @@ type LinksSelf struct {
|
||||
}
|
||||
|
||||
type Users struct {
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Lang string `json:"lang"`
|
||||
Rights Rights `json:"rights"`
|
||||
ID int32 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
UUID string `json:"uuid"`
|
||||
IsConfirmed bool `json:"is_confirmed"`
|
||||
ConfirmLinkSentAt int `json:"confirm_link_sent_at"`
|
||||
Lang string `json:"lang"`
|
||||
FullName string `json:"full_name"`
|
||||
Groups Groups `json:"groups"`
|
||||
//Rights Rights `json:"rights"`
|
||||
Links SelfLink `json:"_links"`
|
||||
Embedded Embedded `json:"_embedded"`
|
||||
}
|
||||
@ -48,6 +53,7 @@ type Rights struct {
|
||||
IsActive bool `json:"is_active"`
|
||||
GroupID *int `json:"group_id,omitempty"`
|
||||
RoleID *int `json:"role_id,omitempty"`
|
||||
Role *string `json:"role,omitempty"`
|
||||
}
|
||||
|
||||
type Leads struct {
|
||||
@ -103,7 +109,11 @@ type Groups struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
//type Embedded struct {
|
||||
// Roles []Roles `json:"roles"`
|
||||
// Groups []Groups `json:"groups"`
|
||||
//}
|
||||
|
||||
type Embedded struct {
|
||||
Roles []Roles `json:"roles"`
|
||||
Groups []Groups `json:"groups"`
|
||||
Rights Rights `json:"rights"`
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"amocrm/internal/models"
|
||||
"amocrm/internal/tools"
|
||||
"context"
|
||||
"go.uber.org/zap"
|
||||
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
|
||||
@ -30,7 +29,7 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
||||
return err
|
||||
}
|
||||
|
||||
// получаем информацию о пользователе по аксес токену и затем по его id
|
||||
// получаем информацию о пользователе по аксес токену
|
||||
userInfo, err := s.amoClient.GetUserInfo(tokens.AccessToken)
|
||||
if err != nil {
|
||||
s.logger.Error("error getting UserInfo in Service:", zap.Error(err))
|
||||
@ -41,12 +40,9 @@ func (s *Service) WebhookCreate(ctx context.Context, req ParamsWebhookCreate) er
|
||||
Name: userInfo.Name,
|
||||
Subdomain: userInfo.Subdomain,
|
||||
AmoID: userInfo.ID,
|
||||
// подключивший юзер считается тот который прокинул хук сюда
|
||||
Amouserid: userInfo.ID,
|
||||
//Email: userInfoByID.Email,
|
||||
Group: tools.ConvertUserGroups(userInfo),
|
||||
//Group: tools.ConvertUserGroups(userInfo),
|
||||
Country: userInfo.Country,
|
||||
//Role: *userInfoByID.Role,
|
||||
}
|
||||
|
||||
err = s.repository.AmoRepo.CreateAccount(ctx, req.AccountID, toUpdate)
|
||||
|
@ -17,13 +17,13 @@ func ConvertUserGroups(groups *models.AmocrmUserInformation) []model.UserGroups
|
||||
return userGroups
|
||||
}
|
||||
|
||||
func ConvertGroups(groups models.Users) []model.UserGroups {
|
||||
var userGroups []model.UserGroups
|
||||
for _, group := range groups.Embedded.Groups {
|
||||
userGroups = append(userGroups, model.UserGroups{
|
||||
ID: group.ID,
|
||||
Name: group.Name,
|
||||
})
|
||||
}
|
||||
return userGroups
|
||||
}
|
||||
//func ConvertGroups(groups models.Users) []model.UserGroups {
|
||||
// var userGroups []model.UserGroups
|
||||
// for _, group := range groups.Embedded.Groups {
|
||||
// userGroups = append(userGroups, model.UserGroups{
|
||||
// ID: group.ID,
|
||||
// Name: group.Name,
|
||||
// })
|
||||
// }
|
||||
// return userGroups
|
||||
//}
|
||||
|
@ -230,7 +230,7 @@ func (wc *DataUpdater) processTasks(ctx context.Context) {
|
||||
}
|
||||
|
||||
func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token) error {
|
||||
var listUser []models.Users
|
||||
listUser := make(map[string][]models.Users)
|
||||
for _, token := range allTokens {
|
||||
page := 1
|
||||
limit := 250
|
||||
@ -248,28 +248,36 @@ func (wc *DataUpdater) UserUpdater(ctx context.Context, allTokens []model.Token)
|
||||
break
|
||||
}
|
||||
|
||||
listUser = append(listUser, userData.Embedded.Users...)
|
||||
listUser[token.AccountID] = append(listUser[token.AccountID], userData.Embedded.Users...)
|
||||
|
||||
page++
|
||||
}
|
||||
}
|
||||
|
||||
for _, user := range listUser {
|
||||
//onlyOneUser, err := wc.amoClient.GetUserByID(user.ID)
|
||||
//if err != nil {
|
||||
// wc.logger.Error("error getting user by id", zap.Error(err))
|
||||
// continue
|
||||
//}
|
||||
err := wc.repo.AmoRepo.CheckUsers(ctx, user.ID, model.User{
|
||||
Name: user.Name,
|
||||
Group: tools.ConvertGroups(user),
|
||||
Role: "todo",
|
||||
Email: user.Email,
|
||||
})
|
||||
|
||||
for accountID, users := range listUser {
|
||||
mainAccount, err := wc.repo.AmoRepo.GetCurrentAccount(ctx, accountID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, user := range users {
|
||||
if user.ID == mainAccount.AmoID {
|
||||
|
||||
}
|
||||
|
||||
err := wc.repo.AmoRepo.CheckAndUpdateUsers(ctx, model.User{
|
||||
AmoID: user.ID,
|
||||
Name: user.FullName,
|
||||
Group: int32(*user.Embedded.Rights.GroupID),
|
||||
Role: int32(*user.Embedded.Rights.RoleID),
|
||||
Email: user.Email,
|
||||
Amouserid: mainAccount.Amouserid,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -54,7 +54,7 @@ func NewAmoClient(deps AmoDeps) *Amo {
|
||||
func (a *Amo) GetUserList(req models.RequestGetListUsers, accesToken string) (*models.ResponseGetListUsers, error) {
|
||||
for {
|
||||
if a.rateLimiter.Check() {
|
||||
uri := fmt.Sprintf("%s/api/v4/users?page=%d&limit=%d&with=role,group,uuid", a.baseApiURL, req.Page, req.Limit)
|
||||
uri := fmt.Sprintf("https://penadigitaltech.amocrm.ru/ajax/v3/users?with=rights&page=%s&limit=%s", req.Page, req.Limit)
|
||||
|
||||
agent := a.fiberClient.Get(uri)
|
||||
agent.Set("Authorization", "Bearer "+accesToken)
|
||||
|
@ -109,14 +109,12 @@ func updateUser(ctx context.Context, repo *dal.AmoDal) error {
|
||||
AmoID: 666,
|
||||
Amouserid: int32(i),
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
Group: int32(i),
|
||||
Country: "Russia",
|
||||
}
|
||||
|
||||
if i%2 == 0 {
|
||||
role := faker.String()
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
info.Role = int32(i)
|
||||
info.ID = faker.Int64()
|
||||
}
|
||||
|
||||
@ -140,13 +138,11 @@ func checkUsers(ctx context.Context, repo *dal.AmoDal) error {
|
||||
info := model.User{
|
||||
Name: faker.String(),
|
||||
Email: faker.Email(),
|
||||
Group: tools.ConvertUserGroups(&testUserInfo),
|
||||
Group: int32(i),
|
||||
}
|
||||
role := faker.String()
|
||||
role2 := &role
|
||||
info.Role = *role2
|
||||
info.Role = int32(i)
|
||||
|
||||
err = repo.AmoRepo.CheckUsers(ctx, int32(i), info)
|
||||
err = repo.AmoRepo.CheckAndUpdateUsers(ctx, info)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user