update after testing

This commit is contained in:
Pavel 2024-10-23 12:21:14 +03:00
parent f4b739015e
commit 63c0845d7a
4 changed files with 24 additions and 15 deletions

@ -3,6 +3,7 @@ package models
import ( import (
"github.com/rs/xid" "github.com/rs/xid"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
"strings"
) )
type FieldsResponse struct { type FieldsResponse struct {
@ -41,6 +42,11 @@ type AddFields struct {
func (a *AddFields) GenFieldName() { func (a *AddFields) GenFieldName() {
guid := xid.New() guid := xid.New()
guidGen := guid.String() guidGen := guid.String()
a.FieldName = guidGen // todo и так и так работает обдумать стоит
a.XMLID = guidGen // https://dev.1c-bitrix.ru/rest_help/crm/cdeals/crm_deal_userfield_add.php
//a.FieldName = guidGen[:13]
//a.XMLID = guidGen[:13]
a.FieldName = strings.ToUpper(guidGen)
a.XMLID = strings.ToUpper(guidGen)
} }

@ -8,6 +8,7 @@ import (
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/models" "penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/models"
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/internal/tools"
"penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/pkg/bitrixClient" "penahub.gitlab.yandexcloud.net/backend/quiz/bitrix/pkg/bitrixClient"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/dal"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/model"
@ -15,6 +16,7 @@ import (
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/bitrix" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/repository/bitrix"
"penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils" "penahub.gitlab.yandexcloud.net/backend/quiz/common.git/utils"
"strconv" "strconv"
"strings"
"time" "time"
) )
@ -217,11 +219,11 @@ func (wc *DealsWorker) constructField(ctx context.Context, request interface{},
} }
if fieldData.FieldType == model.StringCustomFieldsType { if fieldData.FieldType == model.StringCustomFieldsType {
//content := strings.ReplaceAll(data.Content, " ", "") content := strings.ReplaceAll(data.Content, " ", "")
//if content == "" { if content == "" {
// data.Content = "Пустая строка" data.Content = "Пустая строка"
//} }
entityFieldsMap[entityType][fieldData.FieldName] = data.Content entityFieldsMap[entityType][fieldData.FieldName] = tools.EmojiUnicode(data.Content)
continue continue
} }
} }

@ -643,11 +643,11 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, msg models.K
m.logger.Error("error adding fields to amo", zap.Any("type", entity), zap.Error(err)) m.logger.Error("error adding fields to amo", zap.Any("type", entity), zap.Error(err))
continue continue
} }
// todo // todo need checking in prod
newFields = append(newFields, model.BitrixField{ newFields = append(newFields, model.BitrixField{
BitrixID: fmt.Sprintf("%d", createdID), BitrixID: fmt.Sprintf("%d", createdID),
EntityID: entity, EntityID: entity,
FieldName: "UF_CRM_" + strings.ToUpper(field.FieldName), FieldName: "UF_CRM_" + field.FieldName,
EditFromLabel: field.EditFormLabel, EditFromLabel: field.EditFormLabel,
FieldType: field.UserTypeID, FieldType: field.UserTypeID,
}) })
@ -663,11 +663,11 @@ func (m *Methods) CheckFieldRule(ctx context.Context, token string, msg models.K
continue continue
} }
// todo // todo need checking in prod
newFields = append(newFields, model.BitrixField{ newFields = append(newFields, model.BitrixField{
BitrixID: fmt.Sprintf("%d", createdID), BitrixID: fmt.Sprintf("%d", createdID),
EntityID: model.FieldTypeContact, EntityID: model.FieldTypeContact,
FieldName: "UF_CRM_" + strings.ToUpper(contactField.FieldName), FieldName: "UF_CRM_" + contactField.FieldName,
EditFromLabel: contactField.EditFormLabel, EditFromLabel: contactField.EditFormLabel,
FieldType: contactField.UserTypeID, FieldType: contactField.UserTypeID,
}) })

@ -48,7 +48,7 @@ func TestGetListFields(t *testing.T) {
//} //}
// //
fieldAnswer := make(map[string]string) fieldAnswer := make(map[string]string)
fieldAnswer["UF_CRM_CSC0TEL6PVUM0J68N5RG"] = "field1" fieldAnswer["UF_CRM_1729669958"] = "хуйхуйхуйхухй"
// //
//createContactReq := models.CreateContactReq{ //createContactReq := models.CreateContactReq{
@ -98,8 +98,8 @@ func TestGetListFields(t *testing.T) {
Title: "ТЕСТ ОТ ГОУ АПИ 10/10", Title: "ТЕСТ ОТ ГОУ АПИ 10/10",
TypeID: "SALE", TypeID: "SALE",
StageID: "NEW", StageID: "NEW",
CompanyID: 369, CompanyID: 383,
ContactIDs: []int32{211}, ContactIDs: []int32{235},
Opened: "Y", Opened: "Y",
AssignedByID: 1, AssignedByID: 1,
CategoryID: 1, CategoryID: 1,
@ -113,7 +113,8 @@ func TestGetListFields(t *testing.T) {
} }
// //
reqMap := models.FormattingToMap(&createDealReq, fieldAnswer) reqMap := models.FormattingToMap(&createDealReq, fieldAnswer)
result, err := b.CreatingDeal(reqMap, "59161867007232200072541200000001000007a3be721d08cbf9f847b807c4eb79a73f", "b24-s5jg6c.bitrix24.ru") fmt.Println(reqMap)
result, err := b.CreatingDeal(reqMap, "8ec218670000071b0072541200000001000007d0047b935d30b9acc0cbd5d0202b8711", "b24-s5jg6c.bitrix24.ru")
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }